FreeCAD
114 строк · 3.4 Кб
1# FreeCAD TemplatePyMod module
2# (c) 2011 Werner Mayer LGPL
3
4import FreeCAD as App
5import FreeCADGui as Gui
6from PySide import QtGui,QtCore
7
8class MyLineEdit(QtGui.QLineEdit):
9pass
10
11class TaskWatcher:
12def __init__(self):
13self.commands = ["Part_Box", "Part_Sphere", "Part_Cylinder"]
14self.title = "Create primitives"
15self.icon = "Part_Sphere"
16self.widgets = [MyLineEdit()]
17self.widgets[0].setText("Line edit inside task box")
18def shouldShow(self):
19return App.ActiveDocument is not None
20
21class TaskLineEdit:
22def __init__(self):
23self.widgets = [MyLineEdit()]
24self.widgets[0].setText("Line edit with no task box")
25def shouldShow(self):
26return True
27
28class TaskWatcherFilter:
29def __init__(self):
30self.commands = ["Sketcher_NewSketch", "PartDesign_Fillet", "PartDesign_Chamfer"]
31self.filter = "SELECT Part::Feature SUBELEMENT Face COUNT 1"
32self.title = "Face tools"
33self.icon = "Part_Box"
34
35class TaskPanel:
36def __init__(self):
37self.ui = App.getResourceDir() + "Mod/TemplatePyMod/TaskPanel.ui"
38
39def accept(self):
40return True
41
42def reject(self):
43return True
44
45def clicked(self, index):
46pass
47
48def open(self):
49pass
50
51def needsFullSpace(self):
52return False
53
54def isAllowedAlterSelection(self):
55return True
56
57def isAllowedAlterView(self):
58return True
59
60def isAllowedAlterDocument(self):
61return True
62
63def getStandardButtons(self):
64return int(QtGui.QDialogButtonBox.Ok)
65
66def helpRequested(self):
67pass
68
69def setupUi(self):
70mw = self.getMainWindow()
71form = mw.findChild(QtGui.QWidget, "TaskPanel")
72form.pushButton = form.findChild(QtGui.QPushButton, "pushButton")
73form.listWidget = form.findChild(QtGui.QListWidget, "listWidget")
74self.form = form
75#Connect Signals and Slots
76QtCore.QObject.connect(form.pushButton, QtCore.SIGNAL("clicked()"), self.addElement)
77
78def getMainWindow(self):
79"returns the main window"
80# using QtGui.QApplication.activeWindow() isn't very reliable because if another
81# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
82# returned
83toplevel = QtGui.QApplication.topLevelWidgets()
84for i in toplevel:
85if i.metaObject().className() == "Gui::MainWindow":
86return i
87raise RuntimeError("No main window found")
88
89def addElement(self):
90item=QtGui.QInputDialog.getText(self.form, 'Add item', 'Enter:')
91if item[1]:
92self.form.listWidget.addItem(item[0])
93
94class TaskCalendar:
95def __init__(self):
96self.form = QtGui.QCalendarWidget()
97
98class TaskManyTaskBoxes:
99"illustrates how to add several taskboxes"
100def __init__(self):
101widget1 = QtGui.QCalendarWidget()
102widget2 = QtGui.QWidget()
103widget2.setWindowTitle("My Test Box")
104text = QtGui.QLabel("testBox",widget2)
105text.setObjectName("label")
106self.form = [widget1,widget2]
107
108def createTask():
109Gui.Control.addTaskWatcher([TaskWatcher(), TaskLineEdit(), TaskWatcherFilter()])
110panel = TaskCalendar()
111#panel = TaskPanel()
112Gui.Control.showDialog(panel)
113#panel.setupUi()
114return panel
115