def on_plugin_enable(self): ''' .. versionchanged:: 2.5 - Use `zmq_plugin.plugin.watch_plugin()` to monitor ZeroMQ interface in background thread. - Register `clear_routes` commands with ``microdrop.command_plugin``. ''' self.cleanup() self.plugin = RouteControllerZmqPlugin(self, self.name, get_hub_uri()) self._plugin_monitor_task = watch_plugin(self.executor, self.plugin) hub_execute_async('microdrop.command_plugin', 'register_command', command_name='clear_routes', namespace='global', plugin_name=self.name, title='Clear all r_outes') hub_execute_async('microdrop.command_plugin', 'register_command', command_name='clear_routes', namespace='electrode', plugin_name=self.name, title='Clear electrode ' '_routes')
def on_plugin_enable(self): self.cleanup() self.plugin = RouteControllerZmqPlugin(self, self.name, get_hub_uri()) self.route_controller = RouteController(self.plugin) # Initialize sockets. self.plugin.reset() self.plugin_timeout_id = gobject.timeout_add(10, self.plugin.check_sockets)
def on_plugin_enable(self): super(DropBotDxPlugin, self).on_plugin_enable() self.cleanup_plugin() # Initialize 0MQ hub plugin and subscribe to hub messages. self.plugin = DmfZmqPlugin(self, self.name, get_hub_uri(), subscribe_options={zmq.SUBSCRIBE: ''}) # Initialize sockets. self.plugin.reset() # Periodically process outstanding message received on plugin sockets. self.plugin_timeout_id = gtk.timeout_add(10, self.plugin.check_sockets) self.check_device_name_and_version() if get_app().protocol: self.on_step_run() self._update_protocol_grid()
def reset_gui(self): py_exe = sys.executable # Set allocation based on saved app values (i.e., remember window size # and position from last run). app_values = self.get_app_values() allocation_args = ['-a', json.dumps(app_values)] app = get_app() if app.config.data.get('advanced_ui', False): debug_args = ['-d'] else: debug_args = [] self.gui_process = Popen( [py_exe, '-m', 'dmf_device_ui.bin.device_view', '-n', self.name] + allocation_args + debug_args + ['fixed', get_hub_uri()], creationflags=CREATE_NEW_PROCESS_GROUP) self.gui_process.daemon = False self._gui_enabled = True def keep_alive(): if not self._gui_enabled: self.alive_timestamp = None return False elif self.gui_process.poll() == 0: # GUI process has exited. Restart. self.cleanup() self.reset_gui() return False else: self.alive_timestamp = datetime.now() # Keep checking. return True # Go back to Undo 613 for working corners self.step_video_settings = None # Get current video settings from UI. app_values = self.get_app_values() # Convert JSON settings to 0MQ plugin API Python types. ui_settings = self.json_settings_as_python(app_values) self.set_ui_settings(ui_settings, default_corners=True) self.gui_heartbeat_id = gobject.timeout_add(1000, keep_alive)
def reset_gui(self): py_exe = sys.executable # Set allocation based on saved app values (i.e., remember window size # and position from last run). app_values = self.get_app_values() allocation_args = ['-a', json.dumps(app_values)] app = get_app() if app.config.data.get('advanced_ui', False): debug_args = ['-d'] else: debug_args = [] self.gui_process = Popen([py_exe, '-m', 'dmf_device_ui.bin.device_view', '-n', self.name] + allocation_args + debug_args + ['fixed', get_hub_uri()], creationflags=CREATE_NEW_PROCESS_GROUP) self.gui_process.daemon = False self._gui_enabled = True def keep_alive(): if not self._gui_enabled: self.alive_timestamp = None return False elif self.gui_process.poll() == 0: # GUI process has exited. Restart. self.cleanup() self.reset_gui() return False else: self.alive_timestamp = datetime.now() # Keep checking. return True # Go back to Undo 613 for working corners self.step_video_settings = None self.wait_for_gui_process() # Get current video settings from UI. app_values = self.get_app_values() # Convert JSON settings to 0MQ plugin API Python types. ui_settings = self.json_settings_as_python(app_values) self.set_ui_settings(ui_settings, default_corners=True) self.gui_heartbeat_id = gobject.timeout_add(1000, keep_alive)
def on_plugin_enable(self): self.cleanup() self.plugin = DeviceQualityControlZmqPlugin(self, self.name, get_hub_uri()) # Initialize sockets. self.plugin.reset() self.plugin_timeout_id = gobject.timeout_add(10, self.plugin.check_sockets) # Add menu item to launch channel impedance scan. menu = [('Run channel impedance scan...', lambda *args: self.channel_impedance_scan()), ('Run channel impedance scan (slow)...', lambda *args: self.channel_impedance_scan(slow_scan=True))] app = get_app() for label_i, func_i in menu: menu_item_i = gtk.MenuItem(label_i) menu_item_i.connect("activate", func_i) app.main_window_controller.menu_tools.add(menu_item_i) menu_item_i.show()
def on_plugin_enable(self): super(DropBotPlugin, self).on_plugin_enable() if not self.menu_items: # Schedule initialization of menu user interface. Calling # `create_ui()` directly is not thread-safe, since it includes GTK # code. gobject.idle_add(self.create_ui) self.cleanup_plugin() # Initialize 0MQ hub plugin and subscribe to hub messages. self.plugin = DmfZmqPlugin(self, self.name, get_hub_uri(), subscribe_options={zmq.SUBSCRIBE: ''}) # Initialize sockets. self.plugin.reset() # Periodically process outstanding message received on plugin sockets. self.plugin_timeout_id = gtk.timeout_add(10, self.plugin.check_sockets) self.check_device_name_and_version() if get_app().protocol: self.on_step_run() self._update_protocol_grid()
def reset_gui(self): ''' .. versionchanged:: 2.2.2 Use :func:`pygtkhelpers.gthreads.gtk_threadsafe` decorator around function to wait for GUI process, rather than using :func:`gobject.idle_add`, to make intention clear. .. versionchanged:: 2.9 Refresh list of registered commands once device UI process has started. The list of registered commands is used to dynamically generate items in the device UI context menu. ''' py_exe = sys.executable # Set allocation based on saved app values (i.e., remember window size # and position from last run). app_values = self.get_app_values() if os.environ.get('MICRODROP_FIRST_RUN'): # Use default options for window allocation. default_app_values = self.get_default_app_options() for k in ('x', 'y', 'width', 'height'): app_values[k] = default_app_values[k] allocation_args = ['-a', json.dumps(app_values)] app = get_app() if app.config.data.get('advanced_ui', False): debug_args = ['-d'] else: debug_args = [] self.gui_process = Popen( [py_exe, '-m', 'dmf_device_ui.bin.device_view', '-n', self.name] + allocation_args + debug_args + ['fixed', get_hub_uri()], creationflags=CREATE_NEW_PROCESS_GROUP) self._gui_enabled = True def keep_alive(): if not self._gui_enabled: self.alive_timestamp = None return False elif self.gui_process.poll() == 0: # GUI process has exited. Restart. self.cleanup() self.reset_gui() return False else: self.alive_timestamp = datetime.now() # Keep checking. return True self.step_video_settings = None @gtk_threadsafe def _wait_for_gui(): self.wait_for_gui_process() # Get current video settings from UI. app_values = self.get_app_values() # Convert JSON settings to 0MQ plugin API Python types. ui_settings = self.json_settings_as_python(app_values) self.set_ui_settings(ui_settings, default_corners=True) self.gui_heartbeat_id = gobject.timeout_add(1000, keep_alive) # Refresh list of electrode and route commands. hub_execute('microdrop.command_plugin', 'get_commands') # Call as thread-safe function, since function uses GTK. _wait_for_gui()