|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a stand alone shell window. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import QCoreApplication, QPoint, QSize, QSignalMapper |
|
13 from PyQt5.QtGui import QKeySequence |
|
14 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QAction, \ |
|
15 QWhatsThis |
|
16 from PyQt5.Qsci import QsciScintilla |
|
17 |
|
18 from E5Gui.E5MainWindow import E5MainWindow |
|
19 from E5Gui.E5Action import E5Action, createActionGroup |
|
20 from E5Gui.E5Application import e5App |
|
21 from E5Gui.E5ZoomWidget import E5ZoomWidget |
|
22 from E5Gui import E5MessageBox |
|
23 |
|
24 import UI.PixmapCache |
|
25 import Preferences |
|
26 |
|
27 from Globals import isMacPlatform |
|
28 |
|
29 from .Shell import Shell |
|
30 from .APIsManager import APIsManager |
|
31 |
|
32 from Debugger.DebugServer import DebugServer |
|
33 from UI.SearchWidget import SearchWidget |
|
34 |
|
35 |
|
36 class ShellWindow(E5MainWindow): |
|
37 """ |
|
38 Class implementing a stand alone shell window. |
|
39 """ |
|
40 def __init__(self, parent=None, name=None): |
|
41 """ |
|
42 Constructor |
|
43 |
|
44 @param parent reference to the parent widget |
|
45 @type QWidget |
|
46 @param name object name of the window |
|
47 @type str |
|
48 """ |
|
49 super(ShellWindow, self).__init__(parent) |
|
50 if name is not None: |
|
51 self.setObjectName(name) |
|
52 self.setWindowIcon(UI.PixmapCache.getIcon("shell.png")) |
|
53 |
|
54 self.setStyle(Preferences.getUI("Style"), |
|
55 Preferences.getUI("StyleSheet")) |
|
56 |
|
57 # initialize the APIs manager |
|
58 self.__apisManager = APIsManager(parent=self) |
|
59 |
|
60 # initialize the debug server and shell widgets |
|
61 self.__debugServer = DebugServer() |
|
62 self.__shell = Shell(self.__debugServer, self, True, self) |
|
63 self.__searchWidget = SearchWidget(self.__shell, self) |
|
64 |
|
65 centralWidget = QWidget() |
|
66 layout = QVBoxLayout() |
|
67 layout.setContentsMargins(1, 1, 1, 1) |
|
68 layout.addWidget(self.__shell) |
|
69 layout.addWidget(self.__searchWidget) |
|
70 centralWidget.setLayout(layout) |
|
71 self.setCentralWidget(centralWidget) |
|
72 self.__searchWidget.hide() |
|
73 |
|
74 |
|
75 self.__searchWidget.searchNext.connect(self.__shell.searchNext) |
|
76 self.__searchWidget.searchPrevious.connect(self.__shell.searchPrev) |
|
77 self.__shell.searchStringFound.connect( |
|
78 self.__searchWidget.searchStringFound) |
|
79 |
|
80 self.__shell.zoomValueChanged.connect(self.__zoomValueChanged) |
|
81 |
|
82 self.__createActions() |
|
83 ## self.__createMenus() |
|
84 ## self.__createToolBars() |
|
85 self.__createStatusBar() |
|
86 |
|
87 self.__readSettings() |
|
88 |
|
89 # now start the debug client |
|
90 self.__debugServer.startClient(False) |
|
91 |
|
92 # set the keyboard input interval |
|
93 interval = Preferences.getUI("KeyboardInputInterval") |
|
94 if interval > 0: |
|
95 QApplication.setKeyboardInputInterval(interval) |
|
96 |
|
97 def closeEvent(self, event): |
|
98 """ |
|
99 Protected method to handle the close event. |
|
100 |
|
101 @param event close event (QCloseEvent) |
|
102 """ |
|
103 self.__writeSettings() |
|
104 self.__debugServer.shutdownServer() |
|
105 self.__shell.closeShell() |
|
106 |
|
107 event.accept() |
|
108 |
|
109 ################################################################## |
|
110 ## Below are API handling methods |
|
111 ################################################################## |
|
112 |
|
113 def getAPIsManager(self): |
|
114 """ |
|
115 Public method to get a reference to the APIs manager. |
|
116 |
|
117 @return the APIs manager object (eric6.QScintilla.APIsManager) |
|
118 """ |
|
119 return self.__apisManager |
|
120 |
|
121 ################################################################## |
|
122 ## Below are action related methods |
|
123 ################################################################## |
|
124 |
|
125 def __readShortcut(self, act, category): |
|
126 """ |
|
127 Private function to read a single keyboard shortcut from the settings. |
|
128 |
|
129 @param act reference to the action object (E5Action) |
|
130 @param category category the action belongs to (string) |
|
131 """ |
|
132 if act.objectName(): |
|
133 accel = Preferences.Prefs.settings.value( |
|
134 "Shortcuts/{0}/{1}/Accel".format(category, act.objectName())) |
|
135 if accel is not None: |
|
136 act.setShortcut(QKeySequence(accel)) |
|
137 accel = Preferences.Prefs.settings.value( |
|
138 "Shortcuts/{0}/{1}/AltAccel".format( |
|
139 category, act.objectName())) |
|
140 if accel is not None: |
|
141 act.setAlternateShortcut(QKeySequence(accel), removeEmpty=True) |
|
142 |
|
143 def __createActions(self): |
|
144 """ |
|
145 Private method to create the actions. |
|
146 """ |
|
147 self.fileActions = [] |
|
148 self.editActions = [] |
|
149 self.searchActions = [] |
|
150 self.viewActions = [] |
|
151 self.helpActions = [] |
|
152 |
|
153 self.viewActGrp = createActionGroup(self) |
|
154 |
|
155 self.__createFileActions() |
|
156 self.__createEditActions() |
|
157 self.__createSearchActions() |
|
158 self.__createHelpActions() |
|
159 |
|
160 # read the keyboard shortcuts and make them identical to the main |
|
161 # eric6 shortcuts |
|
162 for act in self.helpActions: |
|
163 self.__readShortcut(act, "General") |
|
164 for act in self.editActions: |
|
165 self.__readShortcut(act, "Edit") |
|
166 for act in self.fileActions: |
|
167 self.__readShortcut(act, "View") |
|
168 for act in self.searchActions: |
|
169 self.__readShortcut(act, "Search") |
|
170 |
|
171 def __createFileActions(self): |
|
172 """ |
|
173 Private method defining the user interface actions for the file |
|
174 commands. |
|
175 """ |
|
176 self.exitAct = E5Action( |
|
177 self.tr('Quit'), |
|
178 UI.PixmapCache.getIcon("exit.png"), |
|
179 self.tr('&Quit'), |
|
180 QKeySequence(self.tr("Ctrl+Q", "File|Quit")), |
|
181 0, self, 'quit') |
|
182 self.exitAct.setStatusTip(self.tr('Quit the IDE')) |
|
183 self.exitAct.setWhatsThis(self.tr( |
|
184 """<b>Quit the Shell</b>""" |
|
185 """<p>This quits the Shell window.</p>""" |
|
186 )) |
|
187 self.exitAct.triggered.connect(self.quit) |
|
188 self.exitAct.setMenuRole(QAction.QuitRole) |
|
189 self.fileActions.append(self.exitAct) |
|
190 ## |
|
191 ## self.newWindowAct = E5Action( |
|
192 ## self.tr('New Window'), |
|
193 ## UI.PixmapCache.getIcon("newWindow.png"), |
|
194 ## self.tr('New &Window'), |
|
195 ## QKeySequence(self.tr("Ctrl+Shift+N", "File|New Window")), |
|
196 ## 0, self, 'new_window') |
|
197 ## self.newWindowAct.setStatusTip(self.tr( |
|
198 ## 'Open a new eric6 instance')) |
|
199 ## self.newWindowAct.setWhatsThis(self.tr( |
|
200 ## """<b>New Window</b>""" |
|
201 ## """<p>This opens a new instance of the eric6 IDE.</p>""" |
|
202 ## )) |
|
203 ## self.newWindowAct.triggered.connect(self.__newWindow) |
|
204 ## self.fileActions.append(self.newWindowAct) |
|
205 |
|
206 def __createEditActions(self): |
|
207 """ |
|
208 Private method defining the user interface actions for the edit |
|
209 commands. |
|
210 """ |
|
211 self.editActGrp = createActionGroup(self) |
|
212 self.copyActGrp = createActionGroup(self.editActGrp) |
|
213 |
|
214 self.cutAct = E5Action( |
|
215 QCoreApplication.translate('ViewManager', 'Cut'), |
|
216 UI.PixmapCache.getIcon("editCut.png"), |
|
217 QCoreApplication.translate('ViewManager', 'Cu&t'), |
|
218 QKeySequence(QCoreApplication.translate( |
|
219 'ViewManager', "Ctrl+X", "Edit|Cut")), |
|
220 QKeySequence(QCoreApplication.translate( |
|
221 'ViewManager', "Shift+Del", "Edit|Cut")), |
|
222 self.copyActGrp, 'vm_edit_cut') |
|
223 self.cutAct.setStatusTip(QCoreApplication.translate( |
|
224 'ViewManager', 'Cut the selection')) |
|
225 self.cutAct.setWhatsThis(QCoreApplication.translate( |
|
226 'ViewManager', |
|
227 """<b>Cut</b>""" |
|
228 """<p>Cut the selected text of the current editor to the""" |
|
229 """ clipboard.</p>""" |
|
230 )) |
|
231 self.cutAct.triggered.connect(self.__shell.cut) |
|
232 self.editActions.append(self.cutAct) |
|
233 |
|
234 self.copyAct = E5Action( |
|
235 QCoreApplication.translate('ViewManager', 'Copy'), |
|
236 UI.PixmapCache.getIcon("editCopy.png"), |
|
237 QCoreApplication.translate('ViewManager', '&Copy'), |
|
238 QKeySequence(QCoreApplication.translate( |
|
239 'ViewManager', "Ctrl+C", "Edit|Copy")), |
|
240 QKeySequence(QCoreApplication.translate( |
|
241 'ViewManager', "Ctrl+Ins", "Edit|Copy")), |
|
242 self.copyActGrp, 'vm_edit_copy') |
|
243 self.copyAct.setStatusTip(QCoreApplication.translate( |
|
244 'ViewManager', 'Copy the selection')) |
|
245 self.copyAct.setWhatsThis(QCoreApplication.translate( |
|
246 'ViewManager', |
|
247 """<b>Copy</b>""" |
|
248 """<p>Copy the selected text of the current editor to the""" |
|
249 """ clipboard.</p>""" |
|
250 )) |
|
251 self.copyAct.triggered.connect(self.__shell.copy) |
|
252 self.editActions.append(self.copyAct) |
|
253 |
|
254 self.pasteAct = E5Action( |
|
255 QCoreApplication.translate('ViewManager', 'Paste'), |
|
256 UI.PixmapCache.getIcon("editPaste.png"), |
|
257 QCoreApplication.translate('ViewManager', '&Paste'), |
|
258 QKeySequence(QCoreApplication.translate( |
|
259 'ViewManager', "Ctrl+V", "Edit|Paste")), |
|
260 QKeySequence(QCoreApplication.translate( |
|
261 'ViewManager', "Shift+Ins", "Edit|Paste")), |
|
262 self.copyActGrp, 'vm_edit_paste') |
|
263 self.pasteAct.setStatusTip(QCoreApplication.translate( |
|
264 'ViewManager', 'Paste the last cut/copied text')) |
|
265 self.pasteAct.setWhatsThis(QCoreApplication.translate( |
|
266 'ViewManager', |
|
267 """<b>Paste</b>""" |
|
268 """<p>Paste the last cut/copied text from the clipboard to""" |
|
269 """ the current editor.</p>""" |
|
270 )) |
|
271 self.pasteAct.triggered.connect(self.__shell.paste) |
|
272 self.editActions.append(self.pasteAct) |
|
273 |
|
274 self.deleteAct = E5Action( |
|
275 QCoreApplication.translate('ViewManager', 'Clear'), |
|
276 UI.PixmapCache.getIcon("editDelete.png"), |
|
277 QCoreApplication.translate('ViewManager', 'Clear'), |
|
278 QKeySequence(QCoreApplication.translate( |
|
279 'ViewManager', "Alt+Shift+C", "Edit|Clear")), |
|
280 0, |
|
281 self.copyActGrp, 'vm_edit_clear') |
|
282 self.deleteAct.setStatusTip(QCoreApplication.translate( |
|
283 'ViewManager', 'Clear all text')) |
|
284 self.deleteAct.setWhatsThis(QCoreApplication.translate( |
|
285 'ViewManager', |
|
286 """<b>Clear</b>""" |
|
287 """<p>Delete all text of the current editor.</p>""" |
|
288 )) |
|
289 self.deleteAct.triggered.connect(self.__shell.clear) |
|
290 self.editActions.append(self.deleteAct) |
|
291 |
|
292 self.cutAct.setEnabled(False) |
|
293 self.copyAct.setEnabled(False) |
|
294 self.__shell.copyAvailable.connect(self.cutAct.setEnabled) |
|
295 self.__shell.copyAvailable.connect(self.copyAct.setEnabled) |
|
296 |
|
297 #################################################################### |
|
298 ## Below follow the actions for QScintilla standard commands. |
|
299 #################################################################### |
|
300 |
|
301 self.esm = QSignalMapper(self) |
|
302 self.esm.mapped[int].connect(self.__shell.editorCommand) |
|
303 |
|
304 self.editorActGrp = createActionGroup(self) |
|
305 |
|
306 act = E5Action( |
|
307 QCoreApplication.translate('ViewManager', 'Delete current line'), |
|
308 QCoreApplication.translate('ViewManager', 'Delete current line'), |
|
309 QKeySequence(QCoreApplication.translate( |
|
310 'ViewManager', 'Ctrl+Shift+L')), |
|
311 0, |
|
312 self.editorActGrp, 'vm_edit_delete_current_line') |
|
313 self.esm.setMapping(act, QsciScintilla.SCI_LINEDELETE) |
|
314 act.triggered.connect(self.esm.map) |
|
315 self.editActions.append(act) |
|
316 |
|
317 act = E5Action( |
|
318 QCoreApplication.translate('ViewManager', 'Indent one level'), |
|
319 QCoreApplication.translate('ViewManager', 'Indent one level'), |
|
320 QKeySequence(QCoreApplication.translate('ViewManager', 'Tab')), 0, |
|
321 self.editorActGrp, 'vm_edit_indent_one_level') |
|
322 self.esm.setMapping(act, QsciScintilla.SCI_TAB) |
|
323 act.triggered.connect(self.esm.map) |
|
324 self.editActions.append(act) |
|
325 |
|
326 act = E5Action( |
|
327 QCoreApplication.translate('ViewManager', 'Insert new line'), |
|
328 QCoreApplication.translate('ViewManager', 'Insert new line'), |
|
329 QKeySequence(QCoreApplication.translate('ViewManager', 'Return')), |
|
330 QKeySequence(QCoreApplication.translate('ViewManager', 'Enter')), |
|
331 self.editorActGrp, 'vm_edit_insert_line') |
|
332 self.esm.setMapping(act, QsciScintilla.SCI_NEWLINE) |
|
333 act.triggered.connect(self.esm.map) |
|
334 self.editActions.append(act) |
|
335 |
|
336 act = E5Action( |
|
337 QCoreApplication.translate('ViewManager', |
|
338 'Delete previous character'), |
|
339 QCoreApplication.translate('ViewManager', |
|
340 'Delete previous character'), |
|
341 QKeySequence(QCoreApplication.translate('ViewManager', |
|
342 'Backspace')), |
|
343 0, self.editorActGrp, 'vm_edit_delete_previous_char') |
|
344 if isMacPlatform(): |
|
345 act.setAlternateShortcut(QKeySequence( |
|
346 QCoreApplication.translate('ViewManager', 'Meta+H'))) |
|
347 else: |
|
348 act.setAlternateShortcut(QKeySequence( |
|
349 QCoreApplication.translate('ViewManager', 'Shift+Backspace'))) |
|
350 self.esm.setMapping(act, QsciScintilla.SCI_DELETEBACK) |
|
351 act.triggered.connect(self.esm.map) |
|
352 self.editActions.append(act) |
|
353 |
|
354 act = E5Action( |
|
355 QCoreApplication.translate('ViewManager', |
|
356 'Delete current character'), |
|
357 QCoreApplication.translate('ViewManager', |
|
358 'Delete current character'), |
|
359 QKeySequence(QCoreApplication.translate('ViewManager', 'Del')), |
|
360 0, self.editorActGrp, 'vm_edit_delete_current_char') |
|
361 if isMacPlatform(): |
|
362 act.setAlternateShortcut(QKeySequence( |
|
363 QCoreApplication.translate('ViewManager', 'Meta+D'))) |
|
364 self.esm.setMapping(act, QsciScintilla.SCI_CLEAR) |
|
365 act.triggered.connect(self.esm.map) |
|
366 self.editActions.append(act) |
|
367 |
|
368 act = E5Action( |
|
369 QCoreApplication.translate('ViewManager', 'Delete word to left'), |
|
370 QCoreApplication.translate('ViewManager', 'Delete word to left'), |
|
371 QKeySequence(QCoreApplication.translate( |
|
372 'ViewManager', 'Ctrl+Backspace')), |
|
373 0, |
|
374 self.editorActGrp, 'vm_edit_delete_word_left') |
|
375 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDLEFT) |
|
376 act.triggered.connect(self.esm.map) |
|
377 self.editActions.append(act) |
|
378 |
|
379 act = E5Action( |
|
380 QCoreApplication.translate('ViewManager', 'Delete word to right'), |
|
381 QCoreApplication.translate('ViewManager', 'Delete word to right'), |
|
382 QKeySequence(QCoreApplication.translate('ViewManager', |
|
383 'Ctrl+Del')), |
|
384 0, self.editorActGrp, 'vm_edit_delete_word_right') |
|
385 self.esm.setMapping(act, QsciScintilla.SCI_DELWORDRIGHT) |
|
386 act.triggered.connect(self.esm.map) |
|
387 self.editActions.append(act) |
|
388 |
|
389 act = E5Action( |
|
390 QCoreApplication.translate('ViewManager', 'Delete line to left'), |
|
391 QCoreApplication.translate('ViewManager', 'Delete line to left'), |
|
392 QKeySequence(QCoreApplication.translate( |
|
393 'ViewManager', 'Ctrl+Shift+Backspace')), |
|
394 0, |
|
395 self.editorActGrp, 'vm_edit_delete_line_left') |
|
396 self.esm.setMapping(act, QsciScintilla.SCI_DELLINELEFT) |
|
397 act.triggered.connect(self.esm.map) |
|
398 self.editActions.append(act) |
|
399 |
|
400 act = E5Action( |
|
401 QCoreApplication.translate('ViewManager', 'Delete line to right'), |
|
402 QCoreApplication.translate('ViewManager', 'Delete line to right'), |
|
403 0, 0, |
|
404 self.editorActGrp, 'vm_edit_delete_line_right') |
|
405 if isMacPlatform(): |
|
406 act.setShortcut(QKeySequence( |
|
407 QCoreApplication.translate('ViewManager', 'Meta+K'))) |
|
408 else: |
|
409 act.setShortcut(QKeySequence( |
|
410 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Del'))) |
|
411 self.esm.setMapping(act, QsciScintilla.SCI_DELLINERIGHT) |
|
412 act.triggered.connect(self.esm.map) |
|
413 self.editActions.append(act) |
|
414 |
|
415 act = E5Action( |
|
416 QCoreApplication.translate('ViewManager', |
|
417 'Move left one character'), |
|
418 QCoreApplication.translate('ViewManager', |
|
419 'Move left one character'), |
|
420 QKeySequence(QCoreApplication.translate('ViewManager', 'Left')), 0, |
|
421 self.editorActGrp, 'vm_edit_move_left_char') |
|
422 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFT) |
|
423 if isMacPlatform(): |
|
424 act.setAlternateShortcut(QKeySequence( |
|
425 QCoreApplication.translate('ViewManager', 'Meta+B'))) |
|
426 act.triggered.connect(self.esm.map) |
|
427 self.editActions.append(act) |
|
428 |
|
429 act = E5Action( |
|
430 QCoreApplication.translate('ViewManager', |
|
431 'Move right one character'), |
|
432 QCoreApplication.translate('ViewManager', |
|
433 'Move right one character'), |
|
434 QKeySequence(QCoreApplication.translate('ViewManager', 'Right')), |
|
435 0, self.editorActGrp, 'vm_edit_move_right_char') |
|
436 if isMacPlatform(): |
|
437 act.setAlternateShortcut(QKeySequence( |
|
438 QCoreApplication.translate('ViewManager', 'Meta+F'))) |
|
439 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHT) |
|
440 act.triggered.connect(self.esm.map) |
|
441 self.editActions.append(act) |
|
442 |
|
443 act = E5Action( |
|
444 QCoreApplication.translate('ViewManager', 'Move left one word'), |
|
445 QCoreApplication.translate('ViewManager', 'Move left one word'), |
|
446 0, 0, |
|
447 self.editorActGrp, 'vm_edit_move_left_word') |
|
448 if isMacPlatform(): |
|
449 act.setShortcut(QKeySequence( |
|
450 QCoreApplication.translate('ViewManager', 'Alt+Left'))) |
|
451 else: |
|
452 act.setShortcut(QKeySequence( |
|
453 QCoreApplication.translate('ViewManager', 'Ctrl+Left'))) |
|
454 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFT) |
|
455 act.triggered.connect(self.esm.map) |
|
456 self.editActions.append(act) |
|
457 |
|
458 act = E5Action( |
|
459 QCoreApplication.translate('ViewManager', 'Move right one word'), |
|
460 QCoreApplication.translate('ViewManager', 'Move right one word'), |
|
461 0, 0, |
|
462 self.editorActGrp, 'vm_edit_move_right_word') |
|
463 if not isMacPlatform(): |
|
464 act.setShortcut(QKeySequence( |
|
465 QCoreApplication.translate('ViewManager', 'Ctrl+Right'))) |
|
466 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHT) |
|
467 act.triggered.connect(self.esm.map) |
|
468 self.editActions.append(act) |
|
469 |
|
470 act = E5Action( |
|
471 QCoreApplication.translate( |
|
472 'ViewManager', |
|
473 'Move to first visible character in document line'), |
|
474 QCoreApplication.translate( |
|
475 'ViewManager', |
|
476 'Move to first visible character in document line'), |
|
477 0, 0, |
|
478 self.editorActGrp, 'vm_edit_move_first_visible_char') |
|
479 if not isMacPlatform(): |
|
480 act.setShortcut(QKeySequence( |
|
481 QCoreApplication.translate('ViewManager', 'Home'))) |
|
482 self.esm.setMapping(act, QsciScintilla.SCI_VCHOME) |
|
483 act.triggered.connect(self.esm.map) |
|
484 self.editActions.append(act) |
|
485 |
|
486 act = E5Action( |
|
487 QCoreApplication.translate( |
|
488 'ViewManager', 'Move to end of document line'), |
|
489 QCoreApplication.translate( |
|
490 'ViewManager', 'Move to end of document line'), |
|
491 0, 0, |
|
492 self.editorActGrp, 'vm_edit_move_end_line') |
|
493 if isMacPlatform(): |
|
494 act.setShortcut(QKeySequence( |
|
495 QCoreApplication.translate('ViewManager', 'Meta+E'))) |
|
496 else: |
|
497 act.setShortcut(QKeySequence( |
|
498 QCoreApplication.translate('ViewManager', 'End'))) |
|
499 self.esm.setMapping(act, QsciScintilla.SCI_LINEEND) |
|
500 act.triggered.connect(self.esm.map) |
|
501 self.editActions.append(act) |
|
502 |
|
503 act = E5Action( |
|
504 QCoreApplication.translate('ViewManager', 'Move up one line'), |
|
505 QCoreApplication.translate('ViewManager', 'Move up one line'), |
|
506 QKeySequence(QCoreApplication.translate('ViewManager', 'Up')), 0, |
|
507 self.editorActGrp, 'vm_edit_move_up_line') |
|
508 if isMacPlatform(): |
|
509 act.setAlternateShortcut(QKeySequence( |
|
510 QCoreApplication.translate('ViewManager', 'Meta+P'))) |
|
511 self.esm.setMapping(act, QsciScintilla.SCI_LINEUP) |
|
512 act.triggered.connect(self.esm.map) |
|
513 self.editActions.append(act) |
|
514 |
|
515 act = E5Action( |
|
516 QCoreApplication.translate('ViewManager', 'Move down one line'), |
|
517 QCoreApplication.translate('ViewManager', 'Move down one line'), |
|
518 QKeySequence(QCoreApplication.translate('ViewManager', 'Down')), 0, |
|
519 self.editorActGrp, 'vm_edit_move_down_line') |
|
520 if isMacPlatform(): |
|
521 act.setAlternateShortcut(QKeySequence( |
|
522 QCoreApplication.translate('ViewManager', 'Meta+N'))) |
|
523 self.esm.setMapping(act, QsciScintilla.SCI_LINEDOWN) |
|
524 act.triggered.connect(self.esm.map) |
|
525 self.editActions.append(act) |
|
526 |
|
527 act = E5Action( |
|
528 QCoreApplication.translate('ViewManager', 'Move up one page'), |
|
529 QCoreApplication.translate('ViewManager', 'Move up one page'), |
|
530 QKeySequence(QCoreApplication.translate('ViewManager', 'PgUp')), 0, |
|
531 self.editorActGrp, 'vm_edit_move_up_page') |
|
532 self.esm.setMapping(act, QsciScintilla.SCI_PAGEUP) |
|
533 act.triggered.connect(self.esm.map) |
|
534 self.editActions.append(act) |
|
535 |
|
536 act = E5Action( |
|
537 QCoreApplication.translate('ViewManager', 'Move down one page'), |
|
538 QCoreApplication.translate('ViewManager', 'Move down one page'), |
|
539 QKeySequence(QCoreApplication.translate('ViewManager', 'PgDown')), |
|
540 0, self.editorActGrp, 'vm_edit_move_down_page') |
|
541 if isMacPlatform(): |
|
542 act.setAlternateShortcut(QKeySequence( |
|
543 QCoreApplication.translate('ViewManager', 'Meta+V'))) |
|
544 self.esm.setMapping(act, QsciScintilla.SCI_PAGEDOWN) |
|
545 act.triggered.connect(self.esm.map) |
|
546 self.editActions.append(act) |
|
547 |
|
548 act = E5Action( |
|
549 QCoreApplication.translate('ViewManager', 'Escape'), |
|
550 QCoreApplication.translate('ViewManager', 'Escape'), |
|
551 QKeySequence(QCoreApplication.translate('ViewManager', 'Esc')), 0, |
|
552 self.editorActGrp, 'vm_edit_escape') |
|
553 self.esm.setMapping(act, QsciScintilla.SCI_CANCEL) |
|
554 act.triggered.connect(self.esm.map) |
|
555 self.editActions.append(act) |
|
556 |
|
557 act = E5Action( |
|
558 QCoreApplication.translate( |
|
559 'ViewManager', 'Extend selection left one character'), |
|
560 QCoreApplication.translate( |
|
561 'ViewManager', 'Extend selection left one character'), |
|
562 QKeySequence(QCoreApplication.translate('ViewManager', |
|
563 'Shift+Left')), |
|
564 0, self.editorActGrp, 'vm_edit_extend_selection_left_char') |
|
565 if isMacPlatform(): |
|
566 act.setAlternateShortcut(QKeySequence( |
|
567 QCoreApplication.translate('ViewManager', 'Meta+Shift+B'))) |
|
568 self.esm.setMapping(act, QsciScintilla.SCI_CHARLEFTEXTEND) |
|
569 act.triggered.connect(self.esm.map) |
|
570 self.editActions.append(act) |
|
571 |
|
572 act = E5Action( |
|
573 QCoreApplication.translate( |
|
574 'ViewManager', 'Extend selection right one character'), |
|
575 QCoreApplication.translate( |
|
576 'ViewManager', 'Extend selection right one character'), |
|
577 QKeySequence(QCoreApplication.translate('ViewManager', |
|
578 'Shift+Right')), |
|
579 0, self.editorActGrp, 'vm_edit_extend_selection_right_char') |
|
580 if isMacPlatform(): |
|
581 act.setAlternateShortcut(QKeySequence( |
|
582 QCoreApplication.translate('ViewManager', 'Meta+Shift+F'))) |
|
583 self.esm.setMapping(act, QsciScintilla.SCI_CHARRIGHTEXTEND) |
|
584 act.triggered.connect(self.esm.map) |
|
585 self.editActions.append(act) |
|
586 |
|
587 act = E5Action( |
|
588 QCoreApplication.translate( |
|
589 'ViewManager', 'Extend selection left one word'), |
|
590 QCoreApplication.translate( |
|
591 'ViewManager', 'Extend selection left one word'), |
|
592 0, 0, |
|
593 self.editorActGrp, 'vm_edit_extend_selection_left_word') |
|
594 if isMacPlatform(): |
|
595 act.setShortcut(QKeySequence( |
|
596 QCoreApplication.translate('ViewManager', 'Alt+Shift+Left'))) |
|
597 else: |
|
598 act.setShortcut(QKeySequence( |
|
599 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Left'))) |
|
600 self.esm.setMapping(act, QsciScintilla.SCI_WORDLEFTEXTEND) |
|
601 act.triggered.connect(self.esm.map) |
|
602 self.editActions.append(act) |
|
603 |
|
604 act = E5Action( |
|
605 QCoreApplication.translate( |
|
606 'ViewManager', 'Extend selection right one word'), |
|
607 QCoreApplication.translate( |
|
608 'ViewManager', 'Extend selection right one word'), |
|
609 0, 0, |
|
610 self.editorActGrp, 'vm_edit_extend_selection_right_word') |
|
611 if isMacPlatform(): |
|
612 act.setShortcut(QKeySequence( |
|
613 QCoreApplication.translate('ViewManager', 'Alt+Shift+Right'))) |
|
614 else: |
|
615 act.setShortcut(QKeySequence( |
|
616 QCoreApplication.translate('ViewManager', 'Ctrl+Shift+Right'))) |
|
617 self.esm.setMapping(act, QsciScintilla.SCI_WORDRIGHTEXTEND) |
|
618 act.triggered.connect(self.esm.map) |
|
619 self.editActions.append(act) |
|
620 |
|
621 act = E5Action( |
|
622 QCoreApplication.translate( |
|
623 'ViewManager', |
|
624 'Extend selection to first visible character in document' |
|
625 ' line'), |
|
626 QCoreApplication.translate( |
|
627 'ViewManager', |
|
628 'Extend selection to first visible character in document' |
|
629 ' line'), |
|
630 0, 0, |
|
631 self.editorActGrp, 'vm_edit_extend_selection_first_visible_char') |
|
632 if not isMacPlatform(): |
|
633 act.setShortcut(QKeySequence( |
|
634 QCoreApplication.translate('ViewManager', 'Shift+Home'))) |
|
635 self.esm.setMapping(act, QsciScintilla.SCI_VCHOMEEXTEND) |
|
636 act.triggered.connect(self.esm.map) |
|
637 self.editActions.append(act) |
|
638 |
|
639 act = E5Action( |
|
640 QCoreApplication.translate( |
|
641 'ViewManager', 'Extend selection to end of document line'), |
|
642 QCoreApplication.translate( |
|
643 'ViewManager', 'Extend selection to end of document line'), |
|
644 0, 0, |
|
645 self.editorActGrp, 'vm_edit_extend_selection_end_line') |
|
646 if isMacPlatform(): |
|
647 act.setShortcut(QKeySequence( |
|
648 QCoreApplication.translate('ViewManager', 'Meta+Shift+E'))) |
|
649 else: |
|
650 act.setShortcut(QKeySequence( |
|
651 QCoreApplication.translate('ViewManager', 'Shift+End'))) |
|
652 self.esm.setMapping(act, QsciScintilla.SCI_LINEENDEXTEND) |
|
653 act.triggered.connect(self.esm.map) |
|
654 self.editActions.append(act) |
|
655 |
|
656 def __createSearchActions(self): |
|
657 """ |
|
658 Private method defining the user interface actions for the search |
|
659 commands. |
|
660 """ |
|
661 self.searchActGrp = createActionGroup(self) |
|
662 |
|
663 self.searchAct = E5Action( |
|
664 QCoreApplication.translate('ViewManager', 'Search'), |
|
665 UI.PixmapCache.getIcon("find.png"), |
|
666 QCoreApplication.translate('ViewManager', '&Search...'), |
|
667 QKeySequence(QCoreApplication.translate( |
|
668 'ViewManager', "Ctrl+F", "Search|Search")), |
|
669 0, |
|
670 self.searchActGrp, 'vm_search') |
|
671 self.searchAct.setStatusTip(QCoreApplication.translate( |
|
672 'ViewManager', 'Search for a text')) |
|
673 self.searchAct.setWhatsThis(QCoreApplication.translate( |
|
674 'ViewManager', |
|
675 """<b>Search</b>""" |
|
676 """<p>Search for some text in the current editor. A""" |
|
677 """ dialog is shown to enter the searchtext and options""" |
|
678 """ for the search.</p>""" |
|
679 )) |
|
680 self.searchAct.triggered.connect(self.__showFind) |
|
681 self.searchActions.append(self.searchAct) |
|
682 |
|
683 self.searchNextAct = E5Action( |
|
684 QCoreApplication.translate( |
|
685 'ViewManager', 'Search next'), |
|
686 UI.PixmapCache.getIcon("findNext.png"), |
|
687 QCoreApplication.translate('ViewManager', 'Search &next'), |
|
688 QKeySequence(QCoreApplication.translate( |
|
689 'ViewManager', "F3", "Search|Search next")), |
|
690 0, |
|
691 self.searchActGrp, 'vm_search_next') |
|
692 self.searchNextAct.setStatusTip(QCoreApplication.translate( |
|
693 'ViewManager', 'Search next occurrence of text')) |
|
694 self.searchNextAct.setWhatsThis(QCoreApplication.translate( |
|
695 'ViewManager', |
|
696 """<b>Search next</b>""" |
|
697 """<p>Search the next occurrence of some text in the current""" |
|
698 """ editor. The previously entered searchtext and options are""" |
|
699 """ reused.</p>""" |
|
700 )) |
|
701 self.searchNextAct.triggered.connect( |
|
702 self.__searchWidget.on_findNextButton_clicked) |
|
703 self.searchActions.append(self.searchNextAct) |
|
704 |
|
705 self.searchPrevAct = E5Action( |
|
706 QCoreApplication.translate('ViewManager', 'Search previous'), |
|
707 UI.PixmapCache.getIcon("findPrev.png"), |
|
708 QCoreApplication.translate('ViewManager', 'Search &previous'), |
|
709 QKeySequence(QCoreApplication.translate( |
|
710 'ViewManager', "Shift+F3", "Search|Search previous")), |
|
711 0, |
|
712 self.searchActGrp, 'vm_search_previous') |
|
713 self.searchPrevAct.setStatusTip(QCoreApplication.translate( |
|
714 'ViewManager', 'Search previous occurrence of text')) |
|
715 self.searchPrevAct.setWhatsThis(QCoreApplication.translate( |
|
716 'ViewManager', |
|
717 """<b>Search previous</b>""" |
|
718 """<p>Search the previous occurrence of some text in the current""" |
|
719 """ editor. The previously entered searchtext and options are""" |
|
720 """ reused.</p>""" |
|
721 )) |
|
722 self.searchPrevAct.triggered.connect( |
|
723 self.__searchWidget.on_findPrevButton_clicked) |
|
724 self.searchActions.append(self.searchPrevAct) |
|
725 |
|
726 def __createViewActions(self): |
|
727 """ |
|
728 Private method defining the user interface actions for the view |
|
729 commands. |
|
730 """ |
|
731 self.viewActGrp = createActionGroup(self) |
|
732 self.viewFoldActGrp = createActionGroup(self) |
|
733 |
|
734 self.zoomInAct = E5Action( |
|
735 QCoreApplication.translate('ViewManager', 'Zoom in'), |
|
736 UI.PixmapCache.getIcon("zoomIn.png"), |
|
737 QCoreApplication.translate('ViewManager', 'Zoom &in'), |
|
738 QKeySequence(QCoreApplication.translate( |
|
739 'ViewManager', "Ctrl++", "View|Zoom in")), |
|
740 QKeySequence(QCoreApplication.translate( |
|
741 'ViewManager', "Zoom In", "View|Zoom in")), |
|
742 self.viewActGrp, 'vm_view_zoom_in') |
|
743 self.zoomInAct.setStatusTip(QCoreApplication.translate( |
|
744 'ViewManager', 'Zoom in on the text')) |
|
745 self.zoomInAct.setWhatsThis(QCoreApplication.translate( |
|
746 'ViewManager', |
|
747 """<b>Zoom in</b>""" |
|
748 """<p>Zoom in on the text. This makes the text bigger.</p>""" |
|
749 )) |
|
750 self.zoomInAct.triggered.connect(self.__zoomIn) |
|
751 self.viewActions.append(self.zoomInAct) |
|
752 |
|
753 self.zoomOutAct = E5Action( |
|
754 QCoreApplication.translate('ViewManager', 'Zoom out'), |
|
755 UI.PixmapCache.getIcon("zoomOut.png"), |
|
756 QCoreApplication.translate('ViewManager', 'Zoom &out'), |
|
757 QKeySequence(QCoreApplication.translate( |
|
758 'ViewManager', "Ctrl+-", "View|Zoom out")), |
|
759 QKeySequence(QCoreApplication.translate( |
|
760 'ViewManager', "Zoom Out", "View|Zoom out")), |
|
761 self.viewActGrp, 'vm_view_zoom_out') |
|
762 self.zoomOutAct.setStatusTip(QCoreApplication.translate( |
|
763 'ViewManager', 'Zoom out on the text')) |
|
764 self.zoomOutAct.setWhatsThis(QCoreApplication.translate( |
|
765 'ViewManager', |
|
766 """<b>Zoom out</b>""" |
|
767 """<p>Zoom out on the text. This makes the text smaller.</p>""" |
|
768 )) |
|
769 self.zoomOutAct.triggered.connect(self.__zoomOut) |
|
770 self.viewActions.append(self.zoomOutAct) |
|
771 |
|
772 self.zoomResetAct = E5Action( |
|
773 QCoreApplication.translate('ViewManager', 'Zoom reset'), |
|
774 UI.PixmapCache.getIcon("zoomReset.png"), |
|
775 QCoreApplication.translate('ViewManager', 'Zoom &reset'), |
|
776 QKeySequence(QCoreApplication.translate( |
|
777 'ViewManager', "Ctrl+0", "View|Zoom reset")), |
|
778 0, |
|
779 self.viewActGrp, 'vm_view_zoom_reset') |
|
780 self.zoomResetAct.setStatusTip(QCoreApplication.translate( |
|
781 'ViewManager', 'Reset the zoom of the text')) |
|
782 self.zoomResetAct.setWhatsThis(QCoreApplication.translate( |
|
783 'ViewManager', |
|
784 """<b>Zoom reset</b>""" |
|
785 """<p>Reset the zoom of the text. """ |
|
786 """This sets the zoom factor to 100%.</p>""" |
|
787 )) |
|
788 self.zoomResetAct.triggered.connect(self.__zoomReset) |
|
789 self.viewActions.append(self.zoomResetAct) |
|
790 |
|
791 self.zoomToAct = E5Action( |
|
792 QCoreApplication.translate('ViewManager', 'Zoom'), |
|
793 UI.PixmapCache.getIcon("zoomTo.png"), |
|
794 QCoreApplication.translate('ViewManager', '&Zoom'), |
|
795 QKeySequence(QCoreApplication.translate( |
|
796 'ViewManager', "Ctrl+#", "View|Zoom")), |
|
797 0, |
|
798 self.viewActGrp, 'vm_view_zoom') |
|
799 self.zoomToAct.setStatusTip(QCoreApplication.translate( |
|
800 'ViewManager', 'Zoom the text')) |
|
801 self.zoomToAct.setWhatsThis(QCoreApplication.translate( |
|
802 'ViewManager', |
|
803 """<b>Zoom</b>""" |
|
804 """<p>Zoom the text. This opens a dialog where the""" |
|
805 """ desired size can be entered.</p>""" |
|
806 )) |
|
807 self.zoomToAct.triggered.connect(self.__zoom) |
|
808 self.viewActions.append(self.zoomToAct) |
|
809 |
|
810 def __createHelpActions(self): |
|
811 """ |
|
812 Private method to create the Help actions. |
|
813 """ |
|
814 self.aboutAct = E5Action( |
|
815 self.tr('About'), |
|
816 self.tr('&About'), |
|
817 0, 0, self, 'about_eric') |
|
818 self.aboutAct.setStatusTip(self.tr( |
|
819 'Display information about this software')) |
|
820 self.aboutAct.setWhatsThis(self.tr( |
|
821 """<b>About</b>""" |
|
822 """<p>Display some information about this software.</p>""")) |
|
823 self.aboutAct.triggered.connect(self.__about) |
|
824 self.helpActions.append(self.aboutAct) |
|
825 |
|
826 self.aboutQtAct = E5Action( |
|
827 self.tr('About Qt'), |
|
828 self.tr('About &Qt'), |
|
829 0, 0, self, 'about_qt') |
|
830 self.aboutQtAct.setStatusTip( |
|
831 self.tr('Display information about the Qt toolkit')) |
|
832 self.aboutQtAct.setWhatsThis(self.tr( |
|
833 """<b>About Qt</b>""" |
|
834 """<p>Display some information about the Qt toolkit.</p>""" |
|
835 )) |
|
836 self.aboutQtAct.triggered.connect(self.__aboutQt) |
|
837 self.helpActions.append(self.aboutQtAct) |
|
838 |
|
839 self.whatsThisAct = E5Action( |
|
840 self.tr('What\'s This?'), |
|
841 UI.PixmapCache.getIcon("whatsThis.png"), |
|
842 self.tr('&What\'s This?'), |
|
843 QKeySequence(self.tr("Shift+F1", "Help|What's This?'")), |
|
844 0, self, 'help_help_whats_this') |
|
845 self.whatsThisAct.setStatusTip(self.tr('Context sensitive help')) |
|
846 self.whatsThisAct.setWhatsThis(self.tr( |
|
847 """<b>Display context sensitive help</b>""" |
|
848 """<p>In What's This? mode, the mouse cursor shows an arrow""" |
|
849 """ with a question mark, and you can click on the interface""" |
|
850 """ elements to get a short description of what they do and""" |
|
851 """ how to use them. In dialogs, this feature can be""" |
|
852 """ accessed using the context help button in the titlebar.""" |
|
853 """</p>""" |
|
854 )) |
|
855 self.whatsThisAct.triggered.connect(self.__whatsThis) |
|
856 self.helpActions.append(self.whatsThisAct) |
|
857 |
|
858 def __showFind(self): |
|
859 """ |
|
860 Public method to display the search widget. |
|
861 """ |
|
862 self.__searchWidget.showFind("") |
|
863 |
|
864 def activeWindow(self): |
|
865 """ |
|
866 Public method to get a reference to the active shell. |
|
867 """ |
|
868 return self.__shell |
|
869 |
|
870 def __readSettings(self): |
|
871 """ |
|
872 Private method to read the settings remembered last time. |
|
873 """ |
|
874 settings = Preferences.Prefs.settings |
|
875 pos = settings.value("ShellWindow/Position", QPoint(0, 0)) |
|
876 size = settings.value("ShellWindow/Size", QSize(800, 600)) |
|
877 self.resize(size) |
|
878 self.move(pos) |
|
879 |
|
880 def __writeSettings(self): |
|
881 """ |
|
882 Private method to write the settings for reuse. |
|
883 """ |
|
884 settings = Preferences.Prefs.settings |
|
885 settings.setValue("ShellWindow/Position", self.pos()) |
|
886 settings.setValue("ShellWindow/Size", self.size()) |
|
887 |
|
888 def quit(self): |
|
889 """ |
|
890 Public method to quit the application. |
|
891 """ |
|
892 e5App().closeAllWindows() |
|
893 |
|
894 ################################################################## |
|
895 ## Below are the action methods for the view menu |
|
896 ################################################################## |
|
897 |
|
898 def __zoomIn(self): |
|
899 """ |
|
900 Private method to handle the zoom in action. |
|
901 """ |
|
902 self.__shell.zoomIn() |
|
903 self.__sbZoom.setValue(self.__shell.getZoom()) |
|
904 |
|
905 def __zoomOut(self): |
|
906 """ |
|
907 Private method to handle the zoom out action. |
|
908 """ |
|
909 self.__shell.zoomOut() |
|
910 self.__sbZoom.setValue(self.__shell.getZoom()) |
|
911 |
|
912 def __zoomReset(self): |
|
913 """ |
|
914 Private method to reset the zoom factor. |
|
915 """ |
|
916 self.__shell.zoomTo(0) |
|
917 self.__sbZoom.setValue(self.__shell.getZoom()) |
|
918 |
|
919 def __zoom(self): |
|
920 """ |
|
921 Private method to handle the zoom action. |
|
922 """ |
|
923 from QScintilla.ZoomDialog import ZoomDialog |
|
924 dlg = ZoomDialog(self.__shell.getZoom(), self, None, True) |
|
925 if dlg.exec_() == QDialog.Accepted: |
|
926 value = dlg.getZoomSize() |
|
927 self.__zoomTo(value) |
|
928 |
|
929 def __zoomTo(self, value): |
|
930 """ |
|
931 Private slot to zoom to a given value. |
|
932 |
|
933 @param value zoom value to be set (integer) |
|
934 """ |
|
935 self.__shell.zoomTo(value) |
|
936 self.__sbZoom.setValue(self.__shell.getZoom()) |
|
937 |
|
938 def __zoomValueChanged(self, value): |
|
939 """ |
|
940 Private slot to handle changes of the zoom value. |
|
941 |
|
942 @param value new zoom value (integer) |
|
943 """ |
|
944 self.__sbZoom.setValue(value) |
|
945 |
|
946 ################################################################## |
|
947 ## Below are the action methods for the help menu |
|
948 ################################################################## |
|
949 |
|
950 def __about(self): |
|
951 """ |
|
952 Private slot to show a little About message. |
|
953 """ |
|
954 # TODO: change this text |
|
955 E5MessageBox.about( |
|
956 self, |
|
957 self.tr("About eric6 Mini Editor"), |
|
958 self.tr( |
|
959 "The eric6 Mini Editor is an editor component" |
|
960 " based on QScintilla. It may be used for simple" |
|
961 " editing tasks, that don't need the power of" |
|
962 " a full blown editor.")) |
|
963 |
|
964 def __aboutQt(self): |
|
965 """ |
|
966 Private slot to handle the About Qt dialog. |
|
967 """ |
|
968 E5MessageBox.aboutQt(self, "eric6 Shell windindow") |
|
969 |
|
970 def __whatsThis(self): |
|
971 """ |
|
972 Private slot called in to enter Whats This mode. |
|
973 """ |
|
974 QWhatsThis.enterWhatsThisMode() |
|
975 |
|
976 ################################################################## |
|
977 ## Below are the status bar handling methods |
|
978 ################################################################## |
|
979 |
|
980 def __createStatusBar(self): |
|
981 """ |
|
982 Private slot to set up the status bar. |
|
983 """ |
|
984 self.__statusBar = self.statusBar() |
|
985 self.__statusBar.setSizeGripEnabled(True) |
|
986 |
|
987 self.__sbZoom = E5ZoomWidget( |
|
988 UI.PixmapCache.getPixmap("zoomOut.png"), |
|
989 UI.PixmapCache.getPixmap("zoomIn.png"), |
|
990 UI.PixmapCache.getPixmap("zoomReset.png"), |
|
991 self.__statusBar) |
|
992 self.__statusBar.addPermanentWidget(self.__sbZoom) |
|
993 self.__sbZoom.setWhatsThis(self.tr( |
|
994 """<p>This part of the status bar allows zooming the shell.</p>""" |
|
995 )) |
|
996 |
|
997 self.__sbZoom.valueChanged.connect(self.__zoomTo) |
|
998 self.__sbZoom.setValue(0) |