@@ -32,6 +32,13 @@ def update_manual_labels(self):
3232 elif self .backend == 'panel' :
3333 self ._panel_update_labels ()
3434
35+ def notify_unit_visibility_changed (self ):
36+ selected_units = self .controller .get_visible_unit_ids ()
37+ visible_channel_inds = self .controller .get_common_sparse_channels (selected_units )
38+ self .controller .set_channel_visibility (visible_channel_inds )
39+ self .notify_channel_visibility_changed ()
40+ super ().notify_unit_visibility_changed ()
41+
3542 ## Qt ##
3643 def _qt_make_layout (self ):
3744
@@ -326,8 +333,11 @@ def _qt_on_item_changed(self, item):
326333 is_visible = item .checkState () == QT .Qt .Checked
327334 # visibility checkbox
328335 unit_id = item .unit_id
336+ current_visible_units = self .controller .get_visible_unit_ids ()
329337 self .controller .set_unit_visibility (unit_id , is_visible )
330- self .notify_unit_visibility_changed ()
338+ updated_visibile_units = self .controller .get_visible_unit_ids ()
339+ if set (current_visible_units ) != set (updated_visibile_units ):
340+ self .notify_unit_visibility_changed ()
331341
332342
333343 elif col in self .label_columns :
@@ -342,12 +352,12 @@ def _qt_on_item_changed(self, item):
342352
343353 def _qt_on_double_clicked (self , row , col ):
344354 unit_id = self .table .item (row , 1 ).unit_id
355+ current_visible_units = self .controller .get_visible_unit_ids ()
345356 self .controller .set_visible_unit_ids ([unit_id ])
346- # self.refresh()
347-
348-
349- self .notify_unit_visibility_changed ()
350- self ._qt_refresh_visibility_items ()
357+ updated_visibile_units = self .controller .get_visible_unit_ids ()
358+ if set (current_visible_units ) != set (updated_visibile_units ):
359+ self .notify_unit_visibility_changed ()
360+ self ._qt_refresh_visibility_items ()
351361
352362 def _qt_on_open_context_menu (self ):
353363 self .menu .popup (self .qt_widget .cursor ().pos ())
@@ -369,38 +379,45 @@ def _qt_get_selected_unit_ids(self):
369379 def _qt_on_visible_shortcut (self ):
370380 rows = self ._qt_get_selected_rows ()
371381
382+ current_visible_units = self .controller .get_visible_unit_ids ()
372383 self .controller .set_visible_unit_ids (self .get_selected_unit_ids ())
373- # self.refresh()
374- self .notify_unit_visibility_changed ()
375- self ._qt_refresh_visibility_items ()
376-
377- for row in rows :
378- self .table .selectRow (row )
384+ updated_visibile_units = self .controller .get_visible_unit_ids ()
385+ if set (current_visible_units ) != set (updated_visibile_units ):
386+ self .notify_unit_visibility_changed ()
387+ self ._qt_refresh_visibility_items ()
388+
389+ for row in rows :
390+ self .table .selectRow (row )
379391
380392 def _qt_on_only_previous_shortcut (self ):
381393 sel_rows = self ._qt_get_selected_rows ()
382394 if len (sel_rows ) == 0 :
383395 sel_rows = [self .table .rowCount ()]
384396 new_row = max (sel_rows [0 ] - 1 , 0 )
385397 unit_id = self .table .item (new_row , 1 ).unit_id
398+ current_visible_units = self .controller .get_visible_unit_ids ()
386399 self .controller .set_visible_unit_ids ([unit_id ])
387- self .notify_unit_visibility_changed ()
388- self ._qt_refresh_visibility_items ()
389-
390- self .table .clearSelection ()
391- self .table .selectRow (new_row )
400+ updated_visibile_units = self .controller .get_visible_unit_ids ()
401+ if set (current_visible_units ) != set (updated_visibile_units ):
402+ self .notify_unit_visibility_changed ()
403+ self ._qt_refresh_visibility_items ()
404+ self .table .clearSelection ()
405+ self .table .selectRow (new_row )
392406
393407 def _qt_on_only_next_shortcut (self ):
394408 sel_rows = self ._qt_get_selected_rows ()
395409 if len (sel_rows ) == 0 :
396410 sel_rows = [- 1 ]
397411 new_row = min (sel_rows [- 1 ] + 1 , self .table .rowCount () - 1 )
398412 unit_id = self .table .item (new_row , 1 ).unit_id
413+ current_visible_units = self .controller .get_visible_unit_ids ()
399414 self .controller .set_visible_unit_ids ([unit_id ])
400- self .notify_unit_visibility_changed ()
401- self ._qt_refresh_visibility_items ()
402- self .table .clearSelection ()
403- self .table .selectRow (new_row )
415+ updated_visibile_units = self .controller .get_visible_unit_ids ()
416+ if set (current_visible_units ) != set (updated_visibile_units ):
417+ self .notify_unit_visibility_changed ()
418+ self ._qt_refresh_visibility_items ()
419+ self .table .clearSelection ()
420+ self .table .selectRow (new_row )
404421
405422 def _qt_on_delete_shortcut (self ):
406423 sel_rows = self ._qt_get_selected_rows ()
@@ -728,13 +745,16 @@ def _panel_update_labels(self):
728745 def _panel_on_only_selection (self ):
729746 selected_unit = self .table .selection [0 ]
730747 unit_id = self .table .value .index .values [selected_unit ]
748+ current_visible_units = self .controller .get_visible_unit_ids ()
731749 self .controller .set_visible_unit_ids ([unit_id ])
732- self ._panel_refresh_colors ()
733- # update the visible column
734- df = self .table .value
735- df .loc [self .controller .unit_ids , "visible" ] = self .controller .get_units_visibility_mask ()
736- self .table .value = df
737- self .notify_unit_visibility_changed ()
750+ updated_visibile_units = self .controller .get_visible_unit_ids ()
751+ if set (current_visible_units ) != set (updated_visibile_units ):
752+ self ._panel_refresh_colors ()
753+ # update the visible column
754+ df = self .table .value
755+ df .loc [self .controller .unit_ids , "visible" ] = self .controller .get_units_visibility_mask ()
756+ self .table .value = df
757+ self .notify_unit_visibility_changed ()
738758
739759 def _panel_get_selected_unit_ids (self ):
740760 unit_ids = self .table .value .index .values
@@ -785,9 +805,12 @@ def _panel_handle_shortcut(self, event):
785805 if self .controller .curation :
786806 self ._panel_merge_units ()
787807 elif event .data == "visible" :
808+ current_visibile_units = self .controller .get_visible_unit_ids ()
788809 self .controller .set_visible_unit_ids (selected_unit_ids )
789- self .notify_unit_visibility_changed ()
790- self .refresh ()
810+ updated_visibile_units = self .controller .get_visible_unit_ids ()
811+ if set (current_visibile_units ) != set (updated_visibile_units ):
812+ self .notify_unit_visibility_changed ()
813+ self .refresh ()
791814 elif event .data == "clear" :
792815 for unit_id in selected_unit_ids :
793816 self .controller .set_label_to_unit (unit_id , "quality" , None )
0 commit comments