From a330d8494393f622d15f0a2859e96cfa6abdf662 Mon Sep 17 00:00:00 2001
From: Luke Campagnola <>
Date: Wed, 4 Apr 2012 14:45:12 -0400
Subject: [PATCH] added check for correct python version fixes for flowchart -
added missing FeedbackButton.py - corrected imports
---
__init__.py | 5 +
examples/Flowchart.py | 8 +-
flowchart/FlowchartCtrlTemplate.py | 2 +-
flowchart/FlowchartCtrlTemplate.ui | 2 +-
widgets/FeedbackButton.py | 160 +++++++++++++++++++++++++++++
5 files changed, 171 insertions(+), 6 deletions(-)
create mode 100644 widgets/FeedbackButton.py
diff --git a/__init__.py b/__init__.py
index 5c260d1a..ddfe7d8e 100644
--- a/__init__.py
+++ b/__init__.py
@@ -13,6 +13,11 @@ from Qt import QtGui
## we only enable it where the performance benefit is critical.
## Note this only applies to 2D graphics; 3D graphics always use OpenGL.
import sys
+
+## check python version
+if sys.version_info[0] != 2 or sys.version_info[1] != 7:
+ raise Exception("Pyqtgraph requires Python version 2.7 (this is %d.%d)" % (sys.version_info[0], sys.version_info[1]))
+
if 'linux' in sys.platform: ## linux has numerous bugs in opengl implementation
useOpenGL = False
elif 'darwin' in sys.platform: ## openGL greatly speeds up display on mac
diff --git a/examples/Flowchart.py b/examples/Flowchart.py
index 749fd3b6..2b4613f4 100644
--- a/examples/Flowchart.py
+++ b/examples/Flowchart.py
@@ -24,10 +24,10 @@ w = fc.widget()
w.resize(400,200)
w.show()
-n1 = fc.createNode('Add')
-n2 = fc.createNode('Subtract')
-n3 = fc.createNode('Abs')
-n4 = fc.createNode('Add')
+n1 = fc.createNode('Add', pos=(0,-80))
+n2 = fc.createNode('Subtract', pos=(140,-10))
+n3 = fc.createNode('Abs', pos=(0, 80))
+n4 = fc.createNode('Add', pos=(140,100))
fc.connectTerminals(fc.dataIn, n1.A)
fc.connectTerminals(fc.dataIn, n1.B)
diff --git a/flowchart/FlowchartCtrlTemplate.py b/flowchart/FlowchartCtrlTemplate.py
index 0f2ec162..f09e64ed 100644
--- a/flowchart/FlowchartCtrlTemplate.py
+++ b/flowchart/FlowchartCtrlTemplate.py
@@ -67,5 +67,5 @@ class Ui_Form(object):
self.reloadBtn.setText(QtGui.QApplication.translate("Form", "Reload Libs", None, QtGui.QApplication.UnicodeUTF8))
self.showChartBtn.setText(QtGui.QApplication.translate("Form", "Flowchart", None, QtGui.QApplication.UnicodeUTF8))
-from FeedbackButton import FeedbackButton
+from pyqtgraph.widgets.FeedbackButton import FeedbackButton
from pyqtgraph.widgets.TreeWidget import TreeWidget
diff --git a/flowchart/FlowchartCtrlTemplate.ui b/flowchart/FlowchartCtrlTemplate.ui
index a931fb3a..610846b6 100644
--- a/flowchart/FlowchartCtrlTemplate.ui
+++ b/flowchart/FlowchartCtrlTemplate.ui
@@ -112,7 +112,7 @@
FeedbackButton
QPushButton
-
+ pyqtgraph.widgets.FeedbackButton
diff --git a/widgets/FeedbackButton.py b/widgets/FeedbackButton.py
new file mode 100644
index 00000000..5112e955
--- /dev/null
+++ b/widgets/FeedbackButton.py
@@ -0,0 +1,160 @@
+# -*- coding: utf-8 -*-
+from pyqtgraph.Qt import QtCore, QtGui
+class FeedbackButton(QtGui.QPushButton):
+ """
+ QPushButton which flashes success/failure indication for slow or asynchronous procedures.
+ """
+
+
+ ### For thread-safetyness
+ sigCallSuccess = QtCore.Signal(object, object, object)
+ sigCallFailure = QtCore.Signal(object, object, object)
+ sigCallProcess = QtCore.Signal(object, object, object)
+ sigReset = QtCore.Signal()
+
+ def __init__(self, *args):
+ QtGui.QPushButton.__init__(self, *args)
+ self.origStyle = None
+ self.origText = self.text()
+ self.origStyle = self.styleSheet()
+ self.origTip = self.toolTip()
+ self.limitedTime = True
+
+
+ #self.textTimer = QtCore.QTimer()
+ #self.tipTimer = QtCore.QTimer()
+ #self.textTimer.timeout.connect(self.setText)
+ #self.tipTimer.timeout.connect(self.setToolTip)
+
+ self.sigCallSuccess.connect(self.success)
+ self.sigCallFailure.connect(self.failure)
+ self.sigCallProcess.connect(self.processing)
+ self.sigReset.connect(self.reset)
+
+
+ def feedback(self, success, message=None, tip="", limitedTime=True):
+ """Calls success() or failure(). If you want the message to be displayed until the user takes an action, set limitedTime to False. Then call self.reset() after the desired action.Threadsafe."""
+ if success:
+ self.success(message, tip, limitedTime=limitedTime)
+ else:
+ self.failure(message, tip, limitedTime=limitedTime)
+
+ def success(self, message=None, tip="", limitedTime=True):
+ """Displays specified message on button and flashes button green to let user know action was successful. If you want the success to be displayed until the user takes an action, set limitedTime to False. Then call self.reset() after the desired action. Threadsafe."""
+ isGuiThread = QtCore.QThread.currentThread() == QtCore.QCoreApplication.instance().thread()
+ if isGuiThread:
+ self.setEnabled(True)
+ #print "success"
+ self.startBlink("#0F0", message, tip, limitedTime=limitedTime)
+ else:
+ self.sigCallSuccess.emit(message, tip, limitedTime)
+
+ def failure(self, message=None, tip="", limitedTime=True):
+ """Displays specified message on button and flashes button red to let user know there was an error. If you want the error to be displayed until the user takes an action, set limitedTime to False. Then call self.reset() after the desired action. Threadsafe. """
+ isGuiThread = QtCore.QThread.currentThread() == QtCore.QCoreApplication.instance().thread()
+ if isGuiThread:
+ self.setEnabled(True)
+ #print "fail"
+ self.startBlink("#F00", message, tip, limitedTime=limitedTime)
+ else:
+ self.sigCallFailure.emit(message, tip, limitedTime)
+
+ def processing(self, message="Processing..", tip="", processEvents=True):
+ """Displays specified message on button to let user know the action is in progress. Threadsafe. """
+ isGuiThread = QtCore.QThread.currentThread() == QtCore.QCoreApplication.instance().thread()
+ if isGuiThread:
+ self.setEnabled(False)
+ self.setText(message, temporary=True)
+ self.setToolTip(tip, temporary=True)
+ if processEvents:
+ QtGui.QApplication.processEvents()
+ else:
+ self.sigCallProcess.emit(message, tip, processEvents)
+
+
+ def reset(self):
+ """Resets the button to its original text and style. Threadsafe."""
+ isGuiThread = QtCore.QThread.currentThread() == QtCore.QCoreApplication.instance().thread()
+ if isGuiThread:
+ self.limitedTime = True
+ self.setText()
+ self.setToolTip()
+ self.setStyleSheet()
+ else:
+ self.sigReset.emit()
+
+ def startBlink(self, color, message=None, tip="", limitedTime=True):
+ #if self.origStyle is None:
+ #self.origStyle = self.styleSheet()
+ #self.origText = self.text()
+ self.setFixedHeight(self.height())
+
+ if message is not None:
+ self.setText(message, temporary=True)
+ self.setToolTip(tip, temporary=True)
+ self.count = 0
+ #self.indStyle = "QPushButton {border: 2px solid %s; border-radius: 5px}" % color
+ self.indStyle = "QPushButton {background-color: %s}" % color
+ self.limitedTime = limitedTime
+ self.borderOn()
+ if limitedTime:
+ QtCore.QTimer.singleShot(2000, self.setText)
+ QtCore.QTimer.singleShot(10000, self.setToolTip)
+
+ def borderOn(self):
+ self.setStyleSheet(self.indStyle, temporary=True)
+ if self.limitedTime or self.count <=2:
+ QtCore.QTimer.singleShot(100, self.borderOff)
+
+
+ def borderOff(self):
+ self.setStyleSheet()
+ self.count += 1
+ if self.count >= 2:
+ if self.limitedTime:
+ return
+ QtCore.QTimer.singleShot(30, self.borderOn)
+
+
+ def setText(self, text=None, temporary=False):
+ if text is None:
+ text = self.origText
+ #print text
+ QtGui.QPushButton.setText(self, text)
+ if not temporary:
+ self.origText = text
+
+ def setToolTip(self, text=None, temporary=False):
+ if text is None:
+ text = self.origTip
+ QtGui.QPushButton.setToolTip(self, text)
+ if not temporary:
+ self.origTip = text
+
+ def setStyleSheet(self, style=None, temporary=False):
+ if style is None:
+ style = self.origStyle
+ QtGui.QPushButton.setStyleSheet(self, style)
+ if not temporary:
+ self.origStyle = style
+
+
+if __name__ == '__main__':
+ import time
+ app = QtGui.QApplication([])
+ win = QtGui.QMainWindow()
+ btn = FeedbackButton("Button")
+ fail = True
+ def click():
+ btn.processing("Hold on..")
+ time.sleep(2.0)
+
+ global fail
+ fail = not fail
+ if fail:
+ btn.failure(message="FAIL.", tip="There was a failure. Get over it.")
+ else:
+ btn.success(message="Bueno!")
+ btn.clicked.connect(click)
+ win.setCentralWidget(btn)
+ win.show()
\ No newline at end of file