sat:
- first public release, initial commit
This commit is contained in:
commit
d005c1b9a8
1 changed files with 4704 additions and 0 deletions
95
frontends/wix/param.py
Normal file
95
frontends/wix/param.py
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
wix: a SAT frontend
|
||||
Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
import wx
|
||||
import pdb
|
||||
from logging import debug, info, error
|
||||
|
||||
|
||||
class Param(wx.Frame):
|
||||
def __init__(self, setParam, getParam, getParams, getParamsCategories, title="Configuration"):
|
||||
super(Param, self).__init__(None, title=title)
|
||||
|
||||
self.setParam=setParam
|
||||
self.getParam=getParam
|
||||
self.getParams=getParams
|
||||
self.getParamsCategories=getParamsCategories
|
||||
|
||||
self.modified={} # dict of modified data (i.e. what we have to save)
|
||||
|
||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.notebook=wx.Notebook(self, -1, style=wx.NB_LEFT)
|
||||
self.sizer.Add(self.notebook, 1, flag=wx.EXPAND)
|
||||
self.SetSizer(self.sizer)
|
||||
self.SetAutoLayout(True)
|
||||
|
||||
#events
|
||||
self.Bind(wx.EVT_CLOSE, self.onClose, self)
|
||||
|
||||
self.MakeModal()
|
||||
|
||||
for category in self.getParamsCategories():
|
||||
self.addCategory(category)
|
||||
|
||||
self.Show()
|
||||
|
||||
def addCategory(self, category):
|
||||
panel=wx.Panel(self.notebook)
|
||||
panel.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
for param in self.getParams(category):
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
label=wx.StaticText(panel, -1, param[0]+" ")
|
||||
if param[2]=="string":
|
||||
ctrl = wx.TextCtrl(panel, -1, param[1])
|
||||
elif param[2]=="password":
|
||||
ctrl = wx.TextCtrl(panel, -1, param[1], style=wx.TE_PASSWORD)
|
||||
else:
|
||||
error("FIXME FIXME FIXME") #FIXME !
|
||||
raise NotImplementedError
|
||||
ctrl.param_id=(param[0], category)
|
||||
sizer.Add(label)
|
||||
sizer.Add(ctrl, 1, flag=wx.EXPAND)
|
||||
panel.sizer.Add(sizer, flag=wx.EXPAND)
|
||||
|
||||
panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
|
||||
panel.SetSizer(panel.sizer)
|
||||
panel.SetAutoLayout(True)
|
||||
self.notebook.AddPage(panel, category)
|
||||
|
||||
def onTextChanged(self, event):
|
||||
"""Called when a paramated is modified"""
|
||||
self.modified[event.GetEventObject().param_id]=event.GetString()
|
||||
event.Skip()
|
||||
|
||||
|
||||
def onClose(self, event):
|
||||
"""Close event: we have to save the params."""
|
||||
debug("close")
|
||||
#now we save the modifier params
|
||||
for param in self.modified:
|
||||
self.setParam(param[0], self.modified[param], param[1])
|
||||
|
||||
self.MakeModal(False)
|
||||
event.Skip()
|
||||
|
||||
Loading…
Reference in a new issue