def __init__(self): DBG('Init module') self.monitor_off_after = 0 self.ssaver_on_after = 0 self.only_in_fs = True self.status = 0 # 0=inactive 1=ss_active 2=monitor_off self.last_event_time = time.time() # create ini options if not exists (with defaults) ini.add_section('screensaver') ini.get('screensaver', 'screensaver_on_after', _('never')) ini.get('screensaver', 'screensaver_on_cmd', 'xset s activate') ini.get('screensaver', 'screensaver_off_cmd', 'xset s reset') ini.get('screensaver', 'monitor_off_after', _('never')) ini.get('screensaver', 'monitor_off_cmd', 'xset dpms force off') ini.get('screensaver', 'monitor_on_cmd', 'xset dpms force on') ini.get('screensaver', 'only_in_fs', 'True') # read config values self.parse_config() # register the config item cgui.root_item_add('ssaver', 40, _('Screen saver'), 'icon/evas', self.config_gui_cb) # start the timer self.timer = Timer(50.0, self.timer_cb) # listen to broadcasts events (we need the KEEP_ALIVE event) events.listener_add('screensaveer', self.event_cb)
def _tt_text_replace_timed(obj, data, *args, **kargs): timer = data.get("timer") if timer: timer.delete() del data["timer"] obj.text_set("Simple text tooltip, click to start changed timed") return data["timer"] = Timer(1.5, _tt_text_replace_timer_cb, obj, data) obj.text_set("Simple text tooltip, click to stop changed timed")
def begin_test(obj, *args, **kwargs): (pb1, pb2, pb3, pb4, pb5, pb6, pb7, pb8) = args pb2.pulse(True) pb5.pulse(True) pb7.pulse(True) global my_progressbar_run global my_progressbar_timer if not my_progressbar_run: my_progressbar_timer = Timer(0.1, pb_timer_cb, *args) my_progressbar_run = True
def changed_cb(self, widget, *args): func, delay = args[-2:] if delay: if self.save_timer is not None: self.save_timer.delete() self.save_timer = Timer(2.0, self.save_cb, func) else: self.save_cb(func)
def cb_btn3_clicked(bt, ly): ly.edje.part_external_object_get("ext_pbar1").value = 0.0 for part_name in ["ext_pbar2", "ext_pbar5", "ext_pbar7"]: ly.edje.part_external_object_get(part_name).pulse_mode = True ly.edje.part_external_object_get(part_name).pulse(True) for part_name in ["ext_button1", "ext_button2", "ext_button3"]: ly.edje_get().part_external_object_get(part_name).disabled = True Timer(0.1, animate, ly)
def gl_obj_mouse_down(obj, event_info, data): # Launch a timer to start drag animation anim_st = DragAnimSt() anim_st.e = obj.evas anim_st.mdx = event_info.position.canvas.x anim_st.mdy = event_info.position.canvas.y anim_st.gl = data anim_st.tm = Timer(DRAG_TIMEOUT, gl_anim_start, anim_st) data.event_callback_add(EVAS_CALLBACK_MOUSE_UP, gl_obj_mouse_up, anim_st) data.event_callback_add(EVAS_CALLBACK_MOUSE_MOVE, gl_obj_mouse_move, anim_st)
def animate(ly): val = ly.edje.part_external_object_get("ext_pbar1").value val += 0.0123 for part_name in ["ext_pbar1", "ext_pbar3", "ext_pbar4", "ext_pbar6"]: ly.edje.part_external_object_get(part_name).value = val if val < 1: Timer(0.1, animate, ly) else: for part_name in ["ext_pbar2", "ext_pbar5", "ext_pbar7"]: ly.edje.part_external_object_get(part_name).pulse(False) ly.edje.part_external_object_get(part_name).pulse_mode = False for part_name in ["ext_button1", "ext_button2", "ext_button3"]: ly.edje_get().part_external_object_get(part_name).disabled = False return False
def populate_page(self, doc, itr): try: pg_num = next(itr) pg = doc.getPage(pg_num) except StopIteration: if self.doc_pos is not None: self.scr.region_show(*self.doc_pos) def outlines_get(): self.outlines = doc.outlines t1 = time.clock() t = Thread(target=outlines_get) t.daemon = True t.start() def check_outlines(t): if t.is_alive(): return True t2 = time.clock() log.info("Fetching outlines took: %f", t2 - t1) self.outlines_populate(self.outlines) self.load_notify.content.pulse(False) self.load_notify.hide() self.outlines_timer = Timer(0.2, check_outlines, t) return False mbox = pg.mediaBox w, h = mbox[2], mbox[3] box = self.page_box page = Page(box, self.doc_path, pg_num, w, h, self.zoom) page.callback_add("viewport,in", self._viewport_in, self.page_notify) page.callback_add("viewport,out", self._viewport_out, self.page_notify) box.pack_end(page) page.show() self.pages.append((pg.indirectRef.idnum, page)) return True
class ScreenSaver(EmcModule): name = 'screensaver' label = _('Screen saver') icon = 'icon/evas' info = _('This module manage the X screensaver. It will prevent the ' 'screensaver to activate while watching videos and can be ' 'configured to activate the screensaver and/or shutdown your ' 'monitor after a given amount of time.') def __init__(self): DBG('Init module') self.monitor_off_after = 0 self.ssaver_on_after = 0 self.only_in_fs = True self.status = 0 # 0=inactive 1=ss_active 2=monitor_off self.last_event_time = time.time() # create ini options if not exists (with defaults) ini.add_section('screensaver') ini.get('screensaver', 'screensaver_on_after', _('never')) ini.get('screensaver', 'screensaver_on_cmd', 'xset s activate') ini.get('screensaver', 'screensaver_off_cmd', 'xset s reset') ini.get('screensaver', 'monitor_off_after', _('never')) ini.get('screensaver', 'monitor_off_cmd', 'xset dpms force off') ini.get('screensaver', 'monitor_on_cmd', 'xset dpms force on') ini.get('screensaver', 'only_in_fs', 'True') # read config values self.parse_config() # register the config item cgui.root_item_add('ssaver', 40, _('Screen saver'), 'icon/evas', self.config_gui_cb) # start the timer self.timer = Timer(50.0, self.timer_cb) # listen to broadcasts events (we need the KEEP_ALIVE event) events.listener_add('screensaveer', self.event_cb) def __shutdown__(self): DBG('Shutdown module') events.listener_del('screensaveer') cgui.root_item_del('ssaver') self.timer.delete() self.timer = None def parse_config(self): # get someting like "5 minutes" from config try: ssaver_on_after = ini.get('screensaver', 'screensaver_on_after') ssaver_on_after = int(re.sub('[^0-9]', '', ssaver_on_after)) self.ssaver_on_after = ssaver_on_after * 60 except: self.ssaver_on_after = 0 # get someting like "10 minutes" from config try: monitor_off_after = ini.get('screensaver', 'monitor_off_after') monitor_off_after = int(re.sub('[^0-9]', '', monitor_off_after)) self.monitor_off_after = monitor_off_after * 60 except: self.monitor_off_after = 0 # whenever to manage the ss only when in fullscreen self.only_in_fs = ini.get_bool('screensaver', 'only_in_fs') def event_cb(self, event): if event == 'KEEP_ALIVE': self.last_event_time = time.time() if self.status != 0: self.status = 0 self.timer_cb() def timer_cb(self): # nothing to do if self.ssaver_on_after == self.monitor_off_after == 0: return ECORE_CALLBACK_RENEW # not when windowed if self.only_in_fs is True and not gui.win.fullscreen: return ECORE_CALLBACK_RENEW # DBG("SS on after: %ds MON off after: %ds (only fs: %s)" % # (self.ssaver_on_after, self.monitor_off_after, self.only_in_fs)) # calc elapsed time since last STAY_ALIVE event now = time.time() elapsed = now - self.last_event_time DBG('ScreenSaver: Timer! status: %d elapsed: %.0fs ss_on_in: %.0fs mon_off_in: %.0fs' % \ (self.status, elapsed, self.last_event_time + self.ssaver_on_after - now if self.ssaver_on_after > 0 else -1, self.last_event_time + self.monitor_off_after - now if self.monitor_off_after > 0 else -1)) def exe_run_safe(cmd): try: DBG("Executing: '%s'" % cmd) Exe(cmd) except: pass if self.status == 0: # Status 0: the screensaver is off - user is active if elapsed > self.ssaver_on_after > 0: # turn on the screensaver DBG('ScreenSaver: activate screensaver') self.status = 1 exe_run_safe(ini.get('screensaver', 'screensaver_on_cmd')) elif elapsed > self.monitor_off_after > 0: # turn off the monitor DBG('ScreenSaver: monitor off') self.status = 2 exe_run_safe(ini.get('screensaver', 'monitor_off_cmd')) else: # or keep the screensaver alive and the monitor on DBG('ScreenSaver: keep alive') exe_run_safe(ini.get('screensaver', 'monitor_on_cmd')) exe_run_safe(ini.get('screensaver', 'screensaver_off_cmd')) elif self.status == 1: # Status 1: the screensaver is on - user is away if elapsed > self.monitor_off_after > 0: # turn off the monitor DBG('ScreenSaver: monitor off') self.status = 2 exe_run_safe(ini.get('screensaver', 'monitor_off_cmd')) # the screensaver has been disabled outside epymc if elapsed < self.ssaver_on_after > 0: self.status = 0 elif self.status == 2: # Status 2: the monitor is off - user probably sleeping :) # the monitor has been turned on outside epymc if elapsed < self.monitor_off_after > 0: self.status = 0 return ECORE_CALLBACK_RENEW def config_gui_cb(self): bro = cgui.browser_get() bro.page_add('config://ssaver/', _('Screen saver'), None, self.config_gui_populate) def config_gui_populate(self, browser, url): L = _('never;1 minute;5 minutes;10 minutes;30 minutes;60 minutes').split(';') cgui.standard_item_string_from_list_add('screensaver', 'screensaver_on_after', _('Turn on screensaver after'), L, cb = self.parse_config) cgui.standard_item_string_from_list_add('screensaver', 'monitor_off_after', _('Turn off monitor after'), L, cb = self.parse_config) cgui.standard_item_bool_add('screensaver', 'only_in_fs', _('Manage screensaver only in fullscreen'), cb = self.parse_config)
def my_gl_flush(bt, gl): def my_gl_flush_delay(): cache_all_flush() Timer(1.2, my_gl_flush_delay)
def __init__(self, parent, path, pos=None, zoom=1.0): self.doc_path = path self._zoom = zoom self.doc_pos = pos self.pages = [] self.doc = None self.doc_title = os.path.splitext(os.path.basename(path))[0] self.visible_pages = [] super(Document, self).__init__( parent, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) scr = self.scr = Scroller( self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) scr.callback_scroll_add(self._scrolled) self.pack(scr, 0, 0, 4, 5) scr.show() box = self.page_box = Box( scr, size_hint_weight=EXPAND_BOTH, size_hint_align=(0.5, 0.0)) scr.content = box self.on_resize_add(self._resized) btn = Button( self, text="Toggle outlines", size_hint_align=ALIGN_LEFT) btn.callback_clicked_add(lambda x: self.ol_p.toggle()) self.pack(btn, 0, 5, 1, 1) btn.show() spn = self.spn = Spinner( self, round=1.0, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) spn.special_value_add(1, "First") spn.editable = True self.pack(spn, 1, 5, 1, 1) spn.show() btn = Button( self, text="show page", size_hint_weight=EXPAND_HORIZ, size_hint_align=ALIGN_LEFT) btn.callback_clicked_add(self._show_page_cb, spn) self.pack(btn, 2, 5, 1, 1) btn.show() menu = Menu(self.top_widget) menu.item_add( None, "Zoom In", "zoom-in", lambda x, y: self.zoom_in()) menu.item_add( None, "Zoom Out", "zoom-out", lambda x, y: self.zoom_out()) menu.item_add( None, "Zoom 1:1", "zoom-original", lambda x, y: self.zoom_orig()) menu.item_add( None, "Zoom Fit", "zoom-fit-best", lambda x, y: self.zoom_fit()) def z_clicked(btn): x, y = btn.evas.pointer_canvas_xy_get() menu.move(x, y) menu.show() zlbl = self.zlbl = Button( self, text="%1.0f %%" % (self.zoom * 100.0), size_hint_weight=EXPAND_HORIZ, size_hint_align=ALIGN_RIGHT) zlbl.callback_clicked_add(z_clicked) self.pack(zlbl, 3, 5, 1, 1) zlbl.show() n = self.page_notify = Notify(scr, align=(0.02, 0.02)) b = Box(n, horizontal=True, padding=(6, 0)) n.content = b n = self.load_notify = Notify(scr, align=(0.98, 0.98)) pb = Progressbar(n, pulse_mode=True, style="wheel") n.content = pb pb.pulse(True) n.show() p = self.ol_p = Panel( self, orient=ELM_PANEL_ORIENT_LEFT, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, ) #scrollable=True, scrollable_content_size=0.35) p.hidden = True scr.on_move_add(lambda x: p.move(*x.pos)) scr.on_resize_add(lambda x: p.resize(x.size[0] * 0.35, x.size[1])) ol_gl = self.ol_gl = Genlist( p, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, mode=ELM_LIST_COMPRESS, homogeneous=True, select_mode=ELM_OBJECT_SELECT_MODE_ALWAYS ) p.content = ol_gl ol_gl.callback_contract_request_add(self._gl_contract_req) ol_gl.callback_contracted_add(self._gl_contracted) ol_gl.callback_expand_request_add(self._gl_expand_req) ol_gl.callback_expanded_add(self._gl_expanded) ol_gl.show() p.show() self.show() def read_worker(): t1 = self.t1 = time.clock() try: self.doc = PyPDF2.PdfFileReader(path) self.page_count = self.doc.getNumPages() except Exception as e: log.exception("Document could not be opened because: %r", e) return t2 = time.clock() log.info("Reading the doc took: %f", t2-t1) t = Thread(target=read_worker) t.daemon = True t.start() def worker_check(t): if t.is_alive(): return True if self.doc and self.page_count: spn.special_value_add(self.page_count, "Last") spn.min_max = (1, self.page_count) if self.doc.isEncrypted: PasswordPrompt(self) return False self.metadata_read() self.populate_pages() return False self.load_notify.content.delete() l = Label( self.load_notify, style="marker", text="Document load error", color=(255, 0, 0, 255)) self.load_notify.content = l l.show() timer = Timer(0.2, worker_check, t) self.parent.callback_delete_request_add(lambda x: timer.delete())
def __init__(self, parent, session): self.parent = parent self.session = session elm_conf = Configuration() scale = elm_conf.scale self.log = logging.getLogger("epour.gui") self.torrentitems = {} win = self.win = StandardWindow("epour", "Epour") win.callback_delete_request_add(lambda x: elm.exit()) win.screen_constrain = True win.size = 480 * scale, 400 * scale mbox = Box(win) mbox.size_hint_weight = 1.0, 1.0 win.resize_object_add(mbox) mbox.show() tb = Toolbar(win) tb.homogeneous = False tb.shrink_mode = ELM_TOOLBAR_SHRINK_NONE tb.select_mode = ELM_OBJECT_SELECT_MODE_NONE tb.size_hint_align = -1.0, 0.0 tb.menu_parent = win item = tb.item_append("document-new", "Add torrent", lambda t, i: self.select_torrent()) def pause_session(it): self.session.pause() it.state_set(it.state_next()) def resume_session(it): session.resume() del it.state item = tb.item_append("media-playback-pause", "Pause Session", lambda tb, it: pause_session(it)) item.state_add("media-playback-start", "Resume Session", lambda tb, it: resume_session(it)) item = tb.item_append("preferences-system", "Preferences") item.menu = True item.menu.item_add(None, "General", "preferences-system", lambda o, i: PreferencesGeneral(self, self.session)) item.menu.item_add(None, "Proxy", "preferences-system", lambda o, i: PreferencesProxy(self, self.session)) item.menu.item_add(None, "Session", "preferences-system", lambda o, i: PreferencesSession(self, self.session)) item = tb.item_append("application-exit", "Exit", lambda tb, it: elm.exit()) mbox.pack_start(tb) tb.show() self.tlist = tlist = Genlist(win) tlist.select_mode = ELM_OBJECT_SELECT_MODE_NONE tlist.mode = ELM_LIST_COMPRESS tlist.callback_activated_add(self.item_activated_cb) tlist.homogeneous = True tlist.size_hint_weight = 1.0, 1.0 tlist.size_hint_align = -1.0, -1.0 tlist.show() mbox.pack_end(tlist) pad = Rectangle(win.evas) pad.size_hint_weight = 1.0, 1.0 p = Panel(win) p.color = 200, 200, 200, 200 p.size_hint_weight = 1.0, 1.0 p.size_hint_align = -1.0, -1.0 p.orient = ELM_PANEL_ORIENT_BOTTOM p.content = SessionStatus(win, session) p.hidden = True p.show() topbox = Box(win) topbox.horizontal = True topbox.size_hint_weight = 1.0, 1.0 win.resize_object_add(topbox) topbox.pack_end(pad) topbox.pack_end(p) topbox.stack_above(mbox) topbox.show() session.alert_manager.callback_add("torrent_added_alert", self.torrent_added_cb) session.alert_manager.callback_add("torrent_removed_alert", self.torrent_removed_cb) for a_name in "torrent_paused_alert", "torrent_resumed_alert": session.alert_manager.callback_add(a_name, self.update_icon) session.alert_manager.callback_add("state_changed_alert", self.state_changed_cb) Timer( 15.0, lambda: session.alert_manager.callback_add( "torrent_finished_alert", self.torrent_finished_cb))
def __init__(self, parent, session): Table.__init__(self, parent) self.session = session s = session.status() self.padding = 5, 5 ses_pause_ic = self.ses_pause_ic = Icon(parent) ses_pause_ic.size_hint_align = -1.0, -1.0 try: if session.is_paused(): ses_pause_ic.standard = "player_pause" else: ses_pause_ic.standard = "player_play" except RuntimeError: self.log.debug("Setting session ic failed") self.pack(ses_pause_ic, 1, 0, 1, 1) ses_pause_ic.show() title_l = Label(parent) title_l.text = "<b>Session</b>" self.pack(title_l, 0, 0, 1, 1) title_l.show() d_ic = Icon(parent) try: d_ic.standard = "down" except RuntimeError: self.log.debug("Setting d_ic failed") d_ic.size_hint_align = -1.0, -1.0 self.pack(d_ic, 0, 2, 1, 1) d_ic.show() d_l = self.d_l = Label(parent) d_l.text = "{}/s".format(intrepr(s.payload_download_rate)) self.pack(d_l, 1, 2, 1, 1) d_l.show() u_ic = Icon(self) try: u_ic.standard = "up" except RuntimeError: self.log.debug("Setting u_ic failed") u_ic.size_hint_align = -1.0, -1.0 self.pack(u_ic, 0, 3, 1, 1) u_ic.show() u_l = self.u_l = Label(parent) u_l.text = "{}/s".format(intrepr(s.payload_upload_rate)) self.pack(u_l, 1, 3, 1, 1) u_l.show() peer_t = Label(parent) peer_t.text = "Peers" self.pack(peer_t, 0, 4, 1, 1) peer_t.show() peer_l = self.peer_l = Label(parent) peer_l.text = str(s.num_peers) self.pack(peer_l, 1, 4, 1, 1) peer_l.show() self.show() self.update_timer = Timer(1.0, self.update)
def run(self): self.win.show() self.timer = Timer(1.0, self.update) elm.run() self.quit()
def __init__(self, parent, path, pos=None, zoom=1.0): self.doc_path = path self._zoom = zoom self.doc_pos = pos self.pages = [] self.doc = None self.doc_title = os.path.splitext(os.path.basename(path))[0] self.visible_pages = [] super(Document, self).__init__(parent, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) scr = self.scr = Scroller(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH) scr.callback_scroll_add(self._scrolled) self.pack(scr, 0, 0, 4, 1) scr.show() box = self.page_box = Box(scr, size_hint_weight=EXPAND_BOTH, size_hint_align=(0.5, 0.0)) scr.content = box self.on_resize_add(self._resized) btn = Button(self, text="Toggle outlines", size_hint_align=ALIGN_LEFT) btn.callback_clicked_add(lambda x: self.ol_p.toggle()) self.pack(btn, 0, 1, 1, 1) btn.show() spn = self.spn = Spinner(self, round=1.0, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_HORIZ) spn.special_value_add(1, "First") spn.editable = True self.pack(spn, 1, 1, 1, 1) spn.show() btn = Button(self, text="show page", size_hint_weight=EXPAND_HORIZ, size_hint_align=ALIGN_LEFT) btn.callback_clicked_add(self._show_page_cb, spn) self.pack(btn, 2, 1, 1, 1) btn.show() menu = Menu(self.top_widget) menu.item_add(None, "Zoom In", "zoom-in", lambda x, y: self.zoom_in()) menu.item_add(None, "Zoom Out", "zoom-out", lambda x, y: self.zoom_out()) menu.item_add(None, "Zoom 1:1", "zoom-original", lambda x, y: self.zoom_orig()) menu.item_add(None, "Zoom Fit", "zoom-fit-best", lambda x, y: self.zoom_fit()) def z_clicked(btn): x, y = btn.evas.pointer_canvas_xy_get() menu.move(x, y) menu.show() zlbl = self.zlbl = Button(self, text="%1.0f %%" % (self.zoom * 100.0), size_hint_weight=EXPAND_HORIZ, size_hint_align=ALIGN_RIGHT) zlbl.callback_clicked_add(z_clicked) self.pack(zlbl, 3, 1, 1, 1) zlbl.show() n = self.page_notify = Notify(scr, align=(0.02, 0.02)) b = Box(n, horizontal=True, padding=(6, 0)) n.content = b n = self.load_notify = Notify(scr, align=(0.98, 0.98)) pb = Progressbar(n, pulse_mode=True, style="wheel") n.content = pb pb.pulse(True) n.show() p = self.ol_p = Panel( self, orient=ELM_PANEL_ORIENT_LEFT, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, ) #scrollable=True, scrollable_content_size=0.35) p.hidden = True scr.on_move_add(lambda x: p.move(*x.pos)) scr.on_resize_add(lambda x: p.resize(x.size[0] * 0.35, x.size[1])) ol_gl = self.ol_gl = Genlist(p, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH, mode=ELM_LIST_COMPRESS, homogeneous=True, select_mode=ELM_OBJECT_SELECT_MODE_ALWAYS) p.content = ol_gl ol_gl.callback_contract_request_add(self._gl_contract_req) ol_gl.callback_contracted_add(self._gl_contracted) ol_gl.callback_expand_request_add(self._gl_expand_req) ol_gl.callback_expanded_add(self._gl_expanded) ol_gl.show() p.show() self.show() def read_worker(): t1 = self.t1 = time.clock() try: self.doc = PyPDF2.PdfFileReader(path) self.page_count = self.doc.getNumPages() except Exception as e: log.exception("Document could not be opened because: %r", e) self.doc = None self.display_error(e) return t2 = time.clock() log.info("Reading the doc took: %f", t2 - t1) t = Thread(target=read_worker) t.daemon = True t.start() def worker_check(t): if t.is_alive(): return True elif self.doc and self.page_count: spn.special_value_add(self.page_count, "Last") spn.min_max = (1, self.page_count) if self.doc.isEncrypted: PasswordPrompt(self) return False self.metadata_read() self.populate_pages() return False timer = Timer(0.2, worker_check, t) self.parent.callback_delete_request_add(lambda x: timer.delete())
def __init__(self, session): self.session = session self.timer = Timer(self.update_interval, self.update)