From 0976991efda1825d8f92b2462ded613bcadef188 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Tue, 19 May 2015 09:29:55 -0400 Subject: [PATCH] Import from python2_3 for all uses of basestring, cmp, and xrange --- examples/__main__.py | 1 + examples/hdf5.py | 6 ++-- examples/multiplePlotSpeedTest.py | 4 +-- examples/parallelize.py | 4 ++- examples/relativity/relativity.py | 8 ++--- pyqtgraph/GraphicsScene/GraphicsScene.py | 5 +-- pyqtgraph/__init__.py | 2 +- pyqtgraph/colormap.py | 2 ++ pyqtgraph/configfile.py | 7 ++-- pyqtgraph/console/Console.py | 11 ++++--- pyqtgraph/debug.py | 2 -- pyqtgraph/dockarea/DockArea.py | 10 ++---- pyqtgraph/exporters/Exporter.py | 2 +- pyqtgraph/flowchart/Flowchart.py | 2 -- pyqtgraph/flowchart/library/Filters.py | 4 +-- pyqtgraph/flowchart/library/functions.py | 2 ++ pyqtgraph/functions.py | 2 +- pyqtgraph/graphicsItems/GradientEditorItem.py | 7 ++-- pyqtgraph/graphicsItems/PlotDataItem.py | 3 +- pyqtgraph/graphicsItems/PlotItem/PlotItem.py | 32 +++++++------------ pyqtgraph/graphicsItems/ScatterPlotItem.py | 15 ++++----- pyqtgraph/graphicsItems/ViewBox/ViewBox.py | 10 +++--- pyqtgraph/metaarray/MetaArray.py | 3 +- pyqtgraph/multiprocess/parallelizer.py | 2 ++ pyqtgraph/opengl/GLGraphicsItem.py | 6 ++-- pyqtgraph/opengl/MeshData.py | 4 ++- pyqtgraph/parametertree/Parameter.py | 2 +- pyqtgraph/pixmaps/__init__.py | 1 + pyqtgraph/python2_3.py | 18 +++++------ pyqtgraph/util/cprint.py | 1 + pyqtgraph/widgets/ComboBox.py | 5 +-- pyqtgraph/widgets/TableWidget.py | 32 ++++++++----------- pyqtgraph/widgets/TreeWidget.py | 6 +++- 33 files changed, 108 insertions(+), 113 deletions(-) diff --git a/examples/__main__.py b/examples/__main__.py index 192742f7..06f77f10 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -8,6 +8,7 @@ if __name__ == "__main__" and (__package__ is None or __package__==''): from . import initExample from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE, USE_PYQT5 +from pyqtgraph.python2_3 import basestring import pyqtgraph as pg if USE_PYSIDE: diff --git a/examples/hdf5.py b/examples/hdf5.py index b43ae24a..3cd5de29 100644 --- a/examples/hdf5.py +++ b/examples/hdf5.py @@ -14,11 +14,11 @@ to avoid re-reading the entire visible waveform at every update. import initExample ## Add path to library (just for examples; you do not need this) -import pyqtgraph as pg -from pyqtgraph.Qt import QtCore, QtGui +import sys, os import numpy as np import h5py -import sys, os +import pyqtgraph as pg +from pyqtgraph.Qt import QtCore, QtGui pg.mkQApp() diff --git a/examples/multiplePlotSpeedTest.py b/examples/multiplePlotSpeedTest.py index cea59a35..07df7522 100644 --- a/examples/multiplePlotSpeedTest.py +++ b/examples/multiplePlotSpeedTest.py @@ -23,8 +23,8 @@ def plot(): pts = 100 x = np.linspace(0, 0.8, pts) y = np.random.random(size=pts)*0.8 - for i in xrange(n): - for j in xrange(n): + for i in range(n): + for j in range(n): ## calling PlotWidget.plot() generates a PlotDataItem, which ## has a bit more overhead than PlotCurveItem, which is all ## we need here. This overhead adds up quickly and makes a big diff --git a/examples/parallelize.py b/examples/parallelize.py index 768d6f00..b309aa31 100644 --- a/examples/parallelize.py +++ b/examples/parallelize.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- import initExample ## Add path to library (just for examples; you do not need this) + +import time import numpy as np import pyqtgraph.multiprocess as mp import pyqtgraph as pg -import time +from pyqtgraph.python2_3 import xrange print( "\n=================\nParallelize") diff --git a/examples/relativity/relativity.py b/examples/relativity/relativity.py index 3037103e..e3f2c435 100644 --- a/examples/relativity/relativity.py +++ b/examples/relativity/relativity.py @@ -1,12 +1,12 @@ +import numpy as np +import collections +import sys, os import pyqtgraph as pg from pyqtgraph.Qt import QtGui, QtCore from pyqtgraph.parametertree import Parameter, ParameterTree from pyqtgraph.parametertree import types as pTypes import pyqtgraph.configfile -import numpy as np -import collections -import sys, os - +from pyqtgraph.python2_3 import xrange class RelativityGUI(QtGui.QWidget): diff --git a/pyqtgraph/GraphicsScene/GraphicsScene.py b/pyqtgraph/GraphicsScene/GraphicsScene.py index 6f5354dc..840e3135 100644 --- a/pyqtgraph/GraphicsScene/GraphicsScene.py +++ b/pyqtgraph/GraphicsScene/GraphicsScene.py @@ -1,12 +1,13 @@ -from ..Qt import QtCore, QtGui -from ..python2_3 import sortList import weakref +from ..Qt import QtCore, QtGui +from ..python2_3 import sortList, cmp from ..Point import Point from .. import functions as fn from .. import ptime as ptime from .mouseEvents import * from .. import debug as debug + if hasattr(QtCore, 'PYQT_VERSION'): try: import sip diff --git a/pyqtgraph/__init__.py b/pyqtgraph/__init__.py index 687208f8..2edf928e 100644 --- a/pyqtgraph/__init__.py +++ b/pyqtgraph/__init__.py @@ -346,7 +346,7 @@ def exit(): ## close file handles if sys.platform == 'darwin': - for fd in xrange(3, 4096): + for fd in range(3, 4096): if fd not in [7]: # trying to close 7 produces an illegal instruction on the Mac. os.close(fd) else: diff --git a/pyqtgraph/colormap.py b/pyqtgraph/colormap.py index c0033708..2a7ebb3b 100644 --- a/pyqtgraph/colormap.py +++ b/pyqtgraph/colormap.py @@ -1,5 +1,7 @@ import numpy as np from .Qt import QtGui, QtCore +from .python2_3 import basestring + class ColorMap(object): """ diff --git a/pyqtgraph/configfile.py b/pyqtgraph/configfile.py index c095bba3..7b20db1d 100644 --- a/pyqtgraph/configfile.py +++ b/pyqtgraph/configfile.py @@ -10,14 +10,15 @@ as it can be converted to/from a string using repr and eval. """ import re, os, sys +import numpy from .pgcollections import OrderedDict -GLOBAL_PATH = None # so not thread safe. from . import units -from .python2_3 import asUnicode +from .python2_3 import asUnicode, basestring from .Qt import QtCore from .Point import Point from .colormap import ColorMap -import numpy +GLOBAL_PATH = None # so not thread safe. + class ParseError(Exception): def __init__(self, message, lineNum, line, fileName=None): diff --git a/pyqtgraph/console/Console.py b/pyqtgraph/console/Console.py index 7b3f6d97..3ea1580f 100644 --- a/pyqtgraph/console/Console.py +++ b/pyqtgraph/console/Console.py @@ -1,16 +1,17 @@ +import sys, re, os, time, traceback, subprocess +import pickle from ..Qt import QtCore, QtGui, USE_PYSIDE, USE_PYQT5 -import sys, re, os, time, traceback, subprocess +from ..python2_3 import basestring +from .. import exceptionHandling as exceptionHandling +from .. import getConfigOption if USE_PYSIDE: from . import template_pyside as template elif USE_PYQT5: from . import template_pyqt5 as template else: from . import template_pyqt as template - -from .. import exceptionHandling as exceptionHandling -import pickle -from .. import getConfigOption + class ConsoleWidget(QtGui.QWidget): """ diff --git a/pyqtgraph/debug.py b/pyqtgraph/debug.py index 24c69aaa..43058619 100644 --- a/pyqtgraph/debug.py +++ b/pyqtgraph/debug.py @@ -723,7 +723,6 @@ class ObjTracker(object): for k in self.startCount: c1[k] = c1.get(k, 0) - self.startCount[k] typs = list(c1.keys()) - #typs.sort(lambda a,b: cmp(c1[a], c1[b])) typs.sort(key=lambda a: c1[a]) for t in typs: if c1[t] == 0: @@ -824,7 +823,6 @@ class ObjTracker(object): c = count.get(typ, [0,0]) count[typ] = [c[0]+1, c[1]+objectSize(obj)] typs = list(count.keys()) - #typs.sort(lambda a,b: cmp(count[a][1], count[b][1])) typs.sort(key=lambda a: count[a][1]) for t in typs: diff --git a/pyqtgraph/dockarea/DockArea.py b/pyqtgraph/dockarea/DockArea.py index aedee749..ffe75b61 100644 --- a/pyqtgraph/dockarea/DockArea.py +++ b/pyqtgraph/dockarea/DockArea.py @@ -1,17 +1,11 @@ # -*- coding: utf-8 -*- +import weakref from ..Qt import QtCore, QtGui from .Container import * from .DockDrop import * from .Dock import Dock from .. import debug as debug -import weakref - -## TODO: -# - containers should be drop areas, not docks. (but every slot within a container must have its own drop areas?) -# - drop between tabs -# - nest splitters inside tab boxes, etc. - - +from ..python2_3 import basestring class DockArea(Container, QtGui.QWidget, DockDrop): diff --git a/pyqtgraph/exporters/Exporter.py b/pyqtgraph/exporters/Exporter.py index 64a25294..792e36bd 100644 --- a/pyqtgraph/exporters/Exporter.py +++ b/pyqtgraph/exporters/Exporter.py @@ -1,6 +1,6 @@ from ..widgets.FileDialog import FileDialog from ..Qt import QtGui, QtCore, QtSvg -from ..python2_3 import asUnicode +from ..python2_3 import asUnicode, basestring from ..GraphicsScene import GraphicsScene import os, re LastExportDirectory = None diff --git a/pyqtgraph/flowchart/Flowchart.py b/pyqtgraph/flowchart/Flowchart.py index 94c2e175..17e2bde4 100644 --- a/pyqtgraph/flowchart/Flowchart.py +++ b/pyqtgraph/flowchart/Flowchart.py @@ -352,7 +352,6 @@ class Flowchart(Node): #tdeps[t] = lastNode if lastInd is not None: dels.append((lastInd+1, t)) - #dels.sort(lambda a,b: cmp(b[0], a[0])) dels.sort(key=lambda a: a[0], reverse=True) for i, t in dels: ops.insert(i, ('d', t)) @@ -467,7 +466,6 @@ class Flowchart(Node): self.clear() Node.restoreState(self, state) nodes = state['nodes'] - #nodes.sort(lambda a, b: cmp(a['pos'][0], b['pos'][0])) nodes.sort(key=lambda a: a['pos'][0]) for n in nodes: if n['name'] in self._nodes: diff --git a/pyqtgraph/flowchart/library/Filters.py b/pyqtgraph/flowchart/library/Filters.py index 88a2f6c5..876bf858 100644 --- a/pyqtgraph/flowchart/library/Filters.py +++ b/pyqtgraph/flowchart/library/Filters.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- +import numpy as np from ...Qt import QtCore, QtGui from ..Node import Node from . import functions from ... import functions as pgfn from .common import * -import numpy as np - +from ...python2_3 import xrange from ... import PolyLineROI from ... import Point from ... import metaarray as metaarray diff --git a/pyqtgraph/flowchart/library/functions.py b/pyqtgraph/flowchart/library/functions.py index 338d25c4..cb7fb41a 100644 --- a/pyqtgraph/flowchart/library/functions.py +++ b/pyqtgraph/flowchart/library/functions.py @@ -1,5 +1,7 @@ import numpy as np from ...metaarray import MetaArray +from ...python2_3 import basestring, xrange + def downsample(data, n, axis=0, xvals='subsample'): """Downsample by averaging points together across axis. diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index c22227d3..0fd66419 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -6,7 +6,7 @@ Distributed under MIT/X11 license. See license.txt for more infomation. """ from __future__ import division -from .python2_3 import asUnicode +from .python2_3 import asUnicode, basestring from .Qt import QtGui, QtCore, USE_PYSIDE Colors = { 'b': QtGui.QColor(0,0,255,255), diff --git a/pyqtgraph/graphicsItems/GradientEditorItem.py b/pyqtgraph/graphicsItems/GradientEditorItem.py index 0679321a..aa5a4428 100644 --- a/pyqtgraph/graphicsItems/GradientEditorItem.py +++ b/pyqtgraph/graphicsItems/GradientEditorItem.py @@ -1,14 +1,15 @@ +import weakref +import numpy as np from ..Qt import QtGui, QtCore from ..python2_3 import sortList from .. import functions as fn from .GraphicsObject import GraphicsObject from .GraphicsWidget import GraphicsWidget from ..widgets.SpinBox import SpinBox -import weakref from ..pgcollections import OrderedDict from ..colormap import ColorMap +from ..python2_3 import cmp -import numpy as np __all__ = ['TickSliderItem', 'GradientEditorItem'] @@ -26,8 +27,6 @@ Gradients = OrderedDict([ - - class TickSliderItem(GraphicsWidget): ## public class """**Bases:** :class:`GraphicsWidget ` diff --git a/pyqtgraph/graphicsItems/PlotDataItem.py b/pyqtgraph/graphicsItems/PlotDataItem.py index 520151a3..ce959a98 100644 --- a/pyqtgraph/graphicsItems/PlotDataItem.py +++ b/pyqtgraph/graphicsItems/PlotDataItem.py @@ -1,13 +1,14 @@ +import numpy as np from .. import metaarray as metaarray from ..Qt import QtCore from .GraphicsObject import GraphicsObject from .PlotCurveItem import PlotCurveItem from .ScatterPlotItem import ScatterPlotItem -import numpy as np from .. import functions as fn from .. import debug as debug from .. import getConfigOption + class PlotDataItem(GraphicsObject): """ **Bases:** :class:`GraphicsObject ` diff --git a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py index 6e9c8240..19ebe0c8 100644 --- a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py +++ b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py @@ -16,22 +16,14 @@ This class is very heavily featured: - Control panel with a huge feature set including averaging, decimation, display, power spectrum, svg/png export, plot linking, and more. """ -from ...Qt import QtGui, QtCore, QT_LIB -from ... import pixmaps import sys - -if QT_LIB == 'PyQt4': - from .plotConfigTemplate_pyqt import * -elif QT_LIB == 'PySide': - from .plotConfigTemplate_pyside import * -elif QT_LIB == 'PyQt5': - from .plotConfigTemplate_pyqt5 import * - -from ... import functions as fn -from ...widgets.FileDialog import FileDialog import weakref import numpy as np import os +from ...Qt import QtGui, QtCore, QT_LIB +from ... import pixmaps +from ... import functions as fn +from ...widgets.FileDialog import FileDialog from .. PlotDataItem import PlotDataItem from .. ViewBox import ViewBox from .. AxisItem import AxisItem @@ -41,6 +33,14 @@ from .. GraphicsWidget import GraphicsWidget from .. ButtonItem import ButtonItem from .. InfiniteLine import InfiniteLine from ...WidgetGroup import WidgetGroup +from ...python2_3 import basestring + +if QT_LIB == 'PyQt4': + from .plotConfigTemplate_pyqt import * +elif QT_LIB == 'PySide': + from .plotConfigTemplate_pyside import * +elif QT_LIB == 'PyQt5': + from .plotConfigTemplate_pyqt5 import * __all__ = ['PlotItem'] @@ -773,14 +773,6 @@ class PlotItem(GraphicsWidget): y = pos.y() * sy fh.write('\n' % (x, y, color, opacity)) - #fh.write('') - - ## get list of curves, scatter plots - fh.write("\n") diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index 649449cd..e6be9acd 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -1,8 +1,3 @@ -from ..Qt import QtGui, QtCore, USE_PYSIDE, USE_PYQT5 -from ..Point import Point -from .. import functions as fn -from .GraphicsItem import GraphicsItem -from .GraphicsObject import GraphicsObject from itertools import starmap, repeat try: from itertools import imap @@ -10,10 +5,15 @@ except ImportError: imap = map import numpy as np import weakref +from ..Qt import QtGui, QtCore, USE_PYSIDE, USE_PYQT5 +from ..Point import Point +from .. import functions as fn +from .GraphicsItem import GraphicsItem +from .GraphicsObject import GraphicsObject from .. import getConfigOption -from .. import debug as debug from ..pgcollections import OrderedDict from .. import debug +from ..python2_3 import basestring __all__ = ['ScatterPlotItem', 'SpotItem'] @@ -455,8 +455,6 @@ class ScatterPlotItem(GraphicsObject): brushes = brushes[kargs['mask']] if len(brushes) != len(dataSet): raise Exception("Number of brushes does not match number of points (%d != %d)" % (len(brushes), len(dataSet))) - #for i in xrange(len(brushes)): - #self.data[i]['brush'] = fn.mkBrush(brushes[i], **kargs) dataSet['brush'] = brushes else: self.opts['brush'] = fn.mkBrush(*args, **kargs) @@ -815,7 +813,6 @@ class ScatterPlotItem(GraphicsObject): #else: #print "No hit:", (x, y), (sx, sy) #print " ", (sx-s2x, sy-s2y), (sx+s2x, sy+s2y) - #pts.sort(lambda a,b: cmp(b.zValue(), a.zValue())) return pts[::-1] diff --git a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py index 900c2038..768bbdcf 100644 --- a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py +++ b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py @@ -1,15 +1,15 @@ -from ...Qt import QtGui, QtCore -from ...python2_3 import sortList +import weakref +import sys +from copy import deepcopy import numpy as np +from ...Qt import QtGui, QtCore +from ...python2_3 import sortList, basestring, cmp from ...Point import Point from ... import functions as fn from .. ItemGroup import ItemGroup from .. GraphicsWidget import GraphicsWidget -import weakref -from copy import deepcopy from ... import debug as debug from ... import getConfigOption -import sys from ...Qt import isQObjectAlive __all__ = ['ViewBox'] diff --git a/pyqtgraph/metaarray/MetaArray.py b/pyqtgraph/metaarray/MetaArray.py index 9c3f5b8a..37b51188 100644 --- a/pyqtgraph/metaarray/MetaArray.py +++ b/pyqtgraph/metaarray/MetaArray.py @@ -10,10 +10,11 @@ new methods for slicing and indexing the array based on this meta data. More info at http://www.scipy.org/Cookbook/MetaArray """ -import numpy as np import types, copy, threading, os, re import pickle from functools import reduce +import numpy as np +from ..python2_3 import basestring #import traceback ## By default, the library will use HDF5 when writing files. diff --git a/pyqtgraph/multiprocess/parallelizer.py b/pyqtgraph/multiprocess/parallelizer.py index f4ddd95c..934bc6d0 100644 --- a/pyqtgraph/multiprocess/parallelizer.py +++ b/pyqtgraph/multiprocess/parallelizer.py @@ -1,6 +1,8 @@ import os, sys, time, multiprocessing, re from .processes import ForkedProcess from .remoteproxy import ClosedError +from ..python2_3 import basestring, xrange + class CanceledError(Exception): """Raised when the progress dialog is canceled during a processing operation.""" diff --git a/pyqtgraph/opengl/GLGraphicsItem.py b/pyqtgraph/opengl/GLGraphicsItem.py index 12c5b707..a2c2708a 100644 --- a/pyqtgraph/opengl/GLGraphicsItem.py +++ b/pyqtgraph/opengl/GLGraphicsItem.py @@ -1,7 +1,9 @@ -from ..Qt import QtGui, QtCore -from .. import Transform3D from OpenGL.GL import * from OpenGL import GL +from ..Qt import QtGui, QtCore +from .. import Transform3D +from ..python2_3 import basestring + GLOptions = { 'opaque': { diff --git a/pyqtgraph/opengl/MeshData.py b/pyqtgraph/opengl/MeshData.py index 5adf4b64..f83fcdf6 100644 --- a/pyqtgraph/opengl/MeshData.py +++ b/pyqtgraph/opengl/MeshData.py @@ -1,6 +1,8 @@ +import numpy as np from ..Qt import QtGui from .. import functions as fn -import numpy as np +from ..python2_3 import xrange + class MeshData(object): """ diff --git a/pyqtgraph/parametertree/Parameter.py b/pyqtgraph/parametertree/Parameter.py index 5f37ccdc..99e644b0 100644 --- a/pyqtgraph/parametertree/Parameter.py +++ b/pyqtgraph/parametertree/Parameter.py @@ -1,7 +1,7 @@ from ..Qt import QtGui, QtCore import os, weakref, re from ..pgcollections import OrderedDict -from ..python2_3 import asUnicode +from ..python2_3 import asUnicode, basestring from .ParameterItem import ParameterItem PARAM_TYPES = {} diff --git a/pyqtgraph/pixmaps/__init__.py b/pyqtgraph/pixmaps/__init__.py index c26e4a6b..7a3411cc 100644 --- a/pyqtgraph/pixmaps/__init__.py +++ b/pyqtgraph/pixmaps/__init__.py @@ -6,6 +6,7 @@ Provides support for frozen environments as well. import os, sys, pickle from ..functions import makeQImage from ..Qt import QtGui +from ..python2_3 import basestring if sys.version_info[0] == 2: from . import pixmapData_2 as pixmapData else: diff --git a/pyqtgraph/python2_3.py b/pyqtgraph/python2_3.py index b1c46f26..ae4667eb 100644 --- a/pyqtgraph/python2_3.py +++ b/pyqtgraph/python2_3.py @@ -40,10 +40,6 @@ def sortList(l, cmpFunc): l.sort(key=cmpToKey(cmpFunc)) if sys.version_info[0] == 3: - import builtins - builtins.basestring = str - #builtins.asUnicode = asUnicode - #builtins.sortList = sortList basestring = str def cmp(a,b): if a>b: @@ -52,9 +48,11 @@ if sys.version_info[0] == 3: return -1 else: return 0 - builtins.cmp = cmp - builtins.xrange = range -#else: ## don't use __builtin__ -- this confuses things like pyshell and ActiveState's lazy import recipe - #import __builtin__ - #__builtin__.asUnicode = asUnicode - #__builtin__.sortList = sortList + xrange = range +else: + import __builtin__ + basestring = __builtin__.basestring + cmp = __builtin__.cmp + xrange = __builtin__.xrange + + \ No newline at end of file diff --git a/pyqtgraph/util/cprint.py b/pyqtgraph/util/cprint.py index e88bfd1a..8b4fa208 100644 --- a/pyqtgraph/util/cprint.py +++ b/pyqtgraph/util/cprint.py @@ -7,6 +7,7 @@ import sys, re from .colorama.winterm import WinTerm, WinColor, WinStyle from .colorama.win32 import windll +from ..python2_3 import basestring _WIN = sys.platform.startswith('win') if windll is not None: diff --git a/pyqtgraph/widgets/ComboBox.py b/pyqtgraph/widgets/ComboBox.py index 5cf6f918..a6828959 100644 --- a/pyqtgraph/widgets/ComboBox.py +++ b/pyqtgraph/widgets/ComboBox.py @@ -1,8 +1,9 @@ +import sys from ..Qt import QtGui, QtCore from ..SignalProxy import SignalProxy -import sys from ..pgcollections import OrderedDict -from ..python2_3 import asUnicode +from ..python2_3 import asUnicode, basestring + class ComboBox(QtGui.QComboBox): """Extends QComboBox to add extra functionality. diff --git a/pyqtgraph/widgets/TableWidget.py b/pyqtgraph/widgets/TableWidget.py index 69085a20..9b9dcc49 100644 --- a/pyqtgraph/widgets/TableWidget.py +++ b/pyqtgraph/widgets/TableWidget.py @@ -1,13 +1,8 @@ # -*- coding: utf-8 -*- -from ..Qt import QtGui, QtCore -from ..python2_3 import asUnicode - import numpy as np -try: - import metaarray - HAVE_METAARRAY = True -except ImportError: - HAVE_METAARRAY = False +from ..Qt import QtGui, QtCore +from ..python2_3 import asUnicode, basestring +from .. import metaarray __all__ = ['TableWidget'] @@ -207,7 +202,7 @@ class TableWidget(QtGui.QTableWidget): return lambda d: d.__iter__(), None elif isinstance(data, dict): return lambda d: iter(d.values()), list(map(asUnicode, data.keys())) - elif HAVE_METAARRAY and (hasattr(data, 'implements') and data.implements('MetaArray')): + elif (hasattr(data, 'implements') and data.implements('MetaArray')): if data.axisHasColumns(0): header = [asUnicode(data.columnName(0, i)) for i in range(data.shape[0])] elif data.axisHasValues(0): @@ -491,14 +486,13 @@ if __name__ == '__main__': t.setData(ll) - if HAVE_METAARRAY: - ma = metaarray.MetaArray(np.ones((20, 3)), info=[ - {'values': np.linspace(1, 5, 20)}, - {'cols': [ - {'name': 'x'}, - {'name': 'y'}, - {'name': 'z'}, - ]} - ]) - t.setData(ma) + ma = metaarray.MetaArray(np.ones((20, 3)), info=[ + {'values': np.linspace(1, 5, 20)}, + {'cols': [ + {'name': 'x'}, + {'name': 'y'}, + {'name': 'z'}, + ]} + ]) + t.setData(ma) diff --git a/pyqtgraph/widgets/TreeWidget.py b/pyqtgraph/widgets/TreeWidget.py index ec2c35cf..b98da6fa 100644 --- a/pyqtgraph/widgets/TreeWidget.py +++ b/pyqtgraph/widgets/TreeWidget.py @@ -1,8 +1,12 @@ # -*- coding: utf-8 -*- -from ..Qt import QtGui, QtCore from weakref import * +from ..Qt import QtGui, QtCore +from ..python2_3 import xrange + __all__ = ['TreeWidget', 'TreeWidgetItem'] + + class TreeWidget(QtGui.QTreeWidget): """Extends QTreeWidget to allow internal drag/drop with widgets in the tree. Also maintains the expanded state of subtrees as they are moved.