text
stringlengths
1
93.6k
if linewidth:
rgb = self.get_rgb()
attrib['line'] = str(rgb)
if not forced_alpha and rgb[3] != 1.0:
attrib['line-opacity'] = str(rgb[3])
if linewidth != 1.0:
attrib['line-width'] = str(linewidth)
if self.get_joinstyle() != 'round':
attrib['line-linejoin'] = self.get_joinstyle()
if self.get_capstyle() != 'butt':
attrib['line-linecap'] = _capd[self.get_capstyle()]
return attrib
class TimerKivy(TimerBase):
'''
Subclass of :class:`backend_bases.TimerBase` that uses Kivy for timer events.
Attributes:
* interval: The time between timer events in milliseconds. Default
is 1000 ms.
* single_shot: Boolean flag indicating whether this timer should
operate as single shot (run once and then stop). Defaults to False.
* callbacks: Stores list of (func, args) tuples that will be called
upon timer events. This list can be manipulated directly, or the
functions add_callback and remove_callback can be used.
'''
def _timer_start(self):
# Need to stop it, otherwise we potentially leak a timer id that will
# never be stopped.
self._timer_stop()
self._timer = Clock.schedule_interval(self._on_timer, self._interval / 1000.0)
def _timer_stop(self):
if self._timer is not None:
Clock.unschedule(self._timer)
self._timer = None
def _timer_set_interval(self):
# Only stop and restart it if the timer has already been started
if self._timer is not None:
self._timer_stop()
self._timer_start()
def _on_timer(self, dt):
super(TimerKivy, self)._on_timer()
class FigureCanvasKivy(FocusBehavior, Widget, FigureCanvasBase):
'''FigureCanvasKivy class. See module documentation for more information.
'''
def __init__(self, figure, **kwargs):
Window.bind(mouse_pos=self._on_mouse_pos)
self.bind(size=self._on_size_changed)
self.bind(pos=self._on_pos_changed)
self.entered_figure = True
self.figure = figure
super(FigureCanvasKivy, self).__init__(figure=self.figure, **kwargs)
def draw(self):
'''Draw the figure using the KivyRenderer
'''
self.clear_widgets()
self.canvas.clear()
self._renderer = RendererKivy(self)
self.figure.draw(self._renderer)
def on_touch_down(self, touch):
'''Kivy Event to trigger the following matplotlib events:
`motion_notify_event`, `scroll_event`, `button_press_event`,
`enter_notify_event` and `leave_notify_event`
'''
newcoord = self.to_widget(touch.x, touch.y, relative=True)
x = newcoord[0]
y = newcoord[1]
if super(FigureCanvasKivy, self).on_touch_down(touch):
return True
if self.collide_point(*touch.pos):
self.motion_notify_event(x, y, guiEvent=None)
touch.grab(self)
if 'button' in touch.profile and touch.button in ("scrollup", "scrolldown",):
self.scroll_event(x, y, 5, guiEvent=None)
else:
self.button_press_event(x, y, self.get_mouse_button(touch),
dblclick=False, guiEvent=None)
if self.entered_figure:
self.enter_notify_event(guiEvent=None, xy=None)
else:
if not self.entered_figure:
self.leave_notify_event(guiEvent=None)
return False
def on_touch_move(self, touch):
'''Kivy Event to trigger the following matplotlib events:
`motion_notify_event`, `enter_notify_event` and `leave_notify_event`
'''
newcoord = self.to_widget(touch.x, touch.y, relative=True)
x = newcoord[0]