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
commit b1439274c6
4 changed files with 52 additions and 38 deletions

View file

@ -168,6 +168,7 @@ DEFAULT_PREFS = {
"downloaded_width":13,
"uploaded_width":13,
"owner_width":10,
"disable_three_dots": False
}
column_pref_names = ["queue","name","size","state",
@ -313,7 +314,7 @@ class AllTorrents(BaseMode, component.Component):
for torrent_id in self._sorted_ids:
ts = self.curstate[torrent_id]
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.formatted_rows = newrows
@ -422,7 +423,7 @@ class AllTorrents(BaseMode, component.Component):
def dodeets(arg):
if arg and True in arg[0]:
self.stdscr.clear()
component.get("ConsoleUI").set_mode(TorrentDetail(self,tid,self.stdscr,self.encoding))
component.get("ConsoleUI").set_mode(TorrentDetail(self,tid,self.stdscr, self.config, self.encoding))
else:
self.messages.append(("Error","An error occured trying to display torrent details"))
component.stop(["AllTorrents"]).addCallback(dodeets)

View file

@ -80,10 +80,13 @@ def format_priority(prio):
else:
return pstring
def trim_string(string, w, have_dbls):
def trim_string(string, w, have_dbls, console_config):
if w <= 0:
return ""
elif w == 1:
if console_config["disable_three_dots"]:
return u" "
else:
return u""
elif have_dbls:
# have to do this the slow way
@ -100,11 +103,17 @@ def trim_string(string, w, have_dbls):
if width != w:
chrs.pop()
chrs.append('.')
if console_config["disable_three_dots"]:
return u"%s "%("".join(chrs))
else:
return u"%s"%("".join(chrs))
else:
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
if haveud and isinstance(col,unicode):
# might have some double width chars
@ -115,12 +124,12 @@ def format_column(col, lim):
dbls += 1
size = len(col)+dbls
if (size >= lim - 1):
return trim_string(col,lim,dbls>0)
return trim_string(col,lim,dbls>0, console_config)
else:
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
from collections import deque

View file

@ -310,6 +310,8 @@ class BandwidthPane(BasePane):
class InterfacePane(BasePane):
def __init__(self, offset, parent, width):
BasePane.__init__(self,offset,parent,width)
self.add_header("General")
self.add_checked_input("disable_three_dots","Do not append three dots symbol when trimming columns",parent.console_config["disable_three_dots"])
self.add_header("Columns To Display")
for cpn in deluge.ui.console.modes.alltorrents.column_pref_names:
pn = "show_%s"%cpn

View file

@ -89,7 +89,9 @@ download priority of selected files.
"""
class TorrentDetail(BaseMode, component.Component):
def __init__(self, alltorrentmode, torrentid, stdscr, encoding=None):
def __init__(self, alltorrentmode, torrentid, stdscr, console_config, encoding=None):
self.console_config = console_config
self.alltorrentmode = alltorrentmode
self.torrentid = torrentid
self.torrent_state = None
@ -321,7 +323,7 @@ class TorrentDetail(BaseMode, component.Component):
r = format_utils.format_row(["%s%s %s"%(" "*depth,xchar,fl[0]),
deluge.common.fsize(fl[2]),fl[5],
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)
off += 1