14
14
# Copyright 2009 Jaap Karssenberg <jaap.karssenberg@gmail.com>
19
from zim.plugins.base.imagegenerator import ImageGeneratorPlugin, ImageGeneratorClass
20
20
from zim.fs import File, TmpFile
21
from zim.plugins import PluginClass
22
21
from zim.config import data_file
23
22
from zim.templates import GenericTemplate
24
23
from zim.applications import Application
25
from zim.gui.imagegeneratordialog import ImageGeneratorClass, ImageGeneratorDialog
26
from zim.gui.widgets import populate_popup_add_separator
28
25
# TODO put these commands in preferences
33
<menubar name='menubar'>
34
<menu action='insert_menu'>
35
<placeholder name='plugin_items'>
36
<menuitem action='insert_gnu_r_plot'/>
44
# name, stock id, label, accelerator, tooltip, read only
45
('insert_gnu_r_plot', None, _('GNU _R Plot...'), '', '', False),
46
# T: menu item for insert plot plugin
50
class InsertGNURPlotPlugin(PluginClass):
29
class InsertGNURPlotPlugin(ImageGeneratorPlugin):
53
32
'name': _('Insert GNU R Plot'), # T: plugin name
58
37
'author': 'Lee Braiden',
40
object_type = 'gnu_r_plot'
41
short_label = _('GNU _R Plot')
42
insert_label = _('Insert GNU R Plot')
43
edit_label = _('_Edit GNU R Plot')
62
47
def check_dependencies(klass):
63
48
has_gnur = Application(gnu_r_cmd).tryexec()
64
49
return has_gnur, [('GNU R', has_gnur, True)]
66
def __init__(self, ui):
67
PluginClass.__init__(self, ui)
68
if self.ui.ui_type == 'gtk':
69
self.ui.add_actions(ui_actions, self)
70
self.ui.add_ui(ui_xml, self)
71
self.register_image_generator_plugin('gnu_r_plot')
73
def insert_gnu_r_plot(self):
74
dialog = InsertGNURPlotDialog.unique(self, self.ui)
77
def edit_object(self, buffer, iter, image):
78
dialog = InsertGNURPlotDialog(self.ui, image=image)
81
def do_populate_popup(self, menu, buffer, iter, image):
82
populate_popup_add_separator(menu, prepend=True)
84
item = gtk.MenuItem(_('_Edit GNU R Plot')) # T: menu item in context menu
85
item.connect('activate',
86
lambda o: self.edit_object(buffer, iter, image))
91
class InsertGNURPlotDialog(ImageGeneratorDialog):
93
def __init__(self, ui, image=None):
94
generator = GNURPlotGenerator()
95
ImageGeneratorDialog.__init__(self, ui, _('GNU R Plot'), # T: dialog title
96
generator, image, help=':Plugins:GNU R Plot Editor' )
99
52
class GNURPlotGenerator(ImageGeneratorClass):
101
54
uses_log_file = False
56
object_type = 'gnu_r_plot'
104
57
scriptname = 'gnu_r_plot.r'
105
58
imagename = 'gnu_r_plot.png'
60
def __init__(self, plugin):
61
ImageGeneratorClass.__init__(self, plugin)
108
62
file = data_file('templates/plugins/gnu_r_editor.r')
109
63
assert file, 'BUG: could not find templates/plugins/gnu_r_editor.r'
110
64
self.template = GenericTemplate(file.readlines(), name=file)