@@ -65,10 +65,13 @@ class ManualClusteringView:
6565 plot_canvas_class = PlotCanvas
6666 ex_status = '' # the GUI can update this to
6767 max_n_clusters = 0 # By default, show all clusters.
68+ defer_hidden_updates = False
6869
6970 def __init__ (self , shortcuts = None , ** kwargs ):
7071 self ._lock = None
7172 self ._closed = False
73+ self ._dock_visible = True
74+ self ._pending_selection = None
7275 self .cluster_ids = ()
7376
7477 # Load default shortcuts, and override with any user shortcuts.
@@ -156,6 +159,14 @@ def on_select_threaded(self, sender, cluster_ids, gui=None, **kwargs):
156159 # than leaving its previous contents on screen.
157160 if self .max_n_clusters and len (cluster_ids ) > self .max_n_clusters :
158161 cluster_ids = cluster_ids [:self .max_n_clusters ]
162+ if self .defer_hidden_updates and not self ._dock_visible :
163+ # Keep the public selection state current while retaining only the
164+ # latest small payload needed to redraw the view when it is shown.
165+ cluster_ids = list (cluster_ids )
166+ self .cluster_ids = cluster_ids
167+ self ._pending_selection = (cluster_ids , dict (kwargs ))
168+ return
169+ self ._pending_selection = None
159170
160171 # The lock is used so that two different background threads do not access the same
161172 # view simultaneously, which can lead to conflicts, errors in the plotting code,
@@ -206,6 +217,7 @@ def finished():
206217 emit ('is_busy' , self , False )
207218 self ._lock = None
208219 self .update_status ()
220+ self ._flush_pending_selection ()
209221
210222 # Start the task on the thread pool, and let the OpenGL canvas know that we're
211223 # starting to record all OpenGL calls instead of executing them immediately.
@@ -223,6 +235,24 @@ def finished():
223235 worker .run ()
224236 self ._lock = None
225237
238+ def _flush_pending_selection (self ):
239+ """Render the latest selection deferred while this view was hidden."""
240+ if (
241+ not self ._pending_selection
242+ or not self ._dock_visible
243+ or self ._lock
244+ or self ._closed
245+ ):
246+ return
247+ cluster_ids , kwargs = self ._pending_selection
248+ self ._pending_selection = None
249+ self .on_select_threaded (
250+ self ,
251+ cluster_ids = cluster_ids ,
252+ gui = self .gui ,
253+ ** kwargs ,
254+ )
255+
226256 def on_cluster (self , up ):
227257 """Callback function when a clustering action occurs. May be overridden.
228258
@@ -251,6 +281,14 @@ def attach(self, gui):
251281
252282 gui .add_view (self , position = self ._default_position )
253283 self .gui = gui
284+ self ._dock_visible = self .dock .isVisible ()
285+
286+ def on_visibility_changed (visible ):
287+ self ._dock_visible = visible
288+ if visible :
289+ self ._flush_pending_selection ()
290+
291+ self .dock .visibilityChanged .connect (on_visibility_changed )
254292
255293 # Set the view state.
256294 self .set_state (gui .state .get_view_state (self ))
@@ -281,6 +319,8 @@ def on_close_view(view_, gui):
281319 return
282320 logger .debug ('Close view %s.' , self .name )
283321 self ._closed = True
322+ self ._pending_selection = None
323+ self .dock .visibilityChanged .disconnect (on_visibility_changed )
284324 gui .remove_menu (self .name )
285325 unconnect (on_select )
286326 gui .state .update_view_state (self , self .state )
0 commit comments