Mercurial > libervia-web
annotate browser_side/base_widget.py @ 225:9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
- better PEP8 compliance
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 26 Sep 2013 11:39:54 +0200 |
parents | 3092f6b1710c |
children | 266e9678eec0 |
rev | line source |
---|---|
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
165 | 6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org> |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from pyjamas.ui.SimplePanel import SimplePanel |
33 | 24 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from pyjamas.ui.VerticalPanel import VerticalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas.ui.ScrollPanel import ScrollPanel |
195 | 28 from pyjamas.ui.FlexTable import FlexTable |
23 | 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 | 32 from pyjamas.ui.Button import Button |
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 | 35 from pyjamas.ui.ClickListener import ClickHandler |
83 | 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 | 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 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
43 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 class DropCell(DropWidget): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 """Cell in the middle grid which replace itself with the dropped widget on DnD""" |
195 | 46 drop_keys = {} |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
47 |
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
|
48 def __init__(self, host): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 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
|
50 self.host = host |
83 | 51 self.setStyleName('dropCell') |
195 | 52 |
53 @classmethod | |
54 def addDropKey(cls, key, callback): | |
55 DropCell.drop_keys[key] = callback | |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
56 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 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
|
58 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
|
59 return |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 self.addStyleName('dragover') |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 def onDragLeave(self, event): |
33 | 64 if event.clientX <= self.getAbsoluteLeft() or event.clientY <= self.getAbsoluteTop() or\ |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
65 event.clientX >= self.getAbsoluteLeft() + self.getOffsetWidth() - 1 or event.clientY >= self.getAbsoluteTop() + self.getOffsetHeight() - 1: |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
66 # We check that we are inside widget's box, and we don't remove the style in this case because |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
67 # if the mouse is over a widget inside the DropWidget, if will leave the DropWidget, and we |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
68 # don't want that |
33 | 69 self.removeStyleName('dragover') |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 def onDragOver(self, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 DOM.eventPreventDefault(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 def _getCellAndRow(self, grid, event): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 """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
|
76 cell = grid.getEventTargetCell(event) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 row = DOM.getParent(cell) |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 return (row.rowIndex, cell.cellIndex) |
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 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 def onDrop(self, event): |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
82 DOM.eventPreventDefault(event) |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 dt = event.dataTransfer |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
84 # 'text', 'text/plain', and 'Text' are equivalent. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 try: |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
86 item, item_type = dt.getData("text/plain").split('\n') # Workaround for webkit, only text/plain seems to be managed |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
87 if item_type and item_type[-1] == '\0': # Workaround for what looks like a pyjamas bug: the \0 should not be there, and |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
88 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
89 # item_type = dt.getData("type") |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 print "message: %s" % item |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 print "type: %s" % item_type |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 except: |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 print "no message found" |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
94 item = ' ' |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 item_type = None |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 return |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
100 _new_panel = LiberviaDragWidget.current |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
101 if self == _new_panel: # We can't drop on ourself |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
102 return |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
103 # 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
|
104 widgets_panel = _new_panel.getWidgetsPanel() |
197
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
105 wid_row = widgets_panel.getWidgetCoords(_new_panel)[0] |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
106 row_wids = widgets_panel.getLiberviaRowWidgets(wid_row) |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
107 if len(row_wids) == 1 and wid_row == widgets_panel.getWidgetCoords(self)[0]: |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
108 # the dropped widget is the only one in the same row |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
109 # as the target widget (self), we don't do anything |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
110 self.removeStyleName('dragover') |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
111 return |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
112 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
|
113 elif item_type in self.drop_keys: |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
114 _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
|
115 else: |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
116 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
|
117 return |
84 | 118 if isinstance(self, LiberviaWidget): |
119 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
|
120 self.onQuit() |
84 | 121 if not isinstance(_new_panel, LiberviaWidget): |
122 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
|
123 _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
|
124 _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
|
125 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
|
126 if self.host.getSelected == self: |
cf5c83e7d515
browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents:
191
diff
changeset
|
127 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
|
128 _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
|
129 """_unempty_panels = filter(lambda wid:not isinstance(wid,EmptyWidget),list(_flextable)) |
34 | 130 _width = 90/float(len(_unempty_panels) or 1) |
131 #now we resize all the cell of the column | |
132 for panel in _unempty_panels: | |
133 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
|
134 DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width)""" |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 #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
|
136 |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
137 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
|
138 |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
139 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
|
140 AbsolutePanel.__init__(self) |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
141 self.add(title) |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
142 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
|
143 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
|
144 button_group = HorizontalPanel() |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 self.addStyleName('widgetHeader') |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
157 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
|
158 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
201
diff
changeset
|
159 |
84 | 160 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler): |
83 | 161 """Libervia's widget which can replace itself with a dropped widget on DnD""" |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
201
diff
changeset
|
162 |
84 | 163 def __init__(self, host, title='', selectable=False): |
164 """Init the widget | |
165 @param host: SatWebFrontend object | |
166 @param title: title show in the header of the widget | |
167 @param selectable: True is widget can be selected by user""" | |
83 | 168 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
|
169 DropCell.__init__(self, host) |
84 | 170 ClickHandler.__init__(self) |
171 self.__selectable = selectable | |
172 self.__title_id = HTMLPanel.createUniqueId() | |
173 self.__setting_button_id = HTMLPanel.createUniqueId() | |
174 self.__close_button_id = HTMLPanel.createUniqueId() | |
175 self.__title = Label(title) | |
176 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
|
177 header = WidgetHeader(self, self.__title) |
83 | 178 self.add(header) |
179 self.setSize('100%', '100%') | |
180 self.addStyleName('widget') | |
84 | 181 if self.__selectable: |
182 self.addClickListener(self) | |
183 self.host.registerWidget(self) | |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
184 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
185 def getDebugName(self): |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
186 return "%s (%s)" % (self, self.__title.getText()) |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
187 |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
188 def getWidgetsPanel(self, verbose=True): |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
189 # current = self was not reassuring for the code analyzer |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
190 current = self.getParent() |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
191 while current is not None and not isinstance(current, WidgetsPanel): |
177
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
192 current = current.getParent() |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
193 if current is None and verbose: |
177
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
194 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
|
195 return current |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
196 |
84 | 197 def onClick(self, sender): |
192
cf5c83e7d515
browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents:
191
diff
changeset
|
198 self.host.setSelected(self) |
83 | 199 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
200 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
|
201 """ 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
|
202 _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
|
203 _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
|
204 self.onQuit() |
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
205 |
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
206 def onQuit(self): |
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
207 """ 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
|
208 pass |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
209 |
89
8d2c7be09eef
browser side: CSS: removed useless z-indexes, and replaced tabs by spaces
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
210 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
|
211 widpanel = self.getWidgetsPanel() |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
212 row, col = widpanel.getIndex(self) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
213 body = VerticalPanel() |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
214 |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
215 # colspan & rowspan |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
216 colspan = widpanel.getColSpan(row, col) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
217 rowspan = widpanel.getRowSpan(row, col) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
218 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
219 def onColSpanChange(value): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
220 widpanel.setColSpan(row, col, value) |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
221 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
222 def onRowSpanChange(value): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
223 widpanel.setRowSpan(row, col, value) |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
224 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
|
225 colspan_setter.addValueChangeListener(onColSpanChange) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
226 colspan_setter.setWidth('100%') |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
227 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
|
228 rowspan_setter.addValueChangeListener(onRowSpanChange) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
229 rowspan_setter.setWidth('100%') |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
230 body.add(colspan_setter) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
231 body.add(rowspan_setter) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
232 |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
233 # size |
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 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
|
235 if width_str.endswith('px'): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
236 width = int(width_str[:-2]) |
92
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 width = 0 |
97
3cbbe5c05aa5
browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
239 height_str = self.getHeight() |
3cbbe5c05aa5
browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
240 if height_str.endswith('px'): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
241 height = int(height_str[:-2]) |
97
3cbbe5c05aa5
browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
242 else: |
3cbbe5c05aa5
browser side: widgets' setting: height detection fix
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
243 height = 0 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
244 |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 else: |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
249 self.setWidth('%dpx' % value) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
250 |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 else: |
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
265 # reset |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
266 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
|
267 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
|
268 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
|
269 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
|
270 height_setter.setValue(0) |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
201
diff
changeset
|
271 |
92
dd54bc13ac81
browser side: widgets' width and height can now be fixed + tarot game position fix
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
272 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
|
273 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
|
274 body.setCellHorizontalAlignment(reset_bt, HasAlignment.ALIGN_CENTER) |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
201
diff
changeset
|
275 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
276 _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
|
277 _dialog.show() |
89
8d2c7be09eef
browser side: CSS: removed useless z-indexes, and replaced tabs by spaces
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
278 |
83 | 279 def setTitle(self, text): |
280 """change the title in the header of the widget | |
281 @param text: text of the new title""" | |
84 | 282 self.__title.setText(text) |
283 | |
284 def isSelectable(self): | |
285 return self.__selectable | |
286 | |
287 def setSelectable(self, selectable): | |
288 if not self.__selectable: | |
289 try: | |
290 self.removeClickListener(self) | |
291 except ValueError: | |
292 pass | |
293 if self.selectable and not self in self._clickListeners: | |
294 self.addClickListener(self) | |
295 self.__selectable = selectable | |
83 | 296 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
297 def getWarningData(self): |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
298 """ Return exposition warning level when this widget is selected and something is sent to it |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
299 This method should be overriden by children |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
300 @return: tuple (warning level type/HTML msg). Type can be one of: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
301 - PUBLIC |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
302 - GROUP |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
303 - ONE2ONE |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
304 - MISC |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
305 - NONE |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
306 """ |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
307 if not self.__selectable: |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
308 print "ERROR: getWarningLevel must not be called for an unselectable widget" |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
309 raise Exception |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
310 # TODO: cleaner warning types (more general constants) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
311 return ("NONE", None) |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
312 |
83 | 313 def setWidget(self, widget, scrollable=True): |
314 """Set the widget that will be in the body of the LiberviaWidget | |
315 @param widget: widget to put in the body | |
316 @param scrollable: if true, the widget will be in a ScrollPanelWrapper""" | |
317 if scrollable: | |
318 _scrollpanelwrapper = ScrollPanelWrapper() | |
319 _scrollpanelwrapper.setStyleName('widgetBody') | |
320 _scrollpanelwrapper.setWidget(widget) | |
321 body_wid = _scrollpanelwrapper | |
322 else: | |
323 body_wid = widget | |
324 self.add(body_wid) | |
325 self.setCellHeight(body_wid, '100%') | |
326 | |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
327 def doDetachChildren(self): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
328 # We need to force the use of a panel subclass method here, |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
329 # for the same reason as doAttachChildren |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
330 VerticalPanel.doDetachChildren(self) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
331 |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
332 def doAttachChildren(self): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
333 # We need to force the use of a panel subclass method here, else |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
334 # the event will not propagate to children |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
335 VerticalPanel.doAttachChildren(self) |
83 | 336 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
337 |
34 | 338 class ScrollPanelWrapper(SimplePanel): |
339 """Scroll Panel like component, wich use the full available space | |
340 to work around percent size issue, it use some of the ideas found | |
341 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 | |
342 specially in code given at comment #46, thanks to Stefan Bachert""" | |
343 | |
344 def __init__(self, *args, **kwargs): | |
345 SimplePanel.__init__(self) | |
346 self.spanel = ScrollPanel(*args, **kwargs) | |
347 SimplePanel.setWidget(self, self.spanel) | |
348 DOM.setStyleAttribute(self.getElement(), "position", "relative") | |
349 DOM.setStyleAttribute(self.getElement(), "top", "0px") | |
350 DOM.setStyleAttribute(self.getElement(), "left", "0px") | |
351 DOM.setStyleAttribute(self.getElement(), "width", "100%") | |
352 DOM.setStyleAttribute(self.getElement(), "height", "100%") | |
353 DOM.setStyleAttribute(self.spanel.getElement(), "position", "absolute") | |
354 DOM.setStyleAttribute(self.spanel.getElement(), "width", "100%") | |
355 DOM.setStyleAttribute(self.spanel.getElement(), "height", "100%") | |
356 | |
357 def setWidget(self, widget): | |
358 self.spanel.setWidget(widget) | |
359 | |
360 def setScrollPosition(self, position): | |
361 self.spanel.setScrollPosition(position) | |
362 | |
363 def scrollToBottom(self): | |
364 self.setScrollPosition(self.spanel.getElement().scrollHeight) | |
365 | |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
366 |
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
|
367 class EmptyWidget(DropCell, SimplePanel): |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 """Empty dropable panel""" |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 def __init__(self, host): |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 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
|
372 DropCell.__init__(self, host) |
96
d7a4bbaddfb0
browser side: removed in EmptyPanel
Goffi <goffi@goffi.org>
parents:
92
diff
changeset
|
373 #self.setWidget(HTML('')) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
374 self.setSize('100%', '100%') |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
375 |
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
|
376 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
377 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
|
378 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
|
379 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
|
380 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
|
381 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
382 |
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 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
|
384 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
|
385 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
|
386 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
|
387 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
388 |
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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
394 |
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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
400 |
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
|
401 class WidgetsPanel(ScrollPanelWrapper): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
402 |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
403 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
|
404 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
|
405 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
|
406 self.host = host |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
407 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
|
408 self.selected = None |
83 | 409 self.flextable = FlexTable() |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
410 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
|
411 self.setWidget(self.flextable) |
83 | 412 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
|
413 _bottom = BottomBorderWidget(self.host) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
414 self.flextable.setWidget(0, 0, _bottom) # There will be always an Empty widget on the last row, |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
415 # dropping a widget there will add a new row |
101
ad0696615768
browser side: bottomBorderWidget size fix (for webkit)
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
416 td_elt = _bottom.getElement().parentNode |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
417 DOM.setStyleAttribute(td_elt, "height", "1px") # needed so the cell adapt to the size of the border (specially in webkit) |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
418 self._max_cols = 1 # give the maximum number of columns i a raw |
83 | 419 |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
420 def isLocked(self): |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
421 return self.locked |
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
422 |
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
|
423 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
|
424 """Change the widget in the given location, add row or columns when necessary""" |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
425 print "changing widget:", wid.getDebugName(), row, col |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
426 last_row = max(0, self.flextable.getRowCount() - 1) |
83 | 427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
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 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
|
434 |
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 if isinstance(prev_wid, BorderWidget): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
436 # We are on a border, we must create a row and/or columns |
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 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
|
438 prev_wid.removeStyleName('dragover') |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
439 |
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
|
440 if isinstance(prev_wid, BottomBorderWidget): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
441 # We are on the bottom border, we create a new row |
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
|
442 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
449 elif isinstance(prev_wid, LeftBorderWidget): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
450 if col != 0: |
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
|
451 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
|
452 return |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
453 self.flextable.insertCell(row, col + 1) |
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
|
454 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
|
455 |
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 elif isinstance(prev_wid, RightBorderWidget): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
457 if col != self.flextable.getCellCount(row) - 1: |
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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 |
a8f027738c16
browser side: widgets cells can now be added by putting a widget on a border
Goffi <goffi@goffi.org>
parents:
84
diff
changeset
|
463 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
|
464 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
|
465 self.flextable.setWidget(row, col, wid) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
466 |
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
|
467 _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
|
468 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
|
469 self._max_cols = _max_cols |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
470 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
|
471 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
472 def _sizesAdjust(self): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
473 cellFormatter = self.flextable.getFlexCellFormatter() |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
474 width = 100.0 / max(1, self._max_cols - 2) # we don't count the borders |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
475 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
476 for row_idx in xrange(self.flextable.getRowCount()): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
477 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
|
478 _widget = self.flextable.getWidget(row_idx, col_idx) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
479 if not isinstance(_widget, BorderWidget): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
480 td_elt = _widget.getElement().parentNode |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
481 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
|
482 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
483 last_row = max(0, self.flextable.getRowCount() - 1) |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
484 cellFormatter.setColSpan(last_row, 0, self._max_cols) |
178 | 485 |
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
|
486 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
|
487 """Add a widget to a new cell on the next to last row""" |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
488 last_row = max(0, self.flextable.getRowCount() - 1) |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
489 print "putting widget %s at %d, %d" % (wid.getDebugName(), last_row, 0) |
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
|
490 self.changeWidget(last_row, 0, wid) |
83 | 491 |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
492 def removeWidget(self, wid): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
493 """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
|
494 _row, _col = self.flextable.getIndex(wid) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
495 self.flextable.remove(wid) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
496 self.flextable.removeCell(_row, _col) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
497 if not self.getLiberviaRowWidgets(_row): # we have no more widgets, we remove the row |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
498 self.flextable.removeRow(_row) |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
499 _max_cols = 1 |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
500 for row_idx in xrange(self.flextable.getRowCount()): |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
501 _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
|
502 if _max_cols != self._max_cols: |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
503 self._max_cols = _max_cols |
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
504 self._sizesAdjust() |
177
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
505 current = self |
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
506 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
507 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
|
508 |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
509 if blank_page and not self.isLocked(): |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
510 # we now notice the MainTabPanel that the WidgetsPanel is empty and need to be removed |
177
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
511 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
|
512 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
|
513 current.onWidgetPanelRemove(self) |
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
514 return |
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
515 current = current.getParent() |
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
516 print "Error: no MainTabPanel found !" |
86
6c3b3254605f
browser side: widget removing is now managed
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
517 |
197
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
518 def getWidgetCoords(self, wid): |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
519 return self.flextable.getIndex(wid) |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
520 |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
521 def getLiberviaRowWidgets(self, row): |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
522 """ Return all the LiberviaWidget in the row """ |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
523 return [wid for wid in self.getRowWidgets(row) if isinstance(wid, LiberviaWidget)] |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
524 |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
525 def getRowWidgets(self, row): |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
526 """ Return all the widgets in the row """ |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
527 widgets = [] |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
528 cols = self.flextable.getCellCount(row) |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
529 for col in xrange(cols): |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
530 widgets.append(self.flextable.getWidget(row, col)) |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
531 return widgets |
0fc32122a877
browser side: dropped widget's row is now checked, to avoid the drop on a removed BorderWidget. This finish the previous commit.
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
532 |
196
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
533 def getLiberviaWidgetsCount(self): |
c2639c9f86ea
Browser Side: Widgets can now be moved, header (title bar) is draggable:
Goffi <goffi@goffi.org>
parents:
195
diff
changeset
|
534 """ 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
|
535 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
|
536 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
537 def getIndex(self, wid): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
538 return self.flextable.getIndex(wid) |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
539 |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
540 def getColSpan(self, row, col): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
541 cellFormatter = self.flextable.getFlexCellFormatter() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
542 return cellFormatter.getColSpan(row, col) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
543 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
544 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
|
545 cellFormatter = self.flextable.getFlexCellFormatter() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
546 return cellFormatter.setColSpan(row, col, value) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
547 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
548 def getRowSpan(self, row, col): |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
549 cellFormatter = self.flextable.getFlexCellFormatter() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
550 return cellFormatter.getRowSpan(row, col) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
551 |
90
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
552 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
|
553 cellFormatter = self.flextable.getFlexCellFormatter() |
9729ed7171a6
browser side: Widgets' setting (col & row span can be changed
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
554 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
|
555 |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
556 class DropTab(Label, DropWidget): |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
557 |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
558 def __init__(self, tab_panel, text): |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
559 Label.__init__(self, text) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
560 DropWidget.__init__(self, tab_panel) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
561 self.tab_panel = tab_panel |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
562 self.setStyleName('dropCell') |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
563 self.setWordWrap(False) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
564 DOM.setStyleAttribute(self.getElement(), "min-width", "30px") |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
565 |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
566 def _getIndex(self): |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
567 """ get current index of the DropTab """ |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
568 # XXX: awful hack, but seems the only way to get index |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
569 return self.tab_panel.tabBar.panel.getWidgetIndex(self.getParent().getParent()) - 1 |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
570 |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
571 |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
572 def onDragEnter(self, event): |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
573 #if self == LiberviaDragWidget.current: |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
574 # return |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
575 self.addStyleName('dragover') |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
576 DOM.eventPreventDefault(event) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
577 |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
578 def onDragLeave(self, event): |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
579 self.removeStyleName('dragover') |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
580 |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
581 def onDragOver(self, event): |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
582 DOM.eventPreventDefault(event) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
583 |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
584 def onDrop(self, event): |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
585 DOM.eventPreventDefault(event) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
586 self.removeStyleName('dragover') |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
587 if self._getIndex() == self.tab_panel.tabBar.getSelectedTab(): |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
588 # the widget come from the DragTab, so nothing to do, we let it there |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
589 return |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
590 |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
591 # FIXME: quite the same stuff as in DropCell, need some factorisation |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
592 dt = event.dataTransfer |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
593 # 'text', 'text/plain', and 'Text' are equivalent. |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
594 try: |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
595 item, item_type = dt.getData("text/plain").split('\n') # Workaround for webkit, only text/plain seems to be managed |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
596 if item_type and item_type[-1] == '\0': # Workaround for what looks like a pyjamas bug: the \0 should not be there, and |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
597 item_type = item_type[:-1] # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report |
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
598 # item_type = dt.getData("type") |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
599 print "message: %s" % item |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
600 print "type: %s" % item_type |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
601 except: |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
602 print "no message found" |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
603 item = ' ' |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
604 item_type = None |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
605 if item_type == "WIDGET": |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
606 if not LiberviaDragWidget.current: |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
607 print "ERROR: No widget registered in LiberviaDragWidget !" |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
608 return |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
609 _new_panel = LiberviaDragWidget.current |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
610 _new_panel.getWidgetsPanel().removeWidget(_new_panel) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
611 elif item_type in DropCell.drop_keys: |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
612 _new_panel = DropCell.drop_keys[item_type](self.tab_panel.host, item) |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
613 else: |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
614 print "WARNING: unmanaged item type" |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
615 return |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
616 |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
617 widgets_panel = self.tab_panel.getWidget(self._getIndex()) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
618 widgets_panel.addWidget(_new_panel) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
619 |
34 | 620 class MainTabPanel(TabPanel): |
23 | 621 |
622 def __init__(self, host): | |
33 | 623 TabPanel.__init__(self) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
624 self.host = host |
23 | 625 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
|
626 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
|
627 self.addStyleName('mainTabPanel') |
33 | 628 Window.addWindowResizeListener(self) |
629 | |
192
cf5c83e7d515
browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents:
191
diff
changeset
|
630 def getCurrentPanel(self): |
cf5c83e7d515
browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents:
191
diff
changeset
|
631 """ Get the panel of the currently selected tab """ |
cf5c83e7d515
browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents:
191
diff
changeset
|
632 return self.deck.visibleWidget |
cf5c83e7d515
browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents:
191
diff
changeset
|
633 |
33 | 634 def onWindowResized(self, width, height): |
635 tab_panel_elt = self.getElement() | |
636 _elts = doc().getElementsByClassName('gwt-TabBar') | |
637 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
|
638 print ("ERROR: no TabBar found, it should exist !") |
33 | 639 tab_bar_h = 0 |
640 else: | |
641 tab_bar_h = _elts.item(0).offsetHeight | |
187
d0503f8f15ef
browser side: scroller added to contacts panel
Goffi <goffi@goffi.org>
parents:
186
diff
changeset
|
642 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
|
643 ideal_width = width - DOM.getAbsoluteLeft(tab_panel_elt) - 5 |
184
97d5e9de1106
browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
644 self.setWidth("%s%s" % (ideal_width, "px")); |
33 | 645 self.setHeight("%s%s" % (ideal_height, "px")); |
23 | 646 |
198
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
647 def add(self, widget, text=''): |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
648 tab = DropTab(self, text) |
ab239b3b67b3
browser side: tabs are now dropable (i.e. we can now move widgets between tabs)
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
649 TabPanel.add(self, widget, tab, False) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
650 if self.getWidgetCount() > 1: |
23 | 651 self.tabBar.setVisible(True) |
33 | 652 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
|
653 |
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
654 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
|
655 """ 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 self.host.resize() |
ba95cd824e06
browser side: tab is removed if it doesn't contain widget anymore.
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
661 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
|
662 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
|
663 self.selectTab(widgets_count - 1) |
225
9b93a21dc5e2
browser_side: display widget title in the debug info (LiberviaWidget method "getDebugName")
souliane <souliane@mailoo.org>
parents:
210
diff
changeset
|
664 |