PyGObject GTK+ 3 - Documentation?

前端 未结 5 1580
心在旅途
心在旅途 2021-01-30 11:17

PyGObject appears to have no real documentation. This tutorial is as close as it gets. I\'ve been struggling all morning simply trying to find a description of the arguments acc

5条回答
  •  醉酒成梦
    2021-01-30 11:55

    You can retrieve all the properties of an object with this

    dir(YouObjectInstance.props)
    

    YourObjectInstance is any instance you create of course.

    The easy way might be to open a terminal:

    you@yourcomputer ~/Desktop/python $ python
    Python 2.7.2+ (default, Oct  4 2011, 20:03:08) 
    [GCC 4.6.1] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from gi.repository import Gtk, GtkSource, GObject
    >>> window_instance = Gtk.Window()
    >>> dir(window_instance.props)
    ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__iter__', '__len__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'accept_focus', 'app_paintable', 'application', 'border_width', 'can_default', 'can_focus', 'child', 'composite_child', 'decorated', 'default_height', 'default_width', 'deletable', 'destroy_with_parent', 'double_buffered', 'events', 'expand', 'focus_on_map', 'focus_visible', 'gravity', 'halign', 'has_default', 'has_focus', 'has_resize_grip', 'has_tooltip', 'has_toplevel_focus', 'height_request', 'hexpand', 'hexpand_set', 'icon', 'icon_name', 'is_active', 'is_focus', 'margin', 'margin_bottom', 'margin_left', 'margin_right', 'margin_top', 'mnemonics_visible', 'modal', 'name', 'no_show_all', 'opacity', 'parent', 'receives_default', 'resizable', 'resize_grip_visible', 'resize_mode', 'role', 'screen', 'sensitive', 'skip_pager_hint', 'skip_taskbar_hint', 'startup_id', 'style', 'title', 'tooltip_markup', 'tooltip_text', 'transient_for', 'type', 'type_hint', 'ubuntu_no_proxy', 'urgency_hint', 'valign', 'vexpand', 'vexpand_set', 'visible', 'width_request', 'window', 'window_position']
    >>> 
    

    Now you have instant documentation of the properties of the object.

    If you need the methods?

    for names in dir(window_instance):
        attr = getattr(window_instance,names)
        if callable(attr):
            print names,':',attr.__doc__
    

    If you want reflection you can go to this link: reflection api That will save you tons of time. It could also be modified to accept any object or be inherited.

    You can also use: help(SomeClassModuleOrFunction)

    The printed text that comes from help() can be limited though, but using instance.props and loop over the instance can also have short comings depending on how well documented the code was.

    Use any of the above methods to at least get some documentation. When one doesn't fit what you need try another.

提交回复
热议问题