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