Mercurial > libervia-web
comparison src/browser/sat_browser/main_panel.py @ 654:40c72f3b7638 frontends_multi_profiles
browser_side: MainPanel is now based on a DockPanel, which allows to use less tables and also to remove some "window resized" listeners
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 27 Feb 2015 02:39:43 +0100 |
parents | 6d3142b782c3 |
children | 048401e5c506 |
comparison
equal
deleted
inserted
replaced
653:e1d067378ad3 | 654:40c72f3b7638 |
---|---|
24 log = getLogger(__name__) | 24 log = getLogger(__name__) |
25 | 25 |
26 from sat.core.i18n import _ | 26 from sat.core.i18n import _ |
27 from sat_frontends.tools.strings import addURLToText | 27 from sat_frontends.tools.strings import addURLToText |
28 | 28 |
29 from pyjamas.ui.AbsolutePanel import AbsolutePanel | 29 from pyjamas.ui.DockPanel import DockPanel |
30 from pyjamas.ui.HorizontalPanel import HorizontalPanel | 30 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
31 from pyjamas.ui.VerticalPanel import VerticalPanel | |
31 from pyjamas.ui.Button import Button | 32 from pyjamas.ui.Button import Button |
32 from pyjamas.ui.HTML import HTML | 33 from pyjamas.ui.HTML import HTML |
33 from pyjamas.ui.ClickListener import ClickHandler | 34 from pyjamas.ui.ClickListener import ClickHandler |
34 from pyjamas.Timer import Timer | 35 from pyjamas.Timer import Timer |
35 from pyjamas import Window | 36 from pyjamas.ui import HasVerticalAlignment |
36 from __pyjamas__ import doc | |
37 | 37 |
38 | 38 |
39 import base_menu | 39 import base_menu |
40 import menu | 40 import menu |
41 import dialog | 41 import dialog |
126 | 126 |
127 EMPTY_STATUS = '<click to set a status>' | 127 EMPTY_STATUS = '<click to set a status>' |
128 | 128 |
129 def __init__(self, host, status=''): | 129 def __init__(self, host, status=''): |
130 self.host = host | 130 self.host = host |
131 modifiedCb = lambda content: self.host.bridge.call('setStatus', None, self.host.status_panel.presence, content['text']) or True | 131 modifiedCb = lambda content: self.host.bridge.call('setStatus', None, self.host.presence_status_panel.presence, content['text']) or True |
132 editor_widget.HTMLTextEditor.__init__(self, {'text': status}, modifiedCb, options={'no_xhtml': True, 'listen_focus': True, 'listen_click': True}) | 132 editor_widget.HTMLTextEditor.__init__(self, {'text': status}, modifiedCb, options={'no_xhtml': True, 'listen_focus': True, 'listen_click': True}) |
133 self.edit(False) | 133 self.edit(False) |
134 self.setStyleName('statusPanel') | 134 self.setStyleName('marginAuto') |
135 | 135 |
136 @property | 136 @property |
137 def status(self): | 137 def status(self): |
138 return self._original_content['text'] | 138 return self._original_content['text'] |
139 | 139 |
151 editor_widget.BaseTextEditor.setContent(self, content) | 151 editor_widget.BaseTextEditor.setContent(self, content) |
152 | 152 |
153 def setDisplayContent(self): | 153 def setDisplayContent(self): |
154 status = self._original_content['text'] | 154 status = self._original_content['text'] |
155 try: | 155 try: |
156 presence = self.host.status_panel.presence | 156 presence = self.host.presence_status_panel.presence |
157 except AttributeError: # during initialization | 157 except AttributeError: # during initialization |
158 presence = None | 158 presence = None |
159 if not status: | 159 if not status: |
160 if presence and presence in C.PRESENCE: | 160 if presence and presence in C.PRESENCE: |
161 status = C.PRESENCE[presence] | 161 status = C.PRESENCE[presence] |
197 panel = HorizontalPanel() | 197 panel = HorizontalPanel() |
198 panel.add(self.menu) | 198 panel.add(self.menu) |
199 panel.add(self.status_panel) | 199 panel.add(self.status_panel) |
200 panel.setCellVerticalAlignment(self.menu, 'baseline') | 200 panel.setCellVerticalAlignment(self.menu, 'baseline') |
201 panel.setCellVerticalAlignment(self.status_panel, 'baseline') | 201 panel.setCellVerticalAlignment(self.status_panel, 'baseline') |
202 panel.setStyleName("marginAuto") | 202 panel.setStyleName("presenceStatusPanel") |
203 self.add(panel) | 203 self.add(panel) |
204 | 204 |
205 self.status_panel.edit(False) | 205 self.status_panel.edit(False) |
206 | 206 |
207 ClickHandler.__init__(self) | 207 ClickHandler.__init__(self) |
229 | 229 |
230 | 230 |
231 ### Panels managing the main area ### | 231 ### Panels managing the main area ### |
232 | 232 |
233 | 233 |
234 class MainPanel(AbsolutePanel): | 234 class MainPanel(DockPanel): |
235 """The panel which take the whole screen""" | 235 """The panel which take the whole screen""" |
236 | 236 |
237 def __init__(self, host): | 237 def __init__(self, host): |
238 self.host = host | 238 self.host = host |
239 AbsolutePanel.__init__(self) | 239 DockPanel.__init__(self, StyleName="mainPanel liberviaTabPanel") |
240 | 240 |
241 # menu | 241 # menu and status panel |
242 self.menu = menu.MainMenuPanel(host) | 242 self.header = VerticalPanel(StyleName="header") |
243 | 243 self.menu = menu.MainMenuBar(host) |
244 # # unibox | 244 self.header.add(self.menu) |
245 # self.unibox_panel = UniBoxPanel(host) | 245 |
246 # self.unibox_panel.setVisible(False) | |
247 | |
248 # contacts | 246 # contacts |
249 self._contacts = HorizontalPanel() | |
250 self._contacts.addStyleName('globalLeftArea') | |
251 self.contacts_switch = Button(u'«', self._contactsSwitch) | 247 self.contacts_switch = Button(u'«', self._contactsSwitch) |
252 self.contacts_switch.addStyleName('contactsSwitch') | 248 self.contacts_switch.addStyleName('contactsSwitch') |
253 self._contacts.add(self.contacts_switch) | 249 |
254 | 250 # tab panel |
255 # tabs | |
256 self.tab_panel = libervia_widget.MainTabPanel(host) | 251 self.tab_panel = libervia_widget.MainTabPanel(host) |
257 self.tab_panel.addWidgetsTab(_(u"Discussions"), select=True, locked=True) | 252 self.tab_panel.addWidgetsTab(_(u"Discussions"), select=True, locked=True) |
258 | 253 |
259 self.header = AbsolutePanel() | 254 # XXX: widget's addition order is important! |
260 self.header.add(self.menu) | 255 self.add(self.header, DockPanel.NORTH) |
261 # self.header.add(self.unibox_panel) | 256 self.add(self.tab_panel, DockPanel.CENTER) |
262 self.header.add(self.host.status_panel) | 257 self.setCellWidth(self.tab_panel, '100%') |
263 self.header.setStyleName('header') | 258 self.setCellHeight(self.tab_panel, '100%') |
264 self.add(self.header) | 259 self.add(self.tab_panel.getTabBar(), DockPanel.SOUTH) |
265 | 260 self.add(self.contacts_switch, DockPanel.WEST) |
266 self._hpanel = HorizontalPanel() | |
267 self._hpanel.add(self._contacts) | |
268 self._hpanel.add(self.tab_panel) | |
269 self.add(self._hpanel) | |
270 | |
271 self.setWidth("100%") | |
272 Window.addWindowResizeListener(self) | |
273 | 261 |
274 def addContactList(self, contact_list): | 262 def addContactList(self, contact_list): |
275 self._contacts.add(contact_list) | 263 self.add(contact_list, DockPanel.WEST) |
264 | |
265 def addPresenceStatusPanel(self, panel): | |
266 self.header.add(panel) | |
267 self.header.setCellHeight(panel, '100%') | |
268 self.header.setCellVerticalAlignment(panel, HasVerticalAlignment.ALIGN_BOTTOM) | |
276 | 269 |
277 def _contactsSwitch(self, btn=None): | 270 def _contactsSwitch(self, btn=None): |
278 """ (Un)hide contacts panel """ | 271 """ (Un)hide contacts panel """ |
279 if btn is None: | 272 if btn is None: |
280 btn = self.contacts_switch | 273 btn = self.contacts_switch |
292 if self._contacts.getParent() == parent: | 285 if self._contacts.getParent() == parent: |
293 return | 286 return |
294 self._contacts.removeFromParent() | 287 self._contacts.removeFromParent() |
295 parent.insert(self._contacts, 0) | 288 parent.insert(self._contacts, 0) |
296 | 289 |
297 def onWindowResized(self, width, height): | |
298 _elts = doc().getElementsByClassName('gwt-TabBar') | |
299 if not _elts.length: | |
300 tab_bar_h = 0 | |
301 else: | |
302 tab_bar_h = _elts.item(0).offsetHeight | |
303 ideal_height = Window.getClientHeight() - tab_bar_h | |
304 self.setHeight("%s%s" % (ideal_height, "px")) | |
305 | |
306 def refresh(self): | 290 def refresh(self): |
307 """Refresh the main panel""" | 291 """Refresh the main panel""" |
308 self.unibox_panel.refresh() | 292 self.unibox_panel.refresh() |
309 self.host.contact_panel.refresh() | 293 self.host.contact_panel.refresh() |
310 | 294 |