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 1 commit
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
39 changes: 37 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,38 @@ 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))

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

Uses self.selected_rows to determine which rows to select.
Warning: This method has not been tested with multiple selection.

"""
def should_select_row(model, path, iter_, selection):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why this function/method needs to be embedded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic doesn't really make sense within DotUpdater so I encapsulated it (pep227). I could convert it to a lambda if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(The method, however, does refer to self.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this is resolved happy for this to be merged.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthewrmshin Code now moved into a static method.

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

selection = self.led_treeview.get_selection()
model = self.led_treeview.get_model()
model.foreach(should_select_row, selection)

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 +490,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