From be7a3770acf8e4a8a4c6a7468db19e15845eebe3 Mon Sep 17 00:00:00 2001 From: Mark Wolfman Date: Fri, 7 Jun 2024 15:15:52 -0500 Subject: [PATCH] Added some icons to the plan actions and cleaned up application launching exceptions. --- src/firefly/application.py | 20 ++++++++++++++------ src/firefly/launcher.py | 2 +- src/firefly/main_window.py | 1 - src/firefly/queue_client.py | 6 +++++- src/haven/exceptions.py | 26 ++++++-------------------- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/firefly/application.py b/src/firefly/application.py index 17788cdf..cc38d23f 100644 --- a/src/firefly/application.py +++ b/src/firefly/application.py @@ -265,13 +265,13 @@ def setup_window_actions(self): ) # Actions for executing plans plans = [ - # (plan_name, text, display file, shortcut) - ("count", "&Count", "count.py", "Ctrl+Shift+C"), - ("line_scan", "&Line scan", "line_scan.py", "Ctrl+Shift+L"), - ("xafs_scan", "&XAFS Scan", "xafs_scan.py", "Ctrl+Shift+X"), + # (plan_name, text, display file, shortcut, icon) + ("count", "&Count", "count.py", "Ctrl+Shift+C", "mdi.counter"), + ("line_scan", "&Line scan", "line_scan.py", "Ctrl+Shift+L", None), + ("xafs_scan", "&XAFS Scan", "xafs_scan.py", "Ctrl+Shift+X", None), ] self.plan_actions = [] - for plan_name, text, display_file, shortcut in plans: + for plan_name, text, display_file, shortcut, icon in plans: slot = partial( self.show_plan_window, name=plan_name, display_file=display_file ) @@ -283,6 +283,8 @@ def setup_window_actions(self): action.triggered.connect(slot) if shortcut is not None: action.setShortcut(QKeySequence(shortcut)) + if icon is not None: + action.setIcon(qta.icon(icon)) self.plan_actions.append(action) # Action for showing the run browser window self._setup_window_action( @@ -533,8 +535,14 @@ def prepare_queue_client(self, client=None, api=None): queueserver API. Used for testing. """ + # Load the API for controlling the queueserver. if api is None: - api = queueserver_api() + try: + api = queueserver_api() + except InvalidConfiguration: + log.error("Could not load queueserver API " + "configuration from iconfig.toml file.") + return # Create the client object if client is None: client = QueueClient(api=api) diff --git a/src/firefly/launcher.py b/src/firefly/launcher.py index 4dbc3de8..05a0ae5d 100644 --- a/src/firefly/launcher.py +++ b/src/firefly/launcher.py @@ -182,7 +182,7 @@ def main(default_fullscreen=False, default_display="status"): asyncio.set_event_loop(event_loop) # Define devices on the beamline (slow!) - app.setup_instrument() + app.setup_instrument(load_instrument=not pydm_args.no_instrument) # Get rid of the splash screen now that we're ready to go splash.close() diff --git a/src/firefly/main_window.py b/src/firefly/main_window.py index 214fc1ab..eb525722 100644 --- a/src/firefly/main_window.py +++ b/src/firefly/main_window.py @@ -120,7 +120,6 @@ def customize_ui(self): if hasattr(app, "show_logs_window_action"): self.ui.menuView.addAction(app.show_logs_window_action) # Setup menu - print(type(self.ui.menubar)) self.ui.menuSetup = QtWidgets.QMenu(self.ui.menubar) self.ui.menuSetup.setObjectName("menuSetup") self.ui.menuSetup.setTitle("Set&up") diff --git a/src/firefly/queue_client.py b/src/firefly/queue_client.py index e8b01c4d..4ba9ee32 100644 --- a/src/firefly/queue_client.py +++ b/src/firefly/queue_client.py @@ -9,12 +9,16 @@ from qtpy.QtCore import QObject, QTimer, Signal from haven import load_config +from haven.exceptions import UnknownDeviceConfiguration, InvalidConfiguration log = logging.getLogger() def queueserver_api(): - config = load_config()["queueserver"] + try: + config = load_config()["queueserver"] + except KeyError: + raise InvalidConfiguration("Could not load queueserver info from iconfig.toml file.") ctrl_addr = f"tcp://{config['control_host']}:{config['control_port']}" info_addr = f"tcp://{config['info_host']}:{config['info_port']}" api = REManagerAPI(zmq_control_addr=ctrl_addr, zmq_info_addr=info_addr) diff --git a/src/haven/exceptions.py b/src/haven/exceptions.py index f11fd642..b1a7baac 100644 --- a/src/haven/exceptions.py +++ b/src/haven/exceptions.py @@ -16,25 +16,7 @@ class GainOverflow(RuntimeError): ... - -# class ComponentNotFound(IndexError): -# """Registry looked for a component, but it wasn't registered.""" - -# ... - - -# class MultipleComponentsFound(IndexError): -# """Registry looked for a single component, but found more than one.""" - -# ... - - -# class InvalidComponentLabel(TypeError): -# """Registry looked for a component, but the label provided is not vlaid.""" - -# ... - - + class FileNotWritable(IOError): """Output file is available but does not have write intent.""" @@ -71,7 +53,11 @@ class IOCTimeout(RuntimeError): ... -class UnknownDeviceConfiguration(ValueError): +class InvalidConfiguration(ValueError): + """The configuration files for Haven are missing keys.""" + ... + +class UnknownDeviceConfiguration(InvalidConfiguration): """The configuration for a device does not match the known options.""" ...