annotate browser_side/dialog.py @ 42:71a9cc9b9d57

Browser side: Tarot game - draw game managed - we can now play continuously \o/
author Goffi <goffi@goffi.org>
date Mon, 23 May 2011 00:45:19 +0200
parents 7782a786b2f0
children a7ff1e6f1229
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
27 from pyjamas.ui.HTML import HTML
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
28
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
29 class ContactsChooser(DialogBox):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
30
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
31 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
32 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
33 ContactsChooser allow to select one or several connected contacts
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
34 @param host: SatWebFrontend instance
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
35 @param callback: method to call when contacts have been choosed
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
36 @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
37 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.host = host
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.callback = callback
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
40 self.nb_contact = nb_contact
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
41 DialogBox.__init__(self, centered=True)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
42
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
43 content = VerticalPanel()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
44 content.setWidth('100%')
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.contacts_list = ListBox()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.contacts_list.setVisibleItemCount(10)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.contacts_list.setMultipleSelect(True)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.contacts_list.setWidth("100%")
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.contacts_list.setStyleName('contactsChooser')
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.contacts_list.addChangeListener(self.onChange)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
51 content.add(self.contacts_list)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
52 button_panel = HorizontalPanel()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.choose_button = Button("Choose", self.onChoose)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.choose_button.setEnabled(False)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
55 button_panel.add(self.choose_button)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
56 button_panel.add(Button("Cancel", self.onCancel))
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
57 content.add(button_panel)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.setHTML(text)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.setWidget(content)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
60
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
61 def onChange(self):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
62 if self.nb_contact:
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
63 if len(self.contacts_list.getSelectedValues()) == self.nb_contact:
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.choose_button.setEnabled(True)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
65 else:
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.choose_button.setEnabled(False)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
67
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
68 def getContacts(self):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
69 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
70 Actually ask to choose the contacts
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
71 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.contacts_list.clear()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
73 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
74 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
75 self.contacts_list.addItem(contact)
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.show()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
77
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def onChoose(self):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.hide()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.callback(self.contacts_list.getSelectedValues())
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
81
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def onCancel(self):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.hide()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
84
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
85 class ConfirmDialog(DialogBox):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
86
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
87 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
88 """
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
89 Dialog to confirm an action
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
90 @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
91 """
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
92 self.callback = callback
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
93 DialogBox.__init__(self, centered=True)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
94
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
95 content = VerticalPanel()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
96 content.setWidth('100%')
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
97 button_panel = HorizontalPanel()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
98 self.confirm_button = Button("OK", self.onConfirm)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
99 button_panel.add(self.confirm_button)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
100 button_panel.add(Button("Cancel", self.onCancel))
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
101 content.add(button_panel)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
102 self.setHTML(text)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
103 self.setWidget(content)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
104
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
105 def onConfirm(self):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
106 self.hide()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
107 self.callback(True)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
108
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
109 def onCancel(self):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
110 self.hide()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
111 self.callback(False)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
112
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
113 class SimpleDialog(DialogBox):
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
114
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
115 def __init__(self, title, body, callback = None):
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
116 """Simple notice dialog box
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
117 @param title: HTML put in the header
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
118 @param body: HTML put in the body"""
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
119 DialogBox.__init__(self, centered=True)
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
120 self.callback = callback
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
121 _body = VerticalPanel()
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
122 _body.setSpacing(4)
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
123 _body.add(HTML(body))
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
124 _body.add(Button("Close", self.onClose))
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
125 _body.setStyleName("dialogBody")
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
126 self.setHTML(title)
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
127 self.setWidget(_body)
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
128
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
129 def onClose(self):
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
130 self.hide()
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
131 if self.callback:
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
132 self.callback()