annotate browser_side/panels.py @ 39:305e81c7a32c

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