summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Stadler <mail@renestadler.de>2007-11-07 17:20:02 +0200
committerRené Stadler <mail@renestadler.de>2007-11-07 17:20:02 +0200
commit19d25efb67c6672359a9eacac683bb0510e1a582 (patch)
tree58047c8b584829382166b57dd84e295d98ef4858
parent1eff810f53b4e182e237cb4058595c7c636ad89a (diff)
Split ColumnManager into a reusable base class and a specialized derived class
-rw-r--r--ChangeLog5
-rw-r--r--GstInspector/GUI.py311
2 files changed, 163 insertions, 153 deletions
diff --git a/ChangeLog b/ChangeLog
index 30bd051..d6a1991 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-11-07 Rene Stadler <mail@renestadler.de>
+
+ * GstInspector/GUI.py (ColumnManager, InspectorColumnManager):
+ Separate abstract functionality out into a reusable base class.
+
2007-10-25 Rene Stadler <mail@renestadler.de>
* GstInspector/GUI.py (FilterManager.__init__)
diff --git a/GstInspector/GUI.py b/GstInspector/GUI.py
index c16dcfc..32ebcc8 100644
--- a/GstInspector/GUI.py
+++ b/GstInspector/GUI.py
@@ -2254,13 +2254,10 @@ class RankColumn (TextColumn):
class ColumnManager (Manager):
- """GUI manager that handles the columns of the element list view and the
- menu items that toggle their visibility."""
+ """GUI manager that handles the columns of a list view and the toggle
+ actions that control their visibility."""
- # Order of column classes represents the default column order in the view
- # and matches the order of the check menu items in the ui file.
- column_classes = (NameColumn, LongNameColumn, RankColumn, PluginColumn,
- SourceColumn, PackageColumn,)
+ column_classes = ()
@classmethod
def iter_item_classes (cls):
@@ -2269,23 +2266,22 @@ class ColumnManager (Manager):
def __init__ (self):
- self.logger = logging.getLogger ("ui.columns")
-
self.view = None
- self.columns_changed_id = None
+ self.actions = None
+ self.__columns_changed_id = None
self.columns = []
+ self.column_order = list (self.column_classes)
self.action_group = gtk.ActionGroup ("ColumnActions")
def make_entry (col_class):
- default = (col_class in (NameColumn, LongNameColumn,))
return ("show-%s-column" % (col_class.name,),
None,
col_class.label_header,
None,
None,
None,
- default,)
+ True,)
entries = [make_entry (cls) for cls in self.column_classes]
self.action_group.add_toggle_actions (entries)
@@ -2293,73 +2289,25 @@ class ColumnManager (Manager):
def iter_items (self):
return iter (self.columns)
-
- def attach (self, inspector_window):
-
- view = inspector_window.widgets.main_view
- model = inspector_window.app.element_model
- widgets = inspector_window.widgets
-
- if self.view is not None:
- raise ValueError ("already attached")
-
- self.app = inspector_window.app
- self.actions = inspector_window.actions
- self.view = view
- self.widgets = widgets
- sort_model = view.props.model
- if sort_model:
- self.attach_sort ()
- view.connect ("notify::model", self.handle_view_notify_model)
-
- order = list (self.app.state.column_order)
- if len (order) == len (self.column_classes):
- self.column_order = order
- else:
- self.column_order = list (self.column_classes)
-
- visible = self.app.state.columns_visible
- if not visible:
- # Initial defaults are taken over from the actions.
- visible = []
- for col_class in self.column_classes:
- action = self.get_toggle_action (col_class)
- if action.props.active:
- visible.append (col_class)
+ def attach (self):
for col_class in self.column_classes:
action = self.get_toggle_action (col_class)
- if col_class in visible:
- action.props.active = True
- else:
- action.props.active = False
+ if action.props.active:
+ self.__add_column (col_class ())
action.connect ("toggled",
- self.handle_show_column_action_toggled,
+ self.__handle_show_column_action_toggled,
col_class.name)
- for col_class in self.column_order:
- if col_class in visible:
- self.add_column (col_class ())
+ self.__columns_changed_id = self.view.connect ("columns-changed",
+ self.__handle_view_columns_changed)
- self.columns_changed_id = self.view.connect ("columns-changed",
- self.handle_view_columns_changed)
-
- self.default_sort = (model.COL_FACTORY_NAME, gtk.SORT_ASCENDING,)
-
- state_sort_column = self.app.state.sort_column
- state_sort_order = self.app.state.sort_order
- if state_sort_order == "unsorted":
- self.default_sort = (TREE_SORTABLE_UNSORTED_COLUMN_ID,
- gtk.SORT_ASCENDING,)
- elif state_sort_column:
- sort_id = state_sort_column.id
- if state_sort_order == "ascending":
- self.default_sort = (sort_id, gtk.SORT_ASCENDING,)
- elif state_sort_order == "descending":
- self.default_sort = (sort_id, gtk.SORT_DESCENDING,)
+ def detach (self):
- self.enable_sort ()
+ if self.__columns_changed_id is not None:
+ self.view.disconnect (self.__columns_changed_id)
+ self.__columns_changed_id = None
def attach_sort (self):
@@ -2371,39 +2319,13 @@ class ColumnManager (Manager):
sort_func = col_class.get_sort_func ()
sort_model.set_sort_func (col_class.id, sort_func)
- def detach (self):
-
- self.app.state.column_order = self.column_order
- self.app.state.columns_visible = self.columns
-
- if self.default_sort is None:
- model = self.view.props.model
- sort_id, sort_order = tree_sortable_get_sort_column_id (model)
- else:
- sort_id, sort_order = self.default_sort
-
- if sort_id >= 0:
- self.app.state.sort_column = self.find_item_class (id = sort_id)
- if sort_order == gtk.SORT_ASCENDING:
- self.app.state.sort_order = "ascending"
- else:
- self.app.state.sort_order = "descending"
- else:
- # Most probably TREE_SORTABLE_UNSORTED_COLUMN_ID.
- self.app.state.sort_column = None
- self.app.state.sort_order = "unsorted"
-
- if self.columns_changed_id is not None:
- self.view.disconnect (self.columns_changed_id)
- self.columns_changed_id = None
-
def enable_sort (self):
- model = self.view.props.model
+ sort_model = self.view.props.model
- if model:
+ if sort_model:
self.logger.debug ("activating sort")
- model.set_sort_column_id (*self.default_sort)
+ sort_model.set_sort_column_id (*self.default_sort)
self.default_sort = None
else:
self.logger.debug ("not activating sort (no model set)")
@@ -2412,45 +2334,46 @@ class ColumnManager (Manager):
self.logger.debug ("deactivating sort")
- model = self.view.props.model
+ sort_model = self.view.props.model
- self.default_sort = tree_sortable_get_sort_column_id (model)
+ self.default_sort = tree_sortable_get_sort_column_id (sort_model)
- model.set_sort_column_id (TREE_SORTABLE_UNSORTED_COLUMN_ID,
- gtk.SORT_ASCENDING)
+ sort_model.set_sort_column_id (TREE_SORTABLE_UNSORTED_COLUMN_ID,
+ gtk.SORT_ASCENDING)
- def handle_view_notify_model (self, view, gparam):
+ def get_toggle_action (self, column_class):
- model = view.props.model
- if model:
- self.attach_sort ()
+ action_name = "show-%s-column" % (column_class.name,)
+ return self.action_group.get_action (action_name)
- def handle_view_columns_changed (self, element_view):
+ def get_initial_column_order (self):
- view_columns = element_view.get_columns ()
- new_visible = [self.find_item (view_column = column)
- for column in view_columns]
+ return tuple (self.column_classes)
- # We only care about reordering here.
- if len (new_visible) != len (self.columns):
- return
+ def __add_column (self, column):
- if new_visible != self.columns:
+ name = column.name
+ pos = self.__get_column_insert_position (column)
+ self.columns.insert (pos, column)
+ self.view.insert_column (column.view_column, pos)
- new_order = []
- for column in new_visible:
- col_class = self.find_item_class (name = column.name)
- new_order.append (col_class)
- new_order.extend (self.iter_next_hidden (col_class))
-
- names = (column.name for column in new_visible)
- self.logger.debug ("visible columns reordered: %s",
- ", ".join (names))
+ def __remove_column (self, column):
- self.columns[:] = new_visible
- self.column_order[:] = new_order
+ self.columns.remove (column)
+ self.view.remove_column (column.view_column)
+
+ def __get_column_insert_position (self, column):
+
+ col_class = self.find_item_class (name = column.name)
+ pos = self.column_order.index (col_class)
+ before = self.column_order[:pos]
+ shown_names = [col.name for col in self.columns]
+ for col_class in before:
+ if not col_class.name in shown_names:
+ pos -= 1
+ return pos
- def iter_next_hidden (self, column_class):
+ def __iter_next_hidden (self, column_class):
pos = self.column_order.index (column_class)
rest = self.column_order[pos + 1:]
@@ -2463,7 +2386,7 @@ class ColumnManager (Manager):
else:
break
- def handle_show_column_action_toggled (self, toggle_action, name):
+ def __handle_show_column_action_toggled (self, toggle_action, name):
if toggle_action.props.active:
try:
@@ -2471,7 +2394,7 @@ class ColumnManager (Manager):
column = self.find_item (name = name)
except KeyError:
col_class = self.find_item_class (name = name)
- self.add_column (col_class ())
+ self.__add_column (col_class ())
else:
# Out of sync for some reason.
return
@@ -2482,35 +2405,117 @@ class ColumnManager (Manager):
# Out of sync for some reason.
return
else:
- self.remove_column (column)
+ self.__remove_column (column)
- def get_toggle_action (self, column_class):
+ def __handle_view_columns_changed (self, element_view):
- action_name = "show-%s-column" % (column_class.name,)
- return getattr (self.actions, action_name)
+ view_columns = element_view.get_columns ()
+ new_visible = [self.find_item (view_column = column)
+ for column in view_columns]
- def add_column (self, column):
+ # We only care about reordering here.
+ if len (new_visible) != len (self.columns):
+ return
- name = column.name
- pos = self.get_column_insert_position (column)
- self.columns.insert (pos, column)
- self.view.insert_column (column.view_column, pos)
+ if new_visible != self.columns:
- def remove_column (self, column):
+ new_order = []
+ for column in new_visible:
+ col_class = self.find_item_class (name = column.name)
+ new_order.append (col_class)
+ new_order.extend (self.__iter_next_hidden (col_class))
+
+ names = (column.name for column in new_visible)
+ self.logger.debug ("visible columns reordered: %s",
+ ", ".join (names))
- self.columns.remove (column)
- self.view.remove_column (column.view_column)
+ self.columns[:] = new_visible
+ self.column_order[:] = new_order
- def get_column_insert_position (self, column):
+class InspectorColumnManager (ColumnManager):
- col_class = self.find_item_class (name = column.name)
- pos = self.column_order.index (col_class)
- before = self.column_order[:pos]
- shown_names = [col.name for col in self.columns]
- for col_class in before:
- if not col_class.name in shown_names:
- pos -= 1
- return pos
+ # Order of column classes represents the default column order in the view
+ # and matches the order of the check menu items in the ui file.
+ column_classes = (NameColumn, LongNameColumn, RankColumn, PluginColumn,
+ SourceColumn, PackageColumn,)
+ default_columns = column_classes[:2]
+
+ def __init__ (self):
+
+ ColumnManager.__init__ (self)
+
+ self.logger = logging.getLogger ("ui.columns")
+
+ def attach (self, inspector_window):
+
+ self.view = inspector_window.widgets.main_view
+ model = inspector_window.app.element_model
+
+ self.app = inspector_window.app
+
+ sort_model = self.view.props.model
+ if sort_model:
+ self.attach_sort ()
+ self.view.connect ("notify::model", self.__handle_view_notify_model)
+
+ order = self.app.state.column_order
+ if len (order) == len (self.column_classes):
+ self.column_order[:] = order
+
+ visible = self.app.state.columns_visible
+ if not visible:
+ visible = (NameColumn, LongNameColumn,)
+ for col_class in self.column_classes:
+ action = self.get_toggle_action (col_class)
+ action.props.active = (col_class in visible)
+
+ ColumnManager.attach (self)
+
+ self.default_sort = (model.COL_FACTORY_NAME, gtk.SORT_ASCENDING,)
+
+ state_sort_column = self.app.state.sort_column
+ state_sort_order = self.app.state.sort_order
+ if state_sort_order == "unsorted":
+ self.default_sort = (TREE_SORTABLE_UNSORTED_COLUMN_ID,
+ gtk.SORT_ASCENDING,)
+ elif state_sort_column:
+ sort_id = state_sort_column.id
+ if state_sort_order == "ascending":
+ self.default_sort = (sort_id, gtk.SORT_ASCENDING,)
+ elif state_sort_order == "descending":
+ self.default_sort = (sort_id, gtk.SORT_DESCENDING,)
+
+ self.enable_sort ()
+
+ def detach (self):
+
+ self.app.state.column_order = self.column_order
+ self.app.state.columns_visible = self.columns
+
+ if self.default_sort is None:
+ sort_model = self.view.props.model
+ sort_id, sort_order = tree_sortable_get_sort_column_id (sort_model)
+ else:
+ sort_id, sort_order = self.default_sort
+
+ if sort_id >= 0:
+ self.app.state.sort_column = self.find_item_class (id = sort_id)
+ if sort_order == gtk.SORT_ASCENDING:
+ self.app.state.sort_order = "ascending"
+ else:
+ self.app.state.sort_order = "descending"
+ else:
+ # Most probably TREE_SORTABLE_UNSORTED_COLUMN_ID.
+ self.app.state.sort_column = None
+ self.app.state.sort_order = "unsorted"
+
+ ColumnManager.detach (self)
+
+ def __handle_view_notify_model (self, view, gparam):
+
+ model = view.props.model
+ if model:
+ self.attach_sort ()
class WindowState (object):
@@ -2740,9 +2745,9 @@ class InspectorAppState (AppState):
filter_param = StateString ("filter-param")
sort_order = StateString ("sort-order")
- sort_column = StateItem ("sort-column", ColumnManager)
- column_order = StateItemList ("column-order", ColumnManager)
- columns_visible = StateItemList ("columns-visible", ColumnManager)
+ sort_column = StateItem ("sort-column", InspectorColumnManager)
+ column_order = StateItemList ("column-order", InspectorColumnManager)
+ columns_visible = StateItemList ("columns-visible", InspectorColumnManager)
def __init__ (self):
@@ -2823,7 +2828,7 @@ class InspectorWindow (Data.Consumer):
self.page_manager = PageManager ()
self.filter_manager = FilterManager ()
- self.column_manager = ColumnManager ()
+ self.column_manager = InspectorColumnManager ()
self.window_state = WindowState ()
# These would rather belong in the App object such that one instance of