Mercurial > libervia-web
annotate browser_side/panels.py @ 86:6c3b3254605f
browser side: widget removing is now managed
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 27 Jun 2011 04:11:58 +0200 |
parents | a8f027738c16 |
children | 50b480fd0605 |
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 |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
6 Copyright (C) 2011 Jérôme Poisson <goffi@goffi.org> |
18
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.AbsolutePanel import AbsolutePanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.VerticalPanel import VerticalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas.ui.ScrollPanel import ScrollPanel |
23 | 28 from pyjamas.ui.TabPanel import TabPanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from pyjamas.ui.HTMLPanel import HTMLPanel |
83 | 30 from pyjamas.ui.FlexTable import FlexTable |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from pyjamas.ui.Grid import Grid |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
32 from pyjamas.ui.TextArea import TextArea |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from pyjamas.ui.Label import Label |
83 | 34 from pyjamas.ui.Button import Button |
33 | 35 from pyjamas.ui.HTML import HTML |
83 | 36 from pyjamas.ui.Image import Image |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 from pyjamas.ui.DropWidget import DropWidget |
19 | 38 from pyjamas.ui.ClickListener import ClickHandler |
33 | 39 from pyjamas.ui.KeyboardListener import KEY_ENTER |
83 | 40 from pyjamas.ui import HasAlignment |
33 | 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 |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
44 from card_game import CardPanel |
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
45 from menu import Menu |
19 | 46 from jid import JID |
33 | 47 from tools import html_sanitize |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 from datetime import datetime |
19 | 49 from time import time |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
50 import dialog |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
51 from __pyjamas__ import doc |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 class DropCell(DropWidget): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 """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
|
55 |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
56 def __init__(self, host): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 DropWidget.__init__(self) |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
58 self.host = host |
83 | 59 self.setStyleName('dropCell') |
18
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 onDragEnter(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 self.addStyleName('dragover') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 DOM.eventPreventDefault(event) |
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 def onDragLeave(self, event): |
33 | 66 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ |
67 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth()-1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight()-1: | |
68 #We check that we are inside widget's box, and we don't remove the style in this case because | |
69 #if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we | |
70 #don't want that | |
71 self.removeStyleName('dragover') | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 def onDragOver(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 def _getCellAndRow(self, grid, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 """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
|
78 cell = grid.getEventTargetCell(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 row = DOM.getParent(cell) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 return (row.rowIndex, cell.cellIndex) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 def onDrop(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 dt = event.dataTransfer |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 #'text', 'text/plain', and 'Text' are equivalent. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 try: |
62 | 87 item, item_type = dt.getData("text/plain").split('\n') #Workaround for webkit, only text/plain seems to be managed |
88 if item_type and item_type[-1] == '\0': #Workaround for what looks like a pyjamas bug: the \0 should not be there, and | |
89 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report | |
90 #item_type = dt.getData("type") | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 print "message: %s" % item |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 print "type: %s" % item_type |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 except: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 print "no message found" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 item=' ' |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 item_type = None |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 if item_type=="GROUP": |
19 | 99 _new_panel = MicroblogPanel(self.host, item) |
100 _new_panel.setAcceptedGroup(item) | |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
101 self.host.FillMicroblogPanel(_new_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 elif item_type=="CONTACT": |
19 | 103 _contact = JID(item) |
62 | 104 self.host.contact_panel.setContactMessageWaiting(_contact.bare, False) |
19 | 105 _new_panel = ChatPanel(self.host, _contact) |
106 _new_panel.historyPrint() | |
107 elif item_type=="CONTACT_TITLE": | |
108 _new_panel = MicroblogPanel(self.host, accept_all=True) | |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
109 self.host.FillMicroblogPanel(_new_panel) |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
110 else: |
84 | 111 return False |
112 if isinstance(self, LiberviaWidget): | |
113 self.host.unregisterWidget(self) | |
114 if not isinstance(_new_panel, LiberviaWidget): | |
115 print ('WARNING: droping an object which is not a class of LiberviaWidget') | |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
116 _flextable = self.getParent() |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
117 _widgetpanel = _flextable.getParent() |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
118 row_idx, cell_idx = self._getCellAndRow(_flextable, event) |
19 | 119 if self.host.selected == self: |
120 self.host.select(None) | |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
121 _widgetpanel.changeWidget(row_idx, cell_idx, _new_panel) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
122 """_unempty_panels = filter(lambda wid:not isinstance(wid,EmptyWidget),list(_flextable)) |
34 | 123 _width = 90/float(len(_unempty_panels) or 1) |
124 #now we resize all the cell of the column | |
125 for panel in _unempty_panels: | |
126 td_elt = panel.getElement().parentNode | |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
127 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)""" |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 #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
|
129 |
84 | 130 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler): |
83 | 131 """Libervia's widget which can replace itself with a dropped widget on DnD""" |
132 | |
84 | 133 def __init__(self, host, title='', selectable=False): |
134 """Init the widget | |
135 @param host: SatWebFrontend object | |
136 @param title: title show in the header of the widget | |
137 @param selectable: True is widget can be selected by user""" | |
83 | 138 VerticalPanel.__init__(self) |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
139 DropCell.__init__(self, host) |
84 | 140 ClickHandler.__init__(self) |
141 self.__selectable = selectable | |
142 self.__title_id = HTMLPanel.createUniqueId() | |
143 self.__setting_button_id = HTMLPanel.createUniqueId() | |
144 self.__close_button_id = HTMLPanel.createUniqueId() | |
83 | 145 header = AbsolutePanel() |
84 | 146 self.__title = Label(title) |
147 self.__title.setStyleName('widgetHeader_title') | |
148 header.add(self.__title) | |
83 | 149 #header.setCellVerticalAlignment(self.title, HasAlignment.ALIGN_MIDDLE) |
150 #header.setCellWidth(self.title, '100%') | |
151 button_group_wrapper = SimplePanel() | |
152 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') | |
153 button_group = HorizontalPanel() | |
154 button_group.setStyleName('widgetHeader_buttonGroup') | |
155 setting_button = Image("media/icons/misc/settings.png") | |
156 setting_button.setStyleName('widgetHeader_settingButton') | |
157 close_button = Image("media/icons/misc/close.png") | |
158 close_button.setStyleName('widgetHeader_closeButton') | |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
159 close_button.addClickListener(getattr(self,"onClose")) |
83 | 160 button_group.add(setting_button) |
161 button_group.add(close_button) | |
162 button_group_wrapper.setWidget(button_group) | |
163 header.add(button_group_wrapper) | |
164 self.add(header) | |
165 header.addStyleName('widgetHeader') | |
166 self.setSize('100%', '100%') | |
167 self.addStyleName('widget') | |
84 | 168 if self.__selectable: |
169 self.addClickListener(self) | |
170 self.host.registerWidget(self) | |
171 | |
172 def onClick(self, sender): | |
173 self.host.select(self) | |
83 | 174 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
175 def onClose(self, sender): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
176 print "onClose:", sender |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
177 _widgetpanel = self.getParent().getParent() |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
178 _widgetpanel.removeWidget(self) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
179 |
83 | 180 def setTitle(self, text): |
181 """change the title in the header of the widget | |
182 @param text: text of the new title""" | |
84 | 183 self.__title.setText(text) |
184 | |
185 def isSelectable(self): | |
186 return self.__selectable | |
187 | |
188 def setSelectable(self, selectable): | |
189 if not self.__selectable: | |
190 try: | |
191 self.removeClickListener(self) | |
192 except ValueError: | |
193 pass | |
194 if self.selectable and not self in self._clickListeners: | |
195 self.addClickListener(self) | |
196 self.__selectable = selectable | |
83 | 197 |
198 def setWidget(self, widget, scrollable=True): | |
199 """Set the widget that will be in the body of the LiberviaWidget | |
200 @param widget: widget to put in the body | |
201 @param scrollable: if true, the widget will be in a ScrollPanelWrapper""" | |
202 if scrollable: | |
203 _scrollpanelwrapper = ScrollPanelWrapper() | |
204 _scrollpanelwrapper.setStyleName('widgetBody') | |
205 _scrollpanelwrapper.setWidget(widget) | |
206 body_wid = _scrollpanelwrapper | |
207 else: | |
208 body_wid = widget | |
209 self.add(body_wid) | |
210 self.setCellHeight(body_wid, '100%') | |
211 | |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
212 def doDetachChildren(self): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
213 #We need to force the use of a panel subclass method here, |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
214 #for the same reason as doAttachChildren |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
215 VerticalPanel.doDetachChildren(self) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
216 |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
217 def doAttachChildren(self): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
218 #We need to force the use of a panel subclass method here, else |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
219 #the event will not propagate to children |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
220 VerticalPanel.doAttachChildren(self) |
83 | 221 |
34 | 222 class ScrollPanelWrapper(SimplePanel): |
223 """Scroll Panel like component, wich use the full available space | |
224 to work around percent size issue, it use some of the ideas found | |
225 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 | |
226 specially in code given at comment #46, thanks to Stefan Bachert""" | |
227 | |
228 def __init__(self, *args, **kwargs): | |
229 SimplePanel.__init__(self) | |
230 self.spanel = ScrollPanel(*args, **kwargs) | |
231 SimplePanel.setWidget(self, self.spanel) | |
232 DOM.setStyleAttribute(self.getElement(), "position", "relative") | |
233 DOM.setStyleAttribute(self.getElement(), "top", "0px") | |
234 DOM.setStyleAttribute(self.getElement(), "left", "0px") | |
235 DOM.setStyleAttribute(self.getElement(), "width", "100%") | |
236 DOM.setStyleAttribute(self.getElement(), "height", "100%") | |
237 DOM.setStyleAttribute(self.spanel.getElement(), "position", "absolute") | |
238 DOM.setStyleAttribute(self.spanel.getElement(), "width", "100%") | |
239 DOM.setStyleAttribute(self.spanel.getElement(), "height", "100%") | |
240 | |
241 def setWidget(self, widget): | |
242 self.spanel.setWidget(widget) | |
243 | |
244 def setScrollPosition(self, position): | |
245 self.spanel.setScrollPosition(position) | |
246 | |
247 def scrollToBottom(self): | |
248 self.setScrollPosition(self.spanel.getElement().scrollHeight) | |
249 | |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
250 class EmptyWidget(DropCell, SimplePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 """Empty dropable panel""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 SimplePanel.__init__(self) |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
255 DropCell.__init__(self, host) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
256 self.setWidget(HTML(' ')) |
83 | 257 self.setSize('100%','100%') |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
258 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
259 class BorderWidget(EmptyWidget): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
260 def __init__(self, host): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
261 EmptyWidget.__init__(self, host) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
262 self.addStyleName('borderPanel') |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
263 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
264 class LeftBorderWidget(BorderWidget): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
265 def __init__(self, host): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
266 BorderWidget.__init__(self, host) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
267 self.addStyleName('leftBorderWidget') |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
268 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
269 class RightBorderWidget(BorderWidget): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
270 def __init__(self, host): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
271 BorderWidget.__init__(self, host) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
272 self.addStyleName('rightBorderWidget') |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
273 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
274 class BottomBorderWidget(BorderWidget): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
275 def __init__(self, host): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
276 BorderWidget.__init__(self, host) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
277 self.addStyleName('bottomBorderWidget') |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
278 |
33 | 279 class UniBoxPanel(SimplePanel): |
280 """Panel containing the UniBox""" | |
281 | |
282 def __init__(self, host): | |
283 SimplePanel.__init__(self) | |
284 self.setStyleName('uniBoxPanel') | |
285 self.unibox = UniBox(host) | |
286 self.unibox.setWidth('100%') | |
287 self.add(self.unibox) | |
288 | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
289 class UniBox(TextArea): #AutoCompleteTextBox): |
33 | 290 """This text box is used as a main typing point, for message, microblog, etc""" |
291 | |
292 def __init__(self, host): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
293 TextArea.__init__(self) |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
294 #AutoCompleteTextBox.__init__(self) |
33 | 295 self._popup = None |
296 self._timer = Timer(notify=self._timeCb) | |
297 self.host = host | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
298 self.setStyleName('uniBox') |
83 | 299 self.addKeyboardListener(self) |
33 | 300 |
301 def addKey(self, key): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
302 return |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
303 #self.getCompletionItems().completions.append(key) |
33 | 304 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
305 def removeKey(self, key): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
306 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
307 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
308 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
309 print "WARNING: trying to remove an unknown key" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
310 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
311 |
33 | 312 def showWarning(self, target_data): |
313 type, target = target_data | |
314 if type == "PUBLIC": | |
315 msg = "This message will be PUBLIC and everybody will be able to see it, even people you don't know" | |
316 style = "targetPublic" | |
317 elif type == "GROUP": | |
318 msg = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" % (target or '') | |
319 style = "targetGroup" | |
320 elif type == "STATUS": | |
321 msg = "This will be your new status message" | |
322 style = "targetStatus" | |
323 elif type == "ONE2ONE": | |
324 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % target | |
325 style = "targetOne2One" | |
326 else: | |
327 print "WARNING: undetermined target for this message" | |
328 return | |
329 contents = HTML(msg) | |
330 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
331 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 332 self._popup.target_data = target_data |
333 self._popup.add(contents) | |
334 self._popup.setStyleName("warningPopup") | |
335 if style: | |
336 self._popup.addStyleName(style) | |
337 | |
338 left = 0 | |
339 top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
340 self._popup.setPopupPosition(left, top) | |
341 self._popup.setPopupPosition(left, top) | |
342 self._popup.show() | |
343 | |
344 def _timeCb(self, timer): | |
345 if self._popup: | |
346 self._popup.hide() | |
347 del self._popup | |
348 self._popup = None | |
349 | |
350 def _getTarget(self, txt): | |
351 """Say who will receive the messsage | |
352 Return a tuple (target_type, target info)""" | |
353 type = None | |
354 target = None | |
355 if txt.startswith('@@: '): | |
356 type = "PUBLIC" | |
357 elif txt.startswith('@'): | |
358 type = "GROUP" | |
359 _end = txt.find(': ') | |
360 if _end == -1: | |
361 type = "STATUS" | |
362 else: | |
363 target = txt[1:_end] #only one target group is managed for the moment | |
364 if not target in self.host.contact_panel.getGroups(): | |
365 target = None | |
366 elif self.host.selected == None: | |
367 type = "STATUS" | |
368 elif isinstance(self.host.selected, ChatPanel): | |
369 type = "ONE2ONE" | |
370 target = str(self.host.selected.target) | |
371 else: | |
62 | 372 print "Unknown selected host:",self.host.selected |
33 | 373 type = "UNKNOWN" |
374 return (type, target) | |
375 | |
376 def onKeyPress(self, sender, keycode, modifiers): | |
377 _txt = self.getText() | |
378 if not self._popup: | |
379 self.showWarning(self._getTarget(_txt)) | |
380 else: | |
381 _target = self._getTarget(_txt) | |
382 if _target != self._popup.target_data: | |
383 self._timeCb(None) #we remove the popup | |
384 self.showWarning(_target) | |
385 | |
386 self._timer.schedule(2000) | |
387 | |
83 | 388 #if keycode == KEY_ENTER and not self.visible: |
389 if keycode == KEY_ENTER: | |
33 | 390 if _txt: |
391 if _txt.startswith('@'): | |
392 self.host.bridge.call('sendMblog', None, self.getText()) | |
393 elif self.host.selected == None: | |
394 self.host.bridge.call('setStatus', None, _txt) | |
395 elif isinstance(self.host.selected, ChatPanel): | |
396 _chat = self.host.selected | |
397 mess_type = "groupchat" if _chat.type=='group' else "chat" | |
398 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type) | |
399 self.setText('') | |
400 self._timeCb(None) #we remove the popup | |
401 | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
402 """def complete(self): |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
403 |
33 | 404 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
405 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
406 return AutoCompleteTextBox.complete(self)""" |
33 | 407 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 class MicroblogEntry(SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
410 def __init__(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
413 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 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>" % |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
416 {"author": html_sanitize(mblog_entry.author), |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 "timestamp": _datetime, |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
418 "body": html_sanitize(mblog_entry.content)} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
419 ) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 panel.setStyleName('microblogEntry') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 self.add(panel) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 |
83 | 423 class MicroblogPanel(LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 |
83 | 425 def __init__(self, host, title='', accept_all=False): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 """Panel used to show microblog |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 @param title: title of the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 @param accept_all: if true, show every message, without filtering jids""" |
84 | 429 LiberviaWidget.__init__(self, host, title) |
83 | 430 #ScrollPanelWrapper.__init__(self) |
431 #DropCell.__init__(self) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 self.accept_all = accept_all |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 self.accepted_groups = [] |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
434 self.entries = {} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 self.vpanel = VerticalPanel() |
83 | 436 self.vpanel.setStyleName('microblogPanel') |
34 | 437 self.setWidget(self.vpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
438 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
439 def addEntry(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
440 """Add an entry to the panel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 @param text: main text of the entry |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
442 @param id: unique id of the entry |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
443 @param author: who wrote the entry |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 @param date: when the entry was written""" |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
445 if mblog_entry.id in self.entries: |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
446 return |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
447 _entry = MicroblogEntry(mblog_entry) |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
448 self.entries[mblog_entry.id] = _entry |
83 | 449 self.vpanel.insert(_entry,0) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 def setAcceptedGroup(self, group): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
452 """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
|
453 @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
|
454 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 if isinstance(group, list): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 self.accepted_groups.extend(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 else: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 self.accepted_groups.append(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 def isJidAccepted(self, jid): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
461 """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
|
462 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 @return: True if the jid is accepted""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 if self.accept_all: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
465 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 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
|
467 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
|
468 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 return False |
19 | 470 |
20 | 471 class StatusPanel(HTMLPanel, ClickHandler): |
472 def __init__(self, host, status=''): | |
473 self.host = host | |
474 self.status = status or ' ' | |
19 | 475 HTMLPanel.__init__(self, self.__getContent()) |
20 | 476 self.setStyleName('statusPanel') |
477 ClickHandler.__init__(self) | |
478 self.addClickListener(self) | |
19 | 479 |
480 def __getContent(self): | |
51 | 481 return "<span class='status'>%(status)s</span>" % {'status':html_sanitize(self.status)} |
19 | 482 |
483 def changeStatus(self, new_status): | |
20 | 484 self.status = new_status or ' ' |
19 | 485 self.setHTML(self.__getContent()) |
486 | |
62 | 487 def onClick(self, sender): |
20 | 488 #As status is the default target of uniBar, we don't want to select anything if click on it |
489 self.host.select(None) | |
490 | |
19 | 491 class ChatText(HTMLPanel): |
492 | |
493 def __init__(self, timestamp, nick, mymess, msg): | |
494 _date = datetime.fromtimestamp(float(timestamp or time())) | |
495 _msg_class = ["chat_text_msg"] | |
496 if mymess: | |
497 _msg_class.append("chat_text_mymess") | |
498 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>" % | |
499 {"timestamp": _date.strftime("%H:%M"), | |
51 | 500 "nick": "[%s]" % html_sanitize(nick), |
19 | 501 "msg_class": ' '.join(_msg_class), |
51 | 502 "msg": html_sanitize(msg)} |
19 | 503 ) |
504 self.setStyleName('chatText') | |
33 | 505 |
506 class Occupant(HTML): | |
507 """Occupant of a MUC room""" | |
508 | |
509 def __init__(self, nick): | |
510 self.nick = nick | |
35 | 511 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) |
512 | |
513 def __str__(self): | |
514 return nick | |
33 | 515 |
516 class OccupantsList(AbsolutePanel): | |
517 """Panel user to show occupants of a room""" | |
518 | |
519 def __init__(self): | |
520 AbsolutePanel.__init__(self) | |
35 | 521 self.occupants_list = {} |
33 | 522 self.setStyleName('occupantsList') |
523 | |
524 def addOccupant(self, nick): | |
35 | 525 _occupant = Occupant(nick) |
526 self.occupants_list[nick] = _occupant | |
527 self.add(_occupant) | |
33 | 528 |
35 | 529 def removeOccupant(self, nick): |
530 try: | |
531 self.remove(self.occupants_list[nick]) | |
532 except KeyError: | |
533 print "ERROR: trying to remove an unexisting nick" | |
534 | |
535 def clear(self): | |
536 self.occupants_list.clear() | |
537 AbsolutePanel.clear(self) | |
538 | |
84 | 539 class ChatPanel(LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
540 |
19 | 541 def __init__(self, host, target, type='one2one'): |
542 """Panel used for conversation (one 2 one or group chat) | |
543 @param host: SatWebFrontend instance | |
544 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
545 @param type: one2one for simple conversation, group for MUC""" | |
84 | 546 LiberviaWidget.__init__(self, host, target.bare, selectable = True) |
34 | 547 self.vpanel = VerticalPanel() |
548 self.vpanel.setSize('100%','100%') | |
33 | 549 self.type = type |
550 self.nick = None | |
19 | 551 if not target: |
552 print "ERROR: Empty target !" | |
553 return | |
554 self.target = target | |
84 | 555 self.__body = AbsolutePanel() |
556 self.__body.setStyleName('chatPanel_body') | |
33 | 557 chat_area = HorizontalPanel() |
558 chat_area.setStyleName('chatArea') | |
559 if type == 'group': | |
560 self.occupants_list = OccupantsList() | |
561 chat_area.add(self.occupants_list) | |
84 | 562 self.__body.add(chat_area) |
33 | 563 self.content = AbsolutePanel() |
564 self.content.setStyleName('chatContent') | |
34 | 565 self.content_scroll = ScrollPanelWrapper(self.content) |
566 chat_area.add(self.content_scroll) | |
567 chat_area.setCellWidth(self.content_scroll, '100%') | |
84 | 568 self.vpanel.add(self.__body) |
569 self.addStyleName('chatPanel') | |
34 | 570 self.setWidget(self.vpanel) |
19 | 571 |
84 | 572 """def doDetachChildren(self): |
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
|
573 #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
|
574 #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
|
575 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
|
576 |
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
|
577 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
|
578 #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
|
579 #the event will not propagate to children |
84 | 580 ScrollPanelWrapper.doAttachChildren(self)""" |
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
|
581 |
19 | 582 def setUserNick(self, nick): |
583 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
584 self.nick = nick | |
33 | 585 |
586 def setPresents(self, nicks): | |
587 """Set the users presents in this room | |
588 @param occupants: list of nicks (string)""" | |
35 | 589 self.occupants_list.clear() |
33 | 590 for nick in nicks: |
591 self.occupants_list.addOccupant(nick) | |
592 | |
35 | 593 def userJoined(self, nick, data): |
594 self.occupants_list.addOccupant(nick) | |
595 self.printInfo("=> %s has joined the room" % nick) | |
596 | |
597 def userLeft(self, nick, data): | |
598 self.occupants_list.removeOccupant(nick) | |
599 self.printInfo("<= %s has left the room" % nick) | |
600 | |
19 | 601 def historyPrint(self, size=20): |
602 """Print the initial history""" | |
603 def getHistoryCB(history): | |
604 stamps=history.keys() | |
605 stamps.sort() | |
33 | 606 for stamp in stamps: |
19 | 607 self.printMessage(history[stamp][0], history[stamp][1], stamp) |
62 | 608 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, 20) |
35 | 609 |
610 def printInfo(self, msg, type='normal'): | |
611 """Print general info | |
612 @param msg: message to print | |
613 @type: one of: | |
614 normal: general info like "toto has joined the room" | |
615 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
616 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
617 _wid = Label(msg) |
35 | 618 if type == 'normal': |
619 _wid.setStyleName('chatTextInfo') | |
620 elif type == 'me': | |
621 _wid.setStyleName('chatTextMe') | |
622 else: | |
623 _wid.setStyleName('chatTextInfo') | |
624 self.content.add(_wid) | |
625 | |
626 | |
19 | 627 def printMessage(self, from_jid, msg, timestamp=None): |
628 """Print message in chat window. Must be implemented by child class""" | |
84 | 629 print "print message:",msg |
19 | 630 _jid=JID(from_jid) |
33 | 631 nick = _jid.node if self.type=='one2one' else _jid.resource |
632 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 | 633 if msg.startswith('/me '): |
19 | 634 self.printInfo('* %s %s' % (nick, msg[4:]),type='me') |
35 | 635 return |
19 | 636 self.content.add(ChatText(timestamp, nick, mymess, msg)) |
34 | 637 self.content_scroll.scrollToBottom() |
36 | 638 |
639 def startGame(self, game_type, referee, players): | |
640 """Configure the chat window to start a game""" | |
641 if game_type=="Tarot": | |
642 self.tarot_panel = CardPanel(self, referee, players, self.nick) | |
643 self.vpanel.insert(self.tarot_panel, 1) | |
644 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
|
645 |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
646 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
647 """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
|
648 #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
|
649 if game_type=="Tarot": |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
650 return self.tarot_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
651 |
83 | 652 class WidgetsPanel(SimplePanel): |
653 | |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
654 def __init__(self, host): |
83 | 655 SimplePanel.__init__(self) |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
656 self.host = host |
83 | 657 self.flextable = FlexTable() |
658 self.flextable.setSize('100%','100%') | |
659 self.add(self.flextable) | |
660 self.setStyleName('widgetsPanel') | |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
661 _bottom = BottomBorderWidget(self.host) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
662 self.flextable.setWidget(0, 0, _bottom) #There will be always an Empty widget on the last row, |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
663 #dropping a widget there will add a new row |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
664 self._max_cols = 1 #give the maximum number of columns i a raw |
83 | 665 |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
666 def changeWidget(self, row, col, wid): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
667 """Change the widget in the given location, add row or columns when necessary""" |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
668 print "changing widget:", wid, row, col |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
669 last_row = max(0, self.flextable.getRowCount()-1) |
83 | 670 try: |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
671 prev_wid = self.flextable.getWidget(row, col) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
672 except: |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
673 print "ERROR: Trying to change an unexisting widget !" |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
674 return |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
675 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
676 cellFormatter = self.flextable.getFlexCellFormatter() |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
677 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
678 if isinstance(prev_wid, BorderWidget): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
679 #We are on a border, we must create a row and/or columns |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
680 print "BORDER WIDGET" |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
681 prev_wid.removeStyleName('dragover') |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
682 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
683 if isinstance(prev_wid, BottomBorderWidget): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
684 #We are on the bottom border, we create a new row |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
685 self.flextable.insertRow(last_row) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
686 self.flextable.setWidget(last_row, 0, LeftBorderWidget(self.host)) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
687 self.flextable.setWidget(last_row, 1, wid) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
688 self.flextable.setWidget(last_row, 2, RightBorderWidget(self.host)) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
689 cellFormatter.setHorizontalAlignment(last_row, 2, HasAlignment.ALIGN_RIGHT) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
690 row = last_row |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
691 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
692 elif isinstance(prev_wid, LeftBorderWidget): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
693 if col!=0: |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
694 print "ERROR: LeftBorderWidget must be on the first column !" |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
695 return |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
696 self.flextable.insertCell(row, col+1) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
697 self.flextable.setWidget(row, 1, wid) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
698 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
699 elif isinstance(prev_wid, RightBorderWidget): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
700 if col!=self.flextable.getCellCount(row)-1: |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
701 print "ERROR: RightBorderWidget must be on the last column !" |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
702 return |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
703 self.flextable.insertCell(row, col) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
704 self.flextable.setWidget(row, col, wid) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
705 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
706 else: |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
707 prev_wid.removeFromParent() |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
708 self.flextable.setWidget(row, col, wid) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
709 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
710 _max_cols = max(self._max_cols, self.flextable.getCellCount(row)) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
711 if _max_cols != self._max_cols: |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
712 self._max_cols = _max_cols |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
713 self._sizesAdjust() |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
714 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
715 def _sizesAdjust(self): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
716 cellFormatter = self.flextable.getFlexCellFormatter() |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
717 width = 100.0/max(1, self._max_cols-2) #we don't count the borders |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
718 |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
719 for row_idx in xrange(self.flextable.getRowCount()): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
720 for col_idx in xrange(self.flextable.getCellCount(row_idx)): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
721 _widget = self.flextable.getWidget(row_idx, col_idx) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
722 if not isinstance(_widget, BorderWidget): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
723 td_elt = _widget.getElement().parentNode |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
724 DOM.setStyleAttribute(td_elt, "width", "%.2f%%" % width) |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
725 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
726 last_row = max(0, self.flextable.getRowCount()-1) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
727 cellFormatter.setColSpan(last_row, 0, self._max_cols) |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
728 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
729 def addWidget(self, wid): |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
730 """Add a widget to a new cell on the next to last row""" |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
731 last_row = max(0, self.flextable.getRowCount()-1) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
732 print "putting widget %s at %d, %d" % (wid, last_row, 0) |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
733 self.changeWidget(last_row, 0, wid) |
83 | 734 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
735 def removeWidget(self, wid): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
736 """Remove a widget and the cell where it is""" |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
737 _row, _col = self.flextable.getIndex(wid) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
738 self.flextable.remove(wid) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
739 self.flextable.removeCell(_row, _col) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
740 if self.flextable.getCellCount(_row) == 2: #we have only the borders left, we remove the row |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
741 self.flextable.removeRow(_row) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
742 _max_cols = 1 |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
743 for row_idx in xrange(self.flextable.getRowCount()): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
744 _max_cols = max(_max_cols, self.flextable.getCellCount(row_idx)) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
745 if _max_cols != self._max_cols: |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
746 self._max_cols = _max_cols |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
747 self._sizesAdjust() |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
748 |
34 | 749 class MainDiscussionPanel(HorizontalPanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
750 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
751 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
752 self.host=host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
753 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
|
754 self._left = self.host.contact_panel |
85
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
755 self._right = WidgetsPanel(host) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
756 self._right.setWidth('100%') |
34 | 757 self._right.setHeight('100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
758 self.add(self._left) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
759 self.add(self._right) |
83 | 760 self.setCellWidth(self._right, "100%") |
761 | |
762 def addWidget(self, wid): | |
763 """Add a widget to the WidgetsPanel""" | |
764 print "main addWidget", wid | |
765 self._right.addWidget(wid) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
766 |
34 | 767 class MainTabPanel(TabPanel): |
23 | 768 |
769 def __init__(self, host): | |
33 | 770 TabPanel.__init__(self) |
23 | 771 self.host=host |
772 self.tabBar.setVisible(False) | |
66
9d8e79ac4c9c
Login/Register box: integration of Adrien Vigneron's design
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
773 self.setStyleName('mainTabPanel') |
33 | 774 Window.addWindowResizeListener(self) |
775 | |
776 def onWindowResized(self, width, height): | |
777 tab_panel_elt = self.getElement() | |
778 _elts = doc().getElementsByClassName('gwt-TabBar') | |
779 if not _elts.length: | |
780 print ("ERROR: not TabBar found, it should exist !") | |
781 tab_bar_h = 0 | |
782 else: | |
783 tab_bar_h = _elts.item(0).offsetHeight | |
784 ideal_height = Window.getClientHeight() - tab_panel_elt.offsetTop - tab_bar_h - 5 | |
785 self.setWidth("%s%s" % (width-5, "px")); | |
786 self.setHeight("%s%s" % (ideal_height, "px")); | |
23 | 787 |
788 def add(self, widget, tabText=None, asHTML=False): | |
789 TabPanel.add(self, widget, tabText, asHTML) | |
790 if self.getWidgetCount()>1: | |
791 self.tabBar.setVisible(True) | |
33 | 792 self.host.resize() |
23 | 793 |
33 | 794 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
795 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
796 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
797 self.host=host |
33 | 798 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
799 |
23 | 800 menu = Menu(host) |
33 | 801 unibox_panel = UniBoxPanel(host) |
802 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
|
803 status = host.status_panel |
34 | 804 self.tab_panel = MainTabPanel(host) |
805 self.discuss_panel = MainDiscussionPanel(self.host) | |
23 | 806 self.tab_panel.add(self.discuss_panel, "Discussions") |
807 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
808 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
809 self.add(menu) |
33 | 810 self.add(unibox_panel) |
19 | 811 self.add(status) |
23 | 812 self.add(self.tab_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
813 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
814 self.setWidth("100%") |
33 | 815 Window.addWindowResizeListener(self) |
816 | |
817 def onWindowResized(self, width, height): | |
818 _elts = doc().getElementsByClassName('gwt-TabBar') | |
819 if not _elts.length: | |
820 tab_bar_h = 0 | |
821 else: | |
822 tab_bar_h = _elts.item(0).offsetHeight | |
823 ideal_height = Window.getClientHeight() - tab_bar_h | |
824 self.setHeight("%s%s" % (ideal_height, "px")); | |
825 |