text stringlengths 0 828 |
|---|
pass" |
4306,"def create_ui(self): |
''' |
.. versionchanged:: 0.9 |
Update device registration in real-time while dragging video |
control point to new position. |
.. versionchanged:: 0.12 |
Add ``dynamic_electrode_state_shapes`` layer to show dynamic |
electrode actuations. |
''' |
super(DmfDeviceCanvas, self).create_ui() |
self.video_sink = VideoSink(*[self.socket_info[k] |
for k in ['transport', 'host', 'port']]) |
# Initialize video sink socket. |
self.video_sink.reset() |
# Required to have key-press and key-release events trigger. |
self.widget.set_flags(gtk.CAN_FOCUS) |
self.widget.add_events(gtk.gdk.KEY_PRESS_MASK | |
gtk.gdk.KEY_RELEASE_MASK) |
# Create initial (empty) cairo surfaces. |
surface_names = ('background', 'shapes', 'connections', 'routes', |
'channel_labels', 'static_electrode_state_shapes', |
'dynamic_electrode_state_shapes', 'registration') |
self.df_surfaces = pd.DataFrame([[self.get_surface(), 1.] |
for i in xrange(len(surface_names))], |
columns=['surface', 'alpha'], |
index=pd.Index(surface_names, |
name='name')) |
def _update_registration(event): |
try: |
start_event = self.start_event.copy() |
self.start_event = event.copy() |
self.emit('point-pair-selected', {'start_event': start_event, |
'end_event': event}) |
except AttributeError: |
# Mouse button was released, causing `self.start_event` to be |
# `None` before event was handled here. |
pass |
# Debounce calls to `_update_registration` function to prevent too many |
# calls being triggered from mouse movement events. |
update_registration = debounce.Debounce(_update_registration, wait=10) |
def _on_mouse_move(area, event): |
# XXX Need to make a copy of the event here since the original |
# event will be deallocated before the debounced |
# `update_registration` function is called. |
event = event.copy() |
if self.mode == 'register_video' and self.start_event is not None: |
update_registration(event.copy()) |
# Connect video registration update event to mouse movement event. |
self.widget.connect(""motion_notify_event"", _on_mouse_move)" |
4307,"def insert_surface(self, position, name, surface, alpha=1.): |
''' |
Insert Cairo surface as new layer. |
Args |
---- |
position (int) : Index position to insert layer at. |
name (str) : Name of layer. |
surface (cairo.Context) : Surface to render. |
alpha (float) : Alpha/transparency level in the range `[0, 1]`. |
''' |
if name in self.df_surfaces.index: |
raise NameError('Surface already exists with `name=""{}""`.' |
.format(name)) |
self.df_surfaces.loc[name] = surface, alpha |
# Reorder layers such that the new surface is placed at the specified |
# layer position (relative to the background surface). |
surfaces_order = self.df_surfaces.index.values.tolist() |
surfaces_order.remove(name) |
base_index = surfaces_order.index('background') + 1 |
if position < 0: |
position = len(surfaces_order) + position |
surfaces_order.insert(base_index + position, name) |
self.reorder_surfaces(surfaces_order)" |
4308,"def append_surface(self, name, surface, alpha=1.): |
''' |
Append Cairo surface as new layer on top of existing layers. |
Args |
---- |
name (str) : Name of layer. |
surface (cairo.ImageSurface) : Surface to render. |
alpha (float) : Alpha/transparency level in the range `[0, 1]`. |
''' |
self.insert_surface(position=self.df_surfaces.index.shape[0], |
name=name, surface=surface, alpha=alpha)" |
4309,"def remove_surface(self, name): |
''' |
Remove layer from rendering stack and flatten remaining layers. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.