E5XML/ShortcutsWriter.py

Sat, 05 Jul 2014 11:41:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Jul 2014 11:41:14 +0200
changeset 3669
ac84ac3c0f05
parent 3178
f25fc1364c88
child 3670
f0cb7579c0b4
permissions
-rw-r--r--

Continued renaming eric5 for PyQt5 to eric6.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
3 # Copyright (c) 2004 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the writer class for writing an XML shortcuts file.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3058
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
11
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import time
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 53
diff changeset
14 from E5Gui.E5Application import e5App
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
16 from .XMLStreamWriterBase import XMLStreamWriterBase
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
17 from .Config import shortcutsFileFormatVersion
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 import Preferences
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
21
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
22 class ShortcutsWriter(XMLStreamWriterBase):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Class implementing the writer class for writing an XML shortcuts file.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
26 def __init__(self, device):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
30 @param device reference to the I/O device to write to (QIODevice)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
32 XMLStreamWriterBase.__init__(self, device)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.email = Preferences.getUser("Email")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 def writeXML(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Public method to write the XML to the file.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
40 XMLStreamWriterBase.writeXML(self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
42 self.writeDTD('<!DOCTYPE Shortcuts SYSTEM "Shortcuts-{0}.dtd">'.format(
411
99409cddaaa9 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
43 shortcutsFileFormatVersion))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 # add some generation comments
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
46 self.writeComment(" Eric5 keyboard shortcuts ")
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
47 self.writeComment(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
48 " Saved: {0}".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
49 self.writeComment(" Author: {0} ".format(self.email))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 # add the main tag
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
52 self.writeStartElement("Shortcuts")
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
53 self.writeAttribute("version", shortcutsFileFormatVersion)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
55 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
56 "Project",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
57 e5App().getObject("Project").getActions())
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
58 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
59 "General",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
60 e5App().getObject("UserInterface").getActions('ui'))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
61 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
62 "Wizards",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
63 e5App().getObject("UserInterface").getActions('wizards'))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
64 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
65 "Debug",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
66 e5App().getObject("DebugUI").getActions())
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
67 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
68 "Edit",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
69 e5App().getObject("ViewManager").getActions('edit'))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
70 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
71 "File",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
72 e5App().getObject("ViewManager").getActions('file'))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
73 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
74 "Search",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
75 e5App().getObject("ViewManager").getActions('search'))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
76 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
77 "View",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
78 e5App().getObject("ViewManager").getActions('view'))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
79 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
80 "Macro",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
81 e5App().getObject("ViewManager").getActions('macro'))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
82 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
83 "Bookmarks",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
84 e5App().getObject("ViewManager").getActions('bookmark'))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
85 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
86 "Spelling",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
87 e5App().getObject("ViewManager").getActions('spelling'))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
88 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
89 "Window",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
90 e5App().getObject("ViewManager").getActions('window'))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
53
c3eb7cc1ff8b Renamed e5App to e5App.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 50
diff changeset
92 for category, ref in e5App().getPluginObjects():
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 if hasattr(ref, "getActions"):
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
94 self.__writeActions(category, ref.getActions())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
96 self.__writeActions(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
97 "HelpViewer",
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
98 e5App().getObject("DummyHelpViewer").getActions())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 # add the main end tag
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
101 self.writeEndElement()
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
102 self.writeEndDocument()
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
103
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
104 def __writeActions(self, category, actions):
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
105 """
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
106 Private method to write the shortcuts for the given actions.
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
107
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
108 @param category category the actions belong to (string)
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
109 @param actions list of actions to write (E5Action)
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
110 """
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
111 for act in actions:
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
112 if act.objectName():
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
113 # shortcuts are only exported, if their objectName is set
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
114 self.writeStartElement("Shortcut")
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
115 self.writeAttribute("category", category)
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
116 self.writeTextElement("Name", act.objectName())
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
117 self.writeTextElement("Accel", act.shortcut().toString())
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
118 self.writeTextElement(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
119 "AltAccel", act.alternateShortcut().toString())
595
7d2c8346021c Migrated the shortcuts handler to shortcuts reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
120 self.writeEndElement()

eric ide

mercurial