Mercurial > libervia-web
annotate browser_side/panels.py @ 83:68d360caeecb
New widget system: first draft
- adaptation of Adrien's design
- widgets are now based on a flextable
- widgets now use a base class LiberviaWidget (the name is to avoid confustion with pyjamas' widgets)
- widgets have a title, and setting/close buttons
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 Jun 2011 03:04:17 +0200 |
parents | 12680e220b35 |
children | 8f35e9970e7f |
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: |
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
110 return |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 self.host.mpanels.remove(self) |
19 | 112 self.host.mpanels.append(_new_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 grid = self.getParent() |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 row_idx, cell_idx = self._getCellAndRow(grid, event) |
19 | 115 if self.host.selected == self: |
116 self.host.select(None) | |
34 | 117 self.removeFromParent() |
19 | 118 grid.setWidget(row_idx, cell_idx, _new_panel) |
34 | 119 _panels = list(grid) #this suppose that we only use 1 row, need to be changed in the futur |
120 _unempty_panels = filter(lambda wid:not isinstance(wid,EmptyPanel),list(grid)) | |
121 _width = 90/float(len(_unempty_panels) or 1) | |
122 #now we resize all the cell of the column | |
123 for panel in _unempty_panels: | |
124 td_elt = panel.getElement().parentNode | |
125 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 #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
|
127 |
83 | 128 class LiberviaWidget(DropCell, VerticalPanel): |
129 """Libervia's widget which can replace itself with a dropped widget on DnD""" | |
130 | |
131 def __init__(self, title=''): | |
132 VerticalPanel.__init__(self) | |
133 DropCell.__init__(self) | |
134 self.title_id = HTMLPanel.createUniqueId() | |
135 self.setting_button_id = HTMLPanel.createUniqueId() | |
136 self.close_button_id = HTMLPanel.createUniqueId() | |
137 header = AbsolutePanel() | |
138 self.title = Label(title) | |
139 self.title.setStyleName('widgetHeader_title') | |
140 header.add(self.title) | |
141 #header.setCellVerticalAlignment(self.title, HasAlignment.ALIGN_MIDDLE) | |
142 #header.setCellWidth(self.title, '100%') | |
143 button_group_wrapper = SimplePanel() | |
144 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') | |
145 button_group = HorizontalPanel() | |
146 button_group.setStyleName('widgetHeader_buttonGroup') | |
147 setting_button = Image("media/icons/misc/settings.png") | |
148 setting_button.setStyleName('widgetHeader_settingButton') | |
149 close_button = Image("media/icons/misc/close.png") | |
150 close_button.setStyleName('widgetHeader_closeButton') | |
151 button_group.add(setting_button) | |
152 button_group.add(close_button) | |
153 button_group_wrapper.setWidget(button_group) | |
154 header.add(button_group_wrapper) | |
155 self.add(header) | |
156 header.addStyleName('widgetHeader') | |
157 self.setSize('100%', '100%') | |
158 self.addStyleName('widget') | |
159 | |
160 def setTitle(self, text): | |
161 """change the title in the header of the widget | |
162 @param text: text of the new title""" | |
163 self.title.setText(text) | |
164 | |
165 def setWidget(self, widget, scrollable=True): | |
166 """Set the widget that will be in the body of the LiberviaWidget | |
167 @param widget: widget to put in the body | |
168 @param scrollable: if true, the widget will be in a ScrollPanelWrapper""" | |
169 if scrollable: | |
170 _scrollpanelwrapper = ScrollPanelWrapper() | |
171 _scrollpanelwrapper.setStyleName('widgetBody') | |
172 _scrollpanelwrapper.setWidget(widget) | |
173 body_wid = _scrollpanelwrapper | |
174 else: | |
175 body_wid = widget | |
176 self.add(body_wid) | |
177 self.setCellHeight(body_wid, '100%') | |
178 | |
179 | |
34 | 180 class ScrollPanelWrapper(SimplePanel): |
181 """Scroll Panel like component, wich use the full available space | |
182 to work around percent size issue, it use some of the ideas found | |
183 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 | |
184 specially in code given at comment #46, thanks to Stefan Bachert""" | |
185 | |
186 def __init__(self, *args, **kwargs): | |
187 SimplePanel.__init__(self) | |
188 self.spanel = ScrollPanel(*args, **kwargs) | |
189 SimplePanel.setWidget(self, self.spanel) | |
190 DOM.setStyleAttribute(self.getElement(), "position", "relative") | |
191 DOM.setStyleAttribute(self.getElement(), "top", "0px") | |
192 DOM.setStyleAttribute(self.getElement(), "left", "0px") | |
193 DOM.setStyleAttribute(self.getElement(), "width", "100%") | |
194 DOM.setStyleAttribute(self.getElement(), "height", "100%") | |
195 DOM.setStyleAttribute(self.spanel.getElement(), "position", "absolute") | |
196 DOM.setStyleAttribute(self.spanel.getElement(), "width", "100%") | |
197 DOM.setStyleAttribute(self.spanel.getElement(), "height", "100%") | |
198 | |
199 def setWidget(self, widget): | |
200 self.spanel.setWidget(widget) | |
201 | |
202 def setScrollPosition(self, position): | |
203 self.spanel.setScrollPosition(position) | |
204 | |
205 def scrollToBottom(self): | |
206 self.setScrollPosition(self.spanel.getElement().scrollHeight) | |
207 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 class EmptyPanel(DropCell, SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 """Empty dropable panel""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 self.host = host |
83 | 214 self.setSize('100%','100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 DropCell.__init__(self) |
83 | 216 self.setWidget(HTML(' ')) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 |
33 | 218 class UniBoxPanel(SimplePanel): |
219 """Panel containing the UniBox""" | |
220 | |
221 def __init__(self, host): | |
222 SimplePanel.__init__(self) | |
223 self.setStyleName('uniBoxPanel') | |
224 self.unibox = UniBox(host) | |
225 self.unibox.setWidth('100%') | |
226 self.add(self.unibox) | |
227 | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
228 class UniBox(TextArea): #AutoCompleteTextBox): |
33 | 229 """This text box is used as a main typing point, for message, microblog, etc""" |
230 | |
231 def __init__(self, host): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
232 TextArea.__init__(self) |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
233 #AutoCompleteTextBox.__init__(self) |
33 | 234 self._popup = None |
235 self._timer = Timer(notify=self._timeCb) | |
236 self.host = host | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
237 self.setStyleName('uniBox') |
83 | 238 self.addKeyboardListener(self) |
33 | 239 |
240 def addKey(self, key): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
241 return |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
242 #self.getCompletionItems().completions.append(key) |
33 | 243 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
244 def removeKey(self, key): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
245 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
246 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
247 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
248 print "WARNING: trying to remove an unknown key" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
249 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
250 |
33 | 251 def showWarning(self, target_data): |
252 type, target = target_data | |
253 if type == "PUBLIC": | |
254 msg = "This message will be PUBLIC and everybody will be able to see it, even people you don't know" | |
255 style = "targetPublic" | |
256 elif type == "GROUP": | |
257 msg = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" % (target or '') | |
258 style = "targetGroup" | |
259 elif type == "STATUS": | |
260 msg = "This will be your new status message" | |
261 style = "targetStatus" | |
262 elif type == "ONE2ONE": | |
263 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % target | |
264 style = "targetOne2One" | |
265 else: | |
266 print "WARNING: undetermined target for this message" | |
267 return | |
268 contents = HTML(msg) | |
269 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
270 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 271 self._popup.target_data = target_data |
272 self._popup.add(contents) | |
273 self._popup.setStyleName("warningPopup") | |
274 if style: | |
275 self._popup.addStyleName(style) | |
276 | |
277 left = 0 | |
278 top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
279 self._popup.setPopupPosition(left, top) | |
280 self._popup.setPopupPosition(left, top) | |
281 self._popup.show() | |
282 | |
283 def _timeCb(self, timer): | |
284 if self._popup: | |
285 self._popup.hide() | |
286 del self._popup | |
287 self._popup = None | |
288 | |
289 def _getTarget(self, txt): | |
290 """Say who will receive the messsage | |
291 Return a tuple (target_type, target info)""" | |
292 type = None | |
293 target = None | |
294 if txt.startswith('@@: '): | |
295 type = "PUBLIC" | |
296 elif txt.startswith('@'): | |
297 type = "GROUP" | |
298 _end = txt.find(': ') | |
299 if _end == -1: | |
300 type = "STATUS" | |
301 else: | |
302 target = txt[1:_end] #only one target group is managed for the moment | |
303 if not target in self.host.contact_panel.getGroups(): | |
304 target = None | |
305 elif self.host.selected == None: | |
306 type = "STATUS" | |
307 elif isinstance(self.host.selected, ChatPanel): | |
308 type = "ONE2ONE" | |
309 target = str(self.host.selected.target) | |
310 else: | |
62 | 311 print "Unknown selected host:",self.host.selected |
33 | 312 type = "UNKNOWN" |
313 return (type, target) | |
314 | |
315 def onKeyPress(self, sender, keycode, modifiers): | |
316 _txt = self.getText() | |
317 if not self._popup: | |
318 self.showWarning(self._getTarget(_txt)) | |
319 else: | |
320 _target = self._getTarget(_txt) | |
321 if _target != self._popup.target_data: | |
322 self._timeCb(None) #we remove the popup | |
323 self.showWarning(_target) | |
324 | |
325 self._timer.schedule(2000) | |
326 | |
83 | 327 #if keycode == KEY_ENTER and not self.visible: |
328 if keycode == KEY_ENTER: | |
33 | 329 if _txt: |
330 if _txt.startswith('@'): | |
331 self.host.bridge.call('sendMblog', None, self.getText()) | |
332 elif self.host.selected == None: | |
333 self.host.bridge.call('setStatus', None, _txt) | |
334 elif isinstance(self.host.selected, ChatPanel): | |
335 _chat = self.host.selected | |
336 mess_type = "groupchat" if _chat.type=='group' else "chat" | |
337 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type) | |
338 self.setText('') | |
339 self._timeCb(None) #we remove the popup | |
340 | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
341 """def complete(self): |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
342 |
33 | 343 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
344 #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
|
345 return AutoCompleteTextBox.complete(self)""" |
33 | 346 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 class MicroblogEntry(SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
349 def __init__(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
352 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 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
|
355 {"author": html_sanitize(mblog_entry.author), |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 "timestamp": _datetime, |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
357 "body": html_sanitize(mblog_entry.content)} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 ) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 panel.setStyleName('microblogEntry') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 self.add(panel) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 |
83 | 362 class MicroblogPanel(LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 |
83 | 364 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
|
365 """Panel used to show microblog |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 @param title: title of the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 @param accept_all: if true, show every message, without filtering jids""" |
83 | 368 LiberviaWidget.__init__(self, title) |
369 #ScrollPanelWrapper.__init__(self) | |
370 #DropCell.__init__(self) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 self.host = host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 self.accept_all = accept_all |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 self.accepted_groups = [] |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
374 self.entries = {} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 self.vpanel = VerticalPanel() |
83 | 376 self.vpanel.setStyleName('microblogPanel') |
34 | 377 self.setWidget(self.vpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
379 def addEntry(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 """Add an entry to the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 @param text: main text of the entry |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
382 @param id: unique id of the entry |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 @param author: who wrote the entry |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 @param date: when the entry was written""" |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
385 if mblog_entry.id in self.entries: |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
386 return |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
387 _entry = MicroblogEntry(mblog_entry) |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
388 self.entries[mblog_entry.id] = _entry |
83 | 389 self.vpanel.insert(_entry,0) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 def setAcceptedGroup(self, group): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 """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
|
393 @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
|
394 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 if isinstance(group, list): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 self.accepted_groups.extend(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 else: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 self.accepted_groups.append(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 def isJidAccepted(self, jid): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 """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
|
402 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 @return: True if the jid is accepted""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 if self.accept_all: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 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
|
407 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
|
408 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 return False |
19 | 410 |
20 | 411 class StatusPanel(HTMLPanel, ClickHandler): |
412 def __init__(self, host, status=''): | |
413 self.host = host | |
414 self.status = status or ' ' | |
19 | 415 HTMLPanel.__init__(self, self.__getContent()) |
20 | 416 self.setStyleName('statusPanel') |
417 ClickHandler.__init__(self) | |
418 self.addClickListener(self) | |
19 | 419 |
420 def __getContent(self): | |
51 | 421 return "<span class='status'>%(status)s</span>" % {'status':html_sanitize(self.status)} |
19 | 422 |
423 def changeStatus(self, new_status): | |
20 | 424 self.status = new_status or ' ' |
19 | 425 self.setHTML(self.__getContent()) |
426 | |
62 | 427 def onClick(self, sender): |
20 | 428 #As status is the default target of uniBar, we don't want to select anything if click on it |
429 self.host.select(None) | |
430 | |
19 | 431 class ChatText(HTMLPanel): |
432 | |
433 def __init__(self, timestamp, nick, mymess, msg): | |
434 _date = datetime.fromtimestamp(float(timestamp or time())) | |
435 _msg_class = ["chat_text_msg"] | |
436 if mymess: | |
437 _msg_class.append("chat_text_mymess") | |
438 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>" % | |
439 {"timestamp": _date.strftime("%H:%M"), | |
51 | 440 "nick": "[%s]" % html_sanitize(nick), |
19 | 441 "msg_class": ' '.join(_msg_class), |
51 | 442 "msg": html_sanitize(msg)} |
19 | 443 ) |
444 self.setStyleName('chatText') | |
33 | 445 |
446 class Occupant(HTML): | |
447 """Occupant of a MUC room""" | |
448 | |
449 def __init__(self, nick): | |
450 self.nick = nick | |
35 | 451 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) |
452 | |
453 def __str__(self): | |
454 return nick | |
33 | 455 |
456 class OccupantsList(AbsolutePanel): | |
457 """Panel user to show occupants of a room""" | |
458 | |
459 def __init__(self): | |
460 AbsolutePanel.__init__(self) | |
35 | 461 self.occupants_list = {} |
33 | 462 self.setStyleName('occupantsList') |
463 | |
464 def addOccupant(self, nick): | |
35 | 465 _occupant = Occupant(nick) |
466 self.occupants_list[nick] = _occupant | |
467 self.add(_occupant) | |
33 | 468 |
35 | 469 def removeOccupant(self, nick): |
470 try: | |
471 self.remove(self.occupants_list[nick]) | |
472 except KeyError: | |
473 print "ERROR: trying to remove an unexisting nick" | |
474 | |
475 def clear(self): | |
476 self.occupants_list.clear() | |
477 AbsolutePanel.clear(self) | |
478 | |
479 class ChatPanel(DropCell, ClickHandler, ScrollPanelWrapper): | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 |
19 | 481 def __init__(self, host, target, type='one2one'): |
482 """Panel used for conversation (one 2 one or group chat) | |
483 @param host: SatWebFrontend instance | |
484 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
485 @param type: one2one for simple conversation, group for MUC""" | |
35 | 486 ScrollPanelWrapper.__init__(self) |
34 | 487 DropCell.__init__(self) |
488 ClickHandler.__init__(self) | |
489 self.vpanel = VerticalPanel() | |
490 self.vpanel.setSize('100%','100%') | |
19 | 491 self.host = host |
33 | 492 self.type = type |
493 self.nick = None | |
19 | 494 if not target: |
495 print "ERROR: Empty target !" | |
496 return | |
497 self.target = target | |
498 title="%s" % target.bare | |
499 _class = ['mb_panel_header'] | |
51 | 500 self.header = HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),html_sanitize(title))) |
34 | 501 self.header.setStyleName('chatHeader') |
33 | 502 self.body = AbsolutePanel() |
503 self.body.setStyleName('chatPanel_body') | |
504 chat_area = HorizontalPanel() | |
505 chat_area.setStyleName('chatArea') | |
506 if type == 'group': | |
507 self.occupants_list = OccupantsList() | |
508 chat_area.add(self.occupants_list) | |
509 self.body.add(chat_area) | |
510 self.content = AbsolutePanel() | |
511 self.content.setStyleName('chatContent') | |
34 | 512 self.content_scroll = ScrollPanelWrapper(self.content) |
513 chat_area.add(self.content_scroll) | |
514 chat_area.setCellWidth(self.content_scroll, '100%') | |
515 self.vpanel.add(self.header) | |
516 self.vpanel.setCellHeight(self.header, '1%') | |
517 self.vpanel.add(self.body) | |
518 self.setWidget(self.vpanel) | |
19 | 519 self.setStyleName('chatPanel') |
520 self.addClickListener(self) | |
521 | |
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
|
522 def 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
|
523 #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
|
524 #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
|
525 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
|
526 |
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
|
527 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
|
528 #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
|
529 #the event will not propagate to children |
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
|
530 ScrollPanelWrapper.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
|
531 |
62 | 532 def onClick(self, sender): |
19 | 533 self.host.select(self) |
534 | |
535 def setUserNick(self, nick): | |
536 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
537 self.nick = nick | |
33 | 538 |
539 def setPresents(self, nicks): | |
540 """Set the users presents in this room | |
541 @param occupants: list of nicks (string)""" | |
35 | 542 self.occupants_list.clear() |
33 | 543 for nick in nicks: |
544 self.occupants_list.addOccupant(nick) | |
545 | |
35 | 546 def userJoined(self, nick, data): |
547 self.occupants_list.addOccupant(nick) | |
548 self.printInfo("=> %s has joined the room" % nick) | |
549 | |
550 def userLeft(self, nick, data): | |
551 self.occupants_list.removeOccupant(nick) | |
552 self.printInfo("<= %s has left the room" % nick) | |
553 | |
19 | 554 def historyPrint(self, size=20): |
555 """Print the initial history""" | |
556 def getHistoryCB(history): | |
557 stamps=history.keys() | |
558 stamps.sort() | |
33 | 559 for stamp in stamps: |
19 | 560 self.printMessage(history[stamp][0], history[stamp][1], stamp) |
62 | 561 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, 20) |
35 | 562 |
563 def printInfo(self, msg, type='normal'): | |
564 """Print general info | |
565 @param msg: message to print | |
566 @type: one of: | |
567 normal: general info like "toto has joined the room" | |
568 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
569 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
570 _wid = Label(msg) |
35 | 571 if type == 'normal': |
572 _wid.setStyleName('chatTextInfo') | |
573 elif type == 'me': | |
574 _wid.setStyleName('chatTextMe') | |
575 else: | |
576 _wid.setStyleName('chatTextInfo') | |
577 self.content.add(_wid) | |
578 | |
579 | |
19 | 580 def printMessage(self, from_jid, msg, timestamp=None): |
581 """Print message in chat window. Must be implemented by child class""" | |
582 _jid=JID(from_jid) | |
33 | 583 nick = _jid.node if self.type=='one2one' else _jid.resource |
584 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 | 585 if msg.startswith('/me '): |
19 | 586 self.printInfo('* %s %s' % (nick, msg[4:]),type='me') |
35 | 587 return |
19 | 588 self.content.add(ChatText(timestamp, nick, mymess, msg)) |
34 | 589 self.content_scroll.scrollToBottom() |
36 | 590 |
591 def startGame(self, game_type, referee, players): | |
592 """Configure the chat window to start a game""" | |
593 if game_type=="Tarot": | |
594 self.tarot_panel = CardPanel(self, referee, players, self.nick) | |
595 self.vpanel.insert(self.tarot_panel, 1) | |
596 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
|
597 |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
598 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
599 """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
|
600 #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
|
601 if game_type=="Tarot": |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
602 return self.tarot_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
603 |
83 | 604 class WidgetsPanel(SimplePanel): |
605 | |
606 def __init__(self): | |
607 SimplePanel.__init__(self) | |
608 self.flextable = FlexTable() | |
609 self.flextable.setSize('100%','100%') | |
610 self.add(self.flextable) | |
611 self.setStyleName('widgetsPanel') | |
612 | |
613 def addWidget(self, wid): | |
614 """Add a widget to a new cell""" | |
615 row = max(0, self.flextable.getRowCount()-1) | |
616 try: | |
617 col = self.flextable.getCellCount(0) | |
618 except AttributeError: | |
619 col = 0 | |
620 print "putting widget %s at %d, %d" % (wid, row, col) | |
621 self.flextable.setWidget(row, col, wid) | |
622 | |
34 | 623 class MainDiscussionPanel(HorizontalPanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
624 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
625 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
626 self.host=host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 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
|
628 self._left = self.host.contact_panel |
83 | 629 self._right = WidgetsPanel() |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
630 self._right.setWidth('100%') |
34 | 631 self._right.setHeight('100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
632 self.add(self._left) |
83 | 633 #self.setCellWidth(self._left, "15%") |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
634 self.add(self._right) |
83 | 635 #self.setCellWidth(self._right, "85%") |
636 self.setCellWidth(self._right, "100%") | |
637 | |
638 def addWidget(self, wid): | |
639 """Add a widget to the WidgetsPanel""" | |
640 print "main addWidget", wid | |
641 self._right.addWidget(wid) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
642 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
643 def changePanel(self, idx, panel): |
83 | 644 pass |
645 #self._right.setWidget(0,idx,panel) | |
646 #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
|
647 |
34 | 648 class MainTabPanel(TabPanel): |
23 | 649 |
650 def __init__(self, host): | |
33 | 651 TabPanel.__init__(self) |
23 | 652 self.host=host |
653 self.tabBar.setVisible(False) | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
654 self.setStyleName('mainTabPanel') |
33 | 655 Window.addWindowResizeListener(self) |
656 | |
657 def onWindowResized(self, width, height): | |
658 tab_panel_elt = self.getElement() | |
659 _elts = doc().getElementsByClassName('gwt-TabBar') | |
660 if not _elts.length: | |
661 print ("ERROR: not TabBar found, it should exist !") | |
662 tab_bar_h = 0 | |
663 else: | |
664 tab_bar_h = _elts.item(0).offsetHeight | |
665 ideal_height = Window.getClientHeight() - tab_panel_elt.offsetTop - tab_bar_h - 5 | |
666 self.setWidth("%s%s" % (width-5, "px")); | |
667 self.setHeight("%s%s" % (ideal_height, "px")); | |
23 | 668 |
669 def add(self, widget, tabText=None, asHTML=False): | |
670 TabPanel.add(self, widget, tabText, asHTML) | |
671 if self.getWidgetCount()>1: | |
672 self.tabBar.setVisible(True) | |
33 | 673 self.host.resize() |
23 | 674 |
33 | 675 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
676 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
677 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
678 self.host=host |
33 | 679 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
680 |
23 | 681 menu = Menu(host) |
33 | 682 unibox_panel = UniBoxPanel(host) |
683 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
|
684 status = host.status_panel |
34 | 685 self.tab_panel = MainTabPanel(host) |
686 self.discuss_panel = MainDiscussionPanel(self.host) | |
23 | 687 self.tab_panel.add(self.discuss_panel, "Discussions") |
688 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
689 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
690 self.add(menu) |
33 | 691 self.add(unibox_panel) |
19 | 692 self.add(status) |
23 | 693 self.add(self.tab_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
694 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
695 self.setWidth("100%") |
33 | 696 Window.addWindowResizeListener(self) |
697 | |
698 def onWindowResized(self, width, height): | |
699 _elts = doc().getElementsByClassName('gwt-TabBar') | |
700 if not _elts.length: | |
701 tab_bar_h = 0 | |
702 else: | |
703 tab_bar_h = _elts.item(0).offsetHeight | |
704 ideal_height = Window.getClientHeight() - tab_bar_h | |
705 self.setHeight("%s%s" % (ideal_height, "px")); | |
706 |