Python gi.repository.GObject 模块,type_register() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用gi.repository.GObject.type_register()

项目:nautilus-git    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def __init__(self, git):
        GObject.type_register(GtkSource.View)
        self._git = git
        self._builder = Gtk.Builder()
        self._builder.add_from_resource('/com/nautilus/git/ui/compare.ui')
        self._builder.connect_signals({
            "file_changed": self._on_file_changed
        })

        self._window = self._builder.get_object("window")

        self._build_widgets()
        self._window.show_all()
项目:any_ping_indicator    作者:leggedrobotics    | 项目源码 | 文件源码
def __init__(self, id, name, address, update_rate, number_of_pings,
                 show_indicator, show_text, is_activated=None):
        """Initialize.
        :param id:
        :param address:
        :param update_rate:
        :param number_of_pings:
        :param show_indicator:
        :param is_activated:
        """
        # init gobject
        GObject.GObject.__init__(self)
        GObject.type_register(PingObject)
        GObject.threads_init()
        # ping object properties
        self.id = id
        self.name = name
        if not self.name:
            self.name = address
        self.address = address
        self.update_rate = update_rate
        self.number_of_pings = number_of_pings
        self.show_indicator = show_indicator
        self.show_text = show_text
        if is_activated is None:
            self.is_activated = True
        else:
            self.is_activated = is_activated
        self.icon = "icon_red"
        if not self.is_activated:
            self.icon = "icon_grey"
        self.ping_warning = 50.0
        # indicator menu item
        self.menu_item = gtk.ImageMenuItem("Ping: " + address)
        # result
        self.result = PingStruct(RESULT_NO_RESPONSE, 0.0, 0.0, 0.0, 0.0)
        # gtk image for menu item
        self.image = gtk.Image()
        self.image.set_from_file(resource.image_path("icon_gray", theme.THEME))
        # ping state
        self.state = "Ping: " + self.address + " initializing."
        # store subprocess
        self.process = None
        # mutex
        self.mutex = threading.Lock()
        # thread
        self.thread = None
        self.is_running = False
        # interruptable sleep function
        self.stop_event = threading.Event()
        # current time
        self.time_last = time.time()

    # signal definition returns (id, name, icon name, show_indicator)
项目:any_ping_indicator    作者:leggedrobotics    | 项目源码 | 文件源码
def __init__(self):
        """Initialize the indicator.
        """
        # initialize gobject
        GObject.GObject.__init__(self)
        GObject.type_register(AnyPingIndicator)
        GObject.threads_init()
        # initialize mutex
        self.mutex = threading.Lock()
        # icon counter to get different icon names
        self.icon_count = 0
        # list of icon tuples
        self.list_of_icon_tuple = []
        # get ping objects from config
        self.ping_objects_tuple = config.ping_object_tuples
        self.ping_objects = []
        count = 0
        for item in self.ping_objects_tuple:
            self.ping_objects.append(PingObject(count,
                                                item.name,
                                                item.address,
                                                item.update_rate,
                                                item.number_of_pings,
                                                item.show_indicator,
                                                item.show_text,
                                                item.is_activated))
            self.ping_objects[count].set_ping_warning(config.ping_warning)
            count += 1
        # update list of icon tuples
        self.update_list_of_icon_tuples()
        # init windows variables
        self.preferences_window = None
        self.about_dialog = None
        # check autostart
        self.check_autostart()
        # initialize notification
        notify.init(APPINDICATOR_ID)
        # initialize and build indicator menu
        self.menu = gtk.Menu()
        self.build_menu()
        # initialize indicator
        self.indicator = appindicator.Indicator.new(APPINDICATOR_ID,
                resource.image_path("icon_red", theme.THEME),
                appindicator.IndicatorCategory.SYSTEM_SERVICES)
        self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
        self.indicator.set_menu(self.menu)
        # update indicator icon
        self.update_indicator_icon()
        # start ping objects
        self.start_ping_objects()