annotate frontends/wix/param.py @ 18:6928e3cb73a8

refactoring: using xml params part II
author Goffi <goffi@goffi.org>
date Fri, 06 Nov 2009 23:31:00 +0100
parents c4bc297b82f0
children 633c5ed65701
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 wix: a SAT frontend
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22
goffi@necton2
parents:
diff changeset
23
goffi@necton2
parents:
diff changeset
24 import wx
goffi@necton2
parents:
diff changeset
25 import pdb
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
26 from xml.dom import minidom
0
goffi@necton2
parents:
diff changeset
27 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
28
goffi@necton2
parents:
diff changeset
29
goffi@necton2
parents:
diff changeset
30 class Param(wx.Frame):
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
31 def __init__(self, bridge, title="Configuration"):
0
goffi@necton2
parents:
diff changeset
32 super(Param, self).__init__(None, title=title)
goffi@necton2
parents:
diff changeset
33
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
34 self.bridge = bridge
0
goffi@necton2
parents:
diff changeset
35
goffi@necton2
parents:
diff changeset
36 self.modified={} # dict of modified data (i.e. what we have to save)
goffi@necton2
parents:
diff changeset
37
goffi@necton2
parents:
diff changeset
38 self.sizer = wx.BoxSizer(wx.VERTICAL)
goffi@necton2
parents:
diff changeset
39 self.notebook=wx.Notebook(self, -1, style=wx.NB_LEFT)
goffi@necton2
parents:
diff changeset
40 self.sizer.Add(self.notebook, 1, flag=wx.EXPAND)
goffi@necton2
parents:
diff changeset
41 self.SetSizer(self.sizer)
goffi@necton2
parents:
diff changeset
42 self.SetAutoLayout(True)
goffi@necton2
parents:
diff changeset
43
goffi@necton2
parents:
diff changeset
44 #events
goffi@necton2
parents:
diff changeset
45 self.Bind(wx.EVT_CLOSE, self.onClose, self)
goffi@necton2
parents:
diff changeset
46
goffi@necton2
parents:
diff changeset
47 self.MakeModal()
goffi@necton2
parents:
diff changeset
48
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
49 for category in self.bridge.getParamsCategories():
0
goffi@necton2
parents:
diff changeset
50 self.addCategory(category)
goffi@necton2
parents:
diff changeset
51
goffi@necton2
parents:
diff changeset
52 self.Show()
goffi@necton2
parents:
diff changeset
53
goffi@necton2
parents:
diff changeset
54 def addCategory(self, category):
goffi@necton2
parents:
diff changeset
55 panel=wx.Panel(self.notebook)
goffi@necton2
parents:
diff changeset
56 panel.sizer = wx.BoxSizer(wx.VERTICAL)
goffi@necton2
parents:
diff changeset
57
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
58 cat_dom = minidom.parseString(self.bridge.getParamsForCategory(category))
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
59
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
60 for param in cat_dom.documentElement.getElementsByTagName("param"):
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
61 name = param.getAttribute("name")
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
62 type = param.getAttribute("type")
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
63 value = param.getAttribute("value")
0
goffi@necton2
parents:
diff changeset
64 sizer = wx.BoxSizer(wx.HORIZONTAL)
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
65 label=wx.StaticText(panel, -1, name+" ")
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
66 if type=="string":
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
67 ctrl = wx.TextCtrl(panel, -1, value)
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
68 elif type=="password":
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
69 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
0
goffi@necton2
parents:
diff changeset
70 else:
goffi@necton2
parents:
diff changeset
71 error("FIXME FIXME FIXME") #FIXME !
goffi@necton2
parents:
diff changeset
72 raise NotImplementedError
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
73 ctrl.param_id=(name, category)
0
goffi@necton2
parents:
diff changeset
74 sizer.Add(label)
goffi@necton2
parents:
diff changeset
75 sizer.Add(ctrl, 1, flag=wx.EXPAND)
goffi@necton2
parents:
diff changeset
76 panel.sizer.Add(sizer, flag=wx.EXPAND)
goffi@necton2
parents:
diff changeset
77
goffi@necton2
parents:
diff changeset
78 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
goffi@necton2
parents:
diff changeset
79 panel.SetSizer(panel.sizer)
goffi@necton2
parents:
diff changeset
80 panel.SetAutoLayout(True)
goffi@necton2
parents:
diff changeset
81 self.notebook.AddPage(panel, category)
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
82 cat_dom.unlink()
0
goffi@necton2
parents:
diff changeset
83
goffi@necton2
parents:
diff changeset
84 def onTextChanged(self, event):
goffi@necton2
parents:
diff changeset
85 """Called when a paramated is modified"""
goffi@necton2
parents:
diff changeset
86 self.modified[event.GetEventObject().param_id]=event.GetString()
goffi@necton2
parents:
diff changeset
87 event.Skip()
goffi@necton2
parents:
diff changeset
88
goffi@necton2
parents:
diff changeset
89
goffi@necton2
parents:
diff changeset
90 def onClose(self, event):
goffi@necton2
parents:
diff changeset
91 """Close event: we have to save the params."""
goffi@necton2
parents:
diff changeset
92 debug("close")
goffi@necton2
parents:
diff changeset
93 #now we save the modifier params
goffi@necton2
parents:
diff changeset
94 for param in self.modified:
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
95 self.bridge.setParam(param[0], self.modified[param], param[1])
0
goffi@necton2
parents:
diff changeset
96
goffi@necton2
parents:
diff changeset
97 self.MakeModal(False)
goffi@necton2
parents:
diff changeset
98 event.Skip()
goffi@necton2
parents:
diff changeset
99