From 0a4d1f648afabf067eef31fcb4e6d0ab325902ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 12 Nov 2007 04:50:08 +0000 Subject: [PATCH] Coding style and documentation. --- Wammu/Select.py | 76 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/Wammu/Select.py b/Wammu/Select.py index 8c97cb29..4e9067ef 100644 --- a/Wammu/Select.py +++ b/Wammu/Select.py @@ -27,52 +27,76 @@ import wx import Wammu.Utils from Wammu.Locales import StrConv -def SortName(i1, i2): - return cmp(i1['Name'], i2['Name']) +def SortName(item1, item2): + ''' + Comparator function for sorting by name. + ''' + return cmp(item1['Name'], item2['Name']) -def SelectContact(parent, list, index = False): - list.sort(SortName) +def SelectContact(parent, contactlist, index = False): + ''' + Dialog for selecting contact. + ''' + contactlist.sort(SortName) choices = [] - for e in list: - if e['Name'] == '': - choices.append(StrConv(e['Number'])) + for entry in contactlist: + if entry['Name'] == '': + choices.append(StrConv(entry['Number'])) else: - choices.append(StrConv(e['Name'])) + choices.append(StrConv(entry['Name'])) - dlg = wx.SingleChoiceDialog(parent, _('Select contact from bellow list'), _('Select contact'), - choices, wx.CHOICEDLG_STYLE | wx.RESIZE_BORDER) + dlg = wx.SingleChoiceDialog( + parent, + _('Select contact from bellow list'), + _('Select contact'), + choices, + wx.CHOICEDLG_STYLE | wx.RESIZE_BORDER) if dlg.ShowModal() == wx.ID_OK and len(choices) > 0: - rs = dlg.GetSelection() + result = dlg.GetSelection() if not index: - rs = list[rs]['Location'] + result = contactlist[result]['Location'] else: - rs = -1 + result = -1 del dlg - return rs + return result -def SelectNumber(parent, list): - i = SelectContact(parent, list, True) +def SelectNumber(parent, contactlist): + ''' + Allows user to select number from phone list. First it asks for contact + and then which number to use. + ''' + i = SelectContact(parent, contactlist, True) if i == -1: return None - return SelectContactNumber(parent, list[i]) + return SelectContactNumber(parent, contactlist[i]) def SelectContactNumber(parent, item): + ''' + Selects number of chosen contact. If it has single number, it returns it + directly, otherwise user has to select which number to use. + ''' numbers = [] texts = [] - for x in range(len(item['Entries'])): - if Wammu.Utils.GetItemType(item['Entries'][x]['Type']) == 'phone': - numbers.append(item['Entries'][x]['Value']) - texts.append(StrConv(item['Entries'][x]['Type'] + ' : ' + item['Entries'][x]['Value'])) + for i in range(len(item['Entries'])): + if Wammu.Utils.GetItemType(item['Entries'][i]['Type']) == 'phone': + numbers.append(item['Entries'][i]['Value']) + texts.append(StrConv(u'%s : %s' % ( + item['Entries'][i]['Type'], + item['Entries'][i]['Value']))) if len(numbers) == 0: return None elif len(numbers) == 1: return numbers[0] - dlg = wx.SingleChoiceDialog(parent, _('Select number for selected contact'), _('Select phone number'), - texts, wx.CHOICEDLG_STYLE | wx.RESIZE_BORDER) + dlg = wx.SingleChoiceDialog( + parent, + _('Select number for selected contact'), + _('Select phone number'), + texts, + wx.CHOICEDLG_STYLE | wx.RESIZE_BORDER) if dlg.ShowModal() == wx.ID_OK: - rs = numbers[dlg.GetSelection()] + result = numbers[dlg.GetSelection()] else: - rs = None + result = None del dlg - return rs + return result -- 2.11.4.GIT