1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #!/usr/bin/python
# myconfig.py
import wx
class MyConfig(wx.Frame):
def __init__(self, parent, id, title):
self.cfg = wx.FileConfig(appName="myconfig", vendorName="VendorName", localFilename="test.cfg", style=wx.CONFIG_USE_LOCAL_FILE)
if self.cfg.Exists('width'):
w, h = self.cfg.ReadInt('width'), self.cfg.ReadInt('height')
else:
(w, h) = (250, 250)
wx.Frame.__init__(self, parent, id, title, size=(w, h))
self.conteneur = wx.Panel(self, 1, size=self.GetClientSize())
wx.StaticText(self.conteneur, -1, 'Width:', (20, 20))
wx.StaticText(self.conteneur, -1, 'Height:', (20, 70))
self.sc1 = wx.SpinCtrl(self.conteneur, -1, str(w), (80, 15), (60, -1), min=200, max=500)
self.sc2 = wx.SpinCtrl(self.conteneur, -1, str(h), (80, 65), (60, -1), min=200, max=500)
wx.Button(self.conteneur, 1, 'Save', (20, 120))
self.Bind(wx.EVT_BUTTON, self.OnSave, id=1)
self.statusbar = self.CreateStatusBar()
self.Centre()
self.Show(True)
def OnSave(self, event):
self.cfg.WriteInt("width", self.sc1.GetValue())
self.cfg.WriteInt("height", self.sc2.GetValue())
self.statusbar.SetStatusText('Configuration saved, %s ' % wx.Now())
app = wx.App()
MyConfig(None, -1, 'myconfig.pyw')
app.MainLoop() |
Partager