Pass console config to torrentdetail and format_utils, add an option to disable three dots when trimming columns(they piss me off)

This commit is contained in:
Asmageddon 2012-02-29 20:33:58 +01:00
parent 163870afd9
commit 47ba11be1b
4 changed files with 24 additions and 21 deletions

View File

@ -170,10 +170,7 @@ DEFAULT_PREFS = {
"downloaded_width":13, "downloaded_width":13,
"uploaded_width":13, "uploaded_width":13,
"owner_width":10, "owner_width":10,
"ignore_duplicate_lines": False, "disable_three_dots": False
"move_selection": True,
"third_tab_lists_all": False,
"torrents_per_tab_press": 15
} }
column_pref_names = ["queue","name","size","state", column_pref_names = ["queue","name","size","state",
@ -349,7 +346,7 @@ class AllTorrents(BaseMode, component.Component):
for torrent_id in self._sorted_ids: for torrent_id in self._sorted_ids:
ts = self.curstate[torrent_id] ts = self.curstate[torrent_id]
newnames.append(ts["name"]) newnames.append(ts["name"])
newrows.append((format_utils.format_row([column.get_column_value(name,ts) for name in self.__columns],self.column_widths),ts["state"])) newrows.append((format_utils.format_row([column.get_column_value(name,ts) for name in self.__columns],self.column_widths, self.config),ts["state"]))
self.numtorrents = len(state) self.numtorrents = len(state)
self.formatted_rows = newrows self.formatted_rows = newrows

View File

@ -80,11 +80,14 @@ def format_priority(prio):
else: else:
return pstring return pstring
def trim_string(string, w, have_dbls): def trim_string(string, w, have_dbls, console_config):
if w <= 0: if w <= 0:
return "" return ""
elif w == 1: elif w == 1:
return u" " if console_config["disable_three_dots"]:
return u" "
else:
return u""
elif have_dbls: elif have_dbls:
# have to do this the slow way # have to do this the slow way
chrs = [] chrs = []
@ -100,11 +103,17 @@ def trim_string(string, w, have_dbls):
if width != w: if width != w:
chrs.pop() chrs.pop()
chrs.append('.') chrs.append('.')
return u"%s "%("".join(chrs)) if console_config["disable_three_dots"]:
return u"%s "%("".join(chrs))
else:
return u"%s"%("".join(chrs))
else: else:
return u"%s "%(string[0:w-1]) if console_config["disable_three_dots"]:
return u"%s "%(string[0:w-1])
else:
return u"%s"%(string[0:w-2])
def format_column(col, lim): def format_column(col, lim, console_config):
dbls = 0 dbls = 0
if haveud and isinstance(col,unicode): if haveud and isinstance(col,unicode):
# might have some double width chars # might have some double width chars
@ -115,12 +124,13 @@ def format_column(col, lim):
dbls += 1 dbls += 1
size = len(col)+dbls size = len(col)+dbls
if (size >= lim - 1): if (size >= lim - 1):
return trim_string(col,lim,dbls>0) return trim_string(col,lim,dbls>0, console_config)
else: else:
return "%s%s"%(col," "*(lim-size)) return "%s%s"%(col," "*(lim-size))
def format_row(row, column_widths):
return "".join([format_column(row[i],column_widths[i]) for i in range(0,len(row))]) def format_row(row,column_widths, console_config):
return "".join([format_column(row[i],column_widths[i], console_config) for i in range(0,len(row))])
import re import re
_strip_re = re.compile("\{!.*?!\}") _strip_re = re.compile("\{!.*?!\}")
@ -230,4 +240,4 @@ def pad_string(string, length, character=" ", side="right"):
if side == "left": if side == "left":
return "%s%s" % (character * diff, string) return "%s%s" % (character * diff, string)
elif side == "right": elif side == "right":
return "%s%s" % (string, character * diff) return "%s%s" % (string, character * diff)

View File

@ -311,12 +311,8 @@ class InterfacePane(BasePane):
def __init__(self, offset, parent, width): def __init__(self, offset, parent, width):
BasePane.__init__(self,offset,parent,width) BasePane.__init__(self,offset,parent,width)
self.add_header("General") self.add_header("General")
self.add_checked_input("ignore_duplicate_lines","Do not store duplicate input in history",parent.console_config["ignore_duplicate_lines"]) self.add_checked_input("disable_three_dots","Do not append three dots symbol when trimming columns",parent.console_config["disable_three_dots"])
self.add_checked_input("move_selection","Move selection when moving torrents in the queue",parent.console_config["move_selection"]) self.add_header("Columns To Display")
self.add_checked_input("third_tab_lists_all","Third tab lists all remaining torrents in legacy mode",parent.console_config["third_tab_lists_all"])
self.add_int_spin_input("torrents_per_tab_press","Torrents per tab press",parent.console_config["torrents_per_tab_press"], 5, 100)
self.add_header("Columns To Display", True)
for cpn in deluge.ui.console.modes.alltorrents.column_pref_names: for cpn in deluge.ui.console.modes.alltorrents.column_pref_names:
pn = "show_%s"%cpn pn = "show_%s"%cpn
self.add_checked_input(pn, self.add_checked_input(pn,

View File

@ -333,7 +333,7 @@ class TorrentDetail(BaseMode, component.Component):
r = format_utils.format_row(["%s%s %s"%(" "*depth,xchar,fl[0]), r = format_utils.format_row(["%s%s %s"%(" "*depth,xchar,fl[0]),
deluge.common.fsize(fl[2]),fl[5], deluge.common.fsize(fl[2]),fl[5],
format_utils.format_priority(fl[6])], format_utils.format_priority(fl[6])],
self.column_widths) self.column_widths, self.console_config)
self.add_string(off,"%s%s"%(color_string,r),trim=False) self.add_string(off,"%s%s"%(color_string,r),trim=False)
off += 1 off += 1