TaskPanel.py
Go to the documentation of this file.00001
00002
00003
00004 import FreeCAD as App
00005 import FreeCADGui as Gui
00006 from PyQt4 import QtGui,QtCore
00007
00008 class MyLineEdit(QtGui.QLineEdit):
00009 pass
00010
00011 class TaskWatcher:
00012 def __init__(self):
00013 self.commands = ["Part_Box", "Part_Sphere", "Part_Cylinder"]
00014 self.title = "Create primitives"
00015 self.icon = "Part_Sphere"
00016 self.widgets = [MyLineEdit()]
00017 self.widgets[0].setText("Line edit inside task box")
00018 def shouldShow(self):
00019 return App.ActiveDocument is not None
00020
00021 class TaskLineEdit:
00022 def __init__(self):
00023 self.widgets = [MyLineEdit()]
00024 self.widgets[0].setText("Line edit with no task box")
00025 def shouldShow(self):
00026 return True
00027
00028 class TaskWatcherFilter:
00029 def __init__(self):
00030 self.commands = ["Sketcher_NewSketch", "PartDesign_Fillet", "PartDesign_Chamfer"]
00031 self.filter = "SELECT Part::Feature SUBELEMENT Face COUNT 1"
00032 self.title = "Face tools"
00033 self.icon = "Part_Box"
00034
00035 class TaskPanel:
00036 def __init__(self):
00037 self.ui = App.getResourceDir() + "Mod/TemplatePyMod/TaskPanel.ui"
00038
00039 def accept(self):
00040 return True
00041
00042 def reject(self):
00043 return True
00044
00045 def clicked(self, index):
00046 pass
00047
00048 def open(self):
00049 pass
00050
00051 def needsFullSpace(self):
00052 return False
00053
00054 def isAllowedAlterSelection(self):
00055 return True
00056
00057 def isAllowedAlterView(self):
00058 return True
00059
00060 def isAllowedAlterDocument(self):
00061 return True
00062
00063 def getStandardButtons(self):
00064 return int(QtGui.QDialogButtonBox.Ok)
00065
00066 def helpRequested(self):
00067 pass
00068
00069 def setupUi(self):
00070 mw = self.getMainWindow()
00071 form = mw.findChild(QtGui.QWidget, "TaskPanel")
00072 form.pushButton = form.findChild(QtGui.QPushButton, "pushButton")
00073 form.listWidget = form.findChild(QtGui.QListWidget, "listWidget")
00074 self.form = form
00075
00076 QtCore.QObject.connect(form.pushButton, QtCore.SIGNAL("clicked()"), self.addElement)
00077
00078 def getMainWindow(self):
00079 "returns the main window"
00080
00081
00082
00083 toplevel = QtGui.qApp.topLevelWidgets()
00084 for i in toplevel:
00085 if i.metaObject().className() == "Gui::MainWindow":
00086 return i
00087 raise Exception("No main window found")
00088
00089 def addElement(self):
00090 item=QtGui.QInputDialog.getText(self.form, 'Add item', 'Enter:')
00091 if item[1]:
00092 self.form.listWidget.addItem(item[0])
00093
00094 class TaskCalendar:
00095 def __init__(self):
00096 self.form = QtGui.QCalendarWidget()
00097
00098
00099 def createTask():
00100 Gui.Control.addTaskWatcher([TaskWatcher(), TaskLineEdit(), TaskWatcherFilter()])
00101 panel = TaskCalendar()
00102
00103 Gui.Control.showDialog(panel)
00104
00105 return panel