FreeCAD

Форк
0
/
TaskPanel.py 
114 строк · 3.4 Кб
1
# FreeCAD TemplatePyMod module  
2
# (c) 2011 Werner Mayer LGPL
3

4
import FreeCAD as App
5
import FreeCADGui as Gui
6
from PySide import QtGui,QtCore
7

8
class MyLineEdit(QtGui.QLineEdit):
9
    pass
10

11
class TaskWatcher:
12
    def __init__(self):
13
        self.commands = ["Part_Box", "Part_Sphere", "Part_Cylinder"]
14
        self.title = "Create primitives"
15
        self.icon = "Part_Sphere"
16
        self.widgets = [MyLineEdit()]
17
        self.widgets[0].setText("Line edit inside task box")
18
    def shouldShow(self):
19
        return App.ActiveDocument is not None
20

21
class TaskLineEdit:
22
    def __init__(self):
23
        self.widgets = [MyLineEdit()]
24
        self.widgets[0].setText("Line edit with no task box")
25
    def shouldShow(self):
26
        return True
27

28
class TaskWatcherFilter:
29
    def __init__(self):
30
        self.commands = ["Sketcher_NewSketch", "PartDesign_Fillet", "PartDesign_Chamfer"]
31
        self.filter = "SELECT Part::Feature SUBELEMENT Face COUNT 1"
32
        self.title = "Face tools"
33
        self.icon = "Part_Box"
34

35
class TaskPanel:
36
    def __init__(self):
37
        self.ui = App.getResourceDir() + "Mod/TemplatePyMod/TaskPanel.ui"
38

39
    def accept(self):
40
        return True
41

42
    def reject(self):
43
        return True
44

45
    def clicked(self, index):
46
        pass
47

48
    def open(self):
49
        pass
50

51
    def needsFullSpace(self):
52
        return False
53

54
    def isAllowedAlterSelection(self):
55
        return True
56

57
    def isAllowedAlterView(self):
58
        return True
59

60
    def isAllowedAlterDocument(self):
61
        return True
62

63
    def getStandardButtons(self):
64
        return int(QtGui.QDialogButtonBox.Ok)
65

66
    def helpRequested(self):
67
        pass
68

69
    def setupUi(self):
70
        mw = self.getMainWindow()
71
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
72
        form.pushButton = form.findChild(QtGui.QPushButton, "pushButton")
73
        form.listWidget = form.findChild(QtGui.QListWidget, "listWidget")
74
        self.form = form
75
        #Connect Signals and Slots
76
        QtCore.QObject.connect(form.pushButton, QtCore.SIGNAL("clicked()"), self.addElement)
77

78
    def 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
83
        toplevel = QtGui.QApplication.topLevelWidgets()
84
        for i in toplevel:
85
            if i.metaObject().className() == "Gui::MainWindow":
86
                return i
87
        raise RuntimeError("No main window found")
88

89
    def addElement(self):
90
        item=QtGui.QInputDialog.getText(self.form, 'Add item', 'Enter:')
91
        if item[1]:
92
            self.form.listWidget.addItem(item[0])
93

94
class TaskCalendar:
95
    def __init__(self):
96
        self.form = QtGui.QCalendarWidget()
97

98
class TaskManyTaskBoxes:
99
    "illustrates how to add several taskboxes"
100
    def __init__(self):
101
        widget1 = QtGui.QCalendarWidget()
102
        widget2 = QtGui.QWidget()
103
        widget2.setWindowTitle("My Test Box")
104
        text = QtGui.QLabel("testBox",widget2)
105
        text.setObjectName("label")
106
        self.form = [widget1,widget2]
107

108
def createTask():
109
    Gui.Control.addTaskWatcher([TaskWatcher(), TaskLineEdit(), TaskWatcherFilter()])
110
    panel = TaskCalendar()
111
    #panel = TaskPanel()
112
    Gui.Control.showDialog(panel)
113
    #panel.setupUi()
114
    return panel
115

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.