From e0e1123d338984b98c7a18b769b4fd26adc7b031 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Mon, 29 Apr 2013 08:13:28 -0400 Subject: [PATCH 1/3] fixed import statements python3 compatibility PolyLineROI.getArrayRegion correctly applies mask to N-dimensional data fixed multiprocess for python2.6 compatibility --- examples/__init__.py | 2 +- examples/__main__.py | 12 +++++++++--- pyqtgraph/__init__.py | 3 ++- pyqtgraph/graphicsItems/ROI.py | 2 +- pyqtgraph/multiprocess/parallelizer.py | 2 +- pyqtgraph/multiprocess/remoteproxy.py | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 23b7cd58..76a71e14 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -1 +1 @@ -from __main__ import run +from .__main__ import run diff --git a/examples/__main__.py b/examples/__main__.py index c46d7065..e7b89716 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -1,12 +1,18 @@ import sys, os, subprocess, time -import initExample +try: + from . import initExample +except ValueError: + sys.excepthook(*sys.exc_info()) + print("examples/ can not be executed as a script; please run 'python -m examples' instead.") + sys.exit(1) + from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE if USE_PYSIDE: - from exampleLoaderTemplate_pyside import Ui_Form + from .exampleLoaderTemplate_pyside import Ui_Form else: - from exampleLoaderTemplate_pyqt import Ui_Form + from .exampleLoaderTemplate_pyqt import Ui_Form import os, sys from pyqtgraph.pgcollections import OrderedDict diff --git a/pyqtgraph/__init__.py b/pyqtgraph/__init__.py index 67eb712e..d83e0ec0 100644 --- a/pyqtgraph/__init__.py +++ b/pyqtgraph/__init__.py @@ -154,7 +154,8 @@ def importModules(path, globals, locals, excludes=()): try: if len(path) > 0: modName = path + '.' + modName - mod = __import__(modName, globals, locals, fromlist=['*']) + #mod = __import__(modName, globals, locals, fromlist=['*']) + mod = __import__(modName, globals, locals, ['*'], 1) mods[modName] = mod except: import traceback diff --git a/pyqtgraph/graphicsItems/ROI.py b/pyqtgraph/graphicsItems/ROI.py index 9cdc8c29..97669fe0 100644 --- a/pyqtgraph/graphicsItems/ROI.py +++ b/pyqtgraph/graphicsItems/ROI.py @@ -1771,7 +1771,7 @@ class PolyLineROI(ROI): shape = [1] * data.ndim shape[axes[0]] = sliced.shape[axes[0]] shape[axes[1]] = sliced.shape[axes[1]] - return sliced * mask + return sliced * mask.reshape(shape) class LineSegmentROI(ROI): diff --git a/pyqtgraph/multiprocess/parallelizer.py b/pyqtgraph/multiprocess/parallelizer.py index 9925a573..e96692e2 100644 --- a/pyqtgraph/multiprocess/parallelizer.py +++ b/pyqtgraph/multiprocess/parallelizer.py @@ -129,7 +129,7 @@ class Parallelize(object): self.childs.append(proc) ## Keep track of the progress of each worker independently. - self.progress = {ch.childPid: [] for ch in self.childs} + self.progress = dict([(ch.childPid, []) for ch in self.childs]) ## for each child process, self.progress[pid] is a list ## of task indexes. The last index is the task currently being ## processed; all others are finished. diff --git a/pyqtgraph/multiprocess/remoteproxy.py b/pyqtgraph/multiprocess/remoteproxy.py index 6cd65f6e..974e1e95 100644 --- a/pyqtgraph/multiprocess/remoteproxy.py +++ b/pyqtgraph/multiprocess/remoteproxy.py @@ -803,7 +803,7 @@ class ObjectProxy(object): return val def _getProxyOptions(self): - return {k: self._getProxyOption(k) for k in self._proxyOptions} + return dict([(k, self._getProxyOption(k)) for k in self._proxyOptions]) def __reduce__(self): return (unpickleObjectProxy, (self._processId, self._proxyId, self._typeStr, self._attributes)) From 00e865f56c008d33e831c24b6417d971c56c6559 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sun, 5 May 2013 10:54:47 -0400 Subject: [PATCH 2/3] minor fix in AxisItem --- pyqtgraph/graphicsItems/AxisItem.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyqtgraph/graphicsItems/AxisItem.py b/pyqtgraph/graphicsItems/AxisItem.py index e31030df..d8c49390 100644 --- a/pyqtgraph/graphicsItems/AxisItem.py +++ b/pyqtgraph/graphicsItems/AxisItem.py @@ -731,6 +731,7 @@ class AxisItem(GraphicsWidget): textRects = [] textSpecs = [] ## list of draw + textSize2 = 0 for i in range(len(tickLevels)): ## Get the list of strings to display for this level if tickStrings is None: From 671e624f177f12f43da0971098b53c7f48bb6592 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Thu, 9 May 2013 23:02:14 -0400 Subject: [PATCH 3/3] Fixes: AxisItem correctly handles scaling with values that are not power of 10 Can remove items from legend updated plotItem setLogMode to allow unspecified axes --- examples/__main__.py | 1 + pyqtgraph/graphicsItems/AxisItem.py | 20 +++++++++++-- pyqtgraph/graphicsItems/LegendItem.py | 30 ++++++++++++++++++++ pyqtgraph/graphicsItems/PlotItem/PlotItem.py | 12 ++++---- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/examples/__main__.py b/examples/__main__.py index e7b89716..2ecc810d 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -3,6 +3,7 @@ import sys, os, subprocess, time try: from . import initExample except ValueError: + #__package__ = os.path.split(os.path.dirname(__file__))[-1] sys.excepthook(*sys.exc_info()) print("examples/ can not be executed as a script; please run 'python -m examples' instead.") sys.exit(1) diff --git a/pyqtgraph/graphicsItems/AxisItem.py b/pyqtgraph/graphicsItems/AxisItem.py index d8c49390..846f48ac 100644 --- a/pyqtgraph/graphicsItems/AxisItem.py +++ b/pyqtgraph/graphicsItems/AxisItem.py @@ -281,7 +281,7 @@ class AxisItem(GraphicsWidget): def setScale(self, scale=None): """ Set the value scaling for this axis. Values on the axis are multiplied - by this scale factor before being displayed as text. By default, + by this scale factor before being displayed as text. By default (scale=None), this scaling value is automatically determined based on the visible range and the axis units are updated to reflect the chosen scale factor. @@ -301,6 +301,7 @@ class AxisItem(GraphicsWidget): self.setLabel(unitPrefix=prefix) else: scale = 1.0 + self.autoScale = True else: self.setLabel(unitPrefix='') self.autoScale = False @@ -499,6 +500,10 @@ class AxisItem(GraphicsWidget): """ minVal, maxVal = sorted((minVal, maxVal)) + + minVal *= self.scale + maxVal *= self.scale + #size *= self.scale ticks = [] tickLevels = self.tickSpacing(minVal, maxVal, size) @@ -511,16 +516,25 @@ class AxisItem(GraphicsWidget): ## determine number of ticks num = int((maxVal-start) / spacing) + 1 - values = np.arange(num) * spacing + start + values = (np.arange(num) * spacing + start) / self.scale ## remove any ticks that were present in higher levels ## we assume here that if the difference between a tick value and a previously seen tick value ## is less than spacing/100, then they are 'equal' and we can ignore the new tick. values = list(filter(lambda x: all(np.abs(allValues-x) > spacing*0.01), values) ) allValues = np.concatenate([allValues, values]) - ticks.append((spacing, values)) + ticks.append((spacing/self.scale, values)) if self.logMode: return self.logTickValues(minVal, maxVal, size, ticks) + + + #nticks = [] + #for t in ticks: + #nvals = [] + #for v in t[1]: + #nvals.append(v/self.scale) + #nticks.append((t[0]/self.scale,nvals)) + #ticks = nticks return ticks diff --git a/pyqtgraph/graphicsItems/LegendItem.py b/pyqtgraph/graphicsItems/LegendItem.py index c41feb95..3f4d5fa1 100644 --- a/pyqtgraph/graphicsItems/LegendItem.py +++ b/pyqtgraph/graphicsItems/LegendItem.py @@ -73,6 +73,36 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor): self.layout.addItem(sample, row, 0) self.layout.addItem(label, row, 1) self.updateSize() + + # + # + # Ulrich + def removeItem(self, name): + """ + Removes one item from the legend. + + =========== ======================================================== + Arguments + title The title displayed for this item. + =========== ======================================================== + """ + # cycle for a match + for sample, label in self.items: + print label.text, name + if label.text == name: # hit + self.items.remove( (sample, label) ) # remove from itemlist + self.layout.removeItem(sample) # remove from layout + sample.close() # remove from drawing + self.layout.removeItem(label) + label.close() + self.updateSize() # redraq box + + # hcirlU + # + # + + + def updateSize(self): if self.size is not None: diff --git a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py index c226b9c4..52a1429b 100644 --- a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py +++ b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py @@ -295,19 +295,21 @@ class PlotItem(GraphicsWidget): - def setLogMode(self, x, y): + def setLogMode(self, x=None, y=None): """ - Set log scaling for x and y axes. + Set log scaling for x and/or y axes. This informs PlotDataItems to transform logarithmically and switches the axes to use log ticking. Note that *no other items* in the scene will be affected by - this; there is no generic way to redisplay a GraphicsItem + this; there is (currently) no generic way to redisplay a GraphicsItem with log coordinates. """ - self.ctrl.logXCheck.setChecked(x) - self.ctrl.logYCheck.setChecked(y) + if x is not None: + self.ctrl.logXCheck.setChecked(x) + if y is not None: + self.ctrl.logYCheck.setChecked(y) def showGrid(self, x=None, y=None, alpha=None): """