Mercurial > libervia-backend
comparison frontends/src/wix/param.py @ 223:86d249b6d9b7
Files reorganisation
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 29 Dec 2010 01:06:29 +0100 |
parents | frontends/wix/param.py@9ee4a1d0d7fb |
children | fd9b7834d98a |
comparison
equal
deleted
inserted
replaced
222:3198bfd66daa | 223:86d249b6d9b7 |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 wix: a SAT frontend | |
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 | |
23 | |
24 import wx | |
25 import pdb | |
26 from xml.dom import minidom | |
27 from logging import debug, info, error | |
28 from tools.jid import JID | |
29 | |
30 | |
31 class Param(wx.Frame): | |
32 def __init__(self, host, title=_("Configuration")): | |
33 super(Param, self).__init__(None, title=title) | |
34 | |
35 self.host = host | |
36 | |
37 self.modified = {} # dict of modified data (i.e. what we have to save) | |
38 self.ctl_list = {} # usefull to access ctrl, key = (name, category) | |
39 | |
40 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
41 self.notebook=wx.Notebook(self, -1, style=wx.NB_LEFT) | |
42 self.sizer.Add(self.notebook, 1, flag=wx.EXPAND) | |
43 self.SetSizer(self.sizer) | |
44 self.SetAutoLayout(True) | |
45 | |
46 #events | |
47 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
48 | |
49 self.MakeModal() | |
50 | |
51 for category in self.host.bridge.getParamsCategories(): | |
52 self.addCategory(category) | |
53 | |
54 self.Show() | |
55 | |
56 def addCategory(self, category): | |
57 panel=wx.Panel(self.notebook) | |
58 panel.sizer = wx.BoxSizer(wx.VERTICAL) | |
59 | |
60 cat_dom = minidom.parseString(self.host.bridge.getParamsForCategory(category, profile_key = self.host.profile).encode('utf-8')) | |
61 | |
62 for param in cat_dom.documentElement.getElementsByTagName("param"): | |
63 name = param.getAttribute("name") | |
64 label = param.getAttribute("label") | |
65 type = param.getAttribute("type") | |
66 value = param.getAttribute("value") | |
67 sizer = wx.BoxSizer(wx.HORIZONTAL) | |
68 if type=="string": | |
69 label=wx.StaticText(panel, -1, (label or name)+" ") | |
70 ctrl = wx.TextCtrl(panel, -1, value) | |
71 sizer.Add(label) | |
72 elif type=="password": | |
73 label=wx.StaticText(panel, -1, (label or name)+" ") | |
74 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD) | |
75 sizer.Add(label) | |
76 elif type=="bool": | |
77 ctrl = wx.CheckBox(panel, -1, label or name, style = wx.CHK_2STATE) | |
78 ctrl.SetValue(value=="true") | |
79 elif type=="button": | |
80 ctrl = wx.Button(panel, -1, value) | |
81 ctrl.callback_id = param.getAttribute("callback_id") | |
82 else: | |
83 error(_("FIXME FIXME FIXME")) #FIXME ! | |
84 raise NotImplementedError | |
85 if name: | |
86 ctrl.param_id=(name, category) | |
87 self.ctl_list[(name, category)] = ctrl | |
88 sizer.Add(ctrl, 1, flag=wx.EXPAND) | |
89 panel.sizer.Add(sizer, flag=wx.EXPAND) | |
90 | |
91 if type=="string" or type=="password": | |
92 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) | |
93 elif type=="bool": | |
94 panel.Bind(wx.EVT_CHECKBOX, self.onCheckBoxClicked, ctrl) | |
95 elif type=="button": | |
96 panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl) | |
97 | |
98 panel.SetSizer(panel.sizer) | |
99 panel.SetAutoLayout(True) | |
100 self.notebook.AddPage(panel, category) | |
101 cat_dom.unlink() | |
102 | |
103 def onTextChanged(self, event): | |
104 """Called when a string paramater is modified""" | |
105 self.modified[event.GetEventObject().param_id]=event.GetString() | |
106 | |
107 ### FIXME # Some hacks for better presentation, should be generic # FIXME ### | |
108 if event.GetEventObject().param_id == ('JabberID', 'Connection'): | |
109 domain = JID(event.GetString()).domain | |
110 self.ctl_list[('Server', 'Connection')].SetValue(domain) | |
111 self.modified[('Server', 'Connection')] = domain | |
112 | |
113 event.Skip() | |
114 | |
115 def onCheckBoxClicked(self, event): | |
116 """Called when a bool paramater is modified""" | |
117 self.modified[event.GetEventObject().param_id]="true" if event.GetEventObject().GetValue() else "false" | |
118 event.Skip() | |
119 | |
120 def onButtonClicked(self, event): | |
121 """Called when a button paramater is modified""" | |
122 self.__save_parameters() | |
123 name, category = event.GetEventObject().param_id | |
124 callback_id = event.GetEventObject().callback_id | |
125 data = {"name":name, "category":category, "callback_id":callback_id} | |
126 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile) | |
127 self.host.current_action_ids.add(id) | |
128 event.Skip() | |
129 | |
130 def __save_parameters(self): | |
131 for param in self.modified: | |
132 self.host.bridge.setParam(param[0], self.modified[param], param[1], profile_key = self.host.profile) | |
133 self.modified.clear() | |
134 | |
135 def onClose(self, event): | |
136 """Close event: we have to save the params.""" | |
137 debug(_("close")) | |
138 #now we save the modifier params | |
139 self.__save_parameters() | |
140 | |
141 self.MakeModal(False) | |
142 event.Skip() | |
143 |