Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
def initialize_environment_gui(gui_config=None, runtime_config=None):

    from rafcon.gui.config import global_gui_config
    from rafcon.gui.runtime_config import global_runtime_config
    global GUI_INITIALIZED

    if GUI_INITIALIZED:
        raise DeprecationWarning("Deprecated use of environment initialization. The gui was already initialized.")

    # initialize global gui config
    if isinstance(gui_config, tuple) and exists(join(gui_config[1], gui_config[0])):
        global_gui_config.load(gui_config[1], gui_config[0])
    else:
        global_gui_config.load(path=RAFCON_TEMP_PATH_CONFIGS)
        if isinstance(gui_config, dict):
            for key, value in gui_config.items():
                global_gui_config.set_config_value(key, value)

    # initialize global runtime config
    if isinstance(runtime_config, tuple) and exists(join(runtime_config[1], runtime_config[0])):
        global_runtime_config.load(runtime_config[1], runtime_config[0])
    else:
        global_runtime_config.load(path=RAFCON_TEMP_PATH_CONFIGS)
        if isinstance(runtime_config, dict):
            for key, value in runtime_config.items():
                global_runtime_config.set_config_value(key, value)

    GUI_INITIALIZED = True
Ejemplo n.º 3
0
    def redock_sidebar(self,
                       window_key,
                       sidebar_name,
                       controller_name,
                       widget,
                       event=None):
        """Redock/embed sidebar into main window

        The size & position of the open window are saved to the runtime_config file, the sidebar is redocked back
        to the main-window, and the left-bar window is hidden. The undock button of the bar is made visible again.
        """
        config_parameter_undocked = window_key + '_WINDOW_UNDOCKED'
        config_id_for_pane_position = window_key + '_DOCKED_POS'
        undocked_window_name = window_key.lower() + '_window'
        widget_name = window_key.lower()
        undocked_window_view = getattr(self.view, undocked_window_name)

        self.view['main_window'].disconnect(
            self.handler_ids[undocked_window_name]['state'])
        getattr(self, 'on_{}_return_clicked'.format(widget_name))(None)

        undocked_window_view['central_eventbox'].remove(self.view[widget_name])
        self.view[sidebar_name].pack_start(self.view[widget_name], True, True,
                                           0)

        self.get_controller(controller_name).hide_window()
        self.view['undock_{}_button'.format(widget_name)].show()

        # restore the position of the pane
        self.set_pane_position(config_id_for_pane_position)

        global_runtime_config.set_config_value(config_parameter_undocked,
                                               False)
        return True
Ejemplo n.º 4
0
 def on_show_aborted_preempted_toggled(widget, data=None):
     if widget.get_active():
         global_runtime_config.set_config_value("SHOW_ABORTED_PREEMPTED",
                                                True)
     else:
         global_runtime_config.set_config_value("SHOW_ABORTED_PREEMPTED",
                                                False)
Ejemplo n.º 5
0
    def prepare_destruction(self):
        """Saves current configuration of windows and panes to the runtime config file, before RAFCON is closed."""
        plugins.run_hook("pre_destruction")

        logger.debug("Saving runtime config to {0}".format(
            global_runtime_config.config_file_path))

        # store pane last positions
        for key, widget_name in constants.PANE_ID.items():
            global_runtime_config.store_widget_properties(
                self.view[widget_name], key.replace('_POS', ''))

        # store hidden or undocked widget flags correctly -> make them independent for restoring
        for window_key in constants.UNDOCKABLE_WINDOW_KEYS:
            hidden = False
            if not global_runtime_config.get_config_value(window_key +
                                                          "_WINDOW_UNDOCKED"):
                hidden = getattr(self, window_key.lower() + '_hidden')
            global_runtime_config.set_config_value(window_key + '_HIDDEN',
                                                   hidden)

        global_runtime_config.save_configuration()

        # state-editor will relieve it's model => it won't observe the state machine manager any more
        self.get_controller('states_editor_ctrl').prepare_destruction(
        )  # avoid new state editor TODO tbd (deleted)
        rafcon.core.singleton.state_machine_manager.delete_all_state_machines()
        rafcon.core.singleton.library_manager.prepare_destruction()

        # Recursively destroys the main window
        self.destroy()
        from rafcon.gui.clipboard import global_clipboard
        global_clipboard.destroy()
        gui_singletons.main_window_controller = None
Ejemplo n.º 6
0
 def on_show_data_values_toggled(widget, data=None):
     if widget.get_active():
         global_runtime_config.set_config_value(
             "SHOW_DATA_FLOW_VALUE_LABELS", True)
     else:
         global_runtime_config.set_config_value(
             "SHOW_DATA_FLOW_VALUE_LABELS", False)
Ejemplo n.º 7
0
    def redock_sidebar(self,
                       window_key,
                       sidebar_name,
                       replacement_name,
                       controller_name,
                       widget,
                       event=None):
        """Redock/embed sidebar into main window

        The size & position of the open window are saved to the runtime_config file, the sidebar is redocked back
        to the main-window, and the left-bar window is hidden. The undock button of the bar is made visible again.
        """
        config_parameter_undocked = window_key + '_WINDOW_UNDOCKED'
        undocked_window_name = window_key.lower() + '_window'
        widget_name = window_key.lower()

        self.view['main_window'].disconnect(
            self.handler_ids[undocked_window_name]['state'])
        getattr(self, 'on_{}_return_clicked'.format(widget_name))(None)
        self.view[widget_name].reparent(self.view[sidebar_name])
        self.get_controller(controller_name).hide_window()
        self.view['undock_{}_button'.format(widget_name)].show()
        if replacement_name:
            self.view[replacement_name].hide()
        global_runtime_config.set_config_value(config_parameter_undocked,
                                               False)
        return True
Ejemplo n.º 8
0
def create_folder(query, default_name=None, default_path=None):
    """Shows a user dialog for folder creation
    
    A dialog is opened with the prompt `query`. The current path is set to the last path that was opened/created. The 
    roots of all libraries is added to the list of shortcut folders.
    
    :param str query: Prompt asking the user for a specific folder
    :param str default_name: Default name of the folder to be created 
    :param str default_path: Path in which the folder is created if the user doesn't specify a path 
    :return: Path created by the user or `default_path`\`default_name` if no path was specified or None if none of the
      paths is valid
    :rtype: str
    """
    from os.path import expanduser, dirname, join, exists, isdir
    from rafcon.core.storage.storage import STATEMACHINE_FILE
    last_path = global_runtime_config.get_config_value('LAST_PATH_OPEN_SAVE',
                                                       "")

    if last_path and isdir(last_path) and not exists(
            join(last_path, STATEMACHINE_FILE)):
        pass
    elif last_path:
        last_path = dirname(last_path)
    else:
        last_path = expanduser('~')

    dialog = gtk.FileChooserDialog(query, None,
                                   gtk.FILE_CHOOSER_ACTION_CREATE_FOLDER,
                                   (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                    gtk.STOCK_SAVE, gtk.RESPONSE_OK))
    # Allows confirming with Enter and double-click
    dialog.set_default_response(gtk.RESPONSE_OK)
    if main_window_controller:
        dialog.set_transient_for(main_window_controller.view.get_top_widget())
    dialog.set_current_folder(last_path)
    if default_name:
        dialog.set_current_name(default_name)
    dialog.set_show_hidden(False)

    # Add library roots to list of shortcut folders
    add_library_root_path_to_shortcut_folders_of_dialog(dialog)

    response = dialog.run()

    if response != gtk.RESPONSE_OK:
        dialog.destroy()
        if default_path and default_name:
            default = os.path.join(default_path, default_name)
            if os.path.isdir(default):
                return default
        return None

    path = dialog.get_filename()
    dialog.destroy()

    if os.path.isdir(path):
        global_runtime_config.set_config_value('LAST_PATH_OPEN_SAVE', path)
        return path
    return None
Ejemplo n.º 9
0
def open_folder(query, default_path=None):
    """Shows a user dialog for folder selection
    
    A dialog is opened with the prompt `query`. The current path is set to the last path that was opened/created. The 
    roots of all libraries is added to the list of shortcut folders.
    
    :param str query: Prompt asking the user for a specific folder
    :param str default_path: Path to use if user does not specify one 
    :return: Path selected by the user or `default_path` if no path was specified or None if none of the paths is valid
    :rtype: str
    """
    from gi.repository import Gtk
    from os.path import expanduser, pathsep, dirname, isdir
    from rafcon.gui.singleton import main_window_controller
    from rafcon.gui.runtime_config import global_runtime_config
    last_path = global_runtime_config.get_config_value('LAST_PATH_OPEN_SAVE',
                                                       "")
    selected_filename = None
    if last_path and isdir(last_path):
        selected_filename = last_path.split(pathsep)[-1]
        last_path = dirname(last_path)
    else:
        last_path = expanduser('~')

    dialog = Gtk.FileChooserDialog(title=query,
                                   transient_for=None,
                                   action=Gtk.FileChooserAction.SELECT_FOLDER)
    dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                       Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
    # Allows confirming with Enter and double-click
    dialog.set_default_response(Gtk.ResponseType.OK)
    if main_window_controller:
        dialog.set_transient_for(
            main_window_controller.view.get_parent_widget())
    dialog.set_current_folder(last_path)
    if selected_filename is not None:
        dialog.select_filename(selected_filename)

    dialog.set_show_hidden(False)

    # Add library roots to list of shortcut folders
    add_library_root_path_to_shortcut_folders_of_dialog(dialog)

    response = dialog.run()

    if response != Gtk.ResponseType.OK:
        dialog.destroy()
        if default_path and os.path.isdir(default_path):
            return default_path
        return None

    path = dialog.get_filename()
    dialog.destroy()

    if os.path.isdir(path):
        global_runtime_config.set_config_value('LAST_PATH_OPEN_SAVE', path)
        return path
    return None
Ejemplo n.º 10
0
    def prepare_destruction(self):
        """Saves current configuration of windows and panes to the runtime config file, before RAFCON is closed."""
        plugins.run_hook("pre_destruction")

        logger.debug("Saving runtime config to {0}".format(
            global_runtime_config.config_file_path))

        # store pane last positions
        for key, widget_name in constants.PANE_ID.items():
            global_runtime_config.store_widget_properties(
                self.view[widget_name], key.replace('_POS', ''))

        # store hidden or undocked widget flags correctly -> make them independent for restoring
        for window_key in constants.UNDOCKABLE_WINDOW_KEYS:
            hidden = False
            if not global_runtime_config.get_config_value(window_key +
                                                          "_WINDOW_UNDOCKED"):
                hidden = getattr(self, window_key.lower() + '_hidden')
            global_runtime_config.set_config_value(window_key + '_HIDDEN',
                                                   hidden)

        global_runtime_config.save_configuration()

        # state-editor will relieve it's model => it won't observe the state machine manager any more
        self.get_controller('states_editor_ctrl').prepare_destruction(
        )  # avoid new state editor TODO tbd (deleted)
        rafcon.core.singleton.state_machine_manager.delete_all_state_machines()
        rafcon.core.singleton.library_manager.prepare_destruction()

        # gtkmvc installs a global glade custom handler that holds a reference to the last created View class,
        # preventing it from being destructed. By installing a dummy callback handler, after all views have been
        # created, the old handler is being removed and with it the reference, allowing all Views to be destructed.

        # Gtk TODO: check if necessary and search for replacement
        # try:
        #     from gtk import glade
        #     def dummy(*args, **kwargs):
        #         pass
        #     glade.set_custom_handler(dummy)
        # except ImportError:
        #     pass

        # Recursively destroys the main window
        self.destroy()
        from rafcon.gui.clipboard import global_clipboard
        global_clipboard.destroy()
        gui_singletons.main_window_controller = None
Ejemplo n.º 11
0
 def on_data_flow_mode_toggled(widget, data=None):
     if widget.get_active():
         global_runtime_config.set_config_value("DATA_FLOW_MODE", True)
     else:
         global_runtime_config.set_config_value("DATA_FLOW_MODE", False)
Ejemplo n.º 12
0
def create_folder(query,
                  default_name=None,
                  default_path=None,
                  current_folder=None):
    """Shows a user dialog for folder creation
    
    A dialog is opened with the prompt `query`. The current path is set to the last path that was opened/created. The 
    roots of all libraries is added to the list of shortcut folders.
    
    :param str query: Prompt asking the user for a specific folder
    :param str default_name: Default name of the folder to be created 
    :param str default_path: Path in which the folder is created if the user doesn't specify a path
    :param str current_folder: Current folder that the FileChooserDialog points to in the beginning
    :return: Path created by the user or `default_path`/`default_name` if no path was specified or None if none of the
      paths is valid
    :rtype: str
    """
    from gi.repository import Gtk
    from os.path import expanduser, dirname, join, exists, isdir
    from rafcon.core.storage.storage import STATEMACHINE_FILE
    from rafcon.gui.singleton import main_window_controller
    from rafcon.gui.runtime_config import global_runtime_config
    last_path = global_runtime_config.get_config_value('LAST_PATH_OPEN_SAVE',
                                                       "")

    if last_path and isdir(last_path) and not exists(
            join(last_path, STATEMACHINE_FILE)):
        pass
    elif last_path:
        last_path = dirname(last_path)
    else:
        last_path = expanduser('~')

    dialog = Gtk.FileChooserDialog(title=query,
                                   transient_for=None,
                                   action=Gtk.FileChooserAction.CREATE_FOLDER)
    dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                       Gtk.STOCK_OPEN, Gtk.ResponseType.OK)
    # dialog.add_buttons(Gtk.ButtonsType.OK_CANCEL)
    # Allows confirming with Enter and double-click
    dialog.set_default_response(Gtk.ResponseType.OK)
    if main_window_controller:
        dialog.set_transient_for(
            main_window_controller.view.get_parent_widget())
    dialog.set_current_folder(last_path)
    if current_folder:
        dialog.set_current_folder(current_folder)
    if default_name:
        dialog.set_current_name(default_name)
    dialog.set_show_hidden(False)

    # Add library roots to list of shortcut folders
    add_library_root_path_to_shortcut_folders_of_dialog(dialog)

    response = dialog.run()

    if response != Gtk.ResponseType.OK:
        dialog.destroy()
        if default_path and default_name:
            default = os.path.join(default_path, default_name)
            if os.path.isdir(default):
                return default
        return None

    path = dialog.get_filename()
    dialog.destroy()

    if os.path.isdir(path):
        global_runtime_config.set_config_value('LAST_PATH_OPEN_SAVE', path)
        return path
    return None
Ejemplo n.º 13
0
 def on_show_transitions_toggled(widget, data=None):
     if widget.get_active():
         global_runtime_config.set_config_value("SHOW_TRANSITIONS", True)
     else:
         global_runtime_config.set_config_value("SHOW_TRANSITIONS", False)