def __init__(self): # Initialize the GUI # edje.frametime_set(FRAMETIME) self.evas_canvas = EvasCanvas(FULLSCREEN) self.screens = {} # Register our own callbacks PyneoController.register_callback("gsm_phone_ringing", self.on_ringing) PyneoController.register_callback("gsm_phone_call_start", self.on_call_start) PyneoController.register_callback("gsm_phone_call_end", self.on_call_end) PyneoController.register_callback("show_gps_status_screen", self.on_gps_status_screen) PyneoController.register_callback("show_gps_map_screen", self.on_gps_map_screen) PyneoController.register_callback("show_dialer_screen", self.on_call_end) PyneoController.register_callback("show_lock_screen", self.on_lock_screen) PyneoController.register_callback("show_audio_screen", self.on_audio_screen) PyneoController.register_callback("show_screen", self.on_show_screen) # Initialize the D-Bus interface to pyneo dbus_ml = DBusEcoreMainLoop() self.system_bus = SystemBus(mainloop=dbus_ml) PyneoController.init() PyneoController.path_check(DB_PATH) PyneoController.db_check() DatabaseController.init() self.init_screen(DIALER_SCREEN_NAME, DialerScreen) PyneoController.show_dialer_screen() PyneoController.brightness_change(0) ecore.timer_add(1, self.load_screens)
def th_finished(exception, retval): if exception is not None: log.error("Exception while deleting image: %s" % exception) self.update_text("ERROR!") ecore.timer_add(2, hide_cb) return if not retval: log.error("Error while deleting image") self.update_text("ERROR!") ecore.timer_add(2, hide_cb) return if album_model.current > 0: self.screen_controller.prev() else: if album_model.current < album_model.size -1: self.screen_controller.next() album_model.size -= 1 album_model.prop["cntPhotos"] = str(album_model.size) album_model.children.remove(current_model) self.screen_controller._check_prev_next_visibility() album_model.parent.callback_update_list(current_model) self.stop()
def __do_scroll(self): self.is_scrolling = True if self.continue_scrolling == False: return diff = int(self.pixel_per_sec / 10) if abs(self.pixel_per_sec) - diff <= self.row_height: offset = self.top_pos % self.row_height if offset >= self.row_height / 2: self.sign = 1 offset = self.row_height - offset else: self.sign = -1 self.pixels_left = offset self.__do_magnetic_scroll() return if diff != 0: self.top_pos -= diff self.pixel_per_sec -= self.pixel_per_sec / 10 self.__update_screen() ecore.timer_add(0.02, self.__do_scroll)
def _on_ok_clicked(self): def cb_close(*ignored): self.close() self.parent.killall() if not self.view.username or not self.view.password: self.view.message("Username and <br>Password can't be null") ecore.timer_add(1.5, cb_close) return def refresh(session): session.login(self.view.username,self.view.password) def refresh_finished(exception, retval): def cb_close(*ignored): self.close() self.parent.killall() if exception is None: self.model.title = "Logged in as %s" % \ twitter_manager.getUserName() self.view.message("You are now logged in") ecore.timer_add(1.5, cb_close) elif isinstance(exception, AuthError): self.view.message("Login error.<br>%s" % exception.message) ecore.timer_add(1.5, cb_close) else: self.view.message("Unable to connect to server." "<br>Check your connection and <br>try again.") ecore.timer_add(1.5, cb_close) self.view.message_wait(" Trying to login...") ThreadedFunction(refresh_finished, refresh, twitter_manager).start()
def __init__(self): self.options, self.args = myOptionParser(usage="usage: %prog [options]").parse_args() edje.frametime_set(1.0 / self.options.fps) self.evas_canvas = EvasCanvas( fullscreen=not self.options.no_fullscreen, engine=self.options.engine, size=self.options.geometry ) self.groups = {} for part in ("swallow", "main", "contacts", "power"): self.groups[part] = edje_group(self, part) self.evas_canvas.evas_obj.data[part] = self.groups[part] self.groups["sms"] = pyphone_sms(self) self.evas_canvas.evas_obj.data["sms"] = self.groups["sms"] self.groups["phone"] = pyphone_phone(self) self.evas_canvas.evas_obj.data["phone"] = self.groups["phone"] self.groups["swallow"].show() self.groups["swallow"].on_key_down_add(self.on_key_down) self.groups["swallow"].part_swallow("swallow2", self.groups["main"]) self.current_group = self.groups["main"] self.previous_group = self.groups["phone"] self.in_transition = False ecore.timer_add(1.0, self.display_time) self.display_time()
def on_key_down(self, obj, event): if event.keyname in ("F6", "f"): self.evas_canvas.evas_obj.fullscreen = not self.evas_canvas.evas_obj.fullscreen elif event.keyname in ("Escape", "q"): ecore.main_loop_quit() elif event.keyname in ("F7", "plus") and not self.animate: ecore.timer_add(0.05, self.animate_zoom_in) elif event.keyname in ("F8", "minus") and not self.animate: ecore.timer_add(0.05, self.animate_zoom_out) elif event.keyname in ("Up", ) and not self.animate: delta_y = -10 for icon in self.icons: icon.set_position(icon.pos[0], icon.pos[1]-delta_y) self.current_pos = (self.current_pos[0], self.current_pos[1]-delta_y) elif event.keyname in ("Down", ) and not self.animate: delta_y = 10 for icon in self.icons: icon.set_position(icon.pos[0], icon.pos[1]-delta_y) self.current_pos = (self.current_pos[0], self.current_pos[1]-delta_y) elif event.keyname in ("Left", ) and not self.animate: delta_x = -10 for icon in self.icons: icon.set_position(icon.pos[0]-delta_x, icon.pos[1]) self.current_pos = (self.current_pos[0]-delta_x, self.current_pos[1]) elif event.keyname in ("Right", ) and not self.animate: delta_x = 10 for icon in self.icons: icon.set_position(icon.pos[0]-delta_x, icon.pos[1]) self.current_pos = (self.current_pos[0]-delta_x, self.current_pos[1]) else: print "key not recognized:", event.keyname
def wait_seconds(self,emission, source, param): data = [ param.split(',')[1] , emission] try: ecore.timer_add(float(param.split(',')[0]), self.arbitrary_signal,data) except Exception,e: print e
def cb_btn3_clicked(bt, ly): ly.edje_get().part_external_object_get("ext_pbar1").value = 0.0 for part_name in ["ext_pbar2", "ext_pbar5", "ext_pbar7"]: ly.edje_get().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 ecore.timer_add(0.1, animate, ly)
def th_finished(exception, retval): def view_close(): self.close() if not retval: self.view.throbber.text_set("ERROR!") ecore.timer_add(2, view_close) return self.close()
def on_mouse_down(self, emission, source): if not self.animate: if source in "plus": ecore.timer_add(0.05, self.animate_zoom_in) elif source in "minus": ecore.timer_add(0.05, self.animate_zoom_out) else: self.x_pos, self.y_pos = self.evas_canvas.evas_obj.evas.pointer_canvas_xy self.mouse_down = True
def preview(self, obj, *args, **kwargs): # print self.currentTheme self.prevwin = elementary.Window('preview', 0) bg = elementary.Background(self.prevwin) bg.file_set(self.currentTheme + '/preview.png') bg.show() self.prevwin.resize_object_add(bg) self.prevwin.autodel_set(True) self.prevwin.fullscreen_set(True) self.prevwin.show() ecore.timer_add(5, self.preview_close)
def sync_nextstep(self, *args, **kwargs): if self.backend.syncronizing: status = self.backend.sync_next() self._message( "%s<br><br><br>%s <a href=''>%s</a> %s <a href=''>%s</a>" % (_("Sync"), _("Emails retrieved:"), status[0], _("of"), status[1]) ) ecore.timer_add(0.1, self.sync_nextstep) else: self._mainList_populate() self._message()
def download_finished(exception, mimetype): if exception is None: log.debug("Finished download for %s, calling callback" % path) callback_downloaded() else: log.error("Error while downloading file %s from %s, error %s, trying to download again" % \ (path, url, exception)) try: os.unlink(path) except: log.info("Trying to delete nonexisting file") ecore.timer_add(0.5, download_again, url, path, model)
def _message(self, msg="", timeout=5): def inwin_close(*args, **kwarks): self.innerWin.hide() self.innerWinAnchor.hide() inwin_close() if not msg: return self.innerWin.content_set(self.innerWinAnchor) self.innerWinAnchor.text_set(self.__to_html(msg)) self.innerWin.activate() if timeout != -1: ecore.timer_add(timeout, inwin_close)
def process_connection_status(self): if self.main.error: self.main.transition_to("unable_conn") self.main.error = False self.main.connected = False else: if self.main.connected == False: ecore.timer_add(1.0,self.process_connection_status) else: self.main.transition_to("connection_status")
def execute(self): if self.parent._state: self.parent._remove_albums() self.parent._insert_albums() self.message_text = "DONE" else: self.message_text = "Activate sync first" if self.callback_refresh: self.callback_refresh() if self.callback_locked: self.callback_locked() ecore.timer_add(1.5, self._unlocked_cb)
def refresh_finished(exception, retval): def cb_close(*ignored): self.close() self.parent.killall() if picasa_manager.is_logged(): self.model.title = "Logged as %s" % picasa_manager.user self.view.message("Login successful") ecore.timer_add(1.5, cb_close) else: self.view.message("Login error:<br>%s" % \ picasa_manager.get_login_error()) ecore.timer_add(1.5, cb_close)
def _scroll_text(self): # move text1 if self.move_text1: self._move_text(self.text1) # start moving text2 if self.move_text1 and not self.move_text2: move = self._check_move(self.text1, self.text2) if move: if self.text2_times < self.n_scroll or self.n_scroll == 0: self.move_text2 = True self.text2_times += 1 # reset text1 if self._check_limit(self.text1): self.move_text1 = False # stop animation if self.text1_times == self.n_scroll and self._check_stop(self.text1): self.animator.delete() self.animator = None if self.period > 0: self.repeat_timer = ecore.timer_add(self.period, self.start, None, None, None) # move text2 if self.move_text2: self._move_text(self.text2) # stop animation if n_scroll = 0 if self.n_scroll == 0 and self._check_stop(self.text2): self.animator.delete() self.animator = None if self.period > 0: self.repeat_timer = ecore.timer_add(self.period, self.start, None, None, None) # start moving text1 if self.move_text2 and not self.move_text1: if self._check_move(self.text2, self.text1): self.move_text1 = True self.text1_times += 1 # reset text 2 if self._check_limit(self.text2): self.move_text2 = False return True
def run(self): self.stopped = False self.elapsedTime = 0.0 self.timeStart = time.time() ecore.timer_add(UPDATE_TIME, self.update) ecore.main_loop_begin() # DMR old way of doing it. """ while self.running == True: timeStart = time.time() self.do_work() self.elapsedTime = time.time() - timeStart """ self.stopped = True
def run(self): mainloop = gobject.MainLoop(is_running=True) context = mainloop.get_context() def glib_context_iterate(): iters = 0 while iters < 10 and context.pending(): context.iteration() return True # Every 100ms, call an iteration of the glib main context loop # to allow the protocol context loop to work ecore.timer_add(0.1, glib_context_iterate) ecore.main_loop_begin()
def _scroll_text(self): # move text1 if self.move_text1: self._move_text(self.text1) # start moving text2 if self.move_text1 and not self.move_text2: move = self._check_move(self.text1, self.text2) if move: if self.text2_times < self.n_scroll or self.n_scroll == 0: self.move_text2 = True self.text2_times += 1 # reset text1 if self._check_limit(self.text1): self.move_text1 = False # stop animation if self.text1_times == self.n_scroll and self._check_stop( self.text1): self.animator.delete() self.animator = None if self.period > 0: self.repeat_timer = ecore.timer_add( self.period, self.start, None, None, None) # move text2 if self.move_text2: self._move_text(self.text2) # stop animation if n_scroll = 0 if self.n_scroll == 0 and self._check_stop(self.text2): self.animator.delete() self.animator = None if self.period > 0: self.repeat_timer = ecore.timer_add( self.period, self.start, None, None, None) # start moving text1 if self.move_text2 and not self.move_text1: if self._check_move(self.text2, self.text1): self.move_text1 = True self.text1_times += 1 # reset text 2 if self._check_limit(self.text2): self.move_text2 = False return True
def animate(ly): val = ly.edje_get().part_external_object_get("ext_pbar1").value val += 0.0123 for part_name in ["ext_pbar1", "ext_pbar3", "ext_pbar4", "ext_pbar6"]: ly.edje_get().part_external_object_get(part_name).value = val if val < 1: ecore.timer_add(0.1, animate, ly) else: for part_name in ["ext_pbar2", "ext_pbar5", "ext_pbar7"]: ly.edje_get().part_external_object_get(part_name).pulse(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 init(class_): try: class_.gsm = object_by_url('dbus:///org/pyneo/GsmDevice') class_.gprs = object_by_url('dbus:///org/pyneo/net/Gprs') class_.pwr = object_by_url('dbus:///org/pyneo/System') class_.sys = object_by_url(class_.pwr.GetDevice('system', dbus_interface=DIN_POWERED)) class_.gps = object_by_url('dbus:///org/pyneo/GpsLocation') class_.hon = object_by_url('dbus:///org/pyneo/HotOrNot') class_.music = object_by_url('dbus:///org/pyneo/Music') class_.ama = object_by_url('dbus:///org/pyneo/Amazon') class_.map_tiles = { 'OsmStreet':object_by_url('dbus:///org/pyneo/mapper/OsmStreet'), 'OsmCycle':object_by_url('dbus:///org/pyneo/mapper/OsmCycle'), 'OsmTilesathome':object_by_url('dbus:///org/pyneo/mapper/OsmTilesathome'), 'CloudmadeMidnight':object_by_url('dbus:///org/pyneo/mapper/CloudmadeMidnight'), 'OPNV':object_by_url('dbus:///org/pyneo/mapper/OPNV'), 'GoogleMoon':object_by_url('dbus:///org/pyneo/mapper/GoogleMoon'), } class_.map = object_by_url('dbus:///org/pyneo/mapper') class_.timetable = object_by_url('dbus:///org/pyneo/Timetable') class_.http = object_by_url('dbus:///org/pyneo/NetHttp') class_.wlan = object_by_url('dbus:///org/pyneo/WlanDevice') class_.notify = object_by_url('dbus:///org/pyneo/Notify') class_.ggl = object_by_url('dbus:///org/pyneo/GoogleLocation') class_.news = object_by_url('dbus:///org/pyneo/News') class_.entry = object_by_url('dbus:///org/pyneo/Entry') except Exception, e: print "Pyneo error: " + str(e) if not class_._dbus_timer: class_._dbus_timer = ecore.timer_add(5, class_.init) # We had an error, keep the timer running if we were called by ecore return True
def create_timer(self, time, func): if self._timer is not None: self._timer.delete() self._start_timer = int(ecore.time_get()) self._total_time = time self._timer_func = func self._timer = ecore.timer_add(time, func) return self._timer
def init( self ): # Make sure we have always at least two value tuples in the # acceleration list self.acceleration.append((0,0,0)) self.acceleration.append((0,0,0)) # Register the timer self.timer = ecore.timer_add( 0.1, self.run )
def run(self): #ecore.main_loop_glib_integrate() mainloop = gobject.MainLoop(is_running=True) context = mainloop.get_context() def glib_context_iterate(): iters = 0 while iters < 10 and context.pending(): context.iteration() iters += 1 return True # Every 100ms, call an iteration of the glib main context loop # to allow the protocol context loop to work ecore.timer_add(0.1, glib_context_iterate) #equals elementary.run() ecore.main_loop_begin()
def saveData(self, *args): self.ip, self.np, self.cc, self.ac = self.getEntryData() #print self.ip, self.np, self.cc, self.ac #data=self.getEntryData() phoneutils.set_codes(self.ip, self.np, self.cc, self.ac) phoneutils.save_config() if not self.wizard: dia = elementary.InnerWindow(self.window) dia.style_set('minimal') lab = elementary.Label(self.window) lab.text_set(_("Settings saved!")) lab.show() dia.content_set(lab) self.window.resize_object_add(dia) dia.show() dia.activate() timer_add(1.5, self.closeInwin, dia)
def my_progressbar_test_start(obj, *args, **kwargs): (pb1, pb2, pb3, pb4, pb5, pb6, pb7) = 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 = ecore.timer_add(0.1, my_progressbar_value_set, *args) my_progressbar_run = True
def _tt_text_replace_timed(obj, data, *args, **kargs): timer = data.get("timer") if timer: timer.delete() del data["timer"] obj.label_set("Simple text tooltip, click to start changed timed") return data["timer"] = ecore.timer_add(1.5, _tt_text_replace_timer_cb, obj, data) obj.label_set("Simple text tooltip, click to stop changed timed")
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"] = ecore.timer_add(1.5, _tt_text_replace_timer_cb, obj, data) obj.text_set("Simple text tooltip, click to stop changed timed")
def init_redraw(self): print "redraw" self.animate = True #reload icons list if its length differs from before eg. when size changes if len(self.icons) != (2*self.border_x+1)*(2*self.border_y+1): print "x:", self.border_x, "y:", self.border_y #clean up for icon in self.icons: icon.delete() self.icons = [] #fill for i in xrange((2*self.border_x+1)*(2*self.border_y+1)): self.icons.append(PylgrimView.Tile(self.evas_canvas.evas_obj.evas)) if not self.offline: #add all tiles that are not yet downloaded to a list for i in xrange(2*self.border_x+1): for j in xrange(2*self.border_y+1): if not os.path.exists("%d/%d/%d.png"%(self.zoom, self.x+i-self.border_x, self.y+j-self.border_y))\ and not (self.zoom, self.x+i-self.border_x, self.y+j-self.border_y) in self.tiles_to_download: self.tiles_to_download.append((self.zoom, self.x+i-self.border_x, self.y+j-self.border_y)) self.tiles_to_download_total = len(self.tiles_to_download) ''' #add additional tiles around the raster to a preload list for i in xrange(2*self.border_x+3): if i == 0 or i == 2*self.border_x+2: #if first or last row, download full row for j in xrange(2*self.border_y+3): if not os.path.exists("%d/%d/%d.png"%(self.zoom, self.x+i-self.border_x-1, self.y+j-self.border_y-1)): self.tiles_to_preload.append((self.zoom, self.x+i-self.border_x-1, self.y+j-self.border_y-1)) #lots TODO here #let preload more than one tile - maybe a preload_border_x/y variable #manage simultaneos proeloads #manage not preloading duplicates else #else download first and last tile ''' #if there are tiles to download, display progress bar if self.use_overlay and self.tiles_to_download_total > 0: self.progress_bg.geometry = 39, self.size[1]/2-1, self.size[0]-78, 22 self.progress.geometry = 40, self.size[1]/2, 1, 20 self.overlay.part_text_set("progress", "downloaded 0 of %d tiles"%self.tiles_to_download_total) ecore.timer_add(0.0, self.download_and_paint_current_tiles)
def get_gsm_keyring(class_): try: class_.gsm_keyring = object_by_url(class_.gsm_wireless.GetKeyring(dbus_interface=DIN_AUTHORIZED)) except Exception, e: print "SIM error: " + str(e) if not class_._keyring_timer: class_._keyring_timer = ecore.timer_add(5, class_.get_gsm_keyring) # We had an error, keep the timer running if we were called by ecore return True
def __do_magnetic_scroll(self): if self.pixels_left <= 0 or abs(self.pixel_per_sec) < 1: self.mouse_moved = False self.is_scrolling = False return self.pixel_per_sec -= (self.pixel_per_sec / 10) pixels_to_substract = int(abs(self.pixel_per_sec / 10)) if abs(pixels_to_substract) < 1: pixels_to_substract = 1 if self.pixels_left - pixels_to_substract > 0: self.pixels_left -= pixels_to_substract self.top_pos += self.sign * pixels_to_substract else: self.top_pos += self.sign * self.pixels_left self.pixels_left = 0 self.__update_screen() ecore.timer_add(0.1, self.__do_magnetic_scroll)
def accel_cb(self): text = "x = %3d; y = %3d; z = %3d" % (0, 0, 0) counter = 0 block = self.f.read(16) if block[8] == "\x02": if block[10] == "\x00": self.x_tmp = unpack_from("@l", block[12:])[0] if block[10] == "\x01": self.y_tmp = unpack_from("@l", block[12:])[0] if block[10] == "\x02": self.z_tmp = unpack_from("@l", block[12:])[0] #text = "x = %3d; y = %3d; z = %3d" % ( self.x_tmp, self.y_tmp, self.z_tmp) if counter % 5 == 0: self.x = self.x_tmp self.y = self.y_tmp self.z = self.z_tmp #print ("Values: %s" % text) counter = counter + 1 if self.accel_on: ecore.timer_add(0.0, self.accel_cb)
def accel_cb(self): text = "x = %3d; y = %3d; z = %3d" % ( 0, 0, 0 ) counter = 0 block = self.f.read(16) if block[8] == "\x02": if block[10] == "\x00": self.x_tmp = unpack_from( "@l", block[12:] )[0] if block[10] == "\x01": self.y_tmp = unpack_from( "@l", block[12:] )[0] if block[10] == "\x02": self.z_tmp = unpack_from( "@l", block[12:] )[0] #text = "x = %3d; y = %3d; z = %3d" % ( self.x_tmp, self.y_tmp, self.z_tmp) if counter % 5 == 0: self.x = self.x_tmp self.y = self.y_tmp self.z = self.z_tmp #print ("Values: %s" % text) counter = counter + 1 if self.accel_on: ecore.timer_add(0.0,self.accel_cb)
def __init__ (self): self.brands = [] self.enabledBrands = {} self.usingCelsius = 0 self.usingSensor = 0 self.sensorTemperature = 1 self.LoadDB() self.configfile = os.path.expanduser ('~/.wax-chooser.cfg') self.config = ConfigParser.SafeConfigParser () self.LoadConfig (self.configfile) self.widgets = self.build_gui () self.sensorTimer = ecore.timer_add( 1, self.updateSensorLabel ) self.image_path = './' self.widgets['mainwin'].show () self.snow_cond = 0 self.humidity = 1 self.bestAveTemp = 9999 signal.signal(signal.SIGINT, self.interrupted) elementary.init() elementary.run() elementary.shutdown()
def on_del(x, event): print "ecore.Exe deleted, exit!", x ecore.timer_add(1.0, ecore.main_loop_quit)
def timerAdd(self, delay, func): ecore.timer_add(delay, func)
def print_every_300ms(): global counter2 counter2 += 1 print "every 300ms, run:", counter2 return True # keep running, stop_print_every_300ms will stop me def stop_print_every_300ms(my_timer): print "stopping 'print_every_300ms' timer" my_timer.delete() if __name__ == "__main__": # Use C-like API ecore.timer_add(0.5, print_every_500ms, "arg1", 1234, q=890, p=567) ecore.timer_add(0.6, print_every_600ms_twice) ecore.timer_add(0.7, print_once_after_700ms) # Use pythonic API, ecore.Timer() is a class ecore.Timer(1.0, print_every_1s, "arg1.1", 1234.1, p=567.1) # keep timer object so we can stop it from the other timer my_timer = ecore.timer_add(0.3, print_every_300ms) ecore.timer_add(1.5, stop_print_every_300ms, my_timer) # regular timer using C-like API, will trigger ecore.main_loop_quit() ecore.timer_add(3.0, quit_after_3s) # without a main loop, timers will not work ecore.main_loop_begin()
def accell_value(self): if self.send_event: self.main.connection.release_keyboard_event() self.send_event = False key = self.main.a_key modif, val = key_dec(self, key) self.main.connection.send_keyboard_event(modif, val) print "release" else: if self.pass_event: self.pass_event = False else: self.pass_event2 = False #print "released" #if self.x < -500: # key = self.main.down_key # modif, val = key_dec(self,key) # value = self.main.key_mapper.mapper[str(val)] # print "sending" # self.main.connection.send_accel_event(modif,value) #elif self.x > 500: # key = self.main.up_key # modif, val = key_dec(self,key) # value = self.main.key_mapper.mapper[str(val)] # print "sending" # self.main.connection.send_accel_event(modif,value) if self.y < -400: key = self.main.right_key modif, val = key_dec(self, key) self.main.connection.send_keyboard_event(modif, val) self.send_event = True elif self.y > 400: key = self.main.left_key modif, val = key_dec(self, key) self.main.connection.send_keyboard_event(modif, val) self.send_event = True if not self.pass_event: if self.y < -200: key = self.main.right_key modif, val = key_dec(self, key) print "->>>>>>>>" self.main.connection.send_keyboard_event(modif, val) self.send_event = True self.pass_event = True elif self.y > 200: key = self.main.left_key modif, val = key_dec(self, key) self.main.connection.send_keyboard_event(modif, val) self.send_event = True self.pass_event = True if self.accel_on: ecore.timer_add(0.10, self.accell_value) elif not self.accel_on: self.first_time = True
def cb_read(fd_handler, a, b): data = os.read(fd_handler.fd, 50) print "ready for read:", fd_handler, ", params: a=", a, ", b=", b return True def timer_write(wfd): print "write to fd:", wfd os.write(wfd, "[some data]") return True rfd, wfd = os.pipe() fdh = ecore.fd_handler_add(rfd, ecore.ECORE_FD_READ, cb_read, 123, b="xyz") ecore.timer_add(0.2, timer_write, wfd) print "before: fdh=", fdh ecore.timer_add(1, ecore.main_loop_quit) ecore.main_loop_begin() print "main loop stopped" print "after: fdh=", fdh fdh.delete() del fdh ecore.shutdown()
return True def sleeper(): import time print "sleep 0.1s" time.sleep(0.1) return True i0 = ecore.idle_exiter_add(cb_true, 123, "teste", a=456) i1 = ecore.IdleExiter(cb_false, 789, "bla", a="something in a") print "before: i0=", i0 print "before: i1=", i1 ecore.timer_add(1, ecore.main_loop_quit) ecore.timer_add(0.1, sleeper) ecore.idler_add(cb_idle) ecore.main_loop_begin() print "main loop stopped" print "after: i0=", i0 print "after: i1=", i1 i0.delete() del i0 del i1 # already deleted since returned false ecore.shutdown()
def cb_true(n, t, a): print "cb_true:", n, t, a return True def cb_false(n, t, a): print "cb_false:", n, t, a return False i0 = ecore.idler_add(cb_true, 123, "teste", a=456) i1 = ecore.Idler(cb_false, 789, "bla", a="something in a") print "before: i0=", i0 print "before: i1=", i1 ecore.timer_add(1, ecore.main_loop_quit) ecore.main_loop_begin() print "main loop stopped" print "after: i0=", i0 print "after: i1=", i1 i0.delete() del i0 del i1 # already deleted since returned false ecore.shutdown()
ee = ecore.evas.new(w=800, h=400) bg = ee.evas.Rectangle(color=(255, 255, 255, 255)) bg.size = ee.evas.size bg.show() img = ee.evas.Image() img.file_set("icon.png") img.move(380, 200) w, h = img.image_size_get() img.resize(w, h) img.fill_set(0, 0, w, h) img.show() rotation = [evas.EVAS_IMAGE_ROTATE_90] def rotate_img(rotation): img.rotate(rotation[0]) rotation[0] += 1 return rotation[0] <= evas.EVAS_IMAGE_ROTATE_270 ee.fullscreen = False ee.show() ecore.timer_add(2.0, rotate_img, rotation) ecore.main_loop_begin() # prevent segfault del ee
def timer(self, interval, func): return ecore.timer_add(interval, func)
def my_gl_flush(bt, gl): def my_gl_flush_delay(): elm_cache_all_flush() ecore.timer_add(1.2, my_gl_flush_delay)
def build_gui(self): def destroy(obj, *args, **kargs): try: self.pressureLabelTimer.delete() self.altitudeLabelTimer.delete() self.pressureGraphTimer.delete() self.SaveConfig(self.configfile) except: print "Exception occured on exit" elementary.exit() gui_items = dict() # Create main window gui_items['mainwin'] = elementary.Window("Barom", elementary.ELM_WIN_BASIC) gui_items['mainwin'].title_set("Barom") gui_items['mainwin'].callback_destroy_add(destroy) # Create background bg = elementary.Background(gui_items['mainwin']) bg.size_hint_weight_set(1.0, 1.0) #bg.size_hint_min_set (200,300) gui_items['mainwin'].resize_object_add(bg) bg.show() # Create main box (vertical by default) gui_items['mainbox'] = elementary.Box(gui_items['mainwin']) gui_items['mainbox'].size_hint_weight_set(1.0, 1.0) gui_items['mainbox'].size_hint_align_set(-1.0, -1.0) gui_items['mainwin'].resize_object_add(gui_items['mainbox']) gui_items['mainbox'].show() #Create top toolbar toptoolbar = elementary.Toolbar(gui_items['mainwin']) toptoolbar.menu_parent_set(gui_items['mainwin']) toptoolbar.homogenous_set(False) #toptoolbar.icon_size_set( 64 ) #toptoolbar.size_hint_align_set (evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) #toptoolbar.size_hint_weight_set (1.0, 1.0) toptoolbar.size_hint_align_set(-1.0, 0.0) toptoolbar.item_append(os.path.join(IMAGE_DIR, 'altitude.png'), "Altitude", self.altitudeDialog) toptoolbar.item_append(os.path.join(IMAGE_DIR, "weather.png"), "Weather", self.weatherDialog) toptoolbar.item_append(os.path.join(IMAGE_DIR, 'calibrate.png'), "Calibrate", self.calibrateDialog) toptoolbar.item_append(os.path.join(IMAGE_DIR, "about.png"), "About", self.aboutDialog) gui_items['mainbox'].pack_end(toptoolbar) toptoolbar.show() gui_items['pager'] = elementary.Naviframe(gui_items['mainwin']) gui_items['pager'].size_hint_weight_set(1.0, 1.0) gui_items['pager'].size_hint_align_set(-1.0, -1.0) # Create weather box (vertical by default) gui_items['weatherbox'] = elementary.Box(gui_items['mainwin']) gui_items['weatherbox'].size_hint_weight_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) gui_items['weatherbox'].size_hint_align_set(-1.0, -1.0) gui_items['pressureLabel'] = elementary.Label(gui_items['mainwin']) gui_items['pressureLabel'].text_set('weather') gui_items['pressureLabel'].scale_set(3.5) gui_items['pressureLabel'].size_hint_weight_set(1.0, 0.0) gui_items['pressureLabel'].size_hint_align_set(0.5, -1.0) gui_items['weatherbox'].pack_end(gui_items['pressureLabel']) gui_items['pressureLabel'].show() # Include the graph of past pressures gui_items['graphframe'] = elementary.Frame(gui_items['mainwin']) sc = elementary.Scroller(gui_items['mainwin']) sc.bounce_set(0, 0) sc.size_hint_weight_set(evas.EVAS_HINT_EXPAND, 1.0) sc.size_hint_align_set(-1.0, -1.0) #gui_items['weatherbox'].pack_end(sc) gui_items['mainwin'].resize_object_add(sc) sc.show() gui_items['graphframe'].size_hint_weight_set(1.0, 1.0) gui_items['graphframe'].size_hint_align_set(-1.0, -1.0) gui_items['graphframe'].show() graphcanvas = gui_items['graphframe'].evas bg = graphcanvas.Rectangle(color=(255, 255, 255, 255)) bg.size = (460, 380) bg.layer_set(1) gui_items['graphframe'].data["bg"] = bg #print "FrameSize: " + str(gui_items['graphframe'].size) bg.show() gui_items['graphframe'].content_set(bg) sc.content_set(gui_items['graphframe']) #gb.pack_end(gui_items['graphframe']) gui_items['weatherbox'].pack_end(sc) self.pressureGraphThread = pressureGraphUpdater( self.getPressureFromSensor, gui_items['graphframe'], self.usingMetric) self.pressureLabelTimer = ecore.timer_add(2, self.PressureLabelUpdate) self.pressureGraphTimer = ecore.timer_add( 2, self.pressureGraphThread.pressureGraphUpdate) gui_items['mainwin'].resize_object_add(gui_items['weatherbox']) gui_items['pager'].item_simple_push(gui_items['weatherbox']) ##### # Create calibrate box (vertical by default) gui_items['calibratebox'] = elementary.Box(gui_items['mainwin']) gui_items['calibratebox'].size_hint_weight_set(1.0, 1.0) gui_items['calibratebox'].size_hint_align_set(-1.0, -1.0) # Create scroller to hold calibrate toggles items sc2 = elementary.Scroller(gui_items['mainwin']) sc2.bounce_set(0, 0) sc2.size_hint_weight_set(1.0, 1.0) sc2.size_hint_align_set(-1.0, -1.0) gui_items['calibratebox'].pack_end(sc2) gui_items['mainwin'].resize_object_add(sc2) sc2.show() tb = elementary.Box(gui_items['calibratebox']) tb.size_hint_weight_set(1.0, 1.0) tb.size_hint_align_set(-1.0, -1.0) ut = elementary.Check(gui_items['mainwin']) ut.style_set("toggle") ut.text_set('Units') ut.text_part_set('on', 'Metric') ut.text_part_set('off', 'Imperial') ut.size_hint_weight_set(1.0, 1.0) ut.size_hint_align_set(-1.0, 0.0) tb.pack_end(ut) ut.state_set(self.usingMetric) ut._callback_add('changed', self.setUnits) ut.show() al = elementary.Label(gui_items['mainwin']) al.text_set("Known current altitude") al.show() tb.pack_end(al) tbAlt = elementary.Box(gui_items['mainwin']) tbAlt.horizontal_set(1) gui_items['calibrateAltnumber'] = elementary.Entry( gui_items['mainwin']) gui_items['calibrateAltnumber'].single_line_set(True) gui_items['calibrateAltnumber'].entry_set('XX') gui_items['calibrateAltnumber'].scale_set(2.0) gui_items['calibrateAltnumber'].size_hint_weight_set(1, 1) gui_items['calibrateAltnumber'].callback_activated_add(self.calibrate) tbAlt.pack_end(gui_items['calibrateAltnumber']) gui_items['calibrateAltnumber'].show() gui_items['unitaltlabel'] = elementary.Label(gui_items['mainwin']) gui_items['unitaltlabel'].show() tbAlt.pack_end(gui_items['unitaltlabel']) tbAlt.show() tb.pack_end(tbAlt) pl = elementary.Label(gui_items['mainwin']) pl.text_set("Known current pressure at sea level") pl.show() tb.pack_end(pl) tbPres = elementary.Box(gui_items['mainwin']) tbPres.horizontal_set(1) gui_items['calibratePresnumber'] = elementary.Entry( gui_items['mainwin']) gui_items['calibratePresnumber'].single_line_set(True) gui_items['calibratePresnumber'].entry_set('XX') gui_items['calibratePresnumber'].scale_set(2.0) gui_items['calibratePresnumber'].size_hint_weight_set(1, 1) gui_items['calibratePresnumber'].callback_activated_add(self.calibrate) tbPres.pack_end(gui_items['calibratePresnumber']) gui_items['calibratePresnumber'].show() gui_items['unitpreslabel'] = elementary.Label(gui_items['mainwin']) gui_items['unitpreslabel'].show() tbPres.pack_end(gui_items['unitpreslabel']) tbPres.show() tb.pack_end(tbPres) if self.usingMetric: gui_items['unitaltlabel'].text_set('m') gui_items['unitpreslabel'].text_set('hpa') else: gui_items['unitaltlabel'].text_set('ft') gui_items['unitpreslabel'].text_set('in hg') # Create the calibrate button bt = elementary.Button(gui_items['mainwin']) bt.text_set('Calibrate') bt._callback_add('clicked', self.calibrate) bt.size_hint_weight_set(1.0, 1.0) bt.size_hint_align_set(-1.0, 0.0) tb.pack_end(bt) bt.show() tbFile = elementary.Box(gui_items['mainwin']) tbFile.horizontal_set(1) #create the sensor name label fl = elementary.Label(gui_items['mainwin']) fl.text_set("location of the sensor sysfs file") fl.show() tb.pack_end(fl) # Create the sensor name Entry gui_items['pressureSensorFile'] = elementary.Entry( gui_items['mainwin']) gui_items['pressureSensorFile'].single_line_set(True) gui_items['pressureSensorFile'].entry_set(self.pressureSensorFile) gui_items['pressureSensorFile'].scale_set(1.0) gui_items['pressureSensorFile'].size_hint_weight_set(1, 1) gui_items['pressureSensorFile'].callback_activated_add( self.changeSensorFile) tbFile.pack_end(gui_items['pressureSensorFile']) gui_items['pressureSensorFile'].show() tbFile.show() tb.pack_end(tbFile) sc2.content_set(tb) gui_items['mainwin'].resize_object_add(gui_items['calibratebox']) gui_items['pager'].item_simple_push(gui_items['calibratebox']) ##### # Create about box (vertical by default) gui_items['aboutbox'] = elementary.Box(gui_items['mainwin']) gui_items['aboutbox'].size_hint_weight_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) gui_items['aboutbox'].size_hint_align_set(-1.0, -1.0) al = elementary.Label(gui_items['mainwin']) al.size_hint_weight_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) al.size_hint_align_set(0.5, -1.0) al.text_set("About Barom") gui_items['aboutbox'].pack_end(al) al.show() # Create scroller to hold the author's picture sc2 = elementary.Scroller(gui_items['mainwin']) sc2.bounce_set(0, 0) sc2.size_hint_weight_set(1.0, 1.0) sc2.size_hint_align_set(evas.EVAS_HINT_FILL, -1.0) gui_items['aboutbox'].pack_end(sc2) gui_items['mainwin'].resize_object_add(sc2) sc2.show() ib = elementary.Box(gui_items['aboutbox']) ic = elementary.Icon(gui_items['aboutbox']) gui_items['mainwin'].resize_object_add(ic) ic.size_hint_weight_set(0.5, 0.5) ic.scale_set(0.5, 0.5) ic.size_hint_align_set(0.5, 0.0) ic.file_set(os.path.join(IMAGE_DIR, "author.png")) ib.size_hint_weight_set(0.5, 0.5) ib.size_hint_align_set(evas.EVAS_HINT_FILL, evas.EVAS_HINT_FILL) ib.pack_end(ic) sc2.content_set(ib) ic.show() # Create text box with 'about' info at = elementary.Entry(gui_items['aboutbox']) at.size_hint_weight_set(1.0, 0.0) at.size_hint_align_set(evas.EVAS_HINT_FILL, 0.0) at.scale_set(1) info = self.infoadd("Barom " + APP_VERSION) info += self.infoadd("Copyright (c) 2011 Benjamin Deering") info += self.infoadd("<*****@*****.**>") at.text_set(info) gui_items['aboutbox'].pack_end(at) at.show() gui_items['mainwin'].resize_object_add(gui_items['aboutbox']) gui_items['pager'].item_simple_push(gui_items['aboutbox']) ##### # Create altitude box (vertical by default) gui_items['altitudebox'] = elementary.Box(gui_items['mainwin']) gui_items['altitudebox'].size_hint_weight_set(1.0, 1.0) gui_items['altitudebox'].size_hint_align_set(-1.0, -1.0) gui_items['altitudeLabel'] = elementary.Label(gui_items['mainwin']) gui_items['altitudeLabel'].text_set('altitude') gui_items['altitudeLabel'].scale_set(3.5) gui_items['altitudeLabel'].size_hint_weight_set(1.0, 1.0) gui_items['altitudeLabel'].size_hint_align_set(0.5, -1.0) gui_items['altitudebox'].pack_end(gui_items['altitudeLabel']) gui_items['altitudeLabel'].show() self.altitudeLabelTimer = ecore.timer_add(2, self.AltitudeLabelUpdate) gui_items['mainwin'].resize_object_add(gui_items['altitudebox']) gui_items['pager'].item_simple_push(gui_items['altitudebox']) gui_items['pager'].show() gui_items['mainbox'].pack_end(gui_items['pager']) gui_items['pager'].item_simple_promote(gui_items['altitudebox']) return gui_items
#!/usr/bin/env python import ecore def cb(n, t, a): print "cb:", n, t, a return True t0 = ecore.timer_add(0.2, cb, 123, "teste", a=456) t1 = ecore.timer_add(1, ecore.main_loop_quit) t2 = ecore.Timer(0.5, cb, 789, "bla", a="something in a") print "before: t0=", t0 print "before: t1=", t1 print "before: t2=", t2 ecore.main_loop_begin() print "main loop stopped" print "after: t0=", t0 print "after: t1=", t1 print "after: t2=", t2 t0.delete() del t0 del t1 # already deleted since returned false t2.delete() del t2 ecore.shutdown()
def accell_value(self): #text = "x = %3d; y = %3d; z = %3d" % ( x, y, z ) maxx = maxy = maxz = 0 minx = miny = minz = 0 block = self.f.read(16) if block[8] == "\x02": if block[10] == "\x00": self.x = unpack_from("@l", block[12:])[0] # maxx, minx = max( self.x, maxx ), min( self.x, minx ) if block[10] == "\x01": self.y = unpack_from("@l", block[12:])[0] # maxy, miny = max( self.y, maxy ), min( self.y, miny ) if block[10] == "\x02": self.z = unpack_from("@l", block[12:])[0] # maxz, minz = max( self.z, maxz ), min( self.z, minz ) #print "X=" + str(self.x) + " Y=" + str(self.y) + " Z=" + str(self.z) if self.first_time: self.x_init = self.x self.y_init = self.y self.z_init = self.z elif not self.first_time: if self.y < 120 and self.x < 0: if (self.x - 10) > self.x_init: self.main.connection.send_mouse_event(00, 2, 0, 00) elif self.x > -50: self.main.connection.send_mouse_event(00, -1, 0, 00) elif self.x > -200 and self.x < -100: self.main.connection.send_mouse_event(00, -2, 0, 00) elif self.x > -300 and self.x < -200: self.main.connection.send_mouse_event(00, -4, 0, 00) elif self.x > -400 and self.x < -300: self.main.connection.send_mouse_event(00, -6, 0, 00) elif self.x > -500 and self.x < -400: self.main.connection.send_mouse_event(00, -8, 0, 00) elif self.x > -600 and self.x < -500: self.main.connection.send_mouse_event(00, -10, 0, 00) elif self.x > -700 and self.x < -600: self.main.connection.send_mouse_event(00, -12, 0, 00) elif self.x < -800: self.main.connection.send_mouse_event(00, -15, 0, 00) elif self.y > -130 and self.x > 150: if self.x < 250: self.main.connection.send_mouse_event(00, 1, 0, 00) elif self.x > 250 and self.x < 350: self.main.connection.send_mouse_event(00, 2, 0, 00) elif self.x > 350 and self.x < 450: self.main.connection.send_mouse_event(00, 4, 0, 00) elif self.x > 450 and self.x < 550: self.main.connection.send_mouse_event(00, 6, 0, 00) elif self.x > 550 and self.x < 650: self.main.connection.send_mouse_event(00, 8, 0, 00) elif self.x > 650 and self.x < 750: self.main.connection.send_mouse_event(00, 10, 0, 00) elif self.x > 750 and self.x < 850: self.main.connection.send_mouse_event(00, 12, 0, 00) elif self.x > 950: self.main.connection.send_mouse_event(00, 15, 0, 00) elif self.x < 120 and self.y < -100: if (self.y - 10) > self.y_init: self.main.connection.send_mouse_event(00, 0, 2, 00) if self.y < -100 and self.y > -200: self.main.connection.send_mouse_event(00, 0, -1, 00) elif self.y < -200 and self.y > -300: self.main.connection.send_mouse_event(00, 0, -2, 00) elif self.y < -300 and self.y > -400: self.main.connection.send_mouse_event(00, 0, -4, 00) elif self.y < -400 and self.y > -500: self.main.connection.send_mouse_event(00, 0, -6, 00) elif self.y < -500 and self.y > -600: self.main.connection.send_mouse_event(00, 0, -8, 00) elif self.y < -600 and self.y > -700: self.main.connection.send_mouse_event(00, 0, -10, 00) elif self.y < -700 and self.y > -800: self.main.connection.send_mouse_event(00, 0, -12, 00) elif self.y < -800: self.main.connection.send_mouse_event(00, 0, -15, 00) elif self.x < 190 and self.y > 120: #if (self.y- 10) < self.y_init: # self.main.connection.send_mouse_event(00,0,-2,00) if self.y > 120 and self.y < 220: self.main.connection.send_mouse_event(00, 0, 1, 00) elif self.y > 220 and self.y < 320: self.main.connection.send_mouse_event(00, 0, 2, 00) elif self.y > 320 and self.y < 420: self.main.connection.send_mouse_event(00, 0, 4, 00) elif self.y > 420 and self.y < 520: self.main.connection.send_mouse_event(00, 0, 6, 00) elif self.y > 520 and self.y < 620: self.main.connection.send_mouse_event(00, 0, 8, 00) elif self.y > 720 and self.y < 820: self.main.connection.send_mouse_event(00, 0, 10, 00) elif self.y > 820 and self.y < 920: self.main.connection.send_mouse_event(00, 0, 12, 00) elif self.y > 920: self.main.connection.send_mouse_event(00, 0, 15, 00) self.x_init = self.x self.y_init = self.y self.z_init = self.z #print str(self.y) + "-" + str(self.y_init) if self.press: ecore.timer_add(0.001, self.accell_value) elif self.press: self.first_time = True
def catchall_hello_signals_handler(hello_string): print "Received a hello signal and it says: %s" % hello_string def catchall_testservice_interface_handler(hello_string, dbus_message): print "com.example.TestService interface says %s " \ "when it sent signal %s" % (hello_string, dbus_message.get_member()) dbus_ml = e_dbus.DBusEcoreMainLoop() bus = dbus.SessionBus(mainloop=dbus_ml) obj = bus.get_object("com.example.TestService", "/com/example/TestService/object") obj.connect_to_signal("HelloSignal", hello_signal_handler, dbus_interface="com.example.TestService", arg0="Hello") bus.add_signal_receiver(catchall_hello_signals_handler, dbus_interface = "com.example.TestService", signal_name = "HelloSignal") bus.add_signal_receiver(catchall_testservice_interface_handler, dbus_interface = "com.example.TestService", message_keyword="dbus_message") ecore.timer_add(2.0, emit_signal, obj) ecore.main_loop_begin()
def timeout_add(self, time, callback, *args): return ecore.timer_add(time / 1000., callback, *args)