annotate browser_side/dialog.py @ 232:0ed09cc0566f

browser_side: added UIs for rich text editor and addressing to multiple recipients The rich text format is set according to a user parameter which is for now not created, so you will get a warning on the backend and no toolbar will be displayed. For testing purpose: - you can set _debug to True in RichTextEditor: that will display one toolbar per format. - you can add this parameter to any plugin (the same will be added later in XEP-0071): # DEBUG: TO BE REMOVED LATER, THIS BELONGS TO RICH TEXT EDITOR FORMATS = {"markdown": {}, "bbcode": {}, "dokuwiki": {}, "html": {}} FORMAT_PARAM_KEY = "Composition and addressing" FORMAT_PARAM_NAME = "Format for rich text message composition" # In the parameter definition: <category name="%(format_category_name)s" label="%(format_category_label)s"> <param name="%(format_param_name)s" label="%(format_param_label)s" value="%(format_param_default)s" type="list" security="0"> %(format_options)s </param> </category> # Strings for the placeholders: 'format_category_name': FORMAT_PARAM_KEY, 'format_category_label': _(FORMAT_PARAM_KEY), 'format_param_name': FORMAT_PARAM_NAME, 'format_param_label': _(FORMAT_PARAM_NAME), 'format_param_default': FORMATS.keys()[0], 'format_options': ['<option value="%s"/>' % format for format in FORMATS.keys()]
author souliane <souliane@mailoo.org>
date Tue, 08 Oct 2013 14:12:38 +0200
parents fab7aa366576
children dec76d4536ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
3
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
165
9763dec220ed dates update
Goffi <goffi@goffi.org>
parents: 145
diff changeset
6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org>
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
7
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
12
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
17
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
21
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from pyjamas.ui.VerticalPanel import VerticalPanel
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.HorizontalPanel import HorizontalPanel
43
a7ff1e6f1229 browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents: 42
diff changeset
24 from pyjamas.ui.PopupPanel import PopupPanel
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.DialogBox import DialogBox
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.ListBox import ListBox
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.Button import Button
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
28 from pyjamas.ui.TextBox import TextBox
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
29 from pyjamas.ui.Label import Label
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
30 from pyjamas.ui.HTML import HTML
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 57
diff changeset
31 from pyjamas.ui.Frame import Frame
48
153de5d461a4 added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents: 43
diff changeset
32 from pyjamas.ui import HasAlignment
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
33 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
34 from pyjamas.ui.MouseListener import MouseWheelHandler
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
35 from pyjamas import DOM
211
49920d76aa6a browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents: 210
diff changeset
36 from pyjamas import Window
49920d76aa6a browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents: 210
diff changeset
37
49920d76aa6a browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents: 210
diff changeset
38 # 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
39 FORBIDDEN_PATTERNS_IN_GROUP = ()
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
40
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
41 class ContactsChooser(DialogBox):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
42
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
44 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
45 ContactsChooser allow to select one or several connected contacts
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
46 @param host: SatWebFrontend instance
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
47 @param callback: method to call when contacts have been choosed
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
48 @param nb_contact: number of contacts that have to be selected, None for no limit
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
49 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.host = host
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.callback = callback
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.nb_contact = nb_contact
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
53 DialogBox.__init__(self, centered=True)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
54
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
55 content = VerticalPanel()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
56 content.setWidth('100%')
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.contacts_list = ListBox()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.contacts_list.setVisibleItemCount(10)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.contacts_list.setMultipleSelect(True)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.contacts_list.setWidth("100%")
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.contacts_list.setStyleName('contactsChooser')
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self.contacts_list.addChangeListener(self.onChange)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
63 content.add(self.contacts_list)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
64 button_panel = HorizontalPanel()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.choose_button = Button("Choose", self.onChoose)
125
f9d63624699f radio collective integration, first draft
Goffi <goffi@goffi.org>
parents: 95
diff changeset
66 if (nb_contact):
f9d63624699f radio collective integration, first draft
Goffi <goffi@goffi.org>
parents: 95
diff changeset
67 self.choose_button.setEnabled(False)
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
68 button_panel.add(self.choose_button)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
69 button_panel.add(Button("Cancel", self.onCancel))
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
70 content.add(button_panel)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.setHTML(text)
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
72 self.setWidget(content)
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
73
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 57
diff changeset
74 def onChange(self, sender):
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
75 if self.nb_contact:
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
76 if len(self.contacts_list.getSelectedValues()) == self.nb_contact:
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self.choose_button.setEnabled(True)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
78 else:
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.choose_button.setEnabled(False)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
80
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def getContacts(self):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
82 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
83 Actually ask to choose the contacts
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
84 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.contacts_list.clear()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
86 for contact in self.host.contact_panel.getConnected():
32
6b8da70b0799 browser_side: contactsChooser now discard MUC rooms
Goffi <goffi@goffi.org>
parents: 26
diff changeset
87 if contact not in [room.bare for room in self.host.room_list]:
6b8da70b0799 browser_side: contactsChooser now discard MUC rooms
Goffi <goffi@goffi.org>
parents: 26
diff changeset
88 self.contacts_list.addItem(contact)
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.show()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
90
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 57
diff changeset
91 def onChoose(self, sender):
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.hide()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.callback(self.contacts_list.getSelectedValues())
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
94
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 57
diff changeset
95 def onCancel(self, sender):
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self.hide()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
97
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 227
diff changeset
98
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
99 class GenericConfirmDialog(DialogBox):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
100
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 227
diff changeset
101 def __init__(self, widgets, callback, title='Confirmation', **kwargs):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
102 """
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
103 Dialog to confirm an action
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
104 @param callback: method to call when contacts have been choosed
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
105 """
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
106 self.callback = callback
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 227
diff changeset
107 DialogBox.__init__(self, centered=True, **kwargs)
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
108
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
109 content = VerticalPanel()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
110 content.setWidth('100%')
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
111 for wid in widgets:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
112 content.add(wid)
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
113 button_panel = HorizontalPanel()
224
f3a5a094c8d6 browser_side: center the buttons of GenericConfirmDialog
souliane <souliane@mailoo.org>
parents: 221
diff changeset
114 button_panel.addStyleName("marginAuto")
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
115 self.confirm_button = Button("OK", self.onConfirm)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
116 button_panel.add(self.confirm_button)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
117 button_panel.add(Button("Cancel", self.onCancel))
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
118 content.add(button_panel)
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
119 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
120 self.setWidget(content)
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
121
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 57
diff changeset
122 def onConfirm(self, sender):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
123 self.hide()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
124 self.callback(True)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
125
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 57
diff changeset
126 def onCancel(self, sender):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
127 self.hide()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
128 self.callback(False)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 32
diff changeset
129
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
130
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
131 class ConfirmDialog(GenericConfirmDialog):
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
132
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 227
diff changeset
133 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
134 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
135
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
136
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
137 class GenericDialog(DialogBox):
48
153de5d461a4 added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents: 43
diff changeset
138 """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
139
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 227
diff changeset
140 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
141 """Simple notice dialog box
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
142 @param title: HTML put in the header
145
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
143 @param main_widget: widget put in the body
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
144 @param callback: method to call on closing
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
145 @param options: one or more of the following options:
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
146 - NO_CLOSE: don't add a close button"""
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 227
diff changeset
147 DialogBox.__init__(self, centered=True, **kwargs)
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
148 self.callback = callback
145
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
149 if not options:
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
150 options = []
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
151 _body = VerticalPanel()
48
153de5d461a4 added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents: 43
diff changeset
152 _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
153 _body.setSpacing(4)
145
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
154 _body.add(main_widget)
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
155 _body.setCellWidth(main_widget, '100%')
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
156 _body.setCellHeight(main_widget, '100%')
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
157 if not 'NO_CLOSE' in options:
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
158 _close_button = Button("Close", self.onClose)
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
159 _body.add(_close_button)
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
160 _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
161 self.setHTML(title)
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
162 self.setWidget(_body)
145
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
163 self.panel.setSize('100%', '100%') #Need this hack to have correct size in Gecko & Webkit
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
164
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
165 def close(self):
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
166 """Same effect as clicking the close button"""
c0035e5e2d08 browser side: misc dialog improvment:
Goffi <goffi@goffi.org>
parents: 131
diff changeset
167 self.onClose(None)
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
168
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 57
diff changeset
169 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
170 self.hide()
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
171 if self.callback:
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
172 self.callback()
43
a7ff1e6f1229 browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents: 42
diff changeset
173
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 227
diff changeset
174
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
175 class InfoDialog(GenericDialog):
48
153de5d461a4 added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents: 43
diff changeset
176
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 227
diff changeset
177 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
178 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
179
48
153de5d461a4 added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents: 43
diff changeset
180
43
a7ff1e6f1229 browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents: 42
diff changeset
181 class PopupPanelWrapper(PopupPanel):
a7ff1e6f1229 browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents: 42
diff changeset
182 """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
183
a7ff1e6f1229 browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents: 42
diff changeset
184 def onEventPreview(self, event):
a7ff1e6f1229 browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents: 42
diff changeset
185 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE:
a7ff1e6f1229 browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents: 42
diff changeset
186 #needed to prevent request cancellation in Firefox
a7ff1e6f1229 browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents: 42
diff changeset
187 event.preventDefault()
a7ff1e6f1229 browser_side: prevent default for escape key (cancel HTTPRequest in FF)
Goffi <goffi@goffi.org>
parents: 42
diff changeset
188 return PopupPanel.onEventPreview(self, event)
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
189
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 227
diff changeset
190
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
191 class ExtTextBox(TextBox):
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
192 """Extended TextBox"""
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
193
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
194 def __init__(self, *args, **kwargs):
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
195 if 'enter_cb' in kwargs:
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
196 self.enter_cb = kwargs['enter_cb']
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
197 del kwargs['enter_cb']
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
198 TextBox.__init__(self, *args, **kwargs)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
199 self.addKeyboardListener(self)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
200
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
201 def onKeyUp(self, sender, keycode, modifiers):
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
202 pass
216
9827cda1a6b0 browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents: 212
diff changeset
203
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
204 def onKeyDown(self, sender, keycode, modifiers):
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
205 pass
216
9827cda1a6b0 browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents: 212
diff changeset
206
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
207 def onKeyPress(self, sender, keycode, modifiers):
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
208 if self.enter_cb and keycode == KEY_ENTER:
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
209 self.enter_cb(self)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
210
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
211 class GroupSelector(DialogBox):
216
9827cda1a6b0 browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents: 212
diff changeset
212
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
213 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
214 ok_title="OK", ok_cb=None, cancel_cb=None):
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
215 DialogBox.__init__(self, centered = True)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
216 main_panel = VerticalPanel()
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
217 self.ok_cb = ok_cb
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
218 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
219
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
220 for wid in top_widgets:
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
221 main_panel.add(wid)
216
9827cda1a6b0 browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents: 212
diff changeset
222
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
223 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
224 self.list_box = ListBox()
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
225 self.list_box.setMultipleSelect(True)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
226 self.list_box.setVisibleItemCount(5)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
227 self.setAvailableGroups(initial_groups)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
228 self.setGroupsSelected(selected_groups)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
229 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
230
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
231 add_group_panel = HorizontalPanel()
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
232 add_group_lb = Label('Add group:')
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
233 add_group_tb = ExtTextBox(enter_cb = self.onGroupInput)
208
bbcad87585eb browser side: added "add" button in GroupSelector's add group dialog
Goffi <goffi@goffi.org>
parents: 165
diff changeset
234 add_group_bt = Button("add", lambda sender: self.onGroupInput(add_group_tb))
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
235 add_group_panel.add(add_group_lb)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
236 add_group_panel.add(add_group_tb)
208
bbcad87585eb browser side: added "add" button in GroupSelector's add group dialog
Goffi <goffi@goffi.org>
parents: 165
diff changeset
237 add_group_panel.add(add_group_bt)
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
238 main_panel.add(add_group_panel)
216
9827cda1a6b0 browser_side: added key listener to login and register panels
souliane <souliane@mailoo.org>
parents: 212
diff changeset
239
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
240 button_panel = HorizontalPanel()
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
241 button_panel.add(Button(ok_title, self.onOK))
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
242 button_panel.add(Button("Cancel", self.onCancel))
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
243 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
244
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
245 self.setWidget(main_panel)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
246
54
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 52
diff changeset
247 def getSelectedGroups(self):
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 52
diff changeset
248 """Return a list of selected groups"""
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 52
diff changeset
249 return self.list_box.getSelectedValues()
f25c4077f6b9 addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents: 52
diff changeset
250
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
251 def setAvailableGroups(self, groups):
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
252 _groups = list(set(groups))
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
253 _groups.sort()
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
254 self.list_box.clear()
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
255 for group in _groups:
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
256 self.list_box.addItem(group)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
257
57
e552a67b933d Contact update + add dedication in About dialog
Goffi <goffi@goffi.org>
parents: 55
diff changeset
258 def setGroupsSelected(self, selected_groups):
209
4564c7bc06a7 browser side: fixed setGroupsSelected in GroupSelector
Goffi <goffi@goffi.org>
parents: 208
diff changeset
259 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
260
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
261 def onOK(self, sender):
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
262 self.hide()
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
263 if self.ok_cb:
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
264 self.ok_cb(self)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
265
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
266 def onCancel(self, sender):
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
267 self.hide()
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
268 if self.cancel_cb:
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
269 self.cancel_cb(self)
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
270
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
271 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
272 text = sender.getText()
221
f3898fbb00c3 browser_side: check for duplicate name before adding a new contact group
souliane <souliane@mailoo.org>
parents: 216
diff changeset
273 for index in xrange(0, self.list_box.getItemCount()):
f3898fbb00c3 browser_side: check for duplicate name before adding a new contact group
souliane <souliane@mailoo.org>
parents: 216
diff changeset
274 if text == self.list_box.getValue(index):
f3898fbb00c3 browser_side: check for duplicate name before adding a new contact group
souliane <souliane@mailoo.org>
parents: 216
diff changeset
275 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
276 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
277 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
278 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
279 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
280 return
49920d76aa6a browser side: added a mechanism to define forbidden patterns during new contact group creation
souliane <souliane@mailoo.org>
parents: 210
diff changeset
281 self.list_box.addItem(text)
52
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
282 sender.setText('')
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
283 self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected")
4419ef07bb2b browser side: adding contact, first draft
Goffi <goffi@goffi.org>
parents: 49
diff changeset
284
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
285
95
1c75fd97baf9 browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents: 94
diff changeset
286 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
287
1c75fd97baf9 browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents: 94
diff changeset
288 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
289 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
290 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
291
1c75fd97baf9 browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents: 94
diff changeset
292
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
293 class IntSetter(HorizontalPanel):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
294 """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
295
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
296 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
297 """initialize the intSetter
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
298 @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
299 @param value: initial value
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
300 @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
301 HorizontalPanel.__init__(self)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
302 self.value = value
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
303 self.value_max = value_max
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
304 _label = Label(label)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
305 self.add(_label)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
306 self.setCellWidth(_label, "100%")
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
307 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
308 self.box = WheelTextBox()
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
309 self.box.setVisibleLength(visible_len)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
310 self.box.setText(str(value))
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
311 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
312 self.box.addMouseWheelListener(self)
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
313 plus_button = Button("+", self.onPlus)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
314 self.add(minus_button)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
315 self.add(self.box)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
316 self.add(plus_button)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
317 self.valueChangedListener = []
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
318
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
319 def addValueChangeListener(self, listener):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
320 self.valueChangedListener.append(listener)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
321
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
322 def removeValueChangeListener(self, listener):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
323 if listener in self.valueChangedListener:
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
324 self.valueChangedListener.remove(listener)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
325
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
326 def _callListeners(self):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
327 for listener in self.valueChangedListener:
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
328 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
329
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
330 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
331 """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
332 self.value = value
94
8f9d30672225 browser side: widgets' setting reset button update fix
Goffi <goffi@goffi.org>
parents: 93
diff changeset
333 self.box.setText(str(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
334 self._callListeners()
212
a05e16f4a343 browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents: 211
diff changeset
335
95
1c75fd97baf9 browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents: 94
diff changeset
336 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
337 self.value = max(0, self.value - step)
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
338 self.box.setText(str(self.value))
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
339 self._callListeners()
212
a05e16f4a343 browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents: 211
diff changeset
340
95
1c75fd97baf9 browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents: 94
diff changeset
341 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
342 self.value += step
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
343 if self.value_max:
212
a05e16f4a343 browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents: 211
diff changeset
344 self.value = min(self.value, self.value_max)
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
345 self.box.setText(str(self.value))
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
346 self._callListeners()
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
347
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
348 def onInput(self, sender):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
349 """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
350 try:
212
a05e16f4a343 browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents: 211
diff changeset
351 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
352 except ValueError:
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
353 pass
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
354 if self.value_max:
212
a05e16f4a343 browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents: 211
diff changeset
355 self.value = min(self.value, self.value_max)
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
356 self.box.setText(str(self.value))
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 66
diff changeset
357 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
358
1c75fd97baf9 browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents: 94
diff changeset
359 def onMouseWheel(self, sender, velocity):
212
a05e16f4a343 browser side: bug fix (missing "self." before value_max)
souliane <souliane@mailoo.org>
parents: 211
diff changeset
360 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
361 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
362 else:
1c75fd97baf9 browser side: widgets' setting: mouse wheel can now be used to change values
Goffi <goffi@goffi.org>
parents: 94
diff changeset
363 self.onPlus(sender, 10)