comparison browser_side/dialog.py @ 26:824516b247e6

browser side: added ContactsChooser dialog
author Goffi <goffi@goffi.org>
date Sat, 07 May 2011 23:52:44 +0200
parents
children 6b8da70b0799
comparison
equal deleted inserted replaced
25:46c8d5431198 26:824516b247e6
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 Libervia: a Salut à Toi frontend
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """
21
22 from pyjamas.ui.VerticalPanel import VerticalPanel
23 from pyjamas.ui.HorizontalPanel import HorizontalPanel
24 from pyjamas.ui.DialogBox import DialogBox
25 from pyjamas.ui.ListBox import ListBox
26 from pyjamas.ui.Button import Button
27
28 class ContactsChooser(DialogBox):
29
30 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'):
31 """
32 ContactsChooser allow to select one or several connected contacts
33 @param host: SatWebFrontend instance
34 @param callback: method to call when contacts have been choosed
35 @param nb_contact: number of contacts that have to be selected, None for no limit
36 """
37 self.host = host
38 self.callback = callback
39 self.nb_contact = nb_contact
40 DialogBox.__init__(self, centered=True)
41
42 content = VerticalPanel()
43 content.setWidth('100%')
44 self.contacts_list = ListBox()
45 self.contacts_list.setVisibleItemCount(10)
46 self.contacts_list.setMultipleSelect(True)
47 self.contacts_list.setWidth("100%")
48 self.contacts_list.setStyleName('contactsChooser')
49 self.contacts_list.addChangeListener(self.onChange)
50 content.add(self.contacts_list)
51 button_panel = HorizontalPanel()
52 self.choose_button = Button("Choose", self.onChoose)
53 self.choose_button.setEnabled(False)
54 button_panel.add(self.choose_button)
55 button_panel.add(Button("Cancel", self.onCancel))
56 content.add(button_panel)
57 self.setHTML(text)
58 self.setWidget(content)
59
60 def onChange(self):
61 if self.nb_contact:
62 if len(self.contacts_list.getSelectedValues()) == self.nb_contact:
63 self.choose_button.setEnabled(True)
64 else:
65 self.choose_button.setEnabled(False)
66
67 def getContacts(self):
68 """
69 Actually ask to choose the contacts
70 """
71 self.contacts_list.clear()
72 for contact in self.host.contact_panel.getConnected():
73 self.contacts_list.addItem(contact)
74 self.show()
75
76 def onChoose(self):
77 self.hide()
78 self.callback(self.contacts_list.getSelectedValues())
79
80 def onCancel(self):
81 self.hide()
82