1
2
3
4
5
6
7
8
9
10
11
12 """ Handle Import Calendar wizard
13 """
14
15
16 from __future__ import with_statement
17
18 import wx
19 import wx.wizard as wiz
20 import wx.lib.scrolledpanel as scrolled
21 from wx.lib.expando import ExpandoTextCtrl
22
23
24 import common_calendar
25 import guihelper
26 import importexport
27 import setphone_wizard
28
29
30 IMP_OPTION_REPLACEALL=0
31 IMP_OPTION_ADD=1
32 IMP_OPTION_MERGE=2
33
34
35 -class ImportTypePage(setphone_wizard.MyPage):
36 - def __init__(self, parent):
37 self._data=importexport.GetCalendarImports()
38 super(ImportTypePage, self).__init__(parent,
39 'Select Calendar Import Type')
40 self._populate()
41
42 - def GetMyControls(self):
43 vbs=wx.BoxSizer(wx.VERTICAL)
44 vbs.Add(wx.StaticText(self, -1, 'Import Calendar Type:'), 0,
45 wx.EXPAND|wx.ALL, 5)
46 self._type_lb=wx.ListBox(self, -1,
47 style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_ALWAYS_SB)
48 vbs.Add(self._type_lb, 0, wx.EXPAND|wx.ALL, 5)
49 return vbs
50
51 - def _populate(self):
52
53 self._type_lb.Clear()
54 for _l in self._data:
55 self._type_lb.Append(_l['type'], _l)
56
58
59 return self._type_lb.GetSelection()!=wx.NOT_FOUND
60
61 - def get(self, data):
62
63 _idx=self._type_lb.GetSelection()
64 _type=self._type_lb.GetString(_idx)
65 _new_type=data.get('type', None)!=_type
66 if _new_type or not data.has_key('data'):
67 data['type']=_type
68 _info=self._type_lb.GetClientData(_idx)
69 data['data']=_info['data']
70 data['data_obj']=_info['data']()
71 data['source_class']=_info['source']
72 data['source_obj']=_info['source']()
73 if _new_type:
74
75 data['type']=_type
76 if data.has_key('source_id'):
77 del data['source_id']
78
79 - def set(self, data):
80
81 if data.get('type', None):
82 self._type_lb.SetStringSelection(data['type'])
83
84
85 -class ImportSourcePage(setphone_wizard.MyPage):
86 - def __init__(self, parent):
87 self._source=None
88 super(ImportSourcePage, self).__init__(parent,
89 'Select Import Source')
90 - def GetMyControls(self):
91 vbs=wx.BoxSizer(wx.VERTICAL)
92 vbs.Add(wx.StaticText(self, -1, 'Source of data:'), 0,
93 wx.ALL|wx.EXPAND, 5)
94 self._source_lbl=ExpandoTextCtrl(self, -1, '', style=wx.TE_READONLY)
95 self._source_lbl.SetBackgroundColour(self.GetBackgroundColour())
96 vbs.Add(self._source_lbl, 0, wx.ALL|wx.EXPAND, 5)
97
98 _btn=wx.Button(self, -1, 'Browse')
99 wx.EVT_BUTTON(self, _btn.GetId(), self._OnBrowse)
100 vbs.Add(_btn, 0, wx.ALL, 5)
101 return vbs
102
103 - def setlabel(self):
104 self._source_lbl.SetValue(self._source.name())
105
106 @guihelper.BusyWrapper
107 - def _OnBrowse(self, _=None):
108 if not self._source:
109 return
110 self._source.browse(self)
111 self.setlabel()
112
114 return self._source and self._source.get()
115 - def get(self, data):
116 data['source_obj']=self._source
117 data['source_id']=self._source.id
118 data['imported']=False
119 - def set(self, data):
120 self._source=data['source_obj']
121 if self._source:
122 if data.has_key('source_id'):
123 self._source.id=data['source_id']
124 self.setlabel()
126 return self.GetParent().GetActiveDatabase()
127
131 self._type=None
132 self._source=None
133 super(ImportDataAll, self).__init__(parent, 'Import Data Preview')
134
136 vbs=wx.BoxSizer(wx.VERTICAL)
137 self._data_lb=wx.ListBox(self, -1,
138 style=wx.LB_SINGLE|wx.LB_HSCROLL|wx.LB_ALWAYS_SB)
139 vbs.Add(self._data_lb, 1, wx.EXPAND|wx.ALL, 5)
140 _btn=wx.Button(self, -1, 'Data Filtering Parameters')
141 vbs.Add(_btn, 0, wx.ALL, 5)
142 wx.EVT_BUTTON(self, _btn.GetId(), self._OnFilter)
143 return vbs
144
150 @guihelper.BusyWrapper
152 self._data_lb.Clear()
153 if not self._type or not self._source:
154
155 return
156 with guihelper.WXDialogWrapper(wx.ProgressDialog('Calendar Data Import',
157 'Importing data, please wait ...',
158 parent=self)) as dlg:
159 self._type.read(self._source.get(), dlg)
160 self._populate_lb()
161
170
171 - def set(self, data):
176 - def get(self, data):
177 data['imported']=True
178
179
180 -class ImportOptionPage(setphone_wizard.MyPage):
181 _choices=('Replace All', 'Add', 'Merge')
182 - def __init__(self, parent):
183 super(ImportOptionPage, self).__init__(parent,
184 'Import Options')
185 - def GetMyControls(self):
186 vbs=wx.BoxSizer(wx.VERTICAL)
187 self._option_rb=wx.RadioBox(self, -1, 'Import Options',
188 choices=self._choices,
189 style=wx.RA_SPECIFY_ROWS)
190 vbs.Add(self._option_rb, 0, wx.EXPAND|wx.ALL, 5)
191 return vbs
192
193 - def set(self, data):
194 self._option_rb.SetSelection(data.get('option', 0))
195 - def get(self, data):
196 data['option']=self._option_rb.GetSelection()
197
200 ID_ADD=wx.NewId()
201 ID_MERGE=wx.NewId()
202 - def __init__(self, parent, id=-1, title='Calendar Import Wizard'):
203 super(ImportCalendarWizard, self).__init__(parent, id, title)
204 self._data={}
205 _import_type_page=ImportTypePage(self)
206 _import_source_page=ImportSourcePage(self)
207 _import_data_all=ImportDataAll(self)
208 _import_option=ImportOptionPage(self)
209
210 wiz.WizardPageSimple_Chain(_import_type_page, _import_source_page)
211 wiz.WizardPageSimple_Chain(_import_source_page, _import_data_all)
212 wiz.WizardPageSimple_Chain(_import_data_all, _import_option)
213 self.first_page=_import_type_page
214 self.GetPageAreaSizer().Add(self.first_page, 1, wx.EXPAND|wx.ALL, 5)
215 wiz.EVT_WIZARD_PAGE_CHANGING(self, self.GetId(), self.OnPageChanging)
216 wiz.EVT_WIZARD_PAGE_CHANGED(self, self.GetId(), self.OnPageChanged)
217
220
221 - def OnPageChanging(self, evt):
222 pg=evt.GetPage()
223 if not evt.GetDirection() or pg.ok():
224 pg.get(self._data)
225 else:
226 evt.Veto()
227
228 - def OnPageChanged(self, evt):
229 evt.GetPage().set(self._data)
230
232 if self._data.get('data_obj', None):
233 return self._data['data_obj'].get()
234 return {}
235
239 if self._data.get('data_obj', None):
240 return self._data['data_obj'].get_category_list()
241 return []
242
250
251
252
253 if __name__=="__main__":
254 app=wx.PySimpleApp()
255 f=wx.Frame(None, title='imp_cal_wizard')
256 w=ImportCalendarWizard(f)
257 print w.RunWizard()
258 print w.get()
259 w.Destroy()
260