text
stringlengths 1
93.6k
|
|---|
return 800
|
elif weight == 'black':
|
return 900
|
else:
|
raise ValueError('weight ' + weight + ' not valid')
|
class NavigationToolbar2Kivy(NavigationToolbar2):
|
'''This class extends from matplotlib class NavigationToolbar2 and
|
creates an action bar which is added to the main app to allow the
|
following operations to the figures.
|
Home: Resets the plot axes to the initial state.
|
Left: Undo an operation performed.
|
Right: Redo an operation performed.
|
Pan: Allows to drag the plot.
|
Zoom: Allows to define a rectangular area to zoom in.
|
Configure: Loads a pop up for repositioning elements.
|
Save: Loads a Save Dialog to generate an image.
|
'''
|
def __init__(self, canvas, **kwargs):
|
self.actionbar = ActionBar(pos_hint={'top': 1.0})
|
super(NavigationToolbar2Kivy, self).__init__(canvas)
|
self.rubberband_color = (1.0, 0.0, 0.0, 1.0)
|
self.lastrect = None
|
self.save_dialog = Builder.load_string(textwrap.dedent('''\
|
<SaveDialog>:
|
text_input: text_input
|
BoxLayout:
|
size: root.size
|
pos: root.pos
|
orientation: "vertical"
|
FileChooserListView:
|
id: filechooser
|
on_selection: text_input.text = self.selection and\
|
self.selection[0] or ''
|
TextInput:
|
id: text_input
|
size_hint_y: None
|
height: 30
|
multiline: False
|
BoxLayout:
|
size_hint_y: None
|
height: 30
|
Button:
|
text: "Cancel"
|
on_release: root.cancel()
|
Button:
|
text: "Save"
|
on_release: root.save(filechooser.path,\
|
text_input.text)
|
'''))
|
def _init_toolbar(self):
|
'''A Toolbar is created with an ActionBar widget in which buttons are
|
added with a specific behavior given by a callback. The buttons
|
properties are given by matplotlib.
|
'''
|
basedir = os.path.join(rcParams['datapath'], 'images')
|
actionview = ActionView()
|
actionprevious = ActionPrevious(title="Navigation", with_previous=False)
|
actionoverflow = ActionOverflow()
|
actionview.add_widget(actionprevious)
|
actionview.add_widget(actionoverflow)
|
actionview.use_separator = True
|
self.actionbar.add_widget(actionview)
|
id_group = uuid.uuid4()
|
for text, tooltip_text, image_file, callback in self.toolitems:
|
if text is None:
|
actionview.add_widget(ActionSeparator())
|
continue
|
fname = os.path.join(basedir, image_file + '.png')
|
if text in ['Pan', 'Zoom']:
|
action_button = ActionToggleButton(text=text, icon=fname,
|
group=id_group)
|
else:
|
action_button = ActionButton(text=text, icon=fname)
|
action_button.bind(on_press=getattr(self, callback))
|
actionview.add_widget(action_button)
|
def configure_subplots(self, *largs):
|
'''It will be implemented later.'''
|
pass
|
def dismiss_popup(self):
|
self._popup.dismiss()
|
def show_save(self):
|
'''Displays a popup widget to perform a save operation.'''
|
content = SaveDialog(save=self.save, cancel=self.dismiss_popup)
|
self._popup = Popup(title="Save file", content=content,
|
size_hint=(0.9, 0.9))
|
self._popup.open()
|
def save(self, path, filename):
|
self.canvas.export_to_png(os.path.join(path, filename))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.