From dd64eda4325d69ffbf2459b5403439745ce1ec68 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Fri, 17 Aug 2007 03:44:32 +0000 Subject: [PATCH] little cleanup of width setting and saving --- plugins/TorrentFiles/tab_files.py | 4 +-- plugins/TorrentPeers/tab_peers.py | 28 ++++++++++------ plugins/TorrentSearch/plugin.py | 4 +-- src/dgtk.py | 20 +++++++++--- src/files.py | 12 +++---- src/interface.py | 54 +++++++++---------------------- 6 files changed, 58 insertions(+), 64 deletions(-) diff --git a/plugins/TorrentFiles/tab_files.py b/plugins/TorrentFiles/tab_files.py index 887263437..75bf5ee4a 100644 --- a/plugins/TorrentFiles/tab_files.py +++ b/plugins/TorrentFiles/tab_files.py @@ -29,8 +29,8 @@ class FilesTabManager(FilesBaseManager): percent = float(model.get_value(iter, data)) percent_str = "%.2f%%"%percent cell.set_property("text", percent_str) - percent_col = dgtk.add_func_column(self.file_view, _("Progress"), percent, 3) - percent_col.set_fixed_width(90) + percent_col = dgtk.add_func_column(self.file_view, _("Progress"), \ + percent, 3, width=90) self.file_view.connect("row-activated", self.double_click_file) def set_unique_id(self, unique_id): diff --git a/plugins/TorrentPeers/tab_peers.py b/plugins/TorrentPeers/tab_peers.py index 69777c14f..b1947df15 100644 --- a/plugins/TorrentPeers/tab_peers.py +++ b/plugins/TorrentPeers/tab_peers.py @@ -1,4 +1,5 @@ from itertools import izip +import deluge from deluge import dgtk from deluge import common import gobject @@ -8,6 +9,18 @@ class PeersTabManager(object): self.peer_view = peer_view self.manager = manager self.peer_unique_id = None + self.config_file = deluge.common.CONFIG_DIR + "/peers.conf" + self.config = deluge.pref.Preferences(self.config_file, False, + defaults={'ip_p_width': 120, + 'client_p_width' : 120, + 'percent_p_width': 90, + 'down_p_width': 150, + 'up_p_width': 115}) + try: + self.config.load() + except IOError: + # File does not exist + pass # IP int, IP string, Client, Percent Complete, Down Speed, Up Speed # IP int is for faster sorting self.peer_store = gtk.ListStore(gobject.TYPE_UINT, gtk.gdk.Pixbuf, @@ -36,20 +49,15 @@ class PeersTabManager(object): # self.ip_column is used in self.ip_column_queue_resize() method self.ip_column = dgtk.add_texticon_column(self.peer_view, - _("IP Address"), 1, 2) + _("IP Address"), 1, 2, width=140) self.ip_column.set_sort_column_id(0) - self.ip_column.set_fixed_width(140) - client = dgtk.add_text_column(self.peer_view, _("Client"), 3) - client.set_fixed_width(120) + client = dgtk.add_text_column(self.peer_view, _("Client"), 3, width=120) percent = dgtk.add_func_column(self.peer_view, _("Percent Complete"), - percent, 4) - percent.set_fixed_width(150) + percent, 4, width=150) down = dgtk.add_func_column(self.peer_view, _("Down Speed"), - dgtk.cell_data_speed, 5) - down.set_fixed_width(115) + dgtk.cell_data_speed, 5, width=115) up = dgtk.add_func_column(self.peer_view, _("Up Speed"), - dgtk.cell_data_speed, 6) - up.set_fixed_width(115) + dgtk.cell_data_speed, 6, width=115) def enable_flags(self): self.show_flags = True diff --git a/plugins/TorrentSearch/plugin.py b/plugins/TorrentSearch/plugin.py index 97ebb8a30..f6416ca09 100644 --- a/plugins/TorrentSearch/plugin.py +++ b/plugins/TorrentSearch/plugin.py @@ -17,9 +17,9 @@ class plugin_Search: self.view = glade.get_widget("search_view") model = gtk.ListStore(str, str) self.view.set_model(model) - deluge.dgtk.add_text_column(self.view, _("Name"), 0) + deluge.dgtk.add_text_column(self.view, _("Name"), 0, width=80) deluge.dgtk.add_text_column(self.view, _("Search String"), 1) - self.field_name = glade.get_widget("field_name") + self.field_name = glade.get_widget("field_name") self.field_search = glade.get_widget("field_search") self.button_add = glade.get_widget("button_addsearch") self.button_del = glade.get_widget("button_delsearch") diff --git a/src/dgtk.py b/src/dgtk.py index 2bec7a82a..c22e993a4 100644 --- a/src/dgtk.py +++ b/src/dgtk.py @@ -63,7 +63,7 @@ def cell_data_size(column, cell, model, iter, data): ## Functions to create columns -def add_func_column(view, header, func, data, sortid=None): +def add_func_column(view, header, func, data, sortid=None, width=None): column = gtk.TreeViewColumn(header) render = gtk.CellRendererText() column.pack_start(render, True) @@ -81,6 +81,8 @@ def add_func_column(view, header, func, data, sortid=None): column.set_sort_column_id(data) column.set_resizable(True) column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) + if width: + column.set_fixed_width(width) column.set_expand(False) column.set_min_width(10) column.set_reorderable(True) @@ -88,20 +90,22 @@ def add_func_column(view, header, func, data, sortid=None): return column -def add_text_column(view, header, cid): +def add_text_column(view, header, cid, width=None): render = gtk.CellRendererText() column = gtk.TreeViewColumn(header, render, text=cid) column.set_clickable(True) column.set_sort_column_id(cid) column.set_resizable(True) column.set_expand(False) + if width: + column.set_fixed_width(width) column.set_min_width(10) column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) column.set_reorderable(True) view.append_column(column) return column -def add_progress_column(view, header, pid, mid): +def add_progress_column(view, header, pid, mid, width=None): render = gtk.CellRendererProgress() column = gtk.TreeViewColumn(header, render, value=pid, text=mid) column.set_clickable(True) @@ -109,18 +113,22 @@ def add_progress_column(view, header, pid, mid): column.set_resizable(True) column.set_expand(False) column.set_min_width(10) + if width: + column.set_fixed_width(width) column.set_reorderable(True) column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) view.append_column(column) return column -def add_toggle_column(view, header, cid, toggled_signal=None): +def add_toggle_column(view, header, cid, toggled_signal=None, width=None): render = gtk.CellRendererToggle() render.set_property('activatable', True) column = gtk.TreeViewColumn(header, render, active=cid) column.set_clickable(True) column.set_resizable(True) column.set_expand(False) + if width: + column.set_fixed_width(width) column.set_min_width(10) column.set_reorderable(True) view.append_column(column) @@ -128,11 +136,13 @@ def add_toggle_column(view, header, cid, toggled_signal=None): render.connect("toggled", toggled_signal) return column -def add_texticon_column(view, header, icon_col, text_col): +def add_texticon_column(view, header, icon_col, text_col, width=None): column = gtk.TreeViewColumn(header) column.set_clickable(True) column.set_resizable(True) column.set_expand(False) + if width: + column.set_fixed_width(width) column.set_min_width(10) column.set_reorderable(True) render = gtk.CellRendererPixbuf() diff --git a/src/files.py b/src/files.py index 453658304..a956e85c9 100644 --- a/src/files.py +++ b/src/files.py @@ -75,14 +75,12 @@ class FilesBaseManager(object): priority = common.fpriority(model.get_value(iter, data)) cell.set_property("text", priority) - filename_column = dgtk.add_text_column(self.file_view, _("Filename"), - 0) - filename_column.set_fixed_width(self.config.get("filename_f_width")) + filename_column = dgtk.add_text_column(self.file_view, _("Filename"), \ + 0, width=self.config.get("filename_f_width")) size_column = dgtk.add_func_column(self.file_view, _("Size"), dgtk.cell_data_size, - 1) - size_column.set_fixed_width(self.config.get("size_f_width")) - priority_column = dgtk.add_func_column(self.file_view, _("Priority"), priority, 2) - priority_column.set_fixed_width(self.config.get("priority_f_width")) + 1, width=self.config.get("size_f_width")) + priority_column = dgtk.add_func_column(self.file_view, _("Priority"), \ + priority, 2, width=self.config.get("priority_f_width")) self.file_view.set_model(self.file_store_sorted) self.file_view.get_selection().set_mode(gtk.SELECTION_MULTIPLE) diff --git a/src/interface.py b/src/interface.py index 1c94c2467..d0ef1b6bc 100644 --- a/src/interface.py +++ b/src/interface.py @@ -101,7 +101,6 @@ class DelugeGTK: try: self.load_window_settings() - self.load_column_widths() except KeyError: pass @@ -541,17 +540,17 @@ class DelugeGTK: TORRENT_VIEW_COL_UPLOAD, TORRENT_VIEW_COL_ETA, TORRENT_VIEW_COL_AVAILABILITY, TORRENT_VIEW_COL_RATIO) = range(16) - self.queue_column = dgtk.add_text_column(self.torrent_view, "#", TORRENT_VIEW_COL_QUEUE) - self.name_column = dgtk.add_texticon_column(self.torrent_view, _("Name"), TORRENT_VIEW_COL_STATUSICON, TORRENT_VIEW_COL_NAME) - self.size_column = dgtk.add_func_column(self.torrent_view, _("Size"), dgtk.cell_data_size, TORRENT_VIEW_COL_SIZE) - self.status_column = dgtk.add_progress_column(self.torrent_view, _("Status"), TORRENT_VIEW_COL_PROGRESS, TORRENT_VIEW_COL_STATUS) - self.seed_column = dgtk.add_func_column(self.torrent_view, _("Seeders"), peer, (TORRENT_VIEW_COL_CONNECTED_SEEDS, TORRENT_VIEW_COL_SEEDS)) - self.peer_column = dgtk.add_func_column(self.torrent_view, _("Peers"), peer, (TORRENT_VIEW_COL_CONNECTED_PEERS, TORRENT_VIEW_COL_PEERS)) - self.dl_column = dgtk.add_func_column(self.torrent_view, _("Down Speed"), dgtk.cell_data_speed, TORRENT_VIEW_COL_DOWNLOAD) - self.ul_column = dgtk.add_func_column(self.torrent_view, _("Up Speed"), dgtk.cell_data_speed, TORRENT_VIEW_COL_UPLOAD) - self.eta_column = dgtk.add_func_column(self.torrent_view, _("ETA"), time, TORRENT_VIEW_COL_ETA) - self.availability_column = dgtk.add_func_column(self.torrent_view, _("Avail."), availability, TORRENT_VIEW_COL_AVAILABILITY) - self.share_column = dgtk.add_func_column(self.torrent_view, _("Ratio"), ratio, TORRENT_VIEW_COL_RATIO) + self.queue_column = dgtk.add_text_column(self.torrent_view, "#", TORRENT_VIEW_COL_QUEUE, width=self.config.get("queue_width")) + self.name_column = dgtk.add_texticon_column(self.torrent_view, _("Name"), TORRENT_VIEW_COL_STATUSICON, TORRENT_VIEW_COL_NAME, width=self.config.get("name_width")) + self.size_column = dgtk.add_func_column(self.torrent_view, _("Size"), dgtk.cell_data_size, TORRENT_VIEW_COL_SIZE, width=self.config.get("size_width")) + self.status_column = dgtk.add_progress_column(self.torrent_view, _("Status"), TORRENT_VIEW_COL_PROGRESS, TORRENT_VIEW_COL_STATUS, width=self.config.get("status_width")) + self.seed_column = dgtk.add_func_column(self.torrent_view, _("Seeders"), peer, (TORRENT_VIEW_COL_CONNECTED_SEEDS, TORRENT_VIEW_COL_SEEDS), width=self.config.get("seed_width")) + self.peer_column = dgtk.add_func_column(self.torrent_view, _("Peers"), peer, (TORRENT_VIEW_COL_CONNECTED_PEERS, TORRENT_VIEW_COL_PEERS), width=self.config.get("peer_width")) + self.dl_column = dgtk.add_func_column(self.torrent_view, _("Down Speed"), dgtk.cell_data_speed, TORRENT_VIEW_COL_DOWNLOAD, width=self.config.get("dl_width")) + self.ul_column = dgtk.add_func_column(self.torrent_view, _("Up Speed"), dgtk.cell_data_speed, TORRENT_VIEW_COL_UPLOAD, width=self.config.get("ul_width")) + self.eta_column = dgtk.add_func_column(self.torrent_view, _("ETA"), time, TORRENT_VIEW_COL_ETA, width=self.config.get("eta_width")) + self.availability_column = dgtk.add_func_column(self.torrent_view, _("Avail."), availability, TORRENT_VIEW_COL_AVAILABILITY, width=self.config.get("availability_width")) + self.share_column = dgtk.add_func_column(self.torrent_view, _("Ratio"), ratio, TORRENT_VIEW_COL_RATIO, width=self.config.get("share_width")) self.name_column.set_sort_column_id(TORRENT_VIEW_COL_NAME) self.seed_column.set_sort_column_id(TORRENT_VIEW_COL_CONNECTED_SEEDS) @@ -559,7 +558,6 @@ class DelugeGTK: self.torrent_model.set_sort_column_id(TORRENT_VIEW_COL_QUEUE, gtk.SORT_ASCENDING) - try: self.torrent_view.get_selection().set_select_function(self.torrent_clicked, full=True) except TypeError: @@ -1304,32 +1302,12 @@ class DelugeGTK: self.config.set("show_share", self.share_column.get_visible()) self.config.set("window_pane_position", self.config.get("window_height") - self.wtree.get_widget("vpaned1").get_position()) - def load_column_widths(self): - self.queue_column.set_fixed_width(self.config.get("queue_width")) - self.name_column.set_fixed_width(self.config.get("name_width")) - self.size_column.set_fixed_width(self.config.get("size_width")) - self.status_column.set_fixed_width(self.config.get("status_width")) - self.seed_column.set_fixed_width(self.config.get("seed_width")) - self.peer_column.set_fixed_width(self.config.get("peer_width")) - self.dl_column.set_fixed_width(self.config.get("dl_width")) - self.ul_column.set_fixed_width(self.config.get("ul_width")) - self.eta_column.set_fixed_width(self.config.get("eta_width")) - self.availability_column.set_fixed_width(self.config.get("availability_width")) - self.share_column.set_fixed_width(self.config.get("share_width")) - def save_column_widths(self): - self.config.set("queue_width", self.queue_column.get_width()) - self.config.set("name_width", self.name_column.get_width()) - self.config.set("size_width", self.size_column.get_width()) - self.config.set("status_width", self.status_column.get_width()) - self.config.set("seed_width", self.seed_column.get_width()) - self.config.set("peer_width", self.peer_column.get_width()) - self.config.set("dl_width", self.dl_column.get_width()) - self.config.set("ul_width", self.ul_column.get_width()) - self.config.set("eta_width", self.eta_column.get_width()) - self.config.set("availability_width", self.availability_column.get_width()) - self.config.set("share_width", self.share_column.get_width()) - + to_save = ["queue", "name", "size", "status", "seed", "peer", "dl", \ + "ul", "eta", "availability", "share"] + for columns in to_save: + pref_name = columns + '_width' + self.config.set(pref_name, eval('self.' + columns + '_column.get_width()')) def window_configure_event(self, widget, event): if self.config.get("window_maximized") == False: