コード例 #1
0
ファイル: clock.py プロジェクト: metulburr/tilenol
 def _update_time(self):
     while True:
         tts = 1.0 - (time.time() % 1.0)
         if tts < 0.001:
             tts = 1
         sleep(tts)
         self.bar.redraw.emit()
コード例 #2
0
ファイル: clock.py プロジェクト: rmsilva/tilenol
 def _update_time(self):
     while True:
         tts = 1.0 - (time.time() % 1.0)
         if tts < 0.001:
             tts = 1
         sleep(tts)
         self.bar.redraw.emit()
コード例 #3
0
 def _update_handler(self):
     try:
         woeid = int(self.location)
     except ValueError:
         woeid = self.fetch_woeid()
     self.uri = "{0}{1}".format(
         WEATHER_URL,
         urlencode({'w': woeid, 'u': self.metric and 'c' or 'f'})
     )
     while True:
         result = self.fetch()
         if result is not None:
             self.text = self.format.format_map(result)
             if self.picture_url is not None:
                 self.fetch_image(result)
         sleep(600)
コード例 #4
0
ファイル: yahoo_weather.py プロジェクト: metulburr/tilenol
 def _update_handler(self):
     try:
         woeid = int(self.location)
     except ValueError:
         woeid = self.fetch_woeid()
     self.uri = "{0}{1}".format(
         WEATHER_URL,
         urlencode({
             'w': woeid,
             'u': self.metric and 'c' or 'f'
         }))
     while True:
         result = self.fetch()
         if result is not None:
             self.text = self.format.format_map(result)
             if self.picture_url is not None:
                 self.fetch_image(result)
         sleep(600)
コード例 #5
0
 def fetch_woeid(self):
     woeid = None
     while woeid is None:
         try:
             data = fetchurl(QUERY_URL, query={
                 'q': "select woeid from geo.places "
                 "where text='{0}'".format(self.location),
                 'format': 'json'
             })
             data = json.loads(data.decode('ascii'))['query']
             if data['count'] > 1:
                 woeid = data['results']['place'][0]['woeid']
             else:
                 woeid = data['results']['place']['woeid']
         except Exception as e:
             log.exception("Error fetching woeid", exc_info=e)
             sleep(60)
         else:
             if woeid is None:
                 sleep(60)
     return woeid
コード例 #6
0
ファイル: yahoo_weather.py プロジェクト: metulburr/tilenol
 def fetch_woeid(self):
     woeid = None
     while woeid is None:
         try:
             data = fetchurl(QUERY_URL,
                             query={
                                 'q':
                                 "select woeid from geo.places "
                                 "where text='{0}'".format(self.location),
                                 'format':
                                 'json'
                             })
             data = json.loads(data.decode('ascii'))['query']
             if data['count'] > 1:
                 woeid = data['results']['place'][0]['woeid']
             else:
                 woeid = data['results']['place']['woeid']
         except Exception as e:
             log.exception("Error fetching woeid", exc_info=e)
             sleep(60)
         else:
             if woeid is None:
                 sleep(60)
     return woeid
コード例 #7
0
ファイル: gestures.py プロジェクト: KenjiTakahashi/tilenol
    def _shm_loop(self, ptr):
        while True:
            sleep(0.2)
            struct = ptr[0]
            if struct.numFingers >= 2:
                initialx = struct.x
                initialy = struct.y
                initialf = struct.numFingers
                gesture_prefix = '{}f-'.format(initialf)
                full = False
                name = None
                while initialf == struct.numFingers:
                    sleep(0.05)
                    dx = struct.x - initialx
                    dy = struct.y - initialy
                    angle = atan2(dx, dy)
                    dist = sqrt(dx*dx + dy*dy)
                    for name, cfg in self.cfg.items():
                        if not name.startswith(gesture_prefix):
                            continue
                        cond = cfg['condition']
                        if cond(angle) and dist > cfg['detect-distance']:
                            callbacks = self.callbacks[name]
                            break
                    else:
                        continue
                    break
                else:
                    continue
                for f in callbacks:
                    f(name, 0, START, cfg)

                while initialf == struct.numFingers:
                    sleep(0.05)
                    dx = struct.x - initialx
                    dy = struct.y - initialy
                    angle = atan2(dx, dy)
                    dist = sqrt(dx*dx + dy*dy)
                    percent = dist / cfg['commit-distance']
                    full = percent >= 1
                    if not cond(angle) or dist < cfg['detect-distance']:
                        for f in callbacks:
                            f(name, percent, UNDO, cfg)
                    else:
                        state = FULL if full else PARTIAL
                        for f in callbacks:
                            f(name, percent, state, cfg)

                if full:
                    for f in callbacks:
                        f(name, 1, COMMIT, cfg)
                    self.commander.callback(*cfg['action'])()
                else:
                    for f in callbacks:
                        f(name, 0, CANCEL, cfg)
コード例 #8
0
ファイル: gestures.py プロジェクト: metulburr/tilenol
    def _shm_loop(self, ptr):
        while True:
            sleep(0.2)
            struct = ptr[0]
            if struct.numFingers >= 2:
                initialx = struct.x
                initialy = struct.y
                initialf = struct.numFingers
                gesture_prefix = '{}f-'.format(initialf)
                full = False
                name = None
                while initialf == struct.numFingers:
                    sleep(0.05)
                    dx = struct.x - initialx
                    dy = struct.y - initialy
                    angle = atan2(dx, dy)
                    dist = sqrt(dx * dx + dy * dy)
                    for name, cfg in self.cfg.items():
                        if not name.startswith(gesture_prefix):
                            continue
                        cond = cfg['condition']
                        if cond(angle) and dist > cfg['detect-distance']:
                            callbacks = self.callbacks[name]
                            break
                    else:
                        continue
                    break
                else:
                    continue
                for f in callbacks:
                    f(name, 0, START, cfg)

                while initialf == struct.numFingers:
                    sleep(0.05)
                    dx = struct.x - initialx
                    dy = struct.y - initialy
                    angle = atan2(dx, dy)
                    dist = sqrt(dx * dx + dy * dy)
                    percent = dist / cfg['commit-distance']
                    full = percent >= 1
                    if not cond(angle) or dist < cfg['detect-distance']:
                        for f in callbacks:
                            f(name, percent, UNDO, cfg)
                    else:
                        state = FULL if full else PARTIAL
                        for f in callbacks:
                            f(name, percent, state, cfg)

                if full:
                    for f in callbacks:
                        f(name, 1, COMMIT, cfg)
                    self.commander.callback(*cfg['action'])()
                else:
                    for f in callbacks:
                        f(name, 0, CANCEL, cfg)