File size: 3,529 Bytes
985c397 | 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 | # SPDX-License-Identifier: LGPL-2.1-or-later
# FreeCAD TemplatePyMod module
# (c) 2011 Werner Mayer LGPL
import FreeCAD as App
import FreeCADGui as Gui
from PySide import QtGui,QtCore
class MyLineEdit(QtGui.QLineEdit):
pass
class TaskWatcher:
def __init__(self):
self.commands = ["Part_Box", "Part_Sphere", "Part_Cylinder"]
self.title = "Create primitives"
self.icon = "Part_Sphere"
self.widgets = [MyLineEdit()]
self.widgets[0].setText("Line edit inside task box")
def shouldShow(self):
return App.ActiveDocument is not None
class TaskLineEdit:
def __init__(self):
self.widgets = [MyLineEdit()]
self.widgets[0].setText("Line edit with no task box")
def shouldShow(self):
return True
class TaskWatcherFilter:
def __init__(self):
self.commands = ["Sketcher_NewSketch", "PartDesign_Fillet", "PartDesign_Chamfer"]
self.filter = "SELECT Part::Feature SUBELEMENT Face COUNT 1"
self.title = "Face tools"
self.icon = "Part_Box_Parametric"
class TaskPanel:
def __init__(self):
self.ui = App.getResourceDir() + "Mod/TemplatePyMod/TaskPanel.ui"
def accept(self):
return True
def reject(self):
return True
def clicked(self, index):
pass
def open(self):
pass
def needsFullSpace(self):
return False
def isAllowedAlterSelection(self):
return True
def isAllowedAlterView(self):
return True
def isAllowedAlterDocument(self):
return True
def getStandardButtons(self):
return QtGui.QDialogButtonBox.Ok
def helpRequested(self):
pass
def setupUi(self):
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.pushButton = form.findChild(QtGui.QPushButton, "pushButton")
form.listWidget = form.findChild(QtGui.QListWidget, "listWidget")
self.form = form
#Connect Signals and Slots
QtCore.QObject.connect(form.pushButton, QtCore.SIGNAL("clicked()"), self.addElement)
def getMainWindow(self):
"returns the main window"
# using QtGui.QApplication.activeWindow() isn't very reliable because if another
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
# returned
toplevel = QtGui.QApplication.topLevelWidgets()
for i in toplevel:
if i.metaObject().className() == "Gui::MainWindow":
return i
raise RuntimeError("No main window found")
def addElement(self):
item=QtGui.QInputDialog.getText(self.form, 'Add item', 'Enter:')
if item[1]:
self.form.listWidget.addItem(item[0])
class TaskCalendar:
def __init__(self):
self.form = QtGui.QCalendarWidget()
class TaskManyTaskBoxes:
"illustrates how to add several taskboxes"
def __init__(self):
widget1 = QtGui.QCalendarWidget()
widget2 = QtGui.QWidget()
widget2.setWindowTitle("My Test Box")
text = QtGui.QLabel("testBox",widget2)
text.setObjectName("label")
self.form = [widget1,widget2]
def createTask():
Gui.Control.addTaskWatcher([TaskWatcher(), TaskLineEdit(), TaskWatcherFilter()])
panel = TaskCalendar()
#panel = TaskPanel()
Gui.Control.showDialog(panel)
#panel.setupUi()
return panel
|