我们从Python开源项目中,提取了以下32个代码示例,用于说明如何使用gobject.source_remove()。
def doIteration(self, delay): # flush some pending events, return if there was something to do # don't use the usual "while self.context.pending(): self.context.iteration()" # idiom because lots of IO (in particular test_tcp's # ProperlyCloseFilesTestCase) can keep us from ever exiting. log.msg(channel='system', event='iteration', reactor=self) if self.__pending(): self.__iteration(0) return # nothing to do, must delay if delay == 0: return # shouldn't delay, so just return self.doIterationTimer = gobject.timeout_add(int(delay * 1000), self.doIterationTimeout) # This will either wake up from IO or from a timeout. self.__iteration(1) # block # note: with the .simulate timer below, delays > 0.1 will always be # woken up by the .simulate timer if self.doIterationTimer: # if woken by IO, need to cancel the timer gobject.source_remove(self.doIterationTimer) self.doIterationTimer = None
def close(self): PlayerSource.close(self) if self.io_watcher_id is not None: gobject.source_remove(self.io_watcher_id) self.io_watcher_id = None if self.data: self.data.close() self.data = None if self.control: self.control.close() self.control = None if self.fifo: self.fifo.close() self.fifo = None self.fifo_name = None return True # close() # PlayerSourceGMythStreamer
def start_timer(self, timer_type): """start given timer""" #screen saver if timer_type == 'scrsave' and self.scrsave_delay > 0: if self.scrsave_timer: gobject.source_remove(self.scrsave_timer) self.scrsave_timer = gobject.timeout_add(2500, self.on_scrsave_timer) #video elif timer_type == 'video' and self.video_enabled: #stop any playing vids first self.stop_video() #restart timer self.video_timer = gobject.timeout_add( self.delaymovieprev * 1000, self.on_video_timer) #joystick elif timer_type == 'joystick' and self.joy: self.joystick_timer = gobject.timeout_add(50, self.joy.poll, self.on_winMain_key_press)
def __init__(self, mapping=None, **kwargs): # socket -> (source_id, mask) map, for io_add_watch and source_remove self._watch_map = dict() # fd -> socket map, for the interface self._fd_map = dict() if mapping is not None: self.update(mapping) if kwargs: self.update(kwargs)
def _remove_watch(self, obj): gobject.source_remove(self._watch_map.pop(obj)[0])
def removeReader(self, reader): if hasReader(reader): gobject.source_remove(reads[reader]) del reads[reader]
def removeWriter(self, writer): if hasWriter(writer): gobject.source_remove(writes[writer]) del writes[writer]
def simulate(self): """Run simulation loops and reschedule callbacks. """ global _simtag if _simtag is not None: gobject.source_remove(_simtag) self.runUntilCurrent() timeout = min(self.timeout(), 0.1) if timeout is None: timeout = 0.1 # grumble _simtag = gobject.timeout_add(int(timeout * 1010), self.simulate)
def simulate(self): """Run simulation loops and reschedule callbacks. """ global _simtag if _simtag is not None: gobject.source_remove(_simtag) self.iterate() timeout = min(self.timeout(), 0.1) if timeout is None: timeout = 0.1 # grumble _simtag = gobject.timeout_add(int(timeout * 1010), self.simulate)
def _start_update_timer(self): if self._update_timeout_id is not None: gobject.source_remove(self._update_timeout_id) #print "start_update_timer" self._update_timeout_id = gobject.timeout_add(int(SAMPLE_PERIOD/min(self.speed, 1)*1e3), self.update_view_timeout, priority=PRIORITY_UPDATE_VIEW)
def _on_play_button_toggled(self, button): if button.get_active(): self._start_update_timer() else: if self._update_timeout_id is not None: gobject.source_remove(self._update_timeout_id)
def _quit(self, *dummy_args): if self._update_timeout_id is not None: gobject.source_remove(self._update_timeout_id) self._update_timeout_id = None self.simulation.quit = True self.simulation.go.set() self.simulation.join() gtk.main_quit()
def _refresh_keep_alive(self): if self._keep_alive_interval is None: return restart = False if self._keep_alive_timer is None: logging.info('[KeepAlive] Received request, publishing restarted') restart = True else: gobject.source_remove(self._keep_alive_timer) self._keep_alive_timer = gobject.timeout_add_seconds( self._keep_alive_interval, exit_on_error, self._on_keep_alive_timeout) if restart: # Do this after self._keep_alive_timer is set, because self._publish used it check if it should # publish self._publish_all()
def _init_socket_handlers(self): if self._socket_watch is not None: gobject.source_remove(self._socket_watch) self._socket_watch = gobject.io_add_watch(self._client.socket().fileno(), gobject.IO_IN, self._on_socket_in) if self._socket_timer is None: self._socket_timer = gobject.timeout_add_seconds(1, exit_on_error, self._on_socket_timer)
def _on_disconnect(self, client, userdata, rc): logging.error('[Disconnected] Lost connection to broker') if self._socket_watch is not None: gobject.source_remove(self._socket_watch) self._socket_watch = None logging.info('[Disconnected] Set timer') gobject.timeout_add(5000, exit_on_error, self._reconnect)
def cancel_benchmark(self): self.stop_benchmark() gobject.source_remove(self.countdown_event) self.get('hbox_status').set_visible(False) self.get('seconds_spinbox').set_sensitive(True) self.get('hbox_buttons').set_visible(True)
def _unregister_state_timeout(self): if self.state_timeout is not None: gobject.source_remove(self.state_timeout) self.state_timeout = None # _unregister_state_timeout()
def stop(self): self.dot_widget.animation = NoAnimation(self.dot_widget) if self.timeout_id is not None: gobject.source_remove(self.timeout_id) self.timeout_id = None
def destroy(self, w): if MPI_ENABLED: if mpi.rank == 0: if self.thread is None: wake_nodes(1) mpi.bcast(None) else: wake_nodes(3) gobject.source_remove(self.pbar_timer) gtk.main_quit()
def _reset(self): if self._find_child_hfp_modem: try: gobject.source_remove(self._poll_for_child_hfp_modem_id) except: pass self._poll_for_child_hfp_modem_id = None
def stop_scrsaver(self): """stop screen saver""" if self.scr_timer_id: gobject.source_remove(self.scr_timer_id) if self.video_playing: self.movie_type = '' self.video_playing = False self.video_player.stop() self.drwVideo.set_property('visible', False) self.running = False self.WinMain.hide_window('scrsaver')
def stop_video(self): """stop and playing video and timer""" if self.video_timer: gobject.source_remove(self.video_timer) self.video_timer = None if self.video_playing: self.video_playing = False self.video_player.stop() self.drwVideo.set_property('visible', False) self.video_artwork_widget.set_property('visible', True) self.do_events()
def show_results(self, timed_out=False): # At this point we either have all our output or we give up waiting self.stop_benchmark() if self.output_timeout: gobject.source_remove(self.output_timeout) if self.more_output: gobject.source_remove(self.more_output) upload_col = self.get('upload_column') download_col = self.get('download_column') upload_col.set_cell_data_func(self.get('cellrenderertext2'), self.data_func, 1) download_col.set_cell_data_func(self.get('cellrenderertext3'), self.data_func, 2) results_n = len(self.results) if results_n > 0: graph_entries = [] total_up = 0 total_down = 0 # List all the clients regardless of if we received measurements for client_ip in self.clients: client_name = self.clients[client_ip][1] if client_ip in self.results: up, down = self.results[client_ip] else: up, down = (0,0) graph_entries.append((client_name, bits_to_mbits(up), bits_to_mbits(down))) self.get('results_store').append([client_name, up, down]) total_up += up total_down += down self.graph = self.create_graph(graph_entries) self.graph.set_visible(True) self.dlg.set_visible(False) results_dlg = self.get('results_dialog') results_dlg.set_transient_for(self.parent) results_dlg.show_all() clients_n = len(self.clients) self.get('avg_client').set_text(humanize(total_up / clients_n, unit='bps')) self.get('total_client').set_text(humanize(total_up, unit='bps')) self.get('avg_server').set_text(humanize(total_down / clients_n, unit='bps')) self.get('total_server').set_text(humanize(total_down, unit='bps')) if timed_out: self.get('warning_hbox').show() else: self.get('warning_hbox').hide() else: self.error_message(_("Did not get measurements from any of the clients. Check your network settings.")) self.dlg.set_visible(False)