Mercurial > libervia-web
annotate browser_side/dialog.py @ 39:305e81c7a32c
Tarot game: a game can now be finished
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 22 May 2011 00:15:01 +0200 |
parents | 6b8da70b0799 |
children | 7782a786b2f0 |
rev | line source |
---|---|
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from pyjamas.ui.VerticalPanel import VerticalPanel |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from pyjamas.ui.DialogBox import DialogBox |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.ListBox import ListBox |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.Button import Button |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 class ContactsChooser(DialogBox): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 ContactsChooser allow to select one or several connected contacts |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 @param host: SatWebFrontend instance |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 @param callback: method to call when contacts have been choosed |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 @param nb_contact: number of contacts that have to be selected, None for no limit |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 self.host = host |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 self.callback = callback |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 self.nb_contact = nb_contact |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 DialogBox.__init__(self, centered=True) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 content = VerticalPanel() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 content.setWidth('100%') |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 self.contacts_list = ListBox() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 self.contacts_list.setVisibleItemCount(10) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 self.contacts_list.setMultipleSelect(True) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 self.contacts_list.setWidth("100%") |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 self.contacts_list.setStyleName('contactsChooser') |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 self.contacts_list.addChangeListener(self.onChange) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 content.add(self.contacts_list) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 button_panel = HorizontalPanel() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 self.choose_button = Button("Choose", self.onChoose) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 self.choose_button.setEnabled(False) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 button_panel.add(self.choose_button) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 button_panel.add(Button("Cancel", self.onCancel)) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 content.add(button_panel) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 self.setHTML(text) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.setWidget(content) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 def onChange(self): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 if self.nb_contact: |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 if len(self.contacts_list.getSelectedValues()) == self.nb_contact: |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 self.choose_button.setEnabled(True) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 else: |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 self.choose_button.setEnabled(False) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 def getContacts(self): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 Actually ask to choose the contacts |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 self.contacts_list.clear() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 for contact in self.host.contact_panel.getConnected(): |
32
6b8da70b0799
browser_side: contactsChooser now discard MUC rooms
Goffi <goffi@goffi.org>
parents:
26
diff
changeset
|
73 if contact not in [room.bare for room in self.host.room_list]: |
6b8da70b0799
browser_side: contactsChooser now discard MUC rooms
Goffi <goffi@goffi.org>
parents:
26
diff
changeset
|
74 self.contacts_list.addItem(contact) |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 self.show() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 def onChoose(self): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 self.hide() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 self.callback(self.contacts_list.getSelectedValues()) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 def onCancel(self): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 self.hide() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
84 class ConfirmDialog(DialogBox): |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
85 |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
86 def __init__(self, callback, text='Are you sure ?'): |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
87 """ |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
88 Dialog to confirm an action |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
89 @param callback: method to call when contacts have been choosed |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
90 """ |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
91 self.callback = callback |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
92 DialogBox.__init__(self, centered=True) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
93 |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
94 content = VerticalPanel() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
95 content.setWidth('100%') |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
96 button_panel = HorizontalPanel() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
97 self.confirm_button = Button("OK", self.onConfirm) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
98 button_panel.add(self.confirm_button) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
99 button_panel.add(Button("Cancel", self.onCancel)) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
100 content.add(button_panel) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
101 self.setHTML(text) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
102 self.setWidget(content) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
103 |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
104 def onConfirm(self): |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
105 self.hide() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
106 self.callback(True) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
107 |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
108 def onCancel(self): |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
109 self.hide() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
110 self.callback(False) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
111 |