Plugins/PluginWizardEricPlugin.py

Sat, 03 Feb 2018 10:45:52 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 03 Feb 2018 10:45:52 +0100
branch
maintenance
changeset 6103
55bb39334322
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
permissions
-rw-r--r--

Fixed a situation in the tabview view manager that could cause a traceback.
(grafted from a5b9f6a38fafcd549914bc8d8cdc1b4e44602b01)

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
6048
82ad8ec9548c Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6016
diff changeset
3 # Copyright (c) 2014 - 2018 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 from __future__ import unicode_literals
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 try:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 str = unicode # __IGNORE_EXCEPTION__
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 except NameError:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 pass
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 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
17
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 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
19 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
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 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
22 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
23 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
24
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 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
26
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 # 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
28 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
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36 longDescription = \
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """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
38 """ 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
39 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
40 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
41 python2Compatible = True
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 # 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
43
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 error = ""
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
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 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
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 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
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 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
52 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 Constructor
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 @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
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 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
58 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
59 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
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 __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
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 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
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 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
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 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
68 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 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
70
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @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
72 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 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
74 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
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 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
77
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 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
79 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 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
81 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83 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
84 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
85 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
86
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 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
88 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 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
90 """
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 = E5Action(
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 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
93 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
94 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
95 '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
96 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
97 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
98 """<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
99 """<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
100 """ 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
101 """ 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
102 """ 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
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 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
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 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
107
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 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
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 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
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 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
113 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
114 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
115
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 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
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 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
119
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 @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
121 @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
122 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
123 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 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
125 PluginWizardDialog
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 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
127 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
128 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
129 else:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 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
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 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
133 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 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
135 """
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 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
137
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 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
139 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
140 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
141 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
142 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
143 else:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 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
145 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
146 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
147 # 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
148 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
149 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
150 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
151 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
152 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
153
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 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
155 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
156 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
157 packageName)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 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
159 try:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 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
161 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
162 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
163 self,
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 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
165 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
166 """<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
167 """ 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
168 """</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
169 .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
170 return
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 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
172 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
173 try:
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 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
175 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
176 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
177 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
178 self,
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 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
180 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
181 """<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
182 """ 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
183 """<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
184 .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
185 return
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 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
187 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
188 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
189 packageFile)
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 #
3d594f66a7f7 Added the eric plug-in wizard plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 # eflag: noqa = M801

eric ide

mercurial