Sun, 22 Nov 2020 16:28:08 +0100
Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
# -*- coding: utf-8 -*- # Copyright (c) 2013 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing the base64 data URI encoder wizard plug-in. """ import os from PyQt5.QtCore import QObject, QTranslator from PyQt5.QtWidgets import QDialog from E5Gui.E5Application import e5App from E5Gui.E5Action import E5Action from E5Gui import E5MessageBox # Start-of-Header name = "Base64 Data URI Encoder Wizard Plug-in" author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True version = "3.1.0" className = "WizardDataUriEncoderPlugin" packageName = "WizardDataUriEncoder" shortDescription = "Wizard for the creation of code for a base64 data URI." longDescription = ( """This plug-in implements a wizard to generate code for""" """ base64 encoded data URIs.""" ) needsRestart = False pyqtApi = 2 # End-of-Header error = "" class WizardDataUriEncoderPlugin(QObject): """ Class implementing the base64 data URI encoder wizard plug-in. """ def __init__(self, ui): """ Constructor @param ui reference to the user interface object (UI.UserInterface) """ QObject.__init__(self, ui) self.__ui = ui self.__action = None self.__translator = None self.__loadTranslator() def activate(self): """ Public method to activate this plug-in. @return tuple of None and activation status (boolean) """ self.__initAction() self.__initMenu() return None, True def deactivate(self): """ Public method to deactivate this plug-in. """ menu = self.__ui.getMenu("wizards") if menu: menu.removeAction(self.__action) self.__ui.removeE5Actions([self.__action], 'wizards') def __loadTranslator(self): """ Private method to load the translation file. """ if self.__ui is not None: loc = self.__ui.getLocale() if loc and loc != "C": locale_dir = os.path.join( os.path.dirname(__file__), "WizardDataUriEncoder", "i18n") translation = "datauriencoder_{0}".format(loc) translator = QTranslator(None) loaded = translator.load(translation, locale_dir) if loaded: self.__translator = translator e5App().installTranslator(self.__translator) else: print("Warning: translation file '{0}' could not be" " loaded.".format(translation)) print("Using default.") def __initAction(self): """ Private method to initialize the action. """ self.__action = E5Action( self.tr('Base64 Data Uri Encoder Wizard'), self.tr('Base&64 Data Uri Encoder Wizard...'), 0, 0, self, 'wizards_datauriencoder') self.__action.setStatusTip(self.tr( 'Base64 Data Uri Encoder Wizard')) self.__action.setWhatsThis(self.tr( """<b>Base64 Data Uri Encoder Wizard</b>""" """<p>This wizard opens a dialog for entering all the parameters""" """ needed to create code for a base64 encoded data URI.</p>""" )) self.__action.triggered.connect(self.__handle) self.__ui.addE5Actions([self.__action], 'wizards') def __initMenu(self): """ Private method to add the actions to the right menu. """ menu = self.__ui.getMenu("wizards") if menu: menu.addAction(self.__action) def __handle(self): """ Private method to handle the wizards action. """ editor = e5App().getObject("ViewManager").activeWindow() if editor is None: E5MessageBox.critical( self.__ui, self.tr('No current editor'), self.tr('Please open or create a file first.')) else: from WizardDataUriEncoder.DataUriEncoderWizardDialog import ( DataUriEncoderWizardDialog ) dlg = DataUriEncoderWizardDialog(None) if dlg.exec() == QDialog.Accepted: code = dlg.getCode() if code: line, index = editor.getCursorPosition() # It should be done on this way to allow undo editor.beginUndoAction() editor.insertAt(code, line, index) editor.endUndoAction() # # eflag: noqa = M801