Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcylc: dot view - maintain user selection during update #2221

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 46 additions & 2 deletions lib/cylc/gui/updater_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def __init__(self, cfg, updater, treeview, info_bar, theme, dot_size):
self.task_list = []
self.family_tree = {}
self.expanded_rows = []
self.selected_rows = []

# generate task state icons
dotm = DotMaker(theme, size=dot_size)
Expand Down Expand Up @@ -303,9 +304,47 @@ def _get_expanded_rows(self):
self.expanded_rows.append(self.led_treestore.get_value(
self.led_treestore.get_iter(row), 0))

def _get_selected_rows(self):
"""Make a note of currently selected rows.

Populates self.selected_rows with the value of the first column of all
selected rows.

"""
self.selected_rows = []
_, selected_paths = self.led_treeview.get_selection(
).get_selected_rows()
model = self.led_treeview.get_model()
for path in selected_paths:
self.selected_rows.append(model.get_value(model.get_iter(path), 0))

@staticmethod
def _reselect_row(model, _, iter_, (selection, selected_rows,)):
"""Select rows if they are referenced by selected_rows.

If the value of the first column of a row matches a value in
`selected_rows` then `selection` will be updated to include this row.

Warning: This method has not been tested with multiple selection.

"""
if model.get_value(iter_, 0) in selected_rows:
selection.select_iter(iter_)

def _set_selected_rows(self):
"""Re-Selects previously selected rows where possible.

Uses self.selected_rows to determine which rows to select.

"""
selection = self.led_treeview.get_selection()
selection.unselect_all()
model = self.led_treeview.get_model()
model.foreach(self._reselect_row, (selection, self.selected_rows,))

def ledview_widgets(self):
# Make note of expanded rows.
self._get_expanded_rows()
self._get_expanded_rows() # Make a note of expanded rows.
self._get_selected_rows() # Make a note of selected rows.

if not self.should_transpose_view:
types = [str] + [gtk.gdk.Pixbuf] * len(self.point_strings)
Expand Down Expand Up @@ -460,6 +499,11 @@ def update_gui(self):
self._update_gui_transpose(tasks_by_point_string, state_summary)

self.led_treeview.columns_autosize()

if self.is_transposed == self.should_transpose_view:
# Only select rows if we have not changed view mode.
self._set_selected_rows()

return False

def _update_gui_transpose(self, tasks_by_point_string, state_summary):
Expand Down