eric6/Plugins/PluginWizardEricPlugin.py

Tue, 10 Sep 2019 19:30:07 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 10 Sep 2019 19:30:07 +0200
changeset 7229
53054eb5b15a
parent 7199
c71bd6f21748
child 7256
4ef3b78ebb4e
permissions
-rw-r--r--

Removed obsolete "from __future__ import ..." statements.

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
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
3 # Copyright (c) 2014 - 2019 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
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 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
12
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.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
14 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
15
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.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
17 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
18 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
19
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 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
21
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 # 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
23 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
24 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
25 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
26 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
27 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
28 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
29 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
30 shortDescription = "Wizard for the creation 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
31 longDescription = \
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """This plug-in implements a wizard to generate code for""" \
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """ an eric plug-in main script file."""
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 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 from WizardPlugins.EricPluginWizard.PluginWizardDialog import \
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
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 dlg = PluginWizardDialog(None)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 if dlg.exec_() == QDialog.Accepted:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 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
123 else:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 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
125
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 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
127 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 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
129 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 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
131
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 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
133 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
134 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
135 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
136 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
137 else:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 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
139 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
140 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
141 # 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
142 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
143 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
144 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
145 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
146 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
147
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 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
149 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
150 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
151 packageName)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 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
153 try:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 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
155 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
156 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
157 self,
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.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
159 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
160 """<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
161 """ 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
162 """</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
163 .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
164 return
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 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
166 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
167 try:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 f = open(packageFile, "w", encoding="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
169 f.close()
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 except IOError 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
171 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
172 self,
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.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
174 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
175 """<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
176 """ 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
177 """<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
178 .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
179 return
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 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
181 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
182 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
183 packageFile)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184
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 # eflag: noqa = M801

eric ide

mercurial