Try to import from collections.abc for Python 3.3+ (#887)
* Try to import from collections.abc for Python 3.3+
This commit is contained in:
parent
957aab008c
commit
deab37d533
@ -2,13 +2,17 @@ from __future__ import division
|
||||
|
||||
from ..Qt import QtGui, QtCore
|
||||
import numpy as np
|
||||
import collections
|
||||
from .. import functions as fn
|
||||
from .. import debug as debug
|
||||
from .GraphicsObject import GraphicsObject
|
||||
from ..Point import Point
|
||||
from .. import getConfigOption
|
||||
|
||||
try:
|
||||
from collections.abc import Callable
|
||||
except ImportError:
|
||||
# fallback for python < 3.3
|
||||
from collections import Callable
|
||||
|
||||
__all__ = ['ImageItem']
|
||||
|
||||
@ -357,7 +361,7 @@ class ImageItem(GraphicsObject):
|
||||
|
||||
# Request a lookup table if this image has only one channel
|
||||
if self.image.ndim == 2 or self.image.shape[2] == 1:
|
||||
if isinstance(self.lut, collections.Callable):
|
||||
if isinstance(self.lut, Callable):
|
||||
lut = self.lut(self.image)
|
||||
else:
|
||||
lut = self.lut
|
||||
@ -624,7 +628,7 @@ class ImageItem(GraphicsObject):
|
||||
mask = self.drawMask
|
||||
src = dk
|
||||
|
||||
if isinstance(self.drawMode, collections.Callable):
|
||||
if isinstance(self.drawMode, Callable):
|
||||
self.drawMode(dk, self.image, mask, ss, ts, ev)
|
||||
else:
|
||||
src = src[ss]
|
||||
|
@ -10,15 +10,22 @@ Includes:
|
||||
- ThreadsafeDict, ThreadsafeList - Self-mutexed data structures
|
||||
"""
|
||||
|
||||
import threading, sys, copy, collections
|
||||
#from debug import *
|
||||
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
|
||||
|
||||
|
||||
try:
|
||||
from collections.abc import Sequence
|
||||
except ImportError:
|
||||
# fallback for python < 3.3
|
||||
from collections import Sequence
|
||||
|
||||
|
||||
class ReverseDict(dict):
|
||||
"""extends dict so that reverse lookups are possible by requesting the key as a list of length 1:
|
||||
@ -326,7 +333,7 @@ class ProtectedDict(dict):
|
||||
|
||||
|
||||
|
||||
class ProtectedList(collections.Sequence):
|
||||
class ProtectedList(Sequence):
|
||||
"""
|
||||
A class allowing read-only 'view' of a list or dict.
|
||||
The object can be treated like a normal list, but will never modify the original list it points to.
|
||||
@ -408,7 +415,7 @@ class ProtectedList(collections.Sequence):
|
||||
raise Exception("This is a list. It does not poop.")
|
||||
|
||||
|
||||
class ProtectedTuple(collections.Sequence):
|
||||
class ProtectedTuple(Sequence):
|
||||
"""
|
||||
A class allowing read-only 'view' of a tuple.
|
||||
The object can be treated like a normal tuple, but its contents will be returned as protected objects.
|
||||
|
Loading…
Reference in New Issue
Block a user