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