def startstop(self): if self.world is not None: if not self.running: self.running = True timeout_add(self.runworldinterval, self.runWorld) else: self.running = False
def connected_start(dummy: int) -> None: global conn_list conn_list = [] # Connected mode always passes timeout_add(100, fake_cn_pass, state_id)
def set_state_to(state, connections=None, timeout=180): global com_state, conn_list, state_id, points log.info('Setting state to %s' % state) state_info = state_matrix(state) nmmon.init_nmmon() state_id += 1 nmmon.enable( modemgr.get_state_device(state), state_info.pass_fn, state_info.fail_fn, state_id, ) if connections: if type(conn_list) == str: conn_list = [connections] else: conn_list = connections com_state = state timeout_add(timeout * 1000, state_info.timeout_fn, state_id) state_info.start_fn() return False
def set_state(state, connections=None, timeout=180): global com_state, conn_list, state_id, points log.info('Setting state to %s' % state) state_info = state_matrix(state) log.info("get statematrix") nmmon.init_nmmon() log.info("enable") nmmon.enable(modemgr.get_state_device(state), state_info.pass_fn, state_info.fail_fn) log.info("nmmon enabled") if connections: conn_list = connections state_id += 1 com_state = state timeout_add(timeout * 1000, state_info.timeout_fn, state_id) log.info("state_info.start_fn()") state_info.start_fn()
def _setButtons(self) -> None: """ Sets up the cancel and generate buttons. :return: """ box: Box = Box() self._main_box.pack_end(box, False, True, 0) box.set_halign(Align.CENTER) box.set_orientation(Orientation.HORIZONTAL) setMargin(box, 5) self._cancel_btn = Button(label='Cancel') box.pack_start(self._cancel_btn, False, True, 0) setMargin(self._cancel_btn, 5, 5, 100, 5) self._cancel_btn.connect('clicked', self._onCancelBtnClicked) self._generate_btn = Button(label='Generate') box.pack_end(self._generate_btn, False, True, 0) setMargin(self._generate_btn, 100, 5, 5, 5) self._generate_btn.connect('clicked', self._onGenerateBtnClicked) timeout_add(300, self._setSensitiveGenerateBtn)
def set_state( state: str, connections: List[str] = [], timeout: int = 180, force: bool = False, ) -> None: timeout_add(0, set_state_to, state, connections, timeout, force, state_id)
def check_in_thread(self): """Check source file time. This function is called from GLib.timeout_add""" if not self.__file_name: return try: last_ctime = stat(self.__file_name).st_ctime if last_ctime > self.__last_ctime: self.__pause_period = True dialog = FileChangedDialog(self.__win, self.__file_name) if dialog.run() == Gtk.ResponseType.YES: cursor = self.text_buffer.get_insert() offset = self.text_buffer.get_iter_at_mark( cursor).get_offset() self.read_from_file(self.__file_name, offset) else: self.__last_ctime = last_ctime dialog.destroy() self.__pause_period = False except OSError: pass # file switching when modify by another software timeout_add(200, self.check_in_thread)
def add_timeout_item( self, seconds=3, image=None, stock=None, icon=None, text=None, callback=None ): """Adds an item to the StatusBar for seconds""" item = self.add_item(image, stock, icon, text, callback) # Start a timer to remove this item in seconds timeout_add(seconds * 1000, self.remove_item, item)
def delete_connection(self): def to_fn(): ssid = nm.get_active_ssid(modemgr.get_link_device()) nm.del_connection_by_ssid(ssid) states.set_state('HOTSPOT') return False timeout_add(1, to_fn)
def display_warning(self, text, callback=None): """Displays a warning to the user in the status bar""" if text not in self.current_warnings: item = self.add_item( icon='dialog-warning-symbolic', text=text, callback=callback ) self.current_warnings.append(text) timeout_add(3000, self.remove_warning, item)
def ObjListUpdater(self): self.system_bus = pydbus.SystemBus() self.system_bus.subscribe(sender='org.bluez', signal='PropertiesChanged', signal_fired=self.Update_obj_list) loop = MainLoop() timeout_add(100, self.checkTerminate, loop) loop.run()
def connect(self, ssid, password): def to_fn(ssid, password): if nm.get_connection_by_ssid(ssid): nm.del_connection_by_ssid(ssid) nm.make_connection_for(ssid, password) states.set_state('CONNECTING', [ssid, ssid]) return False timeout_add(1, to_fn, ssid, password)
def any_changed_state(state: int, *args) -> None: from comitup import mdns from comitup.states import dns_names interesting_states = PASS_STATES + FAIL_STATES def reset_mdns(): mdns.clear_entries() mdns.add_hosts(dns_names) if state in interesting_states: timeout_add(0, reset_mdns)
def connect(self, ssid: str, password: str) -> None: def to_fn(ssid, password): if nm.get_connection_by_ssid(ssid): nm.del_connection_by_ssid(ssid) nm.make_connection_for( ssid, password, link_local=conf.getboolean("ipv6_link_local") ) states.set_state("CONNECTING", [ssid, ssid]) return False timeout_add(1, to_fn, ssid, password)
def runWorld(self): if self.running: if not self.world.finished: if self.world.currentState == self.world.totalStates: self.world.stepForward() self.updateDrawingArea() self.updateComlist() self.updatebeedebug() self.updatetime() timeout_add(self.runworldinterval, self.runWorld) else: self.startstop() self.logline("Finished in " + str(self.world.timeToFinish) + " seconds using " + str(self.world.totalStates) + " states!\nEnergy consumed: " + str(self.world.beeSteps) + "\nSpace needed: " + str(self.world.sizeOfWorld))
def init_states(hosts, callbacks): global hotspot_name nmmon.init_nmmon() set_hosts(*hosts) for callback in callbacks: add_state_callback(callback) hotspot_name = dns_to_conn(hosts[0]) assure_hotspot(hotspot_name, modemgr.get_ap_device()) timeout_add(10 * 1000, state_monitor)
def init_states(hosts, callbacks, hotspot_pw): global hotspot_name nmmon.init_nmmon() set_hosts(*hosts) for callback in callbacks: add_state_callback(callback) hotspot_name = dns_to_conn(hosts[0]) assure_hotspot(hotspot_name, modemgr.get_ap_device()) # Set an early kick to set CONNECTING mode set_state('HOTSPOT') timeout_add(5 * 1000, hotspot_timeout, state_id)
def hotspot_start(): global conn_list log.info("Activating hotspot") hs_ssid = dns_to_conn(dns_names[0]) log.debug("states: Calling nm.get_active_ssid()") if hs_ssid != nm.get_active_ssid(modemgr.get_state_device('HOTSPOT')): conn_list = [] activate_connection(hs_ssid, 'HOTSPOT') else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass, state_id)
def __init__(self, win, preferences, action_name=None): super(SourceView, self).__init__() if action_name: self.action_name = action_name self.set_hexpand(True) self.set_vexpand(True) self.text_buffer = Buffer.new_with_language(LANGS['.%s' % preferences.parser]) self.text_buffer.connect("changed", self.inc_changes) # TODO: will work when FileSaver and FileLoader will be used # self.text_buffer.set_implicit_trailing_newline(False) self.source_view = View.new_with_buffer(self.text_buffer) adj = self.get_vadjustment() adj.connect("value-changed", self.on_scroll_changed) self.spellchecker = Checker() self.spellchecker.connect("language-changed", self.on_language_changed) self.source_view.override_font( FontDescription.from_string('Monospace')) # self.source_view.set_monospace(True) since 3.16 self.add(self.source_view) editor_pref = preferences.editor self.set_period_save(editor_pref.period_save) self.set_check_spelling(editor_pref.check_spelling, editor_pref.spell_lang) self.set_spaces_instead_of_tabs(editor_pref.spaces_instead_of_tabs) self.source_view.set_tab_width(editor_pref.tab_width) self.source_view.set_auto_indent(editor_pref.auto_indent) self.source_view.set_show_line_numbers(editor_pref.line_numbers) self.source_view.set_show_right_margin(editor_pref.right_margin) self.source_view.set_highlight_current_line(editor_pref.current_line) self.set_text_wrapping(editor_pref.text_wrapping) self.set_white_chars(editor_pref.white_chars) self.search_settings = SearchSettings(wrap_around=True) self.search_context = SearchContext.new(self.text_buffer, self.search_settings) self.search_mark = None self.__win = win timeout_add(200, self.check_in_thread)
def set_state(state, connections=None, timeout=180): global com_state, conn_list, state_id, points log.info('Setting state to %s' % state) if com_state != 'HOTSPOT': points = nm.get_points_ext(modemgr.get_state_device(com_state)) state_info = state_matrix(state) nmmon.set_device_callbacks(state, state_info.pass_fn, state_info.fail_fn) if connections: conn_list = connections state_id += 1 com_state = state state_info.start_fn() timeout_add(timeout * 1000, state_info.timeout_fn, state_id)
def set_state_to( state: str, connections: List[str], timeout: int, force: bool, curr_state_id: int, ): global com_state, conn_list, state_id if state == com_state and not force: return False if curr_state_id < state_id: return False log.info("Setting state to %s" % state) state_info: state_matrix = state_matrix(state) nmmon.init_nmmon() state_id += 1 nmmon.enable( modemgr.get_state_device(state), state_info.pass_fn, state_info.fail_fn, state_id, ) if state in ["CONNECTED", "HOTSPOT"]: nmmon.enhance_fail_states() if connections: conn_list = connections com_state = state timeout_add(timeout * 1000, state_info.timeout_fn, state_id, 0) state_info.start_fn(0) return False
def connecting_start(dummy: int) -> None: global conn_list, connection dev = modemgr.get_state_device("CONNECTED") full_conn_list = candidate_connections(dev) active_ssid = nm.get_active_ssid(modemgr.get_state_device("CONNECTED")) if active_ssid in full_conn_list: log.debug("Didn't need to connect - already connected") connection = active_ssid # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_cg_pass, state_id) else: if conn_list: log.debug("states: Calling nm.disconnect()") nm.disconnect(modemgr.get_state_device("CONNECTING")) conn = conn_list.pop(0) log.info("Attempting connection to %s" % conn) activate_connection(conn, "CONNECTING") else: set_state("HOTSPOT")
def hotspot_start(): global conn_list log.info("Activating hotspot") hs_ssid = dns_to_conn(dns_names[0]) # if we are in two-wifi device mode, skip the reconnect if possible, # to avoid kicking some clients off if hs_ssid != nm.get_active_ssid(modemgr.get_state_device('HOTSPOT')): mdns.clear_entries() conn_list = [] # tolerate Raspberry Pi 2 try: activate_connection(hs_ssid, 'HOTSPOT') except DBusException: log.warn("Error connecting hotspot") else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass)
def hotspot_start(dummy: int) -> None: global conn_list log.info("Activating hotspot") if startup: mdns.clear_entries() mdns.add_hosts(dns_names) hs_ssid: str = dns_to_conn(dns_names[0]) if startup and modemgr.get_mode() == modemgr.SINGLE_MODE: log.debug("Passing on hotspot connection for now") timeout_add(100, fake_hs_pass, state_id) elif hs_ssid != nm.get_active_ssid(modemgr.get_state_device("HOTSPOT")): conn_list = [] log.debug("Activating connection {}".format(hs_ssid)) activate_connection(hs_ssid, "HOTSPOT") else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass, state_id)
def _onCancelBtnClicked(self, _) -> None: """ Handle the clicked event for the second_cancel_button button. :param widget: Button object. :return: """ if not self._cur_progress: self._generate_btn.set_sensitive(True) self.close() else: self.setCancelTaskStatus(True) self._cur_progress = 0 self._progress_bar.set_fraction(self._cur_progress) self._progress_bar.set_show_text(True) timeout_add(300, self._setSensitiveCancelBtn) self._cur_progress = 0 self._progress_bar.set_fraction(self._cur_progress)
def update_status_bar(self): """Attempts to update status bar""" # If there are no queued torrents.. remove statusbar widgets and return if len(self.queue) == 0: if self.status_item is not None: component.get('StatusBar').remove_item(self.status_item) self.status_item = None return False try: component.get('StatusBar') except Exception: # The statusbar hasn't been loaded yet, so we'll add a timer to # update it later. timeout_add(100, self.update_status_bar) return False # Set the label text for statusbar if len(self.queue) > 1: label = str(len(self.queue)) + _(' Torrents Queued') else: label = str(len(self.queue)) + _(' Torrent Queued') # Add the statusbar items if needed, or just modify the label if they # have already been added. if self.status_item is None: self.status_item = component.get('StatusBar').add_item( icon='view-sort-descending', text=label, callback=self.on_statusbar_click, ) else: self.status_item.set_text(label) # We return False so the timer stops return False
def send_cb(cb): def cb_to(cb): cb() return False timeout_add(1, cb_to, cb)
def start(self): # Start inactive timer or update if it is active if not self.active: self.timer = timeout_add(self.interval, self.handler) self.active = True
def checkTerminate(self, loop): if self.TerminateFlag is True: loop.quit() else: timeout_add(100, self.checkTerminate, loop)
def _setButtonsSignals(self) -> None: """ Set up the buttons and their respective signals for both grids. :param win: A window. :param fst_grid: The first grid container where the buttons goes in. :param box: The box container where the first grid goes in. :param fc_s: A list with file choosers. :return: """ del_img: Optional[Pixbuf] img_path: str = path.abspath('asts/Icons/delete.png') try: del_img = Pixbuf().new_from_file_at_scale(img_path, 20, 20, False) except GLib_Error: exit(f'{img_path} file not found. Failed to create pixbuf.') icons: List[Optional[Image]] = [ Image().new_from_pixbuf(del_img) for _ in range(4) ] btns: List[Button] = [Button() for _ in range(4)] for (idx, btn) in enumerate(btns): btn.set_image(icons[idx]) setMargin(btn, 0, 5, 0, 5) btn.set_halign(Align.END) self._fst_grid.attach(btn, 2, idx, 1, 1) btns[FileType.ANKI2_COLLECTION].connect( 'clicked', lambda _: self._fc_s[FileType.ANKI2_COLLECTION].unselect_all()) btns[FileType.VIDEO].connect( 'clicked', lambda _: self._fc_s[FileType.VIDEO].unselect_all()) btns[FileType.SUBTITLE].connect( 'clicked', lambda _: self._fc_s[FileType.SUBTITLE].unselect_all()) btns[FileType.O_SUBTITLE].connect( 'clicked', lambda _: self._fc_s[FileType.O_SUBTITLE].unselect_all()) box: Box = Box() self._box.pack_end(box, False, True, 0) box.set_orientation(Orientation.HORIZONTAL) box.set_halign(Align.CENTER) cancel_btn: Button = Button(label='Cancel') box.pack_start(cancel_btn, False, True, 0) cancel_btn.set_margin_bottom(10) cancel_btn.connect('clicked', lambda _: self.close()) self._next_btn = Button(label='Next') box.pack_end(self._next_btn, False, True, 0) setMargin(self._next_btn, 200, 10, 0, 0) self._next_btn.connect('clicked', self._onNextBtnClicked) timeout_add(300, self._setSensitiveNextBtn) timeout_add(300, self._checkInvalidSelection)
def set_state(state, connections=None, timeout=180): timeout_add(0, set_state_to, state, connections, timeout)
def connected_fail(): log.warning('Connection lost') set_state('HOTSPOT') timeout_add(5 * 1000, hotspot_timeout, state_id)