annotate browser_side/panels.py @ 191:8213e22c1120

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