-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.py
More file actions
64 lines (48 loc) · 1.5 KB
/
calc.py
File metadata and controls
64 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2011 Patricio Paez <pp@pp.com.mx>
#
# Plugin to use arithmetic in Zim wiki
from arithmetic import ParserGTK
from zim.plugins import PluginClass
ui_xml = '''
<ui>
<menubar name='menubar'>
<menu action='tools_menu'>
<placeholder name='plugin_items'>
<menuitem action='calculate'/>
</placeholder>
</menu>
</menubar>
</ui>
'''
ui_actions = (
# name, stock id, label, accelerator, tooltip, readonly
('calculate', None, _('_Arithmetic'), 'F5', '', False), # T: menu item
)
class ArithmeticPlugin(PluginClass):
plugin_info = {
'name': _('Arithmetic'), # T: plugin name
'description': _('''\
This plugin allows you to embed arithmetic calculations in zim. You may use variables, %, x or * for multiplication.
This is a contributed plugin. Download and install the arithmetic.py module first, from http://pp.com.mx/python/arithmetic.
'''), # T: plugin description
'author': 'Patricio Paez',
'help': 'Plugins:Arithmetic',
}
#~ plugin_preferences = (
# key, type, label, default
#~ )
@classmethod
def check_dependencies(klass):
import subprocess
return [('arithmetic', 0 == subprocess.call( ['python', '-c', 'import arithmetic'] ) )]
def initialize_ui(self, ui):
if self.ui.ui_type == 'gtk':
self.ui.add_actions(ui_actions, self)
self.ui.add_ui(ui_xml, self)
def calculate(self):
"""Perform arithmetic operations"""
# get the buffer
buf = self.ui.mainwindow.pageview.view.get_buffer()
# parse and return modified text
parser = ParserGTK()
parser.parse( buf )