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