deluge/deluge/ui/console/modes/eventview.py
bendikro 20bae1bf90 [Console] Rewrite of the console code
This commit is a rewrite of larger parts of the console code. The
motivation behind the rewrite is to cleanup the code and reduce code
duplication to make it easier to understand and modify, and allow any
form of code reuse. Most changes are to the interactive console, but
also to how the different modes (BaseMode subclasses) are used and set
up.

* Address [#2097] - Improve match_torrent search match:
  Instead of matching e.g. torrent name with name.startswith(pattern)
  now check for asterix at beginning and end of pattern and search
  with startswith, endswith or __contains__ according to the pattern.

Various smaller fixes:
* Add errback handler to connection failed
* Fix cmd line console mixing str and unicode input
* Fix handling delete backwards with ALT+Backspace
* Fix handling resizing of message popups
* Fix docs generation warnings
* Lets not stop the reactor on exception in basemode..
* Markup for translation arg help strings

* Main functionality improvements:
 - Add support for indentation in formatting code in popup messages (like help)
 - Add filter sidebar
 - Add ComboBox and UI language selection
 - Add columnsview to allow rearranging the torrentlist columns
   and changing column widths.
 - Removed Columns pane in preferences as columnsview.py is sufficient
 - Remove torrent info panel (short cut 'i') as the torrent detail view
   is sufficient

* Cleanups and code restructuring
  - Made BaseModes subclass of Component
  - Rewrite of most of basic window/panel to allow easier code reuse
  - Implemented better handling of multple popups by stacking popups. This
    makes it easier to return to previous popup when opening multiple popups.

* Refactured console code:
  - modes/ for the different modes
    - Renamed Legacy mode to CmdLine
    - Renamed alltorrent.py to torrentlist.py and split the code into
      - torrentlist/columnsview.py
      - torrentlist/torrentsview.py
      - torrentlist/search_mode.py (minor mode)
      - torrentlist/queue_mode.py (minor mode)
  - cmdline/ for cmd line commands
  - utils/ for utility files
  - widgets/ for reusable GUI widgets
    - fields.py: Base widgets like TextInput, SelectInput, ComboInput
    - popup.py: Popup windows
    - inputpane.py: The BaseInputPane used to manage multiple base widgets in a panel
	- window.py: The BaseWindow used by all panels needing a curses screen
    - sidebar.py: The Sidebar panel
    - statusbars.py: The statusbars
  - Moved option parsing code from main.py to parser.py
2016-10-30 12:45:04 +00:00

115 lines
3.3 KiB
Python

# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Nick Lanham <nick@afternight.org>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#
import logging
import deluge.component as component
from deluge.decorators import overrides
from deluge.ui.console.modes.basemode import BaseMode
from deluge.ui.console.utils import curses_util as util
try:
import curses
except ImportError:
pass
log = logging.getLogger(__name__)
class EventView(BaseMode):
def __init__(self, parent_mode, stdscr, encoding=None):
BaseMode.__init__(self, stdscr, encoding)
self.parent_mode = parent_mode
self.offset = 0
def back_to_overview(self):
component.get("ConsoleUI").set_mode(self.parent_mode.mode_name)
@overrides(component.Component)
def update(self):
self.refresh()
@overrides(BaseMode)
def refresh(self):
"""
This method just shows each line of the event log
"""
events = component.get("ConsoleUI").events
self.stdscr.erase()
self.draw_statusbars()
if events:
for i, event in enumerate(events):
if i - self.offset >= self.rows - 2:
more = len(events) - self.offset - self.rows + 2
if more > 0:
self.add_string(i - self.offset, " (And %i more)" % more)
break
elif i - self.offset < 0:
continue
try:
self.add_string(i + 1 - self.offset, event)
except curses.error:
pass # This'll just cut the line. Note: This seriously should be fixed in a better way
else:
self.add_string(1, "{!white,black,bold!}No events to show yet")
if not component.get("ConsoleUI").is_active_mode(self):
return
self.stdscr.noutrefresh()
curses.doupdate()
@overrides(BaseMode)
def on_resize(self, rows, cols):
BaseMode.on_resize(self, rows, cols)
self.refresh()
@overrides(BaseMode)
def read_input(self):
c = self.stdscr.getch()
if c in [ord('q'), util.KEY_ESC]:
self.back_to_overview()
return
# TODO: Scroll event list
jumplen = self.rows - 3
num_events = len(component.get("ConsoleUI").events)
if c == curses.KEY_UP:
self.offset -= 1
elif c == curses.KEY_PPAGE:
self.offset -= jumplen
elif c == curses.KEY_HOME:
self.offset = 0
elif c == curses.KEY_DOWN:
self.offset += 1
elif c == curses.KEY_NPAGE:
self.offset += jumplen
elif c == curses.KEY_END:
self.offset += num_events
elif c == ord("j"):
self.offset -= 1
elif c == ord("k"):
self.offset += 1
if self.offset <= 0:
self.offset = 0
elif num_events > self.rows - 3:
if self.offset > num_events - self.rows + 3:
self.offset = num_events - self.rows + 3
else:
self.offset = 0
self.refresh()