當前位置: 首頁>>代碼示例>>Python>>正文


Python GLib.timeout_add方法代碼示例

本文整理匯總了Python中gi.repository.GLib.timeout_add方法的典型用法代碼示例。如果您正苦於以下問題:Python GLib.timeout_add方法的具體用法?Python GLib.timeout_add怎麽用?Python GLib.timeout_add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gi.repository.GLib的用法示例。


在下文中一共展示了GLib.timeout_add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _update_overlay

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def _update_overlay(self, auto = False):
        ffbmeter_overlay = self.ffbmeter_overlay.get_active()
        wheel_range_overlay = self.get_wheel_range_overlay()
        if ffbmeter_overlay or wheel_range_overlay == 'always' or (wheel_range_overlay == 'auto' and auto):
            if not self.overlay_window.props.visible:
                self.overlay_window.show()
            if not self.ffbmeter_timer and self.overlay_window.props.visible and ffbmeter_overlay:
                GLib.timeout_add(250, self.update_ffbmeter_overlay)
            if ffbmeter_overlay:
                self._ffbmeter_overlay.show()
            else:
                self._ffbmeter_overlay.hide()
            if wheel_range_overlay == 'always' or (wheel_range_overlay == 'auto' and auto):
                self._wheel_range_overlay.show()
            else:
                self._wheel_range_overlay.hide()

        else:
            self.overlay_window.hide() 
開發者ID:berarma,項目名稱:oversteer,代碼行數:21,代碼來源:gtk_ui.py

示例2: _gtk_configure

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def _gtk_configure(self, widget, event):
        def resize(*args):
            self._resize_timer_id = None
            width, height = self._window.get_size()
            columns = width // self._cell_pixel_width
            rows = height // self._cell_pixel_height
            if self._screen.columns == columns and self._screen.rows == rows:
                return
            self._bridge.resize(columns, rows)

        if not self._screen:
            return
        if event.width == self._pixel_width and \
           event.height == self._pixel_height:
            return
        if self._resize_timer_id is not None:
            GLib.source_remove(self._resize_timer_id)
        self._resize_timer_id = GLib.timeout_add(250, resize) 
開發者ID:neovim,項目名稱:python-gui,代碼行數:20,代碼來源:gtk_ui.py

示例3: on_btn_start_clicked

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def on_btn_start_clicked(self, _widget):
        """Handle btn_start.clicked event."""
        seconds = int(self.adj_seconds.get_value())
        self.spawn_process.spawn('iperf -s -xS -yC'.split(),
                                 timeout=(seconds + 3),
                                 lines_max=2*len(self.clients))
        for client in self.clients:
            handle = self.clients[client][0]
            # Half time for upload speed and half for download
            self.execute(handle, 'start_benchmark %d' % int(seconds/2))
        self.timeleft = seconds
        self.box_seconds.set_visible(False)
        self.box_countdown.set_visible(True)
        self.btn_start.set_visible(False)
        self.btn_stop.set_visible(True)
        self.lbl_countdown.set_text(_("Benchmark finishing in %d seconds...")
                                    % self.timeleft)
        self.countdown_event = GLib.timeout_add(1000, self.update_countdown) 
開發者ID:epoptes,項目名稱:epoptes,代碼行數:20,代碼來源:benchmark.py

示例4: connect

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def connect(self):
        """Handle btn_action clicked when it's in the Connect state."""
        self.host = self.ent_host.get_text().strip()
        pid = os.getpid()

        share_terminal = self.cmb_method.get_active() != 0
        if share_terminal:
            cmd = ['xterm', '-e', os.path.dirname(__file__) +
                   '/share-terminal', self.host]
            subprocess.Popen(cmd)
            self.on_btn_close_clicked(None)
            return

        cmd = ['x11vnc', '-q', '-nopw', '-connect_or_exit', self.host,
               '-afteraccept', 'kill -USR1 {}'.format(pid)]
        self.proc = subprocess.Popen(cmd)

        # Set the status as "Connecting"
        if self.retry_timeout_id:
            GLib.source_remove(self.retry_timeout_id)
            self.retry_timeout_id = None
        self.set_state('connecting')

        # Start polling the process every 1 second to see if it's still alive
        GLib.timeout_add(1000, self.poll_process) 
開發者ID:epoptes,項目名稱:epoptes,代碼行數:27,代碼來源:remote_assistance.py

示例5: rebuild

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def rebuild(self):
        """
        Rebuild.
        """
        if not self.active:
            return # Don't rebuild, we are hidden.
        if self.load < 3: # avoid to load the database twice
            return
        self.total = self.dbstate.db.get_number_of_people()
        self._erase_name_selection()
        active = self.get_active()
        if active != "":
            self.on_draw_ok = -1
            self.people, self.families, self.layers = self.read_data(active)
            self.canvas.queue_draw()
            self.canvas.grab_focus()
            # We need to wait on_draw is called to draw path lines.
            self.on_draw_ok = 0
            GLib.timeout_add(int(200), self.after_on_draw_on_rebuild) 
開發者ID:gramps-project,項目名稱:addons-source,代碼行數:21,代碼來源:QuiltView.py

示例6: show_family_name

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def show_family_name(self, handle, event):
        """
        Popup menu for node (family).
        """
        if handle:
            family = self.dbstate.db.get_family_from_handle(handle)
        else:
            return False

        if family:
            if not self.timeout:
                self.save_tooltip = handle
                self.scrolledwindow.set_property("has-tooltip", True)
                tooltip = self.get_family_name(handle)
                self.scrolledwindow.set_tooltip_text(tooltip)
                self.timeout = GLib.timeout_add(3*1000, self.remove_tooltip)
            elif handle != self.save_tooltip:
                self.save_tooltip = handle
                GLib.source_remove(self.timeout)
                tooltip = self.get_family_name(handle)
                self.scrolledwindow.set_tooltip_text(tooltip)
                self.timeout = GLib.timeout_add(3*1000, self.remove_tooltip) 
開發者ID:gramps-project,項目名稱:addons-source,代碼行數:24,代碼來源:QuiltView.py

示例7: run

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def run(self):
            self.loop = GLib.MainLoop()

            if self.config.notifications:
                try:
                    notify2.init("pantalaimon", mainloop=self.loop)
                    self.notifications = True
                except dbus.DBusException:
                    logger.error(
                        "Notifications are enabled but no notification "
                        "server could be found, disabling notifications."
                    )
                    self.notifications = False

            GLib.timeout_add(100, self.message_callback)
            if not self.loop:
                return

            self.loop.run() 
開發者ID:matrix-org,項目名稱:pantalaimon,代碼行數:21,代碼來源:ui.py

示例8: on_touch

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def on_touch(self, widget, event):
        """Clear mouse connection when touching screen.

        This stops calling the ButtonX bindings when using the touch screen.
        Reasoning: We do not want to e.g. move to the next image when trying to
            zoom in.
        """
        try:
            self._app["window"].disconnect_by_func(self.on_click)
        # Was already disconnected
        except TypeError:
            pass
        if self._timer_id_touch:
            GLib.source_remove(self._timer_id_touch)
        self._timer_id_touch = GLib.timeout_add(5, self._reconnect_click)
        return True 
開發者ID:karlch,項目名稱:vimiv,代碼行數:18,代碼來源:eventhandler.py

示例9: timer

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def timer(self, name, delay, callback, *data, **kwdata):
		"""
		Runs callback after specified number of seconds. Uses
		GLib.timeout_add_seconds with small wrapping to allow named
		timers to be canceled by reset() call
		"""
		method = GLib.timeout_add_seconds
		if delay < 1 and delay > 0:
			method = GLib.timeout_add
			delay = delay * 1000.0
		if name is None:
			# No wrapping is needed, call GLib directly
			method(delay, callback, *data, **kwdata)
		else:
			if name in self._timers:
				# Cancel old timer
				GLib.source_remove(self._timers[name])
			# Create new one
			self._timers[name] = method(delay, self._callback, name, callback, *data, **kwdata) 
開發者ID:kozec,項目名稱:syncthing-gtk,代碼行數:21,代碼來源:timermanager.py

示例10: enable_all_plots

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def enable_all_plots(self, *args):
        self.plotcanvas.clear()
        self.set_progress_bar(0.1, "Re-plotting...")

        def worker_task(app_obj):
            percentage = 0.1
            try:
                delta = 0.9 / len(self.collection.get_list())
            except ZeroDivisionError:
                GLib.timeout_add(300, lambda: app_obj.set_progress_bar(0.0, ""))
                return
            for obj in self.collection.get_list():
                obj.options['plot'] = True
                obj.plot()
                percentage += delta
                GLib.idle_add(lambda: app_obj.set_progress_bar(percentage, "Re-plotting..."))

            GLib.idle_add(app_obj.plotcanvas.auto_adjust_axes)
            GLib.timeout_add(300, lambda: app_obj.set_progress_bar(0.0, ""))

        # Send to worker
        self.worker.add_task(worker_task, [self]) 
開發者ID:Denvi,項目名稱:FlatCAM,代碼行數:24,代碼來源:FlatCAMApp.py

示例11: on_update_plot

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def on_update_plot(self, widget):
        """
        Callback for button on form for all kinds of objects.
        Re-plots the current object only.

        :param widget: The widget from which this was called. Ignored.
        :return: None
        """

        obj = self.collection.get_active()
        obj.read_form()

        self.set_progress_bar(0.5, "Plotting...")

        def thread_func(app_obj):
            assert isinstance(app_obj, App)
            obj.plot()
            GLib.timeout_add(300, lambda: app_obj.set_progress_bar(0.0, "Idle"))

        # Send to worker
        self.worker.add_task(thread_func, [self]) 
開發者ID:Denvi,項目名稱:FlatCAM,代碼行數:23,代碼來源:FlatCAMApp.py

示例12: on_pane_event

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def on_pane_event(self, widget, evt):
        """ Signal handler for gtk.paned events.

        This function allows one to delay drawing events when resizing, and to speed up redrawing when
        moving the middle pane is done (which happens at the end of a mouse resize)

        Args:
            widget (:class:`~Gtk.Widget`):  the widget in which the event occurred (ignored)
            evt (:class:`~Gdk.Event`):  the event that occurred
        """
        if type(evt) == Gdk.EventButton and evt.type == Gdk.EventType.BUTTON_RELEASE:
            self.redraw_panes()
        elif type(evt) == GObject.GParamSpec and evt.name == "position":
            self.resize_panes = True
            if self.redraw_timeout:
                GLib.Source.remove(self.redraw_timeout)
            self.redraw_timeout = GLib.timeout_add(200, self.redraw_panes)


    ############################################################################
    ############################  Program lifetime  ############################
    ############################################################################ 
開發者ID:Cimbali,項目名稱:pympress,代碼行數:24,代碼來源:ui.py

示例13: state_loop

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def state_loop(self, scroll_scale=None, delay=16):  # 16ms ~ 60hz
        # Remove any pending callbacks
        if self.timeout_id:
            GLib.source_remove(self.timeout_id)
            self.timeout_id = None

        # Set scroll scale if specified, and the state is not dirty
        if not self.state_discard_read and scroll_scale not in (None, self.scroll_scale):
            self.scroll_scale = scroll_scale
            if self.scroll_scale != -1:
                self.emit("scroll-scale-changed", self.scroll_scale)
        self.state_discard_read = False

        # Handle the current state
        if not self.state_loaded or self.state_load_failed or self.state_waiting:
            return
        elif self.state_dirty or delay == 0:
            self.sync_scroll_scale(self.scroll_scale, self.state_dirty)
            self.state_dirty = False
        else:
            self.timeout_id = GLib.timeout_add(delay, self.state_loop, None, 0) 
開發者ID:ApostropheEditor,項目名稱:Apostrophe,代碼行數:23,代碼來源:preview_web_view.py

示例14: play

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def play(self):
        if self.uri.endswith(".MP4"):
            self.is_playing = True
        else:
            self.is_playing = False
        cli.log.info(_("play"))
        self.player.set_state(Gst.State.PLAYING)

        # starting up a timer to check on the current playback value
        GLib.timeout_add(1000, self.update_slider) 
開發者ID:encarsia,項目名稱:gpt,代碼行數:12,代碼來源:modules.py

示例15: delayed_signal

# 需要導入模塊: from gi.repository import GLib [as 別名]
# 或者: from gi.repository.GLib import timeout_add [as 別名]
def delayed_signal(delay=500):
	"""
	A decorator to delay the execution of a signal handler to aggregate emission
	into a single event. This can for example be used to run a handler when a
	:py:class:`Gtk.Entry` widget's ``changed`` signal is emitted but not after
	every single key press meaning the handler can perform network operations to
	validate or otherwise process input.

	.. note::
		The decorated function **must** be a method. The wrapper installed by
		this decorator will automatically add an attribute to the class to track
		invoked instances to ensure the timeout is respected.

	.. versionadded:: 1.14.0

	:param int delay: The delay in milliseconds from the original emission
		before the handler should be executed.
	"""
	def decorator(function):
		src_name = '__delayed_source_' + function.__name__
		@functools.wraps(function)
		def wrapped(self, *args, **kwargs):
			def new_function(self, *args, **kwargs):
				setattr(self, src_name, None)
				return function(self, *args, **kwargs)
			src = getattr(self, src_name, None)
			if src is not None:
				return
			src = GLib.timeout_add(delay, new_function, self, *args, **kwargs)
			setattr(self, src_name, src)
		return wrapped
	return decorator 
開發者ID:rsmusllp,項目名稱:king-phisher,代碼行數:34,代碼來源:gui_utilities.py


注:本文中的gi.repository.GLib.timeout_add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。