def undock_sidebar(self, window_key, widget=None, event=None): """Undock/separate sidebar into independent window The sidebar is undocked and put into a separate new window. The sidebar is hidden in the main-window by triggering the method on_[widget_name]_hide_clicked(). Triggering this method shows the [widget_name]_return_button in the main-window, which does not serve any purpose when the bar is undocked. This button is therefore deliberately hidden. The undock button, which is also part of the sidebar is hidden, because the re-dock button is included in the top_tool_bar of the newly opened window. Not hiding it will result in two re-dock buttons visible in the new window. The new window size and position are loaded from runtime_config, if they exist. """ undocked_window_name = window_key.lower() + '_window' widget_name = window_key.lower() undocked_window_view = getattr(self.view, undocked_window_name) undocked_window = undocked_window_view.get_top_widget() if os.getenv("RAFCON_START_MINIMIZED", False): undocked_window.iconify() gui_helper_label.set_window_size_and_position(undocked_window, window_key) self.view[widget_name].reparent( undocked_window_view['central_eventbox']) self.view['undock_{}_button'.format(widget_name)].hide() getattr(self, 'on_{}_hide_clicked'.format(widget_name))(None) self.view['{}_return_button'.format(widget_name)].hide() main_window = self.view.get_top_widget() state_handler = main_window.connect('window-state-event', self.undock_window_callback, undocked_window) self.handler_ids[undocked_window_name] = {"state": state_handler} undocked_window.set_transient_for(main_window) main_window.grab_focus() global_runtime_config.set_config_value(window_key + '_WINDOW_UNDOCKED', True)
def register_view(self, view): super(MainWindowController, self).register_view(view) self.register_actions(self.shortcut_manager) self.view.get_top_widget().connect("key-press-event", self._on_key_press) self.view.get_top_widget().connect("key-release-event", self._on_key_release) # using helper function to connect functions to GUI elements to be able to access the handler id later on self.connect_button_to_function( 'main_window', "delete_event", self.get_controller('menu_bar_controller').on_quit_activate) # connect left bar, right bar and console hide buttons' signals to their corresponding methods self.connect_button_to_function('left_bar_hide_button', "clicked", self.on_left_bar_hide_clicked) self.connect_button_to_function('right_bar_hide_button', "clicked", self.on_right_bar_hide_clicked) self.connect_button_to_function('console_hide_button', "clicked", self.on_console_hide_clicked) # Connect left bar, right bar and console return buttons' signals to their corresponding methods self.connect_button_to_function('left_bar_return_button', "clicked", self.on_left_bar_return_clicked) self.connect_button_to_function('right_bar_return_button', "clicked", self.on_right_bar_return_clicked) self.connect_button_to_function('console_return_button', "clicked", self.on_console_return_clicked) # Connect undock buttons signals for window_key in constants.UNDOCKABLE_WINDOW_KEYS: self.connect_button_to_function( 'undock_{}_button'.format(window_key.lower()), "clicked", partial(self.undock_sidebar, window_key)) # Connect collapse button for trees self.connect_button_to_function('collapse_tree_button', "clicked", self.on_collapse_button_clicked) # Connect Shortcut buttons' signals to their corresponding methods self.connect_button_to_function('button_start_shortcut', "toggled", self.on_button_start_shortcut_toggled) self.connect_button_to_function('button_stop_shortcut', "clicked", self.on_button_stop_shortcut_clicked) self.connect_button_to_function('button_pause_shortcut', "toggled", self.on_button_pause_shortcut_toggled) self.connect_button_to_function( 'button_start_from_shortcut', "clicked", self.on_button_start_from_shortcut_clicked) self.connect_button_to_function('button_run_to_shortcut', "clicked", self.on_button_run_to_shortcut_clicked) self.connect_button_to_function( 'button_step_mode_shortcut', "toggled", self.on_button_step_mode_shortcut_toggled) self.connect_button_to_function( 'button_step_in_shortcut', "clicked", self.on_button_step_in_shortcut_clicked) self.connect_button_to_function( 'button_step_over_shortcut', "clicked", self.on_button_step_over_shortcut_clicked) self.connect_button_to_function( 'button_step_out_shortcut', "clicked", self.on_button_step_out_shortcut_clicked) self.connect_button_to_function( 'button_step_backward_shortcut', "clicked", self.on_button_step_backward_shortcut_clicked) view['upper_notebook'].connect('switch-page', self.on_notebook_tab_switch, view['upper_notebook_title'], view.left_bar_window, 'upper') view['lower_notebook'].connect('switch-page', self.on_notebook_tab_switch, view['lower_notebook_title'], view.left_bar_window, 'lower') view.get_top_widget().connect("configure-event", self.update_widget_runtime_config, "MAIN_WINDOW") view.left_bar_window.get_top_widget().connect( "configure-event", self.update_widget_runtime_config, "LEFT_BAR_WINDOW") view.right_bar_window.get_top_widget().connect( "configure-event", self.update_widget_runtime_config, "RIGHT_BAR_WINDOW") view.console_window.get_top_widget().connect( "configure-event", self.update_widget_runtime_config, "CONSOLE_WINDOW") # save pane positions in the runtime config on every change view['top_level_h_pane'].connect("button-release-event", self.update_widget_runtime_config, "LEFT_BAR_DOCKED") view['right_h_pane'].connect("button-release-event", self.update_widget_runtime_config, "RIGHT_BAR_DOCKED") view['central_v_pane'].connect("button-release-event", self.update_widget_runtime_config, "CONSOLE_DOCKED") # hide not usable buttons self.view['step_buttons'].hide() # Initializing Main Window Size & Position # secure un maximize in initial condition to restore correct position and size view.get_top_widget().unmaximize() gui_helper_label.set_window_size_and_position(view.get_top_widget(), 'MAIN') wait_for_gui() # Initializing Pane positions for config_id in constants.PANE_ID: self.set_pane_position(config_id) # set the hidden status of all bars for window_key in constants.UNDOCKABLE_WINDOW_KEYS: if global_runtime_config.get_config_value(window_key + '_HIDDEN'): func = getattr(self, 'on_{}_hide_clicked'.format(window_key.lower())) func(None) # restore undock state of bar windows if gui_config.get_config_value("RESTORE_UNDOCKED_SIDEBARS"): for window_key in constants.UNDOCKABLE_WINDOW_KEYS: if global_runtime_config.get_config_value(window_key + "_WINDOW_UNDOCKED"): self.undock_sidebar(window_key) # secure maximized state if global_runtime_config.get_config_value("MAIN_WINDOW_MAXIMIZED"): wait_for_gui() view.get_top_widget().maximize() # check for auto backups if gui_config.get_config_value( 'AUTO_BACKUP_ENABLED') and gui_config.get_config_value( 'AUTO_RECOVERY_CHECK'): import rafcon.gui.models.auto_backup as auto_backup auto_backup.check_for_crashed_rafcon_instances() plugins.run_hook("main_window_setup", self) wait_for_gui() # Ensure that the next message is being printed (needed for LN manager to detect finished startup) level = logger.level logger.setLevel(logging.INFO) logger.info("Ready") logger.setLevel(level)