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