1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
5 Contact and phone number select dialogs
7 __author__
= 'Michal Čihař'
8 __email__
= 'michal@cihar.com'
10 Copyright © 2003 - 2009 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
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
28 from Wammu
.Locales
import StrConv
30 def SortName(item1
, item2
):
32 Comparator function for sorting by name.
34 return cmp(item1
['Name'], item2
['Name'])
36 def SelectContact(parent
, contactlist
, index
= False):
38 Dialog for selecting contact.
40 contactlist
.sort(SortName
)
42 for entry
in contactlist
:
43 if entry
['Name'] == '':
44 choices
.append(StrConv(entry
['Number']))
46 choices
.append(StrConv(entry
['Name']))
48 dlg
= wx
.SingleChoiceDialog(
50 _('Select contact from below list'),
53 wx
.CHOICEDLG_STYLE | wx
.RESIZE_BORDER
)
54 if dlg
.ShowModal() == wx
.ID_OK
and len(choices
) > 0:
55 result
= dlg
.GetSelection()
57 result
= contactlist
[result
]['Location']
63 def SelectNumber(parent
, contactlist
):
65 Allows user to select number from phone list. First it asks for contact
66 and then which number to use.
68 i
= SelectContact(parent
, contactlist
, True)
71 return SelectContactNumber(parent
, contactlist
[i
])
73 def SelectContactNumber(parent
, item
):
75 Selects number of chosen contact. If it has single number, it returns it
76 directly, otherwise user has to select which number to use.
80 for i
in range(len(item
['Entries'])):
81 if Wammu
.Utils
.GetItemType(item
['Entries'][i
]['Type']) == 'phone':
82 numbers
.append(item
['Entries'][i
]['Value'])
83 texts
.append(StrConv(u
'%s : %s' % (
84 item
['Entries'][i
]['Type'],
85 item
['Entries'][i
]['Value'])))
89 elif len(numbers
) == 1:
91 dlg
= wx
.SingleChoiceDialog(
93 _('Select number for selected contact'),
94 _('Select phone number'),
96 wx
.CHOICEDLG_STYLE | wx
.RESIZE_BORDER
)
97 if dlg
.ShowModal() == wx
.ID_OK
:
98 result
= numbers
[dlg
.GetSelection()]