command line args for all/restricted settings; use fake PipelineClient if there is no cam_server_client; take background and save config to pipeline
This commit is contained in:
97
scam.py
97
scam.py
@ -1,12 +1,33 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("-a", "--all", dest="show_all_settings", action="store_true", help="show all settings")
|
||||||
|
clargs = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
SHOWN_SETTINGS = [
|
||||||
|
"image_background",
|
||||||
|
"image_background_enable",
|
||||||
|
"image_threshold",
|
||||||
|
"project_axis",
|
||||||
|
"roi_background",
|
||||||
|
"roi_signal"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
#from cam_server_client import PipelineClient
|
try:
|
||||||
from fake import PipelineClient
|
from cam_server_client import PipelineClient
|
||||||
|
except ImportError:
|
||||||
|
from fake import PipelineClient
|
||||||
|
|
||||||
from tools import EXPANDING, STRETCH, make_filled_vbox, make_filled_hbox
|
from tools import EXPANDING, STRETCH, make_filled_vbox, make_filled_hbox
|
||||||
from mathentry import MathEntry
|
from mathentry import MathEntry
|
||||||
from listentry import ListEntry
|
from listentry import ListEntry
|
||||||
|
from entrybutton import EntryButton
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -20,7 +41,7 @@ pls = sorted(pls)
|
|||||||
|
|
||||||
class MainFrame(wx.Frame):
|
class MainFrame(wx.Frame):
|
||||||
|
|
||||||
def __init__(self, parent=None, title="test"):
|
def __init__(self, parent=None, title="SCam"):
|
||||||
super().__init__(parent, title=title)
|
super().__init__(parent, title=title)
|
||||||
|
|
||||||
panel_main = MainPanel(self)
|
panel_main = MainPanel(self)
|
||||||
@ -34,23 +55,59 @@ class MainPanel(wx.Panel):
|
|||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
self.instance = None
|
||||||
|
self.camera = None
|
||||||
|
|
||||||
self.cb_pls = cb_pls = wx.ComboBox(self, choices=pls)
|
self.cb_pls = cb_pls = wx.ComboBox(self, choices=pls)
|
||||||
|
|
||||||
|
self.eb_bkg = eb_bkg = EntryButton(self, label="Background Images", value=100, button="Save Background")
|
||||||
|
eb_bkg.Disable()
|
||||||
|
|
||||||
self.entries = entries = SettingsList(self)
|
self.entries = entries = SettingsList(self)
|
||||||
|
|
||||||
self.btn_print = btn_print = wx.Button(self, label="Print")
|
self.btn_print = btn_print = wx.Button(self, label="Print")
|
||||||
|
btn_print.Disable()
|
||||||
|
|
||||||
|
self.btn_save = btn_save = wx.Button(self, label="Save")
|
||||||
|
btn_save.Disable()
|
||||||
|
|
||||||
cb_pls.Bind(wx.EVT_COMBOBOX, self.on_select)
|
cb_pls.Bind(wx.EVT_COMBOBOX, self.on_select)
|
||||||
|
eb_bkg.button.Bind(wx.EVT_BUTTON, self.on_save_bkg)
|
||||||
btn_print.Bind(wx.EVT_BUTTON, self.on_print)
|
btn_print.Bind(wx.EVT_BUTTON, self.on_print)
|
||||||
|
btn_save.Bind(wx.EVT_BUTTON, self.on_save_cfg)
|
||||||
|
|
||||||
widgets = [cb_pls, entries, btn_print]
|
widgets = [btn_print, btn_save]
|
||||||
sizer = make_filled_vbox(widgets)
|
btns_sizer = make_filled_hbox(widgets)
|
||||||
|
|
||||||
|
widgets = [cb_pls, STRETCH, eb_bkg, STRETCH, entries, btns_sizer]
|
||||||
|
sizer = make_filled_vbox(widgets, border=10)
|
||||||
self.SetSizer(sizer)
|
self.SetSizer(sizer)
|
||||||
|
|
||||||
|
|
||||||
|
def on_save_bkg(self, event):
|
||||||
|
num = self.eb_bkg.GetValue()
|
||||||
|
bkgname = pc.collect_background(self.camera, num)
|
||||||
|
self.entries.set("image_background", bkgname)
|
||||||
|
print(bkgname)
|
||||||
|
|
||||||
|
|
||||||
def on_select(self, event):
|
def on_select(self, event):
|
||||||
instance = self.cb_pls.GetValue()
|
self.instance = instance = self.cb_pls.GetValue()
|
||||||
cfg = pc.get_instance_config(instance)
|
cfg = pc.get_instance_config(instance)
|
||||||
self.entries.update(cfg)
|
print(cfg)
|
||||||
|
|
||||||
|
self.camera = cfg["camera_name"]
|
||||||
|
self.eb_bkg.Enable()
|
||||||
|
self.btn_print.Enable()
|
||||||
|
self.btn_save.Enable()
|
||||||
|
|
||||||
|
if clargs.show_all_settings:
|
||||||
|
filtered_cfg = cfg
|
||||||
|
else:
|
||||||
|
filtered_cfg = {k: v for k, v in cfg.items() if k in SHOWN_SETTINGS}
|
||||||
|
|
||||||
|
self.entries.update(filtered_cfg)
|
||||||
|
|
||||||
self._adjust_size()
|
self._adjust_size()
|
||||||
|
|
||||||
|
|
||||||
@ -61,8 +118,20 @@ class MainPanel(wx.Panel):
|
|||||||
|
|
||||||
|
|
||||||
def on_print(self, event):
|
def on_print(self, event):
|
||||||
data = self.entries.get()
|
new_cfg = self.entries.get()
|
||||||
print(data)
|
print(new_cfg)
|
||||||
|
old_cfg = pc.get_instance_config(self.instance)
|
||||||
|
|
||||||
|
if not clargs.show_all_settings:
|
||||||
|
old_cfg = {k: v for k, v in old_cfg.items() if k in SHOWN_SETTINGS}
|
||||||
|
|
||||||
|
print("unchanged" if old_cfg == new_cfg else "changed")
|
||||||
|
|
||||||
|
|
||||||
|
def on_save_cfg(self, event):
|
||||||
|
new_cfg = self.entries.get()
|
||||||
|
res = pc.set_instance_config(self.instance, new_cfg)
|
||||||
|
print(res)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +140,7 @@ class SettingsList(wx.GridSizer):
|
|||||||
def __init__(self, parent, hgap=5, vgap=5):
|
def __init__(self, parent, hgap=5, vgap=5):
|
||||||
super().__init__(cols=2, hgap=hgap, vgap=vgap)
|
super().__init__(cols=2, hgap=hgap, vgap=vgap)
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.children = []
|
self.children = {}
|
||||||
|
|
||||||
def update(self, cfg):
|
def update(self, cfg):
|
||||||
self.clear()
|
self.clear()
|
||||||
@ -83,15 +152,14 @@ class SettingsList(wx.GridSizer):
|
|||||||
|
|
||||||
def add(self, *args):
|
def add(self, *args):
|
||||||
new = Setting(self.parent, *args)
|
new = Setting(self.parent, *args)
|
||||||
self.children.append(new)
|
self.children[new.get_name()] = new
|
||||||
self.Add(new.state)
|
self.Add(new.state)
|
||||||
self.Add(new.text, 0, wx.EXPAND|wx.ALL)
|
self.Add(new.text, 0, wx.EXPAND|wx.ALL)
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
res = {}
|
res = {}
|
||||||
for i in self.children:
|
for i in self.children.values():
|
||||||
name = i.get_name()
|
name = i.get_name()
|
||||||
print(name)
|
|
||||||
if i.get_state():
|
if i.get_state():
|
||||||
value = i.get_value()
|
value = i.get_value()
|
||||||
else:
|
else:
|
||||||
@ -99,6 +167,9 @@ class SettingsList(wx.GridSizer):
|
|||||||
res[name] = value
|
res[name] = value
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def set(self, name, value):
|
||||||
|
self.children[name].text.SetValue(value)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Setting:
|
class Setting:
|
||||||
|
Reference in New Issue
Block a user