#!/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_Filepath_Setting(wx.Dialog): """ @description : 文件路径 配置 """ def __init__(self, parent,id): # 串口页面配置 super(UI_Filepath_Setting, 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.sensor = self.config_sensor.get(self.did) # print(self.config_sensor) # print(self.sensor) 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("filepath","path") 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.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('filepath',"path",self.textCtrl1.GetValue( )) self.config_yml.write_yaml(self.config_sensor) del self.config if success: self.EndModal(wx.ID_OK)