PluginWizardDataUriEncoder.py

branch
eric7
changeset 44
1ab3e76972e6
parent 41
f7634f688a52
child 47
2d49cd593939
equal deleted inserted replaced
43:dbb86ed48634 44:1ab3e76972e6
7 Module implementing the base64 data URI encoder wizard plug-in. 7 Module implementing the base64 data URI encoder wizard plug-in.
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt5.QtCore import QObject, QTranslator 12 from PyQt6.QtCore import QObject, QTranslator
13 from PyQt5.QtWidgets import QDialog 13 from PyQt6.QtWidgets import QDialog
14 14
15 from E5Gui.E5Application import e5App 15 from EricWidgets.EricApplication import ericApp
16 from E5Gui.E5Action import E5Action 16 from EricGui.EricAction import EricAction
17 from E5Gui import E5MessageBox 17 from EricWidgets import EricMessageBox
18 18
19 # Start-of-Header 19 # Start-of-Header
20 name = "Base64 Data URI Encoder Wizard Plug-in" 20 name = "Base64 Data URI Encoder Wizard Plug-in"
21 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 21 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
22 autoactivate = True 22 autoactivate = True
23 deactivateable = True 23 deactivateable = True
24 version = "3.2.0" 24 version = "1.0.0"
25 className = "WizardDataUriEncoderPlugin" 25 className = "WizardDataUriEncoderPlugin"
26 packageName = "WizardDataUriEncoder" 26 packageName = "WizardDataUriEncoder"
27 shortDescription = "Wizard for the creation of code for a base64 data URI." 27 shortDescription = "Wizard for the creation of code for a base64 data URI."
28 longDescription = ( 28 longDescription = (
29 """This plug-in implements a wizard to generate code for""" 29 """This plug-in implements a wizard to generate code for"""
42 """ 42 """
43 def __init__(self, ui): 43 def __init__(self, ui):
44 """ 44 """
45 Constructor 45 Constructor
46 46
47 @param ui reference to the user interface object (UI.UserInterface) 47 @param ui reference to the user interface object
48 @type UserInterface
48 """ 49 """
49 QObject.__init__(self, ui) 50 QObject.__init__(self, ui)
50 51
51 self.__ui = ui 52 self.__ui = ui
52 self.__action = None 53 self.__action = None
56 57
57 def activate(self): 58 def activate(self):
58 """ 59 """
59 Public method to activate this plug-in. 60 Public method to activate this plug-in.
60 61
61 @return tuple of None and activation status (boolean) 62 @return tuple of None and activation status
63 @rtype (None, bool)
62 """ 64 """
63 self.__initAction() 65 self.__initAction()
64 self.__initMenu() 66 self.__initMenu()
65 67
66 return None, True 68 return None, True
70 Public method to deactivate this plug-in. 72 Public method to deactivate this plug-in.
71 """ 73 """
72 menu = self.__ui.getMenu("wizards") 74 menu = self.__ui.getMenu("wizards")
73 if menu: 75 if menu:
74 menu.removeAction(self.__action) 76 menu.removeAction(self.__action)
75 self.__ui.removeE5Actions([self.__action], 'wizards') 77 self.__ui.removeEricActions([self.__action], 'wizards')
76 78
77 def __loadTranslator(self): 79 def __loadTranslator(self):
78 """ 80 """
79 Private method to load the translation file. 81 Private method to load the translation file.
80 """ 82 """
86 translation = "datauriencoder_{0}".format(loc) 88 translation = "datauriencoder_{0}".format(loc)
87 translator = QTranslator(None) 89 translator = QTranslator(None)
88 loaded = translator.load(translation, locale_dir) 90 loaded = translator.load(translation, locale_dir)
89 if loaded: 91 if loaded:
90 self.__translator = translator 92 self.__translator = translator
91 e5App().installTranslator(self.__translator) 93 ericApp().installTranslator(self.__translator)
92 else: 94 else:
93 print("Warning: translation file '{0}' could not be" 95 print("Warning: translation file '{0}' could not be"
94 " loaded.".format(translation)) 96 " loaded.".format(translation))
95 print("Using default.") 97 print("Using default.")
96 98
97 def __initAction(self): 99 def __initAction(self):
98 """ 100 """
99 Private method to initialize the action. 101 Private method to initialize the action.
100 """ 102 """
101 self.__action = E5Action( 103 self.__action = EricAction(
102 self.tr('Base64 Data Uri Encoder Wizard'), 104 self.tr('Base64 Data Uri Encoder Wizard'),
103 self.tr('Base&64 Data Uri Encoder Wizard...'), 105 self.tr('Base&64 Data Uri Encoder Wizard...'),
104 0, 0, self, 106 0, 0, self,
105 'wizards_datauriencoder') 107 'wizards_datauriencoder')
106 self.__action.setStatusTip(self.tr( 108 self.__action.setStatusTip(self.tr(
110 """<p>This wizard opens a dialog for entering all the parameters""" 112 """<p>This wizard opens a dialog for entering all the parameters"""
111 """ needed to create code for a base64 encoded data URI.</p>""" 113 """ needed to create code for a base64 encoded data URI.</p>"""
112 )) 114 ))
113 self.__action.triggered.connect(self.__handle) 115 self.__action.triggered.connect(self.__handle)
114 116
115 self.__ui.addE5Actions([self.__action], 'wizards') 117 self.__ui.addEricActions([self.__action], 'wizards')
116 118
117 def __initMenu(self): 119 def __initMenu(self):
118 """ 120 """
119 Private method to add the actions to the right menu. 121 Private method to add the actions to the right menu.
120 """ 122 """
124 126
125 def __handle(self): 127 def __handle(self):
126 """ 128 """
127 Private method to handle the wizards action. 129 Private method to handle the wizards action.
128 """ 130 """
129 editor = e5App().getObject("ViewManager").activeWindow() 131 editor = ericApp().getObject("ViewManager").activeWindow()
130 132
131 if editor is None: 133 if editor is None:
132 E5MessageBox.critical( 134 EricMessageBox.critical(
133 self.__ui, 135 self.__ui,
134 self.tr('No current editor'), 136 self.tr('No current editor'),
135 self.tr('Please open or create a file first.')) 137 self.tr('Please open or create a file first.'))
136 else: 138 else:
137 from WizardDataUriEncoder.DataUriEncoderWizardDialog import ( 139 from WizardDataUriEncoder.DataUriEncoderWizardDialog import (
138 DataUriEncoderWizardDialog 140 DataUriEncoderWizardDialog
139 ) 141 )
140 dlg = DataUriEncoderWizardDialog(None) 142 dlg = DataUriEncoderWizardDialog(None)
141 if dlg.exec() == QDialog.Accepted: 143 if dlg.exec() == QDialog.DialogCode.Accepted:
142 code = dlg.getCode() 144 code = dlg.getCode()
143 if code: 145 if code:
144 line, index = editor.getCursorPosition() 146 line, index = editor.getCursorPosition()
145 # It should be done on this way to allow undo 147 # It should be done on this way to allow undo
146 editor.beginUndoAction() 148 editor.beginUndoAction()

eric ide

mercurial