diff src/browser/libervia_main.py @ 648:6d3142b782c3 frontends_multi_profiles

browser_side: classes reorganisation: - moved widgets in dedicated modules (base, contact, editor, libervia) and a widget module for single classes - same thing for panels (base, main, contact) - libervia_widget mix main panels and widget and drag n drop for technical reasons (see comments) - renamed WebPanel to WebWidget
author Goffi <goffi@goffi.org>
date Thu, 26 Feb 2015 18:10:54 +0100
parents 9972a24592b0
children 2df91d0308ac
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Thu Feb 26 13:10:46 2015 +0100
+++ b/src/browser/libervia_main.py	Thu Feb 26 18:10:54 2015 +0100
@@ -42,13 +42,14 @@
 from sat_browser import json
 from sat_browser import register
 from sat_browser.contact_list import ContactList
-from sat_browser import base_widget
-from sat_browser import panels
+from sat_browser import widget
+from sat_browser import main_panel
 from sat_browser import blog
 from sat_browser import dialog
 from sat_browser import xmlui
 from sat_browser import html_tools
 from sat_browser import notification
+from sat_browser import libervia_widget
 
 from sat_browser.constants import Const as C
 import os.path
@@ -69,7 +70,7 @@
 # Set to true to not create a new LiberviaWidget when a similar one
 # already exist (i.e. a chat panel with the same target). Instead
 # the existing widget will be eventually removed from its parent
-# and added to new base_widget.WidgetsPanel, or replaced to the expected
+# and added to new libervia_widget.WidgetsPanel, or replaced to the expected
 # position if the previous and the new parent are the same.
 REUSE_EXISTING_LIBERVIA_WIDGETS = True
 
@@ -81,7 +82,7 @@
         QuickApp.__init__(self, json.BridgeCall)
         self.uni_box = None # FIXME: to be removed
         self.status_panel = HTML('<br />')
-        self.panel = panels.MainPanel(self)
+        self.panel = main_panel.MainPanel(self)
         self.tab_panel = self.panel.tab_panel
         self.tab_panel.addTabListener(self)
         self._register_box = None
@@ -156,15 +157,15 @@
 
     def getSelected(self):
         wid = self.tab_panel.getCurrentPanel()
-        if not isinstance(wid, base_widget.WidgetsPanel):
-            log.error("Tab widget is not a base_widget.WidgetsPanel, can't get selected widget")
+        if not isinstance(wid, libervia_widget.WidgetsPanel):
+            log.error("Tab widget is not a WidgetsPanel, can't get selected widget")
             return None
         return wid.selected
 
     def setSelected(self, widget):
         """Define the selected widget"""
         widgets_panel = self.tab_panel.getCurrentPanel()
-        if not isinstance(widgets_panel, base_widget.WidgetsPanel):
+        if not isinstance(widgets_panel, libervia_widget.WidgetsPanel):
             return
 
         selected = widgets_panel.selected
@@ -194,7 +195,8 @@
         return True
 
     def onTabSelected(self, sender, tab_index):
-        selected = self.getSelected()
+        pass
+        # selected = self.getSelected()
         # FIXME:
         # for callback in self._selected_listeners:
         #     callback(selected)
@@ -306,7 +308,7 @@
 
         # display the real presence status panel
         self.panel.header.remove(self.status_panel)
-        self.status_panel = panels.PresenceStatusPanel(self)
+        self.status_panel = main_panel.PresenceStatusPanel(self)
         self.panel.header.add(self.status_panel)
 
         self.bridge_signals.call('getSignals', self.bridge_signals.signalHandler)
@@ -329,7 +331,7 @@
         self.plug_profiles([C.PROF_KEY_NONE]) # XXX: None was used intitially, but pyjamas bug when using variable arguments and None is the only arg.
         microblog_widget = self.displayWidget(blog.MicroblogPanel, ())
         self.setSelected(microblog_widget)
-        # self.discuss_panel.addWidget(panels.MicroblogPanel(self, []))
+        # self.discuss_panel.addWidget(panel.MicroblogPanel(self, []))
 
         # # get cached params and refresh the display
         # def param_cb(cat, name, count):
@@ -344,11 +346,11 @@
     def profilePlugged(self, dummy):
         QuickApp.profilePlugged(self, dummy)
         # we fill the panels already here
-        for widget in self.widgets.getWidgets(blog.MicroblogPanel):
-            if widget.accept_all():
-                self.bridge.getMassiveLastMblogs('ALL', [], 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert)
+        for wid in self.widgets.getWidgets(blog.MicroblogPanel):
+            if wid.accept_all():
+                self.bridge.getMassiveLastMblogs('ALL', [], 10, profile=C.PROF_KEY_NONE, callback=wid.massiveInsert)
             else:
-                self.bridge.getMassiveLastMblogs('GROUP', widget.accepted_groups, 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert)
+                self.bridge.getMassiveLastMblogs('GROUP', wid.accepted_groups, 10, profile=C.PROF_KEY_NONE, callback=wid.massiveInsert)
 
         #we ask for our own microblogs:
         self.bridge.getMassiveLastMblogs('JID', [unicode(self.whoami.bare)], 10, profile=C.PROF_KEY_NONE, callback=self._ownBlogsFills)
@@ -363,9 +365,9 @@
         self.panel.addContactList(contact_list)
         return contact_list
 
-    def newWidget(self, widget):
-        log.debug("newWidget: {}".format(widget))
-        self.addWidget(widget)
+    def newWidget(self, wid):
+        log.debug("newWidget: {}".format(wid))
+        self.addWidget(wid)
 
     def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile):
         if type_ == C.MESS_TYPE_HEADLINE:
@@ -418,7 +420,7 @@
             # TODO: use the bare instead of node when all blogs can be retrieved
             node = jid.JID(data['public_blog']).node
             # FIXME: "/blog/{}" won't work with unicode nodes
-            self.displayWidget(panels.WebPanel, "/blog/{}".format(node), show_url=False, new_tab="{}'s blog".format(unicode(node)))
+            self.displayWidget(widget.WebWidget, "/blog/{}".format(node), show_url=False, new_tab="{}'s blog".format(unicode(node)))
         else:
             dialog.InfoDialog("Error",
                               "Unmanaged action result", Width="400px").center()
@@ -464,8 +466,8 @@
 
         if len(self.mblog_cache) > MAX_MBLOG_CACHE:
             del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)]
-        for widget in self.widgets.getWidgets(blog.MicroblogPanel):
-            self.FillMicroblogPanel(widget)
+        for wid in self.widgets.getWidgets(blog.MicroblogPanel):
+            self.FillMicroblogPanel(wid)
 
         # FIXME
         self.initialised = True  # initialisation phase is finished here
@@ -485,7 +487,7 @@
         # self.bridge.call('getWaitingSub', self._getWaitingSubCb)
         # #we fill the panels already here
         # for lib_wid in self.libervia_widgets:
-        #     if isinstance(lib_wid, panels.MicroblogPanel):
+        #     if isinstance(lib_wid, panel.MicroblogPanel):
         #         if lib_wid.accept_all():
         #             self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'ALL', [], 10)
         #         else:
@@ -516,8 +518,8 @@
                 _groups = None
             mblog_entry = blog.MicroblogItem(data)
 
-            for widget in self.widgets.getWidgets(blog.MicroblogPanel):
-                widget.addEntryIfAccepted(sender, _groups, mblog_entry)
+            for wid in self.widgets.getWidgets(blog.MicroblogPanel):
+                wid.addEntryIfAccepted(sender, _groups, mblog_entry)
 
             if sender == self.whoami.bare:
                 found = False
@@ -534,8 +536,8 @@
                     if len(self.mblog_cache) > MAX_MBLOG_CACHE:
                         del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)]
         elif event_type == 'MICROBLOG_DELETE':
-            for widget in self.widgets.getWidgets(blog.MicroblogPanel):
-                widget.removeEntry(data['type'], data['id'])
+            for wid in self.widgets.getWidgets(blog.MicroblogPanel):
+                wid.removeEntry(data['type'], data['id'])
             log.debug("%s %s %s" % (self.whoami.bare, sender, data['type']))
 
             if sender == self.whoami.bare and data['type'] == 'main_item':
@@ -622,7 +624,7 @@
         except quick_widgets.WidgetAlreadyExistsError:
             kwargs['on_existing_widget'] = C.WIDGET_KEEP
             wid = self.widgets.getOrCreateWidget(class_, target, *args, **kwargs)
-            widgets_panel = wid.getParent(base_widget.WidgetsPanel, expect=False)
+            widgets_panel = wid.getParent(libervia_widget.WidgetsPanel, expect=False)
             if widgets_panel is None:
                 # The widget exists but is hidden
                 self.addWidget(wid)
@@ -675,18 +677,18 @@
     #     """Get the MUC widget for the given target.
 
     #     @param target (jid.JID): BARE jid of the MUC
-    #     @return: panels.ChatPanel instance or None
+    #     @return: panel.ChatPanel instance or None
     #     """
     #     entity = {'item': target, 'type_': 'group'}
     #     if target.full() in self.room_list or target in self.room_list:  # as JID is a string-based class, we don't know what will please Pyjamas...
-    #         return self.getLiberviaWidget(panels.ChatPanel, entity, ignoreOtherTabs=False)
+    #         return self.getLiberviaWidget(panel.ChatPanel, entity, ignoreOtherTabs=False)
     #     return None
 
     # def getOrCreateRoomWidget(self, target):
     #     """Get the MUC widget for the given target, create it if necessary.
 
     #     @param target (jid.JID): BARE jid of the MUC
-    #     @return: panels.ChatPanel instance
+    #     @return: panel.ChatPanel instance
     #     """
     #     lib_wid = self.getRoomWidget(target)
     #     if lib_wid:
@@ -707,7 +709,7 @@
 
     #     self.room_list.append(target)
     #     entity = {'item': target, 'type_': 'group'}
-    #     return self.getOrCreateLiberviaWidget(panels.ChatPanel, entity, new_tab=tab_name)
+    #     return self.getOrCreateLiberviaWidget(panel.ChatPanel, entity, new_tab=tab_name)
 
     # def _newMessageCb(self, from_jid_s, msg, msg_type, to_jid_s, extra):
     #     from_jid = jid.JID(from_jid_s)
@@ -720,7 +722,7 @@
 
     # def newMessageCb(self, from_jid, msg, msg_type, to_jid, extra):
     #     other = to_jid if from_jid.bare == self.whoami.bare else from_jid
-    #     lib_wid = self.getLiberviaWidget(panels.ChatPanel, {'item': other}, ignoreOtherTabs=False)
+    #     lib_wid = self.getLiberviaWidget(panel.ChatPanel, {'item': other}, ignoreOtherTabs=False)
     #     self.displayNotification(from_jid, msg)
     #     if msg_type == 'headline' and from_jid.full() == self._defaultDomain:
     #         try:
@@ -748,7 +750,7 @@
     # def _presenceUpdateCb(self, entity, show, priority, statuses):
     #     entity_jid = jid.JID(entity)
     #     if self.whoami and self.whoami == entity_jid:  # XXX: QnD way to get our presence/status
-    #         assert(isinstance(self.status_panel, panels.PresenceStatusPanel))
+    #         assert(isinstance(self.status_panel, main_panel.PresenceStatusPanel))
     #         self.status_panel.setPresence(show)  # pylint: disable=E1103
     #         if statuses:
     #             self.status_panel.setStatus(statuses.values()[0])  # pylint: disable=E1103
@@ -881,11 +883,11 @@
     #     """
     #     if from_jid_s == '@ALL@':
     #         for lib_wid in self.libervia_widgets:
-    #             if isinstance(lib_wid, panels.ChatPanel):
+    #             if isinstance(lib_wid, panel.ChatPanel):
     #                 lib_wid.setState(state, nick=C.ALL_OCCUPANTS)
     #         return
     #     from_jid = jid.JID(from_jid_s)
-    #     lib_wid = self.getLiberviaWidget(panels.ChatPanel, {'item': from_jid}, ignoreOtherTabs=False)
+    #     lib_wid = self.getLiberviaWidget(panel.ChatPanel, {'item': from_jid}, ignoreOtherTabs=False)
     #     lib_wid.setState(state, nick=from_jid.resource)
 
     def _askConfirmation(self, confirmation_id, confirmation_type, data):
@@ -945,7 +947,7 @@
     #         elif type_ == "COMMENT":
     #             self.bridge.call("sendMblogComment", None, entities, text, extra)
     #         elif type_ == "STATUS":
-    #             assert(isinstance(self.status_panel, panels.PresenceStatusPanel))
+    #             assert(isinstance(self.status_panel, main_panel.PresenceStatusPanel))
     #             self.bridge.call('setStatus', None, self.status_panel.presence, text)  # pylint: disable=E1103
     #         elif type_ in ("groupchat", "chat"):
     #             addresses.append((addr, entities))
@@ -970,7 +972,7 @@
         @msg: message to be displayed
         """
         if not hasattr(self, "warning_popup"):
-            self.warning_popup = panels.WarningPopup()
+            self.warning_popup = main_panel.WarningPopup()
         self.warning_popup.showWarning(type_, msg)
 
     def showDialog(self, message, title="", type_="info", answer_cb=None, answer_data=None):