added check for correct python version
fixes for flowchart - added missing FeedbackButton.py - corrected imports
This commit is contained in:
parent
bdb6ff88a2
commit
a330d84943
@ -13,6 +13,11 @@ from Qt import QtGui
|
|||||||
## we only enable it where the performance benefit is critical.
|
## we only enable it where the performance benefit is critical.
|
||||||
## Note this only applies to 2D graphics; 3D graphics always use OpenGL.
|
## Note this only applies to 2D graphics; 3D graphics always use OpenGL.
|
||||||
import sys
|
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
|
if 'linux' in sys.platform: ## linux has numerous bugs in opengl implementation
|
||||||
useOpenGL = False
|
useOpenGL = False
|
||||||
elif 'darwin' in sys.platform: ## openGL greatly speeds up display on mac
|
elif 'darwin' in sys.platform: ## openGL greatly speeds up display on mac
|
||||||
|
@ -24,10 +24,10 @@ w = fc.widget()
|
|||||||
w.resize(400,200)
|
w.resize(400,200)
|
||||||
w.show()
|
w.show()
|
||||||
|
|
||||||
n1 = fc.createNode('Add')
|
n1 = fc.createNode('Add', pos=(0,-80))
|
||||||
n2 = fc.createNode('Subtract')
|
n2 = fc.createNode('Subtract', pos=(140,-10))
|
||||||
n3 = fc.createNode('Abs')
|
n3 = fc.createNode('Abs', pos=(0, 80))
|
||||||
n4 = fc.createNode('Add')
|
n4 = fc.createNode('Add', pos=(140,100))
|
||||||
|
|
||||||
fc.connectTerminals(fc.dataIn, n1.A)
|
fc.connectTerminals(fc.dataIn, n1.A)
|
||||||
fc.connectTerminals(fc.dataIn, n1.B)
|
fc.connectTerminals(fc.dataIn, n1.B)
|
||||||
|
@ -67,5 +67,5 @@ class Ui_Form(object):
|
|||||||
self.reloadBtn.setText(QtGui.QApplication.translate("Form", "Reload Libs", None, QtGui.QApplication.UnicodeUTF8))
|
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))
|
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
|
from pyqtgraph.widgets.TreeWidget import TreeWidget
|
||||||
|
@ -112,7 +112,7 @@
|
|||||||
<customwidget>
|
<customwidget>
|
||||||
<class>FeedbackButton</class>
|
<class>FeedbackButton</class>
|
||||||
<extends>QPushButton</extends>
|
<extends>QPushButton</extends>
|
||||||
<header>FeedbackButton</header>
|
<header>pyqtgraph.widgets.FeedbackButton</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
160
widgets/FeedbackButton.py
Normal file
160
widgets/FeedbackButton.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user