You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
4.6 KiB
110 lines
4.6 KiB
#!/usr/bin/env python
|
|
# -*- encoding: utf-8 -*-
|
|
import wx
|
|
# from configobj import ConfigObj
|
|
from myconfig import MyConfig
|
|
from myconfig import YAML_FILE_NAME
|
|
|
|
class UI_Algorithm(wx.Dialog):
|
|
"""
|
|
@description : 算法配置
|
|
"""
|
|
def __init__(self, parent, id):
|
|
# 串口页面配置
|
|
super(UI_Algorithm, self).__init__( parent ,id = id )
|
|
self.config = MyConfig()
|
|
self.InitUI()
|
|
self.SetSize((400, 400))
|
|
self.SetTitle(" 算法配置 ")
|
|
|
|
def InitUI(self):
|
|
self.config_yml = self.config.read_yaml()
|
|
|
|
self.panel = wx.Panel(self)
|
|
self.vbox = wx.BoxSizer(wx.VERTICAL)
|
|
|
|
self.sb = wx.StaticBox(self.panel, label='算法配置')
|
|
self.sbs = wx.StaticBoxSizer(self.sb, orient=wx.VERTICAL)
|
|
|
|
# self.hbox1 = wx.BoxSizer(wx.HORIZONTAL)
|
|
# self.staticText1 = wx.StaticText(self.panel, label='浊度校正 ',size=(60, -1), style=wx.ALIGN_CENTRE_VERTICAL )
|
|
# self.textCtrl1 = wx.TextCtrl(self.panel, value="",size=(250,25) )
|
|
# tmp = self.get_str_from_config( "algorithm", "A720" )
|
|
# if tmp is not None:
|
|
# self.textCtrl1.SetValue(tmp)
|
|
# self.hbox1.Add(self.staticText1, flag=wx.TOP|wx.LEFT, border=5)
|
|
# self.hbox1.Add(self.textCtrl1, flag=wx.TOP|wx.LEFT, border=5)
|
|
# self.sbs.Add(self.hbox1, flag=wx.TOP|wx.LEFT, border= 5)
|
|
|
|
self.hbox2 = wx.BoxSizer(wx.HORIZONTAL)
|
|
self.staticText2 = wx.StaticText(self.panel, label='包含纯水: ' ,size=(60, -1))
|
|
# self.staticText2_1 = wx.StaticText(self.panel, label='分钟 ' ,size=(60, -1))
|
|
self.textCtrl2 = wx.TextCtrl(self.panel, value="",size=(250,25))
|
|
tmp = self.get_str_from_config( "algorithm", "PureWater" )
|
|
if tmp is not None:
|
|
self.textCtrl2.SetValue(tmp)
|
|
self.hbox2.Add(self.staticText2, flag=wx.TOP|wx.LEFT, border=5)
|
|
self.hbox2.Add(self.textCtrl2,flag=wx.TOP|wx.LEFT, border=5)
|
|
# self.hbox2.Add(self.staticText2_1, flag=wx.TOP|wx.LEFT, border=5)
|
|
self.sbs.Add(self.hbox2, flag=wx.TOP|wx.LEFT, border=5)
|
|
|
|
# self.hbox3 = wx.BoxSizer(wx.HORIZONTAL)
|
|
# self.staticText3 = wx.StaticText(self.panel, label='纯水: ' ,size=(60, -1))
|
|
# # self.staticText2_1 = wx.StaticText(self.panel, label='分钟 ' ,size=(60, -1))
|
|
# self.textCtrl3 = wx.TextCtrl(self.panel, value="",size=(250,25))
|
|
# tmp = self.get_str_from_config( "algorithm", "3" )
|
|
# if tmp is not None:
|
|
# self.textCtrl3.SetValue(tmp)
|
|
# self.hbox3.Add(self.staticText3, flag=wx.TOP|wx.LEFT, border=5)
|
|
# self.hbox3.Add(self.textCtrl3,flag=wx.TOP|wx.LEFT, border=5)
|
|
# # self.hbox2.Add(self.staticText2_1, flag=wx.TOP|wx.LEFT, border=5)
|
|
# self.sbs.Add(self.hbox3, flag=wx.TOP|wx.LEFT, border=5)
|
|
|
|
self.panel.SetSizer(self.sbs)
|
|
|
|
self.hbox_0 = wx.BoxSizer(wx.HORIZONTAL)
|
|
self.okButton = wx.Button(self, label=u'保存配置')
|
|
self.closeButton = wx.Button(self, label='Close')
|
|
self.hbox_0.Add(self.okButton)
|
|
self.hbox_0.Add(self.closeButton, flag = wx.LEFT, border=5)
|
|
|
|
# 添加 vbox 到panel
|
|
self.vbox.Add(self.panel, proportion=1,
|
|
flag=wx.ALL | wx.EXPAND, border=5)
|
|
|
|
self.vbox.Add(self.hbox_0, flag=wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=10)
|
|
self.SetSizer(self.vbox)
|
|
|
|
self.okButton.Bind(wx.EVT_BUTTON, self.OnSave)
|
|
self.closeButton.Bind(wx.EVT_BUTTON, self.OnClose)
|
|
|
|
def get_str_from_config( self, section, key ):
|
|
return str(self.config_yml[section][key])
|
|
pass
|
|
|
|
def set_config_by_section_key_val( self, section, key, val ):
|
|
# print(f" {key} current type {type( self.config_yml[section][key] )}")
|
|
if type( self.config_yml[section][key] ) == int:
|
|
self.config_yml[section][key] = int(val)
|
|
elif type( self.config_yml[section][key] ) == float:
|
|
self.config_yml[section][key] = float(val)
|
|
else:
|
|
self.config_yml[section][key] = val
|
|
pass
|
|
|
|
def saveData(self, e):
|
|
pass
|
|
|
|
def OnClose(self, e):
|
|
self.Destroy()
|
|
|
|
def OnSave(self, e):
|
|
success = True
|
|
# 赋值字典,写入文件
|
|
# self.set_config_by_section_key_val( 'algorithm',"1",self.textCtrl1.GetValue( ) )
|
|
self.set_config_by_section_key_val( 'algorithm',"PureWater",self.textCtrl2.GetValue( ) )
|
|
# self.set_config_by_section_key_val( 'algorithm',"3",self.textCtrl2.GetValue( ) )
|
|
self.config.write_yaml(self.config_yml)
|
|
del self.config
|
|
if success:
|
|
self.EndModal(wx.ID_OK) |