Skip to content

Commit

Permalink
Merge pull request #88 from nowsecure/invisible_columns
Browse files Browse the repository at this point in the history
Hide hidden columns from options popup
  • Loading branch information
bellini666 committed Aug 20, 2015
2 parents affecd6 + 047d951 commit 66f6ed7
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions datagrid_gtk3/ui/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ def _get_view_options(self):
def _get_visibility_options(self):
"""Construct the switches based on the actual model columns."""
model = self._controller.model
hidden_columns = model.hidden_columns

for column in model.columns:
if column['name'].startswith('__'):
if column['name'] in hidden_columns:
continue

switch = Gtk.Switch()
Expand Down Expand Up @@ -1253,21 +1255,13 @@ def _setup_columns(self):
self.check_btn_toggle_all = check_btn
self.append_column(col)

# FIXME: We should find a better way for hiding this columns.
# A way to specify the visibility on the columns config would be nice.
dont_display = set([self.model.data_source.SELECTED_COLUMN])
if not self.model.data_source.display_all:
dont_display.add(self.model.data_source.ID_COLUMN)
dont_display.add(self.model.data_source.PARENT_ID_COLUMN)
if not self.model.active_params.get('flat', False):
dont_display.add(self.model.data_source.FLAT_COLUMN)

hidden_columns = self.model.hidden_columns
samples = list(itertools.islice(
(r.data for r in self.model.iter_rows()), self.SAMPLE_SIZE))
for column_index, column in enumerate(self.model.columns):
item = column['name']
display = item in self.model.display_columns
if display and column['name'] not in dont_display:
if display and column['name'] not in hidden_columns:
item_display = column['display']
if column['transform'] in ['boolean', 'image']:
renderer = Gtk.CellRendererPixbuf()
Expand Down Expand Up @@ -1753,6 +1747,17 @@ def __init__(self, data_source, get_media_callback, decode_fallback,
self.rows = None
self.total_recs = None

@property
def hidden_columns(self):
"""A set of columns names that should not be displayed on the view."""
hidden = {self.data_source.SELECTED_COLUMN}
if not self.data_source.display_all:
hidden.add(self.data_source.ID_COLUMN)
hidden.add(self.data_source.PARENT_ID_COLUMN)
if not self.active_params.get('flat', False):
hidden.add(self.data_source.FLAT_COLUMN)
return hidden

def refresh(self):
"""Refresh the model from the data source."""
if 'page' in self.active_params:
Expand Down

0 comments on commit 66f6ed7

Please sign in to comment.