22 |
22 |
23 def __readShortcut(act, category, prefClass): |
23 def __readShortcut(act, category, prefClass): |
24 """ |
24 """ |
25 Private function to read a single keyboard shortcut from the settings. |
25 Private function to read a single keyboard shortcut from the settings. |
26 |
26 |
27 @param act reference to the action object (EricAction) |
27 @param act reference to the action object |
28 @param category category the action belongs to (string) |
28 @type EricAction |
|
29 @param category category the action belongs to |
|
30 @type str |
29 @param prefClass preferences class used as the storage area |
31 @param prefClass preferences class used as the storage area |
|
32 @type Prefs |
30 """ |
33 """ |
31 if act.objectName(): |
34 if act.objectName(): |
32 accel = prefClass.settings.value( |
35 accel = prefClass.settings.value( |
33 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName()) |
36 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName()) |
34 ) |
37 ) |
39 ) |
42 ) |
40 if accel is not None: |
43 if accel is not None: |
41 act.setAlternateShortcut(QKeySequence(accel), removeEmpty=True) |
44 act.setAlternateShortcut(QKeySequence(accel), removeEmpty=True) |
42 |
45 |
43 |
46 |
44 def readShortcuts(prefClass=Prefs, helpViewer=None, pluginName=None): |
47 def readShortcuts(prefClass=Prefs, webBrowser=None, pluginName=None): |
45 """ |
48 """ |
46 Module function to read the keyboard shortcuts for the defined QActions. |
49 Module function to read the keyboard shortcuts for the defined QActions. |
47 |
50 |
48 @param prefClass preferences class used as the storage area |
51 @param prefClass preferences class used as the storage area |
49 @param helpViewer reference to the help window object |
52 @type Prefs |
|
53 @param webBrowser reference to the web browser window object |
|
54 @type WebBrowserWindow |
50 @param pluginName name of the plugin for which to load shortcuts |
55 @param pluginName name of the plugin for which to load shortcuts |
51 (string) |
56 @type str |
52 """ |
57 """ |
53 if helpViewer is None and pluginName is None: |
58 if webBrowser is None and pluginName is None: |
54 for act in ericApp().getObject("Project").getActions(): |
59 for act in ericApp().getObject("Project").getActions(): |
55 __readShortcut(act, "Project", prefClass) |
60 __readShortcut(act, "Project", prefClass) |
56 |
61 |
57 for act in ericApp().getObject("UserInterface").getActions("ui"): |
62 for act in ericApp().getObject("UserInterface").getActions("ui"): |
58 __readShortcut(act, "General", prefClass) |
63 __readShortcut(act, "General", prefClass) |
93 if hasattr(ref, "getActions"): |
98 if hasattr(ref, "getActions"): |
94 actions = ref.getActions() |
99 actions = ref.getActions() |
95 for act in actions: |
100 for act in actions: |
96 __readShortcut(act, category, prefClass) |
101 __readShortcut(act, category, prefClass) |
97 |
102 |
98 if helpViewer is not None: |
103 if webBrowser is not None: |
99 helpViewerCategory = helpViewer.getActionsCategory() |
104 webBrowserCategory = webBrowser.getActionsCategory() |
100 for act in helpViewer.getActions(): |
105 for act in webBrowser.getActions(): |
101 __readShortcut(act, helpViewerCategory, prefClass) |
106 __readShortcut(act, webBrowserCategory, prefClass) |
102 |
107 |
103 if pluginName is not None: |
108 if pluginName is not None: |
104 with contextlib.suppress(KeyError): |
109 with contextlib.suppress(KeyError): |
105 ref = ericApp().getPluginObject(pluginName) |
110 ref = ericApp().getPluginObject(pluginName) |
106 if hasattr(ref, "getActions"): |
111 if hasattr(ref, "getActions"): |
111 |
116 |
112 def __saveShortcut(act, category, prefClass): |
117 def __saveShortcut(act, category, prefClass): |
113 """ |
118 """ |
114 Private function to write a single keyboard shortcut to the settings. |
119 Private function to write a single keyboard shortcut to the settings. |
115 |
120 |
116 @param act reference to the action object (EricAction) |
121 @param act reference to the action object |
117 @param category category the action belongs to (string) |
122 @type EricAction |
|
123 @param category category the action belongs to |
|
124 @type str |
118 @param prefClass preferences class used as the storage area |
125 @param prefClass preferences class used as the storage area |
|
126 @type Prefs |
119 """ |
127 """ |
120 if act.objectName(): |
128 if act.objectName(): |
121 prefClass.settings.setValue( |
129 prefClass.settings.setValue( |
122 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName()), |
130 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName()), |
123 act.shortcut().toString(), |
131 act.shortcut().toString(), |
126 "Shortcuts/{0}/{1}/AltAccel".format(category, act.objectName()), |
134 "Shortcuts/{0}/{1}/AltAccel".format(category, act.objectName()), |
127 act.alternateShortcut().toString(), |
135 act.alternateShortcut().toString(), |
128 ) |
136 ) |
129 |
137 |
130 |
138 |
131 def saveShortcuts(prefClass=Prefs, helpViewer=None): |
139 def saveShortcuts(prefClass=Prefs, webBrowser=None): |
132 """ |
140 """ |
133 Module function to write the keyboard shortcuts for the defined QActions. |
141 Module function to write the keyboard shortcuts for the defined QActions. |
134 |
142 |
135 @param prefClass preferences class used as the storage area |
143 @param prefClass preferences class used as the storage area |
136 @param helpViewer reference to the help window object |
144 @type Prefs |
137 """ |
145 @param webBrowser reference to the web browser window object |
138 if helpViewer is None: |
146 @type WebBrowserWindow |
|
147 """ |
|
148 if webBrowser is None: |
139 # step 1: clear all previously saved shortcuts |
149 # step 1: clear all previously saved shortcuts |
140 prefClass.settings.beginGroup("Shortcuts") |
150 prefClass.settings.beginGroup("Shortcuts") |
141 prefClass.settings.remove("") |
151 prefClass.settings.remove("") |
142 prefClass.settings.endGroup() |
152 prefClass.settings.endGroup() |
143 |
153 |
185 actions = ref.getActions() |
195 actions = ref.getActions() |
186 for act in actions: |
196 for act in actions: |
187 __saveShortcut(act, category, prefClass) |
197 __saveShortcut(act, category, prefClass) |
188 |
198 |
189 else: |
199 else: |
190 helpViewerCategory = helpViewer.getActionsCategory() |
200 webBrowserCategory = webBrowser.getActionsCategory() |
191 |
201 |
192 # step 1: clear all previously saved shortcuts |
202 # step 1: clear all previously saved shortcuts |
193 prefClass.settings.beginGroup("Shortcuts/{0}".format(helpViewerCategory)) |
203 prefClass.settings.beginGroup("Shortcuts/{0}".format(webBrowserCategory)) |
194 prefClass.settings.remove("") |
204 prefClass.settings.remove("") |
195 prefClass.settings.endGroup() |
205 prefClass.settings.endGroup() |
196 |
206 |
197 # step 2: save the shortcuts |
207 # step 2: save the shortcuts |
198 for act in helpViewer.getActions(): |
208 for act in webBrowser.getActions(): |
199 __saveShortcut(act, helpViewerCategory, prefClass) |
209 __saveShortcut(act, webBrowserCategory, prefClass) |
200 |
210 |
201 |
211 |
202 def exportShortcuts(fn, helpViewer=None): |
212 def exportShortcuts(fn, helpViewer=None): |
203 """ |
213 """ |
204 Module function to export the keyboard shortcuts for the defined QActions. |
214 Module function to export the keyboard shortcuts for the defined QActions. |