Update locales.
[wammu.git] / Wammu / Composer.py
blobcb2a200f8a9503d80b0e5f9fc1f6ff3f0a28ef21
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 SMS composer
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.editor.editor
28 import wx.lib.mixins.listctrl
29 import Wammu
30 import Wammu.Data
31 import Wammu.MessageDisplay
32 import Wammu.Utils
33 import Wammu.PhoneValidator
34 import Wammu.Select
35 import Wammu.EditContactList
36 if Wammu.gammu_error == None:
37 import gammu
38 import locale
39 import Wammu.Locales
41 class MessagePreview(wx.Dialog):
42 text = '''
43 <html>
44 <body>
46 <center>
47 <p><wxp module="wx" class="Button">
48 <param name="id" value="ID_OK">
49 </wxp></p>
50 </center>
51 </body>
52 </html>
53 '''
55 def __init__(self, parent, content):
56 wx.Dialog.__init__(self, parent, -1, _('Message preview'))
57 html = wx.html.HtmlWindow(self, -1, size=(420, -1))
58 html.SetPage(self.text % content)
59 btn = html.FindWindowById(wx.ID_OK)
60 btn.SetDefault()
61 ir = html.GetInternalRepresentation()
62 html.SetSize( (ir.GetWidth()+25, ir.GetHeight()+25) )
63 self.SetClientSize(html.GetSize())
64 self.CentreOnParent(wx.BOTH)
66 class StyleEdit(wx.Dialog):
67 def __init__(self, parent, entry):
68 wx.Dialog.__init__(self, parent, -1, _('Text style'))
70 self.sizer = wx.GridBagSizer()
72 self.entry = entry
74 self.fmt = {}
76 row = 1
78 col = 1
79 maxcol = 1
81 for x in Wammu.Data.TextFormats:
82 if len(x) == 2:
83 name = x[1][0]
84 text = x[1][1]
85 self.fmt[name] = wx.CheckBox(self, -1, text)
86 if self.entry.has_key(name):
87 self.fmt[name].SetValue(self.entry[name])
88 self.sizer.Add(self.fmt[name], pos = (row, col))
89 col = col + 2
90 else:
91 if col > 1:
92 row = row + 2
93 maxcol = max(col, maxcol)
94 col = 1
96 self.sizer.Add(wx.StaticText(self, -1, x[0][0] + ':'), pos = (row, col))
97 col = col + 2
99 rb = wx.RadioButton(self, -1, x[0][1], style = wx.RB_GROUP)
100 rb.SetValue(True)
101 self.sizer.Add(rb, pos = (row, col))
102 col = col + 2
103 for name, text, fmt in x[1:]:
104 self.fmt[name] = wx.RadioButton(self, -1, text)
105 if self.entry.has_key(name):
106 self.fmt[name].SetValue(self.entry[name])
107 self.sizer.Add(self.fmt[name], pos = (row, col))
108 col = col + 2
109 row = row + 2
110 maxcol = max(col, maxcol)
111 col = 1
113 if col > 1:
114 row = row + 2
115 maxcol = max(col, maxcol)
116 col = 1
118 self.ok = wx.Button(self, wx.ID_OK)
119 self.sizer.Add(self.ok, pos = (row, 1), span = wx.GBSpan(colspan = maxcol), flag = wx.ALIGN_CENTER)
120 wx.EVT_BUTTON(self, wx.ID_OK, self.Okay)
122 self.sizer.AddSpacer((5,5), pos=(row + 1, maxcol + 1))
124 self.sizer.Fit(self)
125 self.SetAutoLayout(True)
126 self.SetSizer(self.sizer)
128 self.CentreOnParent(wx.BOTH)
130 def Okay(self, evt):
131 for x in Wammu.Data.TextFormats:
132 for name, text, fmt in x[1:]:
133 self.entry[name] = self.fmt[name].GetValue()
134 self.EndModal(wx.ID_OK)
136 class AutoSizeList(wx.ListCtrl, wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin):
137 def __init__(self, parent, firstcol):
138 wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT | wx.LC_HRULES | wx.LC_VRULES | wx.LC_SINGLE_SEL | wx.SUNKEN_BORDER, size = (-1, 100))
139 self.InsertColumn(0, firstcol)
140 wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin.__init__(self)
142 class GenericEditor(wx.Panel):
144 Generic class for static text with some edit control.
146 def __init__(self, parent, part, cfg, unicode):
147 wx.Panel.__init__(self, parent, -1, style = wx.RAISED_BORDER)
148 self.part = part
149 self.cfg = cfg
150 self.unicode = unicode
152 class TextEditor(GenericEditor):
153 def __init__(self, parent, cfg ,part, unicode):
154 GenericEditor.__init__(self, parent, cfg, part, unicode)
156 self.backuptext = ''
158 self.sizer = wx.GridBagSizer()
160 self.edit = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE)
162 self.sizer.Add(self.edit, pos = (0,0), flag = wx.EXPAND, span = wx.GBSpan(colspan = 4))
163 self.sizer.AddGrowableCol(1)
164 self.sizer.AddGrowableCol(2)
165 self.sizer.AddGrowableRow(0)
167 self.concat = wx.CheckBox(self, -1, _('Concatenated'))
168 self.concat.SetToolTipString(_('Create concatenated message, what allows to send longer messages.'))
169 self.concat.SetValue(self.part['ID'] != 'Text')
170 wx.EVT_CHECKBOX(self.concat, self.concat.GetId(), self.OnConcatChange)
171 self.sizer.Add(self.concat, pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
173 self.leninfo = wx.StaticText(self, -1, '')
174 self.sizer.Add(self.leninfo, pos = (1, 3), flag = wx.ALIGN_RIGHT)
176 self.stylebut = wx.Button(self, -1, _('Style'))
177 wx.EVT_BUTTON(self, self.stylebut.GetId(), self.StylePressed)
178 self.sizer.Add(self.stylebut, pos = (1, 1), flag = wx.ALIGN_CENTER)
180 self.OnConcatChange()
182 wx.EVT_TEXT(self.edit, self.edit.GetId(), self.TextChanged)
183 if self.part.has_key('Buffer'):
184 self.edit.SetValue(self.part['Buffer'])
186 self.sizer.Fit(self)
187 self.SetAutoLayout(True)
188 self.SetSizer(self.sizer)
189 self.TextChanged()
191 def OnUnicode(self, newu):
192 self.unicode = newu
193 self.CheckTextLen()
195 def OnConcatChange(self, evt = None):
196 self.stylebut.Enable(self.concat.GetValue())
197 self.CheckTextLen()
199 def CheckTextLen(self, evt = None):
200 if not self.concat.GetValue():
201 if self.unicode:
202 self.edit.SetValue(self.edit.GetValue()[:70])
203 else:
204 self.edit.SetValue(self.edit.GetValue()[:160])
206 def StylePressed(self, evt):
207 dlg = StyleEdit(self, self.part)
208 dlg.ShowModal()
209 del dlg
211 def TextChanged(self, evt = None):
212 txt = self.edit.GetValue()
213 length = len(txt)
214 if not self.concat.GetValue() and ((self.unicode and length > 70) or (not self.unicode and length > 160)):
215 self.edit.SetValue(self.backuptext)
216 return
217 length = len(self.edit.GetValue())
218 self.leninfo.SetLabel(Wammu.Locales.ngettext('%d char', '%d chars', length) % length)
219 self.sizer.Layout()
220 self.backuptext = txt
222 def GetValue(self):
223 if self.concat.GetValue():
224 if self.cfg.Read('/Message/16bitId') == 'yes':
225 self.part['ID'] = 'ConcatenatedTextLong16bit'
226 else:
227 self.part['ID'] = 'ConcatenatedTextLong'
228 else:
229 self.part['ID'] = 'Text'
230 self.part['Buffer'] = Wammu.Locales.UnicodeConv(self.edit.GetValue())
231 return self.part
233 class PredefinedAnimEditor(GenericEditor):
234 def __init__(self, parent, part, cfg, unicode):
235 GenericEditor.__init__(self, parent, part, cfg, unicode)
236 self.sizer = wx.GridBagSizer()
238 values = []
239 for x in Wammu.Data.PredefinedAnimations:
240 values.append(x[0])
242 self.sizer.AddGrowableRow(0)
243 self.sizer.AddGrowableCol(0)
244 self.sizer.AddGrowableCol(1)
245 self.sizer.AddGrowableCol(2)
247 self.edit = wx.Choice(self, -1, choices = values)
249 bitmap = wx.BitmapFromXPMData(Wammu.Data.UnknownPredefined)
250 self.bitmap = wx.StaticBitmap(self, -1, bitmap, (0,0))
252 wx.EVT_CHOICE(self.edit, self.edit.GetId(), self.OnChange)
254 if not self.part.has_key('Number'):
255 self.part['Number'] = 0
257 self.edit.SetSelection(self.part['Number'])
258 self.OnChange()
260 self.sizer.Add(wx.StaticText(self, -1, _('Select predefined animation:')), pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL)
261 self.sizer.Add(self.edit, pos = (0,1), flag = wx.ALIGN_CENTER)
262 self.sizer.Add(self.bitmap, pos = (0,2), flag = wx.ALIGN_CENTER)
264 self.sizer.Fit(self)
265 self.SetAutoLayout(True)
266 self.SetSizer(self.sizer)
268 def OnChange(self, evt = None):
269 bitmap = wx.BitmapFromXPMData(Wammu.Data.PredefinedAnimations[self.edit.GetSelection()][1])
270 self.bitmap.SetBitmap(bitmap)
272 def GetValue(self):
273 self.part['ID'] = 'EMSPredefinedAnimation'
274 self.part['Number'] = self.edit.GetSelection()
275 return self.part
277 class PredefinedSoundEditor(GenericEditor):
278 def __init__(self, parent, part, cfg, unicode):
279 GenericEditor.__init__(self, parent, part, cfg, unicode)
280 self.sizer = wx.GridBagSizer()
282 values = []
283 for x in Wammu.Data.PredefinedSounds:
284 values.append(x[0])
286 self.sizer.AddGrowableRow(0)
287 self.sizer.AddGrowableCol(0)
288 self.sizer.AddGrowableCol(1)
290 self.edit = wx.Choice(self, -1, choices = values)
292 if not self.part.has_key('Number'):
293 self.part['Number'] = 0
295 self.edit.SetSelection(self.part['Number'])
297 self.sizer.Add(wx.StaticText(self, -1, _('Select predefined sound:')), pos = (0,0), flag = wx.ALIGN_CENTER_VERTICAL)
298 self.sizer.Add(self.edit, pos = (0,1), flag = wx.ALIGN_CENTER)
300 self.sizer.Fit(self)
301 self.SetAutoLayout(True)
302 self.SetSizer(self.sizer)
304 def GetValue(self):
305 self.part['ID'] = 'EMSPredefinedSound'
306 self.part['Number'] = self.edit.GetSelection()
307 return self.part
309 SMSParts = [
310 # FIXME: should support more types...
311 # ID, display text, match types, editor, init type
312 (0, _('Text'), Wammu.Data.SMSIDs['Text'], TextEditor, 'ConcatenatedTextLong16bit'),
313 (1, _('Predefined animation'), Wammu.Data.SMSIDs['PredefinedAnimation'], PredefinedAnimEditor, 'EMSPredefinedAnimation'),
314 (2, _('Predefined sound'), Wammu.Data.SMSIDs['PredefinedSound'], PredefinedSoundEditor, 'EMSPredefinedSound'),
317 class SMSComposer(wx.Dialog):
318 def __init__(self, parent, cfg, entry, values, action = 'save', addtext = True):
319 wx.Dialog.__init__(self, parent, -1, _('Composing SMS'), style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
320 self.entry = entry
321 self.cfg = cfg
322 self.values = values
323 if not entry.has_key('SMSInfo'):
324 entry['SMSInfo'] = {}
325 entry['SMSInfo']['Entries'] = []
326 if self.cfg.Read('/Message/Concatenated') == 'yes':
327 if self.cfg.Read('/Message/16bitId') == 'yes':
328 typ = 'ConcatenatedTextLong16bit'
329 else:
330 typ = 'ConcatenatedTextLong'
331 else:
332 typ = 'Text'
333 if entry.has_key('Text'):
334 entry['SMSInfo']['Entries'].append({'ID': typ, 'Buffer': entry['Text']})
335 elif addtext:
336 entry['SMSInfo']['Entries'].append({'ID': typ, 'Buffer': ''})
337 if not entry.has_key('Number'):
338 entry['Number'] = ''
340 self.sizer = wx.GridBagSizer()
343 row = 1
345 if not action in ['send', 'save']:
346 action = 'save'
348 self.send = wx.CheckBox(self, -1, _('Send message'))
349 self.send.SetToolTipString(_('When checked, message is sent to recipient.'))
350 self.send.SetValue(action == 'send')
352 self.save = wx.CheckBox(self, -1, _('Save into folder'))
353 self.save.SetToolTipString(_('When checked, message is saved to phone.'))
354 self.save.SetValue(action == 'save')
356 self.Bind(wx.EVT_CHECKBOX, self.OnSave, self.save)
357 self.Bind(wx.EVT_CHECKBOX, self.OnSend, self.send)
359 self.folder = wx.SpinCtrl(self, -1, '2', style = wx.SP_WRAP|wx.SP_ARROW_KEYS , min = 0, max = 100, initial = 2)
361 self.sizer.Add(self.send, pos = (row,1), flag = wx.ALIGN_LEFT)
362 self.sizer.Add(self.save, pos = (row,6), flag = wx.ALIGN_LEFT)
363 self.sizer.Add(self.folder, pos = (row,7), flag = wx.ALIGN_LEFT)
365 row = row + 2
367 self.number = wx.TextCtrl(self, -1, entry['Number'], validator = Wammu.PhoneValidator.PhoneValidator(multi = True), size = (150, -1))
368 self.contbut = wx.Button(self, -1, _('Add'))
369 self.contbut.SetToolTipString(_('Add number of recipient from contacts.'))
370 # TODO: when switching to wx 2.8, use wx.ID_EDIT
371 self.editlistbut = wx.Button(self, -1, _('Edit'))
372 self.editlistbut.SetToolTipString(_('Edit recipients list.'))
374 self.sizer.Add(wx.StaticText(self, -1, _('Recipient\'s numbers:')), pos = (row,1), flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)
375 self.sizer.Add(self.number, pos = (row,2), flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, span = wx.GBSpan(colspan = 4))
376 self.sizer.Add(self.editlistbut, pos = (row,6), flag = wx.ALIGN_CENTER)
377 self.sizer.Add(self.contbut, pos = (row,7), flag = wx.ALIGN_CENTER)
379 self.Bind(wx.EVT_BUTTON, self.ContactPressed, self.contbut)
380 self.Bind(wx.EVT_BUTTON, self.EditContactPressed, self.editlistbut)
382 row = row + 2
384 self.unicode = wx.CheckBox(self, -1, _('Unicode'))
385 self.unicode.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.'))
386 if self.entry.has_key('Unicode'):
387 self.unicode.SetValue(self.entry['Unicode'])
388 else:
389 self.unicode.SetValue(self.cfg.Read('/Message/Unicode') == 'yes')
391 self.sizer.Add(self.unicode, pos = (row,1), flag = wx.ALIGN_LEFT)
393 self.Bind(wx.EVT_CHECKBOX, self.OnUnicode, self.unicode)
395 self.report = wx.CheckBox(self, -1, _('Delivery report'))
396 self.report.SetToolTipString(_('Check to request delivery report for message.'))
397 self.report.SetValue(self.cfg.Read('/Message/DeliveryReport') == 'yes')
398 self.sizer.Add(self.report, pos = (row,2), flag = wx.ALIGN_LEFT)
400 self.sent = wx.CheckBox(self, -1, _('Sent'))
401 self.sent.SetToolTipString(_('Check to save message as sent (has only effect when only saving message).'))
402 self.sizer.Add(self.sent, pos = (row,4), flag = wx.ALIGN_LEFT)
404 self.flash = wx.CheckBox(self, -1, _('Flash'))
405 self.flash.SetToolTipString(_('Send flash message - it will be just displayed on display, but not saved in phone.'))
406 self.sizer.Add(self.flash, pos = (row,6), flag = wx.ALIGN_LEFT)
409 row = row + 2
410 self.sizer.AddGrowableRow(row)
412 self.current = AutoSizeList(self, _('Parts of current message'))
413 self.available = AutoSizeList(self, _('Available message parts'))
414 # FIXME: add icons?
416 self.addbut = wx.Button(self, wx.ID_ADD)
417 self.delbut = wx.Button(self, wx.ID_REMOVE)
419 self.Bind(wx.EVT_BUTTON, self.AddPressed, self.addbut)
420 self.Bind(wx.EVT_BUTTON, self.DeletePressed, self.delbut)
422 self.sizer.Add(self.current, pos = (row,1), flag = wx.EXPAND, span = wx.GBSpan(colspan = 2, rowspan = 2))
423 self.sizer.Add(self.addbut, pos = (row,4), flag = wx.ALIGN_CENTER)
424 self.sizer.Add(self.delbut, pos = (row + 1,4), flag = wx.ALIGN_CENTER)
425 self.sizer.Add(self.available, pos = (row,6), flag = wx.EXPAND, span = wx.GBSpan(colspan = 2, rowspan = 2))
427 row = row + 3
429 self.upbut = wx.Button(self, wx.ID_UP)
430 self.dnbut = wx.Button(self, wx.ID_DOWN)
432 self.sizer.Add(self.upbut, pos = (row,1), flag = wx.ALIGN_CENTER)
433 self.sizer.Add(self.dnbut, pos = (row,2), flag = wx.ALIGN_CENTER)
435 self.Bind(wx.EVT_BUTTON, self.UpPressed, self.upbut)
436 self.Bind(wx.EVT_BUTTON, self.DnPressed, self.dnbut)
438 row = row + 2
439 self.sizer.AddGrowableRow(row)
440 self.editorrow = row
442 self.editor = wx.StaticText(self, -1, _('Create new message by adding part to left list...'), size = (-1, 150))
443 self.sizer.Add(self.editor, pos = (row,1), flag = wx.EXPAND, span = wx.GBSpan(colspan = 7))
445 row = row + 2
447 self.preview = wx.Button(self, -1, _('Preview'))
448 self.button_sizer = wx.StdDialogButtonSizer()
449 self.button_sizer.AddButton(wx.Button(self, wx.ID_OK))
450 self.button_sizer.AddButton(wx.Button(self, wx.ID_CANCEL))
451 self.button_sizer.SetNegativeButton(self.preview)
452 self.button_sizer.Realize()
453 self.sizer.Add(self.button_sizer, pos = (row, 1), span = wx.GBSpan(colspan = 7), flag = wx.ALIGN_RIGHT)
455 self.Bind(wx.EVT_BUTTON, self.Okay, id = wx.ID_OK)
456 self.Bind(wx.EVT_BUTTON, self.Preview, self.preview)
458 self.sizer.AddSpacer((5,5), pos=(row + 1,8))
459 self.sizer.AddGrowableCol(1)
460 self.sizer.AddGrowableCol(2)
461 self.sizer.AddGrowableCol(6)
462 self.sizer.AddGrowableCol(7)
463 self.sizer.Fit(self)
464 self.SetAutoLayout(True)
465 self.SetSizer(self.sizer)
467 self.prevedit = -1
468 self.availsel = -1
470 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.CurrentSelected, self.current)
471 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.AvailableSelected, self.available)
473 if action == 'send':
474 self.OnSave()
475 else:
476 self.OnSend()
478 for x in SMSParts:
479 self.available.InsertImageStringItem(x[0], x[1], x[0])
480 self.available.SetItemState(0, wx.LIST_STATE_FOCUSED | wx.LIST_STATE_SELECTED, wx.LIST_STATE_FOCUSED | wx.LIST_STATE_SELECTED)
482 self.GenerateCurrent()
484 def ContactPressed(self, evt):
485 v = Wammu.Select.SelectNumber(self, [] + self.values['contact']['ME'] + self.values['contact']['SM'])
486 if v != None:
487 self.number.SetValue(self.number.GetValue() + ' ' + v)
489 def EditContactPressed(self, evt):
491 Opens dialog for editing contact list.
493 contacts = [] + self.values['contact']['ME'] + self.values['contact']['SM']
494 current = self.number.GetValue()
495 dlg = Wammu.EditContactList.EditContactList(self, contacts, current)
496 if dlg.ShowModal() == wx.ID_OK:
497 self.number.SetValue(dlg.GetNumbers())
499 def OnSend(self, evt = None):
500 self.save.Enable(self.send.GetValue())
501 self.number.GetValidator().empty = not self.send.GetValue()
503 def OnSave(self, evt = None):
504 self.send.Enable(self.save.GetValue())
506 def GenerateCurrent(self, select = 0):
507 self.current.DeleteAllItems()
508 for i in range(len(self.entry['SMSInfo']['Entries'])):
509 found = False
510 x = self.entry['SMSInfo']['Entries'][i]
511 for p in SMSParts:
512 if x['ID'] in p[2]:
513 self.current.InsertImageStringItem(i, p[1], p[0])
514 found = True
515 break
516 if not found:
517 self.current.InsertImageStringItem(i, _('Not supported id: %s') % x['ID'], -1)
518 print 'Not supported id: %s' % x['ID']
520 count = self.current.GetItemCount()
522 if count > 0:
523 while select > count:
524 select = select - 1
525 self.current.SetItemState(select, wx.LIST_STATE_FOCUSED | wx.LIST_STATE_SELECTED, wx.LIST_STATE_FOCUSED | wx.LIST_STATE_SELECTED)
526 else:
527 if hasattr(self, 'editor'):
528 self.sizer.Detach(self.editor)
529 self.editor.Destroy()
530 del self.editor
531 self.editor = wx.StaticText(self, -1, _('Create new message by adding part to left list...'), size = (-1, 150))
532 self.sizer.Add(self.editor, pos = (self.editorrow,1), flag = wx.EXPAND, span = wx.GBSpan(colspan = 7))
533 self.sizer.Layout()
535 def AvailableSelected(self, event):
536 self.availsel = event.m_itemIndex
538 def OnUnicode(self, event):
539 self.entry['SMSInfo']['Unicode'] = self.unicode.GetValue()
540 if hasattr(self.editor, 'OnUnicode'):
541 self.editor.OnUnicode(self.unicode.GetValue())
543 def CurrentSelected(self, event):
544 self.StoreEdited()
545 if hasattr(self, 'editor'):
546 self.sizer.Detach(self.editor)
547 self.editor.Destroy()
548 del self.editor
550 found = False
551 for p in SMSParts:
552 if self.entry['SMSInfo']['Entries'][event.m_itemIndex]['ID'] in p[2]:
553 self.editor = p[3](self, self.entry['SMSInfo']['Entries'][event.m_itemIndex], self.cfg, self.unicode.GetValue())
554 self.sizer.Add(self.editor, pos = (self.editorrow,1), flag = wx.EXPAND, span = wx.GBSpan(colspan = 7))
555 found = True
556 break
557 if not found:
558 self.editor = wx.StaticText(self, -1, _('No editor available for type %s') % self.entry['SMSInfo']['Entries'][event.m_itemIndex]['ID'])
559 self.sizer.Add(self.editor, pos = (self.editorrow,1), flag = wx.EXPAND, span = wx.GBSpan(colspan = 7))
560 self.prevedit = -1
561 else:
562 self.prevedit = event.m_itemIndex
563 self.sizer.Layout()
565 def UpPressed(self, evt):
566 if self.prevedit == -1:
567 return
568 next = self.prevedit - 1
569 if next < 0:
570 return
571 self.StoreEdited()
572 v = self.entry['SMSInfo']['Entries'][self.prevedit]
573 self.entry['SMSInfo']['Entries'][self.prevedit] = self.entry['SMSInfo']['Entries'][next]
574 self.entry['SMSInfo']['Entries'][next] = v
575 self.prevedit = -1
576 self.GenerateCurrent(next)
578 def DnPressed(self, evt):
579 if self.prevedit == -1:
580 return
581 next = self.prevedit + 1
582 if next >= self.current.GetItemCount():
583 return
584 self.StoreEdited()
585 v = self.entry['SMSInfo']['Entries'][self.prevedit]
586 self.entry['SMSInfo']['Entries'][self.prevedit] = self.entry['SMSInfo']['Entries'][next]
587 self.entry['SMSInfo']['Entries'][next] = v
588 self.prevedit = -1
589 self.GenerateCurrent(next)
591 def DeletePressed(self, evt):
592 if self.prevedit == -1:
593 return
594 self.StoreEdited()
595 del self.entry['SMSInfo']['Entries'][self.prevedit]
596 next = self.prevedit - 1
597 self.prevedit = -1
598 self.GenerateCurrent(max(next, 0))
600 def AddPressed(self, evt):
601 if self.availsel == -1:
602 return
603 v = {'ID': SMSParts[self.availsel][4]}
604 if v['ID'][-5:] == '16bit' and self.cfg.Read('/Message/16bitId') != 'yes':
605 v['ID'] = v['ID'][:-5]
606 self.StoreEdited()
607 self.entry['SMSInfo']['Entries'].insert(self.prevedit + 1, v)
608 next = self.prevedit + 1
609 self.prevedit = -1
610 self.GenerateCurrent(next)
612 def StoreEdited(self):
613 if self.prevedit != -1:
614 self.entry['SMSInfo']['Entries'][self.prevedit] = self.editor.GetValue()
616 if self.report.GetValue():
617 self.entry['Type'] = 'Status_Report'
618 else:
619 self.entry['Type'] = 'Submit'
621 if self.sent.GetValue():
622 self.entry['State'] = 'Sent'
623 else:
624 self.entry['State'] = 'UnSent'
626 if self.flash.GetValue():
627 self.entry['SMSInfo']['Class'] = 0
628 else:
629 self.entry['SMSInfo']['Class'] = 1
631 self.entry['Numbers'] = Wammu.PhoneValidator.SplitNumbers(self.number.GetValue())
632 self.entry['SMSInfo']['Unicode'] = self.unicode.GetValue()
633 self.entry['Save'] = self.save.GetValue()
634 self.entry['Send'] = self.send.GetValue()
635 self.entry['Folder'] = self.folder.GetValue()
637 def Preview(self, evt):
638 if len(self.entry['SMSInfo']['Entries']) == 0:
639 dlg = wx.MessageDialog(self, _('Nothing to preview, message is empty.'),
640 _('Message empty!'), wx.OK | wx.ICON_WARNING)
641 else:
642 self.StoreEdited()
643 msg = gammu.EncodeSMS(self.entry['SMSInfo'])
644 info = gammu.DecodeSMS(msg)
645 result = {}
646 result['SMS'] = msg
647 if info != None:
648 result['SMSInfo'] = info
649 Wammu.Utils.ParseMessage(result, (info != None))
650 dlg = MessagePreview(self, ('<i>%s</i><hr>' % (_('Message will fit into %d SMSes') % len(msg))) + Wammu.MessageDisplay.SmsToHtml(self.cfg, result))
652 dlg.ShowModal()
653 del dlg
655 def Okay(self, evt):
656 if not self.number.GetValidator().Validate(self):
657 return
659 self.StoreEdited()
661 self.EndModal(wx.ID_OK)