1
2
3
4
5
6
7
8
9
10
11
12 """ Handle setting phone wizard
13 """
14
15
16 import wx
17 import wx.wizard as wiz
18
19
20 import common
21 import comscan
22 import phone_detect
23 import phones
24 import usbscan
25
26
27 -class MyPage(wiz.WizardPageSimple):
28 """My Common Page Setup"""
29 - def __init__(self, parent, title, instruction=None):
30 super(MyPage, self).__init__(parent)
31 vs=wx.BoxSizer(wx.VERTICAL)
32 _title = wx.StaticText(self, -1, title)
33 _title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
34 vs.Add(_title, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
35 vs.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.ALL, 5)
36 if instruction:
37 _inst=wx.StaticText(self, -1, instruction)
38 vs.Add(_inst, 0, wx.ALIGN_LEFT|wx.ALL, 5)
39
40 _my_ctrl=self.GetMyControls()
41 if _my_ctrl:
42 vs.Add(_my_ctrl, 1, wx.EXPAND|wx.ALL, 5)
43 self.SetSizer(vs)
44 self.SetAutoLayout(True)
45 vs.Fit(self)
46
47 - def GetMyControls(self):
48 """Build your own controls here, which will be appended to the main
49 sizer. Default to None.
50 """
51 return None
52
56 - def get(self, data):
59 - def set(self, data):
62
63
64 -class CommPortPage(MyPage):
65 detail_fields=(
66
67 ('name', 'Name', None),
68 ('description', 'Description', None),
69 ('hardwareinstance', 'Hardware Info', None),
70 ('driverprovider', 'Driver Provider', None),
71 ('driverversion', 'Driver Version', None),
72 ('driverdescription', 'Driver Description', None),
73 ('class', 'Class', None),
74 ('active', 'Active', None),
75 )
76
77 - def __init__(self, parent):
78 super(CommPortPage, self).__init__(parent, 'Communication Port Setting',
79 'Set the serial port through which BitPim communicates with the phone.')
80 self._ports=[{'name': 'auto', 'description': 'BitPim will try to detect the correct port automatically when accessing your phone'}]+\
81 [x for x in comscan.comscan()+usbscan.usbscan() \
82 if x.get('available', False)]
83 self._populate()
84 self._set_max_size()
85
86 - def GetMyControls(self):
87 hs=wx.BoxSizer(wx.HORIZONTAL)
88 _sbs1=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Available Ports'),
89 wx.VERTICAL)
90 self._ports_lb=wx.ListBox(self, -1,
91 style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_ALWAYS_SB)
92 wx.EVT_LISTBOX(self, self._ports_lb.GetId(),
93 self.OnPortSelected)
94 _sbs1.Add(self._ports_lb, 1, wx.EXPAND|wx.ALL, 5)
95 hs.Add(_sbs1, 0, wx.EXPAND|wx.ALL, 5)
96 _sbs2=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Port Detail'),
97 wx.VERTICAL)
98 fgs=wx.FlexGridSizer(0, 2, 5, 5)
99 fgs.AddGrowableCol(1)
100 self._w=[]
101 for e in CommPortPage.detail_fields:
102 fgs.Add(wx.StaticText(self, -1, e[1]), 0, wx.EXPAND|wx.ALL, 0)
103 w=wx.StaticText(self, -1, 100*' ')
104 fgs.Add(w, 0, wx.EXPAND|wx.LEFT, 5)
105 self._w.append(w)
106 _sbs2.Add(fgs, 1, wx.EXPAND|wx.ALL, 5)
107 self._port_details_bs=_sbs2
108 hs.Add(_sbs2, 0, wx.EXPAND|wx.ALL, 5)
109 return hs
110
112 return self._ports_lb.GetSelection()!=wx.NOT_FOUND
113 - def get(self, data):
114 data['com']=self._ports_lb.GetStringSelection()
115
116 - def _set_max_size(self):
117
118 _max_size=wx.Size(0,0)
119 for e in self._ports:
120 self._populate_each(e)
121 _ms=self._port_details_bs.GetMinSize()
122 _max_size[0]=max(_max_size[0], _ms[0])
123 _max_size[1]=max(_max_size[1], _ms[1])
124 self._port_details_bs.SetMinSize(_max_size)
125 for w in self._w:
126 w.SetLabel('')
127
129 self._ports_lb.Clear()
130 for w in self._w:
131 w.SetLabel('')
132
133 - def _populate(self):
134
135 self.Clear()
136 for e in self._ports:
137 self._ports_lb.Append(e['name'])
138 - def _populate_each(self, data):
139 for i,e in enumerate(CommPortPage.detail_fields):
140 v=data.get(e[0], '')
141 self._w[i].SetLabel(str(v))
142 self._port_details_bs.Layout()
143
144 - def OnPortSelected(self, evt):
145 self._populate_each(self._ports[evt.GetInt()])
146
147
148 -class PhoneModelPage(MyPage):
149 - def __init__(self, parent):
150 self._setbyme=False
151 super(PhoneModelPage, self).__init__(parent, 'Phone Model Setting',
152 'Set your phone model.')
153 self._populate()
154
155 - def GetMyControls(self):
156 hs=wx.BoxSizer(wx.HORIZONTAL)
157 _sbs=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Carriers'),
158 wx.VERTICAL)
159 self._carriers_lb=wx.ListBox(self, -1,
160 style=wx.LB_MULTIPLE|wx.LB_HSCROLL|wx.LB_ALWAYS_SB)
161 wx.EVT_LISTBOX(self, self._carriers_lb.GetId(), self.OnCarriersLB)
162 _sbs.Add(self._carriers_lb, 1, wx.EXPAND|wx.ALL, 5)
163 hs.Add(_sbs, 1, wx.EXPAND|wx.ALL, 5)
164 _sbs=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Manufacturers'),
165 wx.VERTICAL)
166 self._manuf_lb=wx.ListBox(self, -1,
167 style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_ALWAYS_SB)
168 wx.EVT_LISTBOX(self, self._manuf_lb.GetId(), self.OnCarriersLB)
169 _sbs.Add(self._manuf_lb, 1, wx.EXPAND|wx.ALL, 5)
170 hs.Add(_sbs, 1, wx.EXPAND|wx.ALL, 5)
171 _sbs=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Models'),
172 wx.VERTICAL)
173 self._models_lb=wx.ListBox(self, -1,
174 style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_ALWAYS_SB)
175 wx.EVT_LISTBOX(self, self._models_lb.GetId(), self.OnModelsLB)
176 _sbs.Add(self._models_lb, 1, wx.EXPAND|wx.ALL, 5)
177 self.help_btn=wx.Button(self, wx.ID_HELP)
178 _sbs.Add(self.help_btn, 0, wx.ALL, 5)
179 wx.EVT_BUTTON(self, self.help_btn.GetId(), self.OnHelp)
180 self.help_btn.Enable(False)
181 hs.Add(_sbs, 1, wx.EXPAND|wx.ALL, 5)
182 return hs
183
184 - def _populate_models(self, carriers=None, brand=None):
185
186 self._models_lb.Clear()
187 self.help_btn.Enable(False)
188 _l=phones.phoneslist(brand, None)
189 if carriers:
190 for _c in carriers:
191 _l=[x for x in phones.phoneslist(brand, _c) if x in _l]
192 for e in _l:
193 self._models_lb.Append(e)
194
195 - def _populate_carriers(self, selection=None):
196 self._carriers_lb.Clear()
197 for e in ['All']+phones.phonecarriers:
198 self._carriers_lb.Append(e)
199 if selection is not None:
200 self._carriers_lb.SetSelection(0)
201
202 - def _populate(self):
203 self._manuf_lb.Clear()
204 for e in ['All']+phones.phonemanufacturers:
205 self._manuf_lb.Append(e)
206 self._manuf_lb.SetSelection(0)
207 self._populate_carriers(0)
208 self._populate_models()
209
211 return self._models_lb.GetSelection()!=wx.NOT_FOUND
212 - def get(self, data):
213 data['phone']=self._models_lb.GetStringSelection()
214
215 - def OnCarriersLB(self, evt):
216 if self._setbyme:
217 return
218 _s=self._carriers_lb.GetSelections()
219 if _s==wx.NOT_FOUND:
220 return
221 self._setbyme=True
222 if 0 in _s:
223 _carriers=None
224 else:
225 _carriers=[self._carriers_lb.GetString(x) for x in _s]
226 _s=self._manuf_lb.GetStringSelection()
227 if not _s or _s=='All':
228 _brand=None
229 else:
230 _brand=_s
231 self._populate_models(_carriers, _brand)
232 self._setbyme=False
233
234 - def OnModelsLB(self, evt):
235 if self._setbyme:
236 return
237 self._setbyme=True
238 _model=evt.GetString()
239 self._manuf_lb.SetStringSelection(phones.manufacturer(_model))
240 self._populate_carriers()
241 for s in phones.carriers(_model):
242 self._carriers_lb.SetStringSelection(s)
243 self.help_btn.Enable(phones.helpid(_model) is not None)
244 self._setbyme=False
245
246 - def OnHelp(self, _):
247 model=self._models_lb.GetStringSelection()
248 if not model:
249 return
250 helpid=phones.helpid(model)
251 if helpid:
252 wx.GetApp().displayhelpid(helpid)
253
254
255 -class SummaryPage(MyPage):
256 - def __init__(self, parent):
257 super(SummaryPage, self).__init__(parent, 'Summary')
258
259 - def GetMyControls(self):
260 vs=wx.BoxSizer(wx.VERTICAL)
261 _sbs=wx.StaticBoxSizer(wx.StaticBox(self, -1, 'User Selection'),
262 wx.VERTICAL)
263 _fgs=wx.FlexGridSizer(0, 2, 5, 5)
264 _fgs.Add(wx.StaticText(self, -1, 'Phone Model:'),
265 0, wx.EXPAND|wx.ALL, 0)
266 self._model=wx.StaticText(self, -1, '')
267 _fgs.Add(self._model, 0, wx.EXPAND|wx.ALL, 0)
268 _fgs.Add(wx.StaticText(self, -1, 'Port:'),
269 0, wx.EXPAND|wx.ALL, 0)
270 self._port=wx.StaticText(self, -1, '')
271 _fgs.Add(self._port, 0, wx.EXPAND|wx.ALL, 0)
272 _fgs.Add(wx.StaticText(self, -1, 'Detection Status:'),
273 0, wx.EXPAND|wx.ALL, 0)
274 self._status=wx.StaticText(self, -1, '')
275 _fgs.Add(self._status, 0, wx.EXPAND|wx.ALL, 0)
276
277 _sbs.Add(_fgs, 1, wx.EXPAND, 0)
278 vs.Add(_sbs, 0, wx.EXPAND|wx.ALL, 5)
279 self._det_btn=wx.Button(self, -1, 'Detect Phone')
280 vs.Add(self._det_btn, 0, wx.ALL, 5)
281 wx.EVT_BUTTON(self, self._det_btn.GetId(), self.OnDetect)
282 return vs
283
284 - def set(self, data):
285 self._status.SetLabel('')
286 self._model_name=data.get('phone', '')
287 self._model.SetLabel(self._model_name)
288 self._com_port=data.get('com', '')
289 self._port.SetLabel(self._com_port)
290 _module=common.importas(phones.module(self._model_name))
291 self._det_btn.Enable(bool(self._model_name and \
292 (hasattr(_module.Phone,
293 'detectphone') or \
294 hasattr(_module.Profile,
295 'phone_model'))))
296
297 - def OnDetect(self, _):
298 if self._com_port=='auto':
299 _port_name=None
300 else:
301 _port_name=str(self._com_port)
302 _res=phone_detect.DetectPhone().detect(using_port=_port_name,
303 using_model=self._model_name)
304 _status='FAILED'
305 if _res and _res.get('phone_name', '')==self._model_name:
306 _status='PASSED'
307 self._status.SetLabel(_status)
308
309
312 super(SetPhoneWizard, self).__init__(parent, -1,
313 'Phone Setting Wizard')
314 self._data={}
315 commport_page=CommPortPage(self)
316 phonemodel_page=PhoneModelPage(self)
317 summary_page=SummaryPage(self)
318 wiz.WizardPageSimple_Chain(phonemodel_page, commport_page)
319 wiz.WizardPageSimple_Chain(commport_page, summary_page)
320 self.first_page=phonemodel_page
321 self.GetPageAreaSizer().Add(phonemodel_page, 1, wx.EXPAND|wx.ALL, 5)
322 wiz.EVT_WIZARD_PAGE_CHANGING(self, self.GetId(), self.OnPageChanging)
323 wiz.EVT_WIZARD_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged)
324
327
328 - def OnPageChanging(self, evt):
329 pg=evt.GetPage()
330 if not evt.GetDirection() or pg.ok():
331 pg.get(self._data)
332 else:
333 evt.Veto()
334
335 - def OnPageChanged(self, evt):
336 evt.GetPage().set(self._data)
337
340
341
342
343 if __name__=="__main__":
344 app=wx.PySimpleApp()
345 f=wx.Frame(None, title='setphone_wizard')
346 w=SetPhoneWizard(f)
347 print w.RunWizard()
348 print w._data
349 w.Destroy()
350