PythonQt.py
Go to the documentation of this file.00001 """
00002 Examples for customizing the FreeCAD application with PyQt facilities.
00003
00004 ***************************************************************************
00005 * Copyright (c) 2007 Werner Mayer <werner.wm.mayer@gmx.de> *
00006 * *
00007 * This file is part of the FreeCAD CAx development system. *
00008 * *
00009 * This program is free software; you can redistribute it and/or modify *
00010 * it under the terms of the GNU General Public License (GPL) *
00011 * as published by the Free Software Foundation; either version 2 of *
00012 * the License, or (at your option) any later version. *
00013 * for detail see the LICENCE text file. *
00014 * *
00015 * FreeCAD is distributed in the hope that it will be useful, *
00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
00018 * GNU Library General Public License for more details. *
00019 * *
00020 * You should have received a copy of the GNU Library General Public *
00021 * License along with FreeCAD; if not, write to the Free Software *
00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
00023 * USA *
00024 * *
00025 ***************************************************************************
00026 """
00027
00028 __author__ = "Werner Mayer <werner.wm.mayer@gmx.de>"
00029
00030 from PyQt4 import QtCore,QtGui
00031 import FreeCAD,FreeCADGui, __main__
00032
00033 class MainWindow:
00034 def __init__(self):
00035 self.app = QtGui.qApp
00036 self.mw = self.app.activeWindow()
00037 self.dock = {}
00038
00039 def setWindowTitle(self, name):
00040 self.mw.setWindowTitle(name)
00041
00042 def addCalendar(self):
00043 d = QtGui.QDockWidget()
00044 d.setWindowTitle("Calendar")
00045 c = QtGui.QCalendarWidget()
00046 d.setWidget(c)
00047 self.mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,d)
00048 self.dock[d] = c
00049
00050 def information(self, title, text):
00051 QtGui.QMessageBox.information(self.mw, title, text)
00052
00053 def warning(self, title, text):
00054 QtGui.QMessageBox.warning(self.mw, title, text)
00055
00056 def critical(self, title, text):
00057 QtGui.QMessageBox.critical(self.mw, title, text)
00058
00059 def question(self, title, text):
00060 QtGui.QMessageBox.question(self.mw, title, text)
00061
00062 def aboutQt(self):
00063 QtGui.QMessageBox.aboutQt(self.mw, self.mw.tr("About Qt"))
00064
00065
00066 class PythonQtWorkbench (__main__.Workbench):
00067 "Python Qt workbench object"
00068 Icon = "python"
00069 MenuText = "PyQt sandbox"
00070 ToolTip = "Python Qt workbench"
00071
00072 def __init__(self):
00073 self.mw = QtGui.qApp.activeWindow()
00074 self.dock = {}
00075 self.item = []
00076
00077 def information(self):
00078 QtGui.QMessageBox.information(self.mw, "Info", "This is an information")
00079
00080 def warning(self):
00081 QtGui.QMessageBox.warning(self.mw, "Warning", "This is a warning")
00082
00083 def critical(self):
00084 QtGui.QMessageBox.critical(self.mw, "Error", "This is an error")
00085
00086 def Initialize(self):
00087 self.menu = QtGui.QMenu()
00088 self.menu.setTitle("Python Qt")
00089 self.item.append(self.menu.addAction("Test 1"))
00090 self.item.append(self.menu.addAction("Test 2"))
00091 self.item.append(self.menu.addAction("Test 3"))
00092
00093 QtCore.QObject.connect(self.item[0], QtCore.SIGNAL("triggered()"), self.information)
00094 QtCore.QObject.connect(self.item[1], QtCore.SIGNAL("triggered()"), self.warning)
00095 QtCore.QObject.connect(self.item[2], QtCore.SIGNAL("triggered()"), self.critical)
00096
00097 def Activated(self):
00098 self.__title__ = self.mw.windowTitle()
00099 self.mw.setWindowTitle("FreeCAD -- PythonQt")
00100
00101 d = QtGui.QDockWidget()
00102 d.setWindowTitle("Calendar")
00103 c = QtGui.QCalendarWidget()
00104 d.setWidget(c)
00105 self.mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,d)
00106 self.dock[d] = c
00107
00108 bar = self.mw.menuBar()
00109 a=bar.actions()
00110 for i in a:
00111 if i.objectName() == "&Windows":
00112 break
00113 bar.insertMenu(i, self.menu)
00114 self.menu.setTitle("Python Qt")
00115 self.menu.menuAction().setVisible(True)
00116
00117 def Deactivated(self):
00118 self.mw.setWindowTitle(self.__title__)
00119 self.dock.clear()
00120
00121 FreeCADGui.addWorkbench(PythonQtWorkbench)