text
stringlengths
0
828
corners['w'] = 1
transform = self.canvas.shapes_to_canvas_transform
canvas_corners = corners.values.dot(transform.T.values).T
points_x = canvas_corners[0]
points_y = canvas_corners[1]
cairo_context = cairo.Context(surface)
cairo_context.move_to(points_x[0], points_y[0])
for x, y in zip(points_x[1:], points_y[1:]):
cairo_context.line_to(x, y)
cairo_context.line_to(points_x[0], points_y[0])
cairo_context.set_source_rgb(1, 0, 0)
cairo_context.stroke()
return surface"
4316,"def render(self):
'''
.. versionchanged:: 0.12
Add ``dynamic_electrode_state_shapes`` layer to show dynamic
electrode actuations.
'''
# Render each layer and update data frame with new content for each
# surface.
surface_names = ('background', 'shapes', 'connections', 'routes',
'channel_labels', 'static_electrode_state_shapes',
'dynamic_electrode_state_shapes', 'registration')
for k in surface_names:
self.set_surface(k, getattr(self, 'render_' + k)())
self.emit('surfaces-reset', self.df_surfaces)
self.cairo_surface = flatten_surfaces(self.df_surfaces)"
4317,"def draw_route(self, df_route, cr, color=None, line_width=None):
'''
Draw a line between electrodes listed in a route.
Arguments
---------
- `df_route`:
* A `pandas.DataFrame` containing a column named `electrode_i`.
* For each row, `electrode_i` corresponds to the integer index of
the corresponding electrode.
- `cr`: Cairo context.
- `color`: Either a RGB or RGBA tuple, with each color channel in the
range [0, 1]. If `color` is `None`, the electrode color is set to
white.
'''
df_route_centers = (self.canvas.df_shape_centers
.ix[df_route.electrode_i][['x_center',
'y_center']])
df_endpoint_marker = (.6 * self.get_endpoint_marker(df_route_centers)
+ df_route_centers.iloc[-1].values)
# Save cairo context to restore after drawing route.
cr.save()
if color is None:
# Colors from [""Show me the numbers""][1].
#
# [1]: http://blog.axc.net/its-the-colors-you-have/
# LiteOrange = rgb(251,178,88);
# MedOrange = rgb(250,164,58);
# LiteGreen = rgb(144,205,151);
# MedGreen = rgb(96,189,104);
color_rgb_255 = np.array([96,189,104, .8 * 255])
color = (color_rgb_255 / 255.).tolist()
if len(color) < 4:
color += [1.] * (4 - len(color))
cr.set_source_rgba(*color)
cr.move_to(*df_route_centers.iloc[0])
for electrode_i, center_i in df_route_centers.iloc[1:].iterrows():
cr.line_to(*center_i)
if line_width is None:
line_width = np.sqrt((df_endpoint_marker.max().values -
df_endpoint_marker.min().values).prod()) * .1
cr.set_line_width(4)
cr.stroke()
cr.move_to(*df_endpoint_marker.iloc[0])
for electrode_i, center_i in df_endpoint_marker.iloc[1:].iterrows():
cr.line_to(*center_i)
cr.close_path()
cr.set_source_rgba(*color)
cr.fill()
# Restore cairo context after drawing route.
cr.restore()"
4318,"def on_widget__button_press_event(self, widget, event):
'''
Called when any mouse button is pressed.
.. versionchanged:: 0.11
Do not trigger `route-electrode-added` event if `ALT` key is
pressed.
'''
if self.mode == 'register_video' and event.button == 1:
self.start_event = event.copy()
return
elif self.mode == 'control':
shape = self.canvas.find_shape(event.x, event.y)