Author: s0undt3ch

Revision: 6069

Log:
        Allow choosing which columns are seen on the torrent view by 
right-clicking it's headers.

Diff:
Modified: trunk/deluge/ui/gtkui/listview.py
===================================================================
--- trunk/deluge/ui/gtkui/listview.py   2010-01-01 21:23:57 UTC (rev 6068)
+++ trunk/deluge/ui/gtkui/listview.py   2010-01-01 21:27:13 UTC (rev 6069)
@@ -18,9 +18,9 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with deluge.    If not, write to:
-#      The Free Software Foundation, Inc.,
-#      51 Franklin Street, Fifth Floor
-#      Boston, MA  02110-1301, USA.
+#     The Free Software Foundation, Inc.,
+#     51 Franklin Street, Fifth Floor
+#     Boston, MA  02110-1301, USA.
 #
 #    In addition, as a special exception, the copyright holders give
 #    permission to link the code of portions of this program with the OpenSSL
@@ -48,6 +48,12 @@
 import deluge.common
 from deluge.log import LOG as log
 
+from gobject import signal_new, SIGNAL_RUN_LAST, TYPE_NONE
+from gtk import gdk
+signal_new('button-press-event', gtk.TreeViewColumn,
+           SIGNAL_RUN_LAST, TYPE_NONE, (gdk.Event,))
+
+
 # Cell data functions to pass to add_func_column()
 def cell_data_speed(column, cell, model, row, data):
     """Display value as a speed, eg. 2 KiB/s"""
@@ -132,6 +138,32 @@
             self.sort_func = None
             self.sort_id = None
 
+    class TreeviewColumn(gtk.TreeViewColumn):
+        """
+            TreeViewColumn does not signal right-click events, and we need them
+            This subclass is equivalent to TreeViewColumn, but it signals 
these events
+
+            Most of the code of this class comes from Quod Libet 
(http://www.sacredchao.net/quodlibet)
+        """
+
+        def __init__(self, title=None, cell_renderer=None, ** args):
+            """ Constructor, see gtk.TreeViewColumn """
+            gtk.TreeViewColumn.__init__(self, title, cell_renderer, ** args)
+            label = gtk.Label(title)
+            self.set_widget(label)
+            label.show()
+            label.__realize = label.connect('realize', self.onRealize)
+
+        def onRealize(self, widget):
+            widget.disconnect(widget.__realize)
+            del widget.__realize
+            button = widget.get_ancestor(gtk.Button)
+            if button is not None:
+                button.connect('button-press-event', self.onButtonPressed)
+
+        def onButtonPressed(self, widget, event):
+            self.emit('button-press-event', event)
+
     def __init__(self, treeview_widget=None, state_file=None):
         log.debug("ListView initialized..")
 
@@ -292,6 +324,11 @@
         self.columns[name].column.set_visible(widget.get_active())
         return
 
+    def on_treeview_header_right_clicked(self, column, event):
+        if event.button == 3:
+            self.menu.popup(None, None, None, event.button, event.get_time())
+
+
     def register_checklist_menu(self, menu):
         """Register a checklist menu with the listview.  It will automatically
         attach any new checklist menu it makes to this menu.
@@ -300,7 +337,7 @@
 
     def create_checklist_menu(self):
         """Creates a menu used for toggling the display of columns."""
-        menu = gtk.Menu()
+        menu = self.menu = gtk.Menu()
         # Iterate through the column_index list to preserve order
         for name in self.column_index:
             column = self.columns[name]
@@ -322,7 +359,6 @@
         for _menu in self.checklist_menus:
             _menu.set_submenu(menu)
             _menu.show_all()
-
         return menu
 
     def create_new_liststore(self):
@@ -415,7 +451,8 @@
         # Create a new list with the added column
         self.create_new_liststore()
 
-        column = gtk.TreeViewColumn(header)
+        column = self.TreeviewColumn(header)
+
         if column_type == "text":
             column.pack_start(render)
             column.add_attribute(render, "text",
@@ -460,6 +497,8 @@
         column.set_min_width(10)
         column.set_reorderable(True)
         column.set_visible(not hidden)
+        column.connect('button-press-event',
+                       self.on_treeview_header_right_clicked)
 
         # Check for loaded state and apply
         if self.state != None:


--

You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.


Reply via email to