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