Update manufacturer mappings.
[wammu.git] / Wammu / Settings.py
blob4653d7f90735d3dfb857a7c43140e641428da147
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 Settings dialog
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2008 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 '''
26 import wx
27 import wx.lib.rcsizer
28 from wx.lib.filebrowsebutton import FileBrowseButton
29 from wx.lib.masked.timectrl import TimeCtrl
30 import os
31 import sys
32 import Wammu
33 import Wammu.GammuSettings
34 import Wammu.PhoneWizard
36 class Settings(wx.Dialog):
37 def __init__(self, parent, config):
38 wx.Dialog.__init__(self, parent, -1, _('Settings'), style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
40 # notebook
41 self.notebook= wx.Notebook(self, -1)
42 self.notebook_gammu = wx.Panel(self.notebook, -1)
43 self.notebook_connection = wx.Panel(self.notebook, -1)
44 self.notebook_messages = wx.Panel(self.notebook, -1)
45 self.notebook_view = wx.Panel(self.notebook, -1)
46 self.notebook_other = wx.Panel(self.notebook, -1)
47 self.notebook_hacks = wx.Panel(self.notebook, -1)
49 # main layout
50 self.sizer = wx.lib.rcsizer.RowColSizer()
52 self.sizer.AddGrowableCol(2)
53 self.sizer.AddGrowableRow(1)
55 self.sizer.AddSpacer(1, 1, pos = (0, 0))
56 self.sizer.AddSpacer(1, 1, pos = (0, 4))
58 self.sizer.Add(self.notebook, pos = (1, 1), colspan = 3, flag = wx.EXPAND)
60 self.sizer.Add(wx.StaticLine(self, -1), pos = (2, 1), colspan = 3, flag = wx.EXPAND)
62 self.button_sizer = wx.StdDialogButtonSizer()
63 self.button_sizer.AddButton(wx.Button(self, wx.ID_OK))
64 self.button_sizer.AddButton(wx.Button(self, wx.ID_CANCEL))
65 self.button_sizer.Realize()
67 self.sizer.Add(self.button_sizer, pos = (3, 1), colspan = 3, flag = wx.ALIGN_RIGHT)
69 self.sizer.AddSpacer(1, 1, pos = (4, 0), colspan = 5)
71 self.config = config
72 self.gammu_config = config.gammu
74 # gammu tab
75 self.sizer_gammu = wx.lib.rcsizer.RowColSizer()
77 self.sizer_gammu.AddGrowableCol(1)
79 self.sizer_gammu.AddSpacer(1, 1, pos = (0, 0))
80 r = 1
82 self.editcfgpath = wx.lib.filebrowsebutton.FileBrowseButton(self.notebook_gammu,
83 size = (250, -1),
84 labelText = '',
85 initialValue = config.Read('/Gammu/Gammurc', False),
86 toolTip = _('Please enter here path to gammu configuration file you want to use.'),
87 changeCallback = self.OnConfigChange,
88 fileMode = wx.OPEN)
89 self.sizer_gammu.Add(wx.StaticText(self.notebook_gammu, -1, _('Gammurc path')), pos = (r, 1), flag = wx.ALIGN_CENTER_VERTICAL)
90 self.sizer_gammu.Add(self.editcfgpath, pos = (r, 2), flag = wx.EXPAND)
91 r += 1
93 self.sizer_gammu.Add(wx.StaticText(self.notebook_gammu, -1, _('You can configure connection parameters on Connection tab.')), pos = (r, 1), colspan = 2)
94 r += 1
96 self.sizer_gammu.AddSpacer(1, 1, pos = (r, 3))
97 r += 1
99 self.editauto = wx.CheckBox(self.notebook_gammu, -1, _('Automatically connect to phone on startup'))
100 self.editauto.SetToolTipString(_('Whether you want application automatically connect to phone when it is started.'))
101 self.editauto.SetValue(config.Read('/Wammu/AutoConnect') == 'yes')
102 self.sizer_gammu.Add(self.editauto, pos = (r, 1), colspan = 2)
103 r += 1
105 self.editdebug = wx.CheckBox(self.notebook_gammu, -1, _('Show debug log'))
106 self.editdebug.SetToolTipString(_('Show debug information on error output.'))
107 self.editdebug.SetValue(config.Read('/Debug/Show') == 'yes')
108 self.sizer_gammu.Add(self.editdebug, pos = (r, 1), colspan = 2)
109 r += 1
111 self.editsync = wx.CheckBox(self.notebook_gammu, -1, _('Synchronize time'))
112 self.editsync.SetToolTipString(_('Synchronise time in phone with computer time while connecting.'))
113 self.editsync.SetValue(config.Read('/Gammu/SyncTime') == 'yes')
114 self.sizer_gammu.Add(self.editsync, pos = (r, 1), colspan = 2)
115 r += 1
117 self.editinfo = wx.CheckBox(self.notebook_gammu, -1, _('Startup information'))
118 self.editinfo.SetToolTipString(_('Display startup on phone (not supported by all models).'))
119 self.editinfo.SetValue(config.Read('/Gammu/StartInfo') == 'yes')
120 self.sizer_gammu.Add(self.editinfo, pos = (r, 1), colspan = 2)
121 r += 1
123 if sys.platform != 'win32':
124 # locking not available on windoze
125 self.editlock = wx.CheckBox(self.notebook_gammu, -1, _('Lock device'))
126 self.editlock.SetToolTipString(_('Whether to lock device in /var/lock. On some systems you might lack privileges to do so.'))
127 self.editlock.SetValue(config.Read('/Gammu/LockDevice') == 'yes')
128 self.sizer_gammu.Add(self.editlock, pos = (r, 1), colspan = 2)
129 r += 1
131 self.sizer_gammu.AddSpacer(1, 1, pos = (r, 3))
133 # size gammu tab
134 self.notebook_gammu.SetAutoLayout(True)
135 self.notebook_gammu.SetSizer(self.sizer_gammu)
136 self.sizer_gammu.Fit(self.notebook_gammu)
137 self.sizer_gammu.SetSizeHints(self.notebook_gammu)
139 # connection tab
140 self.sizer_connection = wx.lib.rcsizer.RowColSizer()
142 self.sizer_connection.AddGrowableCol(1)
144 self.sizer_connection.AddSpacer(1, 1, pos = (0, 0))
145 r = 1
147 lst, choices = config.gammu.GetConfigList()
148 self.editsection = wx.Choice(self.notebook_connection, choices = choices, size = (250, -1))
149 section = config.ReadInt('/Gammu/Section')
150 for i in range(len(lst)):
151 if lst[i]['Id'] == section:
152 self.editsection.SetSelection(i)
153 break
154 self.sizer_connection.Add(wx.StaticText(self.notebook_connection, -1, _('Phone connection')), pos = (r, 1), rowspan = 2, flag = wx.ALIGN_CENTER_VERTICAL)
155 self.sizer_connection.Add(self.editsection, pos = (r, 2))
156 self.Bind(wx.EVT_CHOICE, self.OnConnectionChange, self.editsection)
157 r += 1
159 self.addsection = wx.Button(self.notebook_connection, wx.ID_ADD)
160 self.sizer_connection.Add(self.addsection, pos = (r, 2), flag = wx.EXPAND)
161 r += 1
163 self.sizer_connection.AddSpacer(1, 1, pos = (r, 3))
164 r += 1
166 self.editname = wx.TextCtrl(self.notebook_connection, -1, '', size = (250, -1))
167 self.editname.SetToolTipString(_('Name for this configuration.'))
168 self.sizer_connection.Add(wx.StaticText(self.notebook_connection, -1, _('Name')), pos = (r, 1), flag = wx.ALIGN_CENTER_VERTICAL)
169 self.sizer_connection.Add(self.editname, pos = (r, 2))
170 r += 1
172 self.editdev = wx.ComboBox(self.notebook_connection, -1, '', choices = Wammu.Data.Devices, size = (150, -1))
173 self.editdev.SetToolTipString(_('Device, where your phone is connected.'))
174 self.sizer_connection.Add(wx.StaticText(self.notebook_connection, -1, _('Device')), pos = (r, 1), flag = wx.ALIGN_CENTER_VERTICAL)
175 self.sizer_connection.Add(self.editdev, pos = (r, 2), flag = wx.ALIGN_RIGHT | wx.EXPAND)
176 r += 1
178 self.editconn = wx.ComboBox(self.notebook_connection, -1, '', choices = Wammu.Data.Connections, size = (150, -1))
179 self.editconn.SetToolTipString(_('Connection which your phone understands, check Gammu documentation for connection details.'))
180 self.sizer_connection.Add(wx.StaticText(self.notebook_connection, -1, _('Connection')), pos = (r, 1), flag = wx.ALIGN_CENTER_VERTICAL)
181 self.sizer_connection.Add(self.editconn, pos = (r, 2), flag = wx.ALIGN_RIGHT | wx.EXPAND)
182 r += 1
184 self.editmodel = wx.ComboBox(self.notebook_connection, -1, '', choices = Wammu.Data.Models, size = (150, -1))
185 self.editmodel.SetToolTipString(_('Phone model, you can usually keep here auto unless you have any problems.'))
186 if self.editmodel.GetValue() == '':
187 self.editmodel.SetValue('auto')
188 self.sizer_connection.Add(wx.StaticText(self.notebook_connection, -1, _('Model')), pos = (r, 1), flag = wx.ALIGN_CENTER_VERTICAL)
189 self.sizer_connection.Add(self.editmodel, pos = (r, 2), flag = wx.ALIGN_RIGHT | wx.EXPAND)
190 r += 1
192 # Initialise above fields
193 self.OnConnectionChange()
195 self.sizer_connection.AddSpacer(1, 1, pos = (r, 3))
197 # size connection tab
198 self.notebook_connection.SetAutoLayout(True)
199 self.notebook_connection.SetSizer(self.sizer_connection)
200 self.sizer_connection.Fit(self.notebook_connection)
201 self.sizer_connection.SetSizeHints(self.notebook_connection)
203 # messages tab
204 self.sizer_messages = wx.lib.rcsizer.RowColSizer()
206 self.sizer_messages.AddGrowableCol(1)
208 self.sizer_messages.AddSpacer(1, 1, pos = (0, 0))
209 r = 1
211 v = config.ReadInt('/Message/ScaleImage')
212 self.editscale = wx.SpinCtrl(self.notebook_messages, -1, str(v), style = wx.SP_WRAP|wx.SP_ARROW_KEYS, min = 1, max = 20, initial = v, size = (150, -1))
213 self.editscale.SetToolTipString(_('Whether images in messages should be scaled when displayed. This is usually good idea as they are pretty small.'))
214 self.sizer_messages.Add(wx.StaticText(self.notebook_messages, -1, _('Scale images')), pos = (r, 1))
215 self.sizer_messages.Add(self.editscale, pos = (r, 2))
216 r += 1
218 self.editformat = wx.CheckBox(self.notebook_messages, -1, _('Attempt to reformat text'))
219 self.editformat.SetToolTipString(_('If you get sometimes "compressed" messages likeTHIStext, you should be interested in this choice.'))
220 self.editformat.SetValue(config.Read('/Message/Format') == 'yes')
221 self.sizer_messages.Add(self.editformat, pos = (r, 1), colspan = 2)
222 r += 1
224 # options for new message
225 self.new_message_panel = wx.Panel(self.notebook_messages, -1)
226 self.sizer_messages.Add(self.new_message_panel, pos = (r, 1), colspan = 2, flag = wx.EXPAND)
227 r += 1
229 self.sizer_message_new = wx.StaticBoxSizer(wx.StaticBox(self.new_message_panel, -1, 'Default options for new message'), wx.HORIZONTAL)
230 self.new_message_panel_2 = wx.Panel(self.new_message_panel, -1)
231 self.sizer_message_new.Add(self.new_message_panel_2, 1, wx.EXPAND, 0)
233 self.sizer_message_new_2 = wx.lib.rcsizer.RowColSizer()
235 self.sizer_message_new_2.AddGrowableCol(1)
237 r2 = 0
239 self.editconcat = wx.CheckBox(self.new_message_panel_2, -1, _('Concatenated'))
240 self.editconcat.SetToolTipString(_('Create concatenated message, what allows to send longer messages.'))
241 self.editconcat.SetValue(config.Read('/Message/Concatenated') == 'yes')
242 self.sizer_message_new_2.Add(self.editconcat, pos = (r2, 0), colspan = 2)
243 r2 += 1
245 self.editunicode = wx.CheckBox(self.new_message_panel_2, -1, _('Create unicode message'))
246 self.editunicode.SetToolTipString(_('Unicode messages can contain national and other special characters, check this if you use non latin-1 characters. Your messages will require more space, so you can write less characters into single message.'))
247 self.editunicode.SetValue(config.Read('/Message/Unicode') == 'yes')
248 self.sizer_message_new_2.Add(self.editunicode, pos = (r2, 0), colspan = 2)
249 r2 += 1
251 self.editreport = wx.CheckBox(self.new_message_panel_2, -1, _('Request delivery report by default'))
252 self.editreport.SetToolTipString(_('Check to request delivery report for message.'))
253 self.editreport.SetValue(config.Read('/Message/DeliveryReport') == 'yes')
254 self.sizer_message_new_2.Add(self.editreport, pos = (r2, 0), colspan = 2)
255 r2 += 1
257 self.edit16bit = wx.CheckBox(self.new_message_panel_2, -1, _('Use 16bit Id'))
258 self.edit16bit.SetToolTipString(_('Use 16 bit Id inside message. This is safe for most cases.'))
259 self.edit16bit.SetValue(config.Read('/Message/16bitId') == 'yes')
260 self.sizer_message_new_2.Add(self.edit16bit, pos = (r2, 0), colspan = 2)
261 r2 += 1
263 self.new_message_panel_2.SetAutoLayout(True)
264 self.new_message_panel_2.SetSizer(self.sizer_message_new_2)
265 self.sizer_message_new_2.Fit(self.new_message_panel_2)
266 self.sizer_message_new_2.SetSizeHints(self.new_message_panel_2)
268 self.new_message_panel.SetAutoLayout(True)
269 self.new_message_panel.SetSizer(self.sizer_message_new)
270 self.sizer_message_new.Fit(self.new_message_panel)
271 self.sizer_message_new.SetSizeHints(self.new_message_panel)
273 self.sizer_messages.AddSpacer(1, 1, pos = (r, 3))
275 # size messages tab
276 self.notebook_messages.SetAutoLayout(True)
277 self.notebook_messages.SetSizer(self.sizer_messages)
278 self.sizer_messages.Fit(self.notebook_messages)
279 self.sizer_messages.SetSizeHints(self.notebook_messages)
281 # view tab
282 self.sizer_view = wx.lib.rcsizer.RowColSizer()
284 self.sizer_view.AddGrowableCol(1)
286 self.sizer_view.AddSpacer(1, 1, pos = (0, 0))
287 r = 1
289 v = config.Read('/Wammu/NameFormat')
290 self.editnameformat = wx.Choice(self.notebook_view, choices = [
291 _('Automatic'),
292 _('Automatic starting with first name'),
293 _('Automatic starting with last name'),
294 _('Custom, use format string bellow')
295 ], size = (250, -1))
296 if v == 'auto':
297 self.editnameformat.SetSelection(0)
298 elif v == 'auto-first-last':
299 self.editnameformat.SetSelection(1)
300 elif v == 'auto-last-first':
301 self.editnameformat.SetSelection(2)
302 elif v == 'custom':
303 self.editnameformat.SetSelection(3)
304 self.sizer_view.Add(wx.StaticText(self.notebook_view, -1, _('Name display format')), pos = (r, 1))
305 self.sizer_view.Add(self.editnameformat, pos = (r, 2), flag = wx.EXPAND)
306 self.Bind(wx.EVT_CHOICE, self.OnNameFormatChange, self.editnameformat)
307 r += 1
309 v = config.Read('/Wammu/NameFormatString')
310 self.editnamestring = wx.ComboBox(self.notebook_view, -1, v, choices = [
312 '%(FirstName)s %(LastName)s (%(Company)s)',
313 '%(LastName)s, %(FirstName)s (%(Company)s)',
314 '%(LastName)s, %(FirstName)s (%(NickName)s)',
316 # l10n: The %s will be replaced by list of currently supported tags, %%(value)s should be kept intact (you can translate word value).
317 self.editnamestring.SetToolTipString(_('Format string for name displaying. You can use %%(value)s format marks. Currently available values are: %s.') %
318 'Name, FirstName, LastName, NickName, FormalName, Company')
319 self.sizer_view.Add(wx.StaticText(self.notebook_view, -1, _('Name format string')), pos = (r, 1), flag = wx.ALIGN_CENTER_VERTICAL)
320 self.sizer_view.Add(self.editnamestring, pos = (r, 2), flag = wx.ALIGN_RIGHT | wx.EXPAND)
321 r += 1
323 self.sizer_view.AddSpacer(1, 1, pos = (r, 3))
325 # size view tab
326 self.notebook_view.SetAutoLayout(True)
327 self.notebook_view.SetSizer(self.sizer_view)
328 self.sizer_view.Fit(self.notebook_view)
329 self.sizer_view.SetSizeHints(self.notebook_view)
331 # other tab
332 self.sizer_other = wx.lib.rcsizer.RowColSizer()
334 self.sizer_other.AddGrowableCol(1)
336 self.sizer_other.AddSpacer(1, 1, pos = (0, 0))
337 r = 1
339 v = config.ReadInt('/Wammu/RefreshState')
340 self.editrefresh = wx.SpinCtrl(self.notebook_other, -1, str(v), style = wx.SP_WRAP|wx.SP_ARROW_KEYS, min = 0, max = 10000000, initial = v, size = (150, -1))
341 self.editrefresh.SetToolTipString(_('How often refresh phone state in application status bar. Enter value in miliseconds, 0 to disable.'))
342 self.sizer_other.Add(wx.StaticText(self.notebook_other, -1, _('Refresh phone state')), pos = (r, 1))
343 self.sizer_other.Add(self.editrefresh, pos = (r, 2))
344 r += 1
346 self.editconfirm = wx.CheckBox(self.notebook_other, -1, _('Confirm deleting'))
347 self.editconfirm.SetToolTipString(_('Whether to ask for confirmation when deleting entries.'))
348 self.editconfirm.SetValue(config.Read('/Wammu/ConfirmDelete') == 'yes')
349 self.sizer_other.Add(self.editconfirm, pos = (r, 1), colspan = 2)
350 r += 1
352 self.taskbaricon = wx.CheckBox(self.notebook_other, -1, _('Task bar icon'))
353 self.taskbaricon.SetToolTipString(_('Show icon in task bar.'))
354 self.taskbaricon.SetValue(config.Read('/Wammu/TaskBarIcon') == 'yes')
355 self.sizer_other.Add(self.taskbaricon, pos = (r, 1), colspan = 2)
356 r += 1
358 dtime = config.Read('/Wammu/DefaultTime')
359 try:
360 times = dtime.split(':')
361 th = int(times[0])
362 tm = int(times[1])
363 ts = int(times[2])
364 except:
365 th = 9
366 tm = 0
367 ts = 0
368 self.edittime = TimeCtrl(self.notebook_other, -1, fmt24hr = True)
369 Wammu.Utils.FixupMaskedEdit(self.edittime)
370 self.edittime.SetValue(wx.DateTimeFromHMS(th, tm, ts))
371 self.edittime.SetToolTipString(_('Default time to be used for newly created time fields.'))
372 self.sizer_other.Add(wx.StaticText(self.notebook_other, -1, _('Default time')), pos = (r, 1))
373 self.sizer_other.Add(self.edittime, pos = (r, 2))
374 r += 1
376 v = config.ReadInt('/Wammu/DefaultDateOffset')
377 self.editdate = wx.SpinCtrl(self.notebook_other, -1, str(v), style = wx.SP_WRAP|wx.SP_ARROW_KEYS, min = -10000000, max = 10000000, initial = v, size = (150, -1))
378 self.editdate.SetToolTipString(_('Default date to be used for newly created time fields. Enter amount of days from today (1 = tommorow).'))
379 self.sizer_other.Add(wx.StaticText(self.notebook_other, -1, _('Default date = now + x days')), pos = (r, 1))
380 self.sizer_other.Add(self.editdate, pos = (r, 2))
381 r += 1
383 v = config.ReadInt('/Wammu/DefaultEntries')
384 self.editentries = wx.SpinCtrl(self.notebook_other, -1, str(v), style = wx.SP_WRAP|wx.SP_ARROW_KEYS, min = 0, max = 20, initial = v, size = (150, -1))
385 self.editentries.SetToolTipString(_('How many entries will be shown in newly created item.'))
386 self.sizer_other.Add(wx.StaticText(self.notebook_other, -1, _('Entries for new item')), pos = (r, 1))
387 self.sizer_other.Add(self.editentries, pos = (r, 2))
388 r += 1
390 lst = ['Auto']
391 lst += Wammu.Data.InternationalPrefixes
392 self.editprefix = wx.ComboBox(self.notebook_other, -1, config.Read('/Wammu/PhonePrefix'), choices = lst, size = (150, -1))
393 self.editprefix.SetToolTipString(_('Prefix for non international phone numbers.'))
394 self.sizer_other.Add(wx.StaticText(self.notebook_other, -1, _('Number prefix')), pos = (r, 1))
395 self.sizer_other.Add(self.editprefix, pos = (r, 2))
396 r += 1
398 self.sizer_other.AddSpacer(1, 1, pos = (r, 3))
400 # size other tab
401 self.notebook_other.SetAutoLayout(True)
402 self.notebook_other.SetSizer(self.sizer_other)
403 self.sizer_other.Fit(self.notebook_other)
404 self.sizer_other.SetSizeHints(self.notebook_other)
406 # hacks tab
407 self.sizer_hacks = wx.lib.rcsizer.RowColSizer()
409 self.sizer_hacks.AddGrowableCol(1)
411 self.sizer_hacks.AddSpacer(1, 1, pos = (0, 0))
412 r = 1
414 v = config.ReadInt('/Hacks/MaxEmptyGuess')
415 self.editmaxemptyguess = wx.SpinCtrl(self.notebook_hacks, -1, str(v), style = wx.SP_WRAP|wx.SP_ARROW_KEYS, min = 0, max = 10000000, initial = v, size = (150, -1))
416 self.editmaxemptyguess.SetToolTipString(_('When Wammu encounters continuous this count of empty entries when reading items from phone where total count was guessed, it assumes that rest is empty.'))
417 self.sizer_hacks.Add(wx.StaticText(self.notebook_hacks, -1, _('Maximal empty entries if total is guessed')), pos = (r, 1))
418 self.sizer_hacks.Add(self.editmaxemptyguess, pos = (r, 2))
419 r += 1
421 v = config.ReadInt('/Hacks/MaxEmptyKnown')
422 self.editmaxemptyknown = wx.SpinCtrl(self.notebook_hacks, -1, str(v), style = wx.SP_WRAP|wx.SP_ARROW_KEYS, min = 0, max = 10000000, initial = v, size = (150, -1))
423 self.editmaxemptyknown.SetToolTipString(_('When Wammu encounters continuous this count of empty entries when reading items from phone which have known total count, it assumes that rest is empty.'))
424 self.sizer_hacks.Add(wx.StaticText(self.notebook_hacks, -1, _('Maximal empty entries if total is known')), pos = (r, 1))
425 self.sizer_hacks.Add(self.editmaxemptyknown, pos = (r, 2))
426 r += 1
428 self.sizer_hacks.AddSpacer(1, 1, pos = (r, 3))
430 # size hacks tab
431 self.notebook_hacks.SetAutoLayout(True)
432 self.notebook_hacks.SetSizer(self.sizer_hacks)
433 self.sizer_hacks.Fit(self.notebook_hacks)
434 self.sizer_hacks.SetSizeHints(self.notebook_hacks)
436 # add pages to notebook
437 self.notebook.AddPage(self.notebook_gammu, _('Gammu'))
438 self.notebook.AddPage(self.notebook_connection, _('Connection'))
439 self.notebook.AddPage(self.notebook_messages, _('Messages'))
440 self.notebook.AddPage(self.notebook_view, _('View'))
441 self.notebook.AddPage(self.notebook_other, _('Other'))
442 self.notebook.AddPage(self.notebook_hacks, _('Hacks'))
444 # size main layout
445 self.SetAutoLayout(True)
446 self.SetSizer(self.sizer)
447 self.sizer.Fit(self)
448 self.sizer.SetSizeHints(self)
450 # workaround, when sizers don't set correct size
451 sz = self.GetSize()
452 if sz.y < 150:
453 self.SetSize((400, 400))
455 # Intialise fields
456 self.OnNameFormatChange()
458 # event handlers
459 self.Bind(wx.EVT_BUTTON, self.Okay, id = wx.ID_OK)
460 self.Bind(wx.EVT_BUTTON, self.AddPhone, id = wx.ID_ADD)
462 def OnNameFormatChange(self, evt = None):
463 selection = self.editnameformat.GetSelection()
464 if selection < 0:
465 selection = 0
466 if selection == 3:
467 self.editnamestring.Enable(True)
468 else:
469 self.editnamestring.Enable(False)
471 def OnConnectionChange(self, evt = None):
472 selection = self.editsection.GetSelection()
473 if selection < 0:
474 selection = 0
475 lst, choices = self.gammu_config.GetConfigList()
476 if len(lst) == 0:
477 self.editdev.Enable(False)
478 self.editmodel.Enable(False)
479 self.editname.Enable(False)
480 self.editconn.Enable(False)
481 return
483 self.editdev.Enable(True)
484 self.editmodel.Enable(True)
485 self.editname.Enable(True)
486 self.editconn.Enable(True)
487 current = lst[selection]
488 gammu = self.gammu_config.GetConfig(current['Id'])
489 self.editdev.SetValue(gammu['Device'])
490 self.editmodel.SetValue(gammu['Model'])
491 self.editname.SetValue(gammu['Name'])
492 self.editconn.SetValue(gammu['Connection'])
494 def OnConfigChange(self, evt = None):
495 # temporarily change gammu config data
496 newpath = self.editcfgpath.GetValue()
497 self.gammu_config = Wammu.GammuSettings.GammuSettings(self.config, os.path.expanduser(newpath))
498 self.RereadConfig()
500 def RereadConfig(self):
501 lst, choices = self.gammu_config.GetConfigList()
502 self.editsection.Clear()
503 for x in choices:
504 self.editsection.Append(x)
505 if len(choices) > 0:
506 self.editsection.SetSelection(0)
507 self.OnConnectionChange()
509 def AddPhone(self, evt = None):
510 index = self.gammu_config.FirstFree()
511 result = Wammu.PhoneWizard.RunConfigureWizard(self, index)
512 if result is not None:
513 self.gammu_config.SetConfig(result['Position'], result['Device'], result['Connection'], result['Name'])
514 self.RereadConfig()
515 lst, choices = self.gammu_config.GetConfigList()
516 self.editsection.SetSelection(len(lst) - 1)
517 self.OnConnectionChange()
519 def Okay(self, evt):
520 lst, choices = self.config.gammu.GetConfigList()
522 # Check whether we have some configuration
523 if len(lst) == 0:
524 wx.MessageDialog(self,
525 _('You don\'t have any phone connection configured. Wammu will not be able to conect to your phone!'),
526 _('No phone configured!'),
527 wx.OK | wx.ICON_ERROR).ShowModal()
528 else:
529 current = lst[self.editsection.GetSelection()]
530 self.config.gammu = self.gammu_config
531 self.config.gammu.SetConfig(current['Id'],
532 self.editdev.GetValue(),
533 self.editconn.GetValue(),
534 self.editname.GetValue(),
535 self.editmodel.GetValue())
536 self.config.Write('/Gammu/Gammurc', self.editcfgpath.GetValue())
537 self.config.WriteInt('/Gammu/Section', current['Id'])
539 if self.editsync.GetValue():
540 value = 'yes'
541 else:
542 value = 'no'
543 self.config.Write('/Gammu/SyncTime', value)
544 if sys.platform != 'win32':
545 if self.editlock.GetValue():
546 value = 'yes'
547 else:
548 value = 'no'
549 self.config.Write('/Gammu/LockDevice', value)
550 if self.editinfo.GetValue():
551 value = 'yes'
552 else:
553 value = 'no'
554 self.config.Write('/Gammu/StartInfo', value)
555 if self.editdebug.GetValue():
556 value = 'yes'
557 else:
558 value = 'no'
559 self.config.Write('/Debug/Show', value)
560 if self.editauto.GetValue():
561 value = 'yes'
562 else:
563 value = 'no'
564 self.config.Write('/Wammu/AutoConnect', value)
565 if self.editformat.GetValue():
566 value = 'yes'
567 else:
568 value = 'no'
569 self.config.Write('/Message/Format', value)
570 if self.editconcat.GetValue():
571 value = 'yes'
572 else:
573 value = 'no'
574 self.config.Write('/Message/Concatenated', value)
575 if self.editunicode.GetValue():
576 value = 'yes'
577 else:
578 value = 'no'
579 self.config.Write('/Message/Unicode', value)
580 if self.editreport.GetValue():
581 value = 'yes'
582 else:
583 value = 'no'
584 self.config.Write('/Message/DeliveryReport', value)
585 if self.edit16bit.GetValue():
586 value = 'yes'
587 else:
588 value = 'no'
589 self.config.Write('/Message/16bitId', value)
590 self.config.WriteInt('/Message/ScaleImage', self.editscale.GetValue())
591 self.config.WriteInt('/Wammu/RefreshState', self.editrefresh.GetValue())
592 if self.editconfirm.GetValue():
593 value = 'yes'
594 else:
595 value = 'no'
596 self.config.Write('Wammu/ConfirmDelete', value)
597 if self.taskbaricon.GetValue():
598 value = 'yes'
599 else:
600 value = 'no'
601 self.config.Write('/Wammu/TaskBarIcon', value)
602 self.config.Write('Wammu/DefaultTime', self.edittime.GetValue())
603 self.config.WriteInt('/Wammu/DefaultDateOffset', self.editdate.GetValue())
604 self.config.WriteInt('/Wammu/DefaultEntries', self.editentries.GetValue())
605 self.config.Write('/Wammu/PhonePrefix', self.editprefix.GetValue())
606 self.config.Write('/Wammu/NameFormat', self.editnamestring.GetValue())
607 ind = self.editnameformat.GetSelection()
608 if ind == 0:
609 val = 'auto'
610 elif ind == 1:
611 val = 'auto-first-last'
612 elif ind == 2:
613 val = 'auto-last-first'
614 elif ind == 3:
615 val = 'custom'
616 else:
617 raise Exception('Invalid NameFormatString id: %d' % ind)
618 self.config.Write('/Wammu/NameFormat', val)
620 self.config.WriteInt('/Hacks/MaxEmptyGuess', self.editmaxemptyguess.GetValue())
621 self.config.WriteInt('/Hacks/MaxEmptyKnown', self.editmaxemptyknown.GetValue())
622 self.EndModal(wx.ID_OK)