From 47ba11be1b487253e0139eb7f981aa030e6f992e Mon Sep 17 00:00:00 2001 From: Asmageddon Date: Wed, 29 Feb 2012 20:33:58 +0100 Subject: [PATCH] Pass console config to torrentdetail and format_utils, add an option to disable three dots when trimming columns(they piss me off) --- deluge/ui/console/modes/alltorrents.py | 7 ++---- deluge/ui/console/modes/format_utils.py | 28 ++++++++++++++------- deluge/ui/console/modes/preference_panes.py | 8 ++---- deluge/ui/console/modes/torrentdetail.py | 2 +- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/deluge/ui/console/modes/alltorrents.py b/deluge/ui/console/modes/alltorrents.py index 2b2c6f506..411cac636 100644 --- a/deluge/ui/console/modes/alltorrents.py +++ b/deluge/ui/console/modes/alltorrents.py @@ -170,10 +170,7 @@ DEFAULT_PREFS = { "downloaded_width":13, "uploaded_width":13, "owner_width":10, - "ignore_duplicate_lines": False, - "move_selection": True, - "third_tab_lists_all": False, - "torrents_per_tab_press": 15 + "disable_three_dots": False } column_pref_names = ["queue","name","size","state", @@ -349,7 +346,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 diff --git a/deluge/ui/console/modes/format_utils.py b/deluge/ui/console/modes/format_utils.py index 87c5a7e33..f0f46486c 100644 --- a/deluge/ui/console/modes/format_utils.py +++ b/deluge/ui/console/modes/format_utils.py @@ -80,11 +80,14 @@ 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: - return u" " + if console_config["disable_three_dots"]: + return u" " + else: + return u"…" elif have_dbls: # have to do this the slow way chrs = [] @@ -100,11 +103,17 @@ def trim_string(string, w, have_dbls): if width != w: chrs.pop() 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: - 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 if haveud and isinstance(col,unicode): # might have some double width chars @@ -115,12 +124,13 @@ 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 _strip_re = re.compile("\{!.*?!\}") @@ -230,4 +240,4 @@ def pad_string(string, length, character=" ", side="right"): if side == "left": return "%s%s" % (character * diff, string) elif side == "right": - return "%s%s" % (string, character * diff) \ No newline at end of file + return "%s%s" % (string, character * diff) diff --git a/deluge/ui/console/modes/preference_panes.py b/deluge/ui/console/modes/preference_panes.py index 5df5602b3..848ea8bc6 100644 --- a/deluge/ui/console/modes/preference_panes.py +++ b/deluge/ui/console/modes/preference_panes.py @@ -311,12 +311,8 @@ class InterfacePane(BasePane): def __init__(self, offset, parent, width): BasePane.__init__(self,offset,parent,width) 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("move_selection","Move selection when moving torrents in the queue",parent.console_config["move_selection"]) - 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) + 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 self.add_checked_input(pn, diff --git a/deluge/ui/console/modes/torrentdetail.py b/deluge/ui/console/modes/torrentdetail.py index d1197e8b7..405b61a4a 100644 --- a/deluge/ui/console/modes/torrentdetail.py +++ b/deluge/ui/console/modes/torrentdetail.py @@ -333,7 +333,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