Switched TemplatePyMod scripts to PySide

This commit is contained in:
Yorik van Havre 2014-01-09 18:46:16 -02:00
parent f73a3d6b8a
commit d00327640a
4 changed files with 58 additions and 58 deletions

View File

@ -10,35 +10,35 @@ FreeCADCmd -P <path_to_file> Automation.py
import FreeCAD, Part
def makeSnapshotWithGui():
from PyQt4 import QtGui
import FreeCADGui
def getMainWindow():
toplevel = QtGui.qApp.topLevelWidgets()
for i in toplevel:
if i.metaObject().className() == "Gui::MainWindow":
return i
raise Exception("No main window found")
mw=getMainWindow()
mw.hide()
#mw.showMinimized()
# Create a test geometry and add it to the document
obj=Part.makeCone(10,8,10)
doc = FreeCAD.newDocument()
Part.show(obj)
from PySide import QtGui
import FreeCADGui
def getMainWindow():
toplevel = QtGui.qApp.topLevelWidgets()
for i in toplevel:
if i.metaObject().className() == "Gui::MainWindow":
return i
raise Exception("No main window found")
mw=getMainWindow()
mw.hide()
#mw.showMinimized()
# Create a test geometry and add it to the document
obj=Part.makeCone(10,8,10)
doc = FreeCAD.newDocument()
Part.show(obj)
# switch off animation so that the camera is moved to the final position immediately
view = FreeCADGui.getDocument(doc.Name).activeView()
view.setAnimationEnabled(False)
view.viewAxometric()
view.fitAll()
view.saveImage('crystal.png',800,600,'Current')
FreeCAD.closeDocument(doc.Name)
# close the application
QtGui.qApp.quit()
view.setAnimationEnabled(False)
view.viewAxometric()
view.fitAll()
view.saveImage('crystal.png',800,600,'Current')
FreeCAD.closeDocument(doc.Name)
# close the application
QtGui.qApp.quit()
def makeSnapshotWithoutGui():
from pivy import coin

View File

@ -79,17 +79,17 @@ class TemplatePyMod_Cmd2:
class TemplatePyMod_Cmd3:
"Import PyQt4"
"Import PySide"
def Activated(self):
import PythonQt
from PyQt4 import QtGui
mw=QtGui.qApp.activeWindow()
QtGui.QMessageBox.information(mw,"PyQt","""PyQt was loaded successfully.\n
from PySide import QtGui
mw=FreeCADGui.getMainWindow()
QtGui.QMessageBox.information(mw,"PySide","""PySide was loaded successfully.\n
Load the PyQt sandbox now...""")
FreeCADGui.activateWorkbench("PythonQtWorkbench")
def GetResources(self):
return {'Pixmap' : 'python', 'MenuText': 'Import PyQt4', 'ToolTip': 'Add a workbench for PyQt4 samples'}
return {'Pixmap' : 'python', 'MenuText': 'Import PySide', 'ToolTip': 'Add a workbench for PySide samples'}
class SphereCreator:
def __init__(self):
@ -156,23 +156,23 @@ myRenderArea = None
class TemplatePyMod_Cmd5:
"Example command class"
def Activated(self):
from pivy.sogui import *
from pivy.coin import *
from pivy import sogui
from pivy import coin
global myRenderArea
if myRenderArea == None:
root = SoSeparator()
myCamera = SoPerspectiveCamera()
myMaterial = SoMaterial()
root = coin.SoSeparator()
myCamera = coin.SoPerspectiveCamera()
myMaterial = coin.SoMaterial()
root.addChild(myCamera)
root.addChild(SoDirectionalLight())
root.addChild(coin.SoDirectionalLight())
#myMaterial.diffuseColor = (1.0, 0.0, 0.0) # Red
root.addChild(myMaterial)
root.addChild(SoCone())
root.addChild(coin.SoCone())
# Create a renderArea in which to see our scene graph.
# The render area will appear within the main window.
myRenderArea = SoGuiRenderArea()
myRenderArea = sogui.SoGuiRenderArea(FreeCADGui.getMainWindow())
# Make myCamera see everything.
myCamera.viewAll(root, myRenderArea.getViewportRegion())

View File

@ -1,17 +1,17 @@
"""
Examples for customizing the FreeCAD application with PyQt facilities.
Examples for customizing the FreeCAD application with PySide facilities.
(c) 2007 Werner Mayer LGPL
"""
__author__ = "Werner Mayer <werner.wm.mayer@gmx.de>"
__author__ = "Werner Mayer <werner.wm.mayer@gmx.de>"
from PyQt4 import QtCore,QtGui
from PySide import QtCore,QtGui
import FreeCAD,FreeCADGui, __main__
class MainWindow:
def __init__(self):
self.app = QtGui.qApp
self.mw = self.app.activeWindow()
self.mw = FreeCADGui.getMainWindow()
self.dock = {}
def setWindowTitle(self, name):
@ -40,15 +40,15 @@ class MainWindow:
def aboutQt(self):
QtGui.QMessageBox.aboutQt(self.mw, self.mw.tr("About Qt"))
class PythonQtWorkbench (__main__.Workbench):
"Python Qt workbench object"
Icon = "python"
MenuText = "PyQt sandbox"
ToolTip = "Python Qt workbench"
class PythonQtWorkbench (__main__.Workbench):
"Python Qt workbench object"
Icon = "python"
MenuText = "PySide sandbox"
ToolTip = "Python Qt workbench"
def __init__(self):
self.mw = QtGui.qApp.activeWindow()
self.mw = FreeCADGui.getMainWindow()
self.dock = {}
self.item = []
@ -71,10 +71,10 @@ class PythonQtWorkbench (__main__.Workbench):
QtCore.QObject.connect(self.item[0], QtCore.SIGNAL("triggered()"), self.information)
QtCore.QObject.connect(self.item[1], QtCore.SIGNAL("triggered()"), self.warning)
QtCore.QObject.connect(self.item[2], QtCore.SIGNAL("triggered()"), self.critical)
def Activated(self):
self.__title__ = self.mw.windowTitle()
self.mw.setWindowTitle("FreeCAD -- PythonQt")
self.mw.setWindowTitle("FreeCAD -- PythonQt")
d = QtGui.QDockWidget()
d.setWindowTitle("Calendar")
@ -92,8 +92,8 @@ class PythonQtWorkbench (__main__.Workbench):
self.menu.setTitle("Python Qt")
self.menu.menuAction().setVisible(True)
def Deactivated(self):
def Deactivated(self):
self.mw.setWindowTitle(self.__title__)
self.dock.clear()
FreeCADGui.addWorkbench(PythonQtWorkbench)
self.dock.clear()
FreeCADGui.addWorkbench(PythonQtWorkbench)

View File

@ -3,7 +3,7 @@
import FreeCAD as App
import FreeCADGui as Gui
from PyQt4 import QtGui,QtCore
from PySide import QtGui,QtCore
class MyLineEdit(QtGui.QLineEdit):
pass