예제 #1
0
파일: uim.py 프로젝트: dsaran/packagehelper
    def update_ui(self, gadget, xml, ui_name='initial-state'):
        """Update the ui definition of gadget with name ui_name"""


        # save the parent and the packing props before changing the uim
        old_widget = gadget.widget
        parent = old_widget.get_parent()
        if parent:
            props = {}
            ptype = type(parent)
            for pspec in gtk.container_class_list_child_properties(ptype):
                props[pspec.name] = parent.child_get_property(old_widget,
                                                              pspec.name)

            parent.remove(old_widget)

        # update the ui manager
        old_merge_id = self._uis[gadget][ui_name][1]
        self._uim.remove_ui(old_merge_id)
        new_merge_id = self._uim.add_ui_from_string(xml)

        self._uis[gadget][ui_name] = (xml, new_merge_id)

        # update the gtk widget of gadget
        new_widget = self.get_widget(gadget)

        # copy the packing properties to the new widget
        if parent:
            parent.add(new_widget)

            for name, value in props.items():
                parent.child_set_property(new_widget, name, value)

        # finish widget configuration
        gadget.setup_widget(new_widget)
예제 #2
0
def get_child_pspec_from_name(gtype, name):
    if gtk.pygtk_version < (2, 10, 0):
        pspecs = gtk.container_class_list_child_properties(gtype)
    else:
        pspecs = gtype.list_child_properties()

    for pspec in pspecs:
        if pspec.name == name:
            return pspec
예제 #3
0
    def _write_child_properties(self, owner_node, owner):
        doc = self._doc

        # TODO: we need a smart property fetcher here
        parent = owner.get_parent()
        properties = gtk.container_class_list_child_properties(parent)

        for prop in self._filter_properties(properties):
            node = self._property_to_xml(owner, prop, 'child')
            owner_node.appendChild(node)
예제 #4
0
 def _write_child_properties(self, owner_node, owner):
     doc = self._doc
     
     # TODO: we need a smart property fetcher here
     parent = owner.get_parent()
     properties = gtk.container_class_list_child_properties(parent)
     
     for prop in self._filter_properties(properties):
         node = self._property_to_xml(owner, prop, 'child')
         owner_node.appendChild(node)
예제 #5
0
    def update_ui(self, gadget, xml, ui_name='initial-state',
                  refresh_widget=True):
        """Update the ui definition of gadget with name ui_name

        If the argument refresh_widget is True the gtk widget associated
        with gadget is created again with the new ui and the gadget is
        updated with this new widget
        """

        project = gadget.project
        if refresh_widget:
            # save the parent and the packing props before changing the uim
            old_widget = gadget.widget
            parent = old_widget.get_parent()
            if parent:
                props = {}
                ptype = type(parent)
                for pspec in gtk.container_class_list_child_properties(ptype):
                    props[pspec.name] = parent.child_get_property(old_widget,
                                                                  pspec.name)

                parent.remove(old_widget)

                # Update project. We have to check if the widget is still in
                # the project to play nice with widget name changes
                if project.get_gadget_by_name(old_widget.get_name()):
                    project.remove_widget(old_widget)

        # update the ui manager
        old_merge_id = self._uis[gadget][ui_name][1]
        self._uim.remove_ui(old_merge_id)
        self._uim.ensure_update()
        new_merge_id = self._uim.add_ui_from_string(xml)
        self._uis[gadget][ui_name] = (xml, new_merge_id)

        if refresh_widget:
            # update the gtk widget of gadget
            new_widget = self.get_widget(gadget)

            # copy the packing properties to the new widget
            if parent:
                parent.add(new_widget)

                for name, value in props.items():
                    parent.child_set_property(new_widget, name, value)

            # finish widget configuration
            gadget.setup_widget(new_widget)

            # Update project
            project.add_widget(new_widget)
예제 #6
0
def replace_widget(current, new):
    """
    Replace one widget with another.
    'current' has to be inside a container (e.g. gtk.VBox).
    """
    container = current.parent
    assert container # is "current" inside a container widget?

    # stolen from gazpacho code (widgets/base/base.py):
    props = {}
    for pspec in gtk.container_class_list_child_properties(container):
        props[pspec.name] = container.child_get_property(current, pspec.name)

    gtk.Container.remove(container, current)
    container.add(new)

    for name, value in props.items():
        container.child_set_property(new, name, value)
예제 #7
0
    def _replace_widget(self):
        # This will remove the entry, add a hbox in the entry old position, and
        # reattach the entry to this box. The box will then be used to add two
        # new buttons (one for searching, other for editing/adding new objects
        container = self.entry.parent

        # stolen from gazpacho code (widgets/base/base.py):
        props = {}
        for pspec in gtk.container_class_list_child_properties(container):
            props[pspec.name] = container.child_get_property(self.entry, pspec.name)

        self.box = gtk.HBox()
        self.box.show()
        self.entry.reparent(self.box)
        container.add(self.box)

        for name, value in props.items():
            container.child_set_property(self.box, name, value)
예제 #8
0
    def _replace_widget(self):
        # This will remove the entry, add a hbox in the entry old position, and
        # reattach the entry to this box. The box will then be used to add two
        # new buttons (one for searching, other for editing/adding new objects
        container = self._entry.parent

        # stolen from gazpacho code (widgets/base/base.py):
        props = {}
        for pspec in gtk.container_class_list_child_properties(container):
            props[pspec.name] = container.child_get_property(self._entry, pspec.name)

        self.box = gtk.HBox()
        self.box.show()
        self._entry.reparent(self.box)
        container.add(self.box)

        for name, value in props.items():
            container.child_set_property(self.box, name, value)
예제 #9
0
    def _list_properties(self, type_name):
        "List all properties for type_name, and use a simple cache"
        pspecs = self._pspec_cache.get(type_name, [])
        if pspecs:
            return pspecs

        try:
            if self.child:
                pspecs = gtk.container_class_list_child_properties(type_name)
            else:
                pspecs = gobject.list_properties(type_name)
        except TypeError:
            raise PropertyError("Unknown GType name: %s" % type_name)
        pspecs = list(pspecs)

        self._pspec_cache[type_name] = pspecs

        return pspecs
예제 #10
0
def get_child_property_type(owner, name):
    parent = owner.get_property('parent')
    for property in gtk.container_class_list_child_properties(parent):
        if property.name == name:
            return gobject.type_name(property)
    raise TypeError