Cleaned up example loader

This commit is contained in:
Luke Campagnola 2015-02-28 10:32:34 -05:00
parent caa15d2005
commit 058dd183d3
9 changed files with 246 additions and 303 deletions

View File

@ -118,20 +118,9 @@ class ExampleLoader(QtGui.QMainWindow):
self.ui.loadBtn.clicked.connect(self.loadFile) self.ui.loadBtn.clicked.connect(self.loadFile)
self.ui.exampleTree.currentItemChanged.connect(self.showFile) self.ui.exampleTree.currentItemChanged.connect(self.showFile)
self.ui.exampleTree.itemDoubleClicked.connect(self.loadFile) self.ui.exampleTree.itemDoubleClicked.connect(self.loadFile)
self.ui.pyqtCheck.toggled.connect(self.pyqtToggled)
self.ui.pysideCheck.toggled.connect(self.pysideToggled)
self.ui.codeView.textChanged.connect(self.codeEdited) self.ui.codeView.textChanged.connect(self.codeEdited)
self.codeBtn.clicked.connect(self.runEditedCode) self.codeBtn.clicked.connect(self.runEditedCode)
def pyqtToggled(self, b):
if b:
self.ui.pysideCheck.setChecked(False)
def pysideToggled(self, b):
if b:
self.ui.pyqtCheck.setChecked(False)
def populateTree(self, root, examples): def populateTree(self, root, examples):
for key, val in examples.items(): for key, val in examples.items():
item = QtGui.QTreeWidgetItem([key]) item = QtGui.QTreeWidgetItem([key])
@ -144,7 +133,6 @@ class ExampleLoader(QtGui.QMainWindow):
self.populateTree(item, val) self.populateTree(item, val)
root.addChild(item) root.addChild(item)
def currentFile(self): def currentFile(self):
item = self.ui.exampleTree.currentItem() item = self.ui.exampleTree.currentItem()
if hasattr(item, 'file'): if hasattr(item, 'file'):
@ -155,19 +143,13 @@ class ExampleLoader(QtGui.QMainWindow):
def loadFile(self, edited=False): def loadFile(self, edited=False):
extra = [] extra = []
if self.ui.pyqtCheck.isChecked(): qtLib = str(self.ui.qtLibCombo.currentText())
extra.append('pyqt') gfxSys = str(self.ui.graphicsSystemCombo.currentText())
elif self.ui.pysideCheck.isChecked():
extra.append('pyside')
if self.ui.forceGraphicsCheck.isChecked(): if qtLib != 'default':
extra.append(str(self.ui.forceGraphicsCombo.currentText())) extra.append(qtLib.lower())
elif gfxSys != 'default':
extra.append(gfxSys)
#if sys.platform.startswith('win'):
#os.spawnl(os.P_NOWAIT, sys.executable, '"'+sys.executable+'"', '"' + fn + '"', *extra)
#else:
#os.spawnl(os.P_NOWAIT, sys.executable, sys.executable, fn, *extra)
if edited: if edited:
path = os.path.abspath(os.path.dirname(__file__)) path = os.path.abspath(os.path.dirname(__file__))

View File

@ -6,28 +6,22 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>623</width> <width>846</width>
<height>380</height> <height>552</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QSplitter" name="splitter"> <widget class="QSplitter" name="splitter">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<widget class="QWidget" name=""> <widget class="QWidget" name="">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QGridLayout" name="gridLayout">
<item> <item row="0" column="0" colspan="2">
<widget class="QTreeWidget" name="exampleTree"> <widget class="QTreeWidget" name="exampleTree">
<attribute name="headerVisible"> <attribute name="headerVisible">
<bool>false</bool> <bool>false</bool>
@ -39,55 +33,69 @@
</column> </column>
</widget> </widget>
</item> </item>
<item> <item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout"> <widget class="QComboBox" name="graphicsSystemCombo">
<item> <item>
<widget class="QCheckBox" name="pyqtCheck"> <property name="text">
<property name="text"> <string>default</string>
<string>Force PyQt</string> </property>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="pysideCheck"> <property name="text">
<property name="text"> <string>native</string>
<string>Force PySide</string> </property>
</property>
</widget>
</item> </item>
</layout> <item>
<property name="text">
<string>raster</string>
</property>
</item>
<item>
<property name="text">
<string>opengl</string>
</property>
</item>
</widget>
</item> </item>
<item> <item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QComboBox" name="qtLibCombo">
<item> <item>
<widget class="QCheckBox" name="forceGraphicsCheck"> <property name="text">
<property name="text"> <string>default</string>
<string>Force Graphics System:</string> </property>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="forceGraphicsCombo"> <property name="text">
<item> <string>PyQt4</string>
<property name="text"> </property>
<string>native</string>
</property>
</item>
<item>
<property name="text">
<string>raster</string>
</property>
</item>
<item>
<property name="text">
<string>opengl</string>
</property>
</item>
</widget>
</item> </item>
</layout> <item>
<property name="text">
<string>PySide</string>
</property>
</item>
<item>
<property name="text">
<string>PyQt5</string>
</property>
</item>
</widget>
</item> </item>
<item> <item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Graphics System:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Qt Library:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="loadBtn"> <widget class="QPushButton" name="loadBtn">
<property name="text"> <property name="text">
<string>Run Example</string> <string>Run Example</string>
@ -97,7 +105,7 @@
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name=""> <widget class="QWidget" name="">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QLabel" name="loadedFileLabel"> <widget class="QLabel" name="loadedFileLabel">
<property name="font"> <property name="font">

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file './exampleLoaderTemplate.ui' # Form implementation generated from reading ui file 'exampleLoaderTemplate.ui'
# #
# Created: Mon Feb 25 09:02:09 2013 # Created: Sat Feb 28 10:30:29 2015
# by: PyQt4 UI code generator 4.9.3 # by: PyQt4 UI code generator 4.10.4
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -12,58 +12,64 @@ from PyQt4 import QtCore, QtGui
try: try:
_fromUtf8 = QtCore.QString.fromUtf8 _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError: except AttributeError:
_fromUtf8 = lambda s: s def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object): class Ui_Form(object):
def setupUi(self, Form): def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form")) Form.setObjectName(_fromUtf8("Form"))
Form.resize(623, 380) Form.resize(846, 552)
self.gridLayout = QtGui.QGridLayout(Form) self.gridLayout_2 = QtGui.QGridLayout(Form)
self.gridLayout.setMargin(0) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.gridLayout.setSpacing(0)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.splitter = QtGui.QSplitter(Form) self.splitter = QtGui.QSplitter(Form)
self.splitter.setOrientation(QtCore.Qt.Horizontal) self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName(_fromUtf8("splitter")) self.splitter.setObjectName(_fromUtf8("splitter"))
self.widget = QtGui.QWidget(self.splitter) self.widget = QtGui.QWidget(self.splitter)
self.widget.setObjectName(_fromUtf8("widget")) self.widget.setObjectName(_fromUtf8("widget"))
self.verticalLayout = QtGui.QVBoxLayout(self.widget) self.gridLayout = QtGui.QGridLayout(self.widget)
self.verticalLayout.setMargin(0) self.gridLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.exampleTree = QtGui.QTreeWidget(self.widget) self.exampleTree = QtGui.QTreeWidget(self.widget)
self.exampleTree.setObjectName(_fromUtf8("exampleTree")) self.exampleTree.setObjectName(_fromUtf8("exampleTree"))
self.exampleTree.headerItem().setText(0, _fromUtf8("1")) self.exampleTree.headerItem().setText(0, _fromUtf8("1"))
self.exampleTree.header().setVisible(False) self.exampleTree.header().setVisible(False)
self.verticalLayout.addWidget(self.exampleTree) self.gridLayout.addWidget(self.exampleTree, 0, 0, 1, 2)
self.horizontalLayout = QtGui.QHBoxLayout() self.graphicsSystemCombo = QtGui.QComboBox(self.widget)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.graphicsSystemCombo.setObjectName(_fromUtf8("graphicsSystemCombo"))
self.pyqtCheck = QtGui.QCheckBox(self.widget) self.graphicsSystemCombo.addItem(_fromUtf8(""))
self.pyqtCheck.setObjectName(_fromUtf8("pyqtCheck")) self.graphicsSystemCombo.addItem(_fromUtf8(""))
self.horizontalLayout.addWidget(self.pyqtCheck) self.graphicsSystemCombo.addItem(_fromUtf8(""))
self.pysideCheck = QtGui.QCheckBox(self.widget) self.graphicsSystemCombo.addItem(_fromUtf8(""))
self.pysideCheck.setObjectName(_fromUtf8("pysideCheck")) self.gridLayout.addWidget(self.graphicsSystemCombo, 2, 1, 1, 1)
self.horizontalLayout.addWidget(self.pysideCheck) self.qtLibCombo = QtGui.QComboBox(self.widget)
self.verticalLayout.addLayout(self.horizontalLayout) self.qtLibCombo.setObjectName(_fromUtf8("qtLibCombo"))
self.horizontalLayout_2 = QtGui.QHBoxLayout() self.qtLibCombo.addItem(_fromUtf8(""))
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) self.qtLibCombo.addItem(_fromUtf8(""))
self.forceGraphicsCheck = QtGui.QCheckBox(self.widget) self.qtLibCombo.addItem(_fromUtf8(""))
self.forceGraphicsCheck.setObjectName(_fromUtf8("forceGraphicsCheck")) self.qtLibCombo.addItem(_fromUtf8(""))
self.horizontalLayout_2.addWidget(self.forceGraphicsCheck) self.gridLayout.addWidget(self.qtLibCombo, 1, 1, 1, 1)
self.forceGraphicsCombo = QtGui.QComboBox(self.widget) self.label_2 = QtGui.QLabel(self.widget)
self.forceGraphicsCombo.setObjectName(_fromUtf8("forceGraphicsCombo")) self.label_2.setObjectName(_fromUtf8("label_2"))
self.forceGraphicsCombo.addItem(_fromUtf8("")) self.gridLayout.addWidget(self.label_2, 2, 0, 1, 1)
self.forceGraphicsCombo.addItem(_fromUtf8("")) self.label = QtGui.QLabel(self.widget)
self.forceGraphicsCombo.addItem(_fromUtf8("")) self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout_2.addWidget(self.forceGraphicsCombo) self.gridLayout.addWidget(self.label, 1, 0, 1, 1)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.loadBtn = QtGui.QPushButton(self.widget) self.loadBtn = QtGui.QPushButton(self.widget)
self.loadBtn.setObjectName(_fromUtf8("loadBtn")) self.loadBtn.setObjectName(_fromUtf8("loadBtn"))
self.verticalLayout.addWidget(self.loadBtn) self.gridLayout.addWidget(self.loadBtn, 3, 1, 1, 1)
self.widget1 = QtGui.QWidget(self.splitter) self.widget1 = QtGui.QWidget(self.splitter)
self.widget1.setObjectName(_fromUtf8("widget1")) self.widget1.setObjectName(_fromUtf8("widget1"))
self.verticalLayout_2 = QtGui.QVBoxLayout(self.widget1) self.verticalLayout = QtGui.QVBoxLayout(self.widget1)
self.verticalLayout_2.setMargin(0) self.verticalLayout.setMargin(0)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.loadedFileLabel = QtGui.QLabel(self.widget1) self.loadedFileLabel = QtGui.QLabel(self.widget1)
font = QtGui.QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
@ -72,25 +78,29 @@ class Ui_Form(object):
self.loadedFileLabel.setText(_fromUtf8("")) self.loadedFileLabel.setText(_fromUtf8(""))
self.loadedFileLabel.setAlignment(QtCore.Qt.AlignCenter) self.loadedFileLabel.setAlignment(QtCore.Qt.AlignCenter)
self.loadedFileLabel.setObjectName(_fromUtf8("loadedFileLabel")) self.loadedFileLabel.setObjectName(_fromUtf8("loadedFileLabel"))
self.verticalLayout_2.addWidget(self.loadedFileLabel) self.verticalLayout.addWidget(self.loadedFileLabel)
self.codeView = QtGui.QPlainTextEdit(self.widget1) self.codeView = QtGui.QPlainTextEdit(self.widget1)
font = QtGui.QFont() font = QtGui.QFont()
font.setFamily(_fromUtf8("FreeMono")) font.setFamily(_fromUtf8("FreeMono"))
self.codeView.setFont(font) self.codeView.setFont(font)
self.codeView.setObjectName(_fromUtf8("codeView")) self.codeView.setObjectName(_fromUtf8("codeView"))
self.verticalLayout_2.addWidget(self.codeView) self.verticalLayout.addWidget(self.codeView)
self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1) self.gridLayout_2.addWidget(self.splitter, 0, 0, 1, 1)
self.retranslateUi(Form) self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form): def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8)) Form.setWindowTitle(_translate("Form", "Form", None))
self.pyqtCheck.setText(QtGui.QApplication.translate("Form", "Force PyQt", None, QtGui.QApplication.UnicodeUTF8)) self.graphicsSystemCombo.setItemText(0, _translate("Form", "default", None))
self.pysideCheck.setText(QtGui.QApplication.translate("Form", "Force PySide", None, QtGui.QApplication.UnicodeUTF8)) self.graphicsSystemCombo.setItemText(1, _translate("Form", "native", None))
self.forceGraphicsCheck.setText(QtGui.QApplication.translate("Form", "Force Graphics System:", None, QtGui.QApplication.UnicodeUTF8)) self.graphicsSystemCombo.setItemText(2, _translate("Form", "raster", None))
self.forceGraphicsCombo.setItemText(0, QtGui.QApplication.translate("Form", "native", None, QtGui.QApplication.UnicodeUTF8)) self.graphicsSystemCombo.setItemText(3, _translate("Form", "opengl", None))
self.forceGraphicsCombo.setItemText(1, QtGui.QApplication.translate("Form", "raster", None, QtGui.QApplication.UnicodeUTF8)) self.qtLibCombo.setItemText(0, _translate("Form", "default", None))
self.forceGraphicsCombo.setItemText(2, QtGui.QApplication.translate("Form", "opengl", None, QtGui.QApplication.UnicodeUTF8)) self.qtLibCombo.setItemText(1, _translate("Form", "PyQt4", None))
self.loadBtn.setText(QtGui.QApplication.translate("Form", "Run Example", None, QtGui.QApplication.UnicodeUTF8)) self.qtLibCombo.setItemText(2, _translate("Form", "PySide", None))
self.qtLibCombo.setItemText(3, _translate("Form", "PyQt5", None))
self.label_2.setText(_translate("Form", "Graphics System:", None))
self.label.setText(_translate("Form", "Qt Library:", None))
self.loadBtn.setText(_translate("Form", "Run Example", None))

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'exampleLoaderTemplate.ui' # Form implementation generated from reading ui file 'exampleLoaderTemplate.ui'
# #
# Created: Sat Feb 28 09:38:17 2015 # Created: Sat Feb 28 10:28:50 2015
# by: PyQt5 UI code generator 5.2.1 # by: PyQt5 UI code generator 5.2.1
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -12,53 +12,50 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object): class Ui_Form(object):
def setupUi(self, Form): def setupUi(self, Form):
Form.setObjectName("Form") Form.setObjectName("Form")
Form.resize(623, 380) Form.resize(846, 552)
self.gridLayout = QtWidgets.QGridLayout(Form) self.gridLayout_2 = QtWidgets.QGridLayout(Form)
self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout_2.setObjectName("gridLayout_2")
self.gridLayout.setSpacing(0)
self.gridLayout.setObjectName("gridLayout")
self.splitter = QtWidgets.QSplitter(Form) self.splitter = QtWidgets.QSplitter(Form)
self.splitter.setOrientation(QtCore.Qt.Horizontal) self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName("splitter") self.splitter.setObjectName("splitter")
self.widget = QtWidgets.QWidget(self.splitter) self.widget = QtWidgets.QWidget(self.splitter)
self.widget.setObjectName("widget") self.widget.setObjectName("widget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.widget) self.gridLayout = QtWidgets.QGridLayout(self.widget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout") self.gridLayout.setObjectName("gridLayout")
self.exampleTree = QtWidgets.QTreeWidget(self.widget) self.exampleTree = QtWidgets.QTreeWidget(self.widget)
self.exampleTree.setObjectName("exampleTree") self.exampleTree.setObjectName("exampleTree")
self.exampleTree.headerItem().setText(0, "1") self.exampleTree.headerItem().setText(0, "1")
self.exampleTree.header().setVisible(False) self.exampleTree.header().setVisible(False)
self.verticalLayout.addWidget(self.exampleTree) self.gridLayout.addWidget(self.exampleTree, 0, 0, 1, 2)
self.horizontalLayout = QtWidgets.QHBoxLayout() self.graphicsSystemCombo = QtWidgets.QComboBox(self.widget)
self.horizontalLayout.setObjectName("horizontalLayout") self.graphicsSystemCombo.setObjectName("graphicsSystemCombo")
self.pyqtCheck = QtWidgets.QCheckBox(self.widget) self.graphicsSystemCombo.addItem("")
self.pyqtCheck.setObjectName("pyqtCheck") self.graphicsSystemCombo.addItem("")
self.horizontalLayout.addWidget(self.pyqtCheck) self.graphicsSystemCombo.addItem("")
self.pysideCheck = QtWidgets.QCheckBox(self.widget) self.graphicsSystemCombo.addItem("")
self.pysideCheck.setObjectName("pysideCheck") self.gridLayout.addWidget(self.graphicsSystemCombo, 2, 1, 1, 1)
self.horizontalLayout.addWidget(self.pysideCheck) self.qtLibCombo = QtWidgets.QComboBox(self.widget)
self.verticalLayout.addLayout(self.horizontalLayout) self.qtLibCombo.setObjectName("qtLibCombo")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.qtLibCombo.addItem("")
self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.qtLibCombo.addItem("")
self.forceGraphicsCheck = QtWidgets.QCheckBox(self.widget) self.qtLibCombo.addItem("")
self.forceGraphicsCheck.setObjectName("forceGraphicsCheck") self.qtLibCombo.addItem("")
self.horizontalLayout_2.addWidget(self.forceGraphicsCheck) self.gridLayout.addWidget(self.qtLibCombo, 1, 1, 1, 1)
self.forceGraphicsCombo = QtWidgets.QComboBox(self.widget) self.label_2 = QtWidgets.QLabel(self.widget)
self.forceGraphicsCombo.setObjectName("forceGraphicsCombo") self.label_2.setObjectName("label_2")
self.forceGraphicsCombo.addItem("") self.gridLayout.addWidget(self.label_2, 2, 0, 1, 1)
self.forceGraphicsCombo.addItem("") self.label = QtWidgets.QLabel(self.widget)
self.forceGraphicsCombo.addItem("") self.label.setObjectName("label")
self.horizontalLayout_2.addWidget(self.forceGraphicsCombo) self.gridLayout.addWidget(self.label, 1, 0, 1, 1)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.loadBtn = QtWidgets.QPushButton(self.widget) self.loadBtn = QtWidgets.QPushButton(self.widget)
self.loadBtn.setObjectName("loadBtn") self.loadBtn.setObjectName("loadBtn")
self.verticalLayout.addWidget(self.loadBtn) self.gridLayout.addWidget(self.loadBtn, 3, 1, 1, 1)
self.widget1 = QtWidgets.QWidget(self.splitter) self.widget1 = QtWidgets.QWidget(self.splitter)
self.widget1.setObjectName("widget1") self.widget1.setObjectName("widget1")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.widget1) self.verticalLayout = QtWidgets.QVBoxLayout(self.widget1)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2") self.verticalLayout.setObjectName("verticalLayout")
self.loadedFileLabel = QtWidgets.QLabel(self.widget1) self.loadedFileLabel = QtWidgets.QLabel(self.widget1)
font = QtGui.QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
@ -67,14 +64,14 @@ class Ui_Form(object):
self.loadedFileLabel.setText("") self.loadedFileLabel.setText("")
self.loadedFileLabel.setAlignment(QtCore.Qt.AlignCenter) self.loadedFileLabel.setAlignment(QtCore.Qt.AlignCenter)
self.loadedFileLabel.setObjectName("loadedFileLabel") self.loadedFileLabel.setObjectName("loadedFileLabel")
self.verticalLayout_2.addWidget(self.loadedFileLabel) self.verticalLayout.addWidget(self.loadedFileLabel)
self.codeView = QtWidgets.QPlainTextEdit(self.widget1) self.codeView = QtWidgets.QPlainTextEdit(self.widget1)
font = QtGui.QFont() font = QtGui.QFont()
font.setFamily("FreeMono") font.setFamily("FreeMono")
self.codeView.setFont(font) self.codeView.setFont(font)
self.codeView.setObjectName("codeView") self.codeView.setObjectName("codeView")
self.verticalLayout_2.addWidget(self.codeView) self.verticalLayout.addWidget(self.codeView)
self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1) self.gridLayout_2.addWidget(self.splitter, 0, 0, 1, 1)
self.retranslateUi(Form) self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form) QtCore.QMetaObject.connectSlotsByName(Form)
@ -82,11 +79,15 @@ class Ui_Form(object):
def retranslateUi(self, Form): def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate _translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form")) Form.setWindowTitle(_translate("Form", "Form"))
self.pyqtCheck.setText(_translate("Form", "Force PyQt")) self.graphicsSystemCombo.setItemText(0, _translate("Form", "default"))
self.pysideCheck.setText(_translate("Form", "Force PySide")) self.graphicsSystemCombo.setItemText(1, _translate("Form", "native"))
self.forceGraphicsCheck.setText(_translate("Form", "Force Graphics System:")) self.graphicsSystemCombo.setItemText(2, _translate("Form", "raster"))
self.forceGraphicsCombo.setItemText(0, _translate("Form", "native")) self.graphicsSystemCombo.setItemText(3, _translate("Form", "opengl"))
self.forceGraphicsCombo.setItemText(1, _translate("Form", "raster")) self.qtLibCombo.setItemText(0, _translate("Form", "default"))
self.forceGraphicsCombo.setItemText(2, _translate("Form", "opengl")) self.qtLibCombo.setItemText(1, _translate("Form", "PyQt4"))
self.qtLibCombo.setItemText(2, _translate("Form", "PySide"))
self.qtLibCombo.setItemText(3, _translate("Form", "PyQt5"))
self.label_2.setText(_translate("Form", "Graphics System:"))
self.label.setText(_translate("Form", "Qt Library:"))
self.loadBtn.setText(_translate("Form", "Run Example")) self.loadBtn.setText(_translate("Form", "Run Example"))

View File

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file './exampleLoaderTemplate.ui' # Form implementation generated from reading ui file 'exampleLoaderTemplate.ui'
# #
# Created: Mon Feb 25 09:02:09 2013 # Created: Sat Feb 28 10:31:57 2015
# by: pyside-uic 0.2.13 running on PySide 1.1.1 # by: pyside-uic 0.2.15 running on PySide 1.2.1
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -12,53 +12,50 @@ from PySide import QtCore, QtGui
class Ui_Form(object): class Ui_Form(object):
def setupUi(self, Form): def setupUi(self, Form):
Form.setObjectName("Form") Form.setObjectName("Form")
Form.resize(623, 380) Form.resize(846, 552)
self.gridLayout = QtGui.QGridLayout(Form) self.gridLayout_2 = QtGui.QGridLayout(Form)
self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout_2.setObjectName("gridLayout_2")
self.gridLayout.setSpacing(0)
self.gridLayout.setObjectName("gridLayout")
self.splitter = QtGui.QSplitter(Form) self.splitter = QtGui.QSplitter(Form)
self.splitter.setOrientation(QtCore.Qt.Horizontal) self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName("splitter") self.splitter.setObjectName("splitter")
self.widget = QtGui.QWidget(self.splitter) self.widget = QtGui.QWidget(self.splitter)
self.widget.setObjectName("widget") self.widget.setObjectName("widget")
self.verticalLayout = QtGui.QVBoxLayout(self.widget) self.gridLayout = QtGui.QGridLayout(self.widget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout") self.gridLayout.setObjectName("gridLayout")
self.exampleTree = QtGui.QTreeWidget(self.widget) self.exampleTree = QtGui.QTreeWidget(self.widget)
self.exampleTree.setObjectName("exampleTree") self.exampleTree.setObjectName("exampleTree")
self.exampleTree.headerItem().setText(0, "1") self.exampleTree.headerItem().setText(0, "1")
self.exampleTree.header().setVisible(False) self.exampleTree.header().setVisible(False)
self.verticalLayout.addWidget(self.exampleTree) self.gridLayout.addWidget(self.exampleTree, 0, 0, 1, 2)
self.horizontalLayout = QtGui.QHBoxLayout() self.graphicsSystemCombo = QtGui.QComboBox(self.widget)
self.horizontalLayout.setObjectName("horizontalLayout") self.graphicsSystemCombo.setObjectName("graphicsSystemCombo")
self.pyqtCheck = QtGui.QCheckBox(self.widget) self.graphicsSystemCombo.addItem("")
self.pyqtCheck.setObjectName("pyqtCheck") self.graphicsSystemCombo.addItem("")
self.horizontalLayout.addWidget(self.pyqtCheck) self.graphicsSystemCombo.addItem("")
self.pysideCheck = QtGui.QCheckBox(self.widget) self.graphicsSystemCombo.addItem("")
self.pysideCheck.setObjectName("pysideCheck") self.gridLayout.addWidget(self.graphicsSystemCombo, 2, 1, 1, 1)
self.horizontalLayout.addWidget(self.pysideCheck) self.qtLibCombo = QtGui.QComboBox(self.widget)
self.verticalLayout.addLayout(self.horizontalLayout) self.qtLibCombo.setObjectName("qtLibCombo")
self.horizontalLayout_2 = QtGui.QHBoxLayout() self.qtLibCombo.addItem("")
self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.qtLibCombo.addItem("")
self.forceGraphicsCheck = QtGui.QCheckBox(self.widget) self.qtLibCombo.addItem("")
self.forceGraphicsCheck.setObjectName("forceGraphicsCheck") self.qtLibCombo.addItem("")
self.horizontalLayout_2.addWidget(self.forceGraphicsCheck) self.gridLayout.addWidget(self.qtLibCombo, 1, 1, 1, 1)
self.forceGraphicsCombo = QtGui.QComboBox(self.widget) self.label_2 = QtGui.QLabel(self.widget)
self.forceGraphicsCombo.setObjectName("forceGraphicsCombo") self.label_2.setObjectName("label_2")
self.forceGraphicsCombo.addItem("") self.gridLayout.addWidget(self.label_2, 2, 0, 1, 1)
self.forceGraphicsCombo.addItem("") self.label = QtGui.QLabel(self.widget)
self.forceGraphicsCombo.addItem("") self.label.setObjectName("label")
self.horizontalLayout_2.addWidget(self.forceGraphicsCombo) self.gridLayout.addWidget(self.label, 1, 0, 1, 1)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.loadBtn = QtGui.QPushButton(self.widget) self.loadBtn = QtGui.QPushButton(self.widget)
self.loadBtn.setObjectName("loadBtn") self.loadBtn.setObjectName("loadBtn")
self.verticalLayout.addWidget(self.loadBtn) self.gridLayout.addWidget(self.loadBtn, 3, 1, 1, 1)
self.widget1 = QtGui.QWidget(self.splitter) self.widget1 = QtGui.QWidget(self.splitter)
self.widget1.setObjectName("widget1") self.widget1.setObjectName("widget1")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.widget1) self.verticalLayout = QtGui.QVBoxLayout(self.widget1)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2") self.verticalLayout.setObjectName("verticalLayout")
self.loadedFileLabel = QtGui.QLabel(self.widget1) self.loadedFileLabel = QtGui.QLabel(self.widget1)
font = QtGui.QFont() font = QtGui.QFont()
font.setWeight(75) font.setWeight(75)
@ -67,25 +64,29 @@ class Ui_Form(object):
self.loadedFileLabel.setText("") self.loadedFileLabel.setText("")
self.loadedFileLabel.setAlignment(QtCore.Qt.AlignCenter) self.loadedFileLabel.setAlignment(QtCore.Qt.AlignCenter)
self.loadedFileLabel.setObjectName("loadedFileLabel") self.loadedFileLabel.setObjectName("loadedFileLabel")
self.verticalLayout_2.addWidget(self.loadedFileLabel) self.verticalLayout.addWidget(self.loadedFileLabel)
self.codeView = QtGui.QPlainTextEdit(self.widget1) self.codeView = QtGui.QPlainTextEdit(self.widget1)
font = QtGui.QFont() font = QtGui.QFont()
font.setFamily("FreeMono") font.setFamily("FreeMono")
self.codeView.setFont(font) self.codeView.setFont(font)
self.codeView.setObjectName("codeView") self.codeView.setObjectName("codeView")
self.verticalLayout_2.addWidget(self.codeView) self.verticalLayout.addWidget(self.codeView)
self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1) self.gridLayout_2.addWidget(self.splitter, 0, 0, 1, 1)
self.retranslateUi(Form) self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form): def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8)) Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.pyqtCheck.setText(QtGui.QApplication.translate("Form", "Force PyQt", None, QtGui.QApplication.UnicodeUTF8)) self.graphicsSystemCombo.setItemText(0, QtGui.QApplication.translate("Form", "default", None, QtGui.QApplication.UnicodeUTF8))
self.pysideCheck.setText(QtGui.QApplication.translate("Form", "Force PySide", None, QtGui.QApplication.UnicodeUTF8)) self.graphicsSystemCombo.setItemText(1, QtGui.QApplication.translate("Form", "native", None, QtGui.QApplication.UnicodeUTF8))
self.forceGraphicsCheck.setText(QtGui.QApplication.translate("Form", "Force Graphics System:", None, QtGui.QApplication.UnicodeUTF8)) self.graphicsSystemCombo.setItemText(2, QtGui.QApplication.translate("Form", "raster", None, QtGui.QApplication.UnicodeUTF8))
self.forceGraphicsCombo.setItemText(0, QtGui.QApplication.translate("Form", "native", None, QtGui.QApplication.UnicodeUTF8)) self.graphicsSystemCombo.setItemText(3, QtGui.QApplication.translate("Form", "opengl", None, QtGui.QApplication.UnicodeUTF8))
self.forceGraphicsCombo.setItemText(1, QtGui.QApplication.translate("Form", "raster", None, QtGui.QApplication.UnicodeUTF8)) self.qtLibCombo.setItemText(0, QtGui.QApplication.translate("Form", "default", None, QtGui.QApplication.UnicodeUTF8))
self.forceGraphicsCombo.setItemText(2, QtGui.QApplication.translate("Form", "opengl", None, QtGui.QApplication.UnicodeUTF8)) self.qtLibCombo.setItemText(1, QtGui.QApplication.translate("Form", "PyQt4", None, QtGui.QApplication.UnicodeUTF8))
self.qtLibCombo.setItemText(2, QtGui.QApplication.translate("Form", "PySide", None, QtGui.QApplication.UnicodeUTF8))
self.qtLibCombo.setItemText(3, QtGui.QApplication.translate("Form", "PyQt5", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("Form", "Graphics System:", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Form", "Qt Library:", None, QtGui.QApplication.UnicodeUTF8))
self.loadBtn.setText(QtGui.QApplication.translate("Form", "Run Example", None, QtGui.QApplication.UnicodeUTF8)) self.loadBtn.setText(QtGui.QApplication.translate("Form", "Run Example", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -29,12 +29,18 @@ elif 'pyqt5' in sys.argv:
else: else:
from pyqtgraph.Qt import QtGui from pyqtgraph.Qt import QtGui
import pyqtgraph as pg
## Force use of a specific graphics system ## Force use of a specific graphics system
use_gs = 'default'
for gs in ['raster', 'native', 'opengl']: for gs in ['raster', 'native', 'opengl']:
if gs in sys.argv: if gs in sys.argv:
use_gs = gs
QtGui.QApplication.setGraphicsSystem(gs) QtGui.QApplication.setGraphicsSystem(gs)
break break
print("Using %s (%s graphics system)" % (pg.Qt.QT_LIB, use_gs))
## Enable fault handling to give more helpful error messages on crash. ## Enable fault handling to give more helpful error messages on crash.
## Only available in python 3.3+ ## Only available in python 3.3+
try: try:

View File

@ -20,7 +20,7 @@ QT_LIB = None
## Automatically determine whether to use PyQt or PySide. ## Automatically determine whether to use PyQt or PySide.
## This is done by first checking to see whether one of the libraries ## This is done by first checking to see whether one of the libraries
## is already imported. If not, then attempt to import PyQt4, then PySide. ## is already imported. If not, then attempt to import PyQt4, then PySide.
libOrder = [PYQT5, PYQT4, PYSIDE] libOrder = [PYQT4, PYSIDE, PYQT5]
for lib in libOrder: for lib in libOrder:
if lib in sys.modules: if lib in sys.modules:
@ -36,8 +36,6 @@ if QT_LIB is None:
except ImportError: except ImportError:
pass pass
print(QT_LIB)
if QT_LIB == None: if QT_LIB == None:
raise Exception("PyQtGraph requires one of PyQt4, PyQt5 or PySide; none of these packages could be imported.") raise Exception("PyQtGraph requires one of PyQt4, PyQt5 or PySide; none of these packages could be imported.")
@ -124,24 +122,30 @@ elif QT_LIB == PYQT5:
# Re-implement deprecated APIs # Re-implement deprecated APIs
def scale(self, sx, sy): def scale(self, sx, sy):
self.setTransform(QtGui.QTransform.fromScale(sx, sy), True) tr = self.transform()
tr.scale(sx, sy)
self.setTransform(tr)
QtWidgets.QGraphicsItem.scale = scale QtWidgets.QGraphicsItem.scale = scale
def rotate(self, angle): def rotate(self, angle):
self.setRotation(self.rotation() + angle) tr = self.transform()
tr.rotate(angle)
self.setTransform(tr)
QtWidgets.QGraphicsItem.rotate = rotate QtWidgets.QGraphicsItem.rotate = rotate
def translate(self, dx, dy): def translate(self, dx, dy):
self.setTransform(QtGui.QTransform.fromTranslate(dx, dy), True) tr = self.transform()
tr.translate(dx, dy)
self.setTransform(tr)
QtWidgets.QGraphicsItem.translate = translate QtWidgets.QGraphicsItem.translate = translate
def setMargin(self, i): #def setMargin(self, i):
self.setContentsMargins(i, i, i, i) #self.setContentsMargins(i, i, i, i)
QtWidgets.QGridLayout.setMargin = setMargin #QtWidgets.QGridLayout.setMargin = setMargin
def setResizeMode(self, mode): #def setResizeMode(self, mode):
self.setSectionResizeMode(mode) #self.setSectionResizeMode(mode)
QtWidgets.QHeaderView.setResizeMode = setResizeMode #QtWidgets.QHeaderView.setResizeMode = setResizeMode
QtGui.QApplication = QtWidgets.QApplication QtGui.QApplication = QtWidgets.QApplication
@ -171,12 +175,11 @@ if QT_LIB.startswith('PyQt'):
## Make sure we have Qt >= 4.7 ## Make sure we have Qt >= 4.7
versionReq = [4, 7] versionReq = [4, 7]
USE_PYSIDE = QT_LIB == PYSIDE # for backward compatibility USE_PYSIDE = QT_LIB == PYSIDE
USE_PYQT5 = QT_LIB == PYQT5 # for backward compatibility USE_PYQT4 = QT_LIB == PYQT4
USE_PYQT4 = QT_LIB == PYQT4 # for backward compatibility USE_PYQT5 = QT_LIB == PYQT5
QtVersion = PySide.QtCore.__version__ if QT_LIB == PYSIDE else QtCore.QT_VERSION_STR QtVersion = PySide.QtCore.__version__ if QT_LIB == PYSIDE else QtCore.QT_VERSION_STR
m = re.match(r'(\d+)\.(\d+).*', QtVersion) m = re.match(r'(\d+)\.(\d+).*', QtVersion)
if m is not None and list(map(int, m.groups())) < versionReq: if m is not None and list(map(int, m.groups())) < versionReq:
print(list(map(int, m.groups()))) print(list(map(int, m.groups())))
raise Exception('pyqtgraph requires Qt version >= %d.%d (your version is %s)' % (versionReq[0], versionReq[1], QtVersion)) raise Exception('pyqtgraph requires Qt version >= %d.%d (your version is %s)' % (versionReq[0], versionReq[1], QtVersion))

View File

@ -45,41 +45,6 @@ class SVGExporter(Exporter):
if toBytes is False and copy is False and fileName is None: if toBytes is False and copy is False and fileName is None:
self.fileSaveDialog(filter="Scalable Vector Graphics (*.svg)") self.fileSaveDialog(filter="Scalable Vector Graphics (*.svg)")
return return
#self.svg = QtSvg.QSvgGenerator()
#self.svg.setFileName(fileName)
#dpi = QtGui.QDesktopWidget().physicalDpiX()
### not really sure why this works, but it seems to be important:
#self.svg.setSize(QtCore.QSize(self.params['width']*dpi/90., self.params['height']*dpi/90.))
#self.svg.setResolution(dpi)
##self.svg.setViewBox()
#targetRect = QtCore.QRect(0, 0, self.params['width'], self.params['height'])
#sourceRect = self.getSourceRect()
#painter = QtGui.QPainter(self.svg)
#try:
#self.setExportMode(True)
#self.render(painter, QtCore.QRectF(targetRect), sourceRect)
#finally:
#self.setExportMode(False)
#painter.end()
## Workaround to set pen widths correctly
#data = open(fileName).readlines()
#for i in range(len(data)):
#line = data[i]
#m = re.match(r'(<g .*)stroke-width="1"(.*transform="matrix\(([^\)]+)\)".*)', line)
#if m is not None:
##print "Matched group:", line
#g = m.groups()
#matrix = list(map(float, g[2].split(',')))
##print "matrix:", matrix
#scale = max(abs(matrix[0]), abs(matrix[3]))
#if scale == 0 or scale == 1.0:
#continue
#data[i] = g[0] + ' stroke-width="%0.2g" ' % (1.0/scale) + g[1] + '\n'
##print "old line:", line
##print "new line:", data[i]
#open(fileName, 'w').write(''.join(data))
## Qt's SVG generator is not complete. (notably, it lacks clipping) ## Qt's SVG generator is not complete. (notably, it lacks clipping)
## Instead, we will use Qt to generate SVG for each item independently, ## Instead, we will use Qt to generate SVG for each item independently,

View File

@ -16,7 +16,7 @@ This class is very heavily featured:
- Control panel with a huge feature set including averaging, decimation, - Control panel with a huge feature set including averaging, decimation,
display, power spectrum, svg/png export, plot linking, and more. display, power spectrum, svg/png export, plot linking, and more.
""" """
from ...Qt import QtGui, QtCore, QtSvg, QT_LIB from ...Qt import QtGui, QtCore, QT_LIB
from ... import pixmaps from ... import pixmaps
import sys import sys
@ -785,42 +785,9 @@ class PlotItem(GraphicsWidget):
fileName = str(fileName) fileName = str(fileName)
PlotItem.lastFileDir = os.path.dirname(fileName) PlotItem.lastFileDir = os.path.dirname(fileName)
self.svg = QtSvg.QSvgGenerator() from ...exporters import SVGExporter
self.svg.setFileName(fileName) ex = SVGExporter(self)
res = 120. ex.export(fileName)
view = self.scene().views()[0]
bounds = view.viewport().rect()
bounds = QtCore.QRectF(0, 0, bounds.width(), bounds.height())
self.svg.setResolution(res)
self.svg.setViewBox(bounds)
self.svg.setSize(QtCore.QSize(bounds.width(), bounds.height()))
painter = QtGui.QPainter(self.svg)
view.render(painter, bounds)
painter.end()
## Workaround to set pen widths correctly
import re
data = open(fileName).readlines()
for i in range(len(data)):
line = data[i]
m = re.match(r'(<g .*)stroke-width="1"(.*transform="matrix\(([^\)]+)\)".*)', line)
if m is not None:
#print "Matched group:", line
g = m.groups()
matrix = list(map(float, g[2].split(',')))
#print "matrix:", matrix
scale = max(abs(matrix[0]), abs(matrix[3]))
if scale == 0 or scale == 1.0:
continue
data[i] = g[0] + ' stroke-width="%0.2g" ' % (1.0/scale) + g[1] + '\n'
#print "old line:", line
#print "new line:", data[i]
open(fileName, 'w').write(''.join(data))
def writeImage(self, fileName=None): def writeImage(self, fileName=None):
if fileName is None: if fileName is None: