From 4a071ecba17110db822898185aebc7ef41a151a4 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 14 Feb 2011 12:38:18 +0100 Subject: [PATCH] add an eventview --- deluge/ui/console/modes/alltorrents.py | 10 +++ deluge/ui/console/modes/eventview.py | 105 +++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 deluge/ui/console/modes/eventview.py diff --git a/deluge/ui/console/modes/alltorrents.py b/deluge/ui/console/modes/alltorrents.py index 049103666..2e4056ed3 100644 --- a/deluge/ui/console/modes/alltorrents.py +++ b/deluge/ui/console/modes/alltorrents.py @@ -49,6 +49,7 @@ from input_popup import InputPopup from torrentdetail import TorrentDetail from preferences import Preferences from torrent_actions import torrent_actions_popup +from eventview import EventView import format_utils @@ -336,6 +337,12 @@ class AllTorrents(BaseMode): prefs = Preferences(self,core_config,self.stdscr,self.encoding) component.get("ConsoleUI").set_mode(prefs) + def __show_events(self): + component.stop(["AllTorrentsStateUpdater"]) + self.stdscr.clear() + ev = EventView(self,self.stdscr,self.encoding) + component.get("ConsoleUI").set_mode(ev) + def _torrent_filter(self, idx, data): if data==FILTER.ALL: self.updater.status_dict = {} @@ -614,5 +621,8 @@ class AllTorrents(BaseMode): elif chr(c) == 'p': client.core.get_config().addCallback(self.show_preferences) return + elif chr(c) == 'e': + self.__show_events() + return self.refresh(effected_lines) diff --git a/deluge/ui/console/modes/eventview.py b/deluge/ui/console/modes/eventview.py new file mode 100644 index 000000000..31fb606a0 --- /dev/null +++ b/deluge/ui/console/modes/eventview.py @@ -0,0 +1,105 @@ +# -*- coding: utf-8 -*- +# +# eventview.py +# +# Copyright (C) 2011 Nick Lanham +# +# Deluge is free software. +# +# You may redistribute it and/or modify it under the terms of the +# GNU General Public License, as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) +# any later version. +# +# deluge is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with deluge. If not, write to: +# The Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301, USA. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. +# +# + +import deluge.component as component +from basemode import BaseMode +try: + import curses +except ImportError: + pass + +import logging +log = logging.getLogger(__name__) + +class EventView(BaseMode): + def __init__(self, parent_mode, stdscr, encoding=None): + self.parent_mode = parent_mode + BaseMode.__init__(self, stdscr, encoding) + + def refresh(self): + "This method just shows each line of the event log" + events = component.get("ConsoleUI").events + + self.add_string(0,self.statusbars.topbar) + hstr = "%sPress [h] for help"%(" "*(self.cols - len(self.statusbars.bottombar) - 10)) + self.add_string(self.rows - 1, "%s%s"%(self.statusbars.bottombar,hstr)) + + if events: + for i,event in enumerate(events): + self.add_string(i+1,event) + else: + self.add_string(1,"{!white,black,bold!}No events to show yet") + + self.stdscr.noutrefresh() + curses.doupdate() + + def back_to_overview(self): + self.stdscr.clear() + component.get("ConsoleUI").set_mode(self.parent_mode) + self.parent_mode.resume() + + def _doRead(self): + c = self.stdscr.getch() + + if c > 31 and c < 256: + if chr(c) == 'Q': + from twisted.internet import reactor + if client.connected(): + def on_disconnect(result): + reactor.stop() + client.disconnect().addCallback(on_disconnect) + else: + reactor.stop() + return + elif chr(c) == 'q': + self.back_to_overview() + return + + if c == 27: + self.back_to_overview() + return + + # TODO: Scroll event list + if c == curses.KEY_UP: + pass + elif c == curses.KEY_PPAGE: + pass + elif c == curses.KEY_DOWN: + pass + elif c == curses.KEY_NPAGE: + pass + + #self.refresh()