Skip to content

Commit a16bef0

Browse files
committed
AndorAtmcd, AndorSDK3, PVCamera: let base Device to set _index
The base Device class already sets an '_index' property based on the 'index argument. This removes AndorAtmcd, AndorSDK3, and PVCamera re-setting of the value with a different default. Instead, set the different default on the function signature and pass it up the class hierarchy.
1 parent da14fdd commit a16bef0

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

microscope/cameras/andorsdk3.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,10 @@ def wrapper(self, *args, **kwargs):
101101
class AndorSDK3(devices.FloatingDeviceMixin,
102102
devices.CameraDevice):
103103
SDK_INITIALIZED = False
104-
def __init__(self, *args, **kwargs):
105-
super(AndorSDK3, self).__init__(**kwargs)
104+
def __init__(self, index=0, *args, **kwargs):
105+
super(AndorSDK3, self).__init__(index=index, **kwargs)
106106
if not AndorSDK3.SDK_INITIALIZED:
107107
SDK3.InitialiseLibrary()
108-
self._index = kwargs.get('index', 0)
109108
self.handle = None
110109
#self._sdk3cam = SDK3Camera(self._index)
111110
#SDK3Camera.__init__(self, self._index)

microscope/cameras/atmcd.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,11 +1140,9 @@ class AndorAtmcd(devices.FloatingDeviceMixin,
11401140
devices.CameraDevice):
11411141
""" Implements CameraDevice interface for Andor ATMCD library."""
11421142
def __init__(self, index=0, *args, **kwargs):
1143-
super().__init__(**kwargs)
1143+
super().__init__(index=0, **kwargs)
11441144
# Recursion depth for context manager behaviour.
11451145
self._rdepth = 0
1146-
# The camera index in the list maintained by the DLL.
1147-
self._index = index
11481146
# The handle used by the DLL to identify this camera.
11491147
self._handle = None
11501148
# The following parameters will be populated after hardware init.
@@ -1543,4 +1541,4 @@ def _set_roi(self, roi):
15431541
if any([left < 1, top < 1, left+width-1 > x, top+height-1 > y]):
15441542
return False
15451543
self._roi = ROI(left, top, width, height)
1546-
return True
1544+
return True

microscope/cameras/pvcam.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,8 @@ class PVCamera(devices.FloatingDeviceMixin, devices.CameraDevice):
11851185
open_cameras = []
11861186

11871187

1188-
def __init__(self, *args, **kwargs):
1189-
super(PVCamera, self).__init__(**kwargs)
1190-
# Camera index in DLL.
1191-
self._index = kwargs.get('index', 0)
1188+
def __init__(self, index=0, *args, **kwargs):
1189+
super(PVCamera, self).__init__(index=index, **kwargs)
11921190
# Camera name in DLL.
11931191
self._pv_name = None
11941192
# Camera handle.

microscope/devices.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,22 @@ def get_id(self):
186186

187187

188188
class Device(object):
189-
"""A base device class. All devices should subclass this class."""
189+
"""A base device class. All devices should subclass this class.
190+
191+
Args:
192+
index (int): the index of the device on a shared library.
193+
This argument is added by the deviceserver.
194+
"""
190195
__metaclass__ = abc.ABCMeta
191196

192-
def __init__(self, *args, **kwargs):
197+
def __init__(self, index=None, *args, **kwargs):
193198
self.enabled = None
194199
# A list of settings. (Can't serialize OrderedDict, so use {}.)
195200
self.settings = OrderedDict()
196201
# We fetch a logger here, but it can't log anything until
197202
# a handler is attached after we've identified this device.
198203
self._logger = logging.getLogger(self.__class__.__name__)
199-
self._index = kwargs['index'] if 'index' in kwargs else None
204+
self._index = index
200205

201206
def __del__(self):
202207
self.shutdown()

0 commit comments

Comments
 (0)