Mercurial > libervia-web
annotate browser/sat_browser/dialog.py @ 1143:7bd47d32da87
pages (tickets, merge-requests): convert body from/to markdown while editing/creating new ticket:
there is currently no way to edit XHTML directly inside the browser with Libervia pages, this patch works around this by doing a conversion to/from markdown.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Jan 2019 11:42:37 +0100 |
parents | 28e3eb3bb217 |
children | 2af117bfe6cc |
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 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
1054 | 5 # Copyright (C) 2011-2018 Jérôme Poisson <goffi@goffi.org> |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
10 # (at your option) any later version. |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
15 # GNU Affero General Public License for more details. |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
399
diff
changeset
|
20 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
399
diff
changeset
|
21 log = getLogger(__name__) |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
22 |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
23 from constants import Const as C |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
24 from sat_frontends.tools import jid |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
439
diff
changeset
|
25 |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.VerticalPanel import VerticalPanel |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
27 from pyjamas.ui.Grid import Grid |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 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
|
29 from pyjamas.ui.PopupPanel import PopupPanel |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from pyjamas.ui.DialogBox import DialogBox |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from pyjamas.ui.ListBox import ListBox |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from pyjamas.ui.Button import Button |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
33 from pyjamas.ui.TextBox import TextBox |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
34 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
|
35 from pyjamas.ui.HTML import HTML |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
36 from pyjamas.ui.RadioButton import RadioButton |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
37 from pyjamas.ui import HasAlignment |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
38 from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER |
95
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
39 from pyjamas.ui.MouseListener import MouseWheelHandler |
211
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
40 from pyjamas import Window |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
288
diff
changeset
|
41 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
638
diff
changeset
|
42 import base_panel |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
288
diff
changeset
|
43 |
211
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
44 |
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
45 # List here the patterns that are not allowed in contact group names |
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
46 FORBIDDEN_PATTERNS_IN_GROUP = () |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
240
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
48 |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
49 unicode = str # XXX: pyjama doesn't manage unicode |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
50 |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
51 |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
52 class RoomChooser(Grid): |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
53 """Select a room from the rooms you already joined, or create a new one""" |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
54 |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
55 GENERATE_MUC = "<use random name>" |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
56 |
692
7a9c7b9f6a28
browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents:
686
diff
changeset
|
57 def __init__(self, host, room_jid_s=None): |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
58 """ |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
59 |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
60 @param host (SatWebFrontend) |
692
7a9c7b9f6a28
browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents:
686
diff
changeset
|
61 @param room_jid_s (unicode): room JID |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
62 """ |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
63 Grid.__init__(self, 2, 2, Width='100%') |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
64 self.host = host |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
65 |
288
7316a5696366
browser_side: renamed item and labels for discussion groups
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
66 self.new_radio = RadioButton("room", "Discussion room:") |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
67 self.new_radio.setChecked(True) |
288
7316a5696366
browser_side: renamed item and labels for discussion groups
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
68 self.box = TextBox(Width='95%') |
692
7a9c7b9f6a28
browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents:
686
diff
changeset
|
69 self.box.setText(room_jid_s if room_jid_s else self.GENERATE_MUC) |
399
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
70 self.exist_radio = RadioButton("room", "Already joined:") |
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
71 self.rooms_list = ListBox(Width='95%') |
288
7316a5696366
browser_side: renamed item and labels for discussion groups
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
72 |
7316a5696366
browser_side: renamed item and labels for discussion groups
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
73 self.add(self.new_radio, 0, 0) |
7316a5696366
browser_side: renamed item and labels for discussion groups
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
74 self.add(self.box, 0, 1) |
7316a5696366
browser_side: renamed item and labels for discussion groups
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
75 self.add(self.exist_radio, 1, 0) |
7316a5696366
browser_side: renamed item and labels for discussion groups
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
76 self.add(self.rooms_list, 1, 1) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
77 |
399
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
78 self.box.addFocusListener(self) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
79 self.rooms_list.addFocusListener(self) |
399
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
80 |
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
81 self.exist_radio.setVisible(False) |
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
82 self.rooms_list.setVisible(False) |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
83 self.refreshOptions() |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
84 |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
85 @property |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
86 def room(self): |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
87 """Get the room that has been selected or entered by the user |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
88 |
669
a8fddccf5b84
server and browser sides: fixes joining room with auto-generated name + leave JID error handling to the backend
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
89 @return: jid.JID or None to let the backend generate a new name |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
90 """ |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
91 if self.exist_radio.getChecked(): |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
92 values = self.rooms_list.getSelectedValues() |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
93 return jid.JID(values[0]) if values else None |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
94 value = self.box.getText() |
669
a8fddccf5b84
server and browser sides: fixes joining room with auto-generated name + leave JID error handling to the backend
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
95 return None if value in ('', self.GENERATE_MUC) else jid.JID(value) |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
97 def onFocus(self, sender): |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
98 if sender == self.rooms_list: |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
99 self.exist_radio.setChecked(True) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
100 elif sender == self.box: |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
101 if self.box.getText() == self.GENERATE_MUC: |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
102 self.box.setText("") |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
103 self.new_radio.setChecked(True) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
104 |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
105 def onLostFocus(self, sender): |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
106 if sender == self.box: |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
107 if self.box.getText() == "": |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
108 self.box.setText(self.GENERATE_MUC) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
109 |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
110 def refreshOptions(self): |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
111 """Refresh the already joined room list""" |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
112 contact_list = self.host.contact_list |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
113 muc_rooms = contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP) |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
114 for room in muc_rooms: |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
115 self.rooms_list.addItem(room.bare) |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
116 if len(muc_rooms) > 0: |
399
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
117 self.exist_radio.setVisible(True) |
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
118 self.rooms_list.setVisible(True) |
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
119 self.exist_radio.setChecked(True) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
120 |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
121 |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
122 class ContactsChooser(VerticalPanel): |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
123 """Select one or several connected contacts""" |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
124 |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
125 def __init__(self, host, nb_contact=None, ok_button=None): |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 @param host: SatWebFrontend instance |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 @param nb_contact: number of contacts that have to be selected, None for no limit |
240
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
129 If a tuple is given instead of an integer, nb_contact[0] is the minimal and |
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
130 nb_contact[1] is the maximal number of contacts to be chosen. |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 """ |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 self.host = host |
240
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
133 if isinstance(nb_contact, tuple): |
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
134 if len(nb_contact) == 0: |
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
135 nb_contact = None |
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
136 elif len(nb_contact) == 1: |
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
137 nb_contact = (nb_contact[0], nb_contact[0]) |
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
138 elif nb_contact is not None: |
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
139 nb_contact = (nb_contact, nb_contact) |
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
140 if nb_contact is None: |
669
a8fddccf5b84
server and browser sides: fixes joining room with auto-generated name + leave JID error handling to the backend
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
141 log.debug("Need to select as many contacts as you want") |
240
a565ce2facc0
browser_side: modified class ContactChooser to allow setting a min and max number of contacts to be chosen
souliane <souliane@mailoo.org>
parents:
238
diff
changeset
|
142 else: |
669
a8fddccf5b84
server and browser sides: fixes joining room with auto-generated name + leave JID error handling to the backend
souliane <souliane@mailoo.org>
parents:
662
diff
changeset
|
143 log.debug("Need to select between %d and %d contacts" % nb_contact) |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 self.nb_contact = nb_contact |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
145 self.ok_button = ok_button |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
146 VerticalPanel.__init__(self, Width='100%') |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 self.contacts_list = ListBox() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 self.contacts_list.setMultipleSelect(True) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
149 self.contacts_list.setWidth("95%") |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
150 self.contacts_list.addStyleName('contactsChooser') |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 self.contacts_list.addChangeListener(self.onChange) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
152 self.add(self.contacts_list) |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
153 self.refreshOptions() |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
154 self.onChange() |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
155 |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
156 @property |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
157 def contacts(self): |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
158 """Return the selected contacts. |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
159 |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
160 @return: list[jid.JID] |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
161 """ |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
162 return [jid.JID(contact) for contact in self.contacts_list.getSelectedValues(True)] |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
163 |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
164 def onChange(self, sender=None): |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
165 if self.ok_button is None: |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
166 return |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
167 if self.nb_contact: |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
168 selected = len(self.contacts_list.getSelectedValues(True)) |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
169 if selected >= self.nb_contact[0] and selected <= self.nb_contact[1]: |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
170 self.ok_button.setEnabled(True) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
171 else: |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
172 self.ok_button.setEnabled(False) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
173 |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
174 def refreshOptions(self, keep_selected=False): |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
175 """Fill the list with the connected contacts. |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
176 |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
177 @param keep_selected (boolean): if True, keep the current selection |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
178 """ |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
179 selection = self.contacts if keep_selected else [] |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
180 self.contacts_list.clear() |
944 | 181 contacts = self.host.contact_list.roster_connected |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
182 self.contacts_list.setVisibleItemCount(10 if len(contacts) > 5 else 5) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
183 self.contacts_list.addItem("") |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
184 for contact in contacts: |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
185 self.contacts_list.addItem(contact) |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
186 if selection: |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
187 self.contacts_list.setItemTextSelection([unicode(contact) for contact in selection]) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
188 |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
189 |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
190 class RoomAndContactsChooser(DialogBox): |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
191 """Select a room and some users to invite in""" |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
192 |
288
7316a5696366
browser_side: renamed item and labels for discussion groups
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
193 def __init__(self, host, callback, nb_contact=None, ok_button="OK", title="Discussion groups", |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
194 title_room="Join room", title_invite="Invite contacts", visible=(True, True)): |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
195 DialogBox.__init__(self, centered=True) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
196 self.host = host |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
197 self.callback = callback |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
198 self.title_room = title_room |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
199 self.title_invite = title_invite |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
200 |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 button_panel = HorizontalPanel() |
238
dec76d4536ad
browser_side: set CSS margin: auto for all button panels
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
202 button_panel.addStyleName("marginAuto") |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
203 ok_button = Button("OK", self.onOK) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
204 button_panel.add(ok_button) |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 button_panel.add(Button("Cancel", self.onCancel)) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
206 |
692
7a9c7b9f6a28
browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents:
686
diff
changeset
|
207 self.room_panel = RoomChooser(host, None if visible == (False, True) else host.default_muc) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
208 self.contact_panel = ContactsChooser(host, nb_contact, ok_button) |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
209
diff
changeset
|
209 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
638
diff
changeset
|
210 self.stack_panel = base_panel.ToggleStackPanel(Width="100%") |
399
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
211 self.stack_panel.add(self.room_panel, visible=visible[0]) |
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
212 self.stack_panel.add(self.contact_panel, visible=visible[1]) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
213 self.stack_panel.addStackChangeListener(self) |
399
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
214 self.onStackChanged(self.stack_panel, 0, visible[0]) |
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
215 self.onStackChanged(self.stack_panel, 1, visible[1]) |
6e38d317bc16
browser_side: RoomChooser small improvements:
souliane <souliane@mailoo.org>
parents:
357
diff
changeset
|
216 |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
217 main_panel = VerticalPanel() |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
218 main_panel.setStyleName("room-contact-chooser") |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
219 main_panel.add(self.stack_panel) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
220 main_panel.add(button_panel) |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
222 self.setWidget(main_panel) |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
223 self.setHTML(title) |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 self.show() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
226 # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
227 self.presenceListener = self.refreshContactList |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
228 # update the contacts list when someone logged in/out |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
229 self.host.addListener('presence', self.presenceListener, [C.PROF_KEY_NONE]) |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
230 |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
231 @property |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
232 def room(self): |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
233 """Get the room that has been selected or entered by the user |
271
d868181d0649
browser_side: update contacts in "group and contact chooser" when the a user connect/disconnect
souliane <souliane@mailoo.org>
parents:
268
diff
changeset
|
234 |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
235 @return: jid.JID or None |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
236 """ |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
237 return self.room_panel.room |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
238 |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
239 @property |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
240 def contacts(self): |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
241 """Return the selected contacts. |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
242 |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
243 @return: list[jid.JID] |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
244 """ |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
245 return self.contact_panel.contacts |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
246 |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
247 def onStackChanged(self, sender, index, visible=None): |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
248 if visible is None: |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
249 visible = sender.getWidget(index).getVisible() |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
250 if index == 0: |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
251 suffix = "" if (visible or not self.room) else ": %s" % self.room |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
252 sender.setStackText(0, self.title_room + suffix) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
253 elif index == 1: |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
254 suffix = "" if (visible or not self.contacts) else ": %s" % ", ".join([unicode(contact) for contact in self.contacts]) |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
255 sender.setStackText(1, self.title_invite + suffix) |
271
d868181d0649
browser_side: update contacts in "group and contact chooser" when the a user connect/disconnect
souliane <souliane@mailoo.org>
parents:
268
diff
changeset
|
256 |
638
63697f082e8a
browser side: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents:
626
diff
changeset
|
257 def refreshContactList(self, *args, **kwargs): |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
258 """Called when someone log in/out to update the list. |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
259 |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
260 @param args: set by the event call but not used here |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
261 """ |
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
262 self.contact_panel.refreshOptions(keep_selected=True) |
268
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
263 |
79970bf6af93
browser_side: added class RoomAndContactsChooser:
souliane <souliane@mailoo.org>
parents:
262
diff
changeset
|
264 def onOK(self, sender): |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
265 room = self.room # pyjamas issue: you need to use an intermediate variable to access a property's method |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 self.hide() |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
267 self.callback(room, self.contacts) |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 |
62 | 269 def onCancel(self, sender): |
26
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 self.hide() |
824516b247e6
browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 |
271
d868181d0649
browser_side: update contacts in "group and contact chooser" when the a user connect/disconnect
souliane <souliane@mailoo.org>
parents:
268
diff
changeset
|
272 def hide(self): |
626
ba2555c29c84
browser_side: fixes RoomAndContactsChooser dialog
souliane <souliane@mailoo.org>
parents:
625
diff
changeset
|
273 self.host.removeListener('presence', self.presenceListener) |
271
d868181d0649
browser_side: update contacts in "group and contact chooser" when the a user connect/disconnect
souliane <souliane@mailoo.org>
parents:
268
diff
changeset
|
274 DialogBox.hide(self, autoClosed=True) |
d868181d0649
browser_side: update contacts in "group and contact chooser" when the a user connect/disconnect
souliane <souliane@mailoo.org>
parents:
268
diff
changeset
|
275 |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
276 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
277 class GenericConfirmDialog(DialogBox): |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
278 |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
279 def __init__(self, widgets, callback, title='Confirmation', prompt_widgets=None, **kwargs): |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
280 """ |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
281 Dialog to confirm an action |
516
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
282 @param widgets (list[Widget]): widgets to attach |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
283 @param callback (callable): method to call when a button is pressed, |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
284 with the following arguments: |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
285 - result (bool): set to True if the dialog has been confirmed |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
286 - *args: a list of unicode (the values for the prompt_widgets) |
354
c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
287 @param title: title of the dialog |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
288 @param prompt_widgets (list[TextBox]): input widgets from which to retrieve |
516
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
289 the string value(s) to be passed to the callback when OK button is pressed. |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
290 If None, OK button will return "True". Cancel button always returns "False". |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
291 """ |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
292 self.callback = callback |
524
d41e850b31b9
browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents:
516
diff
changeset
|
293 added_style = kwargs.pop('AddStyleName', None) |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
294 DialogBox.__init__(self, centered=True, **kwargs) |
524
d41e850b31b9
browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents:
516
diff
changeset
|
295 if added_style: |
d41e850b31b9
browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents:
516
diff
changeset
|
296 self.addStyleName(added_style) |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
297 |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
298 if prompt_widgets is None: |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
299 prompt_widgets = [] |
516
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
300 |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
301 content = VerticalPanel() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
302 content.setWidth('100%') |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
303 for wid in widgets: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
304 content.add(wid) |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
305 if wid in prompt_widgets: |
354
c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
306 wid.setWidth('100%') |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
307 button_panel = HorizontalPanel() |
224
f3a5a094c8d6
browser_side: center the buttons of GenericConfirmDialog
souliane <souliane@mailoo.org>
parents:
221
diff
changeset
|
308 button_panel.addStyleName("marginAuto") |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
309 self.confirm_button = Button("OK", self.onConfirm) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
310 button_panel.add(self.confirm_button) |
357
2b5503392fbd
browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents:
354
diff
changeset
|
311 self.cancel_button = Button("Cancel", self.onCancel) |
2b5503392fbd
browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents:
354
diff
changeset
|
312 button_panel.add(self.cancel_button) |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
313 content.add(button_panel) |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
314 self.setHTML(title) |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
209
diff
changeset
|
315 self.setWidget(content) |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
316 self.prompt_widgets = prompt_widgets |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
209
diff
changeset
|
317 |
62 | 318 def onConfirm(self, sender): |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
319 self.hide() |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
320 result = [True] |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
321 result.extend([box.getText() for box in self.prompt_widgets]) |
516
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
322 self.callback(*result) |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
323 |
62 | 324 def onCancel(self, sender): |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
325 self.hide() |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
326 self.callback(False) |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
327 |
354
c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
328 def show(self): |
c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
329 DialogBox.show(self) |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
330 if self.prompt_widgets: |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
331 self.prompt_widgets[0].setFocus(True) |
354
c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
332 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
209
diff
changeset
|
333 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
334 class ConfirmDialog(GenericConfirmDialog): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
335 |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
336 def __init__(self, callback, text='Are you sure ?', title='Confirmation', **kwargs): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
337 GenericConfirmDialog.__init__(self, [HTML(text)], callback, title, **kwargs) |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
209
diff
changeset
|
338 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
339 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
340 class GenericDialog(DialogBox): |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
341 """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
|
342 |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
343 def __init__(self, title, main_widget, callback=None, options=None, **kwargs): |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
344 """Simple notice dialog box |
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
345 @param title: HTML put in the header |
145
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
346 @param main_widget: widget put in the body |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
347 @param callback: method to call on closing |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
348 @param options: one or more of the following options: |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
349 - NO_CLOSE: don't add a close button""" |
524
d41e850b31b9
browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents:
516
diff
changeset
|
350 added_style = kwargs.pop('AddStyleName', None) |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
351 DialogBox.__init__(self, centered=True, **kwargs) |
524
d41e850b31b9
browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents:
516
diff
changeset
|
352 if added_style: |
d41e850b31b9
browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents:
516
diff
changeset
|
353 self.addStyleName(added_style) |
d41e850b31b9
browser_side (plugin OTR): limit the max width for all dialogs
souliane <souliane@mailoo.org>
parents:
516
diff
changeset
|
354 |
42 | 355 self.callback = callback |
145
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
356 if not options: |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
357 options = [] |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
358 _body = VerticalPanel() |
451 | 359 _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
|
360 _body.setSpacing(4) |
145
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
361 _body.add(main_widget) |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
362 _body.setCellWidth(main_widget, '100%') |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
363 _body.setCellHeight(main_widget, '100%') |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
364 if 'NO_CLOSE' not in options: |
145
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
365 _close_button = Button("Close", self.onClose) |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
366 _body.add(_close_button) |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
367 _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
|
368 self.setHTML(title) |
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
369 self.setWidget(_body) |
451 | 370 self.panel.setSize('100%', '100%') # Need this hack to have correct size in Gecko & Webkit |
145
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
371 |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
372 def close(self): |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
373 """Same effect as clicking the close button""" |
c0035e5e2d08
browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
374 self.onClose(None) |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
375 |
62 | 376 def onClose(self, sender): |
41
7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
377 self.hide() |
42 | 378 if self.callback: |
379 self.callback() | |
43
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
380 |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
381 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
382 class InfoDialog(GenericDialog): |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
383 |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
384 def __init__(self, title, body, callback=None, options=None, **kwargs): |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
385 GenericDialog.__init__(self, title, HTML(body), callback, options, **kwargs) |
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
386 |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
387 |
354
c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
388 class PromptDialog(GenericConfirmDialog): |
c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
389 |
516
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
390 def __init__(self, callback, textes=None, values=None, title='User input', **kwargs): |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
391 """Prompt the user for one or more input(s). |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
392 |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
393 @param callback (callable): method to call when a button is pressed, |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
394 with the following arguments: |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
395 - result (bool): set to True if the dialog has been confirmed |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
396 - *args: a list of unicode (the values entered by the user) |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
397 @param textes (list[unicode]): HTML textes to display before the inputs |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
398 @param values (list[unicode]): default values for each input |
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
399 @param title (unicode): dialog title |
516
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
400 """ |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
401 if textes is None: |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
402 textes = [''] # display a single input without any description |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
403 if values is None: |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
404 values = [] |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
405 all_widgets = [] |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
406 prompt_widgets = [] |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
407 for count in xrange(len(textes)): |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
408 all_widgets.append(HTML(textes[count])) |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
409 prompt = TextBox() |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
410 if len(values) > count: |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
411 prompt.setText(values[count]) |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
412 all_widgets.append(prompt) |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
413 prompt_widgets.append(prompt) |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
414 |
1af112b97e45
browser_side: PromptDialog can display several input fields
souliane <souliane@mailoo.org>
parents:
467
diff
changeset
|
415 GenericConfirmDialog.__init__(self, all_widgets, callback, title, prompt_widgets, **kwargs) |
354
c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
416 |
c417a7acfe44
browser_side: class PromptDialog based on GenericConfirmDialog asks the user for a text input
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
417 |
43
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
418 class PopupPanelWrapper(PopupPanel): |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
419 """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
|
420 |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
421 def onEventPreview(self, event): |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
422 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: |
625
ed9cd20260ff
browser_side (PromptDialog): rename prompt attribute to prompt_widgets + related changes
souliane <souliane@mailoo.org>
parents:
524
diff
changeset
|
423 # needed to prevent request cancellation in Firefox |
43
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
424 event.preventDefault() |
a7ff1e6f1229
browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
425 return PopupPanel.onEventPreview(self, event) |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
426 |
231
fab7aa366576
browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents:
227
diff
changeset
|
427 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
428 class ExtTextBox(TextBox): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
429 """Extended TextBox""" |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
430 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
431 def __init__(self, *args, **kwargs): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
432 if 'enter_cb' in kwargs: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
433 self.enter_cb = kwargs['enter_cb'] |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
434 del kwargs['enter_cb'] |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
435 TextBox.__init__(self, *args, **kwargs) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
436 self.addKeyboardListener(self) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
437 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
438 def onKeyUp(self, sender, keycode, modifiers): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
439 pass |
216
9827cda1a6b0
browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents:
212
diff
changeset
|
440 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
441 def onKeyDown(self, sender, keycode, modifiers): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
442 pass |
216
9827cda1a6b0
browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents:
212
diff
changeset
|
443 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
444 def onKeyPress(self, sender, keycode, modifiers): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
445 if self.enter_cb and keycode == KEY_ENTER: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
446 self.enter_cb(self) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
447 |
253
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
448 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
449 class GroupSelector(DialogBox): |
216
9827cda1a6b0
browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents:
212
diff
changeset
|
450 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
209
diff
changeset
|
451 def __init__(self, top_widgets, initial_groups, selected_groups, |
227
67e24c342e7f
browser_side: bug fix for changeset 3092f6b1710c
souliane <souliane@mailoo.org>
parents:
224
diff
changeset
|
452 ok_title="OK", ok_cb=None, cancel_cb=None): |
253
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
453 DialogBox.__init__(self, centered=True) |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
454 main_panel = VerticalPanel() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
455 self.ok_cb = ok_cb |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
456 self.cancel_cb = cancel_cb |
216
9827cda1a6b0
browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents:
212
diff
changeset
|
457 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
458 for wid in top_widgets: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
459 main_panel.add(wid) |
216
9827cda1a6b0
browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents:
212
diff
changeset
|
460 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
461 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
|
462 self.list_box = ListBox() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
463 self.list_box.setMultipleSelect(True) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
464 self.list_box.setVisibleItemCount(5) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
465 self.setAvailableGroups(initial_groups) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
466 self.setGroupsSelected(selected_groups) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
467 main_panel.add(self.list_box) |
216
9827cda1a6b0
browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents:
212
diff
changeset
|
468 |
253
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
469 def cb(text): |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
470 self.list_box.addItem(text) |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
471 self.list_box.setItemSelected(self.list_box.getItemCount() - 1, "selected") |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
472 |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
473 main_panel.add(AddGroupPanel(initial_groups, cb)) |
216
9827cda1a6b0
browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents:
212
diff
changeset
|
474 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
475 button_panel = HorizontalPanel() |
238
dec76d4536ad
browser_side: set CSS margin: auto for all button panels
souliane <souliane@mailoo.org>
parents:
231
diff
changeset
|
476 button_panel.addStyleName("marginAuto") |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
209
diff
changeset
|
477 button_panel.add(Button(ok_title, self.onOK)) |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
478 button_panel.add(Button("Cancel", self.onCancel)) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
479 main_panel.add(button_panel) |
216
9827cda1a6b0
browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents:
212
diff
changeset
|
480 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
481 self.setWidget(main_panel) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
482 |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
483 def getSelectedGroups(self): |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
484 """Return a list of selected groups""" |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
485 return self.list_box.getSelectedValues() |
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
486 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
487 def setAvailableGroups(self, groups): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
488 _groups = list(set(groups)) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
489 _groups.sort() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
490 self.list_box.clear() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
491 for group in _groups: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
492 self.list_box.addItem(group) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
493 |
57
e552a67b933d
Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
494 def setGroupsSelected(self, selected_groups): |
209
4564c7bc06a7
browser side: fixed setGroupsSelected in GroupSelector
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
495 self.list_box.setItemTextSelection(selected_groups) |
211
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
496 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
497 def onOK(self, sender): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
498 self.hide() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
499 if self.ok_cb: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
500 self.ok_cb(self) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
501 |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
502 def onCancel(self, sender): |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
503 self.hide() |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
504 if self.cancel_cb: |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
505 self.cancel_cb(self) |
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
506 |
253
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
507 |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
508 class AddGroupPanel(HorizontalPanel): |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
509 def __init__(self, groups, cb=None): |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
510 """ |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
511 @param groups: list of the already existing groups |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
512 """ |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
513 HorizontalPanel.__init__(self) |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
514 self.groups = groups |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
515 self.add(Label('New group:')) |
262
30c01671e338
browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents:
255
diff
changeset
|
516 self.textbox = ExtTextBox(enter_cb=self.onGroupInput) |
30c01671e338
browser_side: small changes for contact list and "add group" panel:
souliane <souliane@mailoo.org>
parents:
255
diff
changeset
|
517 self.add(self.textbox) |
735
e4ae8e2b0afd
browser_side: improve PopupMenuPanel comments + rename a button + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
518 self.add(Button("Add", lambda sender: self.onGroupInput(self.textbox))) |
253
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
519 self.cb = cb |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
520 |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
521 def onGroupInput(self, sender): |
211
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
522 text = sender.getText() |
255
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
253
diff
changeset
|
523 if text == "": |
da0487f0a2e7
browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents:
253
diff
changeset
|
524 return |
253
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
525 for group in self.groups: |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
526 if text == group: |
221
f3898fbb00c3
browser_side: check for duplicate name before adding a new contact group
souliane <souliane@mailoo.org>
parents:
216
diff
changeset
|
527 Window.alert("The group '%s' already exists." % text) |
f3898fbb00c3
browser_side: check for duplicate name before adding a new contact group
souliane <souliane@mailoo.org>
parents:
216
diff
changeset
|
528 return |
211
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
529 for pattern in FORBIDDEN_PATTERNS_IN_GROUP: |
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
530 if pattern in text: |
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
531 Window.alert("The pattern '%s' is not allowed in group names." % pattern) |
49920d76aa6a
browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
532 return |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
533 sender.setText('') |
253
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
534 self.groups.append(text) |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
535 if self.cb is not None: |
19153af4f327
browser_side: isolate the "add contact group" panel in a re-usable class:
souliane <souliane@mailoo.org>
parents:
240
diff
changeset
|
536 self.cb(text) |
52
4419ef07bb2b
browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents:
49
diff
changeset
|
537 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
209
diff
changeset
|
538 |
95
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
539 class WheelTextBox(TextBox, MouseWheelHandler): |
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
540 |
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
541 def __init__(self, *args, **kwargs): |
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
542 TextBox.__init__(self, *args, **kwargs) |
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
543 MouseWheelHandler.__init__(self) |
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
544 |
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
545 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
546 class IntSetter(HorizontalPanel): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
547 """This class show a bar with button to set an int value""" |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
548 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
549 def __init__(self, label, value=0, value_max=None, visible_len=3): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
550 """initialize the intSetter |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
551 @param label: text shown in front of the setter |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
552 @param value: initial value |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
553 @param value_max: limit value, None or 0 for unlimited""" |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
554 HorizontalPanel.__init__(self) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
555 self.value = value |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
556 self.value_max = value_max |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
557 _label = Label(label) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
558 self.add(_label) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
559 self.setCellWidth(_label, "100%") |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
560 minus_button = Button("-", self.onMinus) |
95
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
561 self.box = WheelTextBox() |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
562 self.box.setVisibleLength(visible_len) |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
648
diff
changeset
|
563 self.box.setText(unicode(value)) |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
564 self.box.addInputListener(self) |
95
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
565 self.box.addMouseWheelListener(self) |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
566 plus_button = Button("+", self.onPlus) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
567 self.add(minus_button) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
568 self.add(self.box) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
569 self.add(plus_button) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
570 self.valueChangedListener = [] |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
571 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
572 def addValueChangeListener(self, listener): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
573 self.valueChangedListener.append(listener) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
574 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
575 def removeValueChangeListener(self, listener): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
576 if listener in self.valueChangedListener: |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
577 self.valueChangedListener.remove(listener) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
578 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
579 def _callListeners(self): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
580 for listener in self.valueChangedListener: |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
581 listener(self.value) |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
582 |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
583 def setValue(self, value): |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
584 """Change the value and fire valueChange listeners""" |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
585 self.value = value |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
648
diff
changeset
|
586 self.box.setText(unicode(value)) |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
587 self._callListeners() |
212
a05e16f4a343
browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents:
211
diff
changeset
|
588 |
95
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
589 def onMinus(self, sender, step=1): |
212
a05e16f4a343
browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents:
211
diff
changeset
|
590 self.value = max(0, self.value - step) |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
648
diff
changeset
|
591 self.box.setText(unicode(self.value)) |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
592 self._callListeners() |
212
a05e16f4a343
browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents:
211
diff
changeset
|
593 |
95
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
594 def onPlus(self, sender, step=1): |
212
a05e16f4a343
browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents:
211
diff
changeset
|
595 self.value += step |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
596 if self.value_max: |
212
a05e16f4a343
browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents:
211
diff
changeset
|
597 self.value = min(self.value, self.value_max) |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
648
diff
changeset
|
598 self.box.setText(unicode(self.value)) |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
599 self._callListeners() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
600 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
601 def onInput(self, sender): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
602 """Accept only valid integer && normalize print (no leading 0)""" |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
603 try: |
212
a05e16f4a343
browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents:
211
diff
changeset
|
604 self.value = int(self.box.getText()) if self.box.getText() else 0 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
605 except ValueError: |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
606 pass |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
607 if self.value_max: |
212
a05e16f4a343
browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents:
211
diff
changeset
|
608 self.value = min(self.value, self.value_max) |
662
ebb602d8b3f2
browser_side: replace all instances of 'str' with 'unicode'
souliane <souliane@mailoo.org>
parents:
648
diff
changeset
|
609 self.box.setText(unicode(self.value)) |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
610 self._callListeners() |
95
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
611 |
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
612 def onMouseWheel(self, sender, velocity): |
212
a05e16f4a343
browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents:
211
diff
changeset
|
613 if velocity > 0: |
95
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
614 self.onMinus(sender, 10) |
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
615 else: |
1c75fd97baf9
browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents:
94
diff
changeset
|
616 self.onPlus(sender, 10) |