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