refactor gphoto_camera
This commit is contained in:
@@ -25,7 +25,7 @@ class CameraWidget:
|
|||||||
name: str
|
name: str
|
||||||
label: str
|
label: str
|
||||||
type: str
|
type: str
|
||||||
widget: object
|
config: object
|
||||||
value: Optional[str] = None
|
value: Optional[str] = None
|
||||||
choices: List[str] = field(default_factory=list)
|
choices: List[str] = field(default_factory=list)
|
||||||
|
|
||||||
@@ -44,9 +44,15 @@ class GPhotoCamera(BaseCamera):
|
|||||||
try:
|
try:
|
||||||
self.camera = gp.Camera() # type: ignore
|
self.camera = gp.Camera() # type: ignore
|
||||||
self.camera.init()
|
self.camera.init()
|
||||||
self.read_config()
|
config = self.camera.get_config()
|
||||||
|
self.read_config(config)
|
||||||
|
for widget in self.widgets:
|
||||||
|
print(widget)
|
||||||
widget = self.get_setting_by_name("iso")
|
widget = self.get_setting_by_name("iso")
|
||||||
|
self.set_setting_by_id(widget.id, "400")
|
||||||
self.set_setting_by_id(widget.id, "100")
|
self.set_setting_by_id(widget.id, "100")
|
||||||
|
self.set_setting_by_id(widget.id, "1600")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.error_msg = f"[GPHOTO2] {e}"
|
self.error_msg = f"[GPHOTO2] {e}"
|
||||||
@@ -83,44 +89,55 @@ class GPhotoCamera(BaseCamera):
|
|||||||
def get_setting_by_name(self, name: str) -> CameraWidget:
|
def get_setting_by_name(self, name: str) -> CameraWidget:
|
||||||
return next(w for w in self.widgets if w.name == name)
|
return next(w for w in self.widgets if w.name == name)
|
||||||
|
|
||||||
def set_setting_by_id(self, id: int, value: str):
|
def set_setting(self, widget:CameraWidget, value):
|
||||||
widget = self.get_setting_by_id(id)
|
if value not in widget.choices:
|
||||||
if value in widget.choices:
|
|
||||||
widget.widget.set_value(value) # type: ignore
|
|
||||||
self.camera.set_single_config(widget.name, widget.widget) # type: ignore
|
|
||||||
|
|
||||||
def read_config(self):
|
|
||||||
if not self.camera:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self.widgets.clear()
|
widget.config.set_value(value) # type: ignore
|
||||||
|
self.camera.set_single_config(widget.name, widget.config) # type: ignore
|
||||||
|
widget.value = value
|
||||||
|
new_config = self.camera.get_single_config(widget.name)
|
||||||
|
print(f"old: {widget}")
|
||||||
|
print(f"new: {new_config}")
|
||||||
|
|
||||||
def parse_widget(widget):
|
def set_setting_by_id(self, id: int, value: str):
|
||||||
temp_widget = CameraWidget(
|
widget = self.get_setting_by_id(id)
|
||||||
id=widget.get_id(),
|
|
||||||
name=widget.get_name(),
|
|
||||||
label=widget.get_label(),
|
|
||||||
type=camera_widget_types[widget.get_type()],
|
|
||||||
widget=widget
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
if value not in widget.choices:
|
||||||
temp_widget.value = widget.get_value()
|
return
|
||||||
except gp.GPhoto2Error:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
widget.config.set_value(value) # type: ignore
|
||||||
temp_widget.choices = list(widget.get_choices())
|
self.camera.set_single_config(widget.name, widget.config) # type: ignore
|
||||||
except gp.GPhoto2Error:
|
# widget.value = value
|
||||||
pass
|
new_config = self.parse_widget( self.camera.get_single_config(widget.name) )
|
||||||
|
print(f"old: {widget}")
|
||||||
|
print(f"new: {new_config}")
|
||||||
|
|
||||||
self.widgets.append(temp_widget)
|
|
||||||
|
|
||||||
for i in range(widget.count_children()):
|
def parse_widget(self, config):
|
||||||
parse_widget(widget.get_child(i))
|
temp_widget = CameraWidget(
|
||||||
|
id=config.get_id(),
|
||||||
|
name=config.get_name(),
|
||||||
|
label=config.get_label(),
|
||||||
|
type=camera_widget_types[config.get_type()],
|
||||||
|
config=config
|
||||||
|
)
|
||||||
|
|
||||||
config = self.camera.get_config()
|
try:
|
||||||
parse_widget(config)
|
temp_widget.value = config.get_value()
|
||||||
|
except gp.GPhoto2Error:
|
||||||
|
pass
|
||||||
|
|
||||||
for wid in self.widgets:
|
try:
|
||||||
print(wid)
|
temp_widget.choices = list(config.get_choices())
|
||||||
|
except gp.GPhoto2Error:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return temp_widget
|
||||||
|
|
||||||
|
def read_config(self, config):
|
||||||
|
self.widgets.append(self.parse_widget(config))
|
||||||
|
|
||||||
|
for i in range(config.count_children()):
|
||||||
|
child = config.get_child(i)
|
||||||
|
self.read_config(child)
|
||||||
|
|||||||
Reference in New Issue
Block a user