annotate browser_side/panels.py @ 89:8d2c7be09eef

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