From af5a5d3eb362ed31ca15e5b75bef212fa14aa297 Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Sat, 10 Nov 2012 11:22:56 -0500 Subject: [PATCH 1/3] Start of work on DateAxis --- examples/customPlot.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/customPlot.py b/examples/customPlot.py index 451ae501..187da5e9 100644 --- a/examples/customPlot.py +++ b/examples/customPlot.py @@ -15,9 +15,18 @@ import time class DateAxis(pg.AxisItem): def tickStrings(self, values, scale, spacing): strns = [] + rng = max(values)-min(values) + if rng < 120: + return pg.AxisItem.tickStrings(self, values, scale, spacing) + elif rng >= 120 and rng < 3600*24: + string = '%H:%M:%S' + elif rng >= 3600*24 and rng < 3600*24*30: + string = '%d' + elif rng >= 3600*24*30: + string = '%b %Y' for x in values: try: - strns.append(time.strftime('%b %Y', time.localtime(x))) + strns.append(time.strftime(string, time.localtime(x))) except ValueError: ## Windows can't handle dates before 1970 strns.append('') return strns From dde6a2ac4cce68ec42f0ccb04f0e27573fcc3696 Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Tue, 27 Nov 2012 14:54:49 -0500 Subject: [PATCH 2/3] work on DateAxisItem --- examples/customPlot.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/examples/customPlot.py b/examples/customPlot.py index 187da5e9..e86fc1e5 100644 --- a/examples/customPlot.py +++ b/examples/customPlot.py @@ -16,19 +16,34 @@ class DateAxis(pg.AxisItem): def tickStrings(self, values, scale, spacing): strns = [] rng = max(values)-min(values) - if rng < 120: - return pg.AxisItem.tickStrings(self, values, scale, spacing) - elif rng >= 120 and rng < 3600*24: + #if rng < 120: + # return pg.AxisItem.tickStrings(self, values, scale, spacing) + if rng < 3600*24: string = '%H:%M:%S' + label1 = '%b %d -' + label2 = ' %b %d, %Y' elif rng >= 3600*24 and rng < 3600*24*30: string = '%d' - elif rng >= 3600*24*30: - string = '%b %Y' + label1 = '%b - ' + label2 = '%b, %Y' + elif rng >= 3600*24*30 and rng < 3600*24*30*24: + string = '%b' + label1 = '%Y -' + label2 = ' %Y' + elif rng >=3600*24*30*24: + string = '%Y' + label1 = '' + label2 = '' for x in values: try: strns.append(time.strftime(string, time.localtime(x))) except ValueError: ## Windows can't handle dates before 1970 strns.append('') + try: + label = time.strftime(label1, time.localtime(min(values)))+time.strftime(label2, time.localtime(max(values))) + except ValueError: + label = '' + #self.setLabel(text=label) return strns class CustomViewBox(pg.ViewBox): From c8123fefaac0fdbdeb5128c0e6893e080594ae93 Mon Sep 17 00:00:00 2001 From: Megan Kratz Date: Thu, 29 Nov 2012 16:50:42 -0500 Subject: [PATCH 3/3] added primitive test capability to run through all examples - works but needs to be refined to make it better -- to run the tests simply run "python pyqtgraph/examples --test" --- examples/__main__.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/examples/__main__.py b/examples/__main__.py index 9bd96d8a..894b178e 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -1,4 +1,4 @@ -import sys, os +import sys, os, subprocess, time ## make sure this pyqtgraph is importable before any others sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE @@ -151,5 +151,38 @@ def run(): app.exec_() +def buildFileList(examples, files=None): + if files == None: + files = [] + for key, val in examples.items(): + #item = QtGui.QTreeWidgetItem([key]) + if isinstance(val, basestring): + #item.file = val + files.append((key,val)) + else: + buildFileList(val, files) + return files + +def testFile(name, f): + global path + fn = os.path.join(path,f) + #print "starting process: ", fn + process = subprocess.Popen([sys.executable, fn], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + time.sleep(1) + process.terminate() + res = process.communicate() + if res[1] == '': + print "%s....................... passed" % name + else: + print "%s....................... FAILED" % name + print res + + + if __name__ == '__main__': - run() + if '--test' in sys.argv[1:]: + files = buildFileList(examples) + for f in files: + testFile(*f) + else: + run()