Bluez support cleanup.
[wammu.git] / Wammu / Select.py
blob8c97cb298e370c0cadc49c0bac059363a748cb0d
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 Contact and phone number select dialogs
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright (c) 2003 - 2007 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 Wammu.Utils
28 from Wammu.Locales import StrConv
30 def SortName(i1, i2):
31 return cmp(i1['Name'], i2['Name'])
33 def SelectContact(parent, list, index = False):
34 list.sort(SortName)
35 choices = []
36 for e in list:
37 if e['Name'] == '':
38 choices.append(StrConv(e['Number']))
39 else:
40 choices.append(StrConv(e['Name']))
42 dlg = wx.SingleChoiceDialog(parent, _('Select contact from bellow list'), _('Select contact'),
43 choices, wx.CHOICEDLG_STYLE | wx.RESIZE_BORDER)
44 if dlg.ShowModal() == wx.ID_OK and len(choices) > 0:
45 rs = dlg.GetSelection()
46 if not index:
47 rs = list[rs]['Location']
48 else:
49 rs = -1
50 del dlg
51 return rs
53 def SelectNumber(parent, list):
54 i = SelectContact(parent, list, True)
55 if i == -1:
56 return None
57 return SelectContactNumber(parent, list[i])
59 def SelectContactNumber(parent, item):
60 numbers = []
61 texts = []
62 for x in range(len(item['Entries'])):
63 if Wammu.Utils.GetItemType(item['Entries'][x]['Type']) == 'phone':
64 numbers.append(item['Entries'][x]['Value'])
65 texts.append(StrConv(item['Entries'][x]['Type'] + ' : ' + item['Entries'][x]['Value']))
67 if len(numbers) == 0:
68 return None
69 elif len(numbers) == 1:
70 return numbers[0]
71 dlg = wx.SingleChoiceDialog(parent, _('Select number for selected contact'), _('Select phone number'),
72 texts, wx.CHOICEDLG_STYLE | wx.RESIZE_BORDER)
73 if dlg.ShowModal() == wx.ID_OK:
74 rs = numbers[dlg.GetSelection()]
75 else:
76 rs = None
77 del dlg
78 return rs