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