~jaap.karssenberg/zim/pyzim-gtk3

« back to all changes in this revision

Viewing changes to zim/plugins/gnu_r_ploteditor.py

  • Committer: Jaap Karssenberg
  • Date: 2014-03-08 11:47:43 UTC
  • mfrom: (668.1.49 pyzim-refactor)
  • Revision ID: jaap.karssenberg@gmail.com-20140308114743-fero6uvy9zirbb4o
Merge branch with refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# Copyright 2009 Jaap Karssenberg <jaap.karssenberg@gmail.com>
15
15
#
16
16
 
17
 
import gtk
18
17
import glob
19
18
 
 
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
27
24
 
28
25
# TODO put these commands in preferences
29
26
gnu_r_cmd = ('R',)
30
27
 
31
 
ui_xml = '''
32
 
<ui>
33
 
        <menubar name='menubar'>
34
 
                <menu action='insert_menu'>
35
 
                        <placeholder name='plugin_items'>
36
 
                                <menuitem action='insert_gnu_r_plot'/>
37
 
                        </placeholder>
38
 
                </menu>
39
 
        </menubar>
40
 
</ui>
41
 
'''
42
 
 
43
 
ui_actions = (
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
47
 
)
48
 
 
49
 
 
50
 
class InsertGNURPlotPlugin(PluginClass):
 
28
 
 
29
class InsertGNURPlotPlugin(ImageGeneratorPlugin):
51
30
 
52
31
        plugin_info = {
53
32
                'name': _('Insert GNU R Plot'), # T: plugin name
58
37
                'author': 'Lee Braiden',
59
38
        }
60
39
 
 
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')
 
44
        syntax = 'r'
 
45
 
61
46
        @classmethod
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)]
65
50
 
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')
72
 
 
73
 
        def insert_gnu_r_plot(self):
74
 
                dialog = InsertGNURPlotDialog.unique(self, self.ui)
75
 
                dialog.run()
76
 
 
77
 
        def edit_object(self, buffer, iter, image):
78
 
                dialog = InsertGNURPlotDialog(self.ui, image=image)
79
 
                dialog.run()
80
 
 
81
 
        def do_populate_popup(self, menu, buffer, iter, image):
82
 
                populate_popup_add_separator(menu, prepend=True)
83
 
 
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))
87
 
                menu.prepend(item)
88
 
 
89
 
 
90
 
 
91
 
class InsertGNURPlotDialog(ImageGeneratorDialog):
92
 
 
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' )
97
 
 
98
51
 
99
52
class GNURPlotGenerator(ImageGeneratorClass):
100
53
 
101
54
        uses_log_file = False
102
55
 
103
 
        type = 'gnu_r_plot'
 
56
        object_type = 'gnu_r_plot'
104
57
        scriptname = 'gnu_r_plot.r'
105
58
        imagename = 'gnu_r_plot.png'
106
59
 
107
 
        def __init__(self):
 
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)