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

This commit is contained in:
Andrew Resch 2011-05-22 15:12:11 -07:00
parent b3865d0a7f
commit 2fb874d486

View File

@ -435,7 +435,7 @@ class ListView:
def add_column(self, header, render, col_types, hidden, position, def add_column(self, header, render, col_types, hidden, position,
status_field, sortid, text=0, value=0, pixbuf=0, function=None, status_field, sortid, text=0, value=0, pixbuf=0, function=None,
column_type=None, sort_func=None, tooltip=None): column_type=None, sort_func=None, tooltip=None, default=True):
"""Adds a column to the ListView""" """Adds a column to the ListView"""
# Add the column types to liststore_columns # Add the column types to liststore_columns
column_indices = [] column_indices = []
@ -516,10 +516,12 @@ class ListView:
column.get_widget().set_tooltip_markup(tooltip) column.get_widget().set_tooltip_markup(tooltip)
# Check for loaded state and apply # Check for loaded state and apply
column_in_state = False
if self.state != None: if self.state != None:
for column_state in self.state: for column_state in self.state:
if header == column_state.name: if header == column_state.name:
# We found a loaded state # We found a loaded state
column_in_state = True
if column_state.width > 0: if column_state.width > 0:
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(column_state.width) column.set_fixed_width(column_state.width)
@ -530,6 +532,12 @@ class ListView:
) )
column.set_visible(column_state.visible) column.set_visible(column_state.visible)
position = column_state.position 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: if position is not None:
self.treeview.insert_column(column, position) self.treeview.insert_column(column, position)
@ -546,64 +554,64 @@ class ListView:
def add_text_column(self, header, col_type=str, hidden=False, position=None, def add_text_column(self, header, col_type=str, hidden=False, position=None,
status_field=None, sortid=0, column_type="text", status_field=None, sortid=0, column_type="text",
sort_func=None, tooltip=None): sort_func=None, tooltip=None, default=True):
"""Add a text column to the listview. Only the header name is required. """Add a text column to the listview. Only the header name is required.
""" """
render = gtk.CellRendererText() render = gtk.CellRendererText()
self.add_column(header, render, col_type, hidden, position, self.add_column(header, render, col_type, hidden, position,
status_field, sortid, column_type=column_type, status_field, sortid, column_type=column_type,
sort_func=sort_func, tooltip=tooltip) sort_func=sort_func, tooltip=tooltip, default=default)
return True return True
def add_bool_column(self, header, col_type=bool, hidden=False, def add_bool_column(self, header, col_type=bool, hidden=False,
position=None, status_field=None, sortid=0, position=None, status_field=None, sortid=0,
column_type="bool", tooltip=None): column_type="bool", tooltip=None, default=True):
"""Add a bool column to the listview""" """Add a bool column to the listview"""
render = gtk.CellRendererToggle() render = gtk.CellRendererToggle()
self.add_column(header, render, col_type, hidden, position, self.add_column(header, render, col_type, hidden, position,
status_field, sortid, column_type=column_type, status_field, sortid, column_type=column_type,
tooltip=tooltip) tooltip=tooltip, default=default)
def add_func_column(self, header, function, col_types, sortid=0, def add_func_column(self, header, function, col_types, sortid=0,
hidden=False, position=None, status_field=None, hidden=False, position=None, status_field=None,
column_type="func", sort_func=None, tooltip=None): column_type="func", sort_func=None, tooltip=None, default=True):
"""Add a function column to the listview. Need a header name, the """Add a function column to the listview. Need a header name, the
function and the column types.""" function and the column types."""
render = gtk.CellRendererText() render = gtk.CellRendererText()
self.add_column(header, render, col_types, hidden, position, self.add_column(header, render, col_types, hidden, position,
status_field, sortid, column_type=column_type, status_field, sortid, column_type=column_type,
function=function, sort_func=sort_func, tooltip=tooltip) function=function, sort_func=sort_func, tooltip=tooltip, default=default)
return True return True
def add_progress_column(self, header, col_types=[float, str], sortid=0, def add_progress_column(self, header, col_types=[float, str], sortid=0,
hidden=False, position=None, status_field=None, hidden=False, position=None, status_field=None,
function=None, column_type="progress", function=None, column_type="progress",
tooltip=None): tooltip=None, default=True):
"""Add a progress column to the listview.""" """Add a progress column to the listview."""
render = gtk.CellRendererProgress() render = gtk.CellRendererProgress()
self.add_column(header, render, col_types, hidden, position, self.add_column(header, render, col_types, hidden, position,
status_field, sortid, function=function, status_field, sortid, function=function,
column_type=column_type, value=0, text=1, column_type=column_type, value=0, text=1,
tooltip=tooltip) tooltip=tooltip, default=default)
return True return True
def add_texticon_column(self, header, col_types=[str, str], sortid=1, def add_texticon_column(self, header, col_types=[str, str], sortid=1,
hidden=False, position=None, status_field=None, hidden=False, position=None, status_field=None,
column_type="texticon", function=None, column_type="texticon", function=None,
tooltip=None): tooltip=None, default=True):
"""Adds a texticon column to the listview.""" """Adds a texticon column to the listview."""
render1 = gtk.CellRendererPixbuf() render1 = gtk.CellRendererPixbuf()
render2 = gtk.CellRendererText() render2 = gtk.CellRendererText()
self.add_column(header, (render1, render2), col_types, hidden, position, self.add_column(header, (render1, render2), col_types, hidden, position,
status_field, sortid, column_type=column_type, status_field, sortid, column_type=column_type,
function=function, pixbuf=0, text=1, tooltip=tooltip) function=function, pixbuf=0, text=1, tooltip=tooltip, default=default)
return True return True