Mercurial > libervia-desktop-kivy
diff cagou/core/cagou_main.py @ 312:772c170b47a9
Python3 port:
/!\ Cagou now runs with Python 3.6+
Port has been done in the same way as for backend (check backend commit b2d067339de3
message for details).
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:14:22 +0200 |
parents | f55b60659ec1 |
children | 86566968837a |
line wrap: on
line diff
--- a/cagou/core/cagou_main.py Mon Aug 05 11:21:54 2019 +0200 +++ b/cagou/core/cagou_main.py Tue Aug 13 19:14:22 2019 +0200 @@ -24,7 +24,7 @@ from sat.core.i18n import _ from . import kivy_hack kivy_hack.do_hack() -from constants import Const as C +from .constants import Const as C from sat.core import log as logging log = logging.getLogger(__name__) from sat.core import exceptions @@ -49,8 +49,8 @@ from kivy.app import App from kivy.lang import Builder from kivy import properties -import xmlui -from profile_manager import ProfileManager +from . import xmlui +from .profile_manager import ProfileManager from kivy.clock import Clock from kivy.uix.label import Label from kivy.uix.boxlayout import BoxLayout @@ -64,7 +64,7 @@ from kivy.metrics import dp from kivy import utils as kivy_utils from kivy.config import Config as KivyConfig -from cagou_widget import CagouWidget +from .cagou_widget import CagouWidget from . import widgets_handler from .common import IconButton from . import menu @@ -78,7 +78,7 @@ from plyer import notification except ImportError: notification = None - log.warning(_(u"Can't import plyer, some features disabled")) + log.warning(_("Can't import plyer, some features disabled")) ## platform specific settings ## @@ -153,14 +153,14 @@ self.clear_widgets() for n in self.notes: kwargs = { - u'title': n.title, - u'message': n.message, - u'level': n.level + 'title': n.title, + 'message': n.message, + 'level': n.level } if n.symbol is not None: - kwargs[u'symbol'] = n.symbol + kwargs['symbol'] = n.symbol if n.action is not None: - kwargs[u'action'] = n.action + kwargs['action'] = n.action self.add_widget(NoteDrop(title=n.title, message=n.message, level=n.level, symbol=n.symbol, action=n.action)) self.add_widget(self.clear_btn) @@ -194,14 +194,14 @@ def addNote(self, title, message, level, symbol, action): kwargs = { - u'title': title, - u'message': message, - u'level': level + 'title': title, + 'message': message, + 'level': level } if symbol is not None: - kwargs[u'symbol'] = symbol + kwargs['symbol'] = symbol if action is not None: - kwargs[u'action'] = action + kwargs['action'] = action note = Note(**kwargs) self.notes.append(note) if self.notes_event is None: @@ -319,7 +319,7 @@ def build(self): Window.bind(on_keyboard=self.key_input) - wid = CagouRootWidget(Label(text=u"Loading please wait")) + wid = CagouRootWidget(Label(text="Loading please wait")) if sys.platform == 'android': # we don't want menu on Android wid.root_menus.height = 0 @@ -413,10 +413,10 @@ bridge_module = dynamic_import.bridge(bridge_name, 'sat_frontends.bridge') if bridge_module is None: - log.error(u"Can't import {} bridge".format(bridge_name)) + log.error("Can't import {} bridge".format(bridge_name)) sys.exit(3) else: - log.debug(u"Loading {} bridge".format(bridge_name)) + log.debug("Loading {} bridge".format(bridge_name)) super(Cagou, self).__init__(bridge_factory=bridge_module.Bridge, xmlui=xmlui, check_options=quick_utils.check_options, @@ -432,7 +432,7 @@ try: os.makedirs(self.downloads_dir) except OSError as e: - log.warnings(_(u"Can't create downloads dir: {reason}").format(reason=e)) + log.warnings(_("Can't create downloads dir: {reason}").format(reason=e)) self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png") self.app.icon = os.path.join(self.media_dir, "icons/muchoslava/png/cagou_profil_bleu_96.png") @@ -456,11 +456,11 @@ if not self.tls_validation: from cagou.core import patches patches.apply() - log.warning(u"SSL certificate validation is disabled, this is unsecure!") + log.warning("SSL certificate validation is disabled, this is unsecure!") @property def visible_widgets(self): - for w_list in self._visible_widgets.itervalues(): + for w_list in self._visible_widgets.values(): for w in w_list: yield w @@ -572,13 +572,13 @@ for kv_file in kv_files: Builder.load_file(kv_file) - log.debug(u"kv file {} loaded".format(kv_file)) + log.debug("kv file {} loaded".format(kv_file)) def _import_plugins(self): """import all plugins""" self.default_wid = None plugins_path = os.path.dirname(cagou.plugins.__file__) - plugin_glob = u"plugin*." + C.PLUGIN_EXT + plugin_glob = "plugin*." + C.PLUGIN_EXT plug_lst = [os.path.splitext(p)[0] for p in map(os.path.basename, glob.glob(os.path.join(plugins_path, plugin_glob)))] @@ -591,10 +591,10 @@ # we get type from plugin name suff = plug[7:] - if u'_' not in suff: - log.error(u"invalid plugin name: {}, skipping".format(plug)) + if '_' not in suff: + log.error("invalid plugin name: {}, skipping".format(plug)) continue - plugin_type = suff[:suff.find(u'_')] + plugin_type = suff[:suff.find('_')] # and select the variable to use according to type if plugin_type == C.PLUG_TYPE_WID: @@ -604,7 +604,7 @@ imported_names = imported_names_transfer default_factory = self._defaultFactoryTransfer else: - log.error(u"unknown plugin type {type_} for plugin {file_}, skipping" + log.error("unknown plugin type {type_} for plugin {file_}, skipping" .format( type_ = plugin_type, file_ = plug @@ -623,7 +623,7 @@ if 'platforms' in plugin_info: if sys.platform not in plugin_info['platforms']: - log.info(u"{plugin_file} is not used on this platform, skipping" + log.info("{plugin_file} is not used on this platform, skipping" .format(**plugin_info)) continue @@ -631,13 +631,13 @@ if 'import_name' not in plugin_info: plugin_info['import_name'] = plug if plugin_info['import_name'] in imported_names: - log.warning(_(u"there is already a plugin named {}, " - u"ignoring new one").format(plugin_info['import_name'])) + log.warning(_("there is already a plugin named {}, " + "ignoring new one").format(plugin_info['import_name'])) continue if plugin_info['import_name'] == C.WID_SELECTOR: if plugin_type != C.PLUG_TYPE_WID: - log.error(u"{import_name} import name can only be used with {type_} " - u"type, skipping {name}".format(type_=C.PLUG_TYPE_WID, + log.error("{import_name} import name can only be used with {type_} " + "type, skipping {name}".format(type_=C.PLUG_TYPE_WID, **plugin_info)) continue # if WidgetSelector exists, it will be our default widget @@ -651,10 +651,10 @@ # we need to load the kv file if 'kv_file' not in plugin_info: - plugin_info['kv_file'] = u'{}.kv'.format(plug) + plugin_info['kv_file'] = '{}.kv'.format(plug) kv_path = os.path.join(plugins_path, plugin_info['kv_file']) if not os.path.exists(kv_path): - log.debug(u"no kv found for {plugin_file}".format(**plugin_info)) + log.debug("no kv found for {plugin_file}".format(**plugin_info)) else: Builder.load_file(kv_path) @@ -669,7 +669,7 @@ # icons for size in ('small', 'medium'): - key = u'icon_{}'.format(size) + key = 'icon_{}'.format(size) try: path = plugin_info[key] except KeyError: @@ -682,7 +682,7 @@ plugins_set.append(plugin_info) if not self._plg_wids: - log.error(_(u"no widget plugin found")) + log.error(_("no widget plugin found")) return # we want widgets sorted by names @@ -699,7 +699,7 @@ elif type_ == C.PLUG_TYPE_TRANSFER: return self._plg_wids_transfer else: - raise KeyError(u"{} plugin type is unknown".format(type_)) + raise KeyError("{} plugin type is unknown".format(type_)) def getPluggedWidgets(self, type_=C.PLUG_TYPE_WID, except_cls=None): """get available widgets plugin infos @@ -727,7 +727,7 @@ """ plugins_set = self._getPluginsSet(type_) for plugin_info in plugins_set: - for k, w in kwargs.iteritems(): + for k, w in kwargs.items(): try: if plugin_info[k] != w: continue @@ -738,9 +738,9 @@ ## widgets handling def newWidget(self, widget): - log.debug(u"new widget created: {}".format(widget)) + log.debug("new widget created: {}".format(widget)) if isinstance(widget, quick_chat.QuickChat) and widget.type == C.CHAT_GROUP: - self.addNote(u"", _(u"room {} has been joined").format(widget.target)) + self.addNote("", _("room {} has been joined").format(widget.target)) def switchWidget(self, old, new): """Replace old widget by new one @@ -761,15 +761,15 @@ break if to_change is None: - raise exceptions.InternalError(u"no CagouWidget found when " - u"trying to switch widget") + raise exceptions.InternalError("no CagouWidget found when " + "trying to switch widget") wrapper = to_change.parent while wrapper is not None and not(isinstance(wrapper, widgets_handler.WHWrapper)): wrapper = wrapper.parent if wrapper is None: - raise exceptions.InternalError(u"no wrapper found") + raise exceptions.InternalError("no wrapper found") wrapper.changeWidget(new) self.selected_widget = new @@ -818,7 +818,7 @@ if w.parent is None and w != widget: to_delete.append(w) for w in to_delete: - log.debug(u"cleaning widget: {wid}".format(wid=w)) + log.debug("cleaning widget: {wid}".format(wid=w)) self.widgets.deleteWidget(w) def getOrClone(self, widget): @@ -873,7 +873,7 @@ plg_infos = [p for p in self.getPluggedWidgets() if action in p['import_name']][0] except IndexError: - log.warning(u"No plugin widget found to do {action}".format(action=action)) + log.warning("No plugin widget found to do {action}".format(action=action)) else: factory = plg_infos['factory'] self.switchWidget(None, @@ -885,7 +885,7 @@ main_menu = self.app.root.root_menus self.menus.addMenus(backend_menus) self.menus.addMenu(C.MENU_GLOBAL, - (_(u"Help"), _(u"About")), + (_("Help"), _("About")), callback=main_menu.onAbout) main_menu.update(C.MENU_GLOBAL) @@ -902,9 +902,9 @@ widget.onOTRState(state, dest_jid, profile) def _debugHandler(self, action, parameters, profile): - if action == u"visible_widgets_dump": + if action == "visible_widgets_dump": from pprint import pformat - log.info(u"Visible widgets dump:\n{data}".format( + log.info("Visible widgets dump:\n{data}".format( data=pformat(self._visible_widgets))) else: return super(Cagou, self)._debugHandler(action, parameters, profile) @@ -916,11 +916,11 @@ self.bridge.menusGet("", C.NO_SECURITY_LIMIT, callback=self._menusGetCb) def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): - log.info(u"Profile presence status set to {show}/{status}".format(show=show, + log.info("Profile presence status set to {show}/{status}".format(show=show, status=status)) def errback(self, failure_, title=_('error'), - message=_(u'error while processing: {msg}')): + message=_('error while processing: {msg}')): self.addNote(title, message.format(msg=failure_), level=C.XMLUI_DATA_LVL_WARNING) def addNote(self, title, message, level=C.XMLUI_DATA_LVL_INFO, symbol=None, @@ -982,10 +982,11 @@ ) self.addNotifWidget(wid) else: - log.warning(_(u"unknown dialog type: {dialog_type}").format(dialog_type=type)) + log.warning(_("unknown dialog type: {dialog_type}").format(dialog_type=type)) - def desktop_notif(self, message, title=u'', duration=5000): + def desktop_notif(self, message, title='', duration=5000): + global notification if notification is not None: try: notification.notify(title=title, @@ -994,7 +995,6 @@ app_icon=self.app.icon, timeout = duration) except Exception as e: - log.warning(_(u"Can't use notifications, disabling: {msg}").format( + log.warning(_("Can't use notifications, disabling: {msg}").format( msg = e)) - global notification notification = None