Module: deluge
Branch: 1.3-stable
Commit: 3c3b68e2cc80d8ea33a74fd1778850c8a4902a47

Author: Andrew Resch <[email protected]>
Date:   Sun May 22 15:12:11 2011 -0700

Add ability to set columns as not visible by default by setting the kwarg 
default to False when adding the column

---

 deluge/ui/gtkui/listview.py |   77 ++++++++++++++++++++----------------------
 1 files changed, 37 insertions(+), 40 deletions(-)

diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py
index 4227b57..cc2b8be 100644
--- a/deluge/ui/gtkui/listview.py
+++ b/deluge/ui/gtkui/listview.py
@@ -432,7 +432,7 @@ class ListView:
 
     def add_column(self, header, render, col_types, hidden, position,
             status_field, sortid, text=0, value=0, pixbuf=0, function=None,
-            column_type=None, sort_func=None):
+            column_type=None, sort_func=None, default=True):
         """Adds a column to the ListView"""
         # Add the column types to liststore_columns
         column_indices = []
@@ -510,10 +510,12 @@ class ListView:
                        self.on_treeview_header_right_clicked)
 
         # Check for loaded state and apply
+        column_in_state = False
         if self.state != None:
             for column_state in self.state:
                 if header == column_state.name:
                     # We found a loaded state
+                    column_in_state = True
                     if column_state.width > 0:
                         column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
                         column.set_fixed_width(column_state.width)
@@ -522,7 +524,13 @@ class ListView:
                         
self.model_filter.set_sort_column_id(column_state.sort, column_state.sort_order)
                     column.set_visible(column_state.visible)
                     position = column_state.position
-
+                    break
+            
+        # Set this column to not visible if its not in the state and
+        # its not supposed to be shown by default
+        if not column_in_state and not default and not hidden:
+            column.set_visible(False)
+                
         if position is not None:
             self.treeview.insert_column(column, position)
         else:
@@ -536,75 +544,64 @@ class ListView:
 
         return True
 
-    def add_text_column(self, header, col_type=str, hidden=False,
-                                            position=None,
-                                            status_field=None,
-                                            sortid=0,
-                                            column_type="text",
-                                            sort_func=None):
+    def add_text_column(self, header, col_type=str, hidden=False, 
position=None,
+                        status_field=None, sortid=0, column_type="text",
+                        sort_func=None, default=True):
         """Add a text column to the listview.  Only the header name is 
required.
         """
         render = gtk.CellRendererText()
         self.add_column(header, render, col_type, hidden, position,
-                    status_field, sortid, column_type=column_type, 
sort_func=sort_func)
+                        status_field, sortid, column_type=column_type,
+                        sort_func=sort_func, default=default)
 
         return True
 
     def add_bool_column(self, header, col_type=bool, hidden=False,
-                                            position=None,
-                                            status_field=None,
-                                            sortid=0,
-                                            column_type="bool"):
-
+                        position=None, status_field=None, sortid=0,
+                        column_type="bool", default=True):
         """Add a bool column to the listview"""
         render = gtk.CellRendererToggle()
         self.add_column(header, render, col_type, hidden, position,
-                    status_field, sortid, column_type=column_type)
+                        status_field, sortid, column_type=column_type,
+                        default=default)
 
     def add_func_column(self, header, function, col_types, sortid=0,
-                                hidden=False, position=None, status_field=None,
-                                column_type="func", sort_func=None):
+                        hidden=False, position=None, status_field=None,
+                        column_type="func", sort_func=None, default=True):
         """Add a function column to the listview.  Need a header name, the
         function and the column types."""
 
         render = gtk.CellRendererText()
         self.add_column(header, render, col_types, hidden, position,
-                            status_field, sortid, column_type=column_type,
-                            function=function, sort_func=sort_func)
+                        status_field, sortid, column_type=column_type,
+                        function=function, sort_func=sort_func, 
default=default)
 
         return True
 
-    def add_progress_column(self, header, col_types=[float, str],
-                                            sortid=0,
-                                            hidden=False,
-                                            position=None,
-                                            status_field=None,
-                                            function=None,
-                                            column_type="progress"):
+    def add_progress_column(self, header, col_types=[float, str], sortid=0,
+                            hidden=False, position=None, status_field=None,
+                            function=None, column_type="progress",
+                            default=True):
         """Add a progress column to the listview."""
 
         render = gtk.CellRendererProgress()
         self.add_column(header, render, col_types, hidden, position,
-                            status_field, sortid, function=function,
-                            column_type=column_type,
-                            value=0, text=1)
+                        status_field, sortid, function=function,
+                        column_type=column_type, value=0, text=1,
+                        default=default)
 
         return True
 
-    def add_texticon_column(self, header, col_types=[str, str],
-                                            sortid=1,
-                                            hidden=False,
-                                            position=None,
-                                            status_field=None,
-                                            column_type="texticon",
-                                            function=None):
+    def add_texticon_column(self, header, col_types=[str, str], sortid=1,
+                            hidden=False, position=None, status_field=None,
+                            column_type="texticon", function=None,
+                            default=True):
         """Adds a texticon column to the listview."""
         render1 = gtk.CellRendererPixbuf()
         render2 = gtk.CellRendererText()
 
-        self.add_column(header, (render1, render2), col_types, hidden,
-                            position, status_field, sortid,
-                            column_type=column_type, function=function,
-                            pixbuf=0, text=1)
+        self.add_column(header, (render1, render2), col_types, hidden, 
position,
+                        status_field, sortid, column_type=column_type,
+                        function=function, pixbuf=0, text=1, default=default)
 
         return True

-- 
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