Python gi.repository.GLib.timeout_add() Examples
The following are 30
code examples of gi.repository.GLib.timeout_add().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gi.repository.GLib
, or try the search function
.
Example #1
Source File: remote_assistance.py From epoptes with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: QuiltView.py From addons-source with GNU General Public License v2.0 | 6 votes |
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)
Example #3
Source File: QuiltView.py From addons-source with GNU General Public License v2.0 | 6 votes |
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)
Example #4
Source File: ui.py From pantalaimon with Apache License 2.0 | 6 votes |
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()
Example #5
Source File: test_file_output.py From brave with Apache License 2.0 | 6 votes |
def assert_valid_output_file(output_video_location): ''' Given a file, validates it is a video (mp4) file ''' import gi gi.require_version('Gst', '1.0') from gi.repository import Gst, GLib Gst.init(None) mainloop = GLib.MainLoop() # We create a pipeline so that we can read the file and check it: pipeline = Gst.ElementFactory.make("playbin") pipeline.set_property('uri','file://'+output_video_location) playsink = pipeline.get_by_name('playsink') playsink.set_property('video-sink', Gst.ElementFactory.make('fakesink')) pipeline.set_state(Gst.State.PAUSED) def after_a_second(): assert pipeline.get_state(0).state == Gst.State.PAUSED element = pipeline.get_by_name('inputselector1') caps = element.get_static_pad('src').get_current_caps() assert caps.to_string() == 'audio/x-raw, format=(string)F32LE, layout=(string)interleaved, rate=(int)48000, channels=(int)2, channel-mask=(bitmask)0x0000000000000003' element = pipeline.get_by_name('inputselector0') caps = element.get_static_pad('src').get_current_caps() assert caps.to_string() == 'video/x-raw, format=(string)NV12, width=(int)640, height=(int)360, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)jpeg, colorimetry=(string)bt601, framerate=(fraction)30/1' pipeline.set_state(Gst.State.NULL) mainloop.quit() GLib.timeout_add(1000, after_a_second) mainloop.run()
Example #6
Source File: eventhandler.py From vimiv with MIT License | 6 votes |
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
Example #7
Source File: timermanager.py From syncthing-gtk with GNU General Public License v2.0 | 6 votes |
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)
Example #8
Source File: ui.py From pympress with GNU General Public License v2.0 | 6 votes |
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 ############################ ############################################################################
Example #9
Source File: FlatCAMApp.py From FlatCAM with MIT License | 6 votes |
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])
Example #10
Source File: benchmark.py From epoptes with GNU General Public License v3.0 | 6 votes |
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)
Example #11
Source File: FlatCAMApp.py From FlatCAM with MIT License | 6 votes |
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])
Example #12
Source File: gtk_ui.py From python-gui with Apache License 2.0 | 6 votes |
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)
Example #13
Source File: gtk_ui.py From oversteer with GNU General Public License v3.0 | 6 votes |
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()
Example #14
Source File: preview_web_view.py From Apostrophe with GNU General Public License v3.0 | 6 votes |
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)
Example #15
Source File: NewFolderDialog.py From bcloud with GNU General Public License v3.0 | 5 votes |
def show_message(self, message): def hide_message(timestamp): if timestamp == self.infobar.timestamp: self.infobar.hide() self.info_label.set_label(message) self.infobar.show_all() timestamp = time.time() self.infobar.timestamp = timestamp GLib.timeout_add(3000, hide_message, timestamp)
Example #16
Source File: RenameDialog.py From bcloud with GNU General Public License v3.0 | 5 votes |
def show_message(self, message): def hide_message(timestamp): if timestamp == self.infobar.timestamp: self.infobar.hide() self.info_label.set_label(message) self.infobar.show_all() timestamp = time.time() self.infobar.timestamp = timestamp GLib.timeout_add(3000, hide_message, timestamp)
Example #17
Source File: backend_gtk3.py From CogAlg with MIT License | 5 votes |
def _timer_start(self): # Need to stop it, otherwise we potentially leak a timer id that will # never be stopped. self._timer_stop() self._timer = GLib.timeout_add(self._interval, self._on_timer)
Example #18
Source File: shell.py From eavatar-me with Apache License 2.0 | 5 votes |
def _run(self): GLib.timeout_add(1000, self.on_timeout, priority=GLib.PRIORITY_DEFAULT) Gtk.main()
Example #19
Source File: status.py From hazzy with GNU General Public License v2.0 | 5 votes |
def __init__(self, stat=None): GObject.GObject.__init__(self) self.signals = GObject.signal_list_names(self) self.stat = stat or linuxcnc.stat() self.error = linuxcnc.error_channel() self.report_actual_position = ini_info.get_position_feedback() axes = ini_info.get_axis_list() self.axis_list = ['xyzabcuvw'.index(axis) for axis in axes] self.num_joints = ini_info.get_num_joints() self.file = None self.registry = [] self.old = {} self.old['joint'] = getattr(self.stat, 'joint') # Setup joint dict signals self.joint_keys = self.old['joint'][0].keys() # keys() is slow, but we only use it on init for key in self.joint_keys: key = 'joint-{}'.format(key) GObject.signal_new(key.replace('_', '-'), self, GObject.SignalFlags.RUN_FIRST, None, (int, object)) self.max_time = 0 self.counter = 0 # Connect internally used signal callbacks self.on_changed('stat.gcodes', self._update_active_gcodes) self.on_changed('stat.mcodes', self._update_active_mcodes) self.on_changed('stat.file', self._update_file) GLib.timeout_add(50, self._periodic) # This allows monitoring any of the linuxcnc.stat attributes # and connecting a callback to be called on attribute value change
Example #20
Source File: async_discover_and_pair.py From python-bluezero with MIT License | 5 votes |
def device_found_handler(device_obj): if 'micro:bit' in device_obj.alias: print('micro:bit found') dongle.stop_discovery() device_obj.pair() waiting = True while waiting: print('waiting...') sleep(1) print('Status ubit', device_obj.connected, device_obj.services_resolved, device_obj.paired) waiting = not device_obj.paired if device_obj.paired: print('Dongle Addres', dongle.address, device_obj.address) ubit_device = microbit.Microbit(adapter_addr=dongle.address, device_addr=device_obj.address, accelerometer_service=False, button_service=True, led_service=False, magnetometer_service=False, pin_service=False, temperature_service=False) print(dir(ubit_device)) # Need long sleep here to allow micro:bit to switch from pairing # mode to normal mode. There should be a smarter way to do this # I just can't think what it is right now sleep(30) print('call ubit', ubit_device.connected, ubit_device.ubit.services_resolved) # Using native GLib timeout method because Bluezero one does # not take parameters. Should update the async_tools.add_timer # method to accept them GLib.timeout_add(500, connect_ubit, ubit_device) return True
Example #21
Source File: FlatCAMApp.py From FlatCAM with MIT License | 5 votes |
def plot_all(self): """ Re-generates all plots from all objects. :return: None """ 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.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.idle_add(lambda: self.on_zoom_fit(None)) GLib.timeout_add(300, lambda: app_obj.set_progress_bar(0.0, "Idle")) # Send to worker self.worker.add_task(worker_task, [self])
Example #22
Source File: editor.py From runsqlrun with MIT License | 5 votes |
def on_buffer_changed_delayed(self, buf): if self._parse_timeout is not None: GLib.source_remove(self._parse_timeout) self._parse_timeout = GLib.timeout_add( 200, self.on_buffer_changed, buf)
Example #23
Source File: backend_gtk3.py From ImageFusion with MIT License | 5 votes |
def _on_timer(self): TimerBase._on_timer(self) # Gtk timeout_add() requires that the callback returns True if it # is to be called again. if len(self.callbacks) > 0 and not self._single: return True else: self._timer = None return False
Example #24
Source File: backend_gtk3.py From ImageFusion with MIT License | 5 votes |
def _timer_start(self): # Need to stop it, otherwise we potentially leak a timer id that will # never be stopped. self._timer_stop() self._timer = GLib.timeout_add(self._interval, self._on_timer)
Example #25
Source File: gp-saml-gui.py From gp-saml-gui with GNU General Public License v3.0 | 5 votes |
def get_saml_headers(self, webview, event): if event != WebKit2.LoadEvent.FINISHED: return mr = webview.get_main_resource() uri = mr.get_uri() rs = mr.get_response() h = rs.get_http_headers() if self.verbose: print('[PAGE ] Finished loading page %s' % uri, file=stderr) if not h: return # convert to normal dict d = {} h.foreach(lambda k, v: setitem(d, k, v)) # filter to interesting headers fd = {name:v for name, v in d.items() if name.startswith('saml-') or name in ('prelogin-cookie', 'portal-userauthcookie')} if fd and self.verbose: print("[SAML ] Got SAML result headers: %r" % fd, file=stderr) if self.verbose > 1: # display everything we found ct = h.get_content_type() mr.get_data(None, self.log_resource_text, ct[0], ct.params.get('charset'), d) # check if we're done self.saml_result.update(fd, server=urlparse(uri).netloc) GLib.timeout_add(1000, self.check_done)
Example #26
Source File: extras.py From pympress with GNU General Public License v2.0 | 5 votes |
def enqueue(cls, callback, *args, **kwargs): """ Do not call callback directly, instead delay as to avoid repeated calls in short periods of time. Args: callback (`function`): callback to call with all the further arguments """ if cls.timeout: GLib.Source.remove(cls.timeout) cls.timeout = GLib.timeout_add(200, cls.call, callback, *args, **kwargs)
Example #27
Source File: gif_backend.py From pympress with GNU General Public License v2.0 | 5 votes |
def advance_gif(self): """ Advance the gif, queue redrawing if the frame changed, and schedule the next frame. """ if self.iter.advance(): self.movie_zone.queue_draw() delay = self.iter.get_delay_time() if delay >= 0: GLib.timeout_add(delay, self.advance_gif)
Example #28
Source File: talk_time.py From pympress with GNU General Public License v2.0 | 5 votes |
def __init__(self, builder, ett): super(TimeCounter, self).__init__() self.label_colorer = TimeLabelColorer(builder.get_object('label_time')) self.ett = ett builder.load_widgets(self) # Setup timer for clocks GLib.timeout_add(250, self.update_time)
Example #29
Source File: FlatCAMApp.py From FlatCAM with MIT License | 5 votes |
def disable_plots(self, except_current=False): """ Disables all plots with exception of the current object if specified. :param except_current: Wether to skip the current object. :rtype except_current: boolean :return: None """ # TODO: This method is very similar to replot_all. Try to merge. 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(): if obj != self.collection.get_active() or not except_current: obj.options['plot'] = False 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])
Example #30
Source File: alttoolbar_type.py From alternative-toolbar with GNU General Public License v3.0 | 5 votes |
def initialise(self, plugin): """ one off initialisation call :param plugin is the plugin reference """ self.plugin = plugin self.shell = plugin.shell self.find = plugin.find # finally - complete the headerbar setup after the database has fully # loaded because # rhythmbox has everything initiated at this point. self.startup_completed = False # self.shell.props.db.connect('load-complete', self.on_load_complete) # fire event anyway - scenario is when plugin is first activated post # rhythmbox having started def delayed(*args): if self.shell.props.selected_page: self.startup_completed = True self.on_startup() return False else: return True GLib.timeout_add(100, delayed)