eric6/Plugins/PluginWizardEricPlugin.py

Sun, 22 Nov 2020 16:04:59 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 22 Nov 2020 16:04:59 +0100
changeset 7836
2f0d208b8137
parent 7785
9978016560ec
child 7923
91e843545d9a
permissions
-rw-r--r--

Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.

6016
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
3 # Copyright (c) 2014 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
6016
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the eric plug-in wizard plug-in.
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt5.QtCore import QObject
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt5.QtWidgets import QDialog
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from E5Gui.E5Application import e5App
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from E5Gui.E5Action import E5Action
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui import E5MessageBox
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 import UI.Info
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 # Start-of-Header
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 name = "eric plug-in Wizard Plug-in"
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 autoactivate = True
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 deactivateable = True
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 version = UI.Info.VersionOnly
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 className = "WizardEricPluginWizard"
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 packageName = "__core__"
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 shortDescription = "Wizard for the creation of an eric plug-in file."
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
30 longDescription = (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
31 """This plug-in implements a wizard to generate code for"""
6016
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """ an eric plug-in main script file."""
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
33 )
6016
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 needsRestart = False
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 pyqtApi = 2
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 # End-of-Header
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 error = ""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 class WizardEricPluginWizard(QObject):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Class implementing the eric plug-in wizard plug-in.
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 def __init__(self, ui):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Constructor
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param ui reference to the user interface object (UI.UserInterface)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 super(WizardEricPluginWizard, self).__init__(ui)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__ui = ui
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.__action = None
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 def __initialize(self):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 Private slot to (re)initialize the plug-in.
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__act = None
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 def activate(self):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 Public method to activate this plug-in.
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @return tuple of None and activation status (boolean)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.__initAction()
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.__initMenu()
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 return None, True
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 def deactivate(self):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 Public method to deactivate this plug-in.
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 menu = self.__ui.getMenu("wizards")
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 if menu:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 menu.removeAction(self.__action)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.__ui.removeE5Actions([self.__action], 'wizards')
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 def __initAction(self):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 Private method to initialize the action.
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.__action = E5Action(
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.tr('eric Plug-in Wizard'),
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.tr('&eric Plug-in Wizard...'),
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 0, 0, self,
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 'wizards_eric_plugin')
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.__action.setStatusTip(self.tr('eric Plug-in Wizard'))
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.__action.setWhatsThis(self.tr(
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """<b>eric Plug-in Wizard</b>"""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """<p>This wizard opens a dialog for entering all the parameters"""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """ needed to create the basic contents of an eric plug-in file."""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """ The generated code is inserted at the current cursor"""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """ position.</p>"""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 ))
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.__action.triggered.connect(self.__handle)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.__ui.addE5Actions([self.__action], 'wizards')
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 def __initMenu(self):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 Private method to add the actions to the right menu.
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 menu = self.__ui.getMenu("wizards")
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 if menu:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 menu.addAction(self.__action)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 def __callForm(self, editor):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 Private method to display a dialog and get the code.
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @param editor reference to the current editor
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @return generated code (string), the plug-in package name (string)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 and a flag indicating success (boolean)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
118 from WizardPlugins.EricPluginWizard.PluginWizardDialog import (
6016
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 PluginWizardDialog
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
120 )
6016
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 dlg = PluginWizardDialog(None)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
122 if dlg.exec() == QDialog.Accepted:
6016
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 return (dlg.getCode(), dlg.packageName(), True)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 else:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 return (None, "", False)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 def __handle(self):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 Private method to handle the wizards action.
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 editor = e5App().getObject("ViewManager").activeWindow()
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 if editor is None:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 E5MessageBox.critical(
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 self.__ui,
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 self.tr('No current editor'),
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 self.tr('Please open or create a file first.'))
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 else:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 code, packageName, ok = self.__callForm(editor)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 if ok:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 line, index = editor.getCursorPosition()
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 # It should be done on this way to allow undo
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 editor.beginUndoAction()
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 editor.insertAt(code, line, index)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 editor.endUndoAction()
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 if not editor.getFileName():
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 editor.setLanguage("dummy.py")
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 if packageName:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 project = e5App().getObject("Project")
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 packagePath = os.path.join(project.getProjectPath(),
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 packageName)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 if not os.path.exists(packagePath):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 try:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 os.mkdir(packagePath)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 except OSError as err:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 E5MessageBox.critical(
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self,
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 self.tr("Create Package"),
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.tr(
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 """<p>The package directory <b>{0}</b>"""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 """ could not be created. Aborting..."""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 """</p><p>Reason: {1}</p>""")
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 .format(packagePath, str(err)))
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 return
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 packageFile = os.path.join(packagePath, "__init__.py")
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 if not os.path.exists(packageFile):
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 try:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
169 with open(packageFile, "w", encoding="utf-8"):
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
170 pass
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
171 except OSError as err:
6016
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 E5MessageBox.critical(
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 self,
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 self.tr("Create Package"),
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 self.tr(
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """<p>The package file <b>{0}</b> could"""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 """ not be created. Aborting...</p>"""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 """<p>Reason: {1}</p>""")
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 .format(packageFile, str(err)))
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 return
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 project.appendFile(packageFile)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 project.saveProject()
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 e5App().getObject("ViewManager").openSourceFile(
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 packageFile)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 #
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 # eflag: noqa = M801

eric ide

mercurial