-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_init.py
150 lines (102 loc) · 4.07 KB
/
local_init.py
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
import sys
import os
import pdb
import traceback
import gc
# wrap all this in try except so can silently fail in init.py
# if local_init.py does not exist
try:
#pdb.set_trace()
# uncomment to debug memory issues
#gc.set_debug(gc.DEBUG_LEAK)
# see if calling this prevents the crashes
# well the previous comments are now incorrect - we do need to do this
# and this solves the crash in the callback
# at Py_EnterRecursiveCall (which gets bad thread data for checking recursion limit)
# did I remove this when trying out importing webkit python module?
# (now using gnucash functions that call webkit)
try:
from gi.repository import GObject
GObject.threads_init()
except ImportError:
import gobject
gobject.threads_init()
# see if can turn off g_log handlers installed by pygobject
# note need to do this AFTER importing gobject
# do we need to do this now?
# maybe the threads_init above will fix this as well
# check for introspection
# if so add current path to girepository paths
try:
import gi
gi.require_version('GIRepository', '2.0')
from gi.repository import GIRepository
except ImportError:
pass
else:
#pdb.set_trace()
rep = GIRepository.Repository.get_default()
addrep = os.path.join(sys.path[0],"girepository")
rep.prepend_search_path(addrep)
print("junk")
# new feature - we apparently have no sys.argv
# - fake up a null entry
sys.argv = [ 'gnucash' ]
#print("loading CAPI")
#from pygobjectcapi import PyGObjectCAPI
#Cgobject = PyGObjectCAPI()
#Cgobject.disable_warning_redirections()
#print("done CAPI")
#print("system path")
#print(sys.path)
# so this is weird - if we leave the Gdk import till needed
# we get import error on Gdk.Color
# import here and it works
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
# need to load early as we extend some base gnucash classes
#import gnucash_ext
# probably need to add the following to the python module c
# - otherwise sys.argv is not set at all
# PySys_SetArgv(argc, argv);
#pdb.set_trace()
import gnc_plugin_manager
import gnc_plugin
myplugin = gnc_plugin.GncPluginPythonTest()
# REMOVE COMMENT
#gnc_plugin_manager.plugin_manager.add_plugin(myplugin)
#pdb.set_trace()
import gnc_plugin_python_example
myplugin_example = gnc_plugin_python_example.GncPluginPythonExample()
gnc_plugin_manager.plugin_manager.add_plugin(myplugin_example)
plugins = gnc_plugin_manager.plugin_manager.get_plugins()
#pdb.set_trace()
for plugin in plugins:
print("plugin loaded",plugin.get_name())
import gnc_plugin_python_tools
python_tools = gnc_plugin_python_tools.GncPluginPythonTools()
gnc_plugin_manager.plugin_manager.add_plugin(python_tools)
import gnc_plugin_page
# hmm - we need to instantiate the python report page module here
# - other wise the callbacks wont exist when restoring pages saved on normal shutdown
# however this means we need a re-factor as can now only do widget stuff later
# looks like in gnucash modules are not effectively multiply instantiated
# essentially we need to define the GType now and figure out how to set the callback
# actually do we need the instantiation - maybe the import is enough??
# yes - looks like the import is enough
import gnc_plugin_page_python_report
# initial testing python plugin
if False:
import python_only_plugin
myplugin = python_only_plugin.MyPlugin()
import gnc_plugin_python_reports
python_reports = gnc_plugin_python_reports.GncPluginPythonReports()
gnc_plugin_manager.plugin_manager.add_plugin(python_reports)
#pdb.set_trace()
print("local_init loaded")
except Exception as errexc:
print("Failed to import in local_init!!", file=sys.stderr)
traceback.print_exc()
pdb.set_trace()