Example #1
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.iteritems():
            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()

        # close all tabs
        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.
        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
Example #2
0
    try:
        __import__(module)
    except Exception, e:
        raise RuntimeError('Failed to load module %s: %s' % (module, e))

    try:
        w = eval(code, sys.modules[module].__dict__)
    except Exception, e:
        raise RuntimeError('Failed call %s in module %s: %s' %
                           (code, module, e))
    w.set_name(name)
    w.show()
    return w


set_custom_handler(flumotion_glade_custom_handler)


class GladeWidget(gtk.VBox):
    '''
    Base class for composite widgets backed by glade interface definitions.

    Example:
    class MyWidget(GladeWidget):
        glade_file = 'my_glade_file.glade'
        ...

    Remember to chain up if you customize __init__().
    '''

    glade_dir = os.path.dirname(os.path.abspath(__file__))
Example #3
0
        mod, attr = proc.rsplit(".", 1)
        raise RuntimeError(
            "There is no widget called %r in module %s" % (
            attr, mod))

    widget = widget_class()
    widget.set_name(name)

    # Normal properties are not parsed for Custom widgets,
    # showing all non-window ones by default is probably a good idea
    if not isinstance(widget, gtk.Window):
        widget.show()

    return widget

glade.set_custom_handler(_flumotion_glade_custom_handler)


class GladeBacked(GladeDelegate):
    """
    Base class for objects backed by glade interface definitions.
    The glade file should have exactly one Window.

    @ivar gladeFile:     filename of glade file containing the interface
    @type gladeFile:     str
    @ivar gladeTypedict: GTK widget class name -> replacement widget class
                          see L{flumotion.ui.fgtk.ProxyWidgetMapping}
    @type gladeTypedict: dict of str -> class
    @ivar widgets:        widget name -> Widget
    @type widgets:        str -> gtk.Widget
    """
Example #4
0
    def __init__(self, glade=None, top=None,
                 parent=None, 
                 builder=None):
        """
        Only the first three may be given as positional arguments. If an
        argument is empty a class attribute of the same name is used. This
        does not work for *parent*.

        *glade* is a path to an XML file defining widgets in libglade format.
        
           .. deprecated:: 1.99.1

        *builder* is a path to an XML file defining widgets in GtkBuilder
        format.

           .. versionadded:: 1.99.1

        *top* is a string or a list of strings containing the names of our top
        level widgets. When using libglade only their children are loaded.

        *parent* is used to call :meth:`set_parent_view`.

        The last two only work if *glade* or *builder* are used, not if you
        intend to create widgets later from code.

        .. deprecated:: 1.99.1
           In future versions the functionality will be split into the new class
           :class:`ManualView` and its child :class:`BuilderView`.
        """
        if isinstance(glade, Controller):
            raise NotImplementedError("This version of GTKMVC does not"
                " support the 1.2 API")
        if isinstance(builder, Controller):
            raise NotImplementedError("This version of GTKMVC does not"
                " support the 1.99.0 API")
        if parent and not isinstance(parent, View):
            raise NotImplementedError("This version of GTKMVC does not"
                " support the unreleased first GtkBuilder API")

        self.manualWidgets = {}
        self.autoWidgets = {}
        self.__autoWidgets_calculated = False
        
        self.glade_xmlWidgets = []
        
        # Sets a callback for custom widgets
        if __glade_is_available__:
            gtkglade.set_custom_handler(self._custom_widget_create)
            pass

        if top: _top = top
        else: _top = self.top
        if type(_top) == types.StringType or _top is None:
            wids = (_top,)
        else: wids = _top  # Already a list or tuple

        # retrieves XML objects from glade
        if glade: _glade = glade
        else: _glade = self.glade

        if _glade is not None:
            if not __glade_is_available__:
                raise ViewError("Module gtk.glade was required, but not available")
            for wid in wids:
                self.glade_xmlWidgets.append(gtkglade.XML(_glade, wid))
                pass
            pass

        # retrieves objects from builder if available
        if builder: _builder = builder
        else: _builder = self.builder
        if _builder is not None:
            if not __builder_is_available__:
                raise ViewError("gtk.Builder was used, but is not available")

            # if the user passed a Builder, use it as it is, otherwise
            # build one
            if isinstance(_builder, gtk.Builder):
                self._builder = _builder
            else:
                self._builder = gtk.Builder()
                self._builder.add_from_file(_builder)
                pass
            pass
        else: self._builder = None # no gtk builder
            
        # top widget list or singleton:
        if _top is not None:
            if len(wids) > 1:
                self.m_topWidget = []
                for i in range(0, len(wids)):
                    self.m_topWidget.append(self[wids[i]])
                    pass
            else: self.m_topWidget = self[wids[0]]
        else:  self.m_topWidget = None
       
        if parent is not None: self.set_parent_view(parent)

        return
Example #5
0
    module, code = parse_proc(proc)
    try:
        __import__(module)
    except Exception, e:
        raise RuntimeError('Failed to load module %s: %s' % (module, e))

    try:
        w = eval(code, sys.modules[module].__dict__)
    except Exception, e:
        raise RuntimeError('Failed call %s in module %s: %s'
                           % (code, module, e))
    w.set_name(name)
    w.show()
    return w
set_custom_handler(flumotion_glade_custom_handler)


class GladeWidget(gtk.VBox):
    '''
    Base class for composite widgets backed by glade interface definitions.

    Example:
    class MyWidget(GladeWidget):
        glade_file = 'my_glade_file.glade'
        ...

    Remember to chain up if you customize __init__().
    '''

    glade_dir = os.path.dirname(os.path.abspath(__file__))
Example #6
0
        mod, attr = proc.rsplit(".", 1)
        raise RuntimeError("There is no widget called %r in module %s" %
                           (attr, mod))

    widget = widget_class()
    widget.set_name(name)

    # Normal properties are not parsed for Custom widgets,
    # showing all non-window ones by default is probably a good idea
    if not isinstance(widget, gtk.Window):
        widget.show()

    return widget


glade.set_custom_handler(_flumotion_glade_custom_handler)


class GladeBacked(GladeDelegate):
    """
    Base class for objects backed by glade interface definitions.
    The glade file should have exactly one Window.

    @ivar gladeFile:     filename of glade file containing the interface
    @type gladeFile:     str
    @ivar gladeTypedict: GTK widget class name -> replacement widget class
                          see L{flumotion.ui.fgtk.ProxyWidgetMapping}
    @type gladeTypedict: dict of str -> class
    @ivar widgets:        widget name -> Widget
    @type widgets:        str -> gtk.Widget
    """