add preferences for display and size of columns in alltorrent mode

This commit is contained in:
Nick Lanham 2011-03-07 13:40:25 +01:00
parent 62da60a0e4
commit f2d560351e
3 changed files with 65 additions and 36 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# alltorrens.py
# alltorrents.py
#
# Copyright (C) 2011 Nick Lanham <nick@afternight.org>
#
@ -141,32 +141,31 @@ DEFAULT_PREFS = {
"show_peers":True,
"show_downspeed":True,
"show_upspeed":True,
"column_widths":{
"#":5,
"Name":-1,
"Size":15,
"State":13,
"Progress":10,
"Seeders":10,
"Peers":10,
"Down Speed":15,
"Up Speed":15}
"queue_width":5,
"name_width":-1,
"size_width":15,
"state_width":13,
"progress_width":10,
"seeders_width":10,
"peers_width":10,
"downspeed_width":15,
"upspeed_width":15,
}
column_prefs = ["show_queue","show_name","show_size","show_state",
"show_progress","show_seeders","show_peers",
"show_downspeed","show_upspeed"]
column_pref_names = ["queue","name","size","state",
"progress","seeders","peers",
"downspeed","upspeed"]
prefs_to_names = {
"show_queue":"#",
"show_name":"Name",
"show_size":"Size",
"show_state":"State",
"show_progress":"Progress",
"show_seeders":"Seeders",
"show_peers":"Peers",
"show_downspeed":"Down Speed",
"show_upspeed":"Up Speed"
"queue":"#",
"name":"Name",
"size":"Size",
"state":"State",
"progress":"Progress",
"seeders":"Seeders",
"peers":"Peers",
"downspeed":"Down Speed",
"upspeed":"Up Speed"
}
class StateUpdater(component.Component):
@ -215,7 +214,6 @@ class AllTorrents(BaseMode):
self.cursor = 0
self.coreconfig = component.get("ConsoleUI").coreconfig
self.__update_config()
self.legacy_mode = None
@ -229,7 +227,7 @@ class AllTorrents(BaseMode):
"num_peers","total_peers","download_payload_rate", "upload_payload_rate"]
self.updater = StateUpdater(self,self.set_state,self._status_fields,self._on_torrent_status)
self.__update_columns()
self.update_config()
self._info_fields = [
@ -258,10 +256,11 @@ class AllTorrents(BaseMode):
"seeding_time","time_added","distributed_copies", "num_pieces",
"piece_length","save_path"]
def __update_config(self):
def update_config(self):
self.config = ConfigManager("console.conf",DEFAULT_PREFS)
self.__columns = [prefs_to_names[pref] for pref in column_prefs if self.config[pref]]
self.__config_widths = self.config["column_widths"]
self.__cols_to_show = [pref for pref in column_pref_names if self.config["show_%s"%pref]]
self.__columns = [prefs_to_names[col] for col in self.__cols_to_show]
self.__update_columns()
def __split_help(self):
self.__help_lines = format_utils.wrap_string(HELP_STR,(self.cols/2)-2)
@ -270,9 +269,8 @@ class AllTorrents(BaseMode):
component.start(["AllTorrentsStateUpdater"])
self.refresh()
def __update_columns(self):
self.column_widths = [self.__config_widths[c] for c in self.__columns]
self.column_widths = [self.config["%s_width"%c] for c in self.__cols_to_show]
req = sum(filter(lambda x:x >= 0,self.column_widths))
if (req > self.cols): # can't satisfy requests, just spread out evenly
cw = int(self.cols/len(self.__columns))
@ -418,7 +416,7 @@ class AllTorrents(BaseMode):
def _on_get_cache_status(status,port,config):
component.stop(["AllTorrentsStateUpdater"])
self.stdscr.clear()
prefs = Preferences(self,config,port,status,self.stdscr,self.encoding)
prefs = Preferences(self,config,self.config,port,status,self.stdscr,self.encoding)
component.get("ConsoleUI").set_mode(prefs)
client.core.get_config().addCallback(_on_get_config)

View File

@ -34,6 +34,7 @@
#
from deluge.ui.console.modes.input_popup import TextInput,SelectInput,CheckedInput,IntSpinInput,FloatSpinInput,CheckedPlusInput
import deluge.ui.console.modes.alltorrents
try:
import curses
@ -293,9 +294,18 @@ class BandwidthPane(BasePane):
class InterfacePane(BasePane):
def __init__(self, offset, parent, width):
BasePane.__init__(self,offset,parent,width)
self.add_header("Interface Settings Comming Soon")
# add title bar control here
self.add_header("Columns To Display")
for cpn in deluge.ui.console.modes.alltorrents.column_pref_names:
pn = "show_%s"%cpn
self.add_checked_input(pn,
deluge.ui.console.modes.alltorrents.prefs_to_names[cpn],
parent.console_config[pn])
self.add_header("Column Widths (-1 = expand)",True)
for cpn in deluge.ui.console.modes.alltorrents.column_pref_names:
pn = "%s_width"%cpn
self.add_int_spin_input(pn,
deluge.ui.console.modes.alltorrents.prefs_to_names[cpn],
parent.console_config[pn],-1,100)
class OtherPane(BasePane):
def __init__(self, offset, parent, width):

View File

@ -105,7 +105,7 @@ class ZONE:
ACTIONS = 2
class Preferences(BaseMode):
def __init__(self, parent_mode, core_config, active_port, status, stdscr, encoding=None):
def __init__(self, parent_mode, core_config, console_config, active_port, status, stdscr, encoding=None):
self.parent_mode = parent_mode
self.categories = [_("Downloads"), _("Network"), _("Bandwidth"),
_("Interface"), _("Other"), _("Daemon"), _("Queue"), _("Proxy"),
@ -116,6 +116,7 @@ class Preferences(BaseMode):
self.action_input = None
self.core_config = core_config
self.console_config = console_config
self.active_port = active_port
self.status = status
@ -197,7 +198,8 @@ class Preferences(BaseMode):
def __apply_prefs(self):
new_core_config = {}
for pane in self.panes:
pane.add_config_values(new_core_config)
if not isinstance(pane,InterfacePane):
pane.add_config_values(new_core_config)
# Apply Core Prefs
if client.connected():
# Only do this if we're connected to a daemon
@ -214,6 +216,25 @@ class Preferences(BaseMode):
# Update the configuration
self.core_config.update(config_to_set)
# Update Interface Prefs
new_console_config = {}
didupdate = False
for pane in self.panes:
# could just access panes by index, but that would break if panes
# are ever reordered, so do it the slightly slower but safer way
if isinstance(pane,InterfacePane):
pane.add_config_values(new_console_config)
for key in new_console_config.keys():
# The values do not match so this needs to be updated
if self.console_config[key] != new_console_config[key]:
self.console_config[key] = new_console_config[key]
didupdate = True
if didupdate:
# changed something, save config and tell alltorrents
self.console_config.save()
self.parent_mode.update_config()
def __update_preferences(self,core_config):
self.core_config = core_config
for pane in self.panes: