diff --git a/Ccs/ccs_function_lib.py b/Ccs/ccs_function_lib.py index 1636911d3e940aae68d3cfbfefb9279d3dda541b..05b7344c3286747180341f01e1367190577f8660 100644 --- a/Ccs/ccs_function_lib.py +++ b/Ccs/ccs_function_lib.py @@ -1757,6 +1757,49 @@ def get_module_handle(module_name, instance=1, timeout=5): return False +def _get_ccs_dbus_names(exclude=None): + if exclude is None: + exclude = [] + + dbus_names = dbus.SessionBus().list_names() + ccs_names = [cfg['ccs-dbus_names'][mod] for mod in cfg['ccs-dbus_names'] if mod not in exclude] + ccs_modules = [mod for mod in dbus_names if mod.startswith(tuple(ccs_names))] + + return ccs_modules + + +def _quit_module(module_name, instance=1): + mod = get_module_handle(module_name, instance=instance) + + if not mod: + logger.error('{}{} not found on DBus').format(module_name, instance) + return False + + try: + mod.Functions('quit_func') + return True + except Exception as err: + logger.exception(err) + return False + + +def _close_modules(): + dbus_names = _get_ccs_dbus_names(exclude=['editor']) + while dbus_names: + print(dbus_names) + for module in dbus_names: + _, name, iid = module.split('.') + success = _quit_module(name, int(iid.replace('communication', ''))) + if success: + logger.info('Closed {}'.format(module)) + else: + logger.error('Could not close {}'.format(module)) + + dbus_names = _get_ccs_dbus_names(exclude=['editor']) + + logger.info('Closed all modules') + + def connect(pool_name, host, port, protocol='PUS', is_server=False, timeout=10, delete_abandoned=False, try_delete=True, pckt_filter=None, options='', drop_rx=False, drop_tx=False): """ diff --git a/Ccs/editor.py b/Ccs/editor.py index 01944da4c5d9d03b1bf96c8d21e748915eda5c29..d163dc5d2f0d7d803e2c88e2ebda900306c5b39a 100644 --- a/Ccs/editor.py +++ b/Ccs/editor.py @@ -173,8 +173,10 @@ class CcsEditor(Gtk.Window): self.grid.attach(toolbar, 0, 1, 2, 1) self.search_context = None - self.editor_notebook = Gtk.Notebook(scrollable=True) + self.editor_notebook = Gtk.Notebook() + self.editor_notebook.set_scrollable(True) self.editor_notebook.connect('switch-page', self._set_search_context) + self.searchbar = self.create_searchbar() self.grid.attach(self.searchbar, 0, 2, 3, 1) @@ -226,7 +228,6 @@ class CcsEditor(Gtk.Window): self.connect("delete-event", self.quit_func) # self.connect("delete-event", self.tcpserver_shutdown) self.connect('key-press-event', self.key_pressed) - # self.open_file("startpv.py") self.show_all() def timeout(self, sec): @@ -409,9 +410,9 @@ class CcsEditor(Gtk.Window): self.ipython_view.connect("size-allocate", self.console_autoscroll, self.ipython_view) - self.ed_host, self.ed_port = self.cfg.get('ccs-misc', 'editor_host'), int(self.cfg.get('ccs-misc', 'editor_ul_port')) # Get standart port + self.ed_host, self.ed_port = self.cfg.get('ccs-misc', 'editor_host'), int(self.cfg.get('ccs-misc', 'editor_ul_port')) # Get standard port - # Connect to standart port if possible otherwise use a random alternative + # Connect to standard port if possible otherwise use a random alternative try: self.setup_editor_socket(self.ed_host, self.ed_port) except OSError: @@ -857,6 +858,7 @@ class CcsEditor(Gtk.Window): sourceview = self.create_textview(filename) self.editor_notebook.append_page(sourceview, hbox) + self.editor_notebook.set_tab_reorderable(sourceview, True) button.connect("clicked", self._notebook_close_tab, sourceview) @@ -1452,12 +1454,30 @@ class CcsEditor(Gtk.Window): about_button.connect("clicked", self._on_select_about_dialog) vbox.pack_start(about_button, True, True, 10) + # Add the close modules button + kill_button = Gtk.Button.new_with_label('Close modules') + kill_button.connect("clicked", self._close_modules_cmd) + vbox.pack_start(kill_button, True, True, 0) + self.popover.add(vbox) self.popover.set_position(Gtk.PositionType.BOTTOM) self.popover.set_relative_to(univie_button) return univie_box + def _close_modules_cmd(self, *args): + dialog = Gtk.MessageDialog() + dialog.add_buttons(Gtk.STOCK_NO, Gtk.ResponseType.NO, Gtk.STOCK_YES, Gtk.ResponseType.YES,) + dialog.set_markup('<b>Close all modules?</b>') + response = dialog.run() + if response == Gtk.ResponseType.YES: + dialog.destroy() + else: + dialog.destroy() + return + + self._to_console('cfl._close_modules()') + def on_univie_button(self, action): """ Adds the Popover menu to the UNIVIE Button