Mercurial > libervia-web
annotate browser_side/panels.py @ 167:9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 09 Jan 2013 22:02:00 +0100 |
parents | 9763dec220ed |
children | d97b0cba8b04 |
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 |
165 | 6 Copyright (C) 2011, 2012, 2013 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 |
127 | 45 from radiocol import RadioColPanel |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
46 from menu import Menu |
19 | 47 from jid import JID |
33 | 48 from tools import html_sanitize |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 from datetime import datetime |
19 | 50 from time import time |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
51 import dialog |
78
12680e220b35
browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
52 from __pyjamas__ import doc |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 class DropCell(DropWidget): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 """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
|
56 |
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
|
57 def __init__(self, host): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 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
|
59 self.host = host |
83 | 60 self.setStyleName('dropCell') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 def onDragEnter(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 self.addStyleName('dragover') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 def onDragLeave(self, event): |
33 | 67 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ |
68 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth()-1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight()-1: | |
69 #We check that we are inside widget's box, and we don't remove the style in this case because | |
70 #if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we | |
71 #don't want that | |
72 self.removeStyleName('dragover') | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 def onDragOver(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 def _getCellAndRow(self, grid, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 """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
|
79 cell = grid.getEventTargetCell(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 row = DOM.getParent(cell) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 return (row.rowIndex, cell.cellIndex) |
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 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 def onDrop(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 dt = event.dataTransfer |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 #'text', 'text/plain', and 'Text' are equivalent. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 try: |
62 | 88 item, item_type = dt.getData("text/plain").split('\n') #Workaround for webkit, only text/plain seems to be managed |
89 if item_type and item_type[-1] == '\0': #Workaround for what looks like a pyjamas bug: the \0 should not be there, and | |
90 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report | |
91 #item_type = dt.getData("type") | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 print "message: %s" % item |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 print "type: %s" % item_type |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 except: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 print "no message found" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 item=' ' |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 item_type = None |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 if item_type=="GROUP": |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
100 _new_panel = MicroblogPanel(self.host, [item]) |
19 | 101 _new_panel.setAcceptedGroup(item) |
139 | 102 self.host.FillMicroblogPanel(_new_panel) |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
103 self.host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'GROUP', [item], 10) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 elif item_type=="CONTACT": |
19 | 105 _contact = JID(item) |
62 | 106 self.host.contact_panel.setContactMessageWaiting(_contact.bare, False) |
19 | 107 _new_panel = ChatPanel(self.host, _contact) |
108 _new_panel.historyPrint() | |
109 elif item_type=="CONTACT_TITLE": | |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
110 _new_panel = MicroblogPanel(self.host, []) |
139 | 111 self.host.FillMicroblogPanel(_new_panel) |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
112 self.host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'ALL', [], 10) |
39
305e81c7a32c
Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
113 else: |
84 | 114 return False |
115 if isinstance(self, LiberviaWidget): | |
116 self.host.unregisterWidget(self) | |
117 if not isinstance(_new_panel, LiberviaWidget): | |
118 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
|
119 _flextable = self.getParent() |
88
50b480fd0605
browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
120 _widgetspanel = _flextable.getParent().getParent() |
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 row_idx, cell_idx = self._getCellAndRow(_flextable, event) |
19 | 122 if self.host.selected == self: |
123 self.host.select(None) | |
88
50b480fd0605
browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
124 _widgetspanel.changeWidget(row_idx, cell_idx, _new_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
|
125 """_unempty_panels = filter(lambda wid:not isinstance(wid,EmptyWidget),list(_flextable)) |
34 | 126 _width = 90/float(len(_unempty_panels) or 1) |
127 #now we resize all the cell of the column | |
128 for panel in _unempty_panels: | |
129 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
|
130 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)""" |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 #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
|
132 |
84 | 133 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler): |
83 | 134 """Libervia's widget which can replace itself with a dropped widget on DnD""" |
135 | |
84 | 136 def __init__(self, host, title='', selectable=False): |
137 """Init the widget | |
138 @param host: SatWebFrontend object | |
139 @param title: title show in the header of the widget | |
140 @param selectable: True is widget can be selected by user""" | |
83 | 141 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
|
142 DropCell.__init__(self, host) |
84 | 143 ClickHandler.__init__(self) |
144 self.__selectable = selectable | |
145 self.__title_id = HTMLPanel.createUniqueId() | |
146 self.__setting_button_id = HTMLPanel.createUniqueId() | |
147 self.__close_button_id = HTMLPanel.createUniqueId() | |
83 | 148 header = AbsolutePanel() |
84 | 149 self.__title = Label(title) |
150 self.__title.setStyleName('widgetHeader_title') | |
151 header.add(self.__title) | |
83 | 152 button_group_wrapper = SimplePanel() |
153 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') | |
154 button_group = HorizontalPanel() | |
155 button_group.setStyleName('widgetHeader_buttonGroup') | |
156 setting_button = Image("media/icons/misc/settings.png") | |
157 setting_button.setStyleName('widgetHeader_settingButton') | |
89
8d2c7be09eef
browser side: CSS: removed useless z-indexes, and replaced tabs by spaces
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
158 setting_button.addClickListener(self.onSetting) |
83 | 159 close_button = Image("media/icons/misc/close.png") |
160 close_button.setStyleName('widgetHeader_closeButton') | |
89
8d2c7be09eef
browser side: CSS: removed useless z-indexes, and replaced tabs by spaces
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
161 close_button.addClickListener(self.onClose) |
83 | 162 button_group.add(setting_button) |
163 button_group.add(close_button) | |
164 button_group_wrapper.setWidget(button_group) | |
165 header.add(button_group_wrapper) | |
166 self.add(header) | |
167 header.addStyleName('widgetHeader') | |
168 self.setSize('100%', '100%') | |
169 self.addStyleName('widget') | |
84 | 170 if self.__selectable: |
171 self.addClickListener(self) | |
172 self.host.registerWidget(self) | |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
173 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
174 def _getWidgetsPanel(self): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
175 return self.getParent().getParent().getParent() |
84 | 176 |
177 def onClick(self, sender): | |
178 self.host.select(self) | |
83 | 179 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
180 def onClose(self, sender): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
181 print "onClose:", sender |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
182 _widgetspanel = self._getWidgetsPanel() |
88
50b480fd0605
browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
183 _widgetspanel.removeWidget(self) |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
184 |
89
8d2c7be09eef
browser side: CSS: removed useless z-indexes, and replaced tabs by spaces
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
185 def onSetting(self, sender): |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
186 widpanel = self._getWidgetsPanel() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
187 row, col = widpanel.getIndex(self) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
188 body = VerticalPanel() |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
189 |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
190 #colspan & rowspan |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
191 colspan = widpanel.getColSpan(row, col) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
192 rowspan = widpanel.getRowSpan(row, col) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
193 def onColSpanChange(value): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
194 widpanel.setColSpan(row, col, value) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
195 def onRowSpanChange(value): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
196 widpanel.setRowSpan(row, col, value) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
197 colspan_setter = dialog.IntSetter("Columns span", colspan) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
198 colspan_setter.addValueChangeListener(onColSpanChange) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
199 colspan_setter.setWidth('100%') |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
200 rowspan_setter = dialog.IntSetter("Rows span", rowspan) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
201 rowspan_setter.addValueChangeListener(onRowSpanChange) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
202 rowspan_setter.setWidth('100%') |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
203 body.add(colspan_setter) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
204 body.add(rowspan_setter) |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
205 |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
206 #size |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
207 width_str = self.getWidth() |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
208 if width_str.endswith('px'): |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
209 width=int(width_str[:-2]) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
210 else: |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
211 width = 0 |
97
3cbbe5c05aa5
browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
212 height_str = self.getHeight() |
3cbbe5c05aa5
browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
213 if height_str.endswith('px'): |
3cbbe5c05aa5
browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
214 height=int(height_str[:-2]) |
3cbbe5c05aa5
browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
215 else: |
3cbbe5c05aa5
browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
216 height = 0 |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
217 def onWidthChange(value): |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
218 if not value: |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
219 self.setWidth('100%') |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
220 else: |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
221 self.setWidth('%dpx' % value) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
222 def onHeightChange(value): |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
223 if not value: |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
224 self.setHeight('100%') |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
225 else: |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
226 self.setHeight('%dpx' % value) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
227 width_setter = dialog.IntSetter("width (0=auto)", width) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
228 width_setter.addValueChangeListener(onWidthChange) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
229 width_setter.setWidth('100%') |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
230 height_setter = dialog.IntSetter("height (0=auto)", height) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
231 height_setter.addValueChangeListener(onHeightChange) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
232 height_setter.setHeight('100%') |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
233 body.add(width_setter) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
234 body.add(height_setter) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
235 |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
236 #reset |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
237 def onReset(sender): |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
238 colspan_setter.setValue(1) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
239 rowspan_setter.setValue(1) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
240 width_setter.setValue(0) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
241 height_setter.setValue(0) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
242 |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
243 reset_bt = Button("Reset", onReset) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
244 body.add(reset_bt) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
245 body.setCellHorizontalAlignment(reset_bt, HasAlignment.ALIGN_CENTER) |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
246 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
247 _dialog = dialog.GenericDialog("Widget setting", body) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
248 _dialog.show() |
89
8d2c7be09eef
browser side: CSS: removed useless z-indexes, and replaced tabs by spaces
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
249 |
83 | 250 def setTitle(self, text): |
251 """change the title in the header of the widget | |
252 @param text: text of the new title""" | |
84 | 253 self.__title.setText(text) |
254 | |
255 def isSelectable(self): | |
256 return self.__selectable | |
257 | |
258 def setSelectable(self, selectable): | |
259 if not self.__selectable: | |
260 try: | |
261 self.removeClickListener(self) | |
262 except ValueError: | |
263 pass | |
264 if self.selectable and not self in self._clickListeners: | |
265 self.addClickListener(self) | |
266 self.__selectable = selectable | |
83 | 267 |
268 def setWidget(self, widget, scrollable=True): | |
269 """Set the widget that will be in the body of the LiberviaWidget | |
270 @param widget: widget to put in the body | |
271 @param scrollable: if true, the widget will be in a ScrollPanelWrapper""" | |
272 if scrollable: | |
273 _scrollpanelwrapper = ScrollPanelWrapper() | |
274 _scrollpanelwrapper.setStyleName('widgetBody') | |
275 _scrollpanelwrapper.setWidget(widget) | |
276 body_wid = _scrollpanelwrapper | |
277 else: | |
278 body_wid = widget | |
279 self.add(body_wid) | |
280 self.setCellHeight(body_wid, '100%') | |
281 | |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
282 def doDetachChildren(self): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
283 #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
|
284 #for the same reason as doAttachChildren |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
285 VerticalPanel.doDetachChildren(self) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
286 |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
287 def doAttachChildren(self): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
288 #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
|
289 #the event will not propagate to children |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
290 VerticalPanel.doAttachChildren(self) |
83 | 291 |
34 | 292 class ScrollPanelWrapper(SimplePanel): |
293 """Scroll Panel like component, wich use the full available space | |
294 to work around percent size issue, it use some of the ideas found | |
295 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 | |
296 specially in code given at comment #46, thanks to Stefan Bachert""" | |
297 | |
298 def __init__(self, *args, **kwargs): | |
299 SimplePanel.__init__(self) | |
300 self.spanel = ScrollPanel(*args, **kwargs) | |
301 SimplePanel.setWidget(self, self.spanel) | |
302 DOM.setStyleAttribute(self.getElement(), "position", "relative") | |
303 DOM.setStyleAttribute(self.getElement(), "top", "0px") | |
304 DOM.setStyleAttribute(self.getElement(), "left", "0px") | |
305 DOM.setStyleAttribute(self.getElement(), "width", "100%") | |
306 DOM.setStyleAttribute(self.getElement(), "height", "100%") | |
307 DOM.setStyleAttribute(self.spanel.getElement(), "position", "absolute") | |
308 DOM.setStyleAttribute(self.spanel.getElement(), "width", "100%") | |
309 DOM.setStyleAttribute(self.spanel.getElement(), "height", "100%") | |
310 | |
311 def setWidget(self, widget): | |
312 self.spanel.setWidget(widget) | |
313 | |
314 def setScrollPosition(self, position): | |
315 self.spanel.setScrollPosition(position) | |
316 | |
317 def scrollToBottom(self): | |
318 self.setScrollPosition(self.spanel.getElement().scrollHeight) | |
319 | |
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
|
320 class EmptyWidget(DropCell, SimplePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 """Empty dropable panel""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 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
|
325 DropCell.__init__(self, host) |
96
d7a4bbaddfb0
browser side: removed in EmptyPanel
Goffi <goffi@goffi.org>
parents:
92
diff
changeset
|
326 #self.setWidget(HTML('')) |
83 | 327 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
|
328 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 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
|
333 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 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
|
338 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 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
|
343 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 |
33 | 349 class UniBoxPanel(SimplePanel): |
350 """Panel containing the UniBox""" | |
351 | |
352 def __init__(self, host): | |
353 SimplePanel.__init__(self) | |
354 self.setStyleName('uniBoxPanel') | |
355 self.unibox = UniBox(host) | |
356 self.unibox.setWidth('100%') | |
357 self.add(self.unibox) | |
358 | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
359 class UniBox(TextArea): #AutoCompleteTextBox): |
33 | 360 """This text box is used as a main typing point, for message, microblog, etc""" |
361 | |
362 def __init__(self, host): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
363 TextArea.__init__(self) |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
364 #AutoCompleteTextBox.__init__(self) |
33 | 365 self._popup = None |
366 self._timer = Timer(notify=self._timeCb) | |
367 self.host = host | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
368 self.setStyleName('uniBox') |
83 | 369 self.addKeyboardListener(self) |
33 | 370 |
371 def addKey(self, key): | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
372 return |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
373 #self.getCompletionItems().completions.append(key) |
33 | 374 |
55
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
375 def removeKey(self, key): |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
376 try: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
377 self.getCompletionItems().completions.remove(key) |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
378 except KeyError: |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
379 print "WARNING: trying to remove an unknown key" |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
380 |
d5266c41ca24
Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents:
54
diff
changeset
|
381 |
33 | 382 def showWarning(self, target_data): |
383 type, target = target_data | |
384 if type == "PUBLIC": | |
385 msg = "This message will be PUBLIC and everybody will be able to see it, even people you don't know" | |
386 style = "targetPublic" | |
387 elif type == "GROUP": | |
388 msg = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>" % (target or '') | |
389 style = "targetGroup" | |
390 elif type == "STATUS": | |
391 msg = "This will be your new status message" | |
392 style = "targetStatus" | |
393 elif type == "ONE2ONE": | |
394 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % target | |
395 style = "targetOne2One" | |
396 else: | |
397 print "WARNING: undetermined target for this message" | |
398 return | |
399 contents = HTML(msg) | |
400 | |
48
153de5d461a4
added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
401 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False) |
33 | 402 self._popup.target_data = target_data |
403 self._popup.add(contents) | |
404 self._popup.setStyleName("warningPopup") | |
405 if style: | |
406 self._popup.addStyleName(style) | |
407 | |
408 left = 0 | |
409 top = 0 #max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2) | |
410 self._popup.setPopupPosition(left, top) | |
411 self._popup.setPopupPosition(left, top) | |
412 self._popup.show() | |
413 | |
414 def _timeCb(self, timer): | |
415 if self._popup: | |
416 self._popup.hide() | |
417 del self._popup | |
418 self._popup = None | |
419 | |
420 def _getTarget(self, txt): | |
421 """Say who will receive the messsage | |
422 Return a tuple (target_type, target info)""" | |
423 type = None | |
424 target = None | |
425 if txt.startswith('@@: '): | |
426 type = "PUBLIC" | |
427 elif txt.startswith('@'): | |
428 type = "GROUP" | |
429 _end = txt.find(': ') | |
430 if _end == -1: | |
431 type = "STATUS" | |
432 else: | |
433 target = txt[1:_end] #only one target group is managed for the moment | |
434 if not target in self.host.contact_panel.getGroups(): | |
435 target = None | |
436 elif self.host.selected == None: | |
437 type = "STATUS" | |
438 elif isinstance(self.host.selected, ChatPanel): | |
439 type = "ONE2ONE" | |
440 target = str(self.host.selected.target) | |
441 else: | |
62 | 442 print "Unknown selected host:",self.host.selected |
33 | 443 type = "UNKNOWN" |
444 return (type, target) | |
445 | |
446 def onKeyPress(self, sender, keycode, modifiers): | |
447 _txt = self.getText() | |
448 if not self._popup: | |
449 self.showWarning(self._getTarget(_txt)) | |
450 else: | |
451 _target = self._getTarget(_txt) | |
452 if _target != self._popup.target_data: | |
453 self._timeCb(None) #we remove the popup | |
454 self.showWarning(_target) | |
455 | |
456 self._timer.schedule(2000) | |
457 | |
83 | 458 #if keycode == KEY_ENTER and not self.visible: |
459 if keycode == KEY_ENTER: | |
33 | 460 if _txt: |
461 if _txt.startswith('@'): | |
462 self.host.bridge.call('sendMblog', None, self.getText()) | |
463 elif self.host.selected == None: | |
464 self.host.bridge.call('setStatus', None, _txt) | |
465 elif isinstance(self.host.selected, ChatPanel): | |
466 _chat = self.host.selected | |
467 mess_type = "groupchat" if _chat.type=='group' else "chat" | |
468 self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', mess_type) | |
469 self.setText('') | |
470 self._timeCb(None) #we remove the popup | |
471 | |
73
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
472 """def complete(self): |
447dc8ac181b
Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
473 |
33 | 474 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done |
475 #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
|
476 return AutoCompleteTextBox.complete(self)""" |
33 | 477 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
478 class MicroblogItem(): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
479 #XXX: should be moved in a separated module |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
480 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
481 def __init__(self, data): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
482 self.id = data['id'] |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
483 self.content = data['content'] |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
484 self.author = data['author'] |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
485 self.timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
486 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 class MicroblogEntry(SimplePanel): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
488 |
119 | 489 def __init__(self, host, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 SimplePanel.__init__(self) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 |
119 | 492 self.author = mblog_entry.author |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
493 self.timestamp = mblog_entry.timestamp |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
494 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 |
119 | 496 self.panel = HTMLPanel(""" |
120
054b7b3424a3
browser side: microblog's entry header with pseudo and timestamp
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
497 <div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div> |
119 | 498 <div class="mb_entry_avatar" id='id_avatar'></div> |
114
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
499 <div class="mb_entry_dialog"> |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
500 <p class="bubble">%(body)s</p> |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
501 </div> |
119 | 502 """ % {"author": html_sanitize(self.author), |
114
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
503 "timestamp": _datetime, |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
504 "body": html_sanitize(mblog_entry.content) |
c64b00f31461
browser side: microblog entries
Adrien Vigneron <adrienvigneron@mailoo.org>
parents:
109
diff
changeset
|
505 }) |
119 | 506 self.avatar = Image(host.getAvatar(self.author)) |
507 self.panel.add(self.avatar, "id_avatar") | |
508 self.panel.setStyleName('mb_entry') | |
509 self.add(self.panel) | |
510 | |
511 def updateAvatar(self, new_avatar): | |
512 """Change the avatar of the entry | |
513 @param new_avatar: path to the new image""" | |
514 self.avatar.setUrl(new_avatar) | |
515 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 |
83 | 517 class MicroblogPanel(LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
518 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
519 def __init__(self, host, accepted_groups): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 """Panel used to show microblog |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
521 @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
522 """ |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
523 LiberviaWidget.__init__(self, host, ", ".join(accepted_groups)) |
83 | 524 #ScrollPanelWrapper.__init__(self) |
525 #DropCell.__init__(self) | |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
526 self.accepted_groups = accepted_groups |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
527 self.entries = {} |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
528 self.vpanel = VerticalPanel() |
83 | 529 self.vpanel.setStyleName('microblogPanel') |
34 | 530 self.setWidget(self.vpanel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
531 |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
532 def accept_all(self): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
533 return not self.accepted_groups #we accept every microblog only if we are not filtering by groups |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
534 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
535 def getEntries(self): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
536 """Ask all the entries for the currenly accepted groups, |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
537 and fill the panel""" |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
538 |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
539 def massiveInsert(self, mblogs): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
540 """Insert several microblogs at once |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
541 @param mblogs: dictionary of microblogs, as the result of getMassiveLastGroupBlogs |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
542 """ |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
543 print "Massive insertion of microblogs" |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
544 for publisher in mblogs: |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
545 print "adding blogs for [%s]" % publisher |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
546 for mblog in mblogs[publisher]: |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
547 if not mblog.has_key('content'): |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
548 print ("WARNING: No content found in microblog [%s]", mblog) |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
549 continue |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
550 mblog_entry = MicroblogItem(mblog) |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
551 self.addEntry(mblog_entry) |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
552 |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
553 def addEntry(self, mblog_entry): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
554 """Add an entry to the panel |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
555 @param mblog_entry: MicroblogItem instance |
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
556 """ |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
557 if mblog_entry.id in self.entries: |
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
558 return |
119 | 559 _entry = MicroblogEntry(self.host, mblog_entry) |
58
4fa3d57f72f8
browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
560 self.entries[mblog_entry.id] = _entry |
135
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
561 |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
562 # we look for the right index to insert our entry: |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
563 # we insert the entry above the first entry |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
564 # in the past |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
565 idx = 0 |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
566 for child in self.vpanel.children: |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
567 if not isinstance(child, MicroblogEntry): |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
568 break |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
569 if child.timestamp < mblog_entry.timestamp: |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
570 break |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
571 idx+=1 |
ceef355156de
server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
572 self.vpanel.insert(_entry,idx) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
573 |
119 | 574 def updateValue(self, type, jid, value): |
575 """Update a jid value in entries | |
576 @param type: one of 'avatar', 'nick' | |
577 @param jid: jid concerned | |
578 @param value: new value""" | |
579 if type=='avatar': | |
580 for entry in self.entries.values(): | |
581 if entry.author == jid: | |
582 entry.updateAvatar(value) | |
583 | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
584 def setAcceptedGroup(self, group): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
585 """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
|
586 @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
|
587 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
588 if isinstance(group, list): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
589 self.accepted_groups.extend(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
590 else: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
591 self.accepted_groups.append(group) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
592 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
593 def isJidAccepted(self, jid): |
163
b887186e8fc8
browser side: get entity's microblogs for newly added contacts
Goffi <goffi@goffi.org>
parents:
148
diff
changeset
|
594 """Tell if a jid is actepted and shown in this panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
595 @param jid: jid |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
596 @return: True if the jid is accepted""" |
132
30d8e328559b
server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
597 if self.accept_all(): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
598 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
599 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
|
600 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
|
601 return True |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
602 return False |
19 | 603 |
20 | 604 class StatusPanel(HTMLPanel, ClickHandler): |
605 def __init__(self, host, status=''): | |
606 self.host = host | |
607 self.status = status or ' ' | |
19 | 608 HTMLPanel.__init__(self, self.__getContent()) |
20 | 609 self.setStyleName('statusPanel') |
610 ClickHandler.__init__(self) | |
611 self.addClickListener(self) | |
19 | 612 |
613 def __getContent(self): | |
51 | 614 return "<span class='status'>%(status)s</span>" % {'status':html_sanitize(self.status)} |
19 | 615 |
616 def changeStatus(self, new_status): | |
20 | 617 self.status = new_status or ' ' |
19 | 618 self.setHTML(self.__getContent()) |
619 | |
62 | 620 def onClick(self, sender): |
20 | 621 #As status is the default target of uniBar, we don't want to select anything if click on it |
622 self.host.select(None) | |
623 | |
19 | 624 class ChatText(HTMLPanel): |
625 | |
626 def __init__(self, timestamp, nick, mymess, msg): | |
627 _date = datetime.fromtimestamp(float(timestamp or time())) | |
628 _msg_class = ["chat_text_msg"] | |
629 if mymess: | |
630 _msg_class.append("chat_text_mymess") | |
631 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>" % | |
632 {"timestamp": _date.strftime("%H:%M"), | |
51 | 633 "nick": "[%s]" % html_sanitize(nick), |
19 | 634 "msg_class": ' '.join(_msg_class), |
51 | 635 "msg": html_sanitize(msg)} |
19 | 636 ) |
637 self.setStyleName('chatText') | |
33 | 638 |
639 class Occupant(HTML): | |
640 """Occupant of a MUC room""" | |
641 | |
642 def __init__(self, nick): | |
643 self.nick = nick | |
35 | 644 HTML.__init__(self, "<div class='occupant'>%s</div>" % html_sanitize(nick)) |
645 | |
646 def __str__(self): | |
647 return nick | |
33 | 648 |
649 class OccupantsList(AbsolutePanel): | |
650 """Panel user to show occupants of a room""" | |
651 | |
652 def __init__(self): | |
653 AbsolutePanel.__init__(self) | |
35 | 654 self.occupants_list = {} |
33 | 655 self.setStyleName('occupantsList') |
656 | |
657 def addOccupant(self, nick): | |
35 | 658 _occupant = Occupant(nick) |
659 self.occupants_list[nick] = _occupant | |
660 self.add(_occupant) | |
33 | 661 |
35 | 662 def removeOccupant(self, nick): |
663 try: | |
664 self.remove(self.occupants_list[nick]) | |
665 except KeyError: | |
666 print "ERROR: trying to remove an unexisting nick" | |
667 | |
668 def clear(self): | |
669 self.occupants_list.clear() | |
670 AbsolutePanel.clear(self) | |
671 | |
84 | 672 class ChatPanel(LiberviaWidget): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
673 |
19 | 674 def __init__(self, host, target, type='one2one'): |
675 """Panel used for conversation (one 2 one or group chat) | |
676 @param host: SatWebFrontend instance | |
677 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) | |
678 @param type: one2one for simple conversation, group for MUC""" | |
84 | 679 LiberviaWidget.__init__(self, host, target.bare, selectable = True) |
34 | 680 self.vpanel = VerticalPanel() |
681 self.vpanel.setSize('100%','100%') | |
33 | 682 self.type = type |
683 self.nick = None | |
19 | 684 if not target: |
685 print "ERROR: Empty target !" | |
686 return | |
687 self.target = target | |
84 | 688 self.__body = AbsolutePanel() |
689 self.__body.setStyleName('chatPanel_body') | |
33 | 690 chat_area = HorizontalPanel() |
691 chat_area.setStyleName('chatArea') | |
692 if type == 'group': | |
693 self.occupants_list = OccupantsList() | |
694 chat_area.add(self.occupants_list) | |
84 | 695 self.__body.add(chat_area) |
33 | 696 self.content = AbsolutePanel() |
697 self.content.setStyleName('chatContent') | |
34 | 698 self.content_scroll = ScrollPanelWrapper(self.content) |
699 chat_area.add(self.content_scroll) | |
700 chat_area.setCellWidth(self.content_scroll, '100%') | |
84 | 701 self.vpanel.add(self.__body) |
702 self.addStyleName('chatPanel') | |
34 | 703 self.setWidget(self.vpanel) |
19 | 704 |
84 | 705 """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
|
706 #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
|
707 #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
|
708 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
|
709 |
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
|
710 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
|
711 #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
|
712 #the event will not propagate to children |
84 | 713 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
|
714 |
19 | 715 def setUserNick(self, nick): |
716 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
717 self.nick = nick | |
33 | 718 |
719 def setPresents(self, nicks): | |
720 """Set the users presents in this room | |
721 @param occupants: list of nicks (string)""" | |
35 | 722 self.occupants_list.clear() |
33 | 723 for nick in nicks: |
724 self.occupants_list.addOccupant(nick) | |
725 | |
35 | 726 def userJoined(self, nick, data): |
727 self.occupants_list.addOccupant(nick) | |
728 self.printInfo("=> %s has joined the room" % nick) | |
729 | |
730 def userLeft(self, nick, data): | |
731 self.occupants_list.removeOccupant(nick) | |
732 self.printInfo("<= %s has left the room" % nick) | |
733 | |
19 | 734 def historyPrint(self, size=20): |
735 """Print the initial history""" | |
736 def getHistoryCB(history): | |
123 | 737 for line in history: |
137 | 738 timestamp, from_jid, to_jid, message, mess_type = line |
123 | 739 self.printMessage(from_jid, message, timestamp) |
740 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True) | |
35 | 741 |
742 def printInfo(self, msg, type='normal'): | |
743 """Print general info | |
744 @param msg: message to print | |
745 @type: one of: | |
746 normal: general info like "toto has joined the room" | |
747 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | |
748 """ | |
54
f25c4077f6b9
addind contact + subscription management + misc
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
749 _wid = Label(msg) |
35 | 750 if type == 'normal': |
751 _wid.setStyleName('chatTextInfo') | |
752 elif type == 'me': | |
753 _wid.setStyleName('chatTextMe') | |
754 else: | |
755 _wid.setStyleName('chatTextInfo') | |
756 self.content.add(_wid) | |
757 | |
758 | |
19 | 759 def printMessage(self, from_jid, msg, timestamp=None): |
760 """Print message in chat window. Must be implemented by child class""" | |
84 | 761 print "print message:",msg |
19 | 762 _jid=JID(from_jid) |
33 | 763 nick = _jid.node if self.type=='one2one' else _jid.resource |
764 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 | 765 if msg.startswith('/me '): |
19 | 766 self.printInfo('* %s %s' % (nick, msg[4:]),type='me') |
35 | 767 return |
19 | 768 self.content.add(ChatText(timestamp, nick, mymess, msg)) |
34 | 769 self.content_scroll.scrollToBottom() |
36 | 770 |
771 def startGame(self, game_type, referee, players): | |
772 """Configure the chat window to start a game""" | |
773 if game_type=="Tarot": | |
167
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
774 if hasattr(self, "tarot_panel"): |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
775 return |
36 | 776 self.tarot_panel = CardPanel(self, referee, players, self.nick) |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
777 self.vpanel.insert(self.tarot_panel, 0) |
36 | 778 self.vpanel.setCellHeight(self.tarot_panel, self.tarot_panel.getHeight()) |
127 | 779 elif game_type=="RadioCol": |
167
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
780 #XXX: We can have double panel if we join quickly enough to have the group chat start signal |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
781 # on invitation + the one triggered on room join |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
782 if hasattr(self, "radiocol_panel"): |
9441893e8f37
browser side: fixed tarot game, radio collective double panel issue
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
783 return |
127 | 784 self.radiocol_panel = RadioColPanel(self, referee, self.nick) |
785 self.vpanel.insert(self.radiocol_panel, 0) | |
786 self.vpanel.setCellHeight(self.radiocol_panel, self.radiocol_panel.getHeight()) | |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
787 |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
788 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
789 """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
|
790 #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
|
791 if game_type=="Tarot": |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
792 return self.tarot_panel |
128 | 793 elif game_type=="RadioCol": |
794 return self.radiocol_panel | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
795 |
88
50b480fd0605
browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
796 class WidgetsPanel(ScrollPanelWrapper): |
83 | 797 |
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
|
798 def __init__(self, host): |
88
50b480fd0605
browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
799 ScrollPanelWrapper.__init__(self) |
50b480fd0605
browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
800 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
|
801 self.host = host |
83 | 802 self.flextable = FlexTable() |
803 self.flextable.setSize('100%','100%') | |
88
50b480fd0605
browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
804 self.setWidget(self.flextable) |
83 | 805 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
|
806 _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
|
807 self.flextable.setWidget(0, 0, _bottom) #There will be always an Empty widget on the last row, |
101
ad0696615768
browser side: bottomBorderWidget size fix (for webkit)
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
808 #dropping a widget there will add a new row |
ad0696615768
browser side: bottomBorderWidget size fix (for webkit)
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
809 td_elt = _bottom.getElement().parentNode |
ad0696615768
browser side: bottomBorderWidget size fix (for webkit)
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
810 DOM.setStyleAttribute(td_elt, "height", "1px") #needed so the cell adapt to the size of the border (specially in webkit) |
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
|
811 self._max_cols = 1 #give the maximum number of columns i a raw |
83 | 812 |
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
|
813 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
|
814 """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
|
815 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
|
816 last_row = max(0, self.flextable.getRowCount()-1) |
83 | 817 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
|
818 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
|
819 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
|
820 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
|
821 return |
88
50b480fd0605
browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
822 |
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
|
823 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
824 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
|
825 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
826 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
|
827 #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
|
828 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
|
829 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
|
830 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
831 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
|
832 #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
|
833 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
|
834 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
|
835 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
|
836 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
|
837 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
|
838 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
|
839 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
840 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
|
841 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
|
842 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
|
843 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
|
844 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
|
845 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
|
846 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
847 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
|
848 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
|
849 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
|
850 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
|
851 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
|
852 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
|
853 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
854 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
|
855 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
|
856 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
|
857 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
858 _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
|
859 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
|
860 self._max_cols = _max_cols |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
861 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
|
862 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
863 def _sizesAdjust(self): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
864 cellFormatter = self.flextable.getFlexCellFormatter() |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
865 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
|
866 |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
867 for row_idx in xrange(self.flextable.getRowCount()): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
868 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
|
869 _widget = self.flextable.getWidget(row_idx, col_idx) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
870 if not isinstance(_widget, BorderWidget): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
871 td_elt = _widget.getElement().parentNode |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
872 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
|
873 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
874 last_row = max(0, self.flextable.getRowCount()-1) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
875 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
|
876 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
877 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
|
878 """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
|
879 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
|
880 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
|
881 self.changeWidget(last_row, 0, wid) |
83 | 882 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
883 def removeWidget(self, wid): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
884 """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
|
885 _row, _col = self.flextable.getIndex(wid) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
886 self.flextable.remove(wid) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
887 self.flextable.removeCell(_row, _col) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
888 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
|
889 self.flextable.removeRow(_row) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
890 _max_cols = 1 |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
891 for row_idx in xrange(self.flextable.getRowCount()): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
892 _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
|
893 if _max_cols != self._max_cols: |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
894 self._max_cols = _max_cols |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
895 self._sizesAdjust() |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
896 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
897 def getIndex(self, wid): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
898 return self.flextable.getIndex(wid) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
899 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
900 def getColSpan(self, row, col): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
901 cellFormatter = self.flextable.getFlexCellFormatter() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
902 return cellFormatter.getColSpan(row, col) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
903 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
904 def setColSpan(self, row, col, value): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
905 cellFormatter = self.flextable.getFlexCellFormatter() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
906 return cellFormatter.setColSpan(row, col, value) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
907 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
908 def getRowSpan(self, row, col): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
909 cellFormatter = self.flextable.getFlexCellFormatter() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
910 return cellFormatter.getRowSpan(row, col) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
911 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
912 def setRowSpan(self, row, col, value): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
913 cellFormatter = self.flextable.getFlexCellFormatter() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
914 return cellFormatter.setRowSpan(row, col, value) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
915 |
34 | 916 class MainDiscussionPanel(HorizontalPanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
917 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
918 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
919 self.host=host |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
920 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
|
921 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
|
922 self._right = WidgetsPanel(host) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
923 self._right.setWidth('100%') |
34 | 924 self._right.setHeight('100%') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
925 self.add(self._left) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
926 self.add(self._right) |
83 | 927 self.setCellWidth(self._right, "100%") |
928 | |
929 def addWidget(self, wid): | |
930 """Add a widget to the WidgetsPanel""" | |
931 print "main addWidget", wid | |
932 self._right.addWidget(wid) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
933 |
34 | 934 class MainTabPanel(TabPanel): |
23 | 935 |
936 def __init__(self, host): | |
33 | 937 TabPanel.__init__(self) |
23 | 938 self.host=host |
939 self.tabBar.setVisible(False) | |
148
8635bc9db9bf
added parameter management to test XMLUI, but it's currently deactivated for security reasons (need some configuration options) + separated mainTabPanel CSS from LiberviaTabPanel
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
940 self.setStyleName('liberviaTabPanel') |
8635bc9db9bf
added parameter management to test XMLUI, but it's currently deactivated for security reasons (need some configuration options) + separated mainTabPanel CSS from LiberviaTabPanel
Goffi <goffi@goffi.org>
parents:
139
diff
changeset
|
941 self.addStyleName('mainTabPanel') |
33 | 942 Window.addWindowResizeListener(self) |
943 | |
944 def onWindowResized(self, width, height): | |
945 tab_panel_elt = self.getElement() | |
946 _elts = doc().getElementsByClassName('gwt-TabBar') | |
947 if not _elts.length: | |
948 print ("ERROR: not TabBar found, it should exist !") | |
949 tab_bar_h = 0 | |
950 else: | |
951 tab_bar_h = _elts.item(0).offsetHeight | |
952 ideal_height = Window.getClientHeight() - tab_panel_elt.offsetTop - tab_bar_h - 5 | |
953 self.setWidth("%s%s" % (width-5, "px")); | |
954 self.setHeight("%s%s" % (ideal_height, "px")); | |
23 | 955 |
956 def add(self, widget, tabText=None, asHTML=False): | |
957 TabPanel.add(self, widget, tabText, asHTML) | |
958 if self.getWidgetCount()>1: | |
959 self.tabBar.setVisible(True) | |
33 | 960 self.host.resize() |
23 | 961 |
33 | 962 class MainPanel(AbsolutePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
963 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
964 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
965 self.host=host |
33 | 966 AbsolutePanel.__init__(self) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
967 |
23 | 968 menu = Menu(host) |
33 | 969 unibox_panel = UniBoxPanel(host) |
970 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
|
971 status = host.status_panel |
34 | 972 self.tab_panel = MainTabPanel(host) |
973 self.discuss_panel = MainDiscussionPanel(self.host) | |
23 | 974 self.tab_panel.add(self.discuss_panel, "Discussions") |
975 self.tab_panel.selectTab(0) | |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
976 |
109
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
977 header=AbsolutePanel() |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
978 header.add(menu) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
979 header.add(unibox_panel) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
980 header.add(status) |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
981 header.setStyleName('header') |
5c363b638127
browser side: grouped header panel in a global Absolute panel
Goffi <goffi@goffi.org>
parents:
101
diff
changeset
|
982 self.add(header) |
23 | 983 self.add(self.tab_panel) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
984 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
985 self.setWidth("100%") |
33 | 986 Window.addWindowResizeListener(self) |
987 | |
988 def onWindowResized(self, width, height): | |
989 _elts = doc().getElementsByClassName('gwt-TabBar') | |
990 if not _elts.length: | |
991 tab_bar_h = 0 | |
992 else: | |
993 tab_bar_h = _elts.item(0).offsetHeight | |
994 ideal_height = Window.getClientHeight() - tab_bar_h | |
995 self.setHeight("%s%s" % (ideal_height, "px")); | |
996 |