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