Exemplo n.º 1
0
def auto_connect_by_name(callback_obj, builder):
    '''finds handlers like on_<widget_name>_<signal> and connects them

    i.e. find widget,signal pair in builder and call
    widget.connect(signal, on_<widget_name>_<signal>)'''

    callback_handler_dict = dict_from_callback_obj(callback_obj)

    for item in builder.widgets.items():
        (widget_name, widget) = item
        signal_ids = []
        try:
            widget_type = type(widget)
            while widget_type:
                signal_ids.extend(gobject.signal_list_ids(widget_type))
                widget_type = gobject.type_parent(widget_type)
        except RuntimeError:  # pylint wants a specific error
            pass
        signal_names = [gobject.signal_name(sid) for sid in signal_ids]

        # Now, automatically find any the user didn't specify in glade
        for sig in signal_names:
            # using convention suggested by glade
            handler_names = ["on_%s_%s" % (widget_name, sig)]

            # Using the convention that the top level window is not
            # specified in the handler name. That is use
            # on_destroy() instead of on_windowname_destroy()
            if widget is callback_obj:
                handler_names.append("on_%s" % sig)

            do_connect(item, sig, handler_names,
             callback_handler_dict, builder.connections)

    log_unconnected_functions(callback_handler_dict, builder.connections)
Exemplo n.º 2
0
 def get_by_name_closest(self, type_name):
     """Return widget_adaptor for type_name or closest ancestor"""
     gtype = gobject.type_from_name(type_name)
     while True:
         adapter = self._widget_adaptors.get(gobject.type_name(gtype))
         if adapter is not None:
             return adapter
         gtype = gobject.type_parent(gtype)
Exemplo n.º 3
0
    def _parse_property(self, pspec, prop):
        value_type = pspec.value_type
        while True:
            parser = self._property_parsers.get(value_type, None)
            if parser is not None:
                return parser(pspec, prop)

            try:
                value_type = GObject.type_parent(value_type)
            except RuntimeError:
                break

        raise NotImplementedError(pspec.value_type)
Exemplo n.º 4
0
def list_properties(gtype, parent=True):
    """
    Return a list of all properties for GType gtype, excluding
    properties in parent classes
    """
    pspecs = gobject.list_properties(gtype)
    if parent:
        return pspecs

    parent = gobject.type_parent(gtype)

    parent_pspecs = gobject.list_properties(parent)
    return [pspec for pspec in pspecs if pspec not in parent_pspecs]
Exemplo n.º 5
0
def list_properties(gtype, parent=True):
    """
    Return a list of all properties for GType gtype, excluding
    properties in parent classes
    """
    pspecs = gobject.list_properties(gtype)
    if parent:
        return pspecs

    parent = gobject.type_parent(gtype)

    parent_pspecs = gobject.list_properties(parent)
    return [pspec for pspec in pspecs
            if pspec not in parent_pspecs]
Exemplo n.º 6
0
    def _get_type_from_prop_name(self, type_name, prop_name):
        """Get the type for type_name::prop_name. If we don't have a PropType
        for this type_name, check in its parent types"""
        assert type(type_name) == str

        while True:
            full_name = type_name + '::' + prop_name
            if full_name in self._types.keys():
                return self._types[full_name]

            if type_name == 'GObject':
                break

            type_name = gobject.type_name(gobject.type_parent(type_name))
Exemplo n.º 7
0
    def parse_one(self, toplevel, gobj):
        if not isinstance(gobj, gobject.GObject):
            raise TypeError

        gtype = gobj
        while True:
            name = gobject.type_name(gtype)
            func = getattr(self, name, None)
            if func:
                if func(toplevel, gobj):
                    break
            if gtype == gobject.GObject.__gtype__:
                break

            gtype = gobject.type_parent(gtype)
Exemplo n.º 8
0
    def parse_one(self, toplevel, gobj):
        if not isinstance(gobj, gobject.GObject):
            raise TypeError

        gtype = gobj
        while True:
            name = gobject.type_name(gtype)
            func = getattr(self, name, None)
            if func:
                if func(toplevel, gobj):
                    break
            if gtype == gobject.GObject.__gtype__:
                break

            gtype = gobject.type_parent(gtype)
Exemplo n.º 9
0
    def _list_custom(self, type_name):
        """
        List custom properties for type_name, check the type and
        all the parent types
        """
        retval = []
        while True:
            for prop_name in self._custom.get(type_name, []):
                full_name = type_name + '::' + prop_name
                retval.append(self._types[full_name])

            if type_name == 'GObject':
                break

            type_name = gobject.type_name(gobject.type_parent(type_name))

        return retval
Exemplo n.º 10
0
    def fill_ancestry(self, full_class_name, class_name, class_type):

        self.app.areaClasses.foreach( lambda btn: self.app.areaClasses.remove(btn) )

        ancs = []
        while True:
            try:
                anc = gobject.type_parent( class_type )
            except:
                anc = None

            if anc == None:
                break
            else:
                class_type = anc.pytype

                if class_type == None:
                    continue

                if anc.name == 'GInitiallyUnowned':
                    continue

                if class_type.__name__ == 'GObject':
                    class_str = "gobject.GObject"
                else:
                    class_str = \
                        class_type.__module__ + '.' + class_type.__name__

                ancs.append( class_str )

        ancs.reverse()
        ancs.append( full_class_name )

        for anc in ancs:
            hb = gtk.HBox()
            hb.add( gtk.image_new_from_pixbuf( self.get_object_image(anc) ) )
            hb.add( gtk.Label(anc) )
            hb.set_spacing( 2 )
            hb.show_all()

            b = gtk.Button()
            b.connect( "clicked", self.ancestry_button_event_on_click, anc )
            b.add( hb )
            b.show()

            self.app.areaClasses.add( b )
Exemplo n.º 11
0
    def get_adapter(self, gobj, type_name=None, build=None):
        # Name is optional, for performance reasons we want
        # to send it as often as we can, normally it's already
        # known at the callsite.
        if type_name == None:
            type_name = gobject.type_name(gobj)
        orig_name = type_name

        while True:
            adapter = self._adapters.get(type_name)
            if adapter:
                # Store a reference for the adapter, to make the
                # next lookup faster
                self._adapters[orig_name] = adapter
                return adapter(build)

            gobj = gobject.type_parent(gobj)
            type_name = gobject.type_name(gobj)
    def get_parent_list(self, obj):
        tobj = type(obj)
        ancs = []
        while True:
            try:
                anc = gobject.type_parent( tobj )
            except:
                anc = None

            if anc == None:
                break
            else:
                tobj = anc.pytype

                if not tobj:
                    continue

                ancs.append( tobj )

        return ancs
Exemplo n.º 13
0
def auto_connect_by_name(callback_obj, builder):
    '''finds handlers like on_<widget_name>_<signal> and connects them

	i.e. find widget,signal pair in builder and call
	widget.connect(signal, on_<widget_name>_<signal>)'''

    callback_handler_dict = dict_from_callback_obj(callback_obj)

    for item in builder.widgets.items():
        (widget_name, widget) = item
        signal_ids = []
        try:
            widget_type = type(widget)
            while widget_type:
                signal_ids.extend(gobject.signal_list_ids(
                    widget_type))  #EDIT:WINDOWS GObject to gobject
                widget_type = gobject.type_parent(
                    widget_type)  #EDIT:WINDOWS GObject to gobject
        except RuntimeError:  # pylint wants a specific error
            pass
        signal_names = [gobject.signal_name(sid) for sid in signal_ids
                        ]  #EDIT:WINDOWS GObject to gobject

        # Now, automatically find any the user didn't specify in glade
        for sig in signal_names:
            # using convention suggested by glade
            handler_names = ["on_%s_%s" % (widget_name, sig)]

            # Using the convention that the top level window is not
            # specified in the handler name. That is use
            # on_destroy() instead of on_windowname_destroy()
            if widget is callback_obj:
                handler_names.append("on_%s" % sig)

            do_connect(item, sig, handler_names, callback_handler_dict,
                       builder.connections)

    log_unconnected_functions(callback_handler_dict, builder.connections)
Exemplo n.º 14
0
def test_modifier_type():
    '''
    Ensure that ``gdk.ModifierType`` is a ``GFlags`` type.
    '''
    gobject.type_parent(gdk.ModifierType) == gobject.GFlags