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