refactor: update detect method in camera classes to return dictionaries instead of lists
This commit is contained in:
@@ -24,20 +24,21 @@ class GPhotoCamera(BaseCamera):
|
||||
super().__init__()
|
||||
self.camera = None
|
||||
self.configs: List[dict] = []
|
||||
self.camera_list = []
|
||||
self.camera_index = 0
|
||||
|
||||
def detect(self) -> list:
|
||||
self.camera_list.clear()
|
||||
@staticmethod
|
||||
def detect() -> dict:
|
||||
cameras = gp.check_result(gp.gp_camera_autodetect()) # type: ignore
|
||||
# cameras = gp.Camera().autodetect()
|
||||
if not cameras or cameras.count() == 0: # type: ignore
|
||||
return []
|
||||
return {}
|
||||
|
||||
camera_list = {}
|
||||
for i in range(cameras.count()): # type: ignore
|
||||
name = cameras.get_name(i) # type: ignore
|
||||
port = cameras.get_value(i) # type: ignore
|
||||
self.camera_list.append({"name": name, "port": port})
|
||||
return self.camera_list
|
||||
camera_list[i] = {"name": name, "port": port}
|
||||
return camera_list
|
||||
|
||||
def connect(self, index: int | None = None) -> bool:
|
||||
self.error_msg = None
|
||||
@@ -45,10 +46,12 @@ class GPhotoCamera(BaseCamera):
|
||||
|
||||
try:
|
||||
if index:
|
||||
self.camera_index = index
|
||||
camera_list = GPhotoCamera.detect()
|
||||
port_info_list = gp.PortInfoList()
|
||||
port_info_list.load()
|
||||
|
||||
port_address = self.camera_list[index]["port"]
|
||||
port_address = camera_list[index]["port"]
|
||||
port_index = port_info_list.lookup_path(port_address)
|
||||
|
||||
self.camera.set_port_info(port_info_list[port_index])
|
||||
|
||||
Reference in New Issue
Block a user