kuuko pushed a commit to branch master. http://git.enlightenment.org/apps/epour.git/commit/?id=e7e2766b698a8d863218506e99b5e705fca68dc4
commit e7e2766b698a8d863218506e99b5e705fca68dc4 Author: Kai Huuhko <kai.huu...@gmail.com> Date: Wed Aug 31 04:40:01 2016 +0300 Fix state and status updates --- epour/gui/__init__.py | 46 +++++++++++++++++++++++----------------------- epour/session.py | 6 ++++++ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/epour/gui/__init__.py b/epour/gui/__init__.py index 2293f3b..e0d13f2 100644 --- a/epour/gui/__init__.py +++ b/epour/gui/__init__.py @@ -190,16 +190,16 @@ class MainInterface(object): def torrent_paused_resumed_cb(a): h = a.handle if not h.is_valid(): - log.debug("State changed for invalid handle.") + log.debug("Paused state changed for invalid handle.") return info_hash = str(h.info_hash()) if info_hash not in self.torrentitems: - log.debug("%s state changed but not in list", str(info_hash)) + log.debug("Paused state for %s changed but not in list of gui items", str(info_hash)) return torrent = self._session.torrents[info_hash] - torrent.state = h.status(0).state + torrent.status = h.status(0) self.torrentitems[info_hash].fields_update( "elm.swallow.icon", ELM_GENLIST_ITEM_FIELD_CONTENT @@ -229,20 +229,20 @@ class MainInterface(object): session.alert_manager.callback_add( "state_changed_alert", state_changed_cb) - # def state_update_alert_cb(a): - # statuses = a.status - # for status in statuses: - # info_hash = str(status.info_hash) + def state_update_alert_cb(a): + statuses = a.status + for status in statuses: + info_hash = str(status.info_hash) - # if info_hash not in self.torrentitems: - # return + if info_hash not in self.torrentitems: + return - # self.torrentitems[info_hash].fields_update( - # "*", ELM_GENLIST_ITEM_FIELD_TEXT - # ) + self.torrentitems[info_hash].fields_update( + "*", ELM_GENLIST_ITEM_FIELD_TEXT + ) - # session.alert_manager.callback_add( - # "state_update_alert", state_update_alert_cb) + session.alert_manager.callback_add( + "state_update_alert", state_update_alert_cb) def torrent_finished_cb(a): msg = _("Torrent {} has finished downloading.").format( @@ -262,11 +262,11 @@ class MainInterface(object): def run_mainloop(self): self.win.show() - self.timer = Timer(1.0, self.update) - self.win.on_del_add(lambda x: self.timer.delete()) - self.win.callback_withdrawn_add(lambda x: self.timer.freeze()) - self.win.callback_iconified_add(lambda x: self.timer.freeze()) - self.win.callback_normal_add(lambda x: self.timer.thaw()) + # self.timer = Timer(1.0, self.update) + # self.win.on_del_add(lambda x: self.timer.delete()) + # self.win.callback_withdrawn_add(lambda x: self.timer.freeze()) + # self.win.callback_iconified_add(lambda x: self.timer.freeze()) + # self.win.callback_normal_add(lambda x: self.timer.thaw()) elm.run() def stop_mainloop(self): @@ -274,9 +274,8 @@ class MainInterface(object): def update(self): #log.debug("Torrent list TICK") - for v in self.tlist.realized_items_get(): - v.fields_update("*", ELM_GENLIST_ITEM_FIELD_TEXT) - self._session.post_torrent_updates(64) + # for v in self.tlist.realized_items_get(): + # v.fields_update("*", ELM_GENLIST_ITEM_FIELD_TEXT) return True def _torrent_item_tooltip_cb(self, gl, it, tooltip, session, torrent): @@ -483,6 +482,7 @@ class TorrentClass(GenlistItemClass): return status = torrent.status + state = torrent.state ic = Icon(obj) try: if status.paused: @@ -511,7 +511,7 @@ class TorrentClass(GenlistItemClass): pass except RuntimeError: log.debug("Setting torrent ic failed") - ic.tooltip_text_set(self.state_str[torrent.state]) + ic.tooltip_text_set(self.state_str[state]) ic.size_hint_aspect_set(EVAS_ASPECT_CONTROL_VERTICAL, 1, 1) return ic diff --git a/epour/session.py b/epour/session.py index 469f6f3..311d1f5 100644 --- a/epour/session.py +++ b/epour/session.py @@ -173,6 +173,12 @@ class Session(lt.session): self.periodic_save_timer = Timer(15.0, periodic_save_func) + def status_updates_timer_cb(): + self.post_torrent_updates(64) + return True + + self.status_updates_timer = Timer(1.0, status_updates_timer_cb) + def state_update_alert_cb(a): statuses = a.status for status in statuses: --