diff --git a/examples/ExampleApp.py b/examples/ExampleApp.py index cb57e3d0..1175f264 100644 --- a/examples/ExampleApp.py +++ b/examples/ExampleApp.py @@ -6,7 +6,7 @@ import subprocess from argparse import Namespace import pyqtgraph as pg from pyqtgraph.Qt import QtGui, QtCore, QT_LIB -from pyqtgraph.pgcollections import OrderedDict +from collections import OrderedDict from .utils import examples path = os.path.abspath(os.path.dirname(__file__)) diff --git a/pyqtgraph/configfile.py b/pyqtgraph/configfile.py index fbedde4b..a4ad9191 100644 --- a/pyqtgraph/configfile.py +++ b/pyqtgraph/configfile.py @@ -11,7 +11,7 @@ as it can be converted to/from a string using repr and eval. import re, os, sys, datetime import numpy -from .pgcollections import OrderedDict +from collections import OrderedDict from . import units from .python2_3 import asUnicode, basestring from .Qt import QtCore diff --git a/pyqtgraph/dockarea/tests/test_dockarea.py b/pyqtgraph/dockarea/tests/test_dockarea.py index 9575c298..a26646bc 100644 --- a/pyqtgraph/dockarea/tests/test_dockarea.py +++ b/pyqtgraph/dockarea/tests/test_dockarea.py @@ -2,7 +2,7 @@ import pytest import pyqtgraph as pg -from pyqtgraph.ordereddict import OrderedDict +from collections import OrderedDict pg.mkQApp() import pyqtgraph.dockarea as da diff --git a/pyqtgraph/flowchart/Flowchart.py b/pyqtgraph/flowchart/Flowchart.py index 49436e4e..29d6ede9 100644 --- a/pyqtgraph/flowchart/Flowchart.py +++ b/pyqtgraph/flowchart/Flowchart.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from ..Qt import QtCore, QtGui, QT_LIB from .Node import * -from ..pgcollections import OrderedDict +from collections import OrderedDict from ..widgets.TreeWidget import * from .. import FileDialog, DataTreeWidget diff --git a/pyqtgraph/flowchart/Node.py b/pyqtgraph/flowchart/Node.py index 000f0e90..d28f89a9 100644 --- a/pyqtgraph/flowchart/Node.py +++ b/pyqtgraph/flowchart/Node.py @@ -3,7 +3,7 @@ from ..Qt import QtCore, QtGui, QtWidgets from ..graphicsItems.GraphicsObject import GraphicsObject from .. import functions as fn from .Terminal import * -from ..pgcollections import OrderedDict +from collections import OrderedDict from ..debug import * import numpy as np import warnings diff --git a/pyqtgraph/flowchart/NodeLibrary.py b/pyqtgraph/flowchart/NodeLibrary.py index 8e04e97d..3484b2b9 100644 --- a/pyqtgraph/flowchart/NodeLibrary.py +++ b/pyqtgraph/flowchart/NodeLibrary.py @@ -1,4 +1,4 @@ -from ..pgcollections import OrderedDict +from collections import OrderedDict from .Node import Node def isNodeClass(cls): diff --git a/pyqtgraph/flowchart/library/__init__.py b/pyqtgraph/flowchart/library/__init__.py index d8038aa4..f7fa87ae 100644 --- a/pyqtgraph/flowchart/library/__init__.py +++ b/pyqtgraph/flowchart/library/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from ...pgcollections import OrderedDict +from collections import OrderedDict import os, types from ...debug import printExc from ..NodeLibrary import NodeLibrary, isNodeClass diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 836d96cf..d4e1ea96 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -21,7 +21,7 @@ from . import debug, reload from .Qt import QtGui, QtCore, QT_LIB, QtVersion from . import Qt from .metaarray import MetaArray -from .pgcollections import OrderedDict +from collections import OrderedDict from .python2_3 import asUnicode, basestring Colors = { diff --git a/pyqtgraph/graphicsItems/DateAxisItem.py b/pyqtgraph/graphicsItems/DateAxisItem.py index 39f03fa8..3f77cef2 100644 --- a/pyqtgraph/graphicsItems/DateAxisItem.py +++ b/pyqtgraph/graphicsItems/DateAxisItem.py @@ -4,7 +4,7 @@ import time from datetime import datetime, timedelta from .AxisItem import AxisItem -from ..pgcollections import OrderedDict +from collections import OrderedDict __all__ = ['DateAxisItem'] diff --git a/pyqtgraph/graphicsItems/GradientEditorItem.py b/pyqtgraph/graphicsItems/GradientEditorItem.py index d81a62c3..8c8e5171 100644 --- a/pyqtgraph/graphicsItems/GradientEditorItem.py +++ b/pyqtgraph/graphicsItems/GradientEditorItem.py @@ -7,7 +7,7 @@ from .. import functions as fn from .GraphicsObject import GraphicsObject from .GraphicsWidget import GraphicsWidget from ..widgets.SpinBox import SpinBox -from ..pgcollections import OrderedDict +from collections import OrderedDict from ..colormap import ColorMap translate = QtCore.QCoreApplication.translate diff --git a/pyqtgraph/graphicsItems/GraphicsItem.py b/pyqtgraph/graphicsItems/GraphicsItem.py index 578645b9..61f48a45 100644 --- a/pyqtgraph/graphicsItems/GraphicsItem.py +++ b/pyqtgraph/graphicsItems/GraphicsItem.py @@ -1,4 +1,5 @@ import warnings +from collections import OrderedDict from functools import reduce from ..Qt import QtGui, QtCore, isQObjectAlive from ..GraphicsScene import GraphicsScene @@ -6,7 +7,29 @@ from ..Point import Point from .. import functions as fn import weakref import operator -from ..util.lru_cache import LRUCache + + +# Recipe from https://docs.python.org/3.8/library/collections.html#collections.OrderedDict +# slightly adapted for Python 3.7 compatibility +class LRU(OrderedDict): + 'Limit size, evicting the least recently looked-up key when full' + + def __init__(self, maxsize=128, *args, **kwds): + self.maxsize = maxsize + super().__init__(*args, **kwds) + + def __getitem__(self, key): + value = super().__getitem__(key) + self.move_to_end(key) + return value + + def __setitem__(self, key, value): + if key in self: + self.move_to_end(key) + super().__setitem__(key, value) + if len(self) > self.maxsize: + oldest = next(iter(self)) + del self[oldest] class GraphicsItem(object): @@ -20,7 +43,7 @@ class GraphicsItem(object): The GraphicsView system places a lot of emphasis on the notion that the graphics within the scene should be device independent--you should be able to take the same graphics and display them on screens of different resolutions, printers, export to SVG, etc. This is nice in principle, but causes me a lot of headache in practice. It means that I have to circumvent all the device-independent expectations any time I want to operate in pixel coordinates rather than arbitrary scene coordinates. A lot of the code in GraphicsItem is devoted to this task--keeping track of view widgets and device transforms, computing the size and shape of a pixel in local item coordinates, etc. Note that in item coordinates, a pixel does not have to be square or even rectangular, so just asking how to increase a bounding rect by 2px can be a rather complex task. """ - _pixelVectorGlobalCache = LRUCache(100, 70) + _pixelVectorGlobalCache = LRU(100) def __init__(self, register=None): if not hasattr(self, '_qtBaseClass'): diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index f9257c99..3d0b9f15 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -14,7 +14,7 @@ from .. import functions as fn from .GraphicsItem import GraphicsItem from .GraphicsObject import GraphicsObject from .. import getConfigOption -from ..pgcollections import OrderedDict +from collections import OrderedDict from .. import debug from ..python2_3 import basestring diff --git a/pyqtgraph/ordereddict.py b/pyqtgraph/ordereddict.py index fb37037f..a562c8b8 100644 --- a/pyqtgraph/ordereddict.py +++ b/pyqtgraph/ordereddict.py @@ -20,6 +20,12 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. +import warnings +warnings.warn( + "OrderedDict is in the standard library for supported versions of Python. Will be removed in 0.13", + DeprecationWarning, stacklevel=2 +) + import sys if sys.version[0] > '2': from collections import OrderedDict diff --git a/pyqtgraph/parametertree/Parameter.py b/pyqtgraph/parametertree/Parameter.py index 6a41e1bb..ef4f0324 100644 --- a/pyqtgraph/parametertree/Parameter.py +++ b/pyqtgraph/parametertree/Parameter.py @@ -2,7 +2,7 @@ from .. import functions as fn from ..Qt import QtGui, QtCore import os, weakref, re -from ..pgcollections import OrderedDict +from collections import OrderedDict from ..python2_3 import asUnicode, basestring from .ParameterItem import ParameterItem import warnings diff --git a/pyqtgraph/parametertree/SystemSolver.py b/pyqtgraph/parametertree/SystemSolver.py index b1d4256a..cac42483 100644 --- a/pyqtgraph/parametertree/SystemSolver.py +++ b/pyqtgraph/parametertree/SystemSolver.py @@ -1,4 +1,4 @@ -from ..pgcollections import OrderedDict +from collections import OrderedDict import numpy as np import copy diff --git a/pyqtgraph/parametertree/parameterTypes.py b/pyqtgraph/parametertree/parameterTypes.py index 43747b9d..ee339824 100644 --- a/pyqtgraph/parametertree/parameterTypes.py +++ b/pyqtgraph/parametertree/parameterTypes.py @@ -8,7 +8,7 @@ from ..widgets.ColorButton import ColorButton from ..colormap import ColorMap from .. import icons as icons from .. import functions as fn -from ..pgcollections import OrderedDict +from collections import OrderedDict class WidgetParameterItem(ParameterItem): diff --git a/pyqtgraph/pgcollections.py b/pyqtgraph/pgcollections.py index 49ed4ed6..faadc063 100644 --- a/pyqtgraph/pgcollections.py +++ b/pyqtgraph/pgcollections.py @@ -10,15 +10,17 @@ Includes: - ThreadsafeDict, ThreadsafeList - Self-mutexed data structures """ +import warnings +warnings.warn( + "None of these are used in pyqtgraph. Will be removed in 0.13", + DeprecationWarning, stacklevel=2 +) + import threading import sys import copy -try: - from collections import OrderedDict -except ImportError: - # fallback: try to use the ordereddict backport when using python 2.6 - from ordereddict import OrderedDict +from collections import OrderedDict try: from collections.abc import Sequence diff --git a/pyqtgraph/util/lru_cache.py b/pyqtgraph/util/lru_cache.py index 5300e0ff..83ca01e0 100644 --- a/pyqtgraph/util/lru_cache.py +++ b/pyqtgraph/util/lru_cache.py @@ -1,3 +1,9 @@ +import warnings +warnings.warn( + "No longer used in pyqtgraph. Will be removed in 0.13", + DeprecationWarning, stacklevel=2 +) + import operator import sys import itertools diff --git a/pyqtgraph/util/pil_fix.py b/pyqtgraph/util/pil_fix.py index da1c52b3..6c0985e9 100644 --- a/pyqtgraph/util/pil_fix.py +++ b/pyqtgraph/util/pil_fix.py @@ -5,6 +5,12 @@ This works by patching objects in the PIL namespace; no files are modified. """ +import warnings +warnings.warn( + "Not used in pyqtgraph. Will be removed in 0.13", + DeprecationWarning, stacklevel=2 +) + from PIL import Image if Image.VERSION == '1.1.7': diff --git a/pyqtgraph/util/tests/test_lru_cache.py b/pyqtgraph/util/tests/test_lru_cache.py index 94451d97..f3a387ca 100644 --- a/pyqtgraph/util/tests/test_lru_cache.py +++ b/pyqtgraph/util/tests/test_lru_cache.py @@ -1,4 +1,9 @@ -from pyqtgraph.util.lru_cache import LRUCache +import warnings + +with warnings.catch_warnings(): + warnings.simplefilter('ignore') + from pyqtgraph.util.lru_cache import LRUCache + def testLRU(): lru = LRUCache(2, 1) diff --git a/pyqtgraph/widgets/ColorMapWidget.py b/pyqtgraph/widgets/ColorMapWidget.py index 76803e9d..5d1e5681 100644 --- a/pyqtgraph/widgets/ColorMapWidget.py +++ b/pyqtgraph/widgets/ColorMapWidget.py @@ -1,7 +1,7 @@ from ..Qt import QtGui, QtCore from .. import parametertree as ptree import numpy as np -from ..pgcollections import OrderedDict +from collections import OrderedDict from .. import functions as fn __all__ = ['ColorMapWidget'] diff --git a/pyqtgraph/widgets/ComboBox.py b/pyqtgraph/widgets/ComboBox.py index 632216ee..1e29431f 100644 --- a/pyqtgraph/widgets/ComboBox.py +++ b/pyqtgraph/widgets/ComboBox.py @@ -1,7 +1,7 @@ import sys from ..Qt import QtGui, QtCore from ..SignalProxy import SignalProxy -from ..pgcollections import OrderedDict +from collections import OrderedDict from ..python2_3 import asUnicode, basestring diff --git a/pyqtgraph/widgets/DataFilterWidget.py b/pyqtgraph/widgets/DataFilterWidget.py index 6421d71b..55af95ca 100644 --- a/pyqtgraph/widgets/DataFilterWidget.py +++ b/pyqtgraph/widgets/DataFilterWidget.py @@ -1,7 +1,7 @@ from ..Qt import QtGui, QtCore from .. import parametertree as ptree import numpy as np -from ..pgcollections import OrderedDict +from collections import OrderedDict from .. import functions as fn from ..python2_3 import basestring diff --git a/pyqtgraph/widgets/DataTreeWidget.py b/pyqtgraph/widgets/DataTreeWidget.py index ad9bf49a..27b979ac 100644 --- a/pyqtgraph/widgets/DataTreeWidget.py +++ b/pyqtgraph/widgets/DataTreeWidget.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from ..Qt import QtGui, QtCore -from ..pgcollections import OrderedDict +from collections import OrderedDict from .TableWidget import TableWidget from ..python2_3 import asUnicode import types, traceback diff --git a/pyqtgraph/widgets/DiffTreeWidget.py b/pyqtgraph/widgets/DiffTreeWidget.py index eac29489..53f575e6 100644 --- a/pyqtgraph/widgets/DiffTreeWidget.py +++ b/pyqtgraph/widgets/DiffTreeWidget.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from ..Qt import QtGui, QtCore -from ..pgcollections import OrderedDict +from collections import OrderedDict from .DataTreeWidget import DataTreeWidget from .. import functions as fn import types, traceback diff --git a/pyqtgraph/widgets/ScatterPlotWidget.py b/pyqtgraph/widgets/ScatterPlotWidget.py index 0f92d474..c81a7023 100644 --- a/pyqtgraph/widgets/ScatterPlotWidget.py +++ b/pyqtgraph/widgets/ScatterPlotWidget.py @@ -7,7 +7,7 @@ from .. import functions as fn from .. import getConfigOption from ..graphicsItems.TextItem import TextItem import numpy as np -from ..pgcollections import OrderedDict +from collections import OrderedDict __all__ = ['ScatterPlotWidget'] diff --git a/pyqtgraph/widgets/tests/test_tablewidget.py b/pyqtgraph/widgets/tests/test_tablewidget.py index 11416430..cb6de379 100644 --- a/pyqtgraph/widgets/tests/test_tablewidget.py +++ b/pyqtgraph/widgets/tests/test_tablewidget.py @@ -1,6 +1,6 @@ import pyqtgraph as pg import numpy as np -from pyqtgraph.pgcollections import OrderedDict +from collections import OrderedDict app = pg.mkQApp()