def _on_apt_finished_stamp_changed(self, monitor, afile, other_file, event): if not event == gio.FILE_MONITOR_EVENT_CHANGES_DONE_HINT: return if self._timeout_id: glib.source_remove(self._timeout_id) self._timeout_id = None self._timeout_id = glib.timeout_add_seconds(10, self.open)
def enabled(self, value): if value and self.event_source is None: # pylint: disable=attribute-defined-outside-init self.event_source = glib.io_add_watch(self.monitor, glib.IO_IN, self._process_udev_event) elif not value and self.event_source is not None: glib.source_remove(self.event_source)
def __stop_or_pause(self): self.__pause_button.set_sensitive(False) self.__start_button.set_sensitive(True) self.__scale.set_sensitive(True) if self.__update_pos_id != 0: glib.source_remove(self.__update_pos_id) self.__update_pos_id = 0
def register_os_signals(callback): from xpra.os_util import SIGNAMES, POSIX, PYTHON3, get_util_logger glib = import_glib() import signal def handle_signal(signum): try: sys.stderr.write("\n") sys.stderr.flush() get_util_logger().info("got signal %s", SIGNAMES.get(signum, signum)) except (IOError, OSError): pass callback(signum) def os_signal(signum, _frame): glib.idle_add(handle_signal, signum) for signum in (signal.SIGINT, signal.SIGTERM): if POSIX and PYTHON3: #replace the previous definition if we had one: global _glib_unix_signals current = _glib_unix_signals.get(signum, None) if current: glib.source_remove(current) source_id = glib.unix_signal_add(glib.PRIORITY_HIGH, signum, handle_signal, signum) _glib_unix_signals[signum] = source_id else: signal.signal(signum, os_signal)
def unread (self): # {{{ if self.event: glib.source_remove (self.event) self.event = None ret = self._linebuffer self._linebuffer = '' return ret
def start(self): """ Start an instance of process and wait for it to appear on the bus. """ self._get_bus() if self.bus_admin.NameHasOwner(self.BUS_NAME): raise Exception("Unable to start test instance of %s: already running" % self.PROCESS_NAME) self.name_owner_match = self.bus.add_signal_receiver( self._name_owner_changed_cb, signal_name="NameOwnerChanged", path="/org/freedesktop/DBus", dbus_interface="org.freedesktop.DBus", ) self.process = self._start_process() # Run the loop until the bus name appears, or the process dies. self.process_watch_timeout = glib.timeout_add(200, self._process_watch_cb) self.loop.run() glib.source_remove(self.process_watch_timeout)
def applet_drag_leave_cb(self, widget, context, time): self.timer_overlay.props.active = False self.get_effects().stop(awn.EFFECT_LAUNCHING) if self.timer_id != 0: glib.source_remove(self.timer_id) self.timer_id = 0 return True
def doRun(self,arg): """ Execute the current animation till the last frame. """ if self.btnRun.get_label() == "Run": # Go running self.desktop.selection.clear() # # Make dup groups empty. # It forces TweenObject to re-generate content from scratch. # nlayers = self._domviewui.get_layer_num() for layer_idx in range(nlayers): layer_dup = self._domviewui.get_layer_dup_group(layer_idx) for child in layer_dup.childList(): layer_dup.removeChild(child) pass pass self.btnRun.set_label("Stop") tmout = 1000 / self.framerate self.last_update = glib.timeout_add(tmout, self.doRunNext) else: # Stop running self.btnRun.set_label("Run") glib.source_remove(self.last_update) pass pass
def on_monitor_changed(self, monitor, gfile1, gfile2, evnt): if evnt == gio.FILE_MONITOR_EVENT_CHANGED: # Reload the module self.reload_module(gfile1.get_path()) elif evnt == gio.FILE_MONITOR_EVENT_DELETED: path = gfile1.get_path() mod = self.resolve_module(path, False) if not mod: return if path in self._timeouts: glib.source_remove(self._timeouts[path]) # We add a timeout because a common save strategy causes a # DELETE/CREATE event chain self._timeouts[path] = glib.timeout_add(500, self.on_timeout_delete, path, mod) elif evnt == gio.FILE_MONITOR_EVENT_CREATED: path = gfile1.get_path() # Check if this CREATE followed a previous DELETE if path in self._timeouts: glib.source_remove(self._timeouts[path]) del self._timeouts[path] # Reload the module self.reload_module(path)
def emit_change(self): if self._signal_timer is not None: glib.source_remove(self._signal_timer) self._signal_timer = None changed = list(self._changed_signals.keys()) self.ValueChanged(changed) self._changed_signals = {}
def shutdown(self): glib.source_remove(self._listen_source) self._listen.close() conns = list(self._conns) for conn in conns: conn.shutdown() self._controller.shutdown()
def save(self, filename=None): if filename is None: filename = self._filename self._confparser.write(open(filename, 'w')) if self._save_timer is not None: glib.source_remove(self._save_timer) self._save_timer = None
def ui(): self.exposureProgress.set_fraction(1.0) self.exposureProgress.set_text("exposure complete ...") if self.exposeTimer: glib.source_remove(self.exposeTimer) self.exposeTimer = 0
def _configure_io_handler(self, handler): """Register an io-handler with the glib main loop.""" if self.check_events(): return if handler in self._unprepared_handlers: old_fileno = self._unprepared_handlers[handler] prepared = self._prepare_io_handler(handler) else: old_fileno = None prepared = True fileno = handler.fileno() if old_fileno is not None and fileno != old_fileno: tag = self._io_sources.pop(handler, None) if tag is not None: glib.source_remove(tag) if not prepared: self._unprepared_handlers[handler] = fileno if fileno is None: logger.debug(" {0!r}.fileno() is None, not polling" .format(handler)) return events = 0 if handler.is_readable(): logger.debug(" {0!r} readable".format(handler)) events |= glib.IO_IN | glib.IO_ERR if handler.is_writable(): logger.debug(" {0!r} writable".format(handler)) events |= glib.IO_OUT | glib.IO_HUP | glib.IO_ERR if events: logger.debug(" registering {0!r} handler fileno {1} for" " events {2}".format(handler, fileno, events)) glib.io_add_watch(fileno, events, self._io_callback, handler)
def lookformod(self, track): if not track or not (track.is_local() or track.get_tag_raw('__length')): self.haveMod = False return self.playingTrack = str(track.get_loc_for_io()) self.playingTrack = self.playingTrack.replace("file://", "") modLoc = self.moodsDir + '/' + self.playingTrack.replace('/', '-') + ".mood" modLoc = modLoc.replace("'", '') needGen = False self.curpos = self.player.get_progress() if os.access(modLoc, 0): self.modwidth = 0 if not self.readMod(modLoc): needGen = True self.updateplayerpos() else: needGen = True if needGen: self.pid = subprocess.Popen(['/usr/bin/moodbar', track.get_local_path(), '-o', modLoc]) self.haveMod = not needGen if self.modTimer: glib.source_remove(self.modTimer) self.modTimer = glib.timeout_add_seconds(1, self.updateMod)
def timer_cb(self, *a): if self.first_update: self.first_update=False if self.TIMER_ID: glib.source_remove(self.TIMER_ID) self.start_timer_cb() self.update_cb() return True
def on_close(self): '''called when the conversation is closed''' self.session.config.unsubscribe(self._on_show_toolbar_changed, 'b_show_toolbar') self.session.signals.picture_change_succeed.unsubscribe( self.on_picture_change_succeed) self.session.signals.contact_attr_changed.unsubscribe( self.on_contact_attr_changed_succeed) self.session.signals.filetransfer_invitation.unsubscribe( self.on_filetransfer_invitation) self.session.signals.filetransfer_accepted.unsubscribe( self.on_filetransfer_accepted) self.session.signals.filetransfer_progress.unsubscribe( self.on_filetransfer_progress) self.session.signals.filetransfer_completed.unsubscribe( self.on_filetransfer_completed) self.session.signals.call_invitation.unsubscribe( self.on_call_invitation) #stop the group chat image rotation timer, if it's started if self.rotate_started: glib.source_remove(self.timer) #stop the avatars animation...if any.. self.avatar.stop() self.his_avatar.stop() #stop the parse emotes timeout of the inputbox self.input.stop_parse_emotes()
def stop(self): glib.source_remove(self.timeout_id) if hasattr(extension, "unregister"): if os.name == "nt": extension.unregister('idle timer', WindowsTimer.WindowsTimer) else: extension.unregister('idle timer', LinuxTimer)
def loop_iteration(self, timeout = 1): self._stack.append(None) try: if self.check_events(): return self._prepare_pending() def dummy_cb(): "Dummy callback function to force event if none are pending." self._anything_done = True logger.debug("Dummy timeout func called") return True self._anything_done = False tag = None logger.debug("Calling main_context_default().iteration()") while not self._anything_done: if not glib.main_context_default().pending() and not tag: tag = glib.timeout_add(int(timeout * 1000), dummy_cb) glib.main_context_default().iteration(True) if tag: glib.source_remove(tag) logger.debug("..main_context_default().iteration() exited") finally: self._stack.pop() if self.exc_info: (exc_type, exc_value, ext_stack), self.exc_info = (self.exc_info, None) raise exc_type, exc_value, ext_stack
def wait(self, stage=STATE_CHANNELS_LOADED): loop = MainLoop(None, True) def data_ready_cb(new_stage): if new_stage >= stage: loop.quit() self.__service.connect_to_signal('DataReady', data_ready_cb) if self.__service.GetDataStage() >= stage: loop.quit() progress_id = 0 if loop.is_running(): if sys.stdout.isatty(): progress = ['-\r', '\\\r', '|\r', '/\r'] def progress_cb(): c = progress.pop(0) sys.stdout.write(c) sys.stdout.flush() progress.append(c) return True progress_id = timeout_add(250, progress_cb) sys.stdout.write(' loading...\r') loop.run() if progress_id: source_remove(progress_id) sys.stdout.write('\r\033[K') sys.stdout.flush()
def enabled(self, value): if value and self.event_source is None: # pylint: disable=attribute-defined-outside-init self.event_source = glib.io_add_watch( self.monitor, glib.IO_IN, self._process_udev_event) elif not value and self.event_source is not None: glib.source_remove(self.event_source)
def buf_on_change(self, buffer, position, chars, n_chars): if hasattr(self, 'timer'): glib.source_remove(self.timer) id = self.statusBar.get_context_id("yans") self.statusBar.push(id, "Loading..."); self.timer = glib.timeout_add(1000, self.renderText) return False
def _on_entry_changed(self, entry): if self._completion_timeout: glib.source_remove(self._completion_timeout) self._completion_timeout = glib.timeout_add( self.COMPLETION_TIMEOUT, self._on_completion_timeout )
def remove_from_connection (self): self.__command_thread.enqueue ("") if self.__poll_source is not None: glib.source_remove (self.__poll_source) self.__poll_source = None panflute.daemon.mpris.Player.remove_from_connection (self)
def close_session(self, do_exit=True): '''close session''' self._remove_subscriptions() for conv_manager in self.conversations: conv_manager.hide_all() self._on_conversation_window_close(conv_manager) if self.timeout_id: glib.source_remove(self.timeout_id) self.timeout_id = None if self.session is not None: self.session.quit() self.save_extensions_config() self._save_login_dimensions() if self.session is not None: self.session.save_config() self.session = None self.config.save(self.config_path) if do_exit: if self.tray_icon is not None: self.tray_icon.set_visible(False) self.window.hide() self.window = None sys.exit(0)
def update_timeout(self, name, t, callback, *args): if name in self.timeouts: glib.source_remove(self.timeouts[name]) del self.timeouts[name] if t != None: self.timeouts[name] = glib.timeout_add_seconds(t, callback, *args)
def rotate_picture(self): """change the account picture in a multichat conversation every 5 seconds""" def increment(): if self.index < len(self.members) - 1: self.index += 1 else: self.index = 0 if len(self.members) == 1: self.index = 0 glib.source_remove(self.timer) self.rotate_started = False elif self.index > len(self.members): self.index = 0 contact = self.session.contacts.get(self.members[self.index]) if contact is None: increment() return True path = contact.picture if path != "": self.his_avatar.set_from_file(path) increment() return True
def close_session(self, do_exit=True): """close session""" self._remove_subscriptions() if self.conversations: self.conversations.get_parent().hide() self._on_conversation_window_close() if self.timeout_id: glib.source_remove(self.timeout_id) self.timeout_id = None if self.session is not None: self.session.quit() self.save_extensions_config() self._save_login_dimensions() if self.session is not None: self.session.save_config() self.session = None self.config.save(self.config_path) if do_exit: if self.tray_icon is not None: self.tray_icon.set_visible(False) self.window.hide() self.window = None while gtk.events_pending(): gtk.main_iteration(False) sys.exit(0)
def defer_hq_rendering(self, t=1.0/8): """Use faster but lower-quality rendering for a brief period :param float t: The time to defer for, in seconds This method is intended to be called repeatedly from scroll or drag event handlers, or other times when the entire display may need to be redrawn repeatedly in short order. It turns off normal rendering, and updates the future time at which normal rendering will be automatically resumed. Resumption of normal service entails a full redraw, so choose `t` appropriately. Normal rendering looks better (it uses a better mipmap), and it's OK for most screen updates. However it's slow enough to make rendering lag appreciably when scrolling. """ if self._restore_hq_rendering_timeout_id: glib.source_remove(self._restore_hq_rendering_timeout_id) self._restore_hq_rendering_timeout_id = None else: logger.debug("hq_rendering: deferring for %0.3fs...", t) self._hq_rendering = False self._restore_hq_rendering_timeout_id = glib.timeout_add( interval = int(t*1000), function = self._resume_hq_rendering_timeout_cb, )
def show(self): """Show search completion.""" # Remove search delay event if searchEventId not None. if self.searchEventId != None: glib.source_remove(self.searchEventId) self.searchEventId = None if self.showCompletion: # Search time bound: 80ms ~ 500ms, most time under INPUT_DELAY. # So user won't feeling *delay* if input delay more than INPUT_DELAY. # Input delay bound: 50ms ~ 200ms currentTime = time.time() delay = (currentTime - self.lastChangeTimestamp) * 1000 if delay > self.INPUT_DELAY: # Record last change time stamp. self.lastChangeTimestamp = currentTime # Show completion. self.showCompletionWindow() else: # Add delay search if input delay less than INPUT_DELAY. # This step to avoid last input character input too fast that can't show completion correctly. if self.searchEventId == None: self.searchEventId = glib.timeout_add(self.WAIT_SEARCH_DELAY, self.showCompletionWindow) self.window.hide_all() else: self.window.hide_all()
def _update(self): if self._sock is None: return if (self._send_closing and not self._send_closed and not self._send_buf): try: self._sock.shutdown(socket.SHUT_WR) except socket.error: pass self._send_closed = True if self._send_closed and self._recv_closed: if self._source is not None: glib.source_remove(self._source) self._source = None self._sock.close() self._sock = None self.emit('close') return cond = 0 if self._recv_callback is not None and not self._recv_closed: cond |= glib.IO_IN if self._send_buf and not self._send_closed: cond |= glib.IO_OUT if self._source is not None: glib.source_remove(self._source) self._source = glib.io_add_watch(self._sock, cond, self._io_ready)
def __disable_timer(self): """ Disables the update timer """ if self.__timer_id is not None: glib.source_remove(self.__timer_id) self.__timer_id = None
def on_playback_track_end(self, event, player, track): """ Stops marker watching """ if self.__timeout_id is not None: glib.source_remove(self.__timeout_id) self.__timeout_id = None
def preview_motion_cb(self, widget, event): self.live.show() if self.live_hide_timeout: glib.source_remove(self.live_hide_timeout) self.live_hide_timeout = 0 self.live_hide_timeout = glib.timeout_add(preview_timeout, self.preview_hide_cb) return True