-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnc_plugin_python_example.py
More file actions
224 lines (134 loc) · 6.05 KB
/
gnc_plugin_python_example.py
File metadata and controls
224 lines (134 loc) · 6.05 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# finally we need to create a new class
# to run plugins in python
import sys
import os
import json
import pdb
import traceback
from gi.repository import GObject
import girepo
#pdb.set_trace()
import ctypes
import gnucash_log
from gnucash_log import ENTER
import girepo
import gi
import gnc_plugin
from gnc_plugin import BaseGncPlugin,BaseGncPluginClass
#from gnc_plugin import GncPluginPythonMixin
from gnc_plugin import GncPluginPython
# define a function equivalent to N_ for internationalization
def N_(msg):
return msg
# define a simple function to convert the 64 bit hash to 32 bit
def hash32 (inhsh):
return (inhsh - (inhsh >> 32)) & (2**32 - 1)
def close_handler (arg):
gnucash_log.dbglog_err("close handler called")
pdb.set_trace()
pass
class GncPluginPythonExample(GncPluginPython, metaclass=girepo.GncPluginSubClassMeta):
#__girmetaclass__ = BaseGncPluginClass
plugin_name = "GncPluginPythonExample"
# ah - this is something I think Ive missed - we can name the GType here
__gtype_name__ = 'GncPluginPythonExample'
# add properties/signals here
#name = GObject.Property(type=int,...)
# I think these are more consistent if they are class variables
# unfortunately cant figure out how to have a method of the class
# in a class variable
# the analysis is that essentially in gnucash plugins are single
# instance classes
def __init__ (self):
print("python gtype obj klass %s address %x"%(str(self.__class__),hash(GObject.type_class_peek(self))))
#pdb.set_trace()
super(GncPluginPythonExample,self).__init__()
#GncPluginPython.__init__(self)
print("python gtype obj klass %s address %x"%(str(self.__class__),hash(GObject.type_class_peek(self))))
#pdb.set_trace()
# following the C code we set the parent GncPlugin class variables
# in the subclass
# dont quite see why these are class variables - this just follows the
# C code currently
GncPluginPythonExample.actions_name = "GncPluginPythonExampleActions"
GncPluginPythonExample.plugin_actions = [ \
("exampleAction", None, N_("Example Description..."), None,
N_("example tooltip"),
self.cmd_test,
),
]
GncPluginPythonExample.plugin_toggle_actions = []
GncPluginPythonExample.plugin_important_actions = []
GncPluginPythonExample.ui_filename = None
GncPluginPythonExample.ui_xml_str = """
<ui>
<menubar>
<menu name="Tools" action="ToolsAction">
<placeholder name="ToolsPlaceholder">
<menuitem name="example" action="exampleAction"/>
</placeholder>
</menu>
</menubar>
</ui>
"""
#pdb.set_trace()
#print("before access class", file=sys.stderr)
#priv = girepo.access_class_data(self)
#print("after access class", file=sys.stderr)
#GncPluginPythonExample.class_init()
self.class_init()
# gobjects have constructor function
#self.constructor(report)
# to follow the C code in python this should be a classmethod
# however this does not appear to work for the codegen wrapped functions
# - looks like you cannot use cls. as the prefix - complains about
# missing argument - which Im assuming is the self object - so Im assuming
# the cls object is not being passed as 1st argument
#@classmethod
#def class_init (cls):
# pass
def class_init (self):
# this is the class init function
# unfortunately Im not seeing anyway to access the private data from python
# first call the parent class_init - this is only way to do this
# if we add the parent class_init call to the parent __init__
# we will call the subclass class_init at that time
#super(GncPluginPythonExample,self).class_init()
# this follows the C code - the GncPlugin class private data is set in the
# subclass class_init function - not by calling the GncPlugin classes own
# class_init function!!
#pdb.set_trace()
# we need to set some parent items - how to do this??
# we probably need to set all of these
#gnc_plugin_class->plugin_name = GNC_PLUGIN_NAME;
print("before super set_plugin_name", file=sys.stderr)
print("junk",self.plugin_name,self.actions_name)
# define special C function in the wrappers to set the class private data
#pdb.set_trace()
#self.set_class_init_data(plugin_name=self.plugin_name, actions_name=self.actions_name)
print("before super set_callbacks", file=sys.stderr)
# and another special C function in the wrappers to set the callbacks
# in the class private data
#self.set_callbacks()
#print("after set_callbacks", file=sys.stderr)
# note that in the C the primary version of these functions are defined in
# gnc-plugin.c - and at the end of their code they call the functions saved
# in the GncPlugin class private data - if they are defined
# in python this gets sort of inverted - we define functions here to call
# the parent GncPluginPython class version of these functions - before doing
# extra work - and the GncPluginPython version of these functions does not
# call functions of the subclass (how could it)
def do_add_to_window (self, window, window_type):
print("called do_add_to_window", file=sys.stderr)
#pdb.set_trace()
super(GncPluginPythonExample,self).add_to_window(window, window_type)
def do_remove_from_window (self, window, window_type):
print("called do_remove_from_window", file=sys.stderr)
pdb.set_trace()
print("called do_remove_from_window", file=sys.stderr)
super(GncPluginPythonExample,self).remove_from_window(window, window_type)
def cmd_test (self, action, data):
print(" entered cmd_test", file=sys.stderr)
pdb.set_trace()
print(" entered cmd_test", file=sys.stderr)
GObject.type_register(GncPluginPythonExample)