def set_state(self, state): """Update the UI to match the new state.""" # Stop the spinner self.spn_status.stop() self.spn_status.hide() self.icn_status.show() if state == 'connecting': # Start the spinner self.icn_status.hide() self.spn_status.show() self.spn_status.start() self.lbl_status.set_text(_('Connecting to %s...') % self.host) self.btn_action.set_label(Gtk.STOCK_DISCONNECT) elif state == 'connected': self.connected = True self.icn_status.set_from_stock(Gtk.STOCK_YES, Gtk.IconSize.BUTTON) self.lbl_status.set_text(_('Connected to %s') % self.host) self.btn_action.set_label(Gtk.STOCK_DISCONNECT) elif state == 'disconnected': msg = _('Not connected') self.icn_status.set_from_stock(Gtk.STOCK_NO, Gtk.IconSize.BUTTON) self.lbl_status.set_text(msg) elif state == 'failed': msg = _('Failed to connect to %s') % self.host self.lbl_status.set_text(msg) self.icn_status.set_from_stock(Gtk.STOCK_DIALOG_ERROR, Gtk.IconSize.BUTTON) if self.retry: self.update_and_retry(msg, self.retry_interval) self.btn_action.set_label(Gtk.STOCK_DISCONNECT) else: self.btn_action.set_label(Gtk.STOCK_CONNECT)
def main(): """Run the module from the command line.""" if len(sys.argv) <= 1 or len(sys.argv) > 5: print(_("Usage: {} text [title] [markup] [icon_name]").format( os.path.basename(__file__)), file=sys.stderr) exit(1) text = sys.argv[1] if len(sys.argv) > 2 and sys.argv[2]: title = sys.argv[2] else: title = "Epoptes" if len(sys.argv) > 3 and sys.argv[3]: markup = sys.argv[3].lower() == "true" else: markup = True if len(sys.argv) > 4: icon_name = sys.argv[4] else: icon_name = "dialog-information" window = MessageWindow(text, title, markup, icon_name) window.connect("destroy", Gtk.main_quit) window.show_all() Gtk.main()
def main(): """Run the module from the command line.""" if len(sys.argv) == 3: sys.stdout.buffer.flush() sys.stdout.buffer.write(thumbshot(int(sys.argv[1]), int(sys.argv[2]))) sys.stdout.buffer.flush() else: print(_("Usage: {} width height").format(os.path.basename(__file__)), file=sys.stderr) exit(1)
def update_and_retry(self, msg, interval): """Show a "Retrying in 10..." label, and then retry.""" if interval == 0: self.on_btn_action_clicked(None) else: self.lbl_status.set_text(msg + ' ' + _('Retrying in %d...') % interval) self.retry_timeout_id = GLib.timeout_add(1000, self.update_and_retry, msg, interval - 1) return False
def main(): """Run the module from the command line.""" if len(sys.argv) > 1 and sys.argv[1]: msg = sys.argv[1] else: msg = _("The screen is locked by a system administrator.") if len(sys.argv) > 2: unlock_secs = int(sys.argv[2]) else: unlock_secs = None LockScreen(True).lock(msg, unlock_secs) Gtk.main()
def poll_process(self): """Continuously check if the spawned process has terminated.""" # If process has not terminated yet return True to continue the timeout if self.proc.poll() is None: return True else: # Check if it disconnected or failed and call the correct signal if self.connected: self.set_state('disconnected') if self.retry and not self.manually_stopped: self.update_and_retry(_('Not connected'), self.retry_interval) self.btn_action.set_label(Gtk.STOCK_DISCONNECT) self.manually_stopped = True else: self.btn_action.set_label(Gtk.STOCK_CONNECT) self.connected = False else: self.set_state('failed') self.proc = None return False