@@ -145,7 +145,6 @@ def _qt_initialize_plot(self):
145145 self .graphicsview .setCentralItem (self .plot )
146146 self .plot .hideButtons ()
147147 self .plot .showAxis ('left' , False )
148-
149148 self .viewBox .doubleclicked .connect (self ._qt_scatter_item_clicked )
150149
151150 self .viewBox .gain_zoom .connect (self .apply_gain_zoom )
@@ -240,11 +239,14 @@ def _qt_seek_with_selected_spike(self):
240239 self .notify_time_info_updated ()
241240 self .refresh ()
242241
243- def _qt_on_use_times_updated (self ):
244- # Update time seeker
245- t_start , t_stop = self .controller .get_t_start_t_stop ()
246- self .timeseeker .set_start_stop (t_start , t_stop )
247-
242+ def _qt_scatter_item_clicked (self , x , y ):
243+ ind_spike_nearest = find_nearest_spike (self .controller , x , segment_index = self .controller .get_time ()[1 ])
244+ if ind_spike_nearest is not None :
245+ self .controller .set_indices_spike_selected ([ind_spike_nearest ])
246+
247+ self .notify_spike_selection_changed ()
248+ self ._qt_seek_with_selected_spike ()
249+
248250 ## panel ##
249251 def _panel_create_toolbar (self ):
250252 import panel as pn
@@ -346,16 +348,6 @@ def _panel_seek_with_selected_spike(self):
346348 self .refresh ()
347349 self .notify_time_info_updated ()
348350
349- def _panel_on_use_times_updated (self ):
350- # Update time seeker
351- t_start , t_stop = self .controller .get_t_start_t_stop ()
352- self .time_slider .start = t_start
353- self .time_slider .end = t_stop
354-
355- # Optionally clamp the current value if out of range
356- self .time_slider .value = max (t_start , min (self .time_slider .value , t_stop ))
357- self .refresh ()
358-
359351 # TODO: pan behavior like Qt?
360352 # def _panel_on_pan_start(self, event):
361353 # self.drag_state["x_start"] = event.x
@@ -476,25 +468,6 @@ def _qt_on_settings_changed(self):
476468 def _qt_on_spike_selection_changed (self ):
477469 MixinViewTrace ._qt_seek_with_selected_spike (self )
478470
479- def _qt_scatter_item_clicked (self , x , y ):
480- # TODO sam : make it faster without boolean mask
481- ind_click = int (x * self .controller .sampling_frequency )
482- in_seg , = np .nonzero (self .controller .spikes ['segment_index' ] == self .controller .get_time ()[1 ])
483- nearest = np .argmin (np .abs (self .controller .spikes [in_seg ]['sample_index' ] - ind_click ))
484-
485- ind_spike_nearest = in_seg [nearest ]
486- sample_index = self .controller .spikes [ind_spike_nearest ]['sample_index' ]
487-
488- if np .abs (ind_click - sample_index ) > (self .controller .sampling_frequency // 30 ):
489- return
490-
491- #~ self.controller.spikes['selected'][:] = False
492- #~ self.controller.spikes['selected'][ind_spike_nearest] = True
493- self .controller .set_indices_spike_selected ([ind_spike_nearest ])
494-
495- self .notify_spike_selection_changed ()
496- self .refresh ()
497-
498471 def _qt_refresh (self ):
499472 t , _ = self .controller .get_time ()
500473 self ._qt_seek (t )
@@ -567,10 +540,11 @@ def _qt_on_time_info_updated(self):
567540 # we need refresh in QT because changing tab/docking/undocking doesn't trigger a refresh
568541 self .refresh ()
569542
570- # def _qt_on_use_times_updated(self):
571- # # Update time seeker
572- # t_start, t_stop = self.controller.get_t_start_t_stop()
573- # self.timeseeker.set_start_stop(t_start, t_stop)
543+ def _qt_on_use_times_updated (self ):
544+ # Update time seeker
545+ t_start , t_stop = self .controller .get_t_start_t_stop ()
546+ self .timeseeker .set_start_stop (t_start , t_stop )
547+ self .timeseeker .seek (self .controller .get_time ()[0 ])
574548
575549 ## panel ##
576550 def _panel_make_layout (self ):
@@ -679,7 +653,8 @@ def _panel_refresh(self):
679653
680654 # TODO: if from a different unit, change unit visibility
681655 def _panel_on_tap (self , event ):
682- ind_spike_nearest = find_nearest_spike (self .controller , event .x , self .controller .get_time ()[1 ])
656+ time = event .x
657+ ind_spike_nearest = find_nearest_spike (self .controller , time , self .controller .get_time ()[1 ])
683658 if ind_spike_nearest is not None :
684659 self .controller .set_indices_spike_selected ([ind_spike_nearest ])
685660 self ._panel_seek_with_selected_spike ()
@@ -693,8 +668,7 @@ def _panel_gain_zoom(self, event):
693668 factor_ratio = 1.3 if event .delta > 0 else 1 / 1.3
694669 else :
695670 factor_ratio = 1.0
696- factor = 1.3 if event .delta > 0 else 1 / 1.3
697- self .apply_gain_zoom (factor )
671+ self .apply_gain_zoom (factor_ratio )
698672
699673 def _panel_auto_scale (self , event ):
700674 self .auto_scale ()
@@ -709,14 +683,23 @@ def _panel_on_time_info_updated(self):
709683 self ._block_auto_refresh = False
710684 # we don't need a refresh in panel because changing tab triggers a refresh
711685
686+ def _panel_on_use_times_updated (self ):
687+ # Update time seeker
688+ t_start , t_stop = self .controller .get_t_start_t_stop ()
689+ self .time_slider .start = t_start
690+ self .time_slider .end = t_stop
691+
692+ # Optionally clamp the current value if out of range
693+ self .time_slider .value = self .controller .get_time ()[0 ]
694+ self .refresh ()
695+
712696
713697
714- # TODO sam refactor Qt and this
715698def find_nearest_spike (controller , x , segment_index , max_distance_samples = None ):
716699 if max_distance_samples is None :
717700 max_distance_samples = controller .sampling_frequency // 30
718701
719- ind_click = int ( x * controller .sampling_frequency )
702+ ind_click = controller .time_to_sample_index ( x )
720703 (in_seg ,) = np .nonzero (controller .spikes ["segment_index" ] == segment_index )
721704
722705 if len (in_seg ) == 0 :
0 commit comments