diff --git a/examples/ViewBox.py b/examples/ViewBox.py index c8487148..2dcbb758 100644 --- a/examples/ViewBox.py +++ b/examples/ViewBox.py @@ -36,6 +36,7 @@ vb = pg.ViewBox() p1 = pg.PlotDataItem() vb.addItem(p1) +## Just something to play with inside the ViewBox class movableRect(QtGui.QGraphicsRectItem): def __init__(self, *args): QtGui.QGraphicsRectItem.__init__(self, *args) @@ -56,8 +57,6 @@ class movableRect(QtGui.QGraphicsRectItem): def mouseMoveEvent(self, ev): self.setPos(self.mapToParent(ev.pos()) - self.pressDelta) - -#rect = QtGui.QGraphicsRectItem(QtCore.QRectF(0, 0, 1, 1)) rect = movableRect(QtCore.QRectF(0, 0, 1, 1)) rect.setPen(QtGui.QPen(QtGui.QColor(100, 200, 100))) vb.addItem(rect) diff --git a/examples/__main__.py b/examples/__main__.py index 9b9e7b57..8d60714c 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -88,6 +88,13 @@ class ExampleLoader(QtGui.QMainWindow): self.setCentralWidget(self.cw) self.ui.setupUi(self.cw) + self.codeBtn = QtGui.QPushButton('Run Edited Code') + self.codeLayout = QtGui.QGridLayout() + self.ui.codeView.setLayout(self.codeLayout) + self.codeLayout.addItem(QtGui.QSpacerItem(100,100,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding), 0, 0) + self.codeLayout.addWidget(self.codeBtn, 1, 1) + self.codeBtn.hide() + global examples self.populateTree(self.ui.exampleTree.invisibleRootItem(), examples) self.ui.exampleTree.expandAll() @@ -100,6 +107,8 @@ class ExampleLoader(QtGui.QMainWindow): 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.codeBtn.clicked.connect(self.runEditedCode) def pyqtToggled(self, b): if b: @@ -127,8 +136,8 @@ class ExampleLoader(QtGui.QMainWindow): return os.path.join(path, item.file) return None - def loadFile(self): - fn = self.currentFile() + def loadFile(self, edited=False): + extra = [] if self.ui.pyqtCheck.isChecked(): extra.append('pyqt') @@ -138,13 +147,25 @@ class ExampleLoader(QtGui.QMainWindow): if self.ui.forceGraphicsCheck.isChecked(): extra.append(str(self.ui.forceGraphicsCombo.currentText())) - if fn is None: - return - 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 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: + proc = subprocess.Popen([sys.executable, '-'] + extra, stdin=subprocess.PIPE) + code = str(self.ui.codeView.toPlainText()).encode('UTF-8') + proc.stdin.write(code) + proc.stdin.close() + else: + fn = self.currentFile() + if fn is None: + return + 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) def showFile(self): fn = self.currentFile() @@ -155,6 +176,14 @@ class ExampleLoader(QtGui.QMainWindow): fn = os.path.join(fn, '__main__.py') text = open(fn).read() self.ui.codeView.setPlainText(text) + self.ui.loadedFileLabel.setText(fn) + self.codeBtn.hide() + + def codeEdited(self): + self.codeBtn.show() + + def runEditedCode(self): + self.loadFile(edited=True) def run(): app = QtGui.QApplication([]) diff --git a/examples/exampleLoaderTemplate.ui b/examples/exampleLoaderTemplate.ui index cd5ce921..2da57800 100644 --- a/examples/exampleLoaderTemplate.ui +++ b/examples/exampleLoaderTemplate.ui @@ -6,8 +6,8 @@ 0 0 - 762 - 302 + 623 + 380 @@ -25,7 +25,7 @@ Qt::Horizontal - + @@ -90,19 +90,40 @@ - Load Example + Run Example - - - - Monospace - 10 - - + + + + + + + 75 + true + + + + + + + Qt::AlignCenter + + + + + + + + FreeMono + + + + + diff --git a/examples/exampleLoaderTemplate_pyqt.py b/examples/exampleLoaderTemplate_pyqt.py index f359cc32..836640c6 100644 --- a/examples/exampleLoaderTemplate_pyqt.py +++ b/examples/exampleLoaderTemplate_pyqt.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file './examples/exampleLoaderTemplate.ui' +# Form implementation generated from reading ui file './exampleLoaderTemplate.ui' # -# Created: Mon Dec 24 00:33:38 2012 -# by: PyQt4 UI code generator 4.9.1 +# Created: Mon Feb 25 09:02:09 2013 +# by: PyQt4 UI code generator 4.9.3 # # WARNING! All changes made in this file will be lost! @@ -17,7 +17,7 @@ except AttributeError: class Ui_Form(object): def setupUi(self, Form): Form.setObjectName(_fromUtf8("Form")) - Form.resize(762, 302) + Form.resize(623, 380) self.gridLayout = QtGui.QGridLayout(Form) self.gridLayout.setMargin(0) self.gridLayout.setSpacing(0) @@ -25,46 +25,60 @@ class Ui_Form(object): self.splitter = QtGui.QSplitter(Form) self.splitter.setOrientation(QtCore.Qt.Horizontal) self.splitter.setObjectName(_fromUtf8("splitter")) - self.layoutWidget = QtGui.QWidget(self.splitter) - self.layoutWidget.setObjectName(_fromUtf8("layoutWidget")) - self.verticalLayout = QtGui.QVBoxLayout(self.layoutWidget) + self.widget = QtGui.QWidget(self.splitter) + self.widget.setObjectName(_fromUtf8("widget")) + self.verticalLayout = QtGui.QVBoxLayout(self.widget) self.verticalLayout.setMargin(0) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) - self.exampleTree = QtGui.QTreeWidget(self.layoutWidget) + self.exampleTree = QtGui.QTreeWidget(self.widget) self.exampleTree.setObjectName(_fromUtf8("exampleTree")) self.exampleTree.headerItem().setText(0, _fromUtf8("1")) self.exampleTree.header().setVisible(False) self.verticalLayout.addWidget(self.exampleTree) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) - self.pyqtCheck = QtGui.QCheckBox(self.layoutWidget) + self.pyqtCheck = QtGui.QCheckBox(self.widget) self.pyqtCheck.setObjectName(_fromUtf8("pyqtCheck")) self.horizontalLayout.addWidget(self.pyqtCheck) - self.pysideCheck = QtGui.QCheckBox(self.layoutWidget) + self.pysideCheck = QtGui.QCheckBox(self.widget) self.pysideCheck.setObjectName(_fromUtf8("pysideCheck")) self.horizontalLayout.addWidget(self.pysideCheck) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout_2 = QtGui.QHBoxLayout() self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) - self.forceGraphicsCheck = QtGui.QCheckBox(self.layoutWidget) + self.forceGraphicsCheck = QtGui.QCheckBox(self.widget) self.forceGraphicsCheck.setObjectName(_fromUtf8("forceGraphicsCheck")) self.horizontalLayout_2.addWidget(self.forceGraphicsCheck) - self.forceGraphicsCombo = QtGui.QComboBox(self.layoutWidget) + self.forceGraphicsCombo = QtGui.QComboBox(self.widget) self.forceGraphicsCombo.setObjectName(_fromUtf8("forceGraphicsCombo")) self.forceGraphicsCombo.addItem(_fromUtf8("")) self.forceGraphicsCombo.addItem(_fromUtf8("")) self.forceGraphicsCombo.addItem(_fromUtf8("")) self.horizontalLayout_2.addWidget(self.forceGraphicsCombo) self.verticalLayout.addLayout(self.horizontalLayout_2) - self.loadBtn = QtGui.QPushButton(self.layoutWidget) + self.loadBtn = QtGui.QPushButton(self.widget) self.loadBtn.setObjectName(_fromUtf8("loadBtn")) self.verticalLayout.addWidget(self.loadBtn) - self.codeView = QtGui.QTextBrowser(self.splitter) + self.widget1 = QtGui.QWidget(self.splitter) + self.widget1.setObjectName(_fromUtf8("widget1")) + self.verticalLayout_2 = QtGui.QVBoxLayout(self.widget1) + self.verticalLayout_2.setMargin(0) + self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) + self.loadedFileLabel = QtGui.QLabel(self.widget1) font = QtGui.QFont() - font.setFamily(_fromUtf8("Monospace")) - font.setPointSize(10) + font.setBold(True) + font.setWeight(75) + self.loadedFileLabel.setFont(font) + self.loadedFileLabel.setText(_fromUtf8("")) + self.loadedFileLabel.setAlignment(QtCore.Qt.AlignCenter) + self.loadedFileLabel.setObjectName(_fromUtf8("loadedFileLabel")) + self.verticalLayout_2.addWidget(self.loadedFileLabel) + self.codeView = QtGui.QPlainTextEdit(self.widget1) + font = QtGui.QFont() + font.setFamily(_fromUtf8("FreeMono")) self.codeView.setFont(font) self.codeView.setObjectName(_fromUtf8("codeView")) + self.verticalLayout_2.addWidget(self.codeView) self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1) self.retranslateUi(Form) @@ -78,5 +92,5 @@ class Ui_Form(object): self.forceGraphicsCombo.setItemText(0, QtGui.QApplication.translate("Form", "native", None, QtGui.QApplication.UnicodeUTF8)) self.forceGraphicsCombo.setItemText(1, QtGui.QApplication.translate("Form", "raster", None, QtGui.QApplication.UnicodeUTF8)) self.forceGraphicsCombo.setItemText(2, QtGui.QApplication.translate("Form", "opengl", None, QtGui.QApplication.UnicodeUTF8)) - self.loadBtn.setText(QtGui.QApplication.translate("Form", "Load Example", None, QtGui.QApplication.UnicodeUTF8)) + self.loadBtn.setText(QtGui.QApplication.translate("Form", "Run Example", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/examples/exampleLoaderTemplate_pyside.py b/examples/exampleLoaderTemplate_pyside.py index 113c1654..f596e566 100644 --- a/examples/exampleLoaderTemplate_pyside.py +++ b/examples/exampleLoaderTemplate_pyside.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file './examples/exampleLoaderTemplate.ui' +# Form implementation generated from reading ui file './exampleLoaderTemplate.ui' # -# Created: Mon Dec 24 00:33:39 2012 -# by: pyside-uic 0.2.13 running on PySide 1.1.2 +# Created: Mon Feb 25 09:02:09 2013 +# by: pyside-uic 0.2.13 running on PySide 1.1.1 # # WARNING! All changes made in this file will be lost! @@ -12,7 +12,7 @@ from PySide import QtCore, QtGui class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") - Form.resize(762, 302) + Form.resize(623, 380) self.gridLayout = QtGui.QGridLayout(Form) self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setSpacing(0) @@ -20,46 +20,60 @@ class Ui_Form(object): self.splitter = QtGui.QSplitter(Form) self.splitter.setOrientation(QtCore.Qt.Horizontal) self.splitter.setObjectName("splitter") - self.layoutWidget = QtGui.QWidget(self.splitter) - self.layoutWidget.setObjectName("layoutWidget") - self.verticalLayout = QtGui.QVBoxLayout(self.layoutWidget) + self.widget = QtGui.QWidget(self.splitter) + self.widget.setObjectName("widget") + self.verticalLayout = QtGui.QVBoxLayout(self.widget) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") - self.exampleTree = QtGui.QTreeWidget(self.layoutWidget) + self.exampleTree = QtGui.QTreeWidget(self.widget) self.exampleTree.setObjectName("exampleTree") self.exampleTree.headerItem().setText(0, "1") self.exampleTree.header().setVisible(False) self.verticalLayout.addWidget(self.exampleTree) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") - self.pyqtCheck = QtGui.QCheckBox(self.layoutWidget) + self.pyqtCheck = QtGui.QCheckBox(self.widget) self.pyqtCheck.setObjectName("pyqtCheck") self.horizontalLayout.addWidget(self.pyqtCheck) - self.pysideCheck = QtGui.QCheckBox(self.layoutWidget) + self.pysideCheck = QtGui.QCheckBox(self.widget) self.pysideCheck.setObjectName("pysideCheck") self.horizontalLayout.addWidget(self.pysideCheck) self.verticalLayout.addLayout(self.horizontalLayout) self.horizontalLayout_2 = QtGui.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") - self.forceGraphicsCheck = QtGui.QCheckBox(self.layoutWidget) + self.forceGraphicsCheck = QtGui.QCheckBox(self.widget) self.forceGraphicsCheck.setObjectName("forceGraphicsCheck") self.horizontalLayout_2.addWidget(self.forceGraphicsCheck) - self.forceGraphicsCombo = QtGui.QComboBox(self.layoutWidget) + self.forceGraphicsCombo = QtGui.QComboBox(self.widget) self.forceGraphicsCombo.setObjectName("forceGraphicsCombo") self.forceGraphicsCombo.addItem("") self.forceGraphicsCombo.addItem("") self.forceGraphicsCombo.addItem("") self.horizontalLayout_2.addWidget(self.forceGraphicsCombo) self.verticalLayout.addLayout(self.horizontalLayout_2) - self.loadBtn = QtGui.QPushButton(self.layoutWidget) + self.loadBtn = QtGui.QPushButton(self.widget) self.loadBtn.setObjectName("loadBtn") self.verticalLayout.addWidget(self.loadBtn) - self.codeView = QtGui.QTextBrowser(self.splitter) + self.widget1 = QtGui.QWidget(self.splitter) + self.widget1.setObjectName("widget1") + self.verticalLayout_2 = QtGui.QVBoxLayout(self.widget1) + self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) + self.verticalLayout_2.setObjectName("verticalLayout_2") + self.loadedFileLabel = QtGui.QLabel(self.widget1) font = QtGui.QFont() - font.setFamily("Monospace") - font.setPointSize(10) + font.setWeight(75) + font.setBold(True) + self.loadedFileLabel.setFont(font) + self.loadedFileLabel.setText("") + self.loadedFileLabel.setAlignment(QtCore.Qt.AlignCenter) + self.loadedFileLabel.setObjectName("loadedFileLabel") + self.verticalLayout_2.addWidget(self.loadedFileLabel) + self.codeView = QtGui.QPlainTextEdit(self.widget1) + font = QtGui.QFont() + font.setFamily("FreeMono") self.codeView.setFont(font) self.codeView.setObjectName("codeView") + self.verticalLayout_2.addWidget(self.codeView) self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1) self.retranslateUi(Form) @@ -73,5 +87,5 @@ class Ui_Form(object): self.forceGraphicsCombo.setItemText(0, QtGui.QApplication.translate("Form", "native", None, QtGui.QApplication.UnicodeUTF8)) self.forceGraphicsCombo.setItemText(1, QtGui.QApplication.translate("Form", "raster", None, QtGui.QApplication.UnicodeUTF8)) self.forceGraphicsCombo.setItemText(2, QtGui.QApplication.translate("Form", "opengl", None, QtGui.QApplication.UnicodeUTF8)) - self.loadBtn.setText(QtGui.QApplication.translate("Form", "Load Example", None, QtGui.QApplication.UnicodeUTF8)) + self.loadBtn.setText(QtGui.QApplication.translate("Form", "Run Example", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/examples/initExample.py b/examples/initExample.py index 204a1ead..d8022aba 100644 --- a/examples/initExample.py +++ b/examples/initExample.py @@ -4,7 +4,10 @@ import sys, os if not hasattr(sys, 'frozen'): - path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + if __file__ == '': + path = os.getcwd() + else: + path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) path.rstrip(os.path.sep) if 'pyqtgraph' in os.listdir(path): sys.path.insert(0, path) ## examples adjacent to pyqtgraph (as in source tree) diff --git a/pyqtgraph/graphicsItems/GradientEditorItem.py b/pyqtgraph/graphicsItems/GradientEditorItem.py index 5439c731..955106d8 100644 --- a/pyqtgraph/graphicsItems/GradientEditorItem.py +++ b/pyqtgraph/graphicsItems/GradientEditorItem.py @@ -782,7 +782,8 @@ class GradientEditorItem(TickSliderItem): self.sigGradientChangeFinished.emit(self) -class Tick(GraphicsObject): +class Tick(QtGui.QGraphicsObject): ## NOTE: Making this a subclass of GraphicsObject instead results in + ## activating this bug: https://bugreports.qt-project.org/browse/PYSIDE-86 ## private class sigMoving = QtCore.Signal(object) @@ -802,7 +803,7 @@ class Tick(GraphicsObject): self.pg.lineTo(QtCore.QPointF(scale/3**0.5, scale)) self.pg.closeSubpath() - GraphicsObject.__init__(self) + QtGui.QGraphicsObject.__init__(self) self.setPos(pos[0], pos[1]) if self.movable: self.setZValue(1) diff --git a/pyqtgraph/rebuildUi.py b/tools/rebuildUi.py similarity index 100% rename from pyqtgraph/rebuildUi.py rename to tools/rebuildUi.py