Mercurial > libervia-web
annotate browser_side/dialog.py @ 54:f25c4077f6b9
addind contact + subscription management + misc
- removed bad html_sanitize (not needed in Label !)
- added isContactInRoster method in ContactPanel
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 May 2011 20:18:14 +0200 |
parents | 4419ef07bb2b |
children | d5266c41ca24 |
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 |
43
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
24 from pyjamas.ui.PopupPanel import PopupPanel |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.DialogBox import DialogBox |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.ListBox import ListBox |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas.ui.Button import Button |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
28 from pyjamas.ui.TextBox import TextBox |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
29 from pyjamas.ui.Label import Label |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
30 from pyjamas.ui.HTML import HTML |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
31 from pyjamas.ui import HasAlignment |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
32 from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 class ContactsChooser(DialogBox): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 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
|
37 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 ContactsChooser allow to select one or several connected contacts |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 @param host: SatWebFrontend instance |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 @param callback: method to call when contacts have been choosed |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 @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
|
42 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 self.host = host |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 self.callback = callback |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 self.nb_contact = nb_contact |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 DialogBox.__init__(self, centered=True) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 content = VerticalPanel() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 content.setWidth('100%') |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self.contacts_list = ListBox() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 self.contacts_list.setVisibleItemCount(10) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 self.contacts_list.setMultipleSelect(True) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 self.contacts_list.setWidth("100%") |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 self.contacts_list.setStyleName('contactsChooser') |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 self.contacts_list.addChangeListener(self.onChange) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 content.add(self.contacts_list) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 button_panel = HorizontalPanel() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.choose_button = Button("Choose", self.onChoose) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self.choose_button.setEnabled(False) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 button_panel.add(self.choose_button) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 button_panel.add(Button("Cancel", self.onCancel)) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 content.add(button_panel) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 self.setHTML(text) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 self.setWidget(content) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 def onChange(self): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 if self.nb_contact: |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 if len(self.contacts_list.getSelectedValues()) == self.nb_contact: |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 self.choose_button.setEnabled(True) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 else: |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 self.choose_button.setEnabled(False) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 def getContacts(self): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 Actually ask to choose the contacts |
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 self.contacts_list.clear() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 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
|
79 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
|
80 self.contacts_list.addItem(contact) |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 self.show() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 def onChoose(self): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 self.hide() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 self.callback(self.contacts_list.getSelectedValues()) |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 def onCancel(self): |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 self.hide() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
90 class ConfirmDialog(DialogBox): |
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 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
|
93 """ |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
94 Dialog to confirm an action |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
95 @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
|
96 """ |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
97 self.callback = callback |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
98 DialogBox.__init__(self, centered=True) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
99 |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
100 content = VerticalPanel() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
101 content.setWidth('100%') |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
102 button_panel = HorizontalPanel() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
103 self.confirm_button = Button("OK", self.onConfirm) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
104 button_panel.add(self.confirm_button) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
105 button_panel.add(Button("Cancel", self.onCancel)) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
106 content.add(button_panel) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
107 self.setHTML(text) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
108 self.setWidget(content) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
109 |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
110 def onConfirm(self): |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
111 self.hide() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
112 self.callback(True) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
113 |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
114 def onCancel(self): |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
115 self.hide() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
116 self.callback(False) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
117 |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
118 class InfoDialog(DialogBox): |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
119 """Dialog which just show a widget and a close button""" |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
120 |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
121 def __init__(self, title, widget, callback = None): |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
122 """Simple notice dialog box |
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
123 @param title: HTML put in the header |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
124 @param body: widget put in the body""" |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
125 DialogBox.__init__(self, centered=True) |
42 | 126 self.callback = callback |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
127 _body = VerticalPanel() |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
128 _body.setSize('100%','100%') |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
129 _body.setSpacing(4) |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
130 _body.add(widget) |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
131 _body.setCellWidth(widget, '100%') |
49 | 132 _close_button = Button("Close", self.onClose) |
133 _body.add(_close_button) | |
134 _body.setCellHorizontalAlignment(_close_button, HasAlignment.ALIGN_CENTER) | |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
135 self.setHTML(title) |
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
136 self.setWidget(_body) |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
137 self.panel.setWidth('100%') |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
138 |
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
139 def onClose(self): |
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
140 self.hide() |
42 | 141 if self.callback: |
142 self.callback() | |
43
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
143 |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
144 class SimpleDialog(InfoDialog): |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
145 |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
146 def __init__(self, title, body, callback = None): |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
147 InfoDialog.__init__(self, title, HTML(body), callback) |
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
148 |
43
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
149 class PopupPanelWrapper(PopupPanel): |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
150 """This wrapper catch Escape event to avoid request cancellation by Firefox""" |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
151 |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
152 def onEventPreview(self, event): |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
153 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
154 #needed to prevent request cancellation in Firefox |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
155 event.preventDefault() |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
156 return PopupPanel.onEventPreview(self, event) |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
157 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
158 class ExtTextBox(TextBox): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
159 """Extended TextBox""" |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
160 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
161 def __init__(self, *args, **kwargs): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
162 if 'enter_cb' in kwargs: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
163 self.enter_cb = kwargs['enter_cb'] |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
164 del kwargs['enter_cb'] |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
165 TextBox.__init__(self, *args, **kwargs) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
166 self.addKeyboardListener(self) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
167 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
168 def onKeyUp(self, sender, keycode, modifiers): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
169 pass |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
170 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
171 def onKeyDown(self, sender, keycode, modifiers): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
172 pass |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
173 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
174 def onKeyPress(self, sender, keycode, modifiers): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
175 if self.enter_cb and keycode == KEY_ENTER: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
176 self.enter_cb(self) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
177 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
178 class GroupSelector(DialogBox): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
179 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
180 def __init__(self, top_widgets, initial_groups, selected_groups, ok_cb = None, cancel_cb = None): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
181 DialogBox.__init__(self, centered = True) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
182 main_panel = VerticalPanel() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
183 self.ok_cb = ok_cb |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
184 self.cancel_cb = cancel_cb |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
185 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
186 for wid in top_widgets: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
187 main_panel.add(wid) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
188 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
189 main_panel.add(Label('Select in which groups your contact is:')) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
190 self.list_box = ListBox() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
191 self.list_box.setMultipleSelect(True) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
192 self.list_box.setVisibleItemCount(5) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
193 self.setAvailableGroups(initial_groups) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
194 self.setGroupsSelected(selected_groups) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
195 main_panel.add(self.list_box) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
196 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
197 add_group_panel = HorizontalPanel() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
198 add_group_lb = Label('Add group:') |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
199 add_group_tb = ExtTextBox(enter_cb = self.onGroupInput) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
200 add_group_panel.add(add_group_lb) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
201 add_group_panel.add(add_group_tb) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
202 main_panel.add(add_group_panel) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
203 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
204 button_panel = HorizontalPanel() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
205 button_panel.add(Button("Add", self.onOK)) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
206 button_panel.add(Button("Cancel", self.onCancel)) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
207 main_panel.add(button_panel) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
208 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
209 self.setWidget(main_panel) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
210 |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
211 def getSelectedGroups(self): |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
212 """Return a list of selected groups""" |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
213 return self.list_box.getSelectedValues() |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
214 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
215 def setAvailableGroups(self, groups): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
216 _groups = list(set(groups)) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
217 _groups.sort() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
218 self.list_box.clear() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
219 for group in _groups: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
220 self.list_box.addItem(group) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
221 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
222 def setGroupsSelected(self, groups): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
223 if groups: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
224 self.list_box.setItemTextSelection(selected_groups) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
225 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
226 def onOK(self, sender): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
227 self.hide() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
228 if self.ok_cb: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
229 self.ok_cb(self) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
230 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
231 def onCancel(self, sender): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
232 self.hide() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
233 if self.cancel_cb: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
234 self.cancel_cb(self) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
235 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
236 def onGroupInput(self, sender): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
237 self.list_box.addItem(sender.getText()) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
238 sender.setText('') |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
239 self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected") |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
240 |