Mercurial > libervia-web
annotate browser_side/panels.py @ 84:8f35e9970e7f
browser side: new widget handling:
- new design integration improved (ChatPanel is now working)
- widget now register themselves for event handling
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 Jun 2011 23:23:22 +0200 |
parents | 68d360caeecb |
children | a8f027738c16 |
rev | line source |
---|---|
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
6 Copyright (C) 2011 Jérôme Poisson <goffi@goffi.org> |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from pyjamas.ui.SimplePanel import SimplePanel |
33 | 24 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.VerticalPanel import VerticalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas.ui.ScrollPanel import ScrollPanel |
23 | 28 from pyjamas.ui.TabPanel import TabPanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from pyjamas.ui.HTMLPanel import HTMLPanel |
83 | 30 from pyjamas.ui.FlexTable import FlexTable |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from pyjamas.ui.Grid import Grid |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
32 from pyjamas.ui.TextArea import TextArea |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from pyjamas.ui.Label import Label |
83 | 34 from pyjamas.ui.Button import Button |
33 | 35 from pyjamas.ui.HTML import HTML |
83 | 36 from pyjamas.ui.Image import Image |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 from pyjamas.ui.DropWidget import DropWidget |
19 | 38 from pyjamas.ui.ClickListener import ClickHandler |
33 | 39 from pyjamas.ui.KeyboardListener import KEY_ENTER |
83 | 40 from pyjamas.ui import HasAlignment |
33 | 41 from pyjamas.Timer import Timer |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 from pyjamas import Window |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 from pyjamas import DOM |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
44 from card_game import CardPanel |
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
45 from menu import Menu |
19 | 46 from jid import JID |
33 | 47 from tools import html_sanitize |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 from datetime import datetime |
19 | 49 from time import time |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
50 import dialog |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
51 from __pyjamas__ import doc |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 class DropCell(DropWidget): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 """Cell in the middle grid which replace itself with the dropped widget on DnD""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 def __init__(self): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 DropWidget.__init__(self) |
83 | 58 self.setStyleName('dropCell') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 def onDragEnter(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 self.addStyleName('dragover') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 def onDragLeave(self, event): |
33 | 65 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ |
66 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth()-1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight()-1: | |
67 #We check that we are inside widget's box, and we don't remove the style in this case because | |
68 #if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we | |
69 #don't want that | |
70 self.removeStyleName('dragover') | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 def onDragOver(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 def _getCellAndRow(self, grid, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 """Return cell and row index where the event is occuring""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 cell = grid.getEventTargetCell(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 row = DOM.getParent(cell) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 return (row.rowIndex, cell.cellIndex) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 def onDrop(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 dt = event.dataTransfer |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 #'text', 'text/plain', and 'Text' are equivalent. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 try: |
62 | 86 item, item_type = dt.getData("text/plain").split('\n') #Workaround for webkit, only text/plain seems to be managed |
87 if item_type and item_type[-1] == '\0': #Workaround for what looks like a pyjamas bug: the \0 should not be there, and | |
88 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report | |
89 #item_type = dt.getData("type") | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 print "message: %s" % item |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 print "type: %s" % item_type |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 except: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 print "no message found" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 item=' ' |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 item_type = None |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 if item_type=="GROUP": |
19 | 98 _new_panel = MicroblogPanel(self.host, item) |
99 _new_panel.setAcceptedGroup(item) | |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
100 self.host.FillMicroblogPanel(_new_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 elif item_type=="CONTACT": |
19 | 102 _contact = JID(item) |
62 | 103 self.host.contact_panel.setContactMessageWaiting(_contact.bare, False) |
19 | 104 _new_panel = ChatPanel(self.host, _contact) |
105 _new_panel.historyPrint() | |
106 elif item_type=="CONTACT_TITLE": | |
107 _new_panel = MicroblogPanel(self.host, accept_all=True) | |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
108 self.host.FillMicroblogPanel(_new_panel) |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
109 else: |
84 | 110 return False |
111 if isinstance(self, LiberviaWidget): | |
112 self.host.unregisterWidget(self) | |
113 if not isinstance(_new_panel, LiberviaWidget): | |
114 print ('WARNING: droping an object which is not a class of LiberviaWidget') | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 grid = self.getParent() |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 row_idx, cell_idx = self._getCellAndRow(grid, event) |
19 | 117 if self.host.selected == self: |
118 self.host.select(None) | |
34 | 119 self.removeFromParent() |
19 | 120 grid.setWidget(row_idx, cell_idx, _new_panel) |
34 | 121 _panels = list(grid) #this suppose that we only use 1 row, need to be changed in the futur |
122 _unempty_panels = filter(lambda wid:not isinstance(wid,EmptyPanel),list(grid)) | |
123 _width = 90/float(len(_unempty_panels) or 1) | |
124 #now we resize all the cell of the column | |
125 for panel in _unempty_panels: | |
126 td_elt = panel.getElement().parentNode | |
127 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 #FIXME: delete object ? Check the right way with pyjamas |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
84 | 130 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler): |
83 | 131 """Libervia's widget which can replace itself with a dropped widget on DnD""" |
132 | |
84 | 133 def __init__(self, host, title='', selectable=False): |
134 """Init the widget | |
135 @param host: SatWebFrontend object | |
136 @param title: title show in the header of the widget | |
137 @param selectable: True is widget can be selected by user""" | |
83 | 138 VerticalPanel.__init__(self) |
139 DropCell.__init__(self) | |
84 | 140 ClickHandler.__init__(self) |
141 self.host = host | |
142 self.__selectable = selectable | |
143 self.__title_id = HTMLPanel.createUniqueId() | |
144 self.__setting_button_id = HTMLPanel.createUniqueId() | |
145 self.__close_button_id = HTMLPanel.createUniqueId() | |
83 | 146 header = AbsolutePanel() |
84 | 147 self.__title = Label(title) |
148 self.__title.setStyleName('widgetHeader_title') | |
149 header.add(self.__title) | |
83 | 150 #header.setCellVerticalAlignment(self.title, HasAlignment.ALIGN_MIDDLE) |
151 #header.setCellWidth(self.title, '100%') | |
152 button_group_wrapper = SimplePanel() | |
153 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') | |
154 button_group = HorizontalPanel() | |
155 button_group.setStyleName('widgetHeader_buttonGroup') | |
156 setting_button = Image("media/icons/misc/settings.png") | |
157 setting_button.setStyleName('widgetHeader_settingButton') | |
158 close_button = Image("media/icons/misc/close.png") | |
159 close_button.setStyleName('widgetHeader_closeButton') | |
160 button_group.add(setting_button) | |
161 button_group.add(close_button) | |
162 button_group_wrapper.setWidget(button_group) | |
163 header.add(button_group_wrapper) | |
164 self.add(header) | |
165 header.addStyleName('widgetHeader') | |
166 self.setSize('100%', '100%') | |
167 self.addStyleName('widget') | |
84 | 168 if self.__selectable: |
169 self.addClickListener(self) | |
170 self.host.registerWidget(self) | |
171 | |
172 def onClick(self, sender): | |
173 self.host.select(self) | |
83 | 174 |
175 def setTitle(self, text): | |
176 """change the title in the header of the widget | |
177 @param text: text of the new title""" | |
84 | 178 self.__title.setText(text) |
179 | |
180 def isSelectable(self): | |
181 return self.__selectable | |
182 | |
183 def setSelectable(self, selectable): | |
184 if not self.__selectable: | |
185 try: | |
186 self.removeClickListener(self) | |
187 except ValueError: | |
188 pass | |
189 if self.selectable and not self in self._clickListeners: | |
190 self.addClickListener(self) | |
191 self.__selectable = selectable | |
83 | 192 |
193 def setWidget(self, widget, scrollable=True): | |
194 """Set the widget that will be in the body of the LiberviaWidget | |
195 @param widget: widget to put in the body | |
196 @param scrollable: if true, the widget will be in a ScrollPanelWrapper""" | |
197 if scrollable: | |
198 _scrollpanelwrapper = ScrollPanelWrapper() | |
199 _scrollpanelwrapper.setStyleName('widgetBody') | |
200 _scrollpanelwrapper.setWidget(widget) | |
201 body_wid = _scrollpanelwrapper | |
202 else: | |
203 body_wid = widget | |
204 self.add(body_wid) | |
205 self.setCellHeight(body_wid, '100%') | |
206 | |
207 | |
34 | 208 class ScrollPanelWrapper(SimplePanel): |
209 """Scroll Panel like component, wich use the full available space | |
210 to work around percent size issue, it use some of the ideas found | |
211 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 | |
212 specially in code given at comment #46, thanks to Stefan Bachert""" | |
213 | |
214 def __init__(self, *args, **kwargs): | |
215 SimplePanel.__init__(self) | |
216 self.spanel = ScrollPanel(*args, **kwargs) | |
217 SimplePanel.setWidget(self, self.spanel) | |
218 DOM.setStyleAttribute(self.getElement(), "position", "relative") | |
219 DOM.setStyleAttribute(self.getElement(), "top", "0px") | |
220 DOM.setStyleAttribute(self.getElement(), "left", "0px") | |
221 DOM.setStyleAttribute(self.getElement(), "width", "100%") | |
222 DOM.setStyleAttribute(self.getElement(), "height", "100%") | |
223 DOM.setStyleAttribute(self.spanel.getElement(), "position", "absolute") | |
224 DOM.setStyleAttribute(self.spanel.getElement(), "width", "100%") | |
225 DOM.setStyleAttribute(self.spanel.getElement(), "height", "100%") | |
226 | |
227 def setWidget(self, widget): | |
228 self.spanel.setWidget(widget) | |
229 | |
230 def setScrollPosition(self, position): | |
231 self.spanel.setScrollPosition(position) | |
232 | |
233 def scrollToBottom(self): | |
234 self.setScrollPosition(self.spanel.getElement().scrollHeight) | |
235 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 class EmptyPanel(DropCell, SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 """Empty dropable panel""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 self.host = host |
83 | 242 self.setSize('100%','100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 DropCell.__init__(self) |
83 | 244 self.setWidget(HTML(' ')) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 |
33 | 246 class UniBoxPanel(SimplePanel): |
247 """Panel containing the UniBox""" | |
248 | |
249 def __init__(self, host): | |
250 SimplePanel.__init__(self) | |
251 self.setStyleName('uniBoxPanel') | |
252 self.unibox = UniBox(host) | |
253 self.unibox.setWidth('100%') | |
254 self.add(self.unibox) | |
255 | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
256 class UniBox(TextArea): #AutoCompleteTextBox): |
33 | 257 """This text box is used as a main typing point, for message, microblog, etc""" |
258 | |
259 def __init__(self, host): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
260 TextArea.__init__(self) |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
261 #AutoCompleteTextBox.__init__(self) |
33 | 262 self._popup = None |
263 self._timer = Timer(notify=self._timeCb) | |
264 self.host = host | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
265 self.setStyleName('uniBox') |
83 | 266 self.addKeyboardListener(self) |
33 | 267 |
268 def addKey(self, key): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
269 return |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
270 #self.getCompletionItems().completions.append(key) |
33 | 271 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
272 def removeKey(self, key): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
273 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
274 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
275 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
276 print "WARNING: trying to remove an unknown key" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
277 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
278 |
33 | 279 def showWarning(self, target_data): |
280 type, target = target_data | |
281 if type == "PUBLIC": | |
282 msg = "This message will be PUBLIC and everybody will be able to see it, even people you don't know" | |
283 style = "targetPublic" | |
284 elif type == "GROUP": | |
285 msg = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" % (target or '') | |
286 style = "targetGroup" | |
287 elif type == "STATUS": | |
288 msg = "This will be your new status message" | |
289 style = "targetStatus" | |
290 elif type == "ONE2ONE": | |
291 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % target | |
292 style = "targetOne2One" | |
293 else: | |
294 print "WARNING: undetermined target for this message" | |
295 return | |
296 contents = HTML(msg) | |
297 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
298 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 299 self._popup.target_data = target_data |
300 self._popup.add(contents) | |
301 self._popup.setStyleName("warningPopup") | |
302 if style: | |
303 self._popup.addStyleName(style) | |
304 | |
305 left = 0 | |
306 top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
307 self._popup.setPopupPosition(left, top) | |
308 self._popup.setPopupPosition(left, top) | |
309 self._popup.show() | |
310 | |
311 def _timeCb(self, timer): | |
312 if self._popup: | |
313 self._popup.hide() | |
314 del self._popup | |
315 self._popup = None | |
316 | |
317 def _getTarget(self, txt): | |
318 """Say who will receive the messsage | |
319 Return a tuple (target_type, target info)""" | |
320 type = None | |
321 target = None | |
322 if txt.startswith('@@: '): | |
323 type = "PUBLIC" | |
324 elif txt.startswith('@'): | |
325 type = "GROUP" | |
326 _end = txt.find(': ') | |
327 if _end == -1: | |
328 type = "STATUS" | |
329 else: | |
330 target = txt[1:_end] #only one target group is managed for the moment | |
331 if not target in self.host.contact_panel.getGroups(): | |
332 target = None | |
333 elif self.host.selected == None: | |
334 type = "STATUS" | |
335 elif isinstance(self.host.selected, ChatPanel): | |
336 type = "ONE2ONE" | |
337 target = str(self.host.selected.target) | |
338 else: | |
62 | 339 print "Unknown selected host:",self.host.selected |
33 | 340 type = "UNKNOWN" |
341 return (type, target) | |
342 | |
343 def onKeyPress(self, sender, keycode, modifiers): | |
344 _txt = self.getText() | |
345 if not self._popup: | |
346 self.showWarning(self._getTarget(_txt)) | |
347 else: | |
348 _target = self._getTarget(_txt) | |
349 if _target != self._popup.target_data: | |
350 self._timeCb(None) #we remove the popup | |
351 self.showWarning(_target) | |
352 | |
353 self._timer.schedule(2000) | |
354 | |
83 | 355 #if keycode == KEY_ENTER and not self.visible: |
356 if keycode == KEY_ENTER: | |
33 | 357 if _txt: |
358 if _txt.startswith('@'): | |
359 self.host.bridge.call('sendMblog', None, self.getText()) | |
360 elif self.host.selected == None: | |
361 self.host.bridge.call('setStatus', None, _txt) | |
362 elif isinstance(self.host.selected, ChatPanel): | |
363 _chat = self.host.selected | |
364 mess_type = "groupchat" if _chat.type=='group' else "chat" | |
365 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type) | |
366 self.setText('') | |
367 self._timeCb(None) #we remove the popup | |
368 | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
369 """def complete(self): |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
370 |
33 | 371 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
372 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
373 return AutoCompleteTextBox.complete(self)""" |
33 | 374 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 class MicroblogEntry(SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
377 def __init__(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
380 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 panel = HTMLPanel("<div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div><div class='mb_entry_body'>%(body)s</div>" % |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
383 {"author": html_sanitize(mblog_entry.author), |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 "timestamp": _datetime, |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
385 "body": html_sanitize(mblog_entry.content)} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 ) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 panel.setStyleName('microblogEntry') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 self.add(panel) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 |
83 | 390 class MicroblogPanel(LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 |
83 | 392 def __init__(self, host, title='', accept_all=False): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 """Panel used to show microblog |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 @param title: title of the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 @param accept_all: if true, show every message, without filtering jids""" |
84 | 396 LiberviaWidget.__init__(self, host, title) |
83 | 397 #ScrollPanelWrapper.__init__(self) |
398 #DropCell.__init__(self) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 self.accept_all = accept_all |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 self.accepted_groups = [] |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
401 self.entries = {} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 self.vpanel = VerticalPanel() |
83 | 403 self.vpanel.setStyleName('microblogPanel') |
34 | 404 self.setWidget(self.vpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
406 def addEntry(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 """Add an entry to the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 @param text: main text of the entry |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
409 @param id: unique id of the entry |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 @param author: who wrote the entry |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 @param date: when the entry was written""" |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
412 if mblog_entry.id in self.entries: |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
413 return |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
414 _entry = MicroblogEntry(mblog_entry) |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
415 self.entries[mblog_entry.id] = _entry |
83 | 416 self.vpanel.insert(_entry,0) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
418 def setAcceptedGroup(self, group): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 """Set the group which can be displayed in this panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 @param group: string of the group, or list of string |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 if isinstance(group, list): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 self.accepted_groups.extend(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 else: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 self.accepted_groups.append(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 def isJidAccepted(self, jid): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 """Tell if a jid is actepted and show in this panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 @return: True if the jid is accepted""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 if self.accept_all: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 for group in self.accepted_groups: |
27
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
434 if self.host.contact_panel.isContactInGroup(group, jid): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 return False |
19 | 437 |
20 | 438 class StatusPanel(HTMLPanel, ClickHandler): |
439 def __init__(self, host, status=''): | |
440 self.host = host | |
441 self.status = status or ' ' | |
19 | 442 HTMLPanel.__init__(self, self.__getContent()) |
20 | 443 self.setStyleName('statusPanel') |
444 ClickHandler.__init__(self) | |
445 self.addClickListener(self) | |
19 | 446 |
447 def __getContent(self): | |
51 | 448 return "<span class='status'>%(status)s</span>" % {'status':html_sanitize(self.status)} |
19 | 449 |
450 def changeStatus(self, new_status): | |
20 | 451 self.status = new_status or ' ' |
19 | 452 self.setHTML(self.__getContent()) |
453 | |
62 | 454 def onClick(self, sender): |
20 | 455 #As status is the default target of uniBar, we don't want to select anything if click on it |
456 self.host.select(None) | |
457 | |
19 | 458 class ChatText(HTMLPanel): |
459 | |
460 def __init__(self, timestamp, nick, mymess, msg): | |
461 _date = datetime.fromtimestamp(float(timestamp or time())) | |
462 _msg_class = ["chat_text_msg"] | |
463 if mymess: | |
464 _msg_class.append("chat_text_mymess") | |
465 HTMLPanel.__init__(self, "<span class='chat_text_timestamp'>%(timestamp)s</span> <span class='chat_text_nick'>%(nick)s</span> <span class='%(msg_class)s'>%(msg)s</span>" % | |
466 {"timestamp": _date.strftime("%H:%M"), | |
51 | 467 "nick": "[%s]" % html_sanitize(nick), |
19 | 468 "msg_class": ' '.join(_msg_class), |
51 | 469 "msg": html_sanitize(msg)} |
19 | 470 ) |
471 self.setStyleName('chatText') | |
33 | 472 |
473 class Occupant(HTML): | |
474 """Occupant of a MUC room""" | |
475 | |
476 def __init__(self, nick): | |
477 self.nick = nick | |
35 | 478 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) |
479 | |
480 def __str__(self): | |
481 return nick | |
33 | 482 |
483 class OccupantsList(AbsolutePanel): | |
484 """Panel user to show occupants of a room""" | |
485 | |
486 def __init__(self): | |
487 AbsolutePanel.__init__(self) | |
35 | 488 self.occupants_list = {} |
33 | 489 self.setStyleName('occupantsList') |
490 | |
491 def addOccupant(self, nick): | |
35 | 492 _occupant = Occupant(nick) |
493 self.occupants_list[nick] = _occupant | |
494 self.add(_occupant) | |
33 | 495 |
35 | 496 def removeOccupant(self, nick): |
497 try: | |
498 self.remove(self.occupants_list[nick]) | |
499 except KeyError: | |
500 print "ERROR: trying to remove an unexisting nick" | |
501 | |
502 def clear(self): | |
503 self.occupants_list.clear() | |
504 AbsolutePanel.clear(self) | |
505 | |
84 | 506 class ChatPanel(LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
507 |
19 | 508 def __init__(self, host, target, type='one2one'): |
509 """Panel used for conversation (one 2 one or group chat) | |
510 @param host: SatWebFrontend instance | |
511 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
512 @param type: one2one for simple conversation, group for MUC""" | |
84 | 513 LiberviaWidget.__init__(self, host, target.bare, selectable = True) |
34 | 514 self.vpanel = VerticalPanel() |
515 self.vpanel.setSize('100%','100%') | |
33 | 516 self.type = type |
517 self.nick = None | |
19 | 518 if not target: |
519 print "ERROR: Empty target !" | |
520 return | |
521 self.target = target | |
84 | 522 self.__body = AbsolutePanel() |
523 self.__body.setStyleName('chatPanel_body') | |
33 | 524 chat_area = HorizontalPanel() |
525 chat_area.setStyleName('chatArea') | |
526 if type == 'group': | |
527 self.occupants_list = OccupantsList() | |
528 chat_area.add(self.occupants_list) | |
84 | 529 self.__body.add(chat_area) |
33 | 530 self.content = AbsolutePanel() |
531 self.content.setStyleName('chatContent') | |
34 | 532 self.content_scroll = ScrollPanelWrapper(self.content) |
533 chat_area.add(self.content_scroll) | |
534 chat_area.setCellWidth(self.content_scroll, '100%') | |
84 | 535 self.vpanel.add(self.__body) |
536 self.addStyleName('chatPanel') | |
34 | 537 self.setWidget(self.vpanel) |
19 | 538 |
84 | 539 """def doDetachChildren(self): |
38
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
540 #We need to force the use of a panel subclass method here, |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
541 #for the same reason as doAttachChildren |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
542 ScrollPanelWrapper.doDetachChildren(self) |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
543 |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
544 def doAttachChildren(self): |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
545 #We need to force the use of a panel subclass method here, else |
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
546 #the event will not propagate to children |
84 | 547 ScrollPanelWrapper.doAttachChildren(self)""" |
38
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
548 |
19 | 549 def setUserNick(self, nick): |
550 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
551 self.nick = nick | |
33 | 552 |
553 def setPresents(self, nicks): | |
554 """Set the users presents in this room | |
555 @param occupants: list of nicks (string)""" | |
35 | 556 self.occupants_list.clear() |
33 | 557 for nick in nicks: |
558 self.occupants_list.addOccupant(nick) | |
559 | |
35 | 560 def userJoined(self, nick, data): |
561 self.occupants_list.addOccupant(nick) | |
562 self.printInfo("=> %s has joined the room" % nick) | |
563 | |
564 def userLeft(self, nick, data): | |
565 self.occupants_list.removeOccupant(nick) | |
566 self.printInfo("<= %s has left the room" % nick) | |
567 | |
19 | 568 def historyPrint(self, size=20): |
569 """Print the initial history""" | |
570 def getHistoryCB(history): | |
571 stamps=history.keys() | |
572 stamps.sort() | |
33 | 573 for stamp in stamps: |
19 | 574 self.printMessage(history[stamp][0], history[stamp][1], stamp) |
62 | 575 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, 20) |
35 | 576 |
577 def printInfo(self, msg, type='normal'): | |
578 """Print general info | |
579 @param msg: message to print | |
580 @type: one of: | |
581 normal: general info like "toto has joined the room" | |
582 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
583 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
584 _wid = Label(msg) |
35 | 585 if type == 'normal': |
586 _wid.setStyleName('chatTextInfo') | |
587 elif type == 'me': | |
588 _wid.setStyleName('chatTextMe') | |
589 else: | |
590 _wid.setStyleName('chatTextInfo') | |
591 self.content.add(_wid) | |
592 | |
593 | |
19 | 594 def printMessage(self, from_jid, msg, timestamp=None): |
595 """Print message in chat window. Must be implemented by child class""" | |
84 | 596 print "print message:",msg |
19 | 597 _jid=JID(from_jid) |
33 | 598 nick = _jid.node if self.type=='one2one' else _jid.resource |
599 mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare #mymess = True if message comes from local user | |
35 | 600 if msg.startswith('/me '): |
19 | 601 self.printInfo('* %s %s' % (nick, msg[4:]),type='me') |
35 | 602 return |
19 | 603 self.content.add(ChatText(timestamp, nick, mymess, msg)) |
34 | 604 self.content_scroll.scrollToBottom() |
36 | 605 |
606 def startGame(self, game_type, referee, players): | |
607 """Configure the chat window to start a game""" | |
608 if game_type=="Tarot": | |
609 self.tarot_panel = CardPanel(self, referee, players, self.nick) | |
610 self.vpanel.insert(self.tarot_panel, 1) | |
611 self.vpanel.setCellHeight(self.tarot_panel, self.tarot_panel.getHeight()) | |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
612 |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
613 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
614 """Return class managing the game type""" |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
615 #TODO: check that the game is launched, and manage errors |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
616 if game_type=="Tarot": |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
617 return self.tarot_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
618 |
83 | 619 class WidgetsPanel(SimplePanel): |
620 | |
621 def __init__(self): | |
622 SimplePanel.__init__(self) | |
623 self.flextable = FlexTable() | |
624 self.flextable.setSize('100%','100%') | |
625 self.add(self.flextable) | |
626 self.setStyleName('widgetsPanel') | |
627 | |
628 def addWidget(self, wid): | |
629 """Add a widget to a new cell""" | |
630 row = max(0, self.flextable.getRowCount()-1) | |
631 try: | |
632 col = self.flextable.getCellCount(0) | |
633 except AttributeError: | |
634 col = 0 | |
635 print "putting widget %s at %d, %d" % (wid, row, col) | |
636 self.flextable.setWidget(row, col, wid) | |
637 | |
34 | 638 class MainDiscussionPanel(HorizontalPanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
639 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
640 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
641 self.host=host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
642 HorizontalPanel.__init__(self) |
27
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
643 self._left = self.host.contact_panel |
83 | 644 self._right = WidgetsPanel() |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
645 self._right.setWidth('100%') |
34 | 646 self._right.setHeight('100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
647 self.add(self._left) |
83 | 648 #self.setCellWidth(self._left, "15%") |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
649 self.add(self._right) |
83 | 650 #self.setCellWidth(self._right, "85%") |
651 self.setCellWidth(self._right, "100%") | |
652 | |
653 def addWidget(self, wid): | |
654 """Add a widget to the WidgetsPanel""" | |
655 print "main addWidget", wid | |
656 self._right.addWidget(wid) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
657 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
658 def changePanel(self, idx, panel): |
83 | 659 pass |
660 #self._right.setWidget(0,idx,panel) | |
661 #self._right.getCellFormatter().setWidth(0, idx, '5%' if isinstance(panel, EmptyPanel) else '90%') | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
662 |
34 | 663 class MainTabPanel(TabPanel): |
23 | 664 |
665 def __init__(self, host): | |
33 | 666 TabPanel.__init__(self) |
23 | 667 self.host=host |
668 self.tabBar.setVisible(False) | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
669 self.setStyleName('mainTabPanel') |
33 | 670 Window.addWindowResizeListener(self) |
671 | |
672 def onWindowResized(self, width, height): | |
673 tab_panel_elt = self.getElement() | |
674 _elts = doc().getElementsByClassName('gwt-TabBar') | |
675 if not _elts.length: | |
676 print ("ERROR: not TabBar found, it should exist !") | |
677 tab_bar_h = 0 | |
678 else: | |
679 tab_bar_h = _elts.item(0).offsetHeight | |
680 ideal_height = Window.getClientHeight() - tab_panel_elt.offsetTop - tab_bar_h - 5 | |
681 self.setWidth("%s%s" % (width-5, "px")); | |
682 self.setHeight("%s%s" % (ideal_height, "px")); | |
23 | 683 |
684 def add(self, widget, tabText=None, asHTML=False): | |
685 TabPanel.add(self, widget, tabText, asHTML) | |
686 if self.getWidgetCount()>1: | |
687 self.tabBar.setVisible(True) | |
33 | 688 self.host.resize() |
23 | 689 |
33 | 690 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
691 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
692 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
693 self.host=host |
33 | 694 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
695 |
23 | 696 menu = Menu(host) |
33 | 697 unibox_panel = UniBoxPanel(host) |
698 self.host.setUniBox(unibox_panel.unibox) | |
27
d89982865c57
browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
699 status = host.status_panel |
34 | 700 self.tab_panel = MainTabPanel(host) |
701 self.discuss_panel = MainDiscussionPanel(self.host) | |
23 | 702 self.tab_panel.add(self.discuss_panel, "Discussions") |
703 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
704 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
705 self.add(menu) |
33 | 706 self.add(unibox_panel) |
19 | 707 self.add(status) |
23 | 708 self.add(self.tab_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
709 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
710 self.setWidth("100%") |
33 | 711 Window.addWindowResizeListener(self) |
712 | |
713 def onWindowResized(self, width, height): | |
714 _elts = doc().getElementsByClassName('gwt-TabBar') | |
715 if not _elts.length: | |
716 tab_bar_h = 0 | |
717 else: | |
718 tab_bar_h = _elts.item(0).offsetHeight | |
719 ideal_height = Window.getClientHeight() - tab_bar_h | |
720 self.setHeight("%s%s" % (ideal_height, "px")); | |
721 |