Plugins/PluginWizardDotDesktop.py

changeset 6017
dab01678626d
child 6048
82ad8ec9548c
equal deleted inserted replaced
6016:3d594f66a7f7 6017:dab01678626d
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2013 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the .desktop wizard plug-in.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import QObject
13 from PyQt5.QtWidgets import QDialog
14
15 from E5Gui.E5Application import e5App
16 from E5Gui.E5Action import E5Action
17 from E5Gui import E5MessageBox
18
19 import UI.Info
20
21 # Start-of-Header
22 name = ".desktop Wizard Plug-in"
23 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
24 autoactivate = True
25 deactivateable = True
26 version = UI.Info.VersionOnly
27 className = "DotDesktopWizard"
28 packageName = "__core__"
29 shortDescription = "Wizard for the creation of a .desktop file."
30 longDescription = \
31 """This plug-in implements a wizard to generate code for""" \
32 """ a .desktop file."""
33 needsRestart = False
34 pyqtApi = 2
35 python2Compatible = True
36 # End-of-Header
37
38 error = ""
39
40
41 class DotDesktopWizard(QObject):
42 """
43 Class implementing the .desktop wizard plug-in.
44 """
45 def __init__(self, ui):
46 """
47 Constructor
48
49 @param ui reference to the user interface object (UI.UserInterface)
50 """
51 super(DotDesktopWizard, self).__init__(ui)
52 self.__ui = ui
53 self.__action = None
54
55 def __initialize(self):
56 """
57 Private slot to (re)initialize the plug-in.
58 """
59 self.__act = None
60
61 def activate(self):
62 """
63 Public method to activate this plug-in.
64
65 @return tuple of None and activation status (boolean)
66 """
67 self.__initAction()
68 self.__initMenu()
69
70 return None, True
71
72 def deactivate(self):
73 """
74 Public method to deactivate this plug-in.
75 """
76 menu = self.__ui.getMenu("wizards")
77 if menu:
78 menu.removeAction(self.__action)
79 self.__ui.removeE5Actions([self.__action], 'wizards')
80
81 def __initAction(self):
82 """
83 Private method to initialize the action.
84 """
85 self.__action = E5Action(
86 self.tr('.desktop Wizard'),
87 self.tr('.&desktop Wizard...'),
88 0, 0, self,
89 'wizards_dotdesktop')
90 self.__action.setStatusTip(self.tr('.desktop Wizard'))
91 self.__action.setWhatsThis(self.tr(
92 """<b>.desktop Wizard</b>"""
93 """<p>This wizard opens a dialog for entering all the parameters"""
94 """ needed to create the contents of a .desktop file. The"""
95 """ generated code replaces the text of the current editor."""
96 """ Alternatively a new editor is opened.</p>"""
97 ))
98 self.__action.triggered.connect(self.__handle)
99
100 self.__ui.addE5Actions([self.__action], 'wizards')
101
102 def __initMenu(self):
103 """
104 Private method to add the actions to the right menu.
105 """
106 menu = self.__ui.getMenu("wizards")
107 if menu:
108 menu.addAction(self.__action)
109
110 def __handle(self):
111 """
112 Private method to handle the wizards action.
113 """
114 editor = e5App().getObject("ViewManager").activeWindow()
115
116 if editor is None:
117 E5MessageBox.critical(
118 self.__ui,
119 self.tr('No current editor'),
120 self.tr('Please open or create a file first.'))
121 else:
122 if editor.text():
123 ok = E5MessageBox.yesNo(
124 self.__ui,
125 self.tr(".desktop Wizard"),
126 self.tr("""The current editor contains text."""
127 """ Shall this be replaced?"""),
128 icon=E5MessageBox.Critical)
129 if not ok:
130 e5App().getObject("ViewManager").newEditor()
131 editor = e5App().getObject("ViewManager").activeWindow()
132
133 from WizardPlugins.DotDesktopWizard.DotDesktopWizardDialog import \
134 DotDesktopWizardDialog
135 dlg = DotDesktopWizardDialog(None)
136 if dlg.exec_() == QDialog.Accepted:
137 code = dlg.getCode()
138 if code:
139 editor.selectAll()
140 # It should be done on this way to allow undo
141 editor.beginUndoAction()
142 editor.replaceSelectedText(code)
143 editor.endUndoAction()
144
145 editor.setLanguage("dummy.desktop")
146
147 #
148 # eflag: noqa = M801

eric ide

mercurial