-
Notifications
You must be signed in to change notification settings - Fork 7
/
InitGui.py
476 lines (404 loc) · 13.8 KB
/
InitGui.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#***************************************************************************
#* *
#* Copyright (c) 2015 microelly <microelly2@freecadbuch.de> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
import FreeCAD
FreeCAD.Console.PrintMessage("Mod pluginloader InitGui.py starting ...\n")
App=FreeCAD
global sys,traceback
import FreeCAD,os,FreeCADGui,time,sys,traceback
import Draft
global PySide
import PySide
from PySide import QtCore, QtGui, QtSvg
from PySide.QtGui import *
from PySide.QtCore import *
from configmanager import ConfigManager
global ConfigManager
global QtGui,QtCore,QtSvg
global myDialog,say,myDialoge
def myDialog(msg):
diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,"Plugin Manager",msg )
diag.exec_()
def myDialoge(msg):
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,"Plugin Manager Error",msg )
diag.exec_()
def say(s):
App.Console.PrintMessage(str(s)+"\n")
global __version__
__version__='0.34 (2015/07/30)'
global sayexc
def sayexc(mess=''):
exc_type, exc_value, exc_traceback = sys.exc_info()
ttt=repr(traceback.format_exception(exc_type, exc_value,exc_traceback))
lls=eval(ttt)
l=len(lls)
l2=lls[(l-3):]
FreeCAD.Console.PrintError(mess + "\n" +"--> ".join(l2))
import re
import os
global pathMacro
def pathMacro(s):
'''
replace shortname by os path
'''
kk=('Linux', 'Arch', '4.0.1-1-ARCH', '#1 SMP PREEMPT Wed Apr 29 12:00:26 CEST 2015', 'x86_64')
import os
try:
kk=os.uname()
except:
kk="NOUNAME"
match = re.search('ARCH', kk[2])
if match:
arch=True
else:
arch=False
for k in ["UserHomePath","UserAppData","AppHomePath"]:
pat=r"(.*)"+k+"/"+"(.*)"
m = re.match(pat, s)
if m:
pre=m.group(1)
post=m.group(2)
inn=FreeCAD.ConfigGet(k)
if arch:
if k == "AppHomePath": #Force sensible Plugin folder
if inn == "/usr/":
inn=inn+"share/freecad/"
if inn == "/usr/bin/":
inn="/usr/share/freecad/"
if k == "UserHomePath":
s2=pre+inn+"/"+post
else:
s2=pre+inn+post
else:
if k == "UserHomePath":
s2=pre+inn+"/"+post
else:
s2=pre+inn+post
s=s2
return s
global runscript
def runscript(fn):
import os
if os.path.exists(fn) and os.path.isfile(fn):
try:
d={};exec(open(fn).read(),d,d)
except:
sayexc("exec error file:" + fn )
else:
sayexc("no access to " + fn)
global runextern
def runextern(fn,arg1="",arg2=""):
import os
if os.path.exists(fn) and os.path.isfile(fn):
try:
#d={};exec(open(fn).read(),d,d)
import subprocess
DETACHED_PROCESS = 0x00000008
windows=False
if windows:
pid = subprocess.Popen([fn,arg1,arg2],creationflags=DETACHED_PROCESS).pid
else:
pid = subprocess.Popen([fn,arg1,arg2]).pid
except:
sayexc("exec error file:" + fn )
else:
sayexc("no access to " + fn)
global MyAction2
class MyAction2():
def __init__(self,method):
self.cmd=method
def run(self):
say("!"+self.cmd+"!")
import re
pat=r"FreeCADGui.activateWorkbench\(\"(.*)\"\)"
m = re.match(pat, self.cmd)
if m:
pre=m.group(1)
if not pre in FreeCADGui.listWorkbenches():
myDialoge("The Workbench \n\n*** " + pre + " ***\n\nis not available \nplease \n\n1. install it and \n2. restart FreeCAD!")
return
try:
exec(self.cmd)
except:
sayexc(self.cmd)
class MyDock(QtGui.QDockWidget):
def __init__(self,master):
QtGui.QDockWidget.__init__(self,master)
self.setStyleSheet("{background-color:white;color:brown;}")
self.labels={}
self.setMinimumSize(200, 185)
master.addDockWidget(QtCore.Qt.RightDockWidgetArea, self)
self.setWindowTitle('Plugin Manager')
self.setObjectName('Pluginloader')
self.centralWidget = QtGui.QWidget(self)
self.centralWidget.setMaximumHeight(800)
self.centralWidget.setStyleSheet("QWidget { background-color: lightblue}\
QPushButton { margin-right:0px;margin-left:0px;margin:0 px;padding:0px;;\
background-color: lightblue;text-align:left;;padding:6px;padding-left:4px;color:brown; }")
self.centralWidget.setObjectName("centralWidget")
self.centralWidget.setGeometry(5,5, 150,60 )
layout = QtGui.QVBoxLayout()
self.centralWidget.setLayout(layout)
self.scroll=QtGui.QScrollArea()
self.liste=QtGui.QWidget()
self.lilayout=QtGui.QVBoxLayout()
self.liste.setLayout(self.lilayout)
mygroupbox = QtGui.QGroupBox()
mygroupbox.setStyleSheet("QWidget { background-color: lightblue;margin:0px;padding:0px;}\
QPushButton { margin-right:0px;margin-left:0px;margin:0 px;padding:0px;;\
background-color: lightblue;text-align:left;;padding:6px;padding-left:4px;color:brown; }")
self.mygroupbox=mygroupbox
myform = QtGui.QFormLayout()
self.myform=myform
self.myform.setSpacing(0)
mygroupbox.setLayout(myform)
scroll = QtGui.QScrollArea()
scroll.setWidget(mygroupbox)
scroll.setWidgetResizable(True)
self.lilayout.addWidget(scroll)
self.pushButton00 = QtGui.QPushButton(QtGui.QIcon('icons:freecad.svg'),"Plugin Manager Version " + __version__)
self.pushButton01 = QtGui.QPushButton(QtGui.QIcon(FreeCAD.ConfigGet('AppHomePath')+'/Mod/mylib/icons/mars.png'),"Plugin Loader" )
self.pushButton01.clicked.connect(self.start)
layout.addWidget(self.pushButton00)
layout.addWidget(self.liste)
layout.addWidget(self.pushButton01)
self.pluginloaderCMD=None # self.myFunction
self.setWidget(self.centralWidget)
#self.setMouseTracking(True)
def start(self):
say("pluginloader started ...")
exec "self.pluginloaderCMD()"
def gentoolbars(self,workbench='init'):
global pathMacro
cf=self.pluginloader.config
say("gentoolbars ...")
if self.pluginloader.config3["toolbars"].has_key(workbench):
for ky in sorted(self.pluginloader.config3["toolbars"][workbench].keys()):
say("ky:"+str(ky))
cma=ConfigManager("__toolbars__/" + workbench +"/" + ky)
funhide=cma.get("_hide_",False)
if funhide:
say("toolbar ignore item " + ky)
continue
try:
mw=FreeCAD.Gui.getMainWindow()
mw.toolbar = mw.addToolBar(workbench +': ' + ky)
mw.toolbar.setWindowTitle("Personal " + workbench +': ' +ky)
mw.toolbar.show()
toolbarBox=mw.toolbar
except Exception:
sayexc("exception add Tool Bar")
for tool in sorted(self.pluginloader.config3["toolbars"][workbench][ky].keys()):
say(tool)
say(ky)
yy=self.pluginloader.config3["toolbars"][workbench][ky][tool]
say(yy)
FreeCAD.yy=yy
FreeCAD.tb=toolbarBox
myAction2=QtGui.QAction(QtGui.QIcon(yy['icon']),tool ,mw)
myAction2.setToolTip(tool)
toolbarBox.addAction(myAction2)
try:
cmd=yy['exec']
except:
cmd="say('"+str(yy)+"')"
yy=MyAction2(pathMacro(cmd))
myAction2.yy=yy
myAction2.triggered.connect(yy.run)
toolbarBox.show()
self.toolbars.append(toolbarBox)
say(ky +" done")
def genlabels(self):
cf=self.pluginloader.config
try:
self.tabs.deleteLater()
except:
pass
if self.pluginloader.config3.has_key("tabs"):
tabs= QtGui.QTabWidget()
kl=sorted(self.pluginloader.config3["tabs"].keys())
# where to place the tabs - still hard coded
mode="north"
if self.pluginloader.config3['base'].has_key('tablocation'):
mode= self.pluginloader.config3['base']['tablocation']
if mode =="west":
tabs.setTabPosition(QtGui.QTabWidget.West)
kl.reverse()
if mode =="east":
tabs.setTabPosition(QtGui.QTabWidget.East)
kl.reverse()
for ky in kl:
import re
cmt=ConfigManager("__tabs__/" + ky)
hide=cmt.get("_hide_",False)
if hide:
say("ignore tab " + ky)
continue
tab1= QtGui.QWidget()
pat=r"[0123456789]+ +(.*)"
m = re.match(pat, ky)
if m:
kyk=m.group(1)
else:
kyk=ky
tabs.addTab(tab1,kyk)
vBoxlayout = QtGui.QVBoxLayout()
vBoxlayout.setAlignment(QtCore.Qt.AlignTop)
head=QtGui.QLabel(kyk.upper())
vBoxlayout.addWidget(head)
head.setStyleSheet("QWidget { font: bold 18px;color:brown;}")
if self.pluginloader.config3['tabs'][ky].has_key("info"):
info=QtGui.QLabel(self.pluginloader.config3['tabs'][ky]["info"])
vBoxlayout.addWidget(info)
for fun in sorted(self.pluginloader.config3["tabs"][ky].keys()):
cma=ConfigManager("__tabs__/" + ky +"/" + fun)
funhide=cma.get("_hide_",False)
if funhide:
say("ignore item " + fun)
continue
ff=self.pluginloader.config3["tabs"][ky][fun]
if fun == 'info':
continue
import re
pat=r"[0123456789]+[\.]? +(.*)"
m = re.match(pat, fun)
if m:
funk=m.group(1)
else:
funk=fun
if ff.has_key('icon'):
pushButton1 = QtGui.QPushButton(QtGui.QIcon(ff['icon']),funk)
else:
pushButton1 = QtGui.QPushButton(QtGui.QIcon(FreeCAD.ConfigGet('AppHomePath')+'/Mod/plugins/icons/sun.png'),funk)
if ff.has_key('info'):
pushButton1.setToolTip(ff['info'])
try:
cmd=ff['exec']
except:
cmd="say('"+str(ff)+"')"
yy=MyAction2(cmd)
yy=MyAction2(pathMacro(cmd))
pushButton1.yy=yy
pushButton1.clicked.connect(yy.run)
hWid= QtGui.QWidget()
hBoxlayout = QtGui.QHBoxLayout()
hBoxlayout.setContentsMargins(0, 0, 0, 0)
hWid.setLayout(hBoxlayout)
pushButt_1 = QtGui.QPushButton(funk)
hBoxlayout.addWidget(pushButton1)
if ff.has_key('man'):
pushButt_2 = QtGui.QPushButton(QtGui.QIcon(FreeCAD.ConfigGet('AppHomePath')+'/Mod/plugins/icons/help.png'),'')
pushButt_2.setToolTip('See WebSite Documentation')
cmdh='import WebGui; WebGui.openBrowser( "' +ff['man'] + '")'
yh=MyAction2(cmdh)
pushButt_2.yh=yh
pushButt_2.clicked.connect(yh.run)
hBoxlayout.addWidget(pushButt_2)
pushButton1.setFixedWidth(250)
else:
pushButton1.setFixedWidth(290)
hBoxlayout.setAlignment(QtCore.Qt.AlignLeft)
vBoxlayout.addWidget(hWid)
vBoxlayout.setSpacing(0)
tab1.setLayout(vBoxlayout)
self.myform.addWidget(tabs)
# aktiver tab
cm=ConfigManager("PluginManager")
ix=cm.get("PluginTabIndex",0)
tabs.setCurrentIndex(ix)
self.tabs=tabs
def reload(self):
FreeCAD.Console.PrintMessage("PluginManager reload ... "+"\n")
import pluginloader
reload (pluginloader)
t=pluginloader.PluginLoader()
self.pluginloaderCMD=t.start
self.pluginloader=t
t.setParams()
self.genlabels()
FreeCAD.Console.PrintMessage("PluginManager reload done"+"\n")
#------------------------ main --------------------------
global PluginManager
try:
PluginManager.hide()
pass
except:
pass
PluginManager=MyDock(FreeCAD.Gui.getMainWindow())
PluginManager.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
FreeCAD.PluginManager=PluginManager
import pluginloader
t=pluginloader.PluginLoader()
PluginManager.pluginloaderCMD=t.start
PluginManager.pluginloader=t
t.setParams()
PluginManager.show()
PluginManager.toolbar=0
PluginManager.toolbars=[]
if FreeCAD.ParamGet('User parameter:Plugins').GetBool('showdock'):
PluginManager.show()
FreeCAD.Console.PrintMessage("Mod pluginloader InitGui.py done"+"\n")
PluginManager.genlabels()
global re
import re
def runme():
if PluginManager.toolbar >= 0:
try:
t=FreeCADGui.getMainWindow()
wb=FreeCADGui.activeWorkbench()
name="TEST"
try:
name=wb.name()
except:
wbs='a'+ str(wb)
pat=r".*\.(.+) inst.*"
import re
m = re.match(pat, wbs)
if m:
name=m.group(1)
import Part
#FreeCAD.Console.PrintMessage("\n " +name)
#FreeCAD.Console.PrintMessage(" gen ..")
if name <>"NoneWorkbench":
PluginManager.gentoolbars(name)
#FreeCAD.Console.PrintMessage(" .. gened" )
except:
sayexc("except 2")
# PluginManager.gentoolbars("Robot")
PluginManager.toolbar +=1
self=FreeCAD.Gui.getMainWindow()
self.show()
t=FreeCADGui.getMainWindow()
t.workbenchActivated.connect(runme)
#import eventfilter
#try:
# FreeCAD.EventServer.speakWord.emit("hallo Eventserver ...")
#except:
# pass
if FreeCAD.ParamGet('User parameter:Plugins').GetBool('autoStartEventFilter'):
try:
import keyfilter
say("start keyfilter ... ")
reload(keyfilter)
keyfilter.start()
except:
pass
sayexc("autostart keyfilter module")