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