text
stringlengths
0
828
if shape is None: return
state = event.get_state()
if event.button == 1:
# Start a new route.
self._route = Route(self.device)
self._route.append(shape)
self.last_pressed = shape
if not (state & gtk.gdk.MOD1_MASK):
# `<Alt>` key is not held down.
self.emit('route-electrode-added', shape)"
4319,"def on_widget__button_release_event(self, widget, event):
'''
Called when any mouse button is released.
.. versionchanged:: 0.11.3
Always reset pending route, regardless of whether a route was
completed. This includes a) removing temporary routes from routes
table, and b) resetting the state of the current route electrode
queue. This fixes
ERROR: type should be string, got " https://github.com/sci-bots/microdrop/issues/256."
'''
event = event.copy()
if self.mode == 'register_video' and (event.button == 1 and
self.start_event is not None):
self.emit('point-pair-selected', {'start_event': self.start_event,
'end_event': event.copy()})
self.start_event = None
return
elif self.mode == 'control':
# XXX Negative `route_i` corresponds to temporary route being
# drawn. Since release of mouse button terminates route drawing,
# clear any rows corresponding to negative `route_i` values from
# the routes table.
self.df_routes = self.df_routes.loc[self.df_routes.route_i >=
0].copy()
shape = self.canvas.find_shape(event.x, event.y)
if shape is not None:
electrode_data = {'electrode_id': shape, 'event': event.copy()}
if event.button == 1:
if gtk.gdk.BUTTON1_MASK == event.get_state():
if self._route.append(shape):
self.emit('route-electrode-added', shape)
if len(self._route.electrode_ids) == 1:
# Single electrode, so select electrode.
self.emit('electrode-selected', electrode_data)
else:
# Multiple electrodes, so select route.
route = self._route
self.emit('route-selected', route)
elif (event.get_state() == (gtk.gdk.MOD1_MASK |
gtk.gdk.BUTTON1_MASK) and
self.last_pressed != shape):
# `<Alt>` key was held down.
self.emit('electrode-pair-selected',
{'source_id': self.last_pressed,
'target_id': shape, 'event': event.copy()})
self.last_pressed = None
elif event.button == 3:
# Create right-click pop-up menu.
menu = self.create_context_menu(event, shape)
# Display menu popup
menu.popup(None, None, None, event.button, event.time)
# Clear route.
self._route = None"
4320,"def create_context_menu(self, event, shape):
'''
Parameters
----------
event : gtk.gdk.Event
GTK mouse click event.
shape : str
Electrode shape identifier (e.g., `""electrode028""`).
Returns
-------
gtk.Menu
Context menu.
.. versionchanged:: 0.13
- Deprecate hard-coded commands (e.g., clear electrodes, clear
routes).
- Add anonymous global commands section at head of menu (i.e.,
commands not specific to an electrode or route).
- Add ""Electrode"" and ""Route(s)"" sub-menus.
'''
routes = self.df_routes.loc[self.df_routes.electrode_i == shape,
'route_i'].astype(int).unique().tolist()
def _connect_callback(menu_item, command_signal, group, command, data):
callback_called = threading.Event()
def _callback(signal, widget, *args):
if callback_called.is_set():
return
callback_called.set()