-
Notifications
You must be signed in to change notification settings - Fork 9
/
factory.py
193 lines (133 loc) · 5.41 KB
/
factory.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
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
# -*- coding: utf-8 -*-
import sys
import traceback
import uno
import unohelper
debug = False
tb = traceback.print_exc
platform = sys.platform
if debug:
pyPath = 'H:\\Programmierung\\Eclipse_Workspace\\Organon\\source\\py'
if platform == 'linux':
pyPath = '/home/xgr/Arbeitsordner/organon/py'
sys.path.append(pyPath)
from com.sun.star.lang import (XSingleComponentFactory,
XServiceInfo)
def pydevBrk():
# adjust your path
if platform == 'linux':
sys.path.append('/opt/eclipse/plugins/org.python.pydev_3.3.3.201401272249/pysrc')
else:
sys.path.append(r'H:/Programme/eclipse/plugins/org.python.pydev_3.5.0.201405201709/pysrc')
from pydevd import settrace
settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True)
#pydevBrk()
class Factory(unohelper.Base, XSingleComponentFactory):
""" This factory instantiate new window content.
Registration of this class have to be there under
/org.openoffice.Office.UI/WindowContentFactories/Registered/ContentFactories.
See its schema for detail. """
# Implementation name should be match with name of
# the configuration node and FactoryImplementation value.
IMPLE_NAME = "xaver.roemers.organon.factory"
SERVICE_NAMES = IMPLE_NAME,
#pydevBrk()
@classmethod
def get_imple(klass):
#pydevBrk()
return klass, klass.IMPLE_NAME, klass.SERVICE_NAMES
def __init__(self, ctx, *args):
self.ctx = ctx
if debug:print("factory init")
#pydevBrk()
def do(self):
return
def createInstanceWithArgumentsAndContext(self, args, ctx):
#if debug:print('createInstanceWithArgumentsAndContext in Factory')
try:
CWHandler = ContainerWindowHandler(ctx)
self.CWHandler = CWHandler
win,tabs = create_window(ctx,self)
window = self.CWHandler.window2
path_to_extension = __file__.decode("utf-8").split('organon.oxt')[0] + 'organon.oxt'
start_main(pydevBrk,window,ctx,tabs,path_to_extension)
return win
except Exception as e:
print(e)
traceback.print_exc()
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(*Factory.get_imple())
from com.sun.star.beans import NamedValue
RESOURCE_URL = "private:resource/dockingwindow/9809"
EXT_ID = "xaver.roemers.organon"
def create_window(ctx,factory):
#if debug: print('create_window')
dialog1 = "vnd.sun.star.extension://xaver.roemers.organon/factory/Dialog1.xdl"
tabs = ctx.getServiceManager().createInstanceWithContext("com.sun.star.comp.framework.TabWindowService",ctx)
id = tabs.insertTab() # Create new tab, return value is tab id
# Valid properties are:
# Title, ToolTip, PageURL, EventHdl, Image, Disabled.
v1 = NamedValue("PageURL", dialog1)
v2 = NamedValue("Title", "ORGANON")
v3 = NamedValue("EventHdl", factory.CWHandler)
tabs.setTabProps(id, (v1, v2, v3))
tabs.activateTab(id)
tabs.Window.setProperty('Name','ProjektFenster')
window = tabs.Window # real window
return window,tabs
from com.sun.star.awt import XWindowListener,XActionListener,XContainerWindowEventHandler
class ContainerWindowHandler(unohelper.Base, XContainerWindowEventHandler):
def __init__(self, ctx):
#if debug:print('init ContainerWindowHandler')
self.ctx = ctx
self.window2 = None
#pydevBrk()
# XContainerWindowEventHandler
def callHandlerMethod(self, window, obj, name):
#if debug:print('callHandlerMethod')
#pydevBrk()
if name == "external_event":
if obj == "initialize":
self.window2 = window
self._initialize(window)
def getSupportedMethodNames(self):
return "external_event",
def _initialize(self, window):
#if debug:print('_initialize in ContainerWindowHandler')
path_to_current = __file__.decode("utf-8")
pyPath = path_to_current.split('factory.py')[0]
sys.path.append(pyPath)
pyPath_lang = pyPath.replace('py','languages')
sys.path.append(pyPath_lang)
def disposing(self, ev):
pass
def start_main(pd,window,ctx,tabs,path_to_extension):
dialog = window
if debug:
modul = 'menu_bar'
menu_bar = load_reload_modul(modul,pyPath) # gleichbedeutend mit: import menu_bar
else:
import menu_bar
Menu_Bar = menu_bar.Menu_Bar(pd,dialog,ctx,tabs,path_to_extension)
Menu_Bar.erzeuge_Menu()
############################ TOOLS ###############################################################
def load_reload_modul(modul,pyPath):
try:
sys.path.append(pyPath)
exec('import '+ modul)
del(sys.modules[modul])
try:
import shutil
if 'LibreOffice' in sys.executable:
if platform == 'linux':
shutil.rmtree(pyPath+'/__pycache__')
else:
shutil.rmtree(pyPath+'\\__pycache__')
elif 'OpenOffice' in sys.executable:
pass
except:
pass
exec('import '+ modul)
return eval(modul)
except:
traceback.print_exc()