Mercurial > libervia-web
comparison libervia.py @ 267:a76243c02074
browser_side: changes regarding widgets and tabs:
- getOrCreateLiberviaWidget gets a tab_label argument to add widgets in a specific tab
- ChatPanel can be matched not only regarding the target jid but also the dialog type ("one2one", "group"...)
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 17 Nov 2013 17:53:37 +0100 |
parents | cc778206b7ae |
children | 9eb9c7d41bdc |
comparison
equal
deleted
inserted
replaced
266:cc778206b7ae | 267:a76243c02074 |
---|---|
167 self.panel = panels.MainPanel(self) | 167 self.panel = panels.MainPanel(self) |
168 self.discuss_panel = self.panel.discuss_panel | 168 self.discuss_panel = self.panel.discuss_panel |
169 self.tab_panel = self.panel.tab_panel | 169 self.tab_panel = self.panel.tab_panel |
170 self.tab_panel.addTabListener(self) | 170 self.tab_panel.addTabListener(self) |
171 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets | 171 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets |
172 self.room_list = set() #set of rooms | 172 self.room_list = set() #set of rooms |
173 self.mblog_cache = [] #used to keep our own blog entries in memory, to show them in new mblog panel | 173 self.mblog_cache = [] #used to keep our own blog entries in memory, to show them in new mblog panel |
174 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file) | 174 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file) |
175 self.current_action_ids = set() | 175 self.current_action_ids = set() |
176 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) | 176 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) |
177 self.discuss_panel.addWidget(panels.MicroblogPanel(self, [])) | 177 self.discuss_panel.addWidget(panels.MicroblogPanel(self, [])) |
265 def setUniBox(self, unibox): | 265 def setUniBox(self, unibox): |
266 """register the unibox widget""" | 266 """register the unibox widget""" |
267 self.uni_box = unibox | 267 self.uni_box = unibox |
268 self.uni_box.addKey("@@: ") | 268 self.uni_box.addKey("@@: ") |
269 | 269 |
270 def addTab(self, wid, label): | 270 def addTab(self, label, wid, select=True): |
271 """Create a new tab and add a widget in | 271 """Create a new tab and eventually add a widget in |
272 @param label: label of the tab | |
272 @param wid: LiberviaWidget to add | 273 @param wid: LiberviaWidget to add |
273 @param label: label of the tab""" | 274 @param select: True to select the added tab |
274 _widgets_panel = WidgetsPanel(self) | 275 """ |
275 _widgets_panel.addWidget(wid) | 276 widgets_panel = WidgetsPanel(self) |
276 self.tab_panel.add(_widgets_panel, label) | 277 self.tab_panel.add(widgets_panel, label) |
277 self.tab_panel.selectTab(self.tab_panel.getWidgetCount() - 1) | 278 widgets_panel.addWidget(wid) |
278 | 279 if select: |
279 def addWidget(self, wid): | 280 self.tab_panel.selectTab(self.tab_panel.getWidgetCount() - 1) |
280 """ Add a widget at the bottom of the current tab | 281 return widgets_panel |
281 @param wid: LiberviaWidget to add """ | 282 |
282 panel = self.tab_panel.getCurrentPanel() | 283 def addWidget(self, wid, tab_index=None): |
284 """ Add a widget at the bottom of the current or specified tab | |
285 @param wid: LiberviaWidget to add | |
286 @param tab_index: index of the tab to add the widget to""" | |
287 if tab_index is None or tab_index < 0 or tab_index >= self.tab_panel.getWidgetCount(): | |
288 panel = self.tab_panel.getCurrentPanel() | |
289 else: | |
290 panel = self.tab_panel.tabBar.getTabWidget(tab_index) | |
283 panel.addWidget(wid) | 291 panel.addWidget(wid) |
284 | 292 |
285 def _isRegisteredCB(self, registered): | 293 def _isRegisteredCB(self, registered): |
286 if not registered: | 294 if not registered: |
287 self._register_box = RegisterBox(self.logged) | 295 self._register_box = RegisterBox(self.logged) |
511 except AttributeError as e: | 519 except AttributeError as e: |
512 e.stack_list() | 520 e.stack_list() |
513 return None | 521 return None |
514 return None | 522 return None |
515 | 523 |
516 def getOrCreateLiberviaWidget(self, class_, entity, select=True): | 524 def getOrCreateLiberviaWidget(self, class_, entity, select=True, new_tab=None): |
517 """Get the matching LiberviaWidget if it exists, or create a new one. | 525 """Get the matching LiberviaWidget if it exists, or create a new one. |
518 @param class_: class of the panel (ChatPanel, MicroblogPanel...) | 526 @param class_: class of the panel (ChatPanel, MicroblogPanel...) |
519 @param entity: polymorphic parameter, see class_.matchEntity. | 527 @param entity: polymorphic parameter, see class_.matchEntity. |
520 @param select: if True, select the widget that has been found or created | 528 @param select: if True, select the widget that has been found or created |
529 @param new_tab: if not None, a widget which is created is created in | |
530 a new tab. In that case new_tab is a unicode to label that new tab. | |
531 If new_tab is not None and a widget is found, no tab is created. | |
521 @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS | 532 @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS |
522 is set to False or if the widget has not been found, the existing | 533 is set to False or if the widget has not been found, the existing |
523 widget that has been found otherwise.""" | 534 widget that has been found otherwise.""" |
524 lib_wid = None | 535 lib_wid = None |
536 tab = None | |
525 if REUSE_EXISTING_LIBERVIA_WIDGETS: | 537 if REUSE_EXISTING_LIBERVIA_WIDGETS: |
526 lib_wid = self.getLiberviaWidget(class_, entity) | 538 lib_wid = self.getLiberviaWidget(class_, entity, new_tab is None) |
527 if lib_wid is None: | 539 if lib_wid is None: # create a new widget |
528 lib_wid = class_.createPanel(self, entity) | 540 lib_wid = class_.createPanel(self, entity[0] if isinstance(entity, tuple) else entity) |
529 else: | 541 if new_tab is None: |
530 # remove the widget from its previous panel | 542 self.addWidget(lib_wid) |
531 panel = lib_wid.getWidgetsPanel(verbose=False) | 543 else: |
532 if panel is not None: | 544 tab = self.addTab(new_tab, lib_wid, False) |
533 panel.removeWidget(lib_wid) | 545 else: # reuse existing widget |
534 self.addWidget(lib_wid) | 546 tab = lib_wid.getWidgetsPanel(verbose=False) |
547 if new_tab is None: | |
548 if tab is not None: | |
549 tab.removeWidget(lib_wid) | |
550 self.addWidget(lib_wid) | |
535 if select: | 551 if select: |
552 if new_tab is not None: | |
553 self.tab_panel.selectTab(tab) | |
536 # must be done after the widget is added, | 554 # must be done after the widget is added, |
537 # for example to scroll to the bottom | 555 # for example to scroll to the bottom |
538 self.setSelected(lib_wid) | 556 self.setSelected(lib_wid) |
539 lib_wid.refresh() | 557 lib_wid.refresh() |
540 return lib_wid | 558 return lib_wid |
562 _target = JID(room_jid) | 580 _target = JID(room_jid) |
563 self.room_list.add(_target) | 581 self.room_list.add(_target) |
564 chat_panel = panels.ChatPanel(self, _target, type_='group') | 582 chat_panel = panels.ChatPanel(self, _target, type_='group') |
565 chat_panel.setUserNick(user_nick) | 583 chat_panel.setUserNick(user_nick) |
566 if _target.node.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :) | 584 if _target.node.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :) |
567 self.addTab(chat_panel, "Tarot") | 585 self.addTab("Tarot", chat_panel) |
568 elif _target.node.startswith('sat_radiocol_'): | 586 elif _target.node.startswith('sat_radiocol_'): |
569 self.addTab(chat_panel, "Radio collective") | 587 self.addTab("Radio collective", chat_panel) |
570 else: | 588 else: |
571 self.addTab(chat_panel, _target.node) | 589 self.addTab(_target.node, chat_panel) |
572 chat_panel.setPresents(room_nicks) | 590 chat_panel.setPresents(room_nicks) |
573 chat_panel.historyPrint() | 591 chat_panel.historyPrint() |
574 | 592 |
575 def _roomUserJoinedCb(self, room_jid_s, user_nick, user_data): | 593 def _roomUserJoinedCb(self, room_jid_s, user_nick, user_data): |
576 for lib_wid in self.libervia_widgets: | 594 for lib_wid in self.libervia_widgets: |