Mercurial > libervia-web
diff src/browser/libervia_main.py @ 467:97c72fe4a5f2
browser_side: import fixes:
- moved browser modules in a sat_browser packages, to avoid import conflicts with std lib (e.g. logging), and let pyjsbuild work normaly
- refactored bad import practices: classes are most of time not imported directly, module is imported instead.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 09 Jun 2014 22:15:26 +0200 |
parents | 07433bd892ee |
children | 830b50593597 |
line wrap: on
line diff
--- a/src/browser/libervia_main.py Mon Jun 09 20:37:28 2014 +0200 +++ b/src/browser/libervia_main.py Mon Jun 09 22:15:26 2014 +0200 @@ -20,7 +20,7 @@ import pyjd # this is dummy in pyjs ### logging configuration ### -import logging +from sat_browser import logging logging.configure() from sat.core.log import getLogger log = getLogger(__name__) @@ -37,18 +37,17 @@ from pyjamas import Window, DOM from pyjamas.JSONService import JSONProxy -from register import RegisterBox -from contact import ContactPanel -from base_widget import WidgetsPanel -from panels import MicroblogItem -import panels -import dialog -from jid import JID -from xmlui import XMLUI -from html_tools import html_sanitize -from notification import Notification +from sat_browser import register +from sat_browser import contact +from sat_browser import base_widget +from sat_browser import panels +from sat_browser import dialog +from sat_browser import jid +from sat_browser import xmlui +from sat_browser import html_tools +from sat_browser import notification -from constants import Const as C +from sat_browser.constants import Const as C MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories @@ -56,7 +55,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 WidgetsPanel, or replaced to the expected +# and added to new base_widget.WidgetsPanel, or replaced to the expected # position if the previous and the new parent are the same. REUSE_EXISTING_LIBERVIA_WIDGETS = True @@ -178,7 +177,7 @@ self.bridge_signals = BridgeSignals(self) self.uni_box = None self.status_panel = HTML('<br />') - self.contact_panel = ContactPanel(self) + self.contact_panel = contact.ContactPanel(self) self.panel = panels.MainPanel(self) self.discuss_panel = self.panel.discuss_panel self.tab_panel = self.panel.tab_panel @@ -189,7 +188,7 @@ self.avatars_cache = {} # keep track of jid's avatar hash (key=jid, value=file) self._register_box = None RootPanel().add(self.panel) - self.notification = Notification() + self.notification = notification.Notification() DOM.addEventPreview(self) self._register = RegisterCall() self._register.call('getMenus', self.panel.menu.createMenus) @@ -204,15 +203,15 @@ def getSelected(self): wid = self.tab_panel.getCurrentPanel() - if not isinstance(wid, WidgetsPanel): - log.error("Tab widget is not a WidgetsPanel, can't get selected widget") + if not isinstance(wid, base_widget.WidgetsPanel): + log.error("Tab widget is not a base_widget.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, WidgetsPanel): + if not isinstance(widgets_panel, base_widget.WidgetsPanel): return selected = widgets_panel.selected @@ -293,7 +292,7 @@ @param wid: LiberviaWidget to add @param select: True to select the added tab """ - widgets_panel = WidgetsPanel(self) + widgets_panel = base_widget.WidgetsPanel(self) self.tab_panel.add(widgets_panel, label) widgets_panel.addWidget(wid) if select: @@ -316,7 +315,7 @@ def _isRegisteredCB(self, result): registered, warning = result if not registered: - self._register_box = RegisterBox(self.logged) + self._register_box = register.RegisterBox(self.logged) self._register_box.centerBox() self._register_box.show() if warning: @@ -395,7 +394,7 @@ # action was a one shot, nothing to do pass elif "xmlui" in data: - ui = XMLUI(self, xml_data=data['xmlui']) + ui = xmlui.XMLUI(self, xml_data=data['xmlui']) options = ['NO_CLOSE'] if ui.type == 'form' else [] _dialog = dialog.GenericDialog(ui.title, ui, options=options) ui.setCloseCb(_dialog.close) @@ -420,8 +419,8 @@ self.bridge.call('launchAction', (self._actionCb, self._actionEb), callback_id, data) def _getContactsCB(self, contacts_data): - for contact in contacts_data: - jid, attributes, groups = contact + for contact_ in contacts_data: + jid, attributes, groups = contact_ self._newContactCb(jid, attributes, groups) def _getSignalsCB(self, signal_data): @@ -487,9 +486,9 @@ elif name == 'chatStateReceived': self._chatStateReceivedCb(*args) - def _getParamsUICB(self, xmlui): + def _getParamsUICB(self, xml_ui): """Hide the parameters item if there's nothing to display""" - if not xmlui: + if not xml_ui: self.panel.menu.removeItemParams() def _ownBlogsFills(self, mblogs): @@ -503,7 +502,7 @@ _groups = set(mblog['groups'].split() if mblog['groups'] else []) else: _groups = None - mblog_entry = MicroblogItem(mblog) + mblog_entry = panels.MicroblogItem(mblog) self.mblog_cache.append((_groups, mblog_entry)) if len(self.mblog_cache) > MAX_MBLOG_CACHE: @@ -517,7 +516,7 @@ del self.init_cache def _getProfileJidCB(self, jid): - self.whoami = JID(jid) + self.whoami = jid.JID(jid) #we can now ask our status self.bridge.call('getPresenceStatuses', self._getPresenceStatusesCb) #the rooms where we are @@ -541,7 +540,7 @@ if not self.initialised: self.init_cache.append((sender, event_type, data)) return - sender = JID(sender).bare + sender = jid.JID(sender).bare if event_type == "MICROBLOG": if not 'content' in data: log.warning("No content found in microblog data") @@ -550,7 +549,7 @@ _groups = set(data['groups'].split() if data['groups'] else []) else: _groups = None - mblog_entry = MicroblogItem(data) + mblog_entry = panels.MicroblogItem(data) for lib_wid in self.libervia_widgets: if isinstance(lib_wid, panels.MicroblogPanel): @@ -588,7 +587,7 @@ @param mblog_panel: MicroblogPanel instance @param sender: jid of the entry sender @param _groups: groups which can receive this entry - @param mblog_entry: MicroblogItem instance""" + @param mblog_entry: panels.MicroblogItem instance""" if mblog_entry.type == "comment" or mblog_panel.isJidAccepted(sender) or (_groups == None and self.whoami and sender == self.whoami.bare) \ or (_groups and _groups.intersection(mblog_panel.accepted_groups)): mblog_panel.addEntry(mblog_entry) @@ -669,8 +668,8 @@ return lib_wid def _newMessageCb(self, from_jid, msg, msg_type, to_jid, extra): - _from = JID(from_jid) - _to = JID(to_jid) + _from = jid.JID(from_jid) + _to = jid.JID(to_jid) other = _to if _from.bare == self.whoami.bare else _from lib_wid = self.getLiberviaWidget(panels.ChatPanel, other, ignoreOtherTabs=False) self.displayNotification(_from, msg) @@ -691,7 +690,7 @@ self.contact_panel.setContactMessageWaiting(other.bare, True) def _presenceUpdateCb(self, entity, show, priority, statuses): - entity_jid = JID(entity) + entity_jid = jid.JID(entity) if self.whoami and self.whoami == entity_jid: # XXX: QnD way to get our presence/status self.status_panel.setPresence(show) if statuses: @@ -700,7 +699,7 @@ self.contact_panel.setConnected(entity_jid.bare, entity_jid.resource, show, priority, statuses) def _roomJoinedCb(self, room_jid, room_nicks, user_nick): - _target = JID(room_jid) + _target = jid.JID(room_jid) if _target not in self.room_list: self.room_list.append(_target) chat_panel = panels.ChatPanel(self, _target, type_='group') @@ -716,8 +715,8 @@ chat_panel.refresh() def _roomLeftCb(self, room_jid, room_nicks, user_nick): - # FIXME: room_list contains JID instances so why MUST we do - # 'remove(room_jid)' and not 'remove(JID(room_jid))' ????!! + # FIXME: room_list contains jid.JID instances so why MUST we do + # 'remove(room_jid)' and not 'remove(jid.JID(room_jid))' ????!! # This looks like a pyjamas bug --> check/report try: self.room_list.remove(room_jid) @@ -776,17 +775,17 @@ def _subscribeCb(self, sub_type, entity): if sub_type == 'subscribed': - dialog.InfoDialog('Subscription confirmation', 'The contact <b>%s</b> has added you to his/her contact list' % html_sanitize(entity)).show() + dialog.InfoDialog('Subscription confirmation', 'The contact <b>%s</b> has added you to his/her contact list' % html_tools.html_sanitize(entity)).show() self.getEntityMBlog(entity) elif sub_type == 'unsubscribed': - dialog.InfoDialog('Subscription refusal', 'The contact <b>%s</b> has refused to add you in his/her contact list' % html_sanitize(entity)).show() + dialog.InfoDialog('Subscription refusal', 'The contact <b>%s</b> has refused to add you in his/her contact list' % html_tools.html_sanitize(entity)).show() #TODO: remove microblogs from panels elif sub_type == 'subscribe': #The user want to subscribe to our presence _dialog = None - msg = HTML('The contact <b>%s</b> want to add you in his/her contact list, do you accept ?' % html_sanitize(entity)) + msg = HTML('The contact <b>%s</b> want to add you in his/her contact list, do you accept ?' % html_tools.html_sanitize(entity)) def ok_cb(ignore): self.bridge.call('subscription', None, "subscribed", entity, '', _dialog.getSelectedGroups()) @@ -824,7 +823,7 @@ target = '@ALL@' nick = C.ALL_OCCUPANTS else: - from_jid = JID(from_jid_s) + from_jid = jid.JID(from_jid_s) target = from_jid.bare nick = from_jid.resource