annotate browser_side/base_widget.py @ 196:c2639c9f86ea

Browser Side: Widgets can now be moved, header (title bar) is draggable: - DragLabel moved to tools - new LiberviaDragWidget which manage currently dragged widget - getLiberviaWidgetsCount give number of widget of WidgetsPanel - LiberviaWidget's header has now its own class - new "WIDGET" drag type /!\ not fully finished, can crash if moved on the bad border (like last row border if the widget is the only one on this row)
author Goffi <goffi@goffi.org>
date Tue, 05 Mar 2013 01:20:59 +0100
parents dd27072d8ae0
children 0fc32122a877
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
3
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
165
9763dec220ed dates update
Goffi <goffi@goffi.org>
parents: 163
diff changeset
6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org>
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
7
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
12
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
17
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
21
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import pyjd # this is dummy in pyjs
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.SimplePanel import SimplePanel
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
24 from pyjamas.ui.AbsolutePanel import AbsolutePanel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.VerticalPanel import VerticalPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.ScrollPanel import ScrollPanel
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
28 from pyjamas.ui.FlexTable import FlexTable
23
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
29 from pyjamas.ui.TabPanel import TabPanel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas.ui.HTMLPanel import HTMLPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from pyjamas.ui.Label import Label
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
32 from pyjamas.ui.Button import Button
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
33 from pyjamas.ui.Image import Image
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from pyjamas.ui.DropWidget import DropWidget
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
35 from pyjamas.ui.ClickListener import ClickHandler
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
36 from pyjamas.ui import HasAlignment
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from pyjamas import DOM
48
153de5d461a4 added Social Contract \o. (in French only so far)
Goffi <goffi@goffi.org>
parents: 43
diff changeset
38 import dialog
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
39 from tools import LiberviaDragWidget
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
40 from pyjamas import Window
78
12680e220b35 browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents: 75
diff changeset
41 from __pyjamas__ import doc
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
42
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
43 class DropCell(DropWidget):
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
44 """Cell in the middle grid which replace itself with the dropped widget on DnD"""
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
45 drop_keys = {}
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
46
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
47 def __init__(self, host):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
48 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
49 self.host = host
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
50 self.setStyleName('dropCell')
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
51
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
52 @classmethod
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
53 def addDropKey(cls, key, callback):
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
54 DropCell.drop_keys[key] = callback
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
55
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
56 def onDragEnter(self, event):
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
57 if self == LiberviaDragWidget.current:
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
58 return
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.addStyleName('dragover')
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
60 DOM.eventPreventDefault(event)
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
61
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def onDragLeave(self, event):
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
63 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
64 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
65 #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
66 #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
67 #don't want that
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
68 self.removeStyleName('dragover')
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
69
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def onDragOver(self, event):
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
71 DOM.eventPreventDefault(event)
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 _getCellAndRow(self, grid, event):
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
74 """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
75 cell = grid.getEventTargetCell(event)
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
76 row = DOM.getParent(cell)
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
77 return (row.rowIndex, cell.cellIndex)
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
78
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
79
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
80 def onDrop(self, event):
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
81 dt = event.dataTransfer
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
82 #'text', 'text/plain', and 'Text' are equivalent.
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
83 try:
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
84 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
85 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
86 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
87 #item_type = dt.getData("type")
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
88 print "message: %s" % item
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
89 print "type: %s" % item_type
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
90 except:
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
91 print "no message found"
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
92 item='&nbsp;'
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
93 item_type = None
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
94 DOM.eventPreventDefault(event)
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
95 if item_type == "WIDGET":
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
96 if not LiberviaDragWidget.current:
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
97 print "ERROR: No widget registered in LiberviaDragWidget !"
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
98 return
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
99 _new_panel = LiberviaDragWidget.current
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
100 if self == _new_panel: # We can't drop on ourself
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
101 return
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
102 # we need to remove the widget from the panel as it will be inserted elsewhere
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
103 widgets_panel = _new_panel.getWidgetsPanel()
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
104 if widgets_panel.getLiberviaWidgetsCount() == 1:
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
105 # the dropped widget is the only one in the panel,
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
106 # we don't do anything
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
107 self.removeStyleName('dragover')
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
108 return
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
109 widgets_panel.removeWidget(_new_panel)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
110 elif item_type in self.drop_keys:
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
111 _new_panel = self.drop_keys[item_type](self.host,item)
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
112 else:
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
113 print "WARNING: unmanaged item type"
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
114 return
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
115 if isinstance(self, LiberviaWidget):
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
116 self.host.unregisterWidget(self)
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
117 self.onQuit()
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
118 if not isinstance(_new_panel, LiberviaWidget):
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
119 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
120 _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
121 _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
122 row_idx, cell_idx = self._getCellAndRow(_flextable, event)
192
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
123 if self.host.getSelected == self:
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
124 self.host.setSelected(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
125 _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
126 """_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
127 _width = 90/float(len(_unempty_panels) or 1)
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
128 #now we resize all the cell of the column
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
129 for panel in _unempty_panels:
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
130 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
131 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)"""
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
132 #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
133
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
134 class WidgetHeader(AbsolutePanel, LiberviaDragWidget):
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
135
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
136 def __init__(self, parent, title):
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
137 AbsolutePanel.__init__(self)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
138 self.add(title)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
139 button_group_wrapper = SimplePanel()
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
140 button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper')
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
141 button_group = HorizontalPanel()
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
142 button_group.setStyleName('widgetHeader_buttonGroup')
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
143 setting_button = Image("media/icons/misc/settings.png")
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
144 setting_button.setStyleName('widgetHeader_settingButton')
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
145 setting_button.addClickListener(parent.onSetting)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
146 close_button = Image("media/icons/misc/close.png")
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
147 close_button.setStyleName('widgetHeader_closeButton')
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
148 close_button.addClickListener(parent.onClose)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
149 button_group.add(setting_button)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
150 button_group.add(close_button)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
151 button_group_wrapper.setWidget(button_group)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
152 self.add(button_group_wrapper)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
153 self.addStyleName('widgetHeader')
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
154 LiberviaDragWidget.__init__(self, "", "WIDGET", parent)
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
155
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
156 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler):
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
157 """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
158
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
159 def __init__(self, host, title='', selectable=False):
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
160 """Init the widget
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
161 @param host: SatWebFrontend object
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
162 @param title: title show in the header of the widget
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
163 @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
164 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
165 DropCell.__init__(self, host)
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
166 ClickHandler.__init__(self)
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
167 self.__selectable = selectable
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
168 self.__title_id = HTMLPanel.createUniqueId()
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
169 self.__setting_button_id = HTMLPanel.createUniqueId()
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
170 self.__close_button_id = HTMLPanel.createUniqueId()
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
171 self.__title = Label(title)
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
172 self.__title.setStyleName('widgetHeader_title')
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
173 header = WidgetHeader(self, self.__title)
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
174 self.add(header)
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
175 self.setSize('100%', '100%')
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
176 self.addStyleName('widget')
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
177 if self.__selectable:
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
178 self.addClickListener(self)
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
179 self.host.registerWidget(self)
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
180
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
181 def getWidgetsPanel(self):
177
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
182 current = self
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
183 while current is not None and current.__class__ != WidgetsPanel:
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
184 current = current.getParent()
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
185 if current is None:
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
186 print "Error: can't find WidgetsPanel"
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
187 return current
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
188
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
189 def onClick(self, sender):
192
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
190 self.host.setSelected(self)
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
191
86
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
192 def onClose(self, sender):
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
193 """ Called when the close button is pushed """
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
194 _widgetspanel = self.getWidgetsPanel()
88
50b480fd0605 browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents: 86
diff changeset
195 _widgetspanel.removeWidget(self)
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
196 self.onQuit()
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
197
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
198 def onQuit(self):
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
199 """ Called when the widget is actually ending """
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
200 pass
86
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
201
89
8d2c7be09eef browser side: CSS: removed useless z-indexes, and replaced tabs by spaces
Goffi <goffi@goffi.org>
parents: 88
diff changeset
202 def onSetting(self, sender):
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
203 widpanel = self.getWidgetsPanel()
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
204 row, col = widpanel.getIndex(self)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
205 body = VerticalPanel()
92
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
206
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
207 #colspan & rowspan
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
208 colspan = widpanel.getColSpan(row, col)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
209 rowspan = widpanel.getRowSpan(row, col)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
210 def onColSpanChange(value):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
211 widpanel.setColSpan(row, col, value)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
212 def onRowSpanChange(value):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
213 widpanel.setRowSpan(row, col, value)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
214 colspan_setter = dialog.IntSetter("Columns span", colspan)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
215 colspan_setter.addValueChangeListener(onColSpanChange)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
216 colspan_setter.setWidth('100%')
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
217 rowspan_setter = dialog.IntSetter("Rows span", rowspan)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
218 rowspan_setter.addValueChangeListener(onRowSpanChange)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
219 rowspan_setter.setWidth('100%')
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
220 body.add(colspan_setter)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
221 body.add(rowspan_setter)
92
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
222
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
223 #size
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
224 width_str = self.getWidth()
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
225 if width_str.endswith('px'):
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
226 width=int(width_str[:-2])
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
227 else:
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
228 width = 0
97
3cbbe5c05aa5 browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents: 96
diff changeset
229 height_str = self.getHeight()
3cbbe5c05aa5 browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents: 96
diff changeset
230 if height_str.endswith('px'):
3cbbe5c05aa5 browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents: 96
diff changeset
231 height=int(height_str[:-2])
3cbbe5c05aa5 browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents: 96
diff changeset
232 else:
3cbbe5c05aa5 browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents: 96
diff changeset
233 height = 0
92
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
234 def onWidthChange(value):
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
235 if not value:
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
236 self.setWidth('100%')
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
237 else:
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
238 self.setWidth('%dpx' % value)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
239 def onHeightChange(value):
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
240 if not value:
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
241 self.setHeight('100%')
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
242 else:
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
243 self.setHeight('%dpx' % value)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
244 width_setter = dialog.IntSetter("width (0=auto)", width)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
245 width_setter.addValueChangeListener(onWidthChange)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
246 width_setter.setWidth('100%')
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
247 height_setter = dialog.IntSetter("height (0=auto)", height)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
248 height_setter.addValueChangeListener(onHeightChange)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
249 height_setter.setHeight('100%')
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
250 body.add(width_setter)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
251 body.add(height_setter)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
252
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
253 #reset
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
254 def onReset(sender):
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
255 colspan_setter.setValue(1)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
256 rowspan_setter.setValue(1)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
257 width_setter.setValue(0)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
258 height_setter.setValue(0)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
259
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
260 reset_bt = Button("Reset", onReset)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
261 body.add(reset_bt)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
262 body.setCellHorizontalAlignment(reset_bt, HasAlignment.ALIGN_CENTER)
dd54bc13ac81 browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents: 90
diff changeset
263
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
264 _dialog = dialog.GenericDialog("Widget setting", body)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
265 _dialog.show()
89
8d2c7be09eef browser side: CSS: removed useless z-indexes, and replaced tabs by spaces
Goffi <goffi@goffi.org>
parents: 88
diff changeset
266
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
267 def setTitle(self, text):
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
268 """change the title in the header of the widget
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
269 @param text: text of the new title"""
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
270 self.__title.setText(text)
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
271
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
272 def isSelectable(self):
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
273 return self.__selectable
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
274
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
275 def setSelectable(self, selectable):
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
276 if not self.__selectable:
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
277 try:
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
278 self.removeClickListener(self)
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
279 except ValueError:
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
280 pass
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
281 if self.selectable and not self in self._clickListeners:
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
282 self.addClickListener(self)
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
283 self.__selectable = selectable
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
284
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
285 def setWidget(self, widget, scrollable=True):
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
286 """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
287 @param widget: widget to put in the body
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
288 @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
289 if scrollable:
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
290 _scrollpanelwrapper = ScrollPanelWrapper()
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
291 _scrollpanelwrapper.setStyleName('widgetBody')
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
292 _scrollpanelwrapper.setWidget(widget)
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
293 body_wid = _scrollpanelwrapper
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
294 else:
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
295 body_wid = widget
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
296 self.add(body_wid)
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
297 self.setCellHeight(body_wid, '100%')
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
298
86
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
299 def doDetachChildren(self):
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
300 #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
301 #for the same reason as doAttachChildren
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
302 VerticalPanel.doDetachChildren(self)
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
303
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
304 def doAttachChildren(self):
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
305 #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
306 #the event will not propagate to children
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
307 VerticalPanel.doAttachChildren(self)
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
308
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
309 class ScrollPanelWrapper(SimplePanel):
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
310 """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
311 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
312 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
313 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
314
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
315 def __init__(self, *args, **kwargs):
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
316 SimplePanel.__init__(self)
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
317 self.spanel = ScrollPanel(*args, **kwargs)
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
318 SimplePanel.setWidget(self, self.spanel)
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
319 DOM.setStyleAttribute(self.getElement(), "position", "relative")
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
320 DOM.setStyleAttribute(self.getElement(), "top", "0px")
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
321 DOM.setStyleAttribute(self.getElement(), "left", "0px")
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
322 DOM.setStyleAttribute(self.getElement(), "width", "100%")
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
323 DOM.setStyleAttribute(self.getElement(), "height", "100%")
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
324 DOM.setStyleAttribute(self.spanel.getElement(), "position", "absolute")
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
325 DOM.setStyleAttribute(self.spanel.getElement(), "width", "100%")
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
326 DOM.setStyleAttribute(self.spanel.getElement(), "height", "100%")
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
327
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
328 def setWidget(self, widget):
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
329 self.spanel.setWidget(widget)
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
330
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
331 def setScrollPosition(self, position):
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
332 self.spanel.setScrollPosition(position)
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
333
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
334 def scrollToBottom(self):
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
335 self.setScrollPosition(self.spanel.getElement().scrollHeight)
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
336
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
337 class EmptyWidget(DropCell, SimplePanel):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
338 """Empty dropable panel"""
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
339
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
340 def __init__(self, host):
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
341 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
342 DropCell.__init__(self, host)
96
d7a4bbaddfb0 browser side: removed &nbsp; in EmptyPanel
Goffi <goffi@goffi.org>
parents: 92
diff changeset
343 #self.setWidget(HTML(''))
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
344 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
345
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
346 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
347 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
348 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
349 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
350
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
351 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
352 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
353 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
354 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
355
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
356 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
357 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
358 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
359 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
360
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
361 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
362 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
363 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
364 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
365
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
366 class WidgetsPanel(ScrollPanelWrapper):
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
367
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
368 def __init__(self, host, locked = False):
88
50b480fd0605 browser side: widgetsPanel is now scrollable when there are too many widgets, and widgets have a minimum size
Goffi <goffi@goffi.org>
parents: 86
diff changeset
369 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
370 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
371 self.host = host
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
372 self.locked = locked #if True: tab will not be removed when there are no more widgets inside
192
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
373 self.selected = None
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
374 self.flextable = FlexTable()
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
375 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
376 self.setWidget(self.flextable)
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
377 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
378 _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
379 self.flextable.setWidget(0, 0, _bottom) #There will be always an Empty widget on the last row,
101
ad0696615768 browser side: bottomBorderWidget size fix (for webkit)
Goffi <goffi@goffi.org>
parents: 97
diff changeset
380 #dropping a widget there will add a new row
ad0696615768 browser side: bottomBorderWidget size fix (for webkit)
Goffi <goffi@goffi.org>
parents: 97
diff changeset
381 td_elt = _bottom.getElement().parentNode
ad0696615768 browser side: bottomBorderWidget size fix (for webkit)
Goffi <goffi@goffi.org>
parents: 97
diff changeset
382 DOM.setStyleAttribute(td_elt, "height", "1px") #needed so the cell adapt to the size of the border (specially in webkit)
85
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
383 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
384
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
385 def isLocked(self):
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
386 return self.locked
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
387
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
388 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
389 """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
390 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
391 last_row = max(0, self.flextable.getRowCount()-1)
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
392 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
393 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
394 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
395 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
396 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
397
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
398
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
399 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
400
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
401 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
402 #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
403 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
404 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
405
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
406 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
407 #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
408 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
409 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
410 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
411 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
412 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
413 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
414
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
415 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
416 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
417 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
418 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
419 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
420 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
421
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
422 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
423 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
424 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
425 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
426 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
427 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
428
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
429 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
430 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
431 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
432
a8f027738c16 browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents: 84
diff changeset
433 _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
434 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
435 self._max_cols = _max_cols
86
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
436 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
437
86
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
438 def _sizesAdjust(self):
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
439 cellFormatter = self.flextable.getFlexCellFormatter()
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
440 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
441
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
442 for row_idx in xrange(self.flextable.getRowCount()):
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
443 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
444 _widget = self.flextable.getWidget(row_idx, col_idx)
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
445 if not isinstance(_widget, BorderWidget):
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
446 td_elt = _widget.getElement().parentNode
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
447 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
448
86
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
449 last_row = max(0, self.flextable.getRowCount()-1)
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
450 cellFormatter.setColSpan(last_row, 0, self._max_cols)
178
7a349be99a77 dummy commit, just for test
Goffi <goffi@goffi.org>
parents: 177
diff changeset
451
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
452 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
453 """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
454 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
455 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
456 self.changeWidget(last_row, 0, wid)
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
457
86
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
458 def removeWidget(self, wid):
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
459 """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
460 _row, _col = self.flextable.getIndex(wid)
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
461 self.flextable.remove(wid)
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
462 self.flextable.removeCell(_row, _col)
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
463 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
464 self.flextable.removeRow(_row)
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
465 _max_cols = 1
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
466 for row_idx in xrange(self.flextable.getRowCount()):
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
467 _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
468 if _max_cols != self._max_cols:
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
469 self._max_cols = _max_cols
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
470 self._sizesAdjust()
177
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
471 current = self
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
472
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
473 blank_page = self.getLiberviaWidgetsCount() == 0 # do we still have widgets on the page ?
177
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
474
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
475 if blank_page and not self.isLocked():
177
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
476 #we now notice the MainTabPanel that the WidgetsPanel is empty and need to be removed
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
477 while current is not None:
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
478 if isinstance(current, MainTabPanel):
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
479 current.onWidgetPanelRemove(self)
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
480 return
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
481 current = current.getParent()
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
482 print "Error: no MainTabPanel found !"
86
6c3b3254605f browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents: 85
diff changeset
483
196
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
484 def getLiberviaWidgetsCount(self):
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
485 """ Get count of contained widgets """
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
486 return len([wid for wid in self.flextable if isinstance(wid, LiberviaWidget)])
c2639c9f86ea Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents: 195
diff changeset
487
90
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
488 def getIndex(self, wid):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
489 return self.flextable.getIndex(wid)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
490
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
491 def getColSpan(self, row, col):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
492 cellFormatter = self.flextable.getFlexCellFormatter()
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
493 return cellFormatter.getColSpan(row, col)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
494
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
495 def setColSpan(self, row, col, value):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
496 cellFormatter = self.flextable.getFlexCellFormatter()
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
497 return cellFormatter.setColSpan(row, col, value)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
498
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
499 def getRowSpan(self, row, col):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
500 cellFormatter = self.flextable.getFlexCellFormatter()
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
501 return cellFormatter.getRowSpan(row, col)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
502
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
503 def setRowSpan(self, row, col, value):
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
504 cellFormatter = self.flextable.getFlexCellFormatter()
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
505 return cellFormatter.setRowSpan(row, col, value)
9729ed7171a6 browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents: 89
diff changeset
506
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
507 class MainTabPanel(TabPanel):
23
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
508
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
509 def __init__(self, host):
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
510 TabPanel.__init__(self)
23
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
511 self.host=host
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
512 self.tabBar.setVisible(False)
148
8635bc9db9bf added parameter management to test XMLUI, but it's currently deactivated for security reasons (need some configuration options) + separated mainTabPanel CSS from LiberviaTabPanel
Goffi <goffi@goffi.org>
parents: 139
diff changeset
513 self.setStyleName('liberviaTabPanel')
8635bc9db9bf added parameter management to test XMLUI, but it's currently deactivated for security reasons (need some configuration options) + separated mainTabPanel CSS from LiberviaTabPanel
Goffi <goffi@goffi.org>
parents: 139
diff changeset
514 self.addStyleName('mainTabPanel')
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
515 Window.addWindowResizeListener(self)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
516
192
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
517 def getCurrentPanel(self):
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
518 """ Get the panel of the currently selected tab """
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
519 return self.deck.visibleWidget
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
520
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
521 def onWindowResized(self, width, height):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
522 tab_panel_elt = self.getElement()
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
523 _elts = doc().getElementsByClassName('gwt-TabBar')
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
524 if not _elts.length:
177
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
525 print ("ERROR: no TabBar found, it should exist !")
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
526 tab_bar_h = 0
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
527 else:
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
528 tab_bar_h = _elts.item(0).offsetHeight
187
d0503f8f15ef browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents: 186
diff changeset
529 ideal_height = height - DOM.getAbsoluteTop(tab_panel_elt) - tab_bar_h - 5
185
40adfd4ee4d7 browser side: fixed MainTabPanel size
Goffi <goffi@goffi.org>
parents: 184
diff changeset
530 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
531 self.setWidth("%s%s" % (ideal_width, "px"));
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
532 self.setHeight("%s%s" % (ideal_height, "px"));
23
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
533
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
534 def add(self, widget, tabText=None, asHTML=False):
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
535 TabPanel.add(self, widget, tabText, asHTML)
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
536 if self.getWidgetCount()>1:
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
537 self.tabBar.setVisible(True)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
538 self.host.resize()
177
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
539
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
540 def onWidgetPanelRemove(self, panel):
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
541 """ Called when a child WidgetsPanel is empty and need to be removed """
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
542 self.remove(panel)
194
6198be95a39c browser side: new tab is automatically selected, if a tab is removed, the last one is automatically selected
Goffi <goffi@goffi.org>
parents: 193
diff changeset
543 widgets_count = self.getWidgetCount()
6198be95a39c browser side: new tab is automatically selected, if a tab is removed, the last one is automatically selected
Goffi <goffi@goffi.org>
parents: 193
diff changeset
544 if widgets_count == 1:
177
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
545 self.tabBar.setVisible(False)
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
546 self.host.resize()
ba95cd824e06 browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents: 174
diff changeset
547 self.selectTab(0)
194
6198be95a39c browser side: new tab is automatically selected, if a tab is removed, the last one is automatically selected
Goffi <goffi@goffi.org>
parents: 193
diff changeset
548 else:
6198be95a39c browser side: new tab is automatically selected, if a tab is removed, the last one is automatically selected
Goffi <goffi@goffi.org>
parents: 193
diff changeset
549 self.selectTab(widgets_count - 1)
23
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
550