QScintilla/Editor.py

Sun, 13 Oct 2013 12:21:37 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 13 Oct 2013 12:21:37 +0200
changeset 3011
18292228c724
parent 2994
5ae1349b8fb4
child 3020
542e97d4ecb3
child 3057
10516539f238
permissions
-rw-r--r--

Continued to shorten the code lines to max. 79 characters.

92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1 # -*- coding: utf-8 -*-
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2262
diff changeset
3 # Copyright (c) 2002 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4 #
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
7 Module implementing the editor component of the eric5 IDE.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
8 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
9 import os
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
10 import re
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
11 import difflib
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
12
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1106
diff changeset
13 from PyQt4.QtCore import QDir, QTimer, QModelIndex, QFileInfo, pyqtSignal, \
1768
8a04ce23e083 Fixed another issue with a multi-connected signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1762
diff changeset
14 pyqtSlot, QCryptographicHash, QEvent, QDateTime, QRegExp, Qt
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
15 from PyQt4.QtGui import QCursor, QPrinter, QPrintDialog, QLineEdit, \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
16 QActionGroup, QDialog, QAbstractPrintDialog, QInputDialog, QApplication, \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
17 QMenu, QPalette, QFont, QPixmap, QPainter
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1106
diff changeset
18 from PyQt4.Qsci import QsciScintilla, QsciMacro, QsciStyledText
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
19
2084
d3f083dd0222 Made the fiveth set of Qt5 compatibility changes (some of the previous changes are backed out due to changes in PyQt4).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2077
diff changeset
20 from E5Gui.E5Application import e5App
536
6d8d39753c82 Started replaceing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 535
diff changeset
21 from E5Gui import E5FileDialog, E5MessageBox
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
22
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
23 from .QsciScintillaCompat import QsciScintillaCompat, QSCINTILLA_VERSION
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
24
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
25 import Preferences
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
26 import Utilities
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
27
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
28 import UI.PixmapCache
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
29
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
30 EditorAutoCompletionListID = 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
31 TemplateCompletionListID = 2
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
32
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
33
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
34 class Editor(QsciScintillaCompat):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
35 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
36 Class implementing the editor component of the eric5 IDE.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
37
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
38 @signal modificationStatusChanged(bool, QsciScintillaCompat) emitted when
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
39 the modification status has changed
501
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
40 @signal undoAvailable(bool) emitted to signal the undo availability
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
41 @signal redoAvailable(bool) emitted to signal the redo availability
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
42 @signal cursorChanged(str, int, int) emitted when the cursor position
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
43 was changed
2768
eab35f6e709f Added support to show the current class/method name in the combo boxes at the top of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2659
diff changeset
44 @signal cursorLineChanged(int) emitted when the cursor line was changed
501
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
45 @signal editorAboutToBeSaved(str) emitted before the editor is saved
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
46 @signal editorSaved(str) emitted after the editor has been saved
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
47 @signal editorRenamed(str) emitted after the editor got a new name
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
48 (i.e. after a 'Save As')
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
49 @signal captionChanged(str, QsciScintillaCompat) emitted when the caption
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
50 is updated. Typically due to a readOnly attribute change.
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
51 @signal breakpointToggled(QsciScintillaCompat) emitted when a breakpoint
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
52 is toggled
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
53 @signal bookmarkToggled(QsciScintillaCompat) emitted when a bookmark is
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
54 toggled
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
55 @signal syntaxerrorToggled(QsciScintillaCompat) emitted when a syntax error
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
56 was discovered
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
57 @signal autoCompletionAPIsAvailable(bool) emitted after the autocompletion
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
58 function has been configured
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
59 @signal coverageMarkersShown(bool) emitted after the coverage markers have
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
60 been shown or cleared
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
61 @signal taskMarkersUpdated(QsciScintillaCompat) emitted when the task
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
62 markers were updated
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
63 @signal changeMarkersUpdated(QsciScintillaCompat) emitted when the change
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
64 markers were updated
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
65 @signal showMenu(str, QMenu, QsciScintillaCompat) emitted when a menu is
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
66 about to be shown. The name of the menu, a reference to the menu and
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
67 a reference to the editor are given.
501
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
68 @signal languageChanged(str) emitted when the editors language was set. The
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
69 language is passed as a parameter.
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
70 @signal eolChanged(str) emitted when the editors eol type was set. The eol
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
71 string is passed as a parameter.
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
72 @signal encodingChanged(str) emitted when the editors encoding was set. The
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
73 encoding name is passed as a parameter.
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
74 @signal lastEditPositionAvailable() emitted when a last edit position is
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
75 available
1807
9898a95461f1 Added a signal to the editor showing a refresh has happend and connected the editor assembly to it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1768
diff changeset
76 @signal refreshed() emitted to signal a refresh of the editor contents
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
77 """
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
78 modificationStatusChanged = pyqtSignal(bool, QsciScintillaCompat)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
79 undoAvailable = pyqtSignal(bool)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
80 redoAvailable = pyqtSignal(bool)
486
e4711a55e482 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 478
diff changeset
81 cursorChanged = pyqtSignal(str, int, int)
2768
eab35f6e709f Added support to show the current class/method name in the combo boxes at the top of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2659
diff changeset
82 cursorLineChanged = pyqtSignal(int)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
83 editorAboutToBeSaved = pyqtSignal(str)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
84 editorSaved = pyqtSignal(str)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
85 editorRenamed = pyqtSignal(str)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
86 captionChanged = pyqtSignal(str, QsciScintillaCompat)
486
e4711a55e482 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 478
diff changeset
87 breakpointToggled = pyqtSignal(QsciScintillaCompat)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
88 bookmarkToggled = pyqtSignal(QsciScintillaCompat)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
89 syntaxerrorToggled = pyqtSignal(QsciScintillaCompat)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
90 autoCompletionAPIsAvailable = pyqtSignal(bool)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
91 coverageMarkersShown = pyqtSignal(bool)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
92 taskMarkersUpdated = pyqtSignal(QsciScintillaCompat)
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
93 changeMarkersUpdated = pyqtSignal(QsciScintillaCompat)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
94 showMenu = pyqtSignal(str, QMenu, QsciScintillaCompat)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
95 languageChanged = pyqtSignal(str)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
96 eolChanged = pyqtSignal(str)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
97 encodingChanged = pyqtSignal(str)
1169
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
98 lastEditPositionAvailable = pyqtSignal()
1807
9898a95461f1 Added a signal to the editor showing a refresh has happend and connected the editor assembly to it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1768
diff changeset
99 refreshed = pyqtSignal()
486
e4711a55e482 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 478
diff changeset
100
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
101 WarningCode = 1
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
102 WarningStyle = 2
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
103
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
104 # Autocompletion icon definitions
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
105 ClassID = 1
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
106 ClassProtectedID = 2
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
107 ClassPrivateID = 3
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
108 MethodID = 4
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
109 MethodProtectedID = 5
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
110 MethodPrivateID = 6
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
111 AttributeID = 7
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
112 AttributeProtectedID = 8
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
113 AttributePrivateID = 9
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
114 EnumID = 10
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
115
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
116 FromDocumentID = 99
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
117
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
118 TemplateImageID = 100
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
119
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
120 # Cooperation related definitions
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
121 Separator = "@@@"
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
122
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
123 StartEditToken = "START_EDIT"
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
124 EndEditToken = "END_EDIT"
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
125 CancelEditToken = "CANCEL_EDIT"
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
126 RequestSyncToken = "REQUEST_SYNC"
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
127 SyncToken = "SYNC"
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
128
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
129 def __init__(self, dbs, fn=None, vm=None,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
130 filetype="", editor=None, tv=None):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
131 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
132 Constructor
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
133
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
134 @param dbs reference to the debug server object
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
135 @param fn name of the file to be opened (string). If it is None,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
136 a new (empty) editor is opened
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
137 @param vm reference to the view manager object
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
138 (ViewManager.ViewManager)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
139 @param filetype type of the source file (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
140 @param editor reference to an Editor object, if this is a cloned view
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
141 @param tv reference to the task viewer object
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
142 @exception IOError raised to indicate an issue accessing the file
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
143 """
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
144 super().__init__()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
145 self.setAttribute(Qt.WA_DeleteOnClose)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
146 self.setAttribute(Qt.WA_KeyCompression)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
147 self.setUtf8(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
148
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
149 self.dbs = dbs
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
150 self.taskViewer = tv
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
151 self.fileName = fn
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
152 self.vm = vm
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
153 self.filetype = filetype
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
154 self.filetypeByFlag = False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
155 self.noName = ""
252
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
156 self.project = e5App().getObject("Project")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
157
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
158 # clear some variables
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
159 self.lastHighlight = None # remember the last highlighted line
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
160 self.lastErrorMarker = None # remember the last error line
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
161 self.lastCurrMarker = None # remember the last current line
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
162
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
163 self.breaks = {}
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
164 # key: marker handle,
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
165 # value: (lineno, condition, temporary,
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
166 # enabled, ignorecount)
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
167 self.bookmarks = []
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
168 # bookmarks are just a list of handles to the
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
169 # bookmark markers
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
170 self.syntaxerrors = {}
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
171 # key: marker handle
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
172 # value: list of (error message, error index)
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
173 self.warnings = {}
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
174 # key: marker handle
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
175 # value: list of (warning message, warning type)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
176 self.notcoveredMarkers = [] # just a list of marker handles
2391
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
177 self.showingNotcoveredMarkers = False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
178
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
179 self.condHistory = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
180 self.lexer_ = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
181 self.__lexerReset = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
182 self.completer = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
183 self.encoding = Preferences.getEditor("DefaultEncoding")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
184 self.apiLanguage = ''
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
185 self.lastModified = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
186 self.line = -1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
187 self.inReopenPrompt = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
188 # true if the prompt to reload a changed source is present
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
189 self.inFileRenamed = False
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
190 # true if we are propagating a rename action
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
191 self.inLanguageChanged = False
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
192 # true if we are propagating a language change
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
193 self.inEolChanged = False
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
194 # true if we are propagating an eol change
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
195 self.inEncodingChanged = False
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
196 # true if we are propagating an encoding change
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
197 self.inDragDrop = False
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
198 # true if we are in drop mode
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
199 self.inLinesChanged = False
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
200 # true if we are propagating a lines changed event
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
201 self.__hasTaskMarkers = False
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
202 # no task markers present
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
203
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
204 self.macros = {} # list of defined macros
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
205 self.curMacro = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
206 self.recording = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
207
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
208 self.acAPI = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
209
1169
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
210 self.__lastEditPosition = None
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
211
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
212 # list of clones
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
213 self.__clones = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
214
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
215 # clear QScintilla defined keyboard commands
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
216 # we do our own handling through the view manager
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
217 self.clearAlternateKeys()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
218 self.clearKeys()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
219
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
220 # initialize the mark occurrences timer
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
221 self.__markOccurrencesTimer = QTimer(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
222 self.__markOccurrencesTimer.setSingleShot(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
223 self.__markOccurrencesTimer.setInterval(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
224 Preferences.getEditor("MarkOccurrencesTimeout"))
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
225 self.__markOccurrencesTimer.timeout.connect(self.__markOccurrences)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
226 self.__markedText = ""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
227
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
228 # initialize some spellchecking stuff
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
229 self.spell = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
230 self.lastLine = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
231 self.lastIndex = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
232
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
233 # initialize some cooperation stuff
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
234 self.__isSyncing = False
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
235 self.__receivedWhileSyncing = []
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
236 self.__savedText = ""
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
237 self.__inSharedEdit = False
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
238 self.__isShared = False
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
239 self.__inRemoteSharedEdit = False
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
240
1169
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
241 # connect signals before loading the text
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
242 self.modificationChanged.connect(self.__modificationChanged)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
243 self.cursorPositionChanged.connect(self.__cursorPositionChanged)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
244 self.modificationAttempted.connect(self.__modificationReadOnly)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
245 self.userListActivated.connect(self.__completionListSelected)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
246
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
247 # margins layout
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
248 if QSCINTILLA_VERSION() >= 0x020301:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
249 self.__unifiedMargins = Preferences.getEditor("UnifiedMargins")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
250 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
251 self.__unifiedMargins = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
252
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
253 # define the margins markers
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
254 self.__changeMarkerSaved = self.markerDefine(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
255 self.__createChangeMarkerPixmap(
2165
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
256 "OnlineChangeTraceMarkerSaved"))
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
257 self.__changeMarkerUnsaved = self.markerDefine(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
258 self.__createChangeMarkerPixmap(
2165
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
259 "OnlineChangeTraceMarkerUnsaved"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
260 self.breakpoint = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
261 self.markerDefine(UI.PixmapCache.getPixmap("break.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
262 self.cbreakpoint = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
263 self.markerDefine(UI.PixmapCache.getPixmap("cBreak.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
264 self.tbreakpoint = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
265 self.markerDefine(UI.PixmapCache.getPixmap("tBreak.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
266 self.tcbreakpoint = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
267 self.markerDefine(UI.PixmapCache.getPixmap("tCBreak.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
268 self.dbreakpoint = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
269 self.markerDefine(UI.PixmapCache.getPixmap("breakDisabled.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
270 self.bookmark = \
1106
3e57cd52e0f6 Added icons to the Mercurial extensions menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1063
diff changeset
271 self.markerDefine(UI.PixmapCache.getPixmap("bookmark16.png"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
272 self.syntaxerror = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
273 self.markerDefine(UI.PixmapCache.getPixmap("syntaxError.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
274 self.notcovered = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
275 self.markerDefine(UI.PixmapCache.getPixmap("notcovered.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
276 self.taskmarker = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
277 self.markerDefine(UI.PixmapCache.getPixmap("task.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
278 self.warning = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
279 self.markerDefine(UI.PixmapCache.getPixmap("warning.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
280
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
281 # define the line markers
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
282 self.currentline = self.markerDefine(QsciScintilla.Background)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
283 self.errorline = self.markerDefine(QsciScintilla.Background)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
284 self.__setLineMarkerColours()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
285
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
286 self.breakpointMask = (1 << self.breakpoint) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
287 (1 << self.cbreakpoint) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
288 (1 << self.tbreakpoint) | \
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
289 (1 << self.tcbreakpoint) | \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
290 (1 << self.dbreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
291
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
292 self.changeMarkersMask = (1 << self.__changeMarkerSaved) | \
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
293 (1 << self.__changeMarkerUnsaved)
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
294
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
295 # configure the margins
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
296 self.__setMarginsDisplay()
2640
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
297 self.linesChanged.connect(self.__resizeLinenoMargin)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
298
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
299 self.marginClicked.connect(self.__marginClicked)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
300
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
301 # set the eol mode
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
302 self.__setEolMode()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
303
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
304 # set the text display
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
305 self.__setTextDisplay()
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
306
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
307 # initialize the online syntax check timer
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
308 self.__initOnlineSyntaxCheck()
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
309
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
310 self.isResourcesFile = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
311 if editor is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
312 if self.fileName is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
313 if (QFileInfo(self.fileName).size() // 1024) > \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
314 Preferences.getEditor("WarnFilesize"):
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
315 res = E5MessageBox.yesNo(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
316 self.trUtf8("Open File"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
317 self.trUtf8("""<p>The size of the file <b>{0}</b>"""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
318 """ is <b>{1} KB</b>."""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
319 """ Do you really want to load it?</p>""")\
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
320 .format(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
321 self.fileName,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
322 QFileInfo(self.fileName).size() //
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
323 1024),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
324 icon=E5MessageBox.Warning)
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
325 if not res:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
326 raise IOError()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
327 self.readFile(self.fileName, True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
328 bindName = self.__bindName(self.text(0))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
329 self.__bindLexer(bindName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
330 self.__bindCompleter(bindName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
331 self.__autoSyntaxCheck()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
332 self.isResourcesFile = self.fileName.endswith(".qrc")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
333
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
334 self.recolor()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
335 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
336 # clone the given editor
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
337 self.setDocument(editor.document())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
338 self.breaks = editor.breaks
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
339 self.bookmarks = editor.bookmarks
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
340 self.syntaxerrors = editor.syntaxerrors
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
341 self.notcoveredMarkers = editor.notcoveredMarkers
2391
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
342 self.showingNotcoveredMarkers = editor.showingNotcoveredMarkers
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
343 self.isResourcesFile = editor.isResourcesFile
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
344 self.lastModified = editor.lastModified
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
345
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
346 self.addClone(editor)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
347 editor.addClone(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
348
832
eb5ff61f927b Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
349 self.gotoLine(1)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
350
741
137cc6344b48 Fixed an issue in the Editor class introduced by the annotation job.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 730
diff changeset
351 # set the text display again
137cc6344b48 Fixed an issue in the Editor class introduced by the annotation job.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 730
diff changeset
352 self.__setTextDisplay()
137cc6344b48 Fixed an issue in the Editor class introduced by the annotation job.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 730
diff changeset
353
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
354 # set the autocompletion and calltips function
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
355 self.__acHookFunction = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
356 self.__setAutoCompletion()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
357 self.__ctHookFunction = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
358 self.__setCallTips()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
359
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
360 sh = self.sizeHint()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
361 if sh.height() < 300:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
362 sh.setHeight(300)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
363 self.resize(sh)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
364
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
365 # Make sure tabbing through a QWorkspace works.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
366 self.setFocusPolicy(Qt.StrongFocus)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
367
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
368 self.__updateReadOnly(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
369
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
370 self.setWhatsThis(self.trUtf8(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
371 """<b>A Source Editor Window</b>"""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
372 """<p>This window is used to display and edit a source file."""
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
373 """ You can open as many of these as you like. The name of the"""
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
374 """ file is displayed in the window's titlebar.</p>"""
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
375 """<p>In order to set breakpoints just click in the space"""
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
376 """ between the line numbers and the fold markers. Via the"""
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
377 """ context menu of the margins they may be edited.</p>"""
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
378 """<p>In order to set bookmarks just Shift click in the space"""
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
379 """ between the line numbers and the fold markers.</p>"""
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
380 """<p>These actions can be reversed via the context menu.</p>"""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
381 """<p>Ctrl clicking on a syntax error marker shows some info"""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
382 """ about this error.</p>"""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
383 ))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
384
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
385 # Set the editors size, if it is too big for the view manager.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
386 if self.vm is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
387 req = self.size()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
388 bnd = req.boundedTo(self.vm.size())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
389
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
390 if bnd.width() < req.width() or bnd.height() < req.height():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
391 self.resize(bnd)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
392
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
393 # set the autosave flag
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
394 self.autosaveEnabled = Preferences.getEditor("AutosaveInterval") > 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
395 self.autosaveManuallyDisabled = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
396
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
397 self.__initContextMenu()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
398 self.__initContextMenuMargins()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
399
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
400 self.__checkEol()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
401 if editor is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
402 self.__checkLanguage()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
403 self.__checkEncoding()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
404 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
405 # it's a clone
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
406 self.__languageChanged(editor.apiLanguage, propagate=False)
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
407 self.__encodingChanged(editor.encoding, propagate=False)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
408
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
409 self.setAcceptDrops(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
410
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
411 # breakpoint handling
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
412 self.breakpointModel = self.dbs.getBreakPointModel()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
413 self.__restoreBreakpoints()
460
6a3899e91d76 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 448
diff changeset
414 self.breakpointModel.rowsAboutToBeRemoved.connect(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
415 self.__deleteBreakPoints)
460
6a3899e91d76 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 448
diff changeset
416 self.breakpointModel.dataAboutToBeChanged.connect(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
417 self.__breakPointDataAboutToBeChanged)
460
6a3899e91d76 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 448
diff changeset
418 self.breakpointModel.dataChanged.connect(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
419 self.__changeBreakPoints)
460
6a3899e91d76 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 448
diff changeset
420 self.breakpointModel.rowsInserted.connect(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
421 self.__addBreakPoints)
1928
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
422 self.SCN_MODIFIED.connect(self.__modified)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
423
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
424 # establish connection to some ViewManager action groups
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
425 self.addActions(self.vm.editorActGrp.actions())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
426 self.addActions(self.vm.editActGrp.actions())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
427 self.addActions(self.vm.copyActGrp.actions())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
428 self.addActions(self.vm.viewActGrp.actions())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
429
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
430 # register images to be shown in autocompletion lists
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
431 self.__registerImages()
1169
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
432
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
433 # connect signals after loading the text
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
434 self.textChanged.connect(self.__textChanged)
1353
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
435
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
436 # initialize the online change trace timer
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
437 self.__initOnlineChangeTrace()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
438
1754
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
439 if self.fileName and \
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
440 self.project.isOpen() and \
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
441 self.project.isProjectSource(self.fileName):
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
442 self.project.projectPropertiesChanged.connect(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
443 self.__projectPropertiesChanged)
1754
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
444
1518
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
445 self.grabGesture(Qt.PinchGesture)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
446
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
447 def __registerImages(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
448 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
449 Private method to register images for autocompletion lists.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
450 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
451 self.registerImage(self.ClassID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
452 UI.PixmapCache.getPixmap("class.png"))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
453 self.registerImage(self.ClassProtectedID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
454 UI.PixmapCache.getPixmap("class_protected.png"))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
455 self.registerImage(self.ClassPrivateID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
456 UI.PixmapCache.getPixmap("class_private.png"))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
457 self.registerImage(self.MethodID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
458 UI.PixmapCache.getPixmap("method.png"))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
459 self.registerImage(self.MethodProtectedID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
460 UI.PixmapCache.getPixmap("method_protected.png"))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
461 self.registerImage(self.MethodPrivateID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
462 UI.PixmapCache.getPixmap("method_private.png"))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
463 self.registerImage(self.AttributeID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
464 UI.PixmapCache.getPixmap("attribute.png"))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
465 self.registerImage(self.AttributeProtectedID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
466 UI.PixmapCache.getPixmap("attribute_protected.png"))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
467 self.registerImage(self.AttributePrivateID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
468 UI.PixmapCache.getPixmap("attribute_private.png"))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
469 self.registerImage(self.EnumID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
470 UI.PixmapCache.getPixmap("enum.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
471
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
472 self.registerImage(self.FromDocumentID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
473 UI.PixmapCache.getPixmap("editor.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
474
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
475 self.registerImage(self.TemplateImageID,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
476 UI.PixmapCache.getPixmap("templateViewer.png"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
477
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
478 def addClone(self, editor):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
479 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
480 Public method to add a clone to our list.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
481
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
482 @param editor reference to the cloned editor (Editor)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
483 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
484 self.__clones.append(editor)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
485
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
486 editor.editorRenamed.connect(self.fileRenamed)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
487 editor.languageChanged.connect(self.languageChanged)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
488 editor.eolChanged.connect(self.__eolChanged)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
489 editor.encodingChanged.connect(self.__encodingChanged)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
490
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
491 def removeClone(self, editor):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
492 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
493 Public method to remove a clone from our list.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
494
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
495 @param editor reference to the cloned editor (Editor)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
496 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
497 if editor in self.__clones:
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
498 editor.editorRenamed.disconnect(self.fileRenamed)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
499 editor.languageChanged.disconnect(self.languageChanged)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
500 editor.eolChanged.disconnect(self.__eolChanged)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
501 editor.encodingChanged.disconnect(self.__encodingChanged)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
502 self.__clones.remove(editor)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
503
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
504 def __bindName(self, line0):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
505 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
506 Private method to generate a dummy filename for binding a lexer.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
507
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
508 @param line0 first line of text to use in the generation process
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
509 (string)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
510 @return dummy file name to be used for binding a lexer (string)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
511 """
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
512 bindName = ""
2221
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
513 line0 = line0.lower()
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
514
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
515 # check first line if it does not start with #!
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
516 if line0.startswith(("<html", "<!doctype html", "<?php")):
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
517 bindName = "dummy.html"
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
518 elif line0.startswith(("<?xml", "<!doctype")):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
519 bindName = "dummy.xml"
2221
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
520 elif line0.startswith("index: "):
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
521 bindName = "dummy.diff"
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
522 elif line0.startswith("\\documentclass"):
f72f8b0478cb Extended the first line checks to determine the file type.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2219
diff changeset
523 bindName = "dummy.tex"
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
524
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
525 # check filetype
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
526 if not bindName and self.filetype:
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
527 if self.filetype in ["Python", "Python2"]:
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
528 bindName = "dummy.py"
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
529 elif self.filetype == "Python3":
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
530 bindName = "dummy.py"
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
531 elif self.filetype == "Ruby":
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
532 bindName = "dummy.rb"
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
533 elif self.filetype == "D":
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
534 bindName = "dummy.d"
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
535 elif self.filetype == "Properties":
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
536 bindName = "dummy.ini"
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
537
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
538 # #! marker detection
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
539 if not bindName and line0.startswith("#!"):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
540 if "python3" in line0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
541 bindName = "dummy.py"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
542 self.filetype = "Python3"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
543 elif "python2" in line0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
544 bindName = "dummy.py"
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
545 self.filetype = "Python2"
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
546 elif "python" in line0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
547 bindName = "dummy.py"
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
548 self.filetype = "Python2"
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
549 elif ("/bash" in line0 or "/sh" in line0):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
550 bindName = "dummy.sh"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
551 elif "ruby" in line0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
552 bindName = "dummy.rb"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
553 self.filetype = "Ruby"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
554 elif "perl" in line0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
555 bindName = "dummy.pl"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
556 elif "lua" in line0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
557 bindName = "dummy.lua"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
558 elif "dmd" in line0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
559 bindName = "dummy.d"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
560 self.filetype = "D"
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
561
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
562 if not bindName:
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
563 bindName = self.fileName
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
564
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
565 return bindName
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
566
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
567 def getMenu(self, menuName):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
568 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
569 Public method to get a reference to the main context menu or a submenu.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
570
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
571 @param menuName name of the menu (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
572 @return reference to the requested menu (QMenu) or None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
573 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
574 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
575 return self.__menus[menuName]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
576 except KeyError:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
577 return None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
578
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
579 def hasMiniMenu(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
580 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
581 Public method to check the miniMenu flag.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
582
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
583 @return flag indicating a minimized context menu (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
584 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
585 return self.miniMenu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
586
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
587 def __initContextMenu(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
588 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
589 Private method used to setup the context menu.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
590 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
591 self.miniMenu = Preferences.getEditor("MiniContextMenu")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
592
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
593 self.menuActs = {}
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
594 self.menu = QMenu()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
595 self.__menus = {
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
596 "Main": self.menu,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
597 }
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
598
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
599 self.languagesMenu = self.__initContextMenuLanguages()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
600 self.__menus["Languages"] = self.languagesMenu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
601 if self.isResourcesFile:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
602 self.resourcesMenu = self.__initContextMenuResources()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
603 self.__menus["Resources"] = self.resourcesMenu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
604 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
605 self.checksMenu = self.__initContextMenuChecks()
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
606 self.menuShow = self.__initContextMenuShow()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
607 self.graphicsMenu = self.__initContextMenuGraphics()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
608 self.autocompletionMenu = self.__initContextMenuAutocompletion()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
609 self.__menus["Checks"] = self.checksMenu
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
610 self.__menus["Show"] = self.menuShow
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
611 self.__menus["Graphics"] = self.graphicsMenu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
612 self.__menus["Autocompletion"] = self.autocompletionMenu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
613 self.exportersMenu = self.__initContextMenuExporters()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
614 self.__menus["Exporters"] = self.exportersMenu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
615 self.eolMenu = self.__initContextMenuEol()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
616 self.__menus["Eol"] = self.eolMenu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
617 self.encodingsMenu = self.__initContextMenuEncodings()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
618 self.__menus["Encodings"] = self.encodingsMenu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
619
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
620 self.menuActs["Undo"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
621 self.menu.addAction(UI.PixmapCache.getIcon("editUndo.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
622 self.trUtf8('Undo'), self.undo)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
623 self.menuActs["Redo"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
624 self.menu.addAction(UI.PixmapCache.getIcon("editRedo.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
625 self.trUtf8('Redo'), self.redo)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
626 self.menuActs["Revert"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
627 self.menu.addAction(self.trUtf8("Revert to last saved state"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
628 self.revertToUnmodified)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
629 self.menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
630 self.menuActs["Cut"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
631 self.menu.addAction(UI.PixmapCache.getIcon("editCut.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
632 self.trUtf8('Cut'), self.cut)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
633 self.menuActs["Copy"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
634 self.menu.addAction(UI.PixmapCache.getIcon("editCopy.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
635 self.trUtf8('Copy'), self.copy)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
636 self.menu.addAction(UI.PixmapCache.getIcon("editPaste.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
637 self.trUtf8('Paste'), self.paste)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
638 if not self.miniMenu:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
639 self.menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
640 self.menu.addAction(UI.PixmapCache.getIcon("editIndent.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
641 self.trUtf8('Indent'), self.indentLineOrSelection)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
642 self.menu.addAction(UI.PixmapCache.getIcon("editUnindent.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
643 self.trUtf8('Unindent'), self.unindentLineOrSelection)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
644 self.menuActs["Comment"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
645 self.menu.addAction(UI.PixmapCache.getIcon("editComment.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
646 self.trUtf8('Comment'), self.commentLineOrSelection)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
647 self.menuActs["Uncomment"] = \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
648 self.menu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
649 UI.PixmapCache.getIcon("editUncomment.png"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
650 self.trUtf8('Uncomment'), self.uncommentLineOrSelection)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
651 self.menuActs["StreamComment"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
652 self.menu.addAction(self.trUtf8('Stream Comment'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
653 self.streamCommentLineOrSelection)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
654 self.menuActs["BoxComment"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
655 self.menu.addAction(self.trUtf8('Box Comment'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
656 self.boxCommentLineOrSelection)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
657 self.menu.addSeparator()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
658 self.menu.addAction(self.trUtf8('Select to brace'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
659 self.selectToMatchingBrace)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
660 self.menu.addAction(self.trUtf8('Select all'), self.__selectAll)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
661 self.menu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
662 self.trUtf8('Deselect all'), self.__deselectAll)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
663 self.menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
664 self.menuActs["SpellCheck"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
665 self.menu.addAction(UI.PixmapCache.getIcon("spellchecking.png"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
666 self.trUtf8('Check spelling...'), self.checkSpelling)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
667 self.menuActs["SpellCheckSelection"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
668 self.menu.addAction(UI.PixmapCache.getIcon("spellchecking.png"),
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
669 self.trUtf8('Check spelling of selection...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
670 self.__checkSpellingSelection)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
671 self.menuActs["SpellCheckRemove"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
672 self.menu.addAction(self.trUtf8("Remove from dictionary"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
673 self.__removeFromSpellingDictionary)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
674 self.menu.addSeparator()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
675 self.menu.addAction(self.trUtf8('Shorten empty lines'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
676 self.shortenEmptyLines)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
677 self.menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
678 self.menuActs["Languages"] = self.menu.addMenu(self.languagesMenu)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
679 self.menuActs["Encodings"] = self.menu.addMenu(self.encodingsMenu)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
680 self.menuActs["Eol"] = self.menu.addMenu(self.eolMenu)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
681 self.menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
682 self.menuActs["MonospacedFont"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
683 self.menu.addAction(self.trUtf8("Use Monospaced Font"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
684 self.handleMonospacedEnable)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
685 self.menuActs["MonospacedFont"].setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
686 self.menuActs["MonospacedFont"].setChecked(self.useMonospaced)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
687 self.menuActs["AutosaveEnable"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
688 self.menu.addAction(self.trUtf8("Autosave enabled"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
689 self.__autosaveEnable)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
690 self.menuActs["AutosaveEnable"].setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
691 self.menuActs["AutosaveEnable"].setChecked(self.autosaveEnabled)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
692 self.menuActs["TypingAidsEnabled"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
693 self.menu.addAction(self.trUtf8("Typing aids enabled"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
694 self.__toggleTypingAids)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
695 self.menuActs["TypingAidsEnabled"].setCheckable(True)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
696 self.menuActs["TypingAidsEnabled"].setEnabled(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
697 self.completer is not None)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
698 self.menuActs["TypingAidsEnabled"].setChecked(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
699 self.completer is not None and self.completer.isEnabled())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
700 self.menuActs["AutoCompletionEnable"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
701 self.menu.addAction(self.trUtf8("Autocompletion enabled"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
702 self.__toggleAutoCompletionEnable)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
703 self.menuActs["AutoCompletionEnable"].setCheckable(True)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
704 self.menuActs["AutoCompletionEnable"].setChecked(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
705 self.autoCompletionThreshold() != -1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
706 if not self.isResourcesFile:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
707 self.menu.addMenu(self.autocompletionMenu)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
708 self.menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
709 if self.isResourcesFile:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
710 self.menu.addMenu(self.resourcesMenu)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
711 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
712 self.menuActs["Check"] = self.menu.addMenu(self.checksMenu)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
713 self.menu.addSeparator()
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
714 self.menuActs["Show"] = self.menu.addMenu(self.menuShow)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
715 self.menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
716 self.menuActs["Diagrams"] = self.menu.addMenu(self.graphicsMenu)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
717 self.menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
718 self.menu.addAction(self.trUtf8('New view'), self.__newView)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
719 act = self.menu.addAction(self.trUtf8('New view (with new split)'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
720 self.__newViewNewSplit)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
721 if not self.vm.canSplit():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
722 act.setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
723 self.menu.addAction(UI.PixmapCache.getIcon("close.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
724 self.trUtf8('Close'), self.__contextClose)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
725 self.menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
726 self.menuActs["Save"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
727 self.menu.addAction(UI.PixmapCache.getIcon("fileSave.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
728 self.trUtf8('Save'), self.__contextSave)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
729 self.menu.addAction(UI.PixmapCache.getIcon("fileSaveAs.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
730 self.trUtf8('Save As...'), self.__contextSaveAs)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
731 if not self.miniMenu:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
732 self.menu.addMenu(self.exportersMenu)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
733 self.menu.addSeparator()
1299
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
734 self.menuActs["OpenRejections"] = \
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
735 self.menu.addAction(self.trUtf8("Open 'rejection' file"),
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
736 self.__contextOpenRejections)
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
737 self.menu.addSeparator()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
738 self.menu.addAction(UI.PixmapCache.getIcon("printPreview.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
739 self.trUtf8("Print Preview"), self.printPreviewFile)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
740 self.menu.addAction(UI.PixmapCache.getIcon("print.png"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
741 self.trUtf8('Print'), self.printFile)
1299
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
742 else:
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
743 self.menuActs["OpenRejections"] = None
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
744
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
745 self.menu.aboutToShow.connect(self.__showContextMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
746
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
747 self.spellingMenu = QMenu()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
748 self.__menus["Spelling"] = self.spellingMenu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
749
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
750 self.spellingMenu.aboutToShow.connect(self.__showContextMenuSpelling)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
751 self.spellingMenu.triggered.connect(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
752 self.__contextMenuSpellingTriggered)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
753
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
754 def __initContextMenuAutocompletion(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
755 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
756 Private method used to setup the Checks context sub menu.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
757
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
758 @return reference to the generated menu (QMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
759 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
760 menu = QMenu(self.trUtf8('Autocomplete'))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
761
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
762 self.menuActs["acDynamic"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
763 menu.addAction(self.trUtf8('dynamic'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
764 self.autoComplete)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
765 menu.addSeparator()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
766 menu.addAction(self.trUtf8('from Document'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
767 self.autoCompleteFromDocument)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
768 self.menuActs["acAPI"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
769 menu.addAction(self.trUtf8('from APIs'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
770 self.autoCompleteFromAPIs)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
771 self.menuActs["acAPIDocument"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
772 menu.addAction(self.trUtf8('from Document and APIs'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
773 self.autoCompleteFromAll)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
774 menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
775 self.menuActs["calltip"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
776 menu.addAction(self.trUtf8('Calltip'), self.callTip)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
777
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
778 menu.aboutToShow.connect(self.__showContextMenuAutocompletion)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
779
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
780 return menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
781
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
782 def __initContextMenuChecks(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
783 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
784 Private method used to setup the Checks context sub menu.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
785
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
786 @return reference to the generated menu (QMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
787 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
788 menu = QMenu(self.trUtf8('Check'))
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
789 menu.aboutToShow.connect(self.__showContextMenuChecks)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
790 return menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
791
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
792 def __initContextMenuShow(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
793 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
794 Private method used to setup the Show context sub menu.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
795
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
796 @return reference to the generated menu (QMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
797 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
798 menu = QMenu(self.trUtf8('Show'))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
799
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
800 menu.addAction(self.trUtf8('Code metrics...'), self.__showCodeMetrics)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
801 self.coverageMenuAct = menu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
802 self.trUtf8('Code coverage...'), self.__showCodeCoverage)
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
803 self.coverageShowAnnotationMenuAct = menu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
804 self.trUtf8('Show code coverage annotations'),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
805 self.codeCoverageShowAnnotations)
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
806 self.coverageHideAnnotationMenuAct = menu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
807 self.trUtf8('Hide code coverage annotations'),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
808 self.__codeCoverageHideAnnotations)
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
809 self.profileMenuAct = menu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
810 self.trUtf8('Profile data...'), self.__showProfileData)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
811
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
812 menu.aboutToShow.connect(self.__showContextMenuShow)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
813
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
814 return menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
815
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
816 def __initContextMenuGraphics(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
817 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
818 Private method used to setup the diagrams context sub menu.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
819
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
820 @return reference to the generated menu (QMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
821 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
822 menu = QMenu(self.trUtf8('Diagrams'))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
823
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
824 menu.addAction(self.trUtf8('Class Diagram...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
825 self.__showClassDiagram)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
826 menu.addAction(self.trUtf8('Package Diagram...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
827 self.__showPackageDiagram)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
828 menu.addAction(self.trUtf8('Imports Diagram...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
829 self.__showImportsDiagram)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
830 self.applicationDiagramMenuAct = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
831 menu.addAction(self.trUtf8('Application Diagram...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
832 self.__showApplicationDiagram)
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
833 menu.addSeparator()
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
834 menu.addAction(UI.PixmapCache.getIcon("open.png"),
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
835 self.trUtf8("Load Diagram..."), self.__loadDiagram)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
836
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
837 menu.aboutToShow.connect(self.__showContextMenuGraphics)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
838
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
839 return menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
840
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
841 def __initContextMenuLanguages(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
842 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
843 Private method used to setup the Languages context sub menu.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
844
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
845 @return reference to the generated menu (QMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
846 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
847 menu = QMenu(self.trUtf8("Languages"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
848
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
849 self.languagesActGrp = QActionGroup(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
850 self.noLanguageAct = menu.addAction(self.trUtf8("No Language"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
851 self.noLanguageAct.setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
852 self.noLanguageAct.setData("None")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
853 self.languagesActGrp.addAction(self.noLanguageAct)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
854 menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
855
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
856 from . import Lexers
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
857 self.supportedLanguages = {}
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
858 supportedLanguages = Lexers.getSupportedLanguages()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
859 languages = sorted(list(supportedLanguages.keys()))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
860 for language in languages:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
861 if language != "Guessed":
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
862 self.supportedLanguages[language] = \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
863 supportedLanguages[language][:2]
2217
e80c74f2a25a Added some icons to the "Languages" and "End-of-Line Type" context menus of the editor and changed the status labels for programming language and end-of-line type of the main window to show an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2216
diff changeset
864 act = menu.addAction(
e80c74f2a25a Added some icons to the "Languages" and "End-of-Line Type" context menus of the editor and changed the status labels for programming language and end-of-line type of the main window to show an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2216
diff changeset
865 UI.PixmapCache.getIcon(supportedLanguages[language][2]),
e80c74f2a25a Added some icons to the "Languages" and "End-of-Line Type" context menus of the editor and changed the status labels for programming language and end-of-line type of the main window to show an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2216
diff changeset
866 self.supportedLanguages[language][0])
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
867 act.setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
868 act.setData(language)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
869 self.supportedLanguages[language].append(act)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
870 self.languagesActGrp.addAction(act)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
871
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
872 menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
873 self.pygmentsAct = menu.addAction(self.trUtf8("Guessed"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
874 self.pygmentsAct.setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
875 self.pygmentsAct.setData("Guessed")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
876 self.languagesActGrp.addAction(self.pygmentsAct)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
877 self.pygmentsSelAct = menu.addAction(self.trUtf8("Alternatives"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
878 self.pygmentsSelAct.setData("Alternatives")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
879
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
880 menu.triggered.connect(self.__languageMenuTriggered)
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
881 menu.aboutToShow.connect(self.__showContextMenuLanguages)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
882
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
883 return menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
884
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
885 def __initContextMenuEncodings(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
886 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
887 Private method used to setup the Encodings context sub menu.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
888
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
889 @return reference to the generated menu (QMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
890 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
891 self.supportedEncodings = {}
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
892
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
893 menu = QMenu(self.trUtf8("Encodings"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
894
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
895 self.encodingsActGrp = QActionGroup(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
896
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
897 for encoding in sorted(Utilities.supportedCodecs):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
898 act = menu.addAction(encoding)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
899 act.setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
900 act.setData(encoding)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
901 self.supportedEncodings[encoding] = act
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
902 self.encodingsActGrp.addAction(act)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
903
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
904 menu.triggered.connect(self.__encodingsMenuTriggered)
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
905 menu.aboutToShow.connect(self.__showContextMenuEncodings)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
906
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
907 return menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
908
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
909 def __initContextMenuEol(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
910 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
911 Private method to setup the eol context sub menu.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
912
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
913 @return reference to the generated menu (QMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
914 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
915 self.supportedEols = {}
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
916
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
917 menu = QMenu(self.trUtf8("End-of-Line Type"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
918
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
919 self.eolActGrp = QActionGroup(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
920
2217
e80c74f2a25a Added some icons to the "Languages" and "End-of-Line Type" context menus of the editor and changed the status labels for programming language and end-of-line type of the main window to show an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2216
diff changeset
921 act = menu.addAction(UI.PixmapCache.getIcon("eolLinux.png"),
e80c74f2a25a Added some icons to the "Languages" and "End-of-Line Type" context menus of the editor and changed the status labels for programming language and end-of-line type of the main window to show an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2216
diff changeset
922 self.trUtf8("Unix"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
923 act.setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
924 act.setData('\n')
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
925 self.supportedEols['\n'] = act
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
926 self.eolActGrp.addAction(act)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
927
2217
e80c74f2a25a Added some icons to the "Languages" and "End-of-Line Type" context menus of the editor and changed the status labels for programming language and end-of-line type of the main window to show an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2216
diff changeset
928 act = menu.addAction(UI.PixmapCache.getIcon("eolWindows.png"),
e80c74f2a25a Added some icons to the "Languages" and "End-of-Line Type" context menus of the editor and changed the status labels for programming language and end-of-line type of the main window to show an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2216
diff changeset
929 self.trUtf8("Windows"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
930 act.setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
931 act.setData('\r\n')
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
932 self.supportedEols['\r\n'] = act
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
933 self.eolActGrp.addAction(act)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
934
2217
e80c74f2a25a Added some icons to the "Languages" and "End-of-Line Type" context menus of the editor and changed the status labels for programming language and end-of-line type of the main window to show an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2216
diff changeset
935 act = menu.addAction(UI.PixmapCache.getIcon("eolMac.png"),
e80c74f2a25a Added some icons to the "Languages" and "End-of-Line Type" context menus of the editor and changed the status labels for programming language and end-of-line type of the main window to show an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2216
diff changeset
936 self.trUtf8("Macintosh"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
937 act.setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
938 act.setData('\r')
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
939 self.supportedEols['\r'] = act
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
940 self.eolActGrp.addAction(act)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
941
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
942 menu.triggered.connect(self.__eolMenuTriggered)
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
943 menu.aboutToShow.connect(self.__showContextMenuEol)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
944
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
945 return menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
946
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
947 def __initContextMenuExporters(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
948 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
949 Private method used to setup the Exporters context sub menu.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
950
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
951 @return reference to the generated menu (QMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
952 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
953 menu = QMenu(self.trUtf8("Export as"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
954
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
955 from . import Exporters
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
956 supportedExporters = Exporters.getSupportedFormats()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
957 exporters = sorted(list(supportedExporters.keys()))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
958 for exporter in exporters:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
959 act = menu.addAction(supportedExporters[exporter])
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
960 act.setData(exporter)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
961
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
962 menu.triggered.connect(self.__exportMenuTriggered)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
963
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
964 return menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
965
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
966 def __initContextMenuMargins(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
967 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
968 Private method used to setup the context menu for the margins.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
969 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
970 self.marginMenuActs = {}
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
971
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
972 if self.__unifiedMargins:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
973 self.__initContextMenuUnifiedMargins()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
974 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
975 self.__initContextMenuSeparateMargins()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
976
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
977 def __initContextMenuSeparateMargins(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
978 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
979 Private method used to setup the context menu for the separated
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
980 margins.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
981 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
982 # bookmark margin
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
983 self.bmMarginMenu = QMenu()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
984
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
985 self.bmMarginMenu.addAction(self.trUtf8('Toggle bookmark'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
986 self.menuToggleBookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
987 self.marginMenuActs["NextBookmark"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
988 self.bmMarginMenu.addAction(self.trUtf8('Next bookmark'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
989 self.nextBookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
990 self.marginMenuActs["PreviousBookmark"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
991 self.bmMarginMenu.addAction(self.trUtf8('Previous bookmark'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
992 self.previousBookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
993 self.marginMenuActs["ClearBookmark"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
994 self.bmMarginMenu.addAction(self.trUtf8('Clear all bookmarks'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
995 self.clearBookmarks)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
996
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
997 self.bmMarginMenu.aboutToShow.connect(self.__showContextMenuMargin)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
998
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
999 # breakpoint margin
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1000 self.bpMarginMenu = QMenu()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1001
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1002 self.marginMenuActs["Breakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1003 self.bpMarginMenu.addAction(self.trUtf8('Toggle breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1004 self.menuToggleBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1005 self.marginMenuActs["TempBreakpoint"] = \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1006 self.bpMarginMenu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1007 self.trUtf8('Toggle temporary breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1008 self.__menuToggleTemporaryBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1009 self.marginMenuActs["EditBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1010 self.bpMarginMenu.addAction(self.trUtf8('Edit breakpoint...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1011 self.menuEditBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1012 self.marginMenuActs["EnableBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1013 self.bpMarginMenu.addAction(self.trUtf8('Enable breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1014 self.__menuToggleBreakpointEnabled)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1015 self.marginMenuActs["NextBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1016 self.bpMarginMenu.addAction(self.trUtf8('Next breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1017 self.menuNextBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1018 self.marginMenuActs["PreviousBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1019 self.bpMarginMenu.addAction(self.trUtf8('Previous breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1020 self.menuPreviousBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1021 self.marginMenuActs["ClearBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1022 self.bpMarginMenu.addAction(self.trUtf8('Clear all breakpoints'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1023 self.__menuClearBreakpoints)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1024
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
1025 self.bpMarginMenu.aboutToShow.connect(self.__showContextMenuMargin)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1026
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1027 # indicator margin
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1028 self.indicMarginMenu = QMenu()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1029
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1030 self.marginMenuActs["GotoSyntaxError"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1031 self.indicMarginMenu.addAction(self.trUtf8('Goto syntax error'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1032 self.gotoSyntaxError)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1033 self.marginMenuActs["ShowSyntaxError"] = \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1034 self.indicMarginMenu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1035 self.trUtf8('Show syntax error message'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1036 self.__showSyntaxError)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1037 self.marginMenuActs["ClearSyntaxError"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1038 self.indicMarginMenu.addAction(self.trUtf8('Clear syntax error'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1039 self.clearSyntaxError)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1040 self.indicMarginMenu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1041 self.marginMenuActs["NextWarningMarker"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1042 self.indicMarginMenu.addAction(self.trUtf8("Next warning"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1043 self.nextFlakesWarning)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1044 self.marginMenuActs["PreviousWarningMarker"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1045 self.indicMarginMenu.addAction(self.trUtf8("Previous warning"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1046 self.previousFlakesWarning)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1047 self.marginMenuActs["ShowWarning"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1048 self.indicMarginMenu.addAction(self.trUtf8('Show warning message'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1049 self.__showFlakesWarning)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1050 self.marginMenuActs["ClearWarnings"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1051 self.indicMarginMenu.addAction(self.trUtf8('Clear warnings'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1052 self.clearFlakesWarnings)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1053 self.indicMarginMenu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1054 self.marginMenuActs["NextCoverageMarker"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1055 self.indicMarginMenu.addAction(self.trUtf8('Next uncovered line'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1056 self.nextUncovered)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1057 self.marginMenuActs["PreviousCoverageMarker"] = \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1058 self.indicMarginMenu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1059 self.trUtf8('Previous uncovered line'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1060 self.previousUncovered)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1061 self.indicMarginMenu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1062 self.marginMenuActs["NextTaskMarker"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1063 self.indicMarginMenu.addAction(self.trUtf8('Next task'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1064 self.nextTask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1065 self.marginMenuActs["PreviousTaskMarker"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1066 self.indicMarginMenu.addAction(self.trUtf8('Previous task'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1067 self.previousTask)
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1068 self.indicMarginMenu.addSeparator()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1069 self.marginMenuActs["NextChangeMarker"] = \
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1070 self.indicMarginMenu.addAction(self.trUtf8('Next change'),
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1071 self.nextChange)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1072 self.marginMenuActs["PreviousChangeMarker"] = \
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1073 self.indicMarginMenu.addAction(self.trUtf8('Previous change'),
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1074 self.previousChange)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1075
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
1076 self.indicMarginMenu.aboutToShow.connect(self.__showContextMenuMargin)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1077
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1078 def __initContextMenuUnifiedMargins(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1079 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1080 Private method used to setup the context menu for the unified margins.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1081 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1082 self.marginMenu = QMenu()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1083
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1084 self.marginMenu.addAction(self.trUtf8('Toggle bookmark'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1085 self.menuToggleBookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1086 self.marginMenuActs["NextBookmark"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1087 self.marginMenu.addAction(self.trUtf8('Next bookmark'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1088 self.nextBookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1089 self.marginMenuActs["PreviousBookmark"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1090 self.marginMenu.addAction(self.trUtf8('Previous bookmark'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1091 self.previousBookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1092 self.marginMenuActs["ClearBookmark"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1093 self.marginMenu.addAction(self.trUtf8('Clear all bookmarks'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1094 self.clearBookmarks)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1095 self.marginMenu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1096 self.marginMenuActs["GotoSyntaxError"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1097 self.marginMenu.addAction(self.trUtf8('Goto syntax error'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1098 self.gotoSyntaxError)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1099 self.marginMenuActs["ShowSyntaxError"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1100 self.marginMenu.addAction(self.trUtf8('Show syntax error message'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1101 self.__showSyntaxError)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1102 self.marginMenuActs["ClearSyntaxError"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1103 self.marginMenu.addAction(self.trUtf8('Clear syntax error'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1104 self.clearSyntaxError)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1105 self.marginMenu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1106 self.marginMenuActs["NextWarningMarker"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1107 self.marginMenu.addAction(self.trUtf8("Next warning"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1108 self.nextFlakesWarning)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1109 self.marginMenuActs["PreviousWarningMarker"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1110 self.marginMenu.addAction(self.trUtf8("Previous warning"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1111 self.previousFlakesWarning)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1112 self.marginMenuActs["ShowWarning"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1113 self.marginMenu.addAction(self.trUtf8('Show warning message'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1114 self.__showFlakesWarning)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1115 self.marginMenuActs["ClearWarnings"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1116 self.marginMenu.addAction(self.trUtf8('Clear warnings'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1117 self.clearFlakesWarnings)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1118 self.marginMenu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1119 self.marginMenuActs["Breakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1120 self.marginMenu.addAction(self.trUtf8('Toggle breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1121 self.menuToggleBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1122 self.marginMenuActs["TempBreakpoint"] = \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1123 self.marginMenu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1124 self.trUtf8('Toggle temporary breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1125 self.__menuToggleTemporaryBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1126 self.marginMenuActs["EditBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1127 self.marginMenu.addAction(self.trUtf8('Edit breakpoint...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1128 self.menuEditBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1129 self.marginMenuActs["EnableBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1130 self.marginMenu.addAction(self.trUtf8('Enable breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1131 self.__menuToggleBreakpointEnabled)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1132 self.marginMenuActs["NextBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1133 self.marginMenu.addAction(self.trUtf8('Next breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1134 self.menuNextBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1135 self.marginMenuActs["PreviousBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1136 self.marginMenu.addAction(self.trUtf8('Previous breakpoint'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1137 self.menuPreviousBreakpoint)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1138 self.marginMenuActs["ClearBreakpoint"] = \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1139 self.marginMenu.addAction(self.trUtf8('Clear all breakpoints'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1140 self.__menuClearBreakpoints)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1141 self.marginMenu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1142 self.marginMenuActs["NextCoverageMarker"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1143 self.marginMenu.addAction(self.trUtf8('Next uncovered line'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1144 self.nextUncovered)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1145 self.marginMenuActs["PreviousCoverageMarker"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1146 self.marginMenu.addAction(self.trUtf8('Previous uncovered line'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1147 self.previousUncovered)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1148 self.marginMenu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1149 self.marginMenuActs["NextTaskMarker"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1150 self.marginMenu.addAction(self.trUtf8('Next task'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1151 self.nextTask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1152 self.marginMenuActs["PreviousTaskMarker"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1153 self.marginMenu.addAction(self.trUtf8('Previous task'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1154 self.previousTask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1155 self.marginMenu.addSeparator()
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1156 self.marginMenuActs["NextChangeMarker"] = \
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1157 self.marginMenu.addAction(self.trUtf8('Next change'),
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1158 self.nextChange)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1159 self.marginMenuActs["PreviousChangeMarker"] = \
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1160 self.marginMenu.addAction(self.trUtf8('Previous change'),
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1161 self.previousChange)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
1162 self.marginMenu.addSeparator()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1163 self.marginMenuActs["LMBbookmarks"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1164 self.marginMenu.addAction(self.trUtf8('LMB toggles bookmarks'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1165 self.__lmBbookmarks)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1166 self.marginMenuActs["LMBbookmarks"].setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1167 self.marginMenuActs["LMBbookmarks"].setChecked(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1168 self.marginMenuActs["LMBbreakpoints"] = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1169 self.marginMenu.addAction(self.trUtf8('LMB toggles breakpoints'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1170 self.__lmBbreakpoints)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1171 self.marginMenuActs["LMBbreakpoints"].setCheckable(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1172 self.marginMenuActs["LMBbreakpoints"].setChecked(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1173
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
1174 self.marginMenu.aboutToShow.connect(self.__showContextMenuMargin)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1175
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1176 def __exportMenuTriggered(self, act):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1177 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1178 Private method to handle the selection of an export format.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1179
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1180 @param act reference to the action that was triggered (QAction)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1181 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1182 exporterFormat = act.data()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1183 self.exportFile(exporterFormat)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1184
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1185 def exportFile(self, exporterFormat):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1186 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1187 Public method to export the file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1188
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1189 @param exporterFormat format the file should be exported into (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1190 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1191 if exporterFormat:
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
1192 from . import Exporters
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1193 exporter = Exporters.getExporter(exporterFormat, self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1194 if exporter:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1195 exporter.exportSource()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1196 else:
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 536
diff changeset
1197 E5MessageBox.critical(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1198 self.trUtf8("Export source"),
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1199 self.trUtf8(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1200 """<p>No exporter available for the """
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1201 """export format <b>{0}</b>. Aborting...</p>""")\
535
4b00d7336e19 Streamlined the use of QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 520
diff changeset
1202 .format(exporterFormat))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1203 else:
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 536
diff changeset
1204 E5MessageBox.critical(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1205 self.trUtf8("Export source"),
535
4b00d7336e19 Streamlined the use of QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 520
diff changeset
1206 self.trUtf8("""No export format given. Aborting..."""))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1207
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1208 def __showContextMenuLanguages(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1209 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1210 Private slot handling the aboutToShow signal of the languages context
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1211 menu.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1212 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1213 if self.apiLanguage.startswith("Pygments|"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1214 self.pygmentsSelAct.setText(
812
240adf04a50e Fixed an issue where selecting a Pygments Python lexer disabled auto completion.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 811
diff changeset
1215 self.trUtf8("Alternatives ({0})").format(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1216 self.getLanguage(normalized=False)))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1217 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1218 self.pygmentsSelAct.setText(self.trUtf8("Alternatives"))
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1219 self.showMenu.emit("Languages", self.languagesMenu, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1220
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1221 def __selectPygmentsLexer(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1222 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1223 Private method to select a specific pygments lexer.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1224
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1225 @return name of the selected pygments lexer (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1226 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1227 from pygments.lexers import get_all_lexers
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1228 lexerList = sorted([l[0] for l in get_all_lexers()])
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1229 try:
1295
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1230 lexerSel = lexerList.index(
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1231 self.getLanguage(normalized=False, forPygments=True))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1232 except ValueError:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1233 lexerSel = 0
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
1234 lexerName, ok = QInputDialog.getItem(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1235 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1236 self.trUtf8("Pygments Lexer"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1237 self.trUtf8("Select the Pygments lexer to apply."),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1238 lexerList,
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1239 lexerSel,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1240 False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1241 if ok and lexerName:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1242 return lexerName
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1243 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1244 return ""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1245
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1246 def __languageMenuTriggered(self, act):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1247 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1248 Private method to handle the selection of a lexer language.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1249
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1250 @param act reference to the action that was triggered (QAction)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1251 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1252 if act == self.noLanguageAct:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1253 self.__resetLanguage()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1254 elif act == self.pygmentsAct:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1255 self.setLanguage("dummy.pygments")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1256 elif act == self.pygmentsSelAct:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1257 language = self.__selectPygmentsLexer()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1258 if language:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1259 self.setLanguage("dummy.pygments", pyname=language)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1260 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1261 language = act.data()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1262 if language:
2219
031fae60d778 Fixed an issue in the editor causing switching the language between Python2 and Python3 to only work every second time.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2217
diff changeset
1263 self.filetype = language
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1264 self.setLanguage(self.supportedLanguages[language][1])
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1265 self.__autoSyntaxCheck()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1266
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1267 def __languageChanged(self, language, propagate=True):
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1268 """
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1269 Private slot handling a change of a connected editor's language.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1270
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1271 @param language language to be set (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1272 @keyparam propagate flag indicating to propagate the change (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1273 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1274 if language == '':
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1275 self.__resetLanguage(propagate=propagate)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1276 elif language == "Guessed":
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1277 self.setLanguage("dummy.pygments")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1278 elif language.startswith("Pygments|"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1279 pyname = language.split("|", 1)[1]
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1280 self.setLanguage("dummy.pygments", pyname=pyname)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1281 else:
2219
031fae60d778 Fixed an issue in the editor causing switching the language between Python2 and Python3 to only work every second time.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2217
diff changeset
1282 self.filetype = language
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1283 self.setLanguage(self.supportedLanguages[language][1],
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1284 propagate=propagate)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1285 self.__autoSyntaxCheck()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1286
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1287 def __resetLanguage(self, propagate=True):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1288 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1289 Private method used to reset the language selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1290
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1291 @keyparam propagate flag indicating to propagate the change (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1292 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1293 if self.lexer_ is not None and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1294 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None):
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1295 self.SCN_STYLENEEDED.disconnect(self.__styleNeeded)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1296
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1297 self.apiLanguage = ""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1298 self.lexer_ = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1299 self.__lexerReset = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1300 self.setLexer()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1301 self.setMonospaced(self.useMonospaced)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1302 if self.completer is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1303 self.completer.setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1304 self.completer = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1305 self.__setTextDisplay()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1306
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1307 if not self.inLanguageChanged and propagate:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1308 self.inLanguageChanged = True
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1309 self.languageChanged.emit(self.apiLanguage)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1310 self.inLanguageChanged = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1311
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1312 def setLanguage(self, filename, initTextDisplay=True, propagate=True,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1313 pyname=""):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1314 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1315 Public method to set a lexer language.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1316
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1317 @param filename filename used to determine the associated lexer
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1318 language (string)
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1319 @param initTextDisplay flag indicating an initialization of the text
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1320 display is required as well (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1321 @keyparam propagate flag indicating to propagate the change (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1322 @keyparam pyname name of the pygments lexer to use (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1323 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1324 self.__lexerReset = False
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1325 self.__bindLexer(filename, pyname=pyname)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1326 self.__bindCompleter(filename)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1327 self.recolor()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1328 self.__checkLanguage()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1329
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1330 # set the text display
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1331 if initTextDisplay:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1332 self.__setTextDisplay()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1333
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1334 # set the autocompletion and calltips function
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1335 self.__setAutoCompletion()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1336 self.__setCallTips()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1337
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1338 if not self.inLanguageChanged and propagate:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1339 self.inLanguageChanged = True
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1340 self.languageChanged.emit(self.apiLanguage)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1341 self.inLanguageChanged = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1342
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1343 def __checkLanguage(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1344 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1345 Private method to check the selected language of the language submenu.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1346 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1347 if self.apiLanguage == "":
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1348 self.noLanguageAct.setChecked(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1349 elif self.apiLanguage == "Guessed":
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1350 self.pygmentsAct.setChecked(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1351 elif self.apiLanguage.startswith("Pygments|"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1352 act = self.languagesActGrp.checkedAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1353 if act:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1354 act.setChecked(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1355 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1356 self.supportedLanguages[self.apiLanguage][2].setChecked(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1357
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1358 def projectLexerAssociationsChanged(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1359 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1360 Public slot to handle changes of the project lexer associations.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1361 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1362 self.setLanguage(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1363
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1364 def __showContextMenuEncodings(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1365 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1366 Private slot handling the aboutToShow signal of the encodings context
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1367 menu.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1368 """
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1369 self.showMenu.emit("Encodings", self.encodingsMenu, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1370
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1371 def __encodingsMenuTriggered(self, act):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1372 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1373 Private method to handle the selection of an encoding.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1374
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1375 @param act reference to the action that was triggered (QAction)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1376 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1377 encoding = act.data()
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
1378 self.__encodingChanged("{0}-selected".format(encoding))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1379
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1380 def __checkEncoding(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1381 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1382 Private method to check the selected encoding of the encodings submenu.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1383 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1384 try:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1385 self.supportedEncodings[self.__normalizedEncoding()]\
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1386 .setChecked(True)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1387 except (AttributeError, KeyError):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1388 pass
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1389
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1390 def __encodingChanged(self, encoding, propagate=True):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1391 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1392 Private slot to handle a change of the encoding.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1393
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1394 @param encoding changed encoding (string)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1395 @keyparam propagate flag indicating to propagate the change (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1396 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1397 self.encoding = encoding
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1398 self.__checkEncoding()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1399
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1400 if not self.inEncodingChanged and propagate:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1401 self.inEncodingChanged = True
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1402 self.encodingChanged.emit(self.encoding)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1403 self.inEncodingChanged = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1404
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1405 def __normalizedEncoding(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1406 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1407 Private method to calculate the normalized encoding string.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1408
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1409 @return normalized encoding (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1410 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1411 return self.encoding.replace("-default", "")\
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1412 .replace("-guessed", "")\
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1413 .replace("-selected", "")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1414
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1415 def __showContextMenuEol(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1416 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1417 Private slot handling the aboutToShow signal of the eol context menu.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1418 """
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1419 self.showMenu.emit("Eol", self.eolMenu, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1420
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1421 def __eolMenuTriggered(self, act):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1422 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1423 Private method to handle the selection of an eol type.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1424
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1425 @param act reference to the action that was triggered (QAction)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1426 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1427 eol = act.data()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1428 self.setEolModeByEolString(eol)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1429 self.convertEols(self.eolMode())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1430
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1431 def __checkEol(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1432 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1433 Private method to check the selected eol type of the eol submenu.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1434 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1435 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1436 self.supportedEols[self.getLineSeparator()].setChecked(True)
875
606815a46bc0 Fixed a strange issue in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 832
diff changeset
1437 except (AttributeError, TypeError):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1438 pass
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1439
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1440 def __eolChanged(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1441 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1442 Private slot to handle a change of the eol mode.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1443 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1444 self.__checkEol()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1445
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1446 if not self.inEolChanged:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1447 self.inEolChanged = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1448 eol = self.getLineSeparator()
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1449 self.eolChanged.emit(eol)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1450 self.inEolChanged = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1451
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1452 def __bindLexer(self, filename, pyname=""):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1453 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1454 Private slot to set the correct lexer depending on language.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1455
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1456 @param filename filename used to determine the associated lexer
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1457 language (string)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1458 @keyparam pyname name of the pygments lexer to use (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1459 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1460 if self.lexer_ is not None and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1461 (self.lexer_.lexer() == "container" or self.lexer_.lexer() is None):
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1462 self.SCN_STYLENEEDED.disconnect(self.__styleNeeded)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1463
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1464 language = ""
252
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
1465 if self.project.isOpen() and self.project.isProjectFile(filename):
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1466 language = self.project.getEditorLexerAssoc(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1467 os.path.basename(filename))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1468 if not language:
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1469 ext = os.path.splitext(filename)[1]
1295
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1470 if ext in [".py", ".pyw"]:
2900
04a13651238e Optimized the Python type detection of the editor to improve Python3 detection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2768
diff changeset
1471 if self.isPy3File():
04a13651238e Optimized the Python type detection of the editor to improve Python3 detection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2768
diff changeset
1472 language = "Python3"
04a13651238e Optimized the Python type detection of the editor to improve Python3 detection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2768
diff changeset
1473 elif self.isPy2File():
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1474 language = "Python2"
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1475 else:
1295
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1476 # default is Python 3
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1477 language = "Python3"
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1478 else:
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1479 filename = os.path.basename(filename)
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1480 language = Preferences.getEditorLexerAssoc(filename)
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1481 if language == "Python":
1295
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1482 # correction for Python
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1483 if self.isPy2File():
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1484 language = "Python2"
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1485 else:
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1486 language = "Python3"
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1487 if language.startswith("Pygments|"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1488 pyname = language.split("|", 1)[1]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1489 language = ""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1490
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
1491 from . import Lexers
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1492 self.lexer_ = Lexers.getLexer(language, self, pyname=pyname)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1493 if self.lexer_ is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1494 self.setLexer()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1495 self.apiLanguage = ""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1496 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1497
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1498 if pyname:
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
1499 self.apiLanguage = "Pygments|{0}".format(pyname)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1500 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1501 self.apiLanguage = self.lexer_.language()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1502 if self.apiLanguage == "POV":
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1503 self.apiLanguage = "Povray"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1504 self.setLexer(self.lexer_)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1505 self.__setMarginsDisplay()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1506 if self.lexer_.lexer() == "container" or self.lexer_.lexer() is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1507 self.setStyleBits(self.lexer_.styleBitsNeeded())
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1508 self.SCN_STYLENEEDED.connect(self.__styleNeeded)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1509
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1510 # get the font for style 0 and set it as the default font
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
1511 key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1512 fdesc = Preferences.Prefs.settings.value(key)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1513 if fdesc is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1514 font = QFont(fdesc[0], int(fdesc[1]))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1515 self.lexer_.setDefaultFont(font)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1516 self.lexer_.readSettings(Preferences.Prefs.settings, "Scintilla")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1517
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1518 # now set the lexer properties
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1519 self.lexer_.initProperties()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1520
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1521 # initialize the lexer APIs settings
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1522 api = self.vm.getAPIsManager().getAPIs(self.apiLanguage)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1523 if api is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1524 self.lexer_.setAPIs(api.getQsciAPIs())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1525 self.acAPI = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1526 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1527 self.acAPI = False
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1528 self.autoCompletionAPIsAvailable.emit(self.acAPI)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1529
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
1530 self.__setAnnotationStyles()
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
1531
1566
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
1532 self.lexer_.setDefaultColor(self.lexer_.color(0))
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
1533 self.lexer_.setDefaultPaper(self.lexer_.paper(0))
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
1534
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1535 def __styleNeeded(self, position):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1536 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1537 Private slot to handle the need for more styling.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1538
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1539 @param position end position, that needs styling (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1540 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1541 self.lexer_.styleText(self.getEndStyled(), position)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1542
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1543 def getLexer(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1544 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1545 Public method to retrieve a reference to the lexer object.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1546
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1547 @return the lexer object (Lexer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1548 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1549 return self.lexer_
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1550
1295
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1551 def getLanguage(self, normalized=True, forPygments=False):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1552 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1553 Public method to retrieve the language of the editor.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1554
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1555 @keyparam normalized flag indicating to normalize some Pygments
812
240adf04a50e Fixed an issue where selecting a Pygments Python lexer disabled auto completion.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 811
diff changeset
1556 lexer names (boolean)
1295
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1557 @keyparam forPygments flag indicating to normalize some lexer
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1558 names for Pygments (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1559 @return language of the editor (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1560 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1561 if self.apiLanguage == "Guessed" or \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1562 self.apiLanguage.startswith("Pygments|"):
812
240adf04a50e Fixed an issue where selecting a Pygments Python lexer disabled auto completion.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 811
diff changeset
1563 lang = self.lexer_.name()
240adf04a50e Fixed an issue where selecting a Pygments Python lexer disabled auto completion.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 811
diff changeset
1564 if normalized:
240adf04a50e Fixed an issue where selecting a Pygments Python lexer disabled auto completion.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 811
diff changeset
1565 # adjust some Pygments lexer names
240adf04a50e Fixed an issue where selecting a Pygments Python lexer disabled auto completion.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 811
diff changeset
1566 if lang == "Python":
240adf04a50e Fixed an issue where selecting a Pygments Python lexer disabled auto completion.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 811
diff changeset
1567 lang = "Python2"
240adf04a50e Fixed an issue where selecting a Pygments Python lexer disabled auto completion.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 811
diff changeset
1568 elif lang == "Python 3":
240adf04a50e Fixed an issue where selecting a Pygments Python lexer disabled auto completion.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 811
diff changeset
1569 lang = "Python3"
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1570 else:
1295
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1571 lang = self.apiLanguage
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1572 if forPygments:
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1573 # adjust some names to Pygments lexer names
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1574 if lang == "Python2":
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1575 lang = "Python"
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1576 elif lang == "Python3":
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1577 lang = "Python 3"
b3db3070d104 Fixed an issue in the editor setting the correct language.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1196
diff changeset
1578 return lang
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1579
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1580 def __bindCompleter(self, filename):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1581 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1582 Private slot to set the correct typing completer depending on language.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1583
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1584 @param filename filename used to determine the associated typing
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1585 completer language (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1586 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1587 if self.completer is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1588 self.completer.setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1589 self.completer = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1590
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1591 filename = os.path.basename(filename)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1592 apiLanguage = Preferences.getEditorLexerAssoc(filename)
811
2ed99614dbf4 Fixed an issue with the editor not activating the correct typing completer in some situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
1593 if apiLanguage == "":
2900
04a13651238e Optimized the Python type detection of the editor to improve Python3 detection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2768
diff changeset
1594 if self.isPy3File():
04a13651238e Optimized the Python type detection of the editor to improve Python3 detection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2768
diff changeset
1595 apiLanguage = "Python3"
04a13651238e Optimized the Python type detection of the editor to improve Python3 detection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2768
diff changeset
1596 elif self.isPy2File():
811
2ed99614dbf4 Fixed an issue with the editor not activating the correct typing completer in some situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
1597 apiLanguage = "Python2"
2ed99614dbf4 Fixed an issue with the editor not activating the correct typing completer in some situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
1598 elif self.isRubyFile():
2ed99614dbf4 Fixed an issue with the editor not activating the correct typing completer in some situations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 802
diff changeset
1599 apiLanguage = "Ruby"
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1600
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
1601 from . import TypingCompleters
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1602 self.completer = TypingCompleters.getCompleter(apiLanguage, self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1603
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1604 def getCompleter(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1605 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1606 Public method to retrieve a reference to the completer object.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1607
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1608 @return the completer object (CompleterBase)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1609 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1610 return self.completer
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1611
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1612 def __modificationChanged(self, m):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1613 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1614 Private slot to handle the modificationChanged signal.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1615
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1616 It emits the signal modificationStatusChanged with parameters
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1617 m and self.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1618
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1619 @param m modification status
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1620 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1621 if not m and self.fileName is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1622 self.lastModified = QFileInfo(self.fileName).lastModified()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1623 if Preferences.getEditor("AutoCheckSyntax"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1624 self.clearSyntaxError()
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1625 self.modificationStatusChanged.emit(m, self)
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1626 self.undoAvailable.emit(self.isUndoAvailable())
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
1627 self.redoAvailable.emit(self.isRedoAvailable())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1628
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1629 def __cursorPositionChanged(self, line, index):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1630 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1631 Private slot to handle the cursorPositionChanged signal.
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1632
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1633 It emits the signal cursorChanged with parameters fileName,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1634 line and pos.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1635
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1636 @param line line number of the cursor
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1637 @param index position in line of the cursor
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1638 """
486
e4711a55e482 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 478
diff changeset
1639 self.cursorChanged.emit(self.fileName, line + 1, index)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1640
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1641 if Preferences.getEditor("MarkOccurrencesEnabled"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1642 self.__markOccurrencesTimer.stop()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1643 self.__markOccurrencesTimer.start()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1644
2768
eab35f6e709f Added support to show the current class/method name in the combo boxes at the top of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2659
diff changeset
1645 if self.lastLine != line:
eab35f6e709f Added support to show the current class/method name in the combo boxes at the top of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2659
diff changeset
1646 self.cursorLineChanged.emit(line)
eab35f6e709f Added support to show the current class/method name in the combo boxes at the top of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2659
diff changeset
1647
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1648 if self.spell is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1649 # do spell checking
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1650 doSpelling = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1651 if self.lastLine == line:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1652 start, end = self.getWordBoundaries(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1653 line, index, useWordChars=False)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1654 if start <= self.lastIndex and self.lastIndex <= end:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1655 doSpelling = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1656 if doSpelling:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1657 pos = self.positionFromLineIndex(self.lastLine, self.lastIndex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1658 self.spell.checkWord(pos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1659
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1660 self.lastLine = line
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1661 self.lastIndex = index
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1662
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1663 def __modificationReadOnly(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1664 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1665 Private slot to handle the modificationAttempted signal.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1666 """
539
87f9bce38a44 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 538
diff changeset
1667 E5MessageBox.warning(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1668 self.trUtf8("Modification of Read Only file"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1669 self.trUtf8("""You are attempting to change a read only file. """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1670 """Please save to a different file first."""))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1671
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1672 def setNoName(self, noName):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1673 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1674 Public method to set the display string for an unnamed editor.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1675
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1676 @param noName display string for this unnamed editor (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1677 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1678 self.noName = noName
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1679
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1680 def getNoName(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1681 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1682 Public method to get the display string for an unnamed editor.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1683
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1684 @return display string for this unnamed editor (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1685 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1686 return self.noName
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1687
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1688 def getFileName(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1689 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1690 Public method to return the name of the file being displayed.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1691
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1692 @return filename of the displayed file (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1693 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1694 return self.fileName
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1695
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1696 def getFileType(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1697 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1698 Public method to return the type of the file being displayed.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1699
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1700 @return type of the displayed file (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1701 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1702 return self.filetype
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1703
795
917f1945355c Added a syntax checker function for Python 2 files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
1704 def getFileTypeByFlag(self):
917f1945355c Added a syntax checker function for Python 2 files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
1705 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1706 Public method to return the type of the file, if it was set by an
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1707 eflag: marker.
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1708
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1709 @return type of the displayed file, if set by an eflag: marker or an
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1710 empty string (string)
795
917f1945355c Added a syntax checker function for Python 2 files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
1711 """
917f1945355c Added a syntax checker function for Python 2 files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
1712 if self.filetypeByFlag:
917f1945355c Added a syntax checker function for Python 2 files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
1713 return self.filetype
917f1945355c Added a syntax checker function for Python 2 files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
1714 else:
917f1945355c Added a syntax checker function for Python 2 files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
1715 return ""
917f1945355c Added a syntax checker function for Python 2 files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
1716
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1717 def determineFileType(self):
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1718 """
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1719 Public method to determine the file type using various tests.
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1720
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1721 @return type of the displayed file or an empty string (string)
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1722 """
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1723 ftype = self.filetype
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1724 if not ftype:
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1725 ftype = self.getFileTypeByFlag()
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1726 if not ftype:
2900
04a13651238e Optimized the Python type detection of the editor to improve Python3 detection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2768
diff changeset
1727 if self.isPy3File():
04a13651238e Optimized the Python type detection of the editor to improve Python3 detection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2768
diff changeset
1728 ftype = "Python3"
04a13651238e Optimized the Python type detection of the editor to improve Python3 detection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2768
diff changeset
1729 elif self.isPy2File():
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1730 ftype = "Python2"
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1731 elif self.isRubyFile():
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1732 ftype = "Ruby"
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1733 else:
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1734 ftype = ""
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1735
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1736 return ftype
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1737
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1738 def getEncoding(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1739 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1740 Public method to return the current encoding.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1741
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1742 @return current encoding (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1743 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1744 return self.encoding
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1745
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
1746 def isPy2File(self):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1747 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1748 Public method to return a flag indicating a Python file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1749
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1750 @return flag indicating a Python file (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1751 """
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1752 if self.filetype in ["Python", "Python2"]:
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1753 return True
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1754
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1755 if self.filetype == "":
2643
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1756 # 1) Determine by first line
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1757 line0 = self.text(0)
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1758 if line0.startswith("#!") and \
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1759 ("python2" in line0 or \
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1760 ("python" in line0 and not "python3" in line0)):
1758
e18f96b1714b A few optimizations and a fix for a bug, that caused incorrect display of breakpoints in the editor margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1754
diff changeset
1761 self.filetype = "Python2"
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1762 return True
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1763
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1764 if self.fileName is not None:
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1765 ext = os.path.splitext(self.fileName)[1]
2643
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1766 if ext in [".py", ".pyw"]:
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1767 # 2) .py and .pyw are ambiguous; determine from project
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1768 if Preferences.getProject("DeterminePyFromProject") and \
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1769 self.project.isOpen() and \
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1770 self.project.isProjectFile(self.fileName):
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1771 isProjectPy2 = \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1772 self.project.getProjectLanguage() in ["Python",
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1773 "Python2"]
2643
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1774 if isProjectPy2:
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1775 self.filetype = "Python2"
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1776 return isProjectPy2
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1777 else:
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1778 # 3) determine by compiling the sources
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1779 syntaxError = Utilities.py2compile(self.fileName,
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1780 checkFlakes=False)[0]
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1781 if not syntaxError:
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1782 self.filetype = "Python2"
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1783 return True
994
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
1784
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
1785 if ext in self.dbs.getExtensions('Python2'):
1758
e18f96b1714b A few optimizations and a fix for a bug, that caused incorrect display of breakpoints in the editor margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1754
diff changeset
1786 self.filetype = "Python2"
994
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
1787 return True
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1788
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1789 return False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1790
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1791 def isPy3File(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1792 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1793 Public method to return a flag indicating a Python3 file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1794
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1795 @return flag indicating a Python3 file (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1796 """
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1797 if self.filetype in ["Python3"]:
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1798 return True
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1799
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1800 if self.filetype == "":
2643
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1801 # 1) Determine by first line
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1802 line0 = self.text(0)
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1803 if line0.startswith("#!") and \
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1804 "python3" in line0:
1758
e18f96b1714b A few optimizations and a fix for a bug, that caused incorrect display of breakpoints in the editor margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1754
diff changeset
1805 self.filetype = "Python3"
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1806 return True
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1807
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1808 if self.fileName is not None:
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1809 ext = os.path.splitext(self.fileName)[1]
2643
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1810 if ext in [".py", ".pyw"]:
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1811 # 2) .py and .pyw are ambiguous; determine from project
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1812 if Preferences.getProject("DeterminePyFromProject") and \
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1813 self.project.isOpen() and \
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1814 self.project.isProjectFile(self.fileName):
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1815 isProjectPy3 = \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1816 self.project.getProjectLanguage() in ["Python3"]
2643
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1817 if isProjectPy3:
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1818 self.filetype = "Python3"
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1819 return isProjectPy3
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1820 else:
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1821 # 3) determine by compiling the sources
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1822 syntaxError = Utilities.compile(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1823 self.fileName, self.text())
2643
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1824 if not syntaxError:
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1825 self.filetype = "Python3"
e870fc2b4819 Extended the Python variant detection in the editor by compiling the source.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2640
diff changeset
1826 return True
994
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
1827
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
1828 if ext in self.dbs.getExtensions('Python3'):
1758
e18f96b1714b A few optimizations and a fix for a bug, that caused incorrect display of breakpoints in the editor margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1754
diff changeset
1829 self.filetype = "Python3"
994
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
1830 return True
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1831
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
1832 return False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1833
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1834 def isRubyFile(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1835 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1836 Public method to return a flag indicating a Ruby file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1837
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1838 @return flag indicating a Ruby file (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1839 """
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1840 if self.filetype == "Ruby":
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1841 return True
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1842
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1843 if self.filetype == "":
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1844 line0 = self.text(0)
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1845 if line0.startswith("#!") and \
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1846 "ruby" in line0:
1758
e18f96b1714b A few optimizations and a fix for a bug, that caused incorrect display of breakpoints in the editor margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1754
diff changeset
1847 self.filetype = "Ruby"
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1848 return True
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1849
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1850 if self.fileName is not None and \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1851 os.path.splitext(self.fileName)[1] in \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1852 self.dbs.getExtensions('Ruby'):
1758
e18f96b1714b A few optimizations and a fix for a bug, that caused incorrect display of breakpoints in the editor margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1754
diff changeset
1853 self.filetype = "Ruby"
991
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1854 return True
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1855
5ec5e707dfa5 Changed algorithm to determine the debugger backend type to be used by analysing a first line starting with '#!'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 989
diff changeset
1856 return False
1196
77da430b4080 Added an action to preview the file in the eric web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1169
diff changeset
1857
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1858 def highlightVisible(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1859 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1860 Public method to make sure that the highlight is visible.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1861 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1862 if self.lastHighlight is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1863 lineno = self.markerLine(self.lastHighlight)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1864 self.ensureVisible(lineno + 1)
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1865
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1866 def highlight(self, line=None, error=False, syntaxError=False):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1867 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1868 Public method to highlight [or de-highlight] a particular line.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1869
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1870 @param line line number to highlight (integer)
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1871 @param error flag indicating whether the error highlight should be
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1872 used (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1873 @param syntaxError flag indicating a syntax error (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1874 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1875 if line is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1876 self.lastHighlight = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1877 if self.lastErrorMarker is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1878 self.markerDeleteHandle(self.lastErrorMarker)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1879 self.lastErrorMarker = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1880 if self.lastCurrMarker is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1881 self.markerDeleteHandle(self.lastCurrMarker)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1882 self.lastCurrMarker = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1883 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1884 if error:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1885 if self.lastErrorMarker is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1886 self.markerDeleteHandle(self.lastErrorMarker)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1887 self.lastErrorMarker = self.markerAdd(line - 1, self.errorline)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1888 self.lastHighlight = self.lastErrorMarker
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1889 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1890 if self.lastCurrMarker is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1891 self.markerDeleteHandle(self.lastCurrMarker)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1892 self.lastCurrMarker = self.markerAdd(line - 1,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1893 self.currentline)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1894 self.lastHighlight = self.lastCurrMarker
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
1895 self.setCursorPosition(line - 1, 0)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1896
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1897 def getHighlightPosition(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1898 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1899 Public method to return the position of the highlight bar.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1900
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1901 @return line number of the highlight bar (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1902 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1903 if self.lastHighlight is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1904 return self.markerLine(self.lastHighlight)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1905 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1906 return 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1907
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1908 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1909 ## Breakpoint handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1910 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1911
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1912 def __modified(self, pos, mtype, text, length, linesAdded, line, foldNow,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1913 foldPrev, token, annotationLinesAdded):
1928
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1914 """
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1915 Private method to handle changes of the number of lines.
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1916
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1917 @param pos start position of change (integer)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1918 @param mtype flags identifying the change (integer)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1919 @param text text that is given to the Undo system (string)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1920 @param length length of the change (integer)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1921 @param linesAdded number of added/deleted lines (integer)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1922 @param line line number of a fold level or marker change (integer)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1923 @param foldNow new fold level (integer)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1924 @param foldPrev previous fold level (integer)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1925 @param token ???
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1926 @param annotationLinesAdded number of added/deleted annotation lines
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1927 (integer)
1928
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1928 """
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1929 if mtype & (self.SC_MOD_INSERTTEXT | self.SC_MOD_DELETETEXT) and \
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1930 linesAdded != 0:
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1931 if self.breaks:
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1932 bps = [] # list of breakpoints
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1933 for handle, (ln, cond, temp, enabled, ignorecount) in \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1934 self.breaks.items():
1928
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1935 line = self.markerLine(handle) + 1
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1936 if ln != line:
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1937 bps.append((ln, line))
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1938 self.breaks[handle] = (line, cond, temp, enabled,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1939 ignorecount)
1928
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1940 self.inLinesChanged = True
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1941 for ln, line in sorted(bps, reverse=linesAdded > 0):
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1942 index1 = self.breakpointModel.getBreakPointIndex(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1943 self.fileName, ln)
1928
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1944 index2 = self.breakpointModel.index(index1.row(), 1)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1945 self.breakpointModel.setData(index2, line)
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1946 self.inLinesChanged = False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1947
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1948 def __restoreBreakpoints(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1949 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1950 Private method to restore the breakpoints.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1951 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1952 for handle in list(self.breaks.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1953 self.markerDeleteHandle(handle)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1954 self.__addBreakPoints(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1955 QModelIndex(), 0, self.breakpointModel.rowCount() - 1)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1956
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1957 def __deleteBreakPoints(self, parentIndex, start, end):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1958 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1959 Private slot to delete breakpoints.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1960
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1961 @param parentIndex index of parent item (QModelIndex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1962 @param start start row (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1963 @param end end row (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1964 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1965 for row in range(start, end + 1):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1966 index = self.breakpointModel.index(row, 0, parentIndex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1967 fn, lineno = self.breakpointModel.getBreakPointByIndex(index)[0:2]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1968 if fn == self.fileName:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1969 self.clearBreakpoint(lineno)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1970
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1971 def __changeBreakPoints(self, startIndex, endIndex):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1972 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1973 Private slot to set changed breakpoints.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1974
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1975 @param startIndex start index of the breakpoints being changed
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1976 (QModelIndex)
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1977 @param endIndex end index of the breakpoints being changed
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1978 (QModelIndex)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1979 """
1928
adde55ed4ce5 Fixed the breakpoint performance issue properly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1897
diff changeset
1980 if not self.inLinesChanged:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1981 self.__addBreakPoints(QModelIndex(), startIndex.row(),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1982 endIndex.row())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1983
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1984 def __breakPointDataAboutToBeChanged(self, startIndex, endIndex):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1985 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1986 Private slot to handle the dataAboutToBeChanged signal of the
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
1987 breakpoint model.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1988
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1989 @param startIndex start index of the rows to be changed (QModelIndex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1990 @param endIndex end index of the rows to be changed (QModelIndex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1991 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1992 self.__deleteBreakPoints(QModelIndex(), startIndex.row(),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
1993 endIndex.row())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1994
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1995 def __addBreakPoints(self, parentIndex, start, end):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1996 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1997 Private slot to add breakpoints.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1998
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
1999 @param parentIndex index of parent item (QModelIndex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2000 @param start start row (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2001 @param end end row (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2002 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2003 for row in range(start, end + 1):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2004 index = self.breakpointModel.index(row, 0, parentIndex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2005 fn, line, cond, temp, enabled, ignorecount = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2006 self.breakpointModel.getBreakPointByIndex(index)[:6]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2007 if fn == self.fileName:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2008 self.newBreakpointWithProperties(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2009 line, (cond, temp, enabled, ignorecount))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2010
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2011 def clearBreakpoint(self, line):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2012 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2013 Public method to clear a breakpoint.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2014
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2015 Note: This doesn't clear the breakpoint in the debugger,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2016 it just deletes it from the editor internal list of breakpoints.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2017
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2018 @param line linenumber of the breakpoint (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2019 """
1758
e18f96b1714b A few optimizations and a fix for a bug, that caused incorrect display of breakpoints in the editor margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1754
diff changeset
2020 if self.inLinesChanged:
e18f96b1714b A few optimizations and a fix for a bug, that caused incorrect display of breakpoints in the editor margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1754
diff changeset
2021 return
e18f96b1714b A few optimizations and a fix for a bug, that caused incorrect display of breakpoints in the editor margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1754
diff changeset
2022
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2023 for handle, (ln, _, _, _, _) in list(self.breaks.items()):
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2024 if self.markerLine(handle) == line - 1:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2025 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2026 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2027 # not found, simply ignore it
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2028 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2029
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2030 del self.breaks[handle]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2031 self.markerDeleteHandle(handle)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2032
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2033 def newBreakpointWithProperties(self, line, properties):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2034 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2035 Private method to set a new breakpoint and its properties.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2036
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2037 @param line line number of the breakpoint (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2038 @param properties properties for the breakpoint (tuple)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2039 (condition, temporary flag, enabled flag, ignore count)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2040 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2041 if not properties[2]:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2042 marker = self.dbreakpoint
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2043 elif properties[0]:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2044 marker = properties[1] and self.tcbreakpoint or self.cbreakpoint
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2045 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2046 marker = properties[1] and self.tbreakpoint or self.breakpoint
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2047
1930
3ecd42f536fd Fixed an issue related to breakpoints and cloned editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1928
diff changeset
2048 if self.markersAtLine(line - 1) & self.breakpointMask == 0:
3ecd42f536fd Fixed an issue related to breakpoints and cloned editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1928
diff changeset
2049 handle = self.markerAdd(line - 1, marker)
3ecd42f536fd Fixed an issue related to breakpoints and cloned editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1928
diff changeset
2050 self.breaks[handle] = (line,) + properties
3ecd42f536fd Fixed an issue related to breakpoints and cloned editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1928
diff changeset
2051 self.breakpointToggled.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2052
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2053 def __toggleBreakpoint(self, line, temporary=False):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2054 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2055 Private method to toggle a breakpoint.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2056
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2057 @param line line number of the breakpoint (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2058 @param temporary flag indicating a temporary breakpoint (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2059 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2060 for handle, (ln, _, _, _, _) in list(self.breaks.items()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2061 if self.markerLine(handle) == line - 1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2062 # delete breakpoint or toggle it to the next state
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2063 index = self.breakpointModel.getBreakPointIndex(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2064 self.fileName, line)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2065 if Preferences.getDebugger("ThreeStateBreakPoints") and \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2066 not self.breakpointModel.isBreakPointTemporaryByIndex(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2067 index):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2068 self.breakpointModel.deleteBreakPointByIndex(index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2069 self.__addBreakPoint(line, True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2070 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2071 self.breakpointModel.deleteBreakPointByIndex(index)
486
e4711a55e482 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 478
diff changeset
2072 self.breakpointToggled.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2073 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2074 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2075 self.__addBreakPoint(line, temporary)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2076
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2077 def __addBreakPoint(self, line, temporary):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2078 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2079 Private method to add a new breakpoint.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2080
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2081 @param line line number of the breakpoint (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2082 @param temporary flag indicating a temporary breakpoint (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2083 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2084 if self.fileName and \
1762
307393ebe9c6 Some little optimisations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1758
diff changeset
2085 (self.isPy3File() or self.isPy2File() or self.isRubyFile()):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2086 self.breakpointModel.addBreakPoint(self.fileName, line,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2087 ('', temporary, True, 0))
486
e4711a55e482 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 478
diff changeset
2088 self.breakpointToggled.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2089
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2090 def __toggleBreakpointEnabled(self, line):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2091 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2092 Private method to toggle a breakpoints enabled status.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2093
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2094 @param line line number of the breakpoint (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2095 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2096 for handle, (ln, cond, temp, enabled, ignorecount) in \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2097 self.breaks.items():
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2098 if self.markerLine(handle) == line - 1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2099 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2100 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2101 # no breakpoint found on that line
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2102 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2103
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2104 index = self.breakpointModel.getBreakPointIndex(self.fileName, line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2105 self.breakpointModel.setBreakPointEnabledByIndex(index, not enabled)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2106
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2107 def curLineHasBreakpoint(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2108 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2109 Public method to check for the presence of a breakpoint at the current
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2110 line.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2111
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2112 @return flag indicating the presence of a breakpoint (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2113 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2114 line, _ = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2115 return self.markersAtLine(line) & self.breakpointMask != 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2116
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2117 def hasBreakpoints(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2118 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2119 Public method to check for the presence of breakpoints.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2120
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2121 @return flag indicating the presence of breakpoints (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2122 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2123 return len(self.breaks) > 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2124
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2125 def __menuToggleTemporaryBreakpoint(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2126 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2127 Private slot to handle the 'Toggle temporary breakpoint' context menu
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2128 action.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2129 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2130 if self.line < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2131 self.line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2132 self.line += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2133 self.__toggleBreakpoint(self.line, 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2134 self.line = -1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2135
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2136 def menuToggleBreakpoint(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2137 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2138 Public slot to handle the 'Toggle breakpoint' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2139 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2140 if self.line < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2141 self.line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2142 self.line += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2143 self.__toggleBreakpoint(self.line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2144 self.line = -1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2145
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2146 def __menuToggleBreakpointEnabled(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2147 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2148 Private slot to handle the 'Enable/Disable breakpoint' context menu
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2149 action.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2150 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2151 if self.line < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2152 self.line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2153 self.line += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2154 self.__toggleBreakpointEnabled(self.line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2155 self.line = -1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2156
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2157 def menuEditBreakpoint(self, line=None):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2158 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2159 Public slot to handle the 'Edit breakpoint' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2160
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2161 @param line linenumber of the breakpoint to edit
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2162 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2163 if line is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2164 self.line = line - 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2165 if self.line < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2166 self.line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2167 found = False
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2168 for handle, (ln, cond, temp, enabled, ignorecount) in \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2169 self.breaks.items():
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2170 if self.markerLine(handle) == self.line:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2171 found = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2172 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2173
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2174 if found:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2175 index = self.breakpointModel.getBreakPointIndex(self.fileName, ln)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2176 if not index.isValid():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2177 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2178
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
2179 from Debugger.EditBreakpointDialog import EditBreakpointDialog
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2180 dlg = EditBreakpointDialog((self.fileName, ln),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2181 (cond, temp, enabled, ignorecount),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2182 self.condHistory, self, modal=True)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2183 if dlg.exec_() == QDialog.Accepted:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2184 cond, temp, enabled, ignorecount = dlg.getData()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2185 self.breakpointModel.setBreakPointByIndex(index,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2186 self.fileName, ln, (cond, temp, enabled, ignorecount))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2187
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2188 self.line = -1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2189
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2190 def menuNextBreakpoint(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2191 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2192 Public slot to handle the 'Next breakpoint' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2193 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2194 line, index = self.getCursorPosition()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2195 if line == self.lines() - 1:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2196 line = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2197 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2198 line += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2199 bpline = self.markerFindNext(line, self.breakpointMask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2200 if bpline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2201 # wrap around
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2202 bpline = self.markerFindNext(0, self.breakpointMask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2203 if bpline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2204 self.setCursorPosition(bpline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2205 self.ensureLineVisible(bpline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2206
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2207 def menuPreviousBreakpoint(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2208 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2209 Public slot to handle the 'Previous breakpoint' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2210 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2211 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2212 if line == 0:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2213 line = self.lines() - 1
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2214 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2215 line -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2216 bpline = self.markerFindPrevious(line, self.breakpointMask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2217 if bpline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2218 # wrap around
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2219 bpline = self.markerFindPrevious(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2220 self.lines() - 1, self.breakpointMask)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2221 if bpline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2222 self.setCursorPosition(bpline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2223 self.ensureLineVisible(bpline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2224
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2225 def __menuClearBreakpoints(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2226 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2227 Private slot to handle the 'Clear all breakpoints' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2228 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2229 self.__clearBreakpoints(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2230
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2231 def __clearBreakpoints(self, fileName):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2232 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2233 Private slot to clear all breakpoints.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
2234
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
2235 @param fileName name of the file (string)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2236 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2237 idxList = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2238 for handle, (ln, _, _, _, _) in list(self.breaks.items()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2239 index = self.breakpointModel.getBreakPointIndex(fileName, ln)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2240 if index.isValid():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2241 idxList.append(index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2242 if idxList:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2243 self.breakpointModel.deleteBreakPoints(idxList)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2244
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2245 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2246 ## Bookmark handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2247 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2248
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2249 def toggleBookmark(self, line):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2250 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2251 Public method to toggle a bookmark.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2252
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2253 @param line line number of the bookmark (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2254 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2255 for handle in self.bookmarks:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2256 if self.markerLine(handle) == line - 1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2257 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2258 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2259 # set a new bookmark
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2260 handle = self.markerAdd(line - 1, self.bookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2261 self.bookmarks.append(handle)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
2262 self.bookmarkToggled.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2263 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2264
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2265 self.bookmarks.remove(handle)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2266 self.markerDeleteHandle(handle)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
2267 self.bookmarkToggled.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2268
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2269 def getBookmarks(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2270 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2271 Public method to retrieve the bookmarks.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2272
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2273 @return sorted list of all lines containing a bookmark
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2274 (list of integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2275 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2276 bmlist = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2277 for handle in self.bookmarks:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2278 bmlist.append(self.markerLine(handle) + 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2279
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2280 bmlist.sort()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2281 return bmlist
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2282
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2283 def hasBookmarks(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2284 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2285 Public method to check for the presence of bookmarks.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2286
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2287 @return flag indicating the presence of bookmarks (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2288 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2289 return len(self.bookmarks) > 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2290
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2291 def menuToggleBookmark(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2292 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2293 Public slot to handle the 'Toggle bookmark' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2294 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2295 if self.line < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2296 self.line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2297 self.line += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2298 self.toggleBookmark(self.line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2299 self.line = -1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2300
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2301 def nextBookmark(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2302 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2303 Public slot to handle the 'Next bookmark' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2304 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2305 line, index = self.getCursorPosition()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2306 if line == self.lines() - 1:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2307 line = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2308 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2309 line += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2310 bmline = self.markerFindNext(line, 1 << self.bookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2311 if bmline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2312 # wrap around
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2313 bmline = self.markerFindNext(0, 1 << self.bookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2314 if bmline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2315 self.setCursorPosition(bmline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2316 self.ensureLineVisible(bmline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2317
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2318 def previousBookmark(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2319 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2320 Public slot to handle the 'Previous bookmark' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2321 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2322 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2323 if line == 0:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2324 line = self.lines() - 1
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2325 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2326 line -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2327 bmline = self.markerFindPrevious(line, 1 << self.bookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2328 if bmline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2329 # wrap around
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2330 bmline = self.markerFindPrevious(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2331 self.lines() - 1, 1 << self.bookmark)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2332 if bmline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2333 self.setCursorPosition(bmline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2334 self.ensureLineVisible(bmline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2335
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2336 def clearBookmarks(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2337 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2338 Public slot to handle the 'Clear all bookmarks' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2339 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2340 for handle in self.bookmarks:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2341 self.markerDeleteHandle(handle)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2342 self.bookmarks = []
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
2343 self.bookmarkToggled.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2344
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2345 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2346 ## Printing methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2347 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2348
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2349 def printFile(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2350 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2351 Public slot to print the text.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2352 """
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
2353 from .Printer import Printer
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2354 printer = Printer(mode=QPrinter.HighResolution)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2355 sb = e5App().getObject("UserInterface").statusBar()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2356 printDialog = QPrintDialog(printer, self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2357 if self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2358 printDialog.addEnabledOption(QAbstractPrintDialog.PrintSelection)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2359 if printDialog.exec_() == QDialog.Accepted:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2360 sb.showMessage(self.trUtf8('Printing...'))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2361 QApplication.processEvents()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2362 fn = self.getFileName()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2363 if fn is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2364 printer.setDocName(os.path.basename(fn))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2365 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2366 printer.setDocName(self.noName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2367 if printDialog.printRange() == QAbstractPrintDialog.Selection:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2368 # get the selection
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2369 fromLine, fromIndex, toLine, toIndex = self.getSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2370 if toIndex == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2371 toLine -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2372 # Qscintilla seems to print one line more than told
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2373 res = printer.printRange(self, fromLine, toLine - 1)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2374 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2375 res = printer.printRange(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2376 if res:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2377 sb.showMessage(self.trUtf8('Printing completed'), 2000)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2378 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2379 sb.showMessage(self.trUtf8('Error while printing'), 2000)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2380 QApplication.processEvents()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2381 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2382 sb.showMessage(self.trUtf8('Printing aborted'), 2000)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2383 QApplication.processEvents()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2384
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2385 def printPreviewFile(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2386 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2387 Public slot to show a print preview of the text.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2388 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2389 from PyQt4.QtGui import QPrintPreviewDialog
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
2390 from .Printer import Printer
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2391
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2392 printer = Printer(mode=QPrinter.HighResolution)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2393 fn = self.getFileName()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2394 if fn is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2395 printer.setDocName(os.path.basename(fn))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2396 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2397 printer.setDocName(self.noName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2398 preview = QPrintPreviewDialog(printer, self)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
2399 preview.paintRequested.connect(self.__printPreview)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2400 preview.exec_()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2401
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2402 def __printPreview(self, printer):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2403 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2404 Private slot to generate a print preview.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2405
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2406 @param printer reference to the printer object
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2407 (QScintilla.Printer.Printer)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2408 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2409 printer.printRange(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2410
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2411 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2412 ## Task handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2413 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2414
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2415 def hasTaskMarkers(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2416 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2417 Public method to determine, if this editor contains any task markers.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2418
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2419 @return flag indicating the presence of task markers (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2420 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2421 return self.__hasTaskMarkers
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2422
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2423 def nextTask(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2424 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2425 Public slot to handle the 'Next task' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2426 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2427 line, index = self.getCursorPosition()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2428 if line == self.lines() - 1:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2429 line = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2430 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2431 line += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2432 taskline = self.markerFindNext(line, 1 << self.taskmarker)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2433 if taskline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2434 # wrap around
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2435 taskline = self.markerFindNext(0, 1 << self.taskmarker)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2436 if taskline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2437 self.setCursorPosition(taskline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2438 self.ensureLineVisible(taskline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2439
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2440 def previousTask(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2441 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2442 Public slot to handle the 'Previous task' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2443 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2444 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2445 if line == 0:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2446 line = self.lines() - 1
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2447 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2448 line -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2449 taskline = self.markerFindPrevious(line, 1 << self.taskmarker)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2450 if taskline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2451 # wrap around
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2452 taskline = self.markerFindPrevious(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2453 self.lines() - 1, 1 << self.taskmarker)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2454 if taskline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2455 self.setCursorPosition(taskline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2456 self.ensureLineVisible(taskline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2457
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2458 def extractTasks(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2459 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2460 Public slot to extract all tasks.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2461 """
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
2462 from Tasks.Task import Task
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2463 markers = {
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2464 Task.TypeWarning:
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2465 Preferences.getTasks("TasksWarningMarkers").split(),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2466 Task.TypeNote:
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2467 Preferences.getTasks("TasksNoteMarkers").split(),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2468 Task.TypeTodo:
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2469 Preferences.getTasks("TasksTodoMarkers").split(),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2470 Task.TypeFixme:
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2471 Preferences.getTasks("TasksFixmeMarkers").split(),
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2472 }
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2473 txtList = self.text().split(self.getLineSeparator())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2474
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2475 # clear all task markers and tasks
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2476 self.markerDeleteAll(self.taskmarker)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2477 self.taskViewer.clearFileTasks(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2478 self.__hasTaskMarkers = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2479
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2480 # now search tasks and record them
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2481 lineIndex = -1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2482 for line in txtList:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2483 lineIndex += 1
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2484 shouldBreak = False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2485
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2486 for taskType, taskMarkers in markers.items():
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2487 for taskMarker in taskMarkers:
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2488 index = line.find(taskMarker)
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2489 if index > -1:
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2490 task = line[index:]
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2491 self.markerAdd(lineIndex, self.taskmarker)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2492 self.taskViewer.addFileTask(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2493 task, self.fileName, lineIndex + 1, taskType)
1819
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2494 self.__hasTaskMarkers = True
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2495 shouldBreak = True
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2496 break
cfcfd617216a Changed the tasks handling to allow for more fine grained task designations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1807
diff changeset
2497 if shouldBreak:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2498 break
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
2499 self.taskMarkersUpdated.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2500
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2501 ###########################################################################
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2502 ## Change tracing methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2503 ###########################################################################
2165
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2504
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2505 def __createChangeMarkerPixmap(self, key, size=16, width=4):
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2506 """
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2507 Private method to create a pixmap for the change markers.
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2508
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2509 @param key key of the color to use (string)
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2510 @param size size of the pixmap (integer)
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2511 @param width width of the marker line (integer)
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2512 @return create pixmap (QPixmap)
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2513 """
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2514 pixmap = QPixmap(size, size)
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2515 pixmap.fill(Qt.transparent)
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2516 painter = QPainter(pixmap)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2517 painter.fillRect(size - 4, 0, 4, size,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2518 Preferences.getEditorColour(key))
2165
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2519 painter.end()
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2520 return pixmap
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2521
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2522 def __initOnlineChangeTrace(self):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2523 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2524 Private slot to initialize the online change trace.
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2525 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2526 self.__hasChangeMarkers = False
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2527 self.__oldText = self.text()
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2528 self.__lastSavedText = self.text()
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2529 self.__onlineChangeTraceTimer = QTimer(self)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2530 self.__onlineChangeTraceTimer.setSingleShot(True)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2531 self.__onlineChangeTraceTimer.setInterval(
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2532 Preferences.getEditor("OnlineChangeTraceInterval"))
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2533 self.__onlineChangeTraceTimer.timeout.connect(
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2534 self.__onlineChangeTraceTimerTimeout)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2535 self.textChanged.connect(self.__resetOnlineChangeTraceTimer)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2536
2189
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
2537 def __reinitOnlineChangeTrace(self):
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
2538 """
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
2539 Private slot to re-initialize the online change trace.
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
2540 """
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
2541 self.__oldText = self.text()
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
2542 self.__lastSavedText = self.text()
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
2543 self.__deleteAllChangeMarkers()
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
2544
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2545 def __resetOnlineChangeTraceTimer(self):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2546 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2547 Private method to reset the online syntax check timer.
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2548 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2549 if Preferences.getEditor("OnlineChangeTrace"):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2550 self.__onlineChangeTraceTimer.stop()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2551 self.__onlineChangeTraceTimer.start()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2552
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2553 def __onlineChangeTraceTimerTimeout(self):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2554 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2555 Private slot to mark added and changed lines.
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2556 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2557 self.__deleteAllChangeMarkers()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2558
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2559 # step 1: mark saved changes
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2560 oldL = self.__oldText.splitlines()
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2561 newL = self.__lastSavedText.splitlines()
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2562 matcher = difflib.SequenceMatcher(None, oldL, newL)
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2563
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2564 for token, i1, i2, j1, j2 in matcher.get_opcodes():
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2565 if token in ["insert", "replace"]:
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2566 for lineNo in range(j1, j2):
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2567 self.markerAdd(lineNo, self.__changeMarkerSaved)
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2568 self.__hasChangeMarkers = True
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2569
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2570 # step 2: mark unsaved changes
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2571 oldL = self.__lastSavedText.splitlines()
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2572 newL = self.text().splitlines()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2573 matcher = difflib.SequenceMatcher(None, oldL, newL)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2574
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2575 for token, i1, i2, j1, j2 in matcher.get_opcodes():
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2576 if token in ["insert", "replace"]:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2577 for lineNo in range(j1, j2):
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2578 self.markerAdd(lineNo, self.__changeMarkerUnsaved)
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2579 self.__hasChangeMarkers = True
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2580
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2581 if self.__hasChangeMarkers:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2582 self.changeMarkersUpdated.emit(self)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2583
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2584 def __resetOnlineChangeTraceInfo(self):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2585 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2586 Private slot to reset the online change trace info.
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2587 """
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2588 self.__lastSavedText = self.text()
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2589 self.__deleteAllChangeMarkers()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2590
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2591 # mark saved changes
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2592 oldL = self.__oldText.splitlines()
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2593 newL = self.__lastSavedText.splitlines()
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2594 matcher = difflib.SequenceMatcher(None, oldL, newL)
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2595
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2596 for token, i1, i2, j1, j2 in matcher.get_opcodes():
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2597 if token in ["insert", "replace"]:
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2598 for lineNo in range(j1, j2):
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2599 self.markerAdd(lineNo, self.__changeMarkerSaved)
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2600 self.__hasChangeMarkers = True
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2601
2165
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2602 if self.__hasChangeMarkers:
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2603 self.changeMarkersUpdated.emit(self)
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
2604
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2605 def __deleteAllChangeMarkers(self):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2606 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2607 Private slot to delete all change markers.
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2608 """
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2609 self.markerDeleteAll(self.__changeMarkerUnsaved)
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2610 self.markerDeleteAll(self.__changeMarkerSaved)
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2611 self.__hasChangeMarkers = False
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2612 self.changeMarkersUpdated.emit(self)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2613
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2614 def hasChangeMarkers(self):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2615 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2616 Public method to determine, if this editor contains any change markers.
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2617
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2618 @return flag indicating the presence of change markers (boolean)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2619 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2620 return self.__hasChangeMarkers
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2621
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2622 def nextChange(self):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2623 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2624 Public slot to handle the 'Next change' context menu action.
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2625 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2626 line, index = self.getCursorPosition()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2627 if line == self.lines() - 1:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2628 line = 0
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2629 else:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2630 line += 1
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2631 changeline = self.markerFindNext(line, self.changeMarkersMask)
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2632 if changeline < 0:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2633 # wrap around
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2634 changeline = self.markerFindNext(0, self.changeMarkersMask)
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2635 if changeline >= 0:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2636 self.setCursorPosition(changeline, 0)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2637 self.ensureLineVisible(changeline)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2638
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2639 def previousChange(self):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2640 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2641 Public slot to handle the 'Previous task' context menu action.
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2642 """
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2643 line, index = self.getCursorPosition()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2644 if line == 0:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2645 line = self.lines() - 1
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2646 else:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2647 line -= 1
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
2648 changeline = self.markerFindPrevious(line, self.changeMarkersMask)
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2649 if changeline < 0:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2650 # wrap around
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2651 changeline = self.markerFindPrevious(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2652 self.lines() - 1, self.changeMarkersMask)
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2653 if changeline >= 0:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2654 self.setCursorPosition(changeline, 0)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2655 self.ensureLineVisible(changeline)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2656
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2657 ###########################################################################
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2658 ## Flags handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2659 ###########################################################################
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2660
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2661 def __processFlags(self):
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2662 """
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2663 Private method to extract flags and process them.
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2664
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2665 @return list of change flags (list of string)
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2666 """
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2667 txt = self.text()
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2668 flags = Utilities.extractFlags(txt)
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2669
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2670 changedFlags = []
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2671
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2672 # Flag 1: FileType
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2673 if "FileType" in flags:
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2674 oldFiletype = self.filetype
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2675 if isinstance(flags["FileType"], str):
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2676 self.filetype = flags["FileType"]
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2677 self.filetypeByFlag = True
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2678 if oldFiletype != self.filetype:
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2679 changedFlags.append("FileType")
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2680 else:
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2681 if self.filetype != "" and self.filetypeByFlag:
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2682 self.filetype = ""
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2683 self.filetypeByFlag = False
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2684 self.__bindName(txt.splitlines()[0])
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2685 changedFlags.append("FileType")
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2686
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2687 return changedFlags
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2688
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2689 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2690 ## File handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2691 ###########################################################################
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2692
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2693 def checkDirty(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2694 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2695 Public method to check dirty status and open a message window.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2696
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2697 @return flag indicating successful reset of the dirty flag (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2698 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2699 if self.isModified():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2700 fn = self.fileName
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2701 if fn is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2702 fn = self.noName
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2703 res = E5MessageBox.okToClearData(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2704 self.trUtf8("File Modified"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2705 self.trUtf8("<p>The file <b>{0}</b> has unsaved changes.</p>")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2706 .format(fn),
549
fe99d46d56c8 Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 548
diff changeset
2707 self.saveFile)
fe99d46d56c8 Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 548
diff changeset
2708 if res:
fe99d46d56c8 Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 548
diff changeset
2709 self.vm.setEditorName(self, self.fileName)
fe99d46d56c8 Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 548
diff changeset
2710 return res
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2711
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2712 return True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2713
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2714 def revertToUnmodified(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2715 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2716 Public method to revert back to the last saved state.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2717 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2718 undo_ = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2719 while self.isModified():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2720 if undo_:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2721 # try undo first
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2722 if self.isUndoAvailable():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2723 self.undo()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2724 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2725 undo_ = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2726 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2727 # try redo next
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2728 if self.isRedoAvailable():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2729 self.redo()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2730 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2731 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2732 # Couldn't find the unmodified state
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2733
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2734 def readFile(self, fn, createIt=False):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2735 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2736 Public slot to read the text from a file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2737
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2738 @param fn filename to read from (string)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2739 @param createIt flag indicating the creation of a new file, if the
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2740 given one doesn't exist (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2741 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2742 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2743
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2744 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2745 if createIt and not os.path.exists(fn):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2746 f = open(fn, "w")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2747 f.close()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2748 txt, self.encoding = Utilities.readEncodedFile(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2749 except (UnicodeDecodeError, IOError) as why:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2750 QApplication.restoreOverrideCursor()
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 536
diff changeset
2751 E5MessageBox.critical(self.vm, self.trUtf8('Open File'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2752 self.trUtf8('<p>The file <b>{0}</b> could not be opened.</p>'
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2753 '<p>Reason: {1}</p>')
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2754 .format(fn, str(why)))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2755 QApplication.restoreOverrideCursor()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2756 raise
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2757 fileEol = self.detectEolString(txt)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2758
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2759 modified = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2760 if (not Preferences.getEditor("TabForIndentation")) and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2761 Preferences.getEditor("ConvertTabsOnLoad") and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2762 not (self.lexer_ and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2763 self.lexer_.alwaysKeepTabs()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2764 txtExpanded = txt.expandtabs(Preferences.getEditor("TabWidth"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2765 if txtExpanded != txt:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2766 modified = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2767 txt = txtExpanded
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2768 del txtExpanded
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2769
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2770 self.setText(txt)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2771
788
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2772 # get eric specific flags
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2773 self.__processFlags()
5b1b59777460 Added a feature where flags can be given at the end of a source file. The only flag supported is 'FileType' to overwrite the filetype detection mechanism.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 777
diff changeset
2774
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2775 # perform automatic eol conversion
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2776 if Preferences.getEditor("AutomaticEOLConversion"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2777 self.convertEols(self.eolMode())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2778 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2779 self.setEolModeByEolString(fileEol)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2780
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2781 self.extractTasks()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2782
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2783 QApplication.restoreOverrideCursor()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2784
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2785 self.setModified(modified)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2786 self.lastModified = QFileInfo(self.fileName).lastModified()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2787
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2788 def __removeTrailingWhitespace(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2789 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2790 Private method to remove trailing whitespace.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2791 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2792 searchRE = r"[ \t]+$" # whitespace at the end of a line
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2793
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2794 ok = self.findFirstTarget(searchRE, True, False, False, 0, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2795 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2796 while ok:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2797 self.replaceTarget("")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2798 ok = self.findNextTarget()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2799 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2800
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2801 def writeFile(self, fn):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2802 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2803 Public slot to write the text to a file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2804
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2805 @param fn filename to write to (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2806 @return flag indicating success (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2807 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2808 if Preferences.getEditor("StripTrailingWhitespace"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2809 self.__removeTrailingWhitespace()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2810
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2811 txt = self.text()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2812 # work around glitch in scintilla: always make sure,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2813 # that the last line is terminated properly
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2814 eol = self.getLineSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2815 if eol:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2816 if len(txt) >= len(eol):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2817 if txt[-len(eol):] != eol:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2818 txt += eol
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2819 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2820 txt += eol
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2821
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2822 # create a backup file, if the option is set
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2823 createBackup = Preferences.getEditor("CreateBackupFile")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2824 if createBackup:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2825 if os.path.islink(fn):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2826 fn = os.path.realpath(fn)
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
2827 bfn = '{0}~'.format(fn)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2828 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2829 permissions = os.stat(fn).st_mode
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2830 perms_valid = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2831 except EnvironmentError:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2832 # if there was an error, ignore it
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2833 perms_valid = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2834 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2835 os.remove(bfn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2836 except EnvironmentError:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2837 # if there was an error, ignore it
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2838 pass
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2839 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2840 os.rename(fn, bfn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2841 except EnvironmentError:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2842 # if there was an error, ignore it
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2843 pass
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2844
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2845 # now write text to the file fn
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2846 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2847 self.encoding = Utilities.writeEncodedFile(fn, txt, self.encoding)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2848 if createBackup and perms_valid:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2849 os.chmod(fn, permissions)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2850 return True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2851 except (IOError, Utilities.CodingError, UnicodeError) as why:
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 536
diff changeset
2852 E5MessageBox.critical(self, self.trUtf8('Save File'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2853 self.trUtf8('<p>The file <b>{0}</b> could not be saved.<br/>'
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2854 'Reason: {1}</p>')
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2855 .format(fn, str(why)))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2856 return False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2857
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2858 def saveFile(self, saveas=False, path=None):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2859 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2860 Public slot to save the text to a file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2861
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2862 @param saveas flag indicating a 'save as' action (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2863 @param path directory to save the file in (string)
548
ac7af05dd54a Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 547
diff changeset
2864 @return flag indicating success (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2865 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2866 if not saveas and not self.isModified():
548
ac7af05dd54a Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 547
diff changeset
2867 return False # do nothing if text wasn't changed
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2868
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2869 newName = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2870 if saveas or self.fileName is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2871 saveas = True
825
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2872
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2873 # save to project, if a project is loaded
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2874 if self.project.isOpen():
994
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
2875 if self.fileName is not None and \
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
2876 self.project.startswithProjectPath(self.fileName):
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
2877 path = os.path.dirname(self.fileName)
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
2878 else:
8ed60a191a3a Fixed an issue in isPy2File and isPy3File in the editor and refined the save as function when a project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 991
diff changeset
2879 path = self.project.getProjectPath()
825
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2880
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2881 if not path and self.fileName is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2882 path = os.path.dirname(self.fileName)
1939
eadb2328d7d4 Introduced a "workspace" directory that is used as the default for opening or saving new files or projects (configurable on Multiproject config page).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1930
diff changeset
2883 if not path:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2884 path = Preferences.getMultiProject("Workspace") or \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2885 Utilities.getHomeDir()
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
2886
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
2887 from . import Lexers
1978
1366fb8e7aed A little enhancement to the editor "Save As" function to use the extension of the current file to select the filter for the file dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1940
diff changeset
2888 if self.fileName:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2889 filterPattern = "(*{0})".format(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2890 os.path.splitext(self.fileName)[1])
1978
1366fb8e7aed A little enhancement to the editor "Save As" function to use the extension of the current file to select the filter for the file dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1940
diff changeset
2891 for filter in Lexers.getSaveFileFiltersList(True):
1366fb8e7aed A little enhancement to the editor "Save As" function to use the extension of the current file to select the filter for the file dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1940
diff changeset
2892 if filterPattern in filter:
1366fb8e7aed A little enhancement to the editor "Save As" function to use the extension of the current file to select the filter for the file dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1940
diff changeset
2893 defaultFilter = filter
1366fb8e7aed A little enhancement to the editor "Save As" function to use the extension of the current file to select the filter for the file dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1940
diff changeset
2894 break
1366fb8e7aed A little enhancement to the editor "Save As" function to use the extension of the current file to select the filter for the file dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1940
diff changeset
2895 else:
1366fb8e7aed A little enhancement to the editor "Save As" function to use the extension of the current file to select the filter for the file dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1940
diff changeset
2896 defaultFilter = Preferences.getEditor("DefaultSaveFilter")
1366fb8e7aed A little enhancement to the editor "Save As" function to use the extension of the current file to select the filter for the file dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1940
diff changeset
2897 else:
1366fb8e7aed A little enhancement to the editor "Save As" function to use the extension of the current file to select the filter for the file dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1940
diff changeset
2898 defaultFilter = Preferences.getEditor("DefaultSaveFilter")
520
b0f523c3b037 Added code to cope with Linux distributor's usage of KDE wrapper dialogs for the Qt file dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 507
diff changeset
2899 fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2900 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2901 self.trUtf8("Save File"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2902 path,
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2903 Lexers.getSaveFileFiltersList(True, True),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2904 defaultFilter,
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
2905 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2906
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2907 if fn:
718
979d6e242404 Fixed an issue in the editor saving files without extension on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 564
diff changeset
2908 if fn.endswith("."):
979d6e242404 Fixed an issue in the editor saving files without extension on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 564
diff changeset
2909 fn = fn[:-1]
979d6e242404 Fixed an issue in the editor saving files without extension on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 564
diff changeset
2910
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2911 ext = QFileInfo(fn).suffix()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2912 if not ext:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2913 ex = selectedFilter.split("(*")[1].split(")")[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2914 if ex:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2915 fn += ex
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2916 if QFileInfo(fn).exists():
546
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 542
diff changeset
2917 res = E5MessageBox.yesNo(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2918 self.trUtf8("Save File"),
546
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 542
diff changeset
2919 self.trUtf8("<p>The file <b>{0}</b> already exists."
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 542
diff changeset
2920 " Overwrite it?</p>").format(fn),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2921 icon=E5MessageBox.Warning)
546
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 542
diff changeset
2922 if not res:
548
ac7af05dd54a Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 547
diff changeset
2923 return False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2924 fn = Utilities.toNativeSeparators(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2925 newName = fn
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2926 else:
548
ac7af05dd54a Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 547
diff changeset
2927 return False
825
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2928
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2929 # save to project, if a project is loaded
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2930 if self.project.isOpen() and \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2931 self.project.startswithProjectPath(fn):
825
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2932 self.setEolModeByEolString(self.project.getEolString())
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2933 self.convertEols(self.eolMode())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2934 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2935 fn = self.fileName
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2936
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
2937 self.editorAboutToBeSaved.emit(self.fileName)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2938 if self.writeFile(fn):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2939 if saveas:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2940 self.__clearBreakpoints(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2941 self.fileName = fn
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2942 self.setModified(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2943 self.setReadOnly(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2944 self.setWindowTitle(self.fileName)
789
c190cd71b097 Fixed an issue introduced by the latest change.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 788
diff changeset
2945 # get eric specific flags
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2946 changedFlags = self.__processFlags()
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
2947 if not self.__lexerReset and "FileType" in changedFlags:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2948 self.setLanguage(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2949
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2950 if saveas:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2951 self.isResourcesFile = self.fileName.endswith(".qrc")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2952 self.__initContextMenu()
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
2953 self.editorRenamed.emit(self.fileName)
825
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2954
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2955 # save to project, if a project is loaded
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2956 if self.project.isOpen() and \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2957 self.project.startswithProjectPath(fn):
825
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2958 self.project.appendFile(self.fileName)
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2959 self.addedToProject()
2517
495777476cc4 Added a line to the editor to reset the lexer after a file was saved to a project (in order to apply project specific lexer settings).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2493
diff changeset
2960 self.setLanguage(self.fileName)
825
9cdec3c5bc07 Merged "Save to Project" into "Save" and "Save As...".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 812
diff changeset
2961
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2962 self.lastModified = QFileInfo(self.fileName).lastModified()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2963 if newName is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2964 self.vm.addToRecentList(newName)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
2965 self.editorSaved.emit(self.fileName)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2966 self.__autoSyntaxCheck()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2967 self.extractTasks()
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
2968 self.__resetOnlineChangeTraceInfo()
548
ac7af05dd54a Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 547
diff changeset
2969 return True
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2970 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2971 self.lastModified = QFileInfo(fn).lastModified()
548
ac7af05dd54a Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 547
diff changeset
2972 return False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2973
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
2974 def saveFileAs(self, path=None, toProject=False):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2975 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2976 Public slot to save a file with a new name.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2977
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2978 @param path directory to save the file in (string)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2979 @keyparam toProject flag indicating a save to project operation
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2980 (boolean)
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2981 @return tuple of two values (boolean, string) giving a success
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
2982 indicator and the name of the saved file
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2983 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2984 return self.saveFile(True, path)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2985
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2986 def handleRenamed(self, fn):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2987 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2988 Public slot to handle the editorRenamed signal.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2989
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2990 @param fn filename to be set for the editor (string).
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2991 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2992 self.__clearBreakpoints(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2993
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2994 self.fileName = fn
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2995 self.setWindowTitle(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2996
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2997 if self.lexer_ is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2998 self.setLanguage(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
2999
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3000 self.lastModified = QFileInfo(self.fileName).lastModified()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3001 self.vm.setEditorName(self, self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3002 self.__updateReadOnly(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3003
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3004 def fileRenamed(self, fn):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3005 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3006 Public slot to handle the editorRenamed signal.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3007
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3008 @param fn filename to be set for the editor (string).
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3009 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3010 self.handleRenamed(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3011 if not self.inFileRenamed:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3012 self.inFileRenamed = True
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
3013 self.editorRenamed.emit(self.fileName)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3014 self.inFileRenamed = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3015
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3016 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3017 ## Utility methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3018 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3019
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3020 def ensureVisible(self, line):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3021 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3022 Public slot to ensure, that the specified line is visible.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3023
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3024 @param line line number to make visible
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3025 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3026 self.ensureLineVisible(line - 1)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3027
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3028 def ensureVisibleTop(self, line):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3029 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3030 Public slot to ensure, that the specified line is visible at the top
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3031 of the editor.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3032
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3033 @param line line number to make visible
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3034 """
1897
4c89af5a756f Little improvement to the editor assembly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1831
diff changeset
3035 self.setFirstVisibleLine(line - 1)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3036
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3037 def __marginClicked(self, margin, line, modifiers):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3038 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3039 Private slot to handle the marginClicked signal.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3040
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3041 @param margin id of the clicked margin (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3042 @param line line number of the click (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3043 @param modifiers keyboard modifiers (Qt.KeyboardModifiers)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3044 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3045 if self.__unifiedMargins:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3046 if margin == 1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3047 if modifiers & Qt.KeyboardModifiers(Qt.ShiftModifier):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3048 if self.marginMenuActs["LMBbreakpoints"].isChecked():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3049 self.toggleBookmark(line + 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3050 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3051 self.__toggleBreakpoint(line + 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3052 elif modifiers & Qt.KeyboardModifiers(Qt.ControlModifier):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3053 if self.markersAtLine(line) & (1 << self.syntaxerror):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3054 self.__showSyntaxError(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3055 elif self.markersAtLine(line) & (1 << self.warning):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3056 self.__showFlakesWarning(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3057 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3058 if self.marginMenuActs["LMBbreakpoints"].isChecked():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3059 self.__toggleBreakpoint(line + 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3060 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3061 self.toggleBookmark(line + 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3062 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3063 if margin == self.__bmMargin:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3064 self.toggleBookmark(line + 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3065 elif margin == self.__bpMargin:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3066 self.__toggleBreakpoint(line + 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3067 elif margin == self.__indicMargin:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3068 if self.markersAtLine(line) & (1 << self.syntaxerror):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3069 self.__showSyntaxError(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3070 elif self.markersAtLine(line) & (1 << self.warning):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3071 self.__showFlakesWarning(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3072
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3073 def handleMonospacedEnable(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3074 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3075 Private slot to handle the Use Monospaced Font context menu entry.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3076 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3077 if self.menuActs["MonospacedFont"].isChecked():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3078 self.setMonospaced(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3079 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3080 if self.lexer_:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3081 self.lexer_.readSettings(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3082 Preferences.Prefs.settings, "Scintilla")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3083 self.lexer_.initProperties()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3084 self.setMonospaced(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3085 self.__setMarginsDisplay()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3086
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3087 def getWordBoundaries(self, line, index, useWordChars=True):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3088 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3089 Public method to get the word boundaries at a position.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3090
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3091 @param line number of line to look at (int)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3092 @param index position to look at (int)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3093 @keyparam useWordChars flag indicating to use the wordCharacters
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3094 method (boolean)
2213
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3095 @return tuple with start and end indexes of the word at the position
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3096 (integer, integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3097 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3098 text = self.text(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3099 if self.caseSensitive():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3100 cs = Qt.CaseSensitive
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3101 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3102 cs = Qt.CaseInsensitive
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3103 wc = self.wordCharacters()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3104 if wc is None or not useWordChars:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3105 regExp = QRegExp('[^\w_]', cs)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3106 else:
448
a1f1b226ff4b Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
3107 wc = re.sub('\w', "", wc)
a1f1b226ff4b Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 429
diff changeset
3108 regExp = QRegExp('[^\w{0}]'.format(re.escape(wc)), cs)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3109 start = regExp.lastIndexIn(text, index) + 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3110 end = regExp.indexIn(text, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3111 if start == end + 1 and index > 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3112 # we are on a word boundary, try again
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3113 start = regExp.lastIndexIn(text, index - 1) + 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3114 if start == -1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3115 start = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3116 if end == -1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3117 end = len(text)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3118
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3119 return (start, end)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3120
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3121 def getWord(self, line, index, direction=0, useWordChars=True):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3122 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3123 Public method to get the word at a position.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3124
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3125 @param line number of line to look at (int)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3126 @param index position to look at (int)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3127 @param direction direction to look in (0 = whole word, 1 = left,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3128 2 = right)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3129 @keyparam useWordChars flag indicating to use the wordCharacters
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3130 method (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3131 @return the word at that position (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3132 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3133 start, end = self.getWordBoundaries(line, index, useWordChars)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3134 if direction == 1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3135 end = index
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3136 elif direction == 2:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3137 start = index
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3138 if end > start:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3139 text = self.text(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3140 word = text[start:end]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3141 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3142 word = ''
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3143 return word
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3144
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3145 def getWordLeft(self, line, index):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3146 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3147 Public method to get the word to the left of a position.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3148
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3149 @param line number of line to look at (int)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3150 @param index position to look at (int)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3151 @return the word to the left of that position (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3152 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3153 return self.getWord(line, index, 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3154
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3155 def getWordRight(self, line, index):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3156 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3157 Public method to get the word to the right of a position.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3158
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3159 @param line number of line to look at (int)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3160 @param index position to look at (int)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3161 @return the word to the right of that position (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3162 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3163 return self.getWord(line, index, 2)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3164
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3165 def getCurrentWord(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3166 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3167 Public method to get the word at the current position.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3168
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3169 @return the word at that current position (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3170 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3171 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3172 return self.getWord(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3173
2213
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3174 def getCurrentWordBoundaries(self):
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3175 """
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3176 Public method to get the word boundaries at the current position.
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3177
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3178 @return tuple with start and end indexes of the current word
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3179 (integer, integer)
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3180 """
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3181 line, index = self.getCursorPosition()
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3182 return self.getWordBoundaries(line, index)
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
3183
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3184 def selectWord(self, line, index):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3185 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3186 Public method to select the word at a position.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3187
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3188 @param line number of line to look at (int)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3189 @param index position to look at (int)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3190 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3191 start, end = self.getWordBoundaries(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3192 self.setSelection(line, start, line, end)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3193
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3194 def selectCurrentWord(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3195 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3196 Public method to select the current word.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3197 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3198 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3199 self.selectWord(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3200
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3201 def __getCharacter(self, pos):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3202 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3203 Private method to get the character to the left of the current position
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3204 in the current line.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3205
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3206 @param pos position to get character at (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3207 @return requested character or "", if there are no more (string) and
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3208 the next position (i.e. pos - 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3209 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3210 if pos <= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3211 return "", pos
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3212
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3213 pos = self.positionBefore(pos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3214 ch = self.charAt(pos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3215
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3216 # Don't go past the end of the previous line
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3217 if ch == '\n' or ch == '\r':
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3218 return "", pos
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3219
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3220 return ch, pos
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3221
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3222 def getSearchText(self, selectionOnly=False):
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3223 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3224 Public method to determine the selection or the current word for the
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3225 next search operation.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3226
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3227 @param selectionOnly flag indicating that only selected text should be
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3228 returned (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3229 @return selection or current word (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3230 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3231 if self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3232 text = self.selectedText()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3233 if '\r' in text or '\n' in text:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3234 # the selection contains at least a newline, it is
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3235 # unlikely to be the expression to search for
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3236 return ''
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3237
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3238 return text
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3239
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3240 if not selectionOnly:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3241 # no selected text, determine the word at the current position
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3242 return self.getCurrentWord()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3243
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3244 return ''
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3245
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3246 def setSearchIndicator(self, startPos, indicLength):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3247 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3248 Public method to set a search indicator for the given range.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3249
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3250 @param startPos start position of the indicator (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3251 @param indicLength length of the indicator (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3252 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3253 self.setIndicatorRange(self.searchIndicator, startPos, indicLength)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3254
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3255 def clearSearchIndicators(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3256 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3257 Public method to clear all search indicators.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3258 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3259 self.clearAllIndicators(self.searchIndicator)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3260 self.__markedText = ""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3261
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3262 def __markOccurrences(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3263 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3264 Private method to mark all occurrences of the current word.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3265 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3266 word = self.getCurrentWord()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3267 if not word:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3268 self.clearSearchIndicators()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3269 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3270
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3271 if self.__markedText == word:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3272 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3273
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3274 self.clearSearchIndicators()
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3275 ok = self.findFirstTarget(word, False, self.caseSensitive(), True,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3276 0, 0)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3277 while ok:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3278 tgtPos, tgtLen = self.getFoundTarget()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3279 self.setSearchIndicator(tgtPos, tgtLen)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3280 ok = self.findNextTarget()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3281 self.__markedText = word
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3282
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3283 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3284 ## Comment handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3285 ###########################################################################
2493
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3286
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3287 def __isCommentedLine(self, line, commentStr):
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3288 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3289 Private method to check, if the given line is a comment line as
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3290 produced by the configured comment rules.
2493
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3291
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3292 @param line text of the line to check (string)
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3293 @param commentStr comment string to check against (string)
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3294 @return flag indicating a commented line (boolean)
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3295 """
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3296 if Preferences.getEditor("CommentColumn0"):
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3297 return line.startswith(commentStr)
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3298 else:
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3299 return line.strip().startswith(commentStr)
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3300
1500
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3301 def toggleCommentBlock(self):
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3302 """
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3303 Public slot to toggle the comment of a block.
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3304
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3305 If the line of the cursor or the selection is not commented, it will
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3306 be commented. If it is commented, the comment block will be removed.
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3307 The later works independent of the current selection.
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3308 """
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3309 if self.lexer_ is None or not self.lexer_.canBlockComment():
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3310 return
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3311
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3312 commentStr = self.lexer_.commentStr()
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3313 line, index = self.getCursorPosition()
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3314
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3315 # check if line starts with our comment string (i.e. was commented
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3316 # by our comment...() slots
2490
3d011f457ddd Extended the logic of the 'Toggle Comment Block' action to consider the current selection first.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2424
diff changeset
3317 if self.hasSelectedText() and \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3318 self.__isCommentedLine(self.text(self.getSelection()[0]),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3319 commentStr):
2490
3d011f457ddd Extended the logic of the 'Toggle Comment Block' action to consider the current selection first.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2424
diff changeset
3320 self.uncommentLineOrSelection()
2493
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3321 elif not self.__isCommentedLine(self.text(line), commentStr):
1500
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3322 # it doesn't, so comment the line or selection
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3323 self.commentLineOrSelection()
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3324 else:
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3325 # determine the start of the comment block
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3326 begline = line
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3327 while begline > 0 and \
2493
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3328 self.__isCommentedLine(self.text(begline - 1), commentStr):
1588
dccffd13be8d Did some PEP-8 related corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1566
diff changeset
3329 begline -= 1
1500
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3330 # determine the end of the comment block
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3331 endline = line
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3332 lines = self.lines()
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3333 while endline < lines and \
2493
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3334 self.__isCommentedLine(self.text(endline + 1), commentStr):
1588
dccffd13be8d Did some PEP-8 related corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1566
diff changeset
3335 endline += 1
1500
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3336
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3337 self.setSelection(begline, 0, endline, self.lineLength(endline))
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3338 self.uncommentLineOrSelection()
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3339
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3340 # reset the cursor
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3341 self.setCursorPosition(line, index - len(commentStr))
6ce6deb421cf Added an action to the editor to toggle block comments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1491
diff changeset
3342
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3343 def commentLine(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3344 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3345 Public slot to comment the current line.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3346 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3347 if self.lexer_ is None or not self.lexer_.canBlockComment():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3348 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3349
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3350 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3351 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3352 if Preferences.getEditor("CommentColumn0"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3353 self.insertAt(self.lexer_.commentStr(), line, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3354 else:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3355 self.insertAt(self.lexer_.commentStr(), line,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3356 self.indentation(line))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3357 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3358
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3359 def uncommentLine(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3360 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3361 Public slot to uncomment the current line.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3362 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3363 if self.lexer_ is None or not self.lexer_.canBlockComment():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3364 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3365
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3366 commentStr = self.lexer_.commentStr()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3367 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3368
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3369 # check if line starts with our comment string (i.e. was commented
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3370 # by our comment...() slots
2493
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3371 if not self.__isCommentedLine(self.text(line), commentStr):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3372 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3373
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3374 # now remove the comment string
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3375 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3376 if Preferences.getEditor("CommentColumn0"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3377 self.setSelection(line, 0, line, len(commentStr))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3378 else:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3379 self.setSelection(line, self.indentation(line),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3380 line, self.indentation(line) + len(commentStr))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3381 self.removeSelectedText()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3382 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3383
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3384 def commentSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3385 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3386 Public slot to comment the current selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3387 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3388 if self.lexer_ is None or not self.lexer_.canBlockComment():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3389 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3390
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3391 if not self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3392 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3393
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3394 commentStr = self.lexer_.commentStr()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3395
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3396 # get the selection boundaries
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3397 lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3398 if indexTo == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3399 endLine = lineTo - 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3400 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3401 endLine = lineTo
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3402
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3403 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3404 # iterate over the lines
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3405 for line in range(lineFrom, endLine + 1):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3406 if Preferences.getEditor("CommentColumn0"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3407 self.insertAt(commentStr, line, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3408 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3409 self.insertAt(commentStr, line, self.indentation(line))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3410
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3411 # change the selection accordingly
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3412 self.setSelection(lineFrom, 0, endLine + 1, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3413 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3414
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3415 def uncommentSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3416 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3417 Public slot to uncomment the current selection.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3418 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3419 if self.lexer_ is None or not self.lexer_.canBlockComment():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3420 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3421
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3422 if not self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3423 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3424
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3425 commentStr = self.lexer_.commentStr()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3426
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3427 # get the selection boundaries
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3428 lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3429 if indexTo == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3430 endLine = lineTo - 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3431 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3432 endLine = lineTo
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3433
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3434 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3435 # iterate over the lines
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3436 for line in range(lineFrom, endLine + 1):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3437 # check if line starts with our comment string (i.e. was commented
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3438 # by our comment...() slots
2493
476f6016114d Fixed an issue with the uncomment and toggle comment functions of the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2490
diff changeset
3439 if not self.__isCommentedLine(self.text(line), commentStr):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3440 continue
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3441
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3442 if Preferences.getEditor("CommentColumn0"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3443 self.setSelection(line, 0, line, len(commentStr))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3444 else:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3445 self.setSelection(line,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3446 self.indentation(line),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3447 line,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3448 self.indentation(line) + len(commentStr))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3449 self.removeSelectedText()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3450
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3451 # adjust selection start
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3452 if line == lineFrom:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3453 indexFrom -= len(commentStr)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3454 if indexFrom < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3455 indexFrom = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3456
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3457 # adjust selection end
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3458 if line == lineTo:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3459 indexTo -= len(commentStr)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3460 if indexTo < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3461 indexTo = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3462
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3463 # change the selection accordingly
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3464 self.setSelection(lineFrom, indexFrom, lineTo, indexTo)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3465 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3466
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3467 def commentLineOrSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3468 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3469 Public slot to comment the current line or current selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3470 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3471 if self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3472 self.commentSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3473 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3474 self.commentLine()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3475
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3476 def uncommentLineOrSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3477 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3478 Public slot to uncomment the current line or current selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3479 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3480 if self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3481 self.uncommentSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3482 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3483 self.uncommentLine()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3484
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3485 def streamCommentLine(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3486 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3487 Public slot to stream comment the current line.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3488 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3489 if self.lexer_ is None or not self.lexer_.canStreamComment():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3490 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3491
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3492 commentStr = self.lexer_.streamCommentStr()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3493 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3494
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3495 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3496 self.insertAt(commentStr['end'], line, self.lineLength(line))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3497 self.insertAt(commentStr['start'], line, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3498 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3499
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3500 def streamCommentSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3501 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3502 Public slot to comment the current selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3503 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3504 if self.lexer_ is None or not self.lexer_.canStreamComment():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3505 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3506
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3507 if not self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3508 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3509
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3510 commentStr = self.lexer_.streamCommentStr()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3511
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3512 # get the selection boundaries
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3513 lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3514 if indexTo == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3515 endLine = lineTo - 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3516 endIndex = self.lineLength(endLine)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3517 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3518 endLine = lineTo
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3519 endIndex = indexTo
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3520
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3521 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3522 self.insertAt(commentStr['end'], endLine, endIndex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3523 self.insertAt(commentStr['start'], lineFrom, indexFrom)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3524
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3525 # change the selection accordingly
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3526 if indexTo > 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3527 indexTo += len(commentStr['end'])
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3528 if lineFrom == endLine:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3529 indexTo += len(commentStr['start'])
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3530 self.setSelection(lineFrom, indexFrom, lineTo, indexTo)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3531 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3532
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3533 def streamCommentLineOrSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3534 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3535 Public slot to stream comment the current line or current selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3536 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3537 if self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3538 self.streamCommentSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3539 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3540 self.streamCommentLine()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3541
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3542 def boxCommentLine(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3543 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3544 Public slot to box comment the current line.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3545 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3546 if self.lexer_ is None or not self.lexer_.canBoxComment():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3547 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3548
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3549 commentStr = self.lexer_.boxCommentStr()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3550 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3551
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3552 eol = self.getLineSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3553 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3554 self.insertAt(eol, line, self.lineLength(line))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3555 self.insertAt(commentStr['end'], line + 1, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3556 self.insertAt(commentStr['middle'], line, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3557 self.insertAt(eol, line, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3558 self.insertAt(commentStr['start'], line, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3559 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3560
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3561 def boxCommentSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3562 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3563 Public slot to box comment the current selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3564 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3565 if self.lexer_ is None or not self.lexer_.canBoxComment():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3566 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3567
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3568 if not self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3569 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3570
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3571 commentStr = self.lexer_.boxCommentStr()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3572
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3573 # get the selection boundaries
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3574 lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3575 if indexTo == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3576 endLine = lineTo - 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3577 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3578 endLine = lineTo
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3579
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3580 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3581 # iterate over the lines
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3582 for line in range(lineFrom, endLine + 1):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3583 self.insertAt(commentStr['middle'], line, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3584
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3585 # now do the comments before and after the selection
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3586 eol = self.getLineSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3587 self.insertAt(eol, endLine, self.lineLength(endLine))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3588 self.insertAt(commentStr['end'], endLine + 1, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3589 self.insertAt(eol, lineFrom, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3590 self.insertAt(commentStr['start'], lineFrom, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3591
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3592 # change the selection accordingly
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3593 self.setSelection(lineFrom, 0, endLine + 3, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3594 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3595
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3596 def boxCommentLineOrSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3597 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3598 Public slot to box comment the current line or current selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3599 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3600 if self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3601 self.boxCommentSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3602 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3603 self.boxCommentLine()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3604
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3605 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3606 ## Indentation handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3607 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3608
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3609 def __indentLine(self, indent=True):
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3610 """
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3611 Private method to indent or unindent the current line.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3612
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3613 @param indent flag indicating an indent operation (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3614 <br />If the flag is true, an indent operation is performed.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3615 Otherwise the current line is unindented.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3616 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3617 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3618 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3619 if indent:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3620 self.indent(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3621 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3622 self.unindent(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3623 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3624 if indent:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3625 self.setCursorPosition(line, index + self.indentationWidth())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3626 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3627 self.setCursorPosition(line, index - self.indentationWidth())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3628
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3629 def __indentSelection(self, indent=True):
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3630 """
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3631 Private method to indent or unindent the current selection.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3632
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3633 @param indent flag indicating an indent operation (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3634 <br />If the flag is true, an indent operation is performed.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3635 Otherwise the current line is unindented.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3636 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3637 if not self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3638 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3639
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3640 # get the selection
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3641 lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3642
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3643 if indexTo == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3644 endLine = lineTo - 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3645 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3646 endLine = lineTo
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3647
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3648 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3649 # iterate over the lines
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3650 for line in range(lineFrom, endLine + 1):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3651 if indent:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3652 self.indent(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3653 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3654 self.unindent(line)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3655 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3656 if indent:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3657 if indexTo == 0:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3658 self.setSelection(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3659 lineFrom, indexFrom + self.indentationWidth(),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3660 lineTo, 0)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3661 else:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3662 self.setSelection(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3663 lineFrom, indexFrom + self.indentationWidth(),
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3664 lineTo, indexTo + self.indentationWidth())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3665 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3666 indexStart = indexFrom - self.indentationWidth()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3667 if indexStart < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3668 indexStart = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3669 indexEnd = indexTo - self.indentationWidth()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3670 if indexEnd < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3671 indexEnd = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3672 self.setSelection(lineFrom, indexStart, lineTo, indexEnd)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3673
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3674 def indentLineOrSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3675 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
3676 Public slot to indent the current line or current selection.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3677 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3678 if self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3679 self.__indentSelection(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3680 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3681 self.__indentLine(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3682
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3683 def unindentLineOrSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3684 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3685 Public slot to unindent the current line or current selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3686 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3687 if self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3688 self.__indentSelection(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3689 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3690 self.__indentLine(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3691
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3692 def smartIndentLineOrSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3693 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3694 Public slot to indent current line smartly.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3695 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3696 if self.hasSelectedText():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3697 if self.lexer_ and self.lexer_.hasSmartIndent():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3698 self.lexer_.smartIndentSelection(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3699 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3700 self.__indentSelection(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3701 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3702 if self.lexer_ and self.lexer_.hasSmartIndent():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3703 self.lexer_.smartIndentLine(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3704 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3705 self.__indentLine(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3706
1897
4c89af5a756f Little improvement to the editor assembly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1831
diff changeset
3707 def gotoLine(self, line, pos=1, firstVisible=False):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3708 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3709 Public slot to jump to the beginning of a line.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3710
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3711 @param line line number to go to (integer)
832
eb5ff61f927b Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
3712 @keyparam pos position in line to go to (integer)
1897
4c89af5a756f Little improvement to the editor assembly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1831
diff changeset
3713 @keyparam firstVisible flag indicating to make the line the first
4c89af5a756f Little improvement to the editor assembly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1831
diff changeset
3714 visible line (boolean)
832
eb5ff61f927b Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
3715 """
eb5ff61f927b Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
3716 self.setCursorPosition(line - 1, pos - 1)
1897
4c89af5a756f Little improvement to the editor assembly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1831
diff changeset
3717 if firstVisible:
4c89af5a756f Little improvement to the editor assembly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1831
diff changeset
3718 self.ensureVisibleTop(line)
4c89af5a756f Little improvement to the editor assembly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1831
diff changeset
3719 else:
4c89af5a756f Little improvement to the editor assembly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1831
diff changeset
3720 self.ensureVisible(line)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3721
1169
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3722 def __textChanged(self):
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3723 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3724 Private slot to handle a change of the editor text.
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3725
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3726 This slot defers the handling to the next time the event loop
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3727 is run in order to ensure, that cursor position has been updated
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3728 by the underlying Scintilla editor.
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3729 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3730 QTimer.singleShot(0, self.__saveLastEditPosition)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3731
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3732 def __saveLastEditPosition(self):
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3733 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3734 Private slot to record the last edit position.
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3735 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3736 self.__lastEditPosition = self.getCursorPosition()
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3737 self.lastEditPositionAvailable.emit()
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3738
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3739 def isLastEditPositionAvailable(self):
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3740 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3741 Public method to check, if a last edit position is available.
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3742
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3743 @return flag indicating availability (boolean)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3744 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3745 return self.__lastEditPosition is not None
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3746
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3747 def gotoLastEditPosition(self):
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3748 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3749 Public method to move the cursor to the last edit position.
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3750 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3751 self.setCursorPosition(*self.__lastEditPosition)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3752 self.ensureVisible(self.__lastEditPosition[0])
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3753
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3754 def gotoMethodClass(self, goUp=False):
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3755 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3756 Public method to go to the next Python method or class definition.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
3757
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
3758 @param goUp flag indicating the move direction (boolean)
1169
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3759 """
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3760 if self.isPy3File() or self.isPy2File() or self.isRubyFile():
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3761 lineNo = self.getCursorPosition()[0]
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3762 line = self.text(lineNo)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3763 if line.strip().startswith(("class ", "def ", "module ")):
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3764 if goUp:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3765 lineNo -= 1
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3766 else:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3767 lineNo += 1
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3768 while True:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3769 if goUp and lineNo < 0:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3770 self.setCursorPosition(0, 0)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3771 self.ensureVisible(0)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3772 return
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3773 elif not goUp and lineNo == self.lines():
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3774 lineNo = self.lines() - 1
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3775 self.setCursorPosition(lineNo, self.lineLength(lineNo))
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3776 self.ensureVisible(lineNo)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3777 return
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3778
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3779 line = self.text(lineNo)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3780 if line.strip().startswith(("class ", "def ", "module ")):
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3781 # try 'def ' first because it occurs more often
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3782 first = line.find("def ")
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3783 if first > -1:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3784 first += 4
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3785 else:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3786 first = line.find("class ")
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3787 if first > -1:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3788 first += 6
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3789 else:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3790 first = line.find("module ") + 7
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3791 match = re.search("[:(]", line)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3792 if match:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3793 end = match.start()
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3794 else:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3795 end = self.lineLength(lineNo) - 1
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3796 self.setSelection(lineNo, first, lineNo, end)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3797 self.ensureVisible(lineNo)
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3798 return
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3799
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3800 if goUp:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3801 lineNo -= 1
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3802 else:
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3803 lineNo += 1
36a3bb21e6e6 Added editor actions to go to the last edit location and to the previous or next Python or Ruby class or method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
3804
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3805 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3806 ## Setup methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3807 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3808
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3809 def readSettings(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3810 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3811 Public slot to read the settings into our lexer.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3812 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3813 # read the lexer settings and reinit the properties
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3814 if self.lexer_ is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3815 self.lexer_.readSettings(Preferences.Prefs.settings, "Scintilla")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3816 self.lexer_.initProperties()
1566
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
3817
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
3818 self.lexer_.setDefaultColor(self.lexer_.color(0))
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
3819 self.lexer_.setDefaultPaper(self.lexer_.paper(0))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3820
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3821 # read the typing completer settings
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3822 if self.completer is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3823 self.completer.readSettings()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3824
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3825 # set the margins layout
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3826 if QSCINTILLA_VERSION() >= 0x020301:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3827 self.__unifiedMargins = Preferences.getEditor("UnifiedMargins")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3828
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3829 # set the line marker colours
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3830 self.__setLineMarkerColours()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3831
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3832 # set the text display
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3833 self.__setTextDisplay()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3834
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3835 # set margin 0 and 2 configuration
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3836 self.__setMarginsDisplay()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3837
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3838 # set the autocompletion and calltips function
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3839 self.__setAutoCompletion()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3840 self.__setCallTips()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3841
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3842 # set the autosave flags
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3843 self.autosaveEnabled = Preferences.getEditor("AutosaveInterval") > 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3844
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3845 if Preferences.getEditor("MiniContextMenu") != self.miniMenu:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3846 # regenerate context menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3847 self.__initContextMenu()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3848 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3849 # set checked context menu items
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
3850 self.menuActs["AutoCompletionEnable"].setChecked(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3851 self.autoCompletionThreshold() != -1)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
3852 self.menuActs["MonospacedFont"].setChecked(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3853 self.useMonospaced)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
3854 self.menuActs["AutosaveEnable"].setChecked(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3855 self.autosaveEnabled and not self.autosaveManuallyDisabled)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3856
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3857 # regenerate the margins context menu(s)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3858 self.__initContextMenuMargins()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3859
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3860 if Preferences.getEditor("MarkOccurrencesEnabled"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3861 self.__markOccurrencesTimer.setInterval(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3862 Preferences.getEditor("MarkOccurrencesTimeout"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3863 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3864 self.__markOccurrencesTimer.stop()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3865 self.clearSearchIndicators()
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
3866
1353
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
3867 if Preferences.getEditor("OnlineSyntaxCheck"):
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
3868 self.__onlineSyntaxCheckTimer.setInterval(
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
3869 Preferences.getEditor("OnlineSyntaxCheckInterval") * 1000)
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
3870 else:
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
3871 self.__onlineSyntaxCheckTimer.stop()
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
3872
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
3873 if Preferences.getEditor("OnlineChangeTrace"):
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
3874 self.__onlineChangeTraceTimer.setInterval(
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
3875 Preferences.getEditor("OnlineChangeTraceInterval"))
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
3876 else:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
3877 self.__onlineChangeTraceTimer.stop()
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
3878 self.__deleteAllChangeMarkers()
2165
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
3879 self.markerDefine(self.__createChangeMarkerPixmap(
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
3880 "OnlineChangeTraceMarkerUnsaved"), self.__changeMarkerUnsaved)
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
3881 self.markerDefine(self.__createChangeMarkerPixmap(
f89fc1162ffe Finalized the change tracing stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2164
diff changeset
3882 "OnlineChangeTraceMarkerSaved"), self.__changeMarkerSaved)
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
3883
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
3884 # refresh the annotations display
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
3885 self.__refreshAnnotations()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3886
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3887 def __setLineMarkerColours(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3888 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3889 Private method to set the line marker colours.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3890 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3891 self.setMarkerForegroundColor(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3892 Preferences.getEditorColour("CurrentMarker"), self.currentline)
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3893 self.setMarkerBackgroundColor(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3894 Preferences.getEditorColour("CurrentMarker"), self.currentline)
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3895 self.setMarkerForegroundColor(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3896 Preferences.getEditorColour("ErrorMarker"), self.errorline)
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3897 self.setMarkerBackgroundColor(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3898 Preferences.getEditorColour("ErrorMarker"), self.errorline)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3899
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3900 def __setMarginsDisplay(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3901 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3902 Private method to configure margins 0 and 2.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3903 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3904 # set the settings for all margins
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3905 self.setMarginsFont(Preferences.getEditorOtherFonts("MarginsFont"))
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3906 self.setMarginsForegroundColor(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3907 Preferences.getEditorColour("MarginsForeground"))
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3908 self.setMarginsBackgroundColor(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
3909 Preferences.getEditorColour("MarginsBackground"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3910
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3911 # reset standard margins settings
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3912 for margin in range(5):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3913 self.setMarginLineNumbers(margin, False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3914 self.setMarginMarkerMask(margin, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3915 self.setMarginWidth(margin, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3916 self.setMarginSensitivity(margin, False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3917
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3918 # set marker margin(s) settings
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3919 if self.__unifiedMargins:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3920 margin1Mask = (1 << self.breakpoint) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3921 (1 << self.cbreakpoint) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3922 (1 << self.tbreakpoint) | \
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3923 (1 << self.tcbreakpoint) | \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3924 (1 << self.dbreakpoint) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3925 (1 << self.currentline) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3926 (1 << self.errorline) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3927 (1 << self.bookmark) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3928 (1 << self.syntaxerror) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3929 (1 << self.notcovered) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3930 (1 << self.taskmarker) | \
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
3931 (1 << self.warning) | \
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
3932 (1 << self.__changeMarkerUnsaved) | \
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
3933 (1 << self.__changeMarkerSaved)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3934 self.setMarginWidth(1, 16)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3935 self.setMarginSensitivity(1, True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3936 self.setMarginMarkerMask(1, margin1Mask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3937
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3938 self.__linenoMargin = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3939 self.__foldMargin = 2
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3940 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3941
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3942 self.__bmMargin = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3943 self.__linenoMargin = 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3944 self.__bpMargin = 2
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3945 self.__foldMargin = 3
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3946 self.__indicMargin = 4
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3947
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3948 marginBmMask = (1 << self.bookmark)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3949 self.setMarginWidth(self.__bmMargin, 16)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3950 self.setMarginSensitivity(self.__bmMargin, True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3951 self.setMarginMarkerMask(self.__bmMargin, marginBmMask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3952
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3953 marginBpMask = (1 << self.breakpoint) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3954 (1 << self.cbreakpoint) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3955 (1 << self.tbreakpoint) | \
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3956 (1 << self.tcbreakpoint) | \
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3957 (1 << self.dbreakpoint) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3958 (1 << self.currentline) | \
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3959 (1 << self.errorline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3960 self.setMarginWidth(self.__bpMargin, 16)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3961 self.setMarginSensitivity(self.__bpMargin, True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3962 self.setMarginMarkerMask(self.__bpMargin, marginBpMask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3963
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3964 marginIndicMask = (1 << self.syntaxerror) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3965 (1 << self.notcovered) | \
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3966 (1 << self.taskmarker) | \
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
3967 (1 << self.warning) | \
2164
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
3968 (1 << self.__changeMarkerUnsaved) | \
d67b14a3f884 Improved the change tracing function by marking saved and unsaved changes differently.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2163
diff changeset
3969 (1 << self.__changeMarkerSaved)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3970 self.setMarginWidth(self.__indicMargin, 16)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3971 self.setMarginSensitivity(self.__indicMargin, True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3972 self.setMarginMarkerMask(self.__indicMargin, marginIndicMask)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3973
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3974 # set linenumber margin settings
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3975 linenoMargin = Preferences.getEditor("LinenoMargin")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3976 self.setMarginLineNumbers(self.__linenoMargin, linenoMargin)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3977 if linenoMargin:
2640
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
3978 self.__resizeLinenoMargin()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3979 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3980 self.setMarginWidth(self.__linenoMargin, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3981
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3982 # set folding margin settings
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3983 if Preferences.getEditor("FoldingMargin"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3984 self.setMarginWidth(self.__foldMargin, 16)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3985 folding = Preferences.getEditor("FoldingStyle")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3986 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3987 folding = QsciScintilla.FoldStyle(folding)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3988 except AttributeError:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3989 pass
342
360c4eb76d6c Added capability to configure the colors of the foldmarkers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
3990 self.setFolding(folding, self.__foldMargin)
360c4eb76d6c Added capability to configure the colors of the foldmarkers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
3991 self.setFoldMarginColors(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
3992 Preferences.getEditorColour("FoldmarginBackground"),
342
360c4eb76d6c Added capability to configure the colors of the foldmarkers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
3993 Preferences.getEditorColour("FoldmarginBackground"))
360c4eb76d6c Added capability to configure the colors of the foldmarkers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
3994 self.setFoldMarkersColors(
360c4eb76d6c Added capability to configure the colors of the foldmarkers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
3995 Preferences.getEditorColour("FoldMarkersForeground"),
360c4eb76d6c Added capability to configure the colors of the foldmarkers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
3996 Preferences.getEditorColour("FoldMarkersBackground"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3997 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
3998 self.setMarginWidth(self.__foldMargin, 0)
342
360c4eb76d6c Added capability to configure the colors of the foldmarkers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 253
diff changeset
3999 self.setFolding(QsciScintilla.NoFoldStyle, self.__foldMargin)
2640
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
4000
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
4001 def __resizeLinenoMargin(self):
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
4002 """
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
4003 Private slot to resize the line numbers margin.
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
4004 """
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
4005 linenoMargin = Preferences.getEditor("LinenoMargin")
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
4006 if linenoMargin:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4007 self.setMarginWidth(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4008 self.__linenoMargin, '8' * (len(str(self.lines())) + 1))
2640
dedcd4f987e0 Changed the line numbers margin to adjust themselves to the size needed (Editor, Mini Editor, Shell).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2632
diff changeset
4009
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4010 def __setTextDisplay(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4011 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4012 Private method to configure the text display.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4013 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4014 self.setTabWidth(Preferences.getEditor("TabWidth"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4015 self.setIndentationWidth(Preferences.getEditor("IndentWidth"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4016 if self.lexer_ and self.lexer_.alwaysKeepTabs():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4017 self.setIndentationsUseTabs(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4018 else:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4019 self.setIndentationsUseTabs(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4020 Preferences.getEditor("TabForIndentation"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4021 self.setTabIndents(Preferences.getEditor("TabIndents"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4022 self.setBackspaceUnindents(Preferences.getEditor("TabIndents"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4023 self.setIndentationGuides(Preferences.getEditor("IndentationGuides"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4024 if Preferences.getEditor("ShowWhitespace"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4025 self.setWhitespaceVisibility(QsciScintilla.WsVisible)
939
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4026 try:
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4027 self.setWhitespaceForegroundColor(
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4028 Preferences.getEditorColour("WhitespaceForeground"))
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4029 self.setWhitespaceBackgroundColor(
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4030 Preferences.getEditorColour("WhitespaceBackground"))
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4031 self.setWhitespaceSize(
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4032 Preferences.getEditor("WhitespaceSize"))
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4033 except AttributeError:
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4034 # QScintilla before 2.5 doesn't support this
10d3a201cd27 Added configuration options for visible whitespace (as of QScintilla 2.5).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 938
diff changeset
4035 pass
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4036 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4037 self.setWhitespaceVisibility(QsciScintilla.WsInvisible)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4038 self.setEolVisibility(Preferences.getEditor("ShowEOL"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4039 self.setAutoIndent(Preferences.getEditor("AutoIndentation"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4040 if Preferences.getEditor("BraceHighlighting"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4041 self.setBraceMatching(QsciScintilla.SloppyBraceMatch)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4042 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4043 self.setBraceMatching(QsciScintilla.NoBraceMatch)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4044 self.setMatchedBraceForegroundColor(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4045 Preferences.getEditorColour("MatchingBrace"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4046 self.setMatchedBraceBackgroundColor(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4047 Preferences.getEditorColour("MatchingBraceBack"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4048 self.setUnmatchedBraceForegroundColor(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4049 Preferences.getEditorColour("NonmatchingBrace"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4050 self.setUnmatchedBraceBackgroundColor(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4051 Preferences.getEditorColour("NonmatchingBraceBack"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4052 if Preferences.getEditor("CustomSelectionColours"):
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
4053 self.setSelectionBackgroundColor(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4054 Preferences.getEditorColour("SelectionBackground"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4055 else:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
4056 self.setSelectionBackgroundColor(
2084
d3f083dd0222 Made the fiveth set of Qt5 compatibility changes (some of the previous changes are backed out due to changes in PyQt4).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2077
diff changeset
4057 QApplication.palette().color(QPalette.Highlight))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4058 if Preferences.getEditor("ColourizeSelText"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4059 self.resetSelectionForegroundColor()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4060 elif Preferences.getEditor("CustomSelectionColours"):
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
4061 self.setSelectionForegroundColor(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4062 Preferences.getEditorColour("SelectionForeground"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4063 else:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
4064 self.setSelectionForegroundColor(
2084
d3f083dd0222 Made the fiveth set of Qt5 compatibility changes (some of the previous changes are backed out due to changes in PyQt4).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2077
diff changeset
4065 QApplication.palette().color(QPalette.HighlightedText))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4066 self.setSelectionToEol(Preferences.getEditor("ExtendSelectionToEol"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4067 self.setCaretForegroundColor(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4068 Preferences.getEditorColour("CaretForeground"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4069 self.setCaretLineBackgroundColor(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4070 Preferences.getEditorColour("CaretLineBackground"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4071 self.setCaretLineVisible(Preferences.getEditor("CaretLineVisible"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4072 self.caretWidth = Preferences.getEditor("CaretWidth")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4073 self.setCaretWidth(self.caretWidth)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4074 self.useMonospaced = Preferences.getEditor("UseMonospacedFont")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4075 self.setMonospaced(self.useMonospaced)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4076 edgeMode = Preferences.getEditor("EdgeMode")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4077 edge = QsciScintilla.EdgeMode(edgeMode)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4078 self.setEdgeMode(edge)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4079 if edgeMode:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4080 self.setEdgeColumn(Preferences.getEditor("EdgeColumn"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4081 self.setEdgeColor(Preferences.getEditorColour("Edge"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4082
2262
2371836c3c45 Made some more adjustments for QScintilla 2.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2261
diff changeset
4083 wrapVisualFlag = Preferences.getEditor("WrapVisualFlag")
2371836c3c45 Made some more adjustments for QScintilla 2.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2261
diff changeset
4084 self.setWrapMode(Preferences.getEditor("WrapLongLinesMode"))
2371836c3c45 Made some more adjustments for QScintilla 2.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2261
diff changeset
4085 self.setWrapVisualFlags(wrapVisualFlag, wrapVisualFlag)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4086
230
2cde09c26384 Added code to configure the zoom factor a file is opened with.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 206
diff changeset
4087 self.zoomTo(Preferences.getEditor("ZoomFactor"))
2cde09c26384 Added code to configure the zoom factor a file is opened with.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 206
diff changeset
4088
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4089 self.searchIndicator = QsciScintilla.INDIC_CONTAINER
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4090 self.indicatorDefine(self.searchIndicator, QsciScintilla.INDIC_BOX,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4091 Preferences.getEditorColour("SearchMarkers"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4092 if not Preferences.getEditor("SearchMarkersEnabled") and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4093 not Preferences.getEditor("QuickSearchMarkersEnabled") and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4094 not Preferences.getEditor("MarkOccurrencesEnabled"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4095 self.clearAllIndicators(self.searchIndicator)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4096
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4097 self.spellingIndicator = QsciScintilla.INDIC_CONTAINER + 1
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4098 self.indicatorDefine(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4099 self.spellingIndicator, QsciScintilla.INDIC_SQUIGGLE,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4100 Preferences.getEditorColour("SpellingMarkers"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4101 self.__setSpelling()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4102
404
44a541bea034 Added code to adjust the cursor flash time of the editor to the global settings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 342
diff changeset
4103 self.setCursorFlashTime(QApplication.cursorFlashTime())
44a541bea034 Added code to adjust the cursor flash time of the editor to the global settings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 342
diff changeset
4104
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
4105 try:
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
4106 if Preferences.getEditor("AnnotationsEnabled"):
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
4107 self.setAnnotationDisplay(QsciScintilla.AnnotationBoxed)
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
4108 else:
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
4109 self.setAnnotationDisplay(QsciScintilla.AnnotationHidden)
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
4110 except AttributeError:
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
4111 pass
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
4112 self.__setAnnotationStyles()
1566
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
4113
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
4114 if Preferences.getEditor("OverrideEditAreaColours"):
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
4115 self.setColor(Preferences.getEditorColour("EditAreaForeground"))
0cb791cc631a Fixed the issue where a non matching background was shown in the editor for lines below the end of the text, if a lexer with a non-standard background was set.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1518
diff changeset
4116 self.setPaper(Preferences.getEditorColour("EditAreaBackground"))
2659
7f46c5a7ed73 Added support for virtual space to the Editor and Mini Editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2643
diff changeset
4117
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4118 self.setVirtualSpaceOptions(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4119 Preferences.getEditor("VirtualSpaceOptions"))
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
4120
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4121 def __setEolMode(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4122 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4123 Private method to configure the eol mode of the editor.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4124 """
253
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
4125 if self.fileName and \
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
4126 self.project.isOpen() and \
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
4127 self.project.isProjectFile(self.fileName):
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
4128 self.setEolModeByEolString(self.project.getEolString())
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
4129 else:
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
4130 eolMode = Preferences.getEditor("EOLMode")
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
4131 eolMode = QsciScintilla.EolMode(eolMode)
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
4132 self.setEolMode(eolMode)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4133 self.__eolChanged()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4134
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4135 def __setAutoCompletion(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4136 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4137 Private method to configure the autocompletion function.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4138 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4139 if self.lexer_:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4140 self.setAutoCompletionFillupsEnabled(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4141 Preferences.getEditor("AutoCompletionFillups"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4142 self.setAutoCompletionCaseSensitivity(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4143 Preferences.getEditor("AutoCompletionCaseSensitivity"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4144 self.setAutoCompletionReplaceWord(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4145 Preferences.getEditor("AutoCompletionReplaceWord"))
971
1243c600ba57 Added a compatibilitiy fix for QScintilla 2.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 954
diff changeset
4146 try:
1243c600ba57 Added a compatibilitiy fix for QScintilla 2.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 954
diff changeset
4147 self.setAutoCompletionUseSingle(
1243c600ba57 Added a compatibilitiy fix for QScintilla 2.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 954
diff changeset
4148 Preferences.getEditor("AutoCompletionShowSingle"))
1243c600ba57 Added a compatibilitiy fix for QScintilla 2.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 954
diff changeset
4149 except AttributeError:
1243c600ba57 Added a compatibilitiy fix for QScintilla 2.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 954
diff changeset
4150 self.setAutoCompletionShowSingle(
1243c600ba57 Added a compatibilitiy fix for QScintilla 2.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 954
diff changeset
4151 Preferences.getEditor("AutoCompletionShowSingle"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4152 autoCompletionSource = Preferences.getEditor("AutoCompletionSource")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4153 if autoCompletionSource == QsciScintilla.AcsDocument:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4154 self.setAutoCompletionSource(QsciScintilla.AcsDocument)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4155 elif autoCompletionSource == QsciScintilla.AcsAPIs:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4156 self.setAutoCompletionSource(QsciScintilla.AcsAPIs)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4157 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4158 self.setAutoCompletionSource(QsciScintilla.AcsAll)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4159 if Preferences.getEditor("AutoCompletionEnabled"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4160 if self.__acHookFunction is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4161 self.setAutoCompletionThreshold(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4162 Preferences.getEditor("AutoCompletionThreshold"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4163 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4164 self.setAutoCompletionThreshold(0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4165 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4166 self.setAutoCompletionThreshold(-1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4167 self.setAutoCompletionSource(QsciScintilla.AcsNone)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4168
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4169 def __setCallTips(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4170 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4171 Private method to configure the calltips function.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4172 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4173 if Preferences.getEditor("CallTipsEnabled"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4174 self.setCallTipsBackgroundColor(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4175 Preferences.getEditorColour("CallTipsBackground"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4176 self.setCallTipsVisible(Preferences.getEditor("CallTipsVisible"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4177 calltipsStyle = Preferences.getEditor("CallTipsStyle")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4178 if calltipsStyle == QsciScintilla.CallTipsNoContext:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4179 self.setCallTipsStyle(QsciScintilla.CallTipsNoContext)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4180 elif calltipsStyle == \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4181 QsciScintilla.CallTipsNoAutoCompletionContext:
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4182 self.setCallTipsStyle(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4183 QsciScintilla.CallTipsNoAutoCompletionContext)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4184 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4185 self.setCallTipsStyle(QsciScintilla.CallTipsContext)
2262
2371836c3c45 Made some more adjustments for QScintilla 2.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2261
diff changeset
4186 try:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4187 self.setCallTipsPosition(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4188 Preferences.getEditor("CallTipsPosition"))
2262
2371836c3c45 Made some more adjustments for QScintilla 2.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2261
diff changeset
4189 except AttributeError:
2371836c3c45 Made some more adjustments for QScintilla 2.7.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2261
diff changeset
4190 pass
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4191 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4192 self.setCallTipsStyle(QsciScintilla.CallTipsNone)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4193
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4194 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4195 ## Autocompletion handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4196 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4197
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4198 def canAutoCompleteFromAPIs(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4199 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4200 Public method to check for API availablity.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4201
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4202 @return flag indicating autocompletion from APIs is available (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4203 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4204 return self.acAPI
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4205
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4206 def autoCompleteQScintilla(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4207 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4208 Public method to perform an autocompletion using QScintilla methods.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4209 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4210 acs = Preferences.getEditor("AutoCompletionSource")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4211 if acs == QsciScintilla.AcsDocument:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4212 self.autoCompleteFromDocument()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4213 elif acs == QsciScintilla.AcsAPIs:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4214 self.autoCompleteFromAPIs()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4215 elif acs == QsciScintilla.AcsAll:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4216 self.autoCompleteFromAll()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4217 else:
536
6d8d39753c82 Started replaceing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 535
diff changeset
4218 E5MessageBox.information(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4219 self.trUtf8("Autocompletion"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4220 self.trUtf8("""Autocompletion is not available because"""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4221 """ there is no autocompletion source set."""))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4222
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4223 def setAutoCompletionEnabled(self, enable):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4224 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4225 Public method to enable/disable autocompletion.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4226
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4227 @param enable flag indicating the desired autocompletion status
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4228 (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4229 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4230 if enable:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4231 self.setAutoCompletionThreshold(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4232 Preferences.getEditor("AutoCompletionThreshold"))
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4233 autoCompletionSource = \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4234 Preferences.getEditor("AutoCompletionSource")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4235 if autoCompletionSource == QsciScintilla.AcsDocument:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4236 self.setAutoCompletionSource(QsciScintilla.AcsDocument)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4237 elif autoCompletionSource == QsciScintilla.AcsAPIs:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4238 self.setAutoCompletionSource(QsciScintilla.AcsAPIs)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4239 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4240 self.setAutoCompletionSource(QsciScintilla.AcsAll)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4241 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4242 self.setAutoCompletionThreshold(-1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4243 self.setAutoCompletionSource(QsciScintilla.AcsNone)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4244
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4245 def __toggleAutoCompletionEnable(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4246 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4247 Private slot to handle the Enable Autocompletion context menu entry.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4248 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4249 if self.menuActs["AutoCompletionEnable"].isChecked():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4250 self.setAutoCompletionEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4251 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4252 self.setAutoCompletionEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4253
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4254 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4255 ## Support for autocompletion hook methods
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4256 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4257
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4258 def __charAdded(self, charNumber):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4259 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4260 Public slot called to handle the user entering a character.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4261
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4262 @param charNumber value of the character entered (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4263 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4264 if self.isListActive():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4265 char = chr(charNumber)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4266 if self.__isStartChar(char):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4267 self.cancelList()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4268 self.autoComplete(auto=True, context=True)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4269 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4270 elif char == '(':
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4271 self.cancelList()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4272
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4273 if self.callTipsStyle() != QsciScintilla.CallTipsNone and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4274 self.lexer_ is not None and chr(charNumber) in '()':
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4275 self.callTip()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4276
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4277 if not self.isCallTipActive():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4278 char = chr(charNumber)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4279 if self.__isStartChar(char):
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4280 self.autoComplete(auto=True, context=True)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4281 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4282
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4283 line, col = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4284 txt = self.getWordLeft(line, col)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4285 if len(txt) >= Preferences.getEditor("AutoCompletionThreshold"):
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4286 self.autoComplete(auto=True, context=False)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4287 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4288
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4289 def __isStartChar(self, ch):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4290 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4291 Private method to check, if a character is an autocompletion start
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4292 character.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4293
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4294 @param ch character to be checked (one character string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4295 @return flag indicating the result (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4296 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4297 if self.lexer_ is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4298 return False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4299
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4300 wseps = self.lexer_.autoCompletionWordSeparators()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4301 for wsep in wseps:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4302 if wsep.endswith(ch):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4303 return True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4304
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4305 return False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4306
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4307 def setAutoCompletionHook(self, func):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4308 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4309 Public method to set an autocompletion hook.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4310
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4311 @param func Function to be set to handle autocompletion. func
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4312 should be a function taking a reference to the editor and
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4313 a boolean indicating to complete a context.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4314 """
1063
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4315 if self.__acHookFunction is not None:
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4316 # there is another provider registered already
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4317 E5MessageBox.warning(self,
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4318 self.trUtf8("Activating Auto-Completion Provider"),
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4319 self.trUtf8("""Auto-completion provider cannot be connected"""
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4320 """ because there is already another one active."""
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4321 """ Please check your configuration."""))
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4322 return
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4323
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4324 if self.autoCompletionThreshold() > 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4325 self.setAutoCompletionThreshold(0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4326 self.__acHookFunction = func
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
4327 self.SCN_CHARADDED.connect(self.__charAdded)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4328
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4329 def unsetAutoCompletionHook(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4330 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4331 Public method to unset a previously installed autocompletion hook.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4332 """
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
4333 self.SCN_CHARADDED.disconnect(self.__charAdded)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4334 self.__acHookFunction = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4335 if self.autoCompletionThreshold() == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4336 self.setAutoCompletionThreshold(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4337 Preferences.getEditor("AutoCompletionThreshold"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4338
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4339 def autoCompletionHook(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4340 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4341 Public method to get the autocompletion hook function.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4342
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4343 @return function set by setAutoCompletionHook()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4344 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4345 return self.__acHookFunction
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4346
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4347 def autoComplete(self, auto=False, context=True):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4348 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4349 Public method to start autocompletion.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4350
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4351 @keyparam auto flag indicating a call from the __charAdded method
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4352 (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4353 @keyparam context flag indicating to complete a context (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4354 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4355 if auto and self.autoCompletionThreshold() == -1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4356 # autocompletion is disabled
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4357 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4358
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4359 if self.__acHookFunction is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4360 self.__acHookFunction(self, context)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4361 elif not auto:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4362 self.autoCompleteQScintilla()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4363 elif self.autoCompletionSource() != QsciScintilla.AcsNone:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4364 self.autoCompleteQScintilla()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4365
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4366 def callTip(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4367 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4368 Public method to show calltips.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4369 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4370 if self.__ctHookFunction is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4371 self.__callTip()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4372 else:
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
4373 super().callTip()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4374
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4375 def __callTip(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4376 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4377 Private method to show call tips provided by a plugin.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4378 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4379 pos = self.currentPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4380
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4381 # move backward to the start of the current calltip working out
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4382 # which argument to highlight
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4383 commas = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4384 found = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4385 ch, pos = self.__getCharacter(pos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4386 while ch:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4387 if ch == ',':
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4388 commas += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4389 elif ch == ')':
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4390 depth = 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4391
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4392 # ignore everything back to the start of the corresponding
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4393 # parenthesis
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4394 ch, pos = self.__getCharacter(pos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4395 while ch:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4396 if ch == ')':
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4397 depth += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4398 elif ch == '(':
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4399 depth -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4400 if depth == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4401 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4402 ch, pos = self.__getCharacter(pos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4403 elif ch == '(':
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4404 found = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4405 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4406
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4407 ch, pos = self.__getCharacter(pos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4408
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4409 self.SendScintilla(QsciScintilla.SCI_CALLTIPCANCEL)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4410
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4411 if not found:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4412 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4413
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4414 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4415 callTips = self.__ctHookFunction(self, pos, commas)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4416 except TypeError:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4417 # for backward compatibility
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4418 callTips = self.__ctHookFunction(self, pos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4419 if len(callTips) == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4420 if Preferences.getEditor("CallTipsScintillaOnFail"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4421 # try QScintilla calltips
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
4422 super().callTip()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4423 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4424
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4425 ctshift = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4426 for ct in callTips:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4427 shift = ct.index("(")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4428 if ctshift < shift:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4429 ctshift = shift
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4430
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4431 cv = self.callTipsVisible()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4432 if cv > 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4433 # this is just a safe guard
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4434 ct = self._encodeString("\n".join(callTips[:cv]))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4435 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4436 # until here and unindent below
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4437 ct = self._encodeString("\n".join(callTips))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4438
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4439 self.SendScintilla(QsciScintilla.SCI_CALLTIPSHOW,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4440 self.__adjustedCallTipPosition(ctshift, pos), ct)
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4441 if b'\n' in ct:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4442 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4443
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4444 # Highlight the current argument
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4445 if commas == 0:
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4446 astart = ct.find(b'(')
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4447 else:
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4448 astart = ct.find(b',')
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4449 commas -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4450 while astart != -1 and commas > 0:
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4451 astart = ct.find(b',', astart + 1)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4452 commas -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4453
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4454 if astart == -1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4455 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4456
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4457 depth = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4458 for aend in range(astart + 1, len(ct)):
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4459 ch = ct[aend:aend + 1]
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4460
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4461 if ch == b',' and depth == 0:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4462 break
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4463 elif ch == b'(':
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4464 depth += 1
502
7500b9d5b21d Fixed an issue in the editor related to unicode handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 501
diff changeset
4465 elif ch == b')':
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4466 if depth == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4467 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4468
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4469 depth -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4470
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4471 if astart != aend:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4472 self.SendScintilla(QsciScintilla.SCI_CALLTIPSETHLT,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4473 astart + 1, aend)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4474
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4475 def __adjustedCallTipPosition(self, ctshift, pos):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4476 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4477 Private method to calculate an adjusted position for showing calltips.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4478
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4479 @param ctshift amount the calltip shall be shifted (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4480 @param pos position into the text (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4481 @return new position for the calltip (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4482 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4483 ct = pos
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4484 if ctshift:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4485 ctmin = self.SendScintilla(QsciScintilla.SCI_POSITIONFROMLINE,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4486 self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, ct))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4487 if ct - ctshift < ctmin:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4488 ct = ctmin
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4489 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4490 ct = ct - ctshift
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4491 return ct
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4492
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4493 def setCallTipHook(self, func):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4494 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4495 Public method to set a calltip hook.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4496
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4497 @param func Function to be set to determine calltips. func
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4498 should be a function taking a reference to the editor,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4499 a position into the text and the amount of commas to the
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4500 left of the cursor. It should return the possible
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4501 calltips as a list of strings.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4502 """
1063
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4503 if self.__ctHookFunction is not None:
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4504 # there is another provider registered already
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4505 E5MessageBox.warning(self,
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4506 self.trUtf8("Activating Calltip Provider"),
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4507 self.trUtf8("""Calltip provider cannot be connected"""
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4508 """ because there is already another one active."""
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4509 """ Please check your configuration."""))
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4510 return
a0afd409c566 Added code to check, if there is an auto-completion/calltip provider connected already.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1002
diff changeset
4511
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4512 self.__ctHookFunction = func
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4513
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4514 def unsetCallTipHook(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4515 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4516 Public method to unset a calltip hook.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4517 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4518 self.__ctHookFunction = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4519
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4520 def callTipHook(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4521 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4522 Public method to get the calltip hook function.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4523
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4524 @return function set by setCallTipHook()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4525 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4526 return self.__ctHookFunction
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4527
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4528 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4529 ## Methods needed by the context menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4530 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4531
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4532 def __marginNumber(self, xPos):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4533 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4534 Private method to calculate the margin number based on a x position.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4535
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4536 @param xPos x position (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4537 @return margin number (integer, -1 for no margin)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4538 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4539 width = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4540 for margin in range(5):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4541 width += self.marginWidth(margin)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4542 if xPos <= width:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4543 return margin
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4544 return -1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4545
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4546 def contextMenuEvent(self, evt):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4547 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4548 Private method implementing the context menu event.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4549
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4550 @param evt the context menu event (QContextMenuEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4551 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4552 evt.accept()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4553 if self.__marginNumber(evt.x()) == -1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4554 self.spellingMenuPos = self.positionFromPoint(evt.pos())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4555 if self.spellingMenuPos >= 0 and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4556 self.spell is not None and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4557 self.hasIndicator(self.spellingIndicator, self.spellingMenuPos):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4558 self.spellingMenu.popup(evt.globalPos())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4559 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4560 self.menu.popup(evt.globalPos())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4561 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4562 self.line = self.lineAt(evt.pos())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4563 if self.__unifiedMargins:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4564 self.marginMenu.popup(evt.globalPos())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4565 else:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4566 if self.__marginNumber(evt.x()) in [self.__bmMargin,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4567 self.__linenoMargin]:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4568 self.bmMarginMenu.popup(evt.globalPos())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4569 elif self.__marginNumber(evt.x()) == self.__bpMargin:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4570 self.bpMarginMenu.popup(evt.globalPos())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4571 elif self.__marginNumber(evt.x()) == self.__indicMargin:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4572 self.indicMarginMenu.popup(evt.globalPos())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4573
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4574 def __showContextMenu(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4575 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4576 Private slot handling the aboutToShow signal of the context menu.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4577 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4578 self.menuActs["Save"].setEnabled(self.isModified())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4579 self.menuActs["Undo"].setEnabled(self.isUndoAvailable())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4580 self.menuActs["Redo"].setEnabled(self.isRedoAvailable())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4581 self.menuActs["Revert"].setEnabled(self.isModified())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4582 if not self.miniMenu:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4583 self.menuActs["Cut"].setEnabled(self.hasSelectedText())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4584 self.menuActs["Copy"].setEnabled(self.hasSelectedText())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4585 if not self.isResourcesFile:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4586 if self.fileName and \
1762
307393ebe9c6 Some little optimisations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1758
diff changeset
4587 (self.isPy3File() or self.isPy2File()):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4588 self.menuActs["Show"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4589 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4590 self.menuActs["Show"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4591 if self.fileName and \
1762
307393ebe9c6 Some little optimisations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1758
diff changeset
4592 (self.isPy3File() or self.isPy2File() or self.isRubyFile()):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4593 self.menuActs["Diagrams"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4594 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4595 self.menuActs["Diagrams"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4596 if not self.miniMenu:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4597 if self.lexer_ is not None:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4598 self.menuActs["Comment"].setEnabled(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4599 self.lexer_.canBlockComment())
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4600 self.menuActs["Uncomment"].setEnabled(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4601 self.lexer_.canBlockComment())
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4602 self.menuActs["StreamComment"].setEnabled(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4603 self.lexer_.canStreamComment())
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4604 self.menuActs["BoxComment"].setEnabled(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4605 self.lexer_.canBoxComment())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4606 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4607 self.menuActs["Comment"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4608 self.menuActs["Uncomment"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4609 self.menuActs["StreamComment"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4610 self.menuActs["BoxComment"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4611
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4612 self.menuActs["TypingAidsEnabled"].setEnabled(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4613 self.completer is not None)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
4614 self.menuActs["TypingAidsEnabled"].setChecked(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4615 self.completer is not None and self.completer.isEnabled())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4616
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
4617 from .SpellChecker import SpellChecker
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4618 spellingAvailable = SpellChecker.isAvailable()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4619 self.menuActs["SpellCheck"].setEnabled(spellingAvailable)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4620 self.menuActs["SpellCheckSelection"].setEnabled(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4621 spellingAvailable and self.hasSelectedText())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4622 self.menuActs["SpellCheckRemove"].setEnabled(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4623 spellingAvailable and self.spellingMenuPos >= 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4624
1299
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4625 if self.menuActs["OpenRejections"]:
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4626 if self.fileName:
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4627 rej = "{0}.rej".format(self.fileName)
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4628 self.menuActs["OpenRejections"].setEnabled(os.path.exists(rej))
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4629 else:
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4630 self.menuActs["OpenRejections"].setEnabled(False)
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4631
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
4632 self.showMenu.emit("Main", self.menu, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4633
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4634 def __showContextMenuAutocompletion(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4635 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4636 Private slot called before the autocompletion menu is shown.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4637 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4638 self.menuActs["acDynamic"].setEnabled(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4639 self.acAPI or self.__acHookFunction is not None)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4640 self.menuActs["acAPI"].setEnabled(self.acAPI)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4641 self.menuActs["acAPIDocument"].setEnabled(self.acAPI)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4642 self.menuActs["calltip"].setEnabled(self.acAPI)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4643
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
4644 self.showMenu.emit("Autocompletion", self.autocompletionMenu, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4645
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4646 def __showContextMenuShow(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4647 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4648 Private slot called before the show menu is shown.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4649 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4650 prEnable = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4651 coEnable = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4652
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4653 # first check if the file belongs to a project
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4654 if self.project.isOpen() and \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4655 self.project.isProjectSource(self.fileName):
252
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
4656 fn = self.project.getMainScript(True)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4657 if fn is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4658 tfn = Utilities.getTestFileName(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4659 basename = os.path.splitext(fn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4660 tbasename = os.path.splitext(tfn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4661 prEnable = prEnable or \
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
4662 os.path.isfile("{0}.profile".format(basename)) or \
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
4663 os.path.isfile("{0}.profile".format(tbasename))
1491
985c5abc8226 Corrected a few issues related to showing the coverage context menu items.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1474
diff changeset
4664 coEnable = (coEnable or \
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
4665 os.path.isfile("{0}.coverage".format(basename)) or \
1491
985c5abc8226 Corrected a few issues related to showing the coverage context menu items.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1474
diff changeset
4666 os.path.isfile("{0}.coverage".format(tbasename))) and \
985c5abc8226 Corrected a few issues related to showing the coverage context menu items.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1474
diff changeset
4667 self.project.isPy3Project()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4668
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4669 # now check ourself
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4670 fn = self.getFileName()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4671 if fn is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4672 tfn = Utilities.getTestFileName(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4673 basename = os.path.splitext(fn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4674 tbasename = os.path.splitext(tfn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4675 prEnable = prEnable or \
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
4676 os.path.isfile("{0}.profile".format(basename)) or \
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
4677 os.path.isfile("{0}.profile".format(tbasename))
1491
985c5abc8226 Corrected a few issues related to showing the coverage context menu items.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1474
diff changeset
4678 coEnable = (coEnable or \
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
4679 os.path.isfile("{0}.coverage".format(basename)) or \
1491
985c5abc8226 Corrected a few issues related to showing the coverage context menu items.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1474
diff changeset
4680 os.path.isfile("{0}.coverage".format(tbasename))) and \
985c5abc8226 Corrected a few issues related to showing the coverage context menu items.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1474
diff changeset
4681 self.isPy3File()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4682
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4683 # now check for syntax errors
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4684 if self.hasSyntaxErrors():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4685 coEnable = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4686
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4687 self.profileMenuAct.setEnabled(prEnable)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4688 self.coverageMenuAct.setEnabled(coEnable)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
4689 self.coverageShowAnnotationMenuAct.setEnabled(
2391
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
4690 coEnable and len(self.notcoveredMarkers) == 0)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
4691 self.coverageHideAnnotationMenuAct.setEnabled(
2391
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
4692 len(self.notcoveredMarkers) > 0)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
4693
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
4694 self.showMenu.emit("Show", self.menuShow, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4695
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4696 def __showContextMenuGraphics(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4697 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4698 Private slot handling the aboutToShow signal of the diagrams context
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4699 menu.
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4700 """
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4701 if self.project.isOpen() and \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4702 self.project.isProjectSource(self.fileName):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4703 self.applicationDiagramMenuAct.setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4704 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4705 self.applicationDiagramMenuAct.setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4706
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
4707 self.showMenu.emit("Graphics", self.graphicsMenu, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4708
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4709 def __showContextMenuMargin(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4710 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4711 Private slot handling the aboutToShow signal of the margins context
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4712 menu.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4713 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4714 if self.fileName and \
1762
307393ebe9c6 Some little optimisations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1758
diff changeset
4715 (self.isPy3File() or self.isPy2File() or self.isRubyFile()):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4716 self.marginMenuActs["Breakpoint"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4717 self.marginMenuActs["TempBreakpoint"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4718 if self.markersAtLine(self.line) & self.breakpointMask:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4719 self.marginMenuActs["EditBreakpoint"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4720 self.marginMenuActs["EnableBreakpoint"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4721 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4722 self.marginMenuActs["EditBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4723 self.marginMenuActs["EnableBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4724 if self.markersAtLine(self.line) & (1 << self.dbreakpoint):
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
4725 self.marginMenuActs["EnableBreakpoint"].setText(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4726 self.trUtf8('Enable breakpoint'))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4727 else:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
4728 self.marginMenuActs["EnableBreakpoint"].setText(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4729 self.trUtf8('Disable breakpoint'))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4730 if self.breaks:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4731 self.marginMenuActs["NextBreakpoint"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4732 self.marginMenuActs["PreviousBreakpoint"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4733 self.marginMenuActs["ClearBreakpoint"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4734 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4735 self.marginMenuActs["NextBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4736 self.marginMenuActs["PreviousBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4737 self.marginMenuActs["ClearBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4738 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4739 self.marginMenuActs["Breakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4740 self.marginMenuActs["TempBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4741 self.marginMenuActs["EditBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4742 self.marginMenuActs["EnableBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4743 self.marginMenuActs["NextBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4744 self.marginMenuActs["PreviousBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4745 self.marginMenuActs["ClearBreakpoint"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4746
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4747 if self.bookmarks:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4748 self.marginMenuActs["NextBookmark"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4749 self.marginMenuActs["PreviousBookmark"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4750 self.marginMenuActs["ClearBookmark"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4751 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4752 self.marginMenuActs["NextBookmark"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4753 self.marginMenuActs["PreviousBookmark"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4754 self.marginMenuActs["ClearBookmark"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4755
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4756 if len(self.syntaxerrors):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4757 self.marginMenuActs["GotoSyntaxError"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4758 self.marginMenuActs["ClearSyntaxError"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4759 if self.markersAtLine(self.line) & (1 << self.syntaxerror):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4760 self.marginMenuActs["ShowSyntaxError"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4761 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4762 self.marginMenuActs["ShowSyntaxError"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4763 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4764 self.marginMenuActs["GotoSyntaxError"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4765 self.marginMenuActs["ClearSyntaxError"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4766 self.marginMenuActs["ShowSyntaxError"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4767
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4768 if len(self.warnings):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4769 self.marginMenuActs["NextWarningMarker"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4770 self.marginMenuActs["PreviousWarningMarker"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4771 self.marginMenuActs["ClearWarnings"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4772 if self.markersAtLine(self.line) & (1 << self.warning):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4773 self.marginMenuActs["ShowWarning"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4774 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4775 self.marginMenuActs["ShowWarning"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4776 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4777 self.marginMenuActs["NextWarningMarker"].setEnabled(False)
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4778 self.marginMenuActs["PreviousWarningMarker"].setEnabled(False)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4779 self.marginMenuActs["ClearWarnings"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4780 self.marginMenuActs["ShowWarning"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4781
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4782 if self.notcoveredMarkers:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4783 self.marginMenuActs["NextCoverageMarker"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4784 self.marginMenuActs["PreviousCoverageMarker"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4785 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4786 self.marginMenuActs["NextCoverageMarker"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4787 self.marginMenuActs["PreviousCoverageMarker"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4788
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4789 if self.__hasTaskMarkers:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4790 self.marginMenuActs["PreviousTaskMarker"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4791 self.marginMenuActs["NextTaskMarker"].setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4792 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4793 self.marginMenuActs["PreviousTaskMarker"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4794 self.marginMenuActs["NextTaskMarker"].setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4795
2162
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
4796 if self.__hasChangeMarkers:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
4797 self.marginMenuActs["PreviousChangeMarker"].setEnabled(True)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
4798 self.marginMenuActs["NextChangeMarker"].setEnabled(True)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
4799 else:
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
4800 self.marginMenuActs["PreviousChangeMarker"].setEnabled(False)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
4801 self.marginMenuActs["NextChangeMarker"].setEnabled(False)
4627e6ea7b6b Added capability to mark changed lines and to navigate between them to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2084
diff changeset
4802
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
4803 self.showMenu.emit("Margin", self.sender(), self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4804
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4805 def __showContextMenuChecks(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4806 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4807 Private slot handling the aboutToShow signal of the checks context
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4808 menu.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4809 """
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
4810 self.showMenu.emit("Checks", self.checksMenu, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4811
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4812 def __contextSave(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4813 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4814 Private slot handling the save context menu entry.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4815 """
548
ac7af05dd54a Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 547
diff changeset
4816 ok = self.saveFile()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4817 if ok:
548
ac7af05dd54a Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 547
diff changeset
4818 self.vm.setEditorName(self, self.fileName)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4819
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4820 def __contextSaveAs(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4821 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4822 Private slot handling the save as context menu entry.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4823 """
559
ee695ebbd6e0 Fixed an issue introduced by the E5MessageBox job.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 553
diff changeset
4824 ok = self.saveFileAs()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4825 if ok:
559
ee695ebbd6e0 Fixed an issue introduced by the E5MessageBox job.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 553
diff changeset
4826 self.vm.setEditorName(self, self.fileName)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4827
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4828 def __contextClose(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4829 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4830 Private slot handling the close context menu entry.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4831 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4832 self.vm.closeEditor(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4833
1299
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4834 def __contextOpenRejections(self):
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4835 """
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4836 Private slot handling the open rejections file context menu entry.
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4837 """
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4838 if self.fileName:
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4839 rej = "{0}.rej".format(self.fileName)
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4840 if os.path.exists(rej):
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4841 self.vm.openSourceFile(rej)
fd5d21389d2b Added an action to the editor context menu and to the tabview and listview view managers to open an associated 'rejections' file (i.e. same file name with '.rej' appended).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1295
diff changeset
4842
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4843 def __newView(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4844 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4845 Private slot to create a new view to an open document.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4846 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4847 self.vm.newEditorView(self.fileName, self, self.filetype)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4848
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4849 def __newViewNewSplit(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4850 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4851 Private slot to create a new view to an open document.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4852 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4853 self.vm.addSplit()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4854 self.vm.newEditorView(self.fileName, self, self.filetype)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4855
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4856 def __selectAll(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4857 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4858 Private slot handling the select all context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4859 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4860 self.selectAll(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4861
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4862 def __deselectAll(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4863 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4864 Private slot handling the deselect all context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4865 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4866 self.selectAll(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4867
478
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4868 def joinLines(self):
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4869 """
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4870 Public slot to join the current line with the next one.
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4871 """
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4872 curLine = self.getCursorPosition()[0]
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4873 if curLine == self.lines() - 1:
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4874 return
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4875
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4876 line0Text = self.text(curLine)
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4877 line1Text = self.text(curLine + 1)
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4878 if line1Text in ["", "\r", "\n", "\r\n"]:
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4879 return
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4880
2994
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4881 if line0Text.rstrip("\r\n\\ \t").endswith(("'", '"')) and \
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4882 line1Text.lstrip().startswith(("'", '"')):
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4883 # merging multi line strings
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4884 startChars = "\r\n\\ \t'\""
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4885 endChars = " \t'\""
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4886 else:
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4887 startChars = "\r\n\\ \t"
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4888 endChars = " \t"
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4889
478
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4890 # determine start index
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4891 startIndex = len(line0Text)
2994
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4892 while startIndex > 0 and line0Text[startIndex - 1] in startChars:
478
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4893 startIndex -= 1
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4894 if startIndex == 0:
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4895 return
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4896
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4897 # determine end index
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4898 endIndex = 0
2994
5ae1349b8fb4 A little enhancement to the editors line joining function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2980
diff changeset
4899 while line1Text[endIndex] in endChars:
478
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4900 endIndex += 1
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4901
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4902 self.setSelection(curLine, startIndex, curLine + 1, endIndex)
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4903 self.beginUndoAction()
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4904 self.removeSelectedText()
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4905 self.insertAt(" ", curLine, startIndex)
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4906 self.endUndoAction()
e7d778ea21d6 Added an editor action to join the current line with the next one.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 461
diff changeset
4907
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4908 def shortenEmptyLines(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4909 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4910 Public slot to compress lines consisting solely of whitespace
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4911 characters.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4912 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4913 searchRE = r"^[ \t]+$"
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4914
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4915 ok = self.findFirstTarget(searchRE, True, False, False, 0, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4916 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4917 while ok:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4918 self.replaceTarget("")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4919 ok = self.findNextTarget()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4920 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4921
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4922 def __autosaveEnable(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4923 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4924 Private slot handling the autosave enable context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4925 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4926 if self.menuActs["AutosaveEnable"].isChecked():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4927 self.autosaveManuallyDisabled = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4928 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4929 self.autosaveManuallyDisabled = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4930
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4931 def shouldAutosave(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4932 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4933 Public slot to check the autosave flags.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4934
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4935 @return flag indicating this editor should be saved (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4936 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4937 return self.fileName is not None and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4938 not self.autosaveManuallyDisabled and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4939 not self.isReadOnly()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4940
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4941 def __autoSyntaxCheck(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4942 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4943 Private method to perform an automatic syntax check of the file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4944 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4945 if Preferences.getEditor("AutoCheckSyntax"):
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
4946 if Preferences.getEditor("OnlineSyntaxCheck"):
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
4947 self.__onlineSyntaxCheckTimer.stop()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4948 self.clearSyntaxError()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4949 self.clearFlakesWarnings()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4950 if self.isPy3File():
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4951 syntaxError, _fn, errorline, errorindex, _code, _error = \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4952 Utilities.compile(self.fileName or "(Unnamed)",
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4953 self.text())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4954 if syntaxError:
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4955 self.toggleSyntaxError(
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4956 int(errorline), int(errorindex), True, _error)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4957 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4958 if Preferences.getFlakes("IncludeInSyntaxCheck"):
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
4959 from Utilities.py3flakes.checker import Checker
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
4960 from Utilities.py3flakes.messages import ImportStarUsed
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
4961
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4962 ignoreStarImportWarnings = \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
4963 Preferences.getFlakes("IgnoreStarImportWarnings")
115
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4964 try:
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4965 txt = self.text()\
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4966 .replace("\r\n", "\n")\
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4967 .replace("\r", "\n")
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4968 warnings = Checker(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4969 txt, self.fileName or "(Unnamed)")
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4970 warnings.messages.sort(key=lambda a: a.lineno)
115
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4971 for warning in warnings.messages:
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4972 if ignoreStarImportWarnings and \
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4973 isinstance(warning, ImportStarUsed):
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4974 continue
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4975
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4976 _fn, lineno, message = warning.getMessageData()
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4977 if "__IGNORE_WARNING__" not in \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4978 Utilities.extractLineFlags(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
4979 self.text(lineno - 1).strip()):
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4980 self.toggleFlakesWarning(
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4981 lineno, True, message)
115
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4982 except SyntaxError as err:
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4983 if err.text.strip():
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4984 msg = err.text.strip()
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4985 else:
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4986 msg = err.msg
13d58f643b43 Fixed an issue where the py3flakes checker threw a syntax error although the syntax check passed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 109
diff changeset
4987 self.toggleSyntaxError(err.lineno, True, msg)
984
f4bddd7cf51e Fixed an issue with automatic syntax check of an unsaved file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 971
diff changeset
4988 elif self.isPy2File() and self.fileName is not None:
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4989 syntaxError, _fn, errorline, errorindex, _code, _error, \
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4990 warnings = Utilities.py2compile(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
4991 self.fileName,
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4992 checkFlakes=Preferences.getFlakes("IncludeInSyntaxCheck"))
795
917f1945355c Added a syntax checker function for Python 2 files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
4993 if syntaxError:
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4994 self.toggleSyntaxError(
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4995 int(errorline), int(errorindex), True, _error)
802
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
4996 else:
e8882d16384c Added a pyflakes checker function for Python 2 files and made some additional Python 2 related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 795
diff changeset
4997 for warning in warnings:
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4998 self.toggleFlakesWarning(
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
4999 int(warning[1]), True, warning[2])
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5000
1353
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5001 def __initOnlineSyntaxCheck(self):
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5002 """
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5003 Private slot to initialize the online syntax check.
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5004 """
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5005 self.__onlineSyntaxCheckTimer = QTimer(self)
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5006 self.__onlineSyntaxCheckTimer.setSingleShot(True)
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5007 self.__onlineSyntaxCheckTimer.setInterval(
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5008 Preferences.getEditor("OnlineSyntaxCheckInterval") * 1000)
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5009 self.__onlineSyntaxCheckTimer.timeout.connect(self.__autoSyntaxCheck)
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5010 self.textChanged.connect(self.__resetOnlineSyntaxCheckTimer)
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5011
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5012 def __resetOnlineSyntaxCheckTimer(self):
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5013 """
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5014 Private method to reset the online syntax check timer.
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5015 """
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5016 if Preferences.getEditor("OnlineSyntaxCheck"):
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5017 self.__onlineSyntaxCheckTimer.stop()
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5018 self.__onlineSyntaxCheckTimer.start()
e1c0af081a8e Added a syntax check while typing function.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1308
diff changeset
5019
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5020 def __showCodeMetrics(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5021 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5022 Private method to handle the code metrics context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5023 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5024 if not self.checkDirty():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5025 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5026
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
5027 from DataViews.CodeMetricsDialog import CodeMetricsDialog
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5028 self.codemetrics = CodeMetricsDialog()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5029 self.codemetrics.show()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5030 self.codemetrics.start(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5031
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5032 def __getCodeCoverageFile(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5033 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5034 Private method to get the filename of the file containing coverage
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5035 info.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5036
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5037 @return filename of the coverage file (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5038 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5039 files = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5040
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5041 # first check if the file belongs to a project and there is
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5042 # a project coverage file
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5043 if self.project.isOpen() and \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5044 self.project.isProjectSource(self.fileName):
252
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
5045 fn = self.project.getMainScript(True)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5046 if fn is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5047 tfn = Utilities.getTestFileName(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5048 basename = os.path.splitext(fn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5049 tbasename = os.path.splitext(tfn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5050
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
5051 f = "{0}.coverage".format(basename)
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
5052 tf = "{0}.coverage".format(tbasename)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5053 if os.path.isfile(f):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5054 files.append(f)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5055 if os.path.isfile(tf):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5056 files.append(tf)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5057
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5058 # now check, if there are coverage files belonging to ourself
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5059 fn = self.getFileName()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5060 if fn is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5061 tfn = Utilities.getTestFileName(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5062 basename = os.path.splitext(fn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5063 tbasename = os.path.splitext(tfn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5064
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
5065 f = "{0}.coverage".format(basename)
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
5066 tf = "{0}.coverage".format(tbasename)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5067 if os.path.isfile(f) and not f in files:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5068 files.append(f)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5069 if os.path.isfile(tf) and not tf in files:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5070 files.append(tf)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5071
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5072 if files:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5073 if len(files) > 1:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
5074 fn, ok = QInputDialog.getItem(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5075 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5076 self.trUtf8("Code Coverage"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5077 self.trUtf8("Please select a coverage file"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5078 files,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5079 0, False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5080 if not ok:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5081 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5082 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5083 fn = files[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5084 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5085 fn = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5086
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5087 return fn
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5088
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5089 def __showCodeCoverage(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5090 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5091 Private method to handle the code coverage context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5092 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5093 fn = self.__getCodeCoverageFile()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5094 if fn:
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
5095 from DataViews.PyCoverageDialog import PyCoverageDialog
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5096 self.codecoverage = PyCoverageDialog()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5097 self.codecoverage.show()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5098 self.codecoverage.start(fn, self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5099
2391
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5100 def refreshCoverageAnnotations(self):
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5101 """
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5102 Public method to refresh the code coverage annotations.
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5103 """
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5104 if self.showingNotcoveredMarkers:
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5105 self.codeCoverageShowAnnotations(silent=True)
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5106
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5107 def codeCoverageShowAnnotations(self, silent=False):
2163
2b02339f52bf Enhanced the code coverage dialog functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2162
diff changeset
5108 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5109 Public method to handle the show code coverage annotations context
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5110 menu action.
2391
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5111
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5112 @param silent flag indicating to not show any dialog (boolean)
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5113 """
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5114 self.__codeCoverageHideAnnotations()
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5115
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5116 fn = self.__getCodeCoverageFile()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5117 if fn:
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
5118 from DebugClients.Python3.coverage import coverage
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5119 cover = coverage(data_file=fn)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5120 cover.use_cache(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5121 cover.load()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5122 missing = cover.analysis2(self.fileName)[3]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5123 if missing:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5124 for line in missing:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5125 handle = self.markerAdd(line - 1, self.notcovered)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5126 self.notcoveredMarkers.append(handle)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5127 self.coverageMarkersShown.emit(True)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5128 else:
2391
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5129 if not silent:
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5130 E5MessageBox.information(self,
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5131 self.trUtf8("Show Code Coverage Annotations"),
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5132 self.trUtf8("""All lines have been covered."""))
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5133 self.showingNotcoveredMarkers = True
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5134 else:
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5135 if not silent:
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5136 E5MessageBox.warning(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5137 self.trUtf8("Show Code Coverage Annotations"),
2391
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5138 self.trUtf8("""There is no coverage file available."""))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5139
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5140 def __codeCoverageHideAnnotations(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5141 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5142 Private method to handle the hide code coverage annotations context
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5143 menu action.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5144 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5145 for handle in self.notcoveredMarkers:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5146 self.markerDeleteHandle(handle)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5147 self.notcoveredMarkers = []
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5148 self.coverageMarkersShown.emit(False)
2391
f9a6a512bc1e Added functionality to refresh the coverage markers of an editor if such are shown.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
5149 self.showingNotcoveredMarkers = False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5150
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5151 def hasCoverageMarkers(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5152 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5153 Public method to test, if there are coverage markers.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
5154
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
5155 @return flag indicating the presence of coverage markers (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5156 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5157 return len(self.notcoveredMarkers) > 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5158
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5159 def nextUncovered(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5160 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5161 Public slot to handle the 'Next uncovered' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5162 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5163 line, index = self.getCursorPosition()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5164 if line == self.lines() - 1:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5165 line = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5166 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5167 line += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5168 ucline = self.markerFindNext(line, 1 << self.notcovered)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5169 if ucline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5170 # wrap around
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5171 ucline = self.markerFindNext(0, 1 << self.notcovered)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5172 if ucline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5173 self.setCursorPosition(ucline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5174 self.ensureLineVisible(ucline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5175
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5176 def previousUncovered(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5177 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5178 Public slot to handle the 'Previous uncovered' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5179 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5180 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5181 if line == 0:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5182 line = self.lines() - 1
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5183 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5184 line -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5185 ucline = self.markerFindPrevious(line, 1 << self.notcovered)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5186 if ucline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5187 # wrap around
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5188 ucline = self.markerFindPrevious(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5189 self.lines() - 1, 1 << self.notcovered)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5190 if ucline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5191 self.setCursorPosition(ucline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5192 self.ensureLineVisible(ucline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5193
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5194 def __showProfileData(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5195 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5196 Private method to handle the show profile data context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5197 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5198 files = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5199
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5200 # first check if the file belongs to a project and there is
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5201 # a project profile file
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5202 if self.project.isOpen() and \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5203 self.project.isProjectSource(self.fileName):
252
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
5204 fn = self.project.getMainScript(True)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5205 if fn is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5206 tfn = Utilities.getTestFileName(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5207 basename = os.path.splitext(fn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5208 tbasename = os.path.splitext(tfn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5209
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
5210 f = "{0}.profile".format(basename)
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
5211 tf = "{0}.profile".format(tbasename)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5212 if os.path.isfile(f):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5213 files.append(f)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5214 if os.path.isfile(tf):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5215 files.append(tf)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5216
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5217 # now check, if there are profile files belonging to ourself
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5218 fn = self.getFileName()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5219 if fn is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5220 tfn = Utilities.getTestFileName(fn)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5221 basename = os.path.splitext(fn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5222 tbasename = os.path.splitext(tfn)[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5223
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
5224 f = "{0}.profile".format(basename)
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
5225 tf = "{0}.profile".format(tbasename)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5226 if os.path.isfile(f) and not f in files:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5227 files.append(f)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5228 if os.path.isfile(tf) and not tf in files:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5229 files.append(tf)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5230
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5231 if files:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5232 if len(files) > 1:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
5233 fn, ok = QInputDialog.getItem(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5234 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5235 self.trUtf8("Profile Data"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5236 self.trUtf8("Please select a profile file"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5237 files,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5238 0, False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5239 if not ok:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5240 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5241 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5242 fn = files[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5243 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5244 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5245
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
5246 from DataViews.PyProfileDialog import PyProfileDialog
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5247 self.profiledata = PyProfileDialog()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5248 self.profiledata.show()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5249 self.profiledata.start(fn, self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5250
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5251 def __lmBbookmarks(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5252 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5253 Private method to handle the 'LMB toggles bookmark' context menu
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5254 action.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5255 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5256 self.marginMenuActs["LMBbookmarks"].setChecked(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5257 self.marginMenuActs["LMBbreakpoints"].setChecked(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5258
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5259 def __lmBbreakpoints(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5260 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5261 Private method to handle the 'LMB toggles breakpoint' context menu
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5262 action.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5263 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5264 self.marginMenuActs["LMBbookmarks"].setChecked(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5265 self.marginMenuActs["LMBbreakpoints"].setChecked(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5266
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5267 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5268 ## Syntax error handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5269 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5270
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5271 def toggleSyntaxError(self, line, index, error, msg="", show=False):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5272 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5273 Public method to toggle a syntax error indicator.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5274
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5275 @param line line number of the syntax error (integer)
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5276 @param index index number of the syntax error (integer)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5277 @param error flag indicating if the error marker should be
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5278 set or deleted (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5279 @param msg error message (string)
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5280 @keyparam show flag indicating to set the cursor to the error position
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5281 (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5282 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5283 if line == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5284 line = 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5285 # hack to show a syntax error marker, if line is reported to be 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5286 if error:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5287 # set a new syntax error marker
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5288 markers = self.markersAtLine(line - 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5289 if not (markers & (1 << self.syntaxerror)):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5290 handle = self.markerAdd(line - 1, self.syntaxerror)
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5291 index += self.indentation(line - 1)
2904
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5292 self.syntaxerrors[handle] = [(msg, index)]
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5293 self.syntaxerrorToggled.emit(self)
2904
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5294 else:
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5295 for handle in list(self.syntaxerrors.keys()):
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5296 if self.markerLine(handle) == line - 1 and \
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5297 (msg, index) not in self.syntaxerrors[handle]:
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5298 self.syntaxerrors[handle].append((msg, index))
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5299 if show:
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5300 self.setCursorPosition(line - 1, index)
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5301 self.ensureLineVisible(line - 1)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5302 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5303 for handle in list(self.syntaxerrors.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5304 if self.markerLine(handle) == line - 1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5305 del self.syntaxerrors[handle]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5306 self.markerDeleteHandle(handle)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5307 self.syntaxerrorToggled.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5308
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5309 self.__setAnnotation(line - 1)
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5310
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5311 def getSyntaxErrors(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5312 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5313 Public method to retrieve the syntax error markers.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5314
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5315 @return sorted list of all lines containing a syntax error
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5316 (list of integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5317 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5318 selist = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5319 for handle in list(self.syntaxerrors.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5320 selist.append(self.markerLine(handle) + 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5321
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5322 selist.sort()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5323 return selist
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5324
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5325 def hasSyntaxErrors(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5326 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5327 Public method to check for the presence of syntax errors.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5328
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5329 @return flag indicating the presence of syntax errors (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5330 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5331 return len(self.syntaxerrors) > 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5332
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5333 def gotoSyntaxError(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5334 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5335 Public slot to handle the 'Goto syntax error' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5336 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5337 seline = self.markerFindNext(0, 1 << self.syntaxerror)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5338 if seline >= 0:
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5339 index = 0
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5340 for handle in self.syntaxerrors.keys():
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5341 if self.markerLine(handle) == seline:
2904
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5342 index = self.syntaxerrors[handle][0][1]
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5343 self.setCursorPosition(seline, index)
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5344 self.ensureLineVisible(seline)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5345
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5346 def clearSyntaxError(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5347 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5348 Public slot to handle the 'Clear all syntax error' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5349 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5350 for handle in list(self.syntaxerrors.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5351 line = self.markerLine(handle) + 1
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5352 self.toggleSyntaxError(line, 0, False)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5353
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5354 def __showSyntaxError(self, line=-1):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5355 """
915
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5356 Private slot to handle the 'Show syntax error message'
c1e052773c08 Changed syntax check to report error position within the line.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
5357 context menu action.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5358
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5359 @param line line number to show the syntax error for (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5360 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5361 if line == -1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5362 line = self.line
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5363
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5364 for handle in list(self.syntaxerrors.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5365 if self.markerLine(handle) == line:
2904
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5366 errors = [e[0] for e in self.syntaxerrors[handle]]
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 536
diff changeset
5367 E5MessageBox.critical(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5368 self.trUtf8("Syntax Error"),
2904
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5369 "\n".join(errors))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5370 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5371 else:
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 536
diff changeset
5372 E5MessageBox.critical(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5373 self.trUtf8("Syntax Error"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5374 self.trUtf8("No syntax error message available."))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5375
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5376 ###########################################################################
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5377 ## Flakes warning handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5378 ###########################################################################
2904
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5379
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5380 def toggleFlakesWarning(self, line, warning, msg="",
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5381 warningType=WarningCode):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5382 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5383 Public method to toggle a flakes warning indicator.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5384
2980
2cb4e3c50b37 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
5385 Note: This method is used to set code style warnings as well.
832
eb5ff61f927b Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
5386
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5387 @param line line number of the flakes warning
832
eb5ff61f927b Added a checker for PEP 8 compliance.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
5388 @param warning flag indicating if the warning marker should be
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5389 set or deleted (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5390 @param msg warning message (string)
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5391 @keyparam warningType type of warning message (integer)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5392 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5393 if line == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5394 line = 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5395 # hack to show a warning marker, if line is reported to be 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5396 if warning:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5397 # set/ammend a new warning marker
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5398 warn = (msg, warningType)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5399 markers = self.markersAtLine(line - 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5400 if not (markers & (1 << self.warning)):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5401 handle = self.markerAdd(line - 1, self.warning)
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5402 self.warnings[handle] = [warn]
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5403 self.syntaxerrorToggled.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5404 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5405 for handle in list(self.warnings.keys()):
95
261bc03812fd Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 92
diff changeset
5406 if self.markerLine(handle) == line - 1 and \
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5407 warn not in self.warnings[handle]:
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5408 self.warnings[handle].append(warn)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5409 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5410 for handle in list(self.warnings.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5411 if self.markerLine(handle) == line - 1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5412 del self.warnings[handle]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5413 self.markerDeleteHandle(handle)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5414 self.syntaxerrorToggled.emit(self)
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5415
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5416 self.__setAnnotation(line - 1)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5417
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5418 def getFlakesWarnings(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5419 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5420 Public method to retrieve the flakes warning markers.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5421
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5422 @return sorted list of all lines containing a flakes warning
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5423 (list of integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5424 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5425 fwlist = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5426 for handle in list(self.warnings.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5427 fwlist.append(self.markerLine(handle) + 1)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5428
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5429 fwlist.sort()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5430 return fwlist
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5431
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5432 def hasFlakesWarnings(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5433 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5434 Public method to check for the presence of flakes warnings.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5435
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5436 @return flag indicating the presence of flakes warnings (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5437 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5438 return len(self.warnings) > 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5439
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5440 def nextFlakesWarning(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5441 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5442 Public slot to handle the 'Next warning' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5443 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5444 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5445 if line == self.lines() - 1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5446 line = 0
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5447 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5448 line += 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5449 fwline = self.markerFindNext(line, 1 << self.warning)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5450 if fwline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5451 # wrap around
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5452 fwline = self.markerFindNext(0, 1 << self.warning)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5453 if fwline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5454 self.setCursorPosition(fwline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5455 self.ensureLineVisible(fwline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5456
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5457 def previousFlakesWarning(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5458 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5459 Public slot to handle the 'Previous warning' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5460 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5461 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5462 if line == 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5463 line = self.lines() - 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5464 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5465 line -= 1
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5466 fwline = self.markerFindPrevious(line, 1 << self.warning)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5467 if fwline < 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5468 # wrap around
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5469 fwline = self.markerFindPrevious(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5470 self.lines() - 1, 1 << self.warning)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5471 if fwline >= 0:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5472 self.setCursorPosition(fwline, 0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5473 self.ensureLineVisible(fwline)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5474
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5475 def clearFlakesWarnings(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5476 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5477 Public slot to handle the 'Clear all warnings' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5478 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5479 for handle in self.warnings:
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5480 self.warnings[handle] = []
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5481 self.__setAnnotation(self.markerLine(handle))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5482 self.markerDeleteHandle(handle)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5483 self.warnings = {}
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5484 self.syntaxerrorToggled.emit(self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5485
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5486 def __showFlakesWarning(self, line=-1):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5487 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5488 Private slot to handle the 'Show warning' context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5489
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5490 @param line line number to show the flakes warning for (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5491 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5492 if line == -1:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5493 line = self.line
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5494
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5495 for handle in list(self.warnings.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5496 if self.markerLine(handle) == line:
539
87f9bce38a44 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 538
diff changeset
5497 E5MessageBox.warning(self,
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5498 self.trUtf8("Warning"),
2955
e9aeafe80329 Fixed an issue in the editor showing warning messages via the margin.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2926
diff changeset
5499 '\n'.join([w[0] for w in self.warnings[handle]]))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5500 break
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5501 else:
539
87f9bce38a44 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 538
diff changeset
5502 E5MessageBox.warning(self,
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5503 self.trUtf8("Warning"),
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5504 self.trUtf8("No warning messages available."))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5505
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5506 ###########################################################################
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5507 ## Annotation handling methods below
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5508 ###########################################################################
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5509
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5510 def __setAnnotationStyles(self):
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5511 """
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5512 Private slot to define the style used by inline annotations.
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5513 """
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5514 if hasattr(QsciScintilla, "annotate"):
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5515 self.annotationWarningStyle = \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5516 QsciScintilla.STYLE_LASTPREDEFINED + 1
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5517 self.SendScintilla(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5518 QsciScintilla.SCI_STYLESETFORE,
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5519 self.annotationWarningStyle,
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5520 Preferences.getEditorColour("AnnotationsWarningForeground"))
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5521 self.SendScintilla(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5522 QsciScintilla.SCI_STYLESETBACK,
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5523 self.annotationWarningStyle,
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5524 Preferences.getEditorColour("AnnotationsWarningBackground"))
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5525
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5526 self.annotationErrorStyle = self.annotationWarningStyle + 1
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5527 self.SendScintilla(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5528 QsciScintilla.SCI_STYLESETFORE,
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5529 self.annotationErrorStyle,
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5530 Preferences.getEditorColour("AnnotationsErrorForeground"))
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5531 self.SendScintilla(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5532 QsciScintilla.SCI_STYLESETBACK,
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5533 self.annotationErrorStyle,
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5534 Preferences.getEditorColour("AnnotationsErrorBackground"))
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5535
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5536 self.annotationStyleStyle = self.annotationErrorStyle + 1
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5537 self.SendScintilla(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5538 QsciScintilla.SCI_STYLESETFORE,
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5539 self.annotationStyleStyle,
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5540 Preferences.getEditorColour("AnnotationsStyleForeground"))
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5541 self.SendScintilla(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5542 QsciScintilla.SCI_STYLESETBACK,
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5543 self.annotationStyleStyle,
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5544 Preferences.getEditorColour("AnnotationsStyleBackground"))
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5545
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5546 def __setAnnotation(self, line):
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5547 """
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5548 Private method to set the annotations for the given line.
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5549
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5550 @param line number of the line that needs annotation (integer)
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5551 """
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5552 if hasattr(QsciScintilla, "annotate"):
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5553 warningAnnotations = []
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5554 errorAnnotations = []
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5555 styleAnnotations = []
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5556
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5557 # step 1: do warnings
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5558 for handle in list(self.warnings.keys()):
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5559 if self.markerLine(handle) == line:
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5560 for msg, warningType in self.warnings[handle]:
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5561 if warningType == self.WarningStyle:
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5562 styleAnnotations.append(
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5563 self.trUtf8("Style: {0}").format(msg))
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5564 else:
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5565 warningAnnotations.append(
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5566 self.trUtf8("Warning: {0}").format(msg))
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5567
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5568 # step 2: do syntax errors
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5569 for handle in list(self.syntaxerrors.keys()):
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5570 if self.markerLine(handle) == line:
2904
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5571 for msg, _ in self.syntaxerrors[handle]:
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5572 errorAnnotations.append(
1da821da961e Changed editor code to allow multiple syntax error messages per line and changed PEP-8 dialog to show E901 errors as error instead of warning.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2900
diff changeset
5573 self.trUtf8("Error: {0}").format(msg))
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5574
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5575 annotations = []
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
5576 if styleAnnotations:
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5577 annotationStyleTxt = "\n".join(styleAnnotations)
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
5578 if warningAnnotations or errorAnnotations:
2905
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5579 annotationStyleTxt += "\n"
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5580 annotations.append(QsciStyledText(annotationStyleTxt,
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5581 self.annotationStyleStyle))
a1ae4b297bc0 Added capability to have different warning styles to the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2904
diff changeset
5582
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
5583 if warningAnnotations:
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5584 annotationWarningTxt = "\n".join(warningAnnotations)
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
5585 if errorAnnotations:
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5586 annotationWarningTxt += "\n"
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5587 annotations.append(QsciStyledText(annotationWarningTxt,
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5588 self.annotationWarningStyle))
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5589
2959
86ad8854361b Corrected an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2955
diff changeset
5590 if errorAnnotations:
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5591 annotationErrorTxt = "\n".join(errorAnnotations)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5592 annotations.append(QsciStyledText(annotationErrorTxt,
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5593 self.annotationErrorStyle))
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5594
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5595 if annotations:
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5596 self.annotate(line, annotations)
726
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5597 else:
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5598 self.clearAnnotations(line)
57d1efea16e0 Started implementing annotations support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 723
diff changeset
5599
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5600 def __refreshAnnotations(self):
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5601 """
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5602 Private method to refresh the annotations.
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5603 """
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5604 if hasattr(QsciScintilla, "annotate"):
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5605 self.clearAnnotations()
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5606 for handle in list(self.warnings.keys()) + \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5607 list(self.syntaxerrors.keys()):
728
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5608 line = self.markerLine(handle)
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5609 self.__setAnnotation(line)
3ee110082fb7 Finished implementing the display of annotations .
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 726
diff changeset
5610
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5611 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5612 ## Macro handling methods
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5613 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5614
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5615 def __getMacroName(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5616 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5617 Private method to select a macro name from the list of macros.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5618
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5619 @return Tuple of macro name and a flag, indicating, if the user
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5620 pressed ok or canceled the operation. (string, boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5621 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5622 qs = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5623 for s in list(self.macros.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5624 qs.append(s)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5625 qs.sort()
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
5626 return QInputDialog.getItem(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5627 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5628 self.trUtf8("Macro Name"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5629 self.trUtf8("Select a macro name:"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5630 qs,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5631 0, False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5632
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5633 def macroRun(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5634 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5635 Public method to execute a macro.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5636 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5637 name, ok = self.__getMacroName()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5638 if ok and name:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5639 self.macros[name].play()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5640
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5641 def macroDelete(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5642 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5643 Public method to delete a macro.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5644 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5645 name, ok = self.__getMacroName()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5646 if ok and name:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5647 del self.macros[name]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5648
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5649 def macroLoad(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5650 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5651 Public method to load a macro from a file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5652 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5653 configDir = Utilities.getConfigDir()
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
5654 fname = E5FileDialog.getOpenFileName(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5655 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5656 self.trUtf8("Load macro file"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5657 configDir,
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
5658 self.trUtf8("Macro files (*.macro)"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5659
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5660 if not fname:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5661 return # user aborted
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5662
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5663 try:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5664 f = open(fname, "r", encoding="utf-8")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5665 lines = f.readlines()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5666 f.close()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5667 except IOError:
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 536
diff changeset
5668 E5MessageBox.critical(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5669 self.trUtf8("Error loading macro"),
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5670 self.trUtf8(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5671 "<p>The macro file <b>{0}</b> could not be read.</p>")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5672 .format(fname))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5673 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5674
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5675 if len(lines) != 2:
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 536
diff changeset
5676 E5MessageBox.critical(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5677 self.trUtf8("Error loading macro"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5678 self.trUtf8("<p>The macro file <b>{0}</b> is corrupt.</p>")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5679 .format(fname))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5680 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5681
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5682 macro = QsciMacro(lines[1], self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5683 self.macros[lines[0].strip()] = macro
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5684
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5685 def macroSave(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5686 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5687 Public method to save a macro to a file.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5688 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5689 configDir = Utilities.getConfigDir()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5690
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5691 name, ok = self.__getMacroName()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5692 if not ok or not name:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5693 return # user abort
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5694
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
5695 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5696 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5697 self.trUtf8("Save macro file"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5698 configDir,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5699 self.trUtf8("Macro files (*.macro)"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5700 "",
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
5701 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5702
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5703 if not fname:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5704 return # user aborted
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5705
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5706 ext = QFileInfo(fname).suffix()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5707 if not ext:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5708 ex = selectedFilter.split("(*")[1].split(")")[0]
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5709 if ex:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5710 fname += ex
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5711 if QFileInfo(fname).exists():
546
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 542
diff changeset
5712 res = E5MessageBox.yesNo(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5713 self.trUtf8("Save macro"),
546
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 542
diff changeset
5714 self.trUtf8("<p>The macro file <b>{0}</b> already exists."
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 542
diff changeset
5715 " Overwrite it?</p>").format(fname),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5716 icon=E5MessageBox.Warning)
546
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 542
diff changeset
5717 if not res:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5718 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5719 fname = Utilities.toNativeSeparators(fname)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5720
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5721 try:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5722 f = open(fname, "w", encoding="utf-8")
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
5723 f.write("{0}{1}".format(name, "\n"))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5724 f.write(self.macros[name].save())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5725 f.close()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5726 except IOError:
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 536
diff changeset
5727 E5MessageBox.critical(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5728 self.trUtf8("Error saving macro"),
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5729 self.trUtf8(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5730 "<p>The macro file <b>{0}</b> could not be written.</p>")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5731 .format(fname))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5732 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5733
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5734 def macroRecordingStart(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5735 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5736 Public method to start macro recording.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5737 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5738 if self.recording:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5739 res = E5MessageBox.yesNo(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5740 self.trUtf8("Start Macro Recording"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5741 self.trUtf8("Macro recording is already active. Start new?"),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5742 icon=E5MessageBox.Warning,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5743 yesDefault=True)
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
5744 if res:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5745 self.macroRecordingStop()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5746 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5747 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5748 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5749 self.recording = True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5750
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5751 self.curMacro = QsciMacro(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5752 self.curMacro.startRecording()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5753
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5754 def macroRecordingStop(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5755 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5756 Public method to stop macro recording.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5757 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5758 if not self.recording:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5759 return # we are not recording
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5760
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5761 self.curMacro.endRecording()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5762 self.recording = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5763
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
5764 name, ok = QInputDialog.getText(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5765 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5766 self.trUtf8("Macro Recording"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5767 self.trUtf8("Enter name of the macro:"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5768 QLineEdit.Normal)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5769
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5770 if ok and name:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5771 self.macros[name] = self.curMacro
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5772
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5773 self.curMacro = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5774
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5775 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5776 ## Overwritten methods
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5777 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5778
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5779 def undo(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5780 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5781 Public method to undo the last recorded change.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5782 """
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
5783 super().undo()
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5784 self.undoAvailable.emit(self.isUndoAvailable())
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5785 self.redoAvailable.emit(self.isRedoAvailable())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5786
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5787 def redo(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5788 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5789 Public method to redo the last recorded change.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5790 """
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
5791 super().redo()
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5792 self.undoAvailable.emit(self.isUndoAvailable())
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
5793 self.redoAvailable.emit(self.isRedoAvailable())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5794
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5795 def close(self, alsoDelete=False):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5796 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5797 Public method called when the window gets closed.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5798
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5799 This overwritten method redirects the action to our
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5800 ViewManager.closeEditor, which in turn calls our closeIt
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5801 method.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5802
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5803 @param alsoDelete ignored
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
5804 @return flag indicating a successful close of the editor (boolean)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5805 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5806 return self.vm.closeEditor(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5807
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5808 def closeIt(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5809 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5810 Public method called by the viewmanager to finally get rid of us.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5811 """
1930
3ecd42f536fd Fixed an issue related to breakpoints and cloned editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1928
diff changeset
5812 if Preferences.getEditor("ClearBreaksOnClose") and not self.__clones:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5813 self.__menuClearBreakpoints()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5814
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5815 for clone in self.__clones[:]:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5816 self.removeClone(clone)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5817 clone.removeClone(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5818
460
6a3899e91d76 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 448
diff changeset
5819 self.breakpointModel.rowsAboutToBeRemoved.disconnect(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5820 self.__deleteBreakPoints)
460
6a3899e91d76 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 448
diff changeset
5821 self.breakpointModel.dataAboutToBeChanged.disconnect(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5822 self.__breakPointDataAboutToBeChanged)
460
6a3899e91d76 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 448
diff changeset
5823 self.breakpointModel.dataChanged.disconnect(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5824 self.__changeBreakPoints)
460
6a3899e91d76 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 448
diff changeset
5825 self.breakpointModel.rowsInserted.disconnect(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5826 self.__addBreakPoints)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5827
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5828 if self.spell:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5829 self.spell.stopIncrementalCheck()
1754
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
5830
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
5831 try:
507
23652b3a0533 Fixed an issue with not connected signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 502
diff changeset
5832 self.project.projectPropertiesChanged.disconnect(
23652b3a0533 Fixed an issue with not connected signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 502
diff changeset
5833 self.__projectPropertiesChanged)
1754
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
5834 except TypeError:
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
5835 pass
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5836
1406
e2f1634cceed Fixed an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1373
diff changeset
5837 if self.fileName:
e2f1634cceed Fixed an issue in the editor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1373
diff changeset
5838 self.taskViewer.clearFileTasks(self.fileName, True)
1373
b3b3c99dba01 Made tasks manager forget about global file tasks when file is closed (configurable via configuration dialog).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1353
diff changeset
5839
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
5840 super().close()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5841
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5842 def keyPressEvent(self, ev):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5843 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5844 Re-implemented to handle the user input a key at a time.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5845
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5846 @param ev key event (QKeyEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5847 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5848 txt = ev.text()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5849
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5850 # See it is text to insert.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5851 if len(txt) and txt >= " ":
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
5852 super().keyPressEvent(ev)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5853 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5854 ev.ignore()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5855
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5856 def focusInEvent(self, event):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5857 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5858 Protected method called when the editor receives focus.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5859
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5860 This method checks for modifications of the current file and
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5861 rereads it upon request. The cursor is placed at the current position
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5862 assuming, that it is in the vicinity of the old position after the
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5863 reread.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5864
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5865 @param event the event object (QFocusEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5866 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5867 self.recolor()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5868 self.vm.editActGrp.setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5869 self.vm.editorActGrp.setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5870 self.vm.copyActGrp.setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5871 self.vm.viewActGrp.setEnabled(True)
128
13e96bd0f5a5 Fixed an issue with handling the focus and (de-)activation of actions as it changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 115
diff changeset
5872 self.vm.searchActGrp.setEnabled(True)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5873 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5874 self.setCaretWidth(self.caretWidth)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5875 except AttributeError:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5876 pass
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5877 self.__updateReadOnly(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5878 if self.vm.editorsCheckFocusInEnabled() and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5879 not self.inReopenPrompt and self.fileName and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5880 QFileInfo(self.fileName).lastModified().toString() != \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5881 self.lastModified.toString():
1831
2dd263d670ca Fixed an issue in the editor that can lead to an endless loop.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1819
diff changeset
5882 self.inReopenPrompt = True
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5883 if Preferences.getEditor("AutoReopen") and not self.isModified():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5884 self.refresh()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5885 else:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
5886 msg = self.trUtf8(
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5887 """<p>The file <b>{0}</b> has been changed while it"""
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5888 """ was opened in eric5. Reread it?</p>""")\
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
5889 .format(self.fileName)
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
5890 yesDefault = True
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5891 if self.isModified():
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
5892 msg += self.trUtf8(
929
ed471c1f23b8 Fixed a typo.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 915
diff changeset
5893 """<br><b>Warning:</b> You will lose"""
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5894 """ your changes upon reopening it.""")
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
5895 yesDefault = False
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
5896 res = E5MessageBox.yesNo(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5897 self.trUtf8("File changed"), msg,
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5898 icon=E5MessageBox.Warning,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
5899 yesDefault=yesDefault)
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
5900 if res:
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5901 self.refresh()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5902 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5903 # do not prompt for this change again...
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5904 self.lastModified = QFileInfo(self.fileName).lastModified()
1831
2dd263d670ca Fixed an issue in the editor that can lead to an endless loop.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1819
diff changeset
5905 self.inReopenPrompt = False
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5906
404
44a541bea034 Added code to adjust the cursor flash time of the editor to the global settings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 342
diff changeset
5907 self.setCursorFlashTime(QApplication.cursorFlashTime())
44a541bea034 Added code to adjust the cursor flash time of the editor to the global settings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 342
diff changeset
5908
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
5909 super().focusInEvent(event)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5910
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5911 def focusOutEvent(self, event):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5912 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5913 Public method called when the editor loses focus.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5914
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5915 @param event the event object (QFocusEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5916 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5917 self.vm.editorActGrp.setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5918 self.setCaretWidth(0)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5919
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
5920 super().focusOutEvent(event)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5921
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5922 def changeEvent(self, evt):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5923 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5924 Protected method called to process an event.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5925
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5926 This implements special handling for the events showMaximized,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5927 showMinimized and showNormal. The windows caption is shortened
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5928 for the minimized mode and reset to the full filename for the
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5929 other modes. This is to make the editor windows work nicer
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5930 with the QWorkspace.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5931
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5932 @param evt the event, that was generated (QEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5933 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5934 if evt.type() == QEvent.WindowStateChange and \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5935 self.fileName is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5936 if self.windowState() == Qt.WindowStates(Qt.WindowMinimized):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5937 cap = os.path.basename(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5938 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5939 cap = self.fileName
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5940 if self.isReadOnly():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5941 cap = self.trUtf8("{0} (ro)").format(cap)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5942 self.setWindowTitle(cap)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5943
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
5944 super().changeEvent(evt)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5945
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5946 def mousePressEvent(self, event):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5947 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5948 Protected method to handle the mouse press event.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5949
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5950 @param event the mouse press event (QMouseEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5951 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5952 self.vm.eventFilter(self, event)
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
5953 super().mousePressEvent(event)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
5954
1507
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5955 def wheelEvent(self, evt):
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5956 """
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5957 Protected method to handle wheel events.
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5958
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5959 @param evt reference to the wheel event (QWheelEvent)
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5960 """
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5961 if evt.modifiers() & Qt.ControlModifier:
1588
dccffd13be8d Did some PEP-8 related corrections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1566
diff changeset
5962 if evt.delta() < 0:
1507
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5963 self.zoomOut()
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5964 else:
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5965 self.zoomIn()
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5966 evt.accept()
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5967 return
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5968
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5969 if evt.modifiers() & Qt.ShiftModifier:
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5970 if evt.delta() < 0:
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5971 self.gotoMethodClass(False)
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5972 else:
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5973 self.gotoMethodClass(True)
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5974 evt.accept()
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5975 return
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5976
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5977 super().wheelEvent(evt)
9225700cbff5 - added capability to zoom by Ctrl + Mouse Wheel to the editor
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1500
diff changeset
5978
1518
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5979 def event(self, evt):
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5980 """
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5981 Protected method handling events.
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5982
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5983 @param evt reference to the event (QEvent)
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5984 @return flag indicating, if the event was handled (boolean)
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5985 """
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5986 if evt.type() == QEvent.Gesture:
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5987 self.gestureEvent(evt)
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5988 return True
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5989
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5990 return super().event(evt)
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5991
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5992 def gestureEvent(self, evt):
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5993 """
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5994 Protected method handling gesture events.
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5995
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5996 @param evt reference to the gesture event (QGestureEvent
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5997 """
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5998 pinch = evt.gesture(Qt.PinchGesture)
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
5999 if pinch:
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6000 if pinch.state() == Qt.GestureStarted:
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6001 zoom = (self.getZoom() + 10) / 10.0
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6002 pinch.setScaleFactor(zoom)
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6003 else:
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6004 zoom = int(pinch.scaleFactor() * 10) - 10
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6005 if zoom <= -9:
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6006 zoom = -9
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6007 pinch.setScaleFactor(0.1)
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6008 elif zoom >= 20:
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6009 zoom = 20
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6010 pinch.setScaleFactor(3.0)
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6011 self.zoomTo(zoom)
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6012 evt.accept()
e6e21910210d Added capability to zoom by a pinch gesture to the editor, the shell, the terminal, the web browser and various graphics related windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
6013
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6014 def __updateReadOnly(self, bForce=True):
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6015 """
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6016 Private method to update the readOnly information for this editor.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6017
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6018 If bForce is True, then updates everything regardless if
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6019 the attributes have actually changed, such as during
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6020 initialization time. A signal is emitted after the
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6021 caption change.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6022
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6023 @param bForce True to force change, False to only update and emit
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6024 signal if there was an attribute change.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6025 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6026 if self.fileName is None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6027 return
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6028 readOnly = not QFileInfo(self.fileName).isWritable() or \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6029 self.isReadOnly()
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6030 if not bForce and (readOnly == self.isReadOnly()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6031 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6032 cap = self.fileName
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6033 if readOnly:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6034 cap = self.trUtf8("{0} (ro)".format(cap))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6035 self.setReadOnly(readOnly)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6036 self.setWindowTitle(cap)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
6037 self.captionChanged.emit(cap, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6038
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6039 def refresh(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6040 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6041 Public slot to refresh the editor contents.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6042 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6043 # save cursor position
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6044 cline, cindex = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6045
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6046 # save bookmarks and breakpoints and clear them
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6047 bmlist = self.getBookmarks()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6048 self.clearBookmarks()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6049
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6050 # clear syntax error markers
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6051 self.clearSyntaxError()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6052
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6053 # clear flakes warning markers
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6054 self.clearFlakesWarnings()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6055
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6056 # clear breakpoint markers
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6057 for handle in list(self.breaks.keys()):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6058 self.markerDeleteHandle(handle)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6059 self.breaks = {}
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6060
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6061 # reread the file
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6062 try:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6063 self.readFile(self.fileName)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6064 except IOError:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6065 # do not prompt for this change again...
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6066 self.lastModified = QDateTime.currentDateTime()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6067 self.setModified(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6068
2189
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
6069 # re-initialize the online change tracer
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
6070 self.__reinitOnlineChangeTrace()
5149cec53130 Fixed an issue in the editor related to not re-initializing the online change tracer after a file has been refreshed (reread after an external change).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2165
diff changeset
6071
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6072 # reset cursor position
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6073 self.setCursorPosition(cline, cindex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6074 self.ensureCursorVisible()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6075
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6076 # reset bookmarks and breakpoints to their old position
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6077 if bmlist:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6078 for bm in bmlist:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6079 self.toggleBookmark(bm)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6080 self.__restoreBreakpoints()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6081
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
6082 self.editorSaved.emit(self.fileName)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6083 self.__autoSyntaxCheck()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6084
1807
9898a95461f1 Added a signal to the editor showing a refresh has happend and connected the editor assembly to it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1768
diff changeset
6085 self.refreshed.emit()
9898a95461f1 Added a signal to the editor showing a refresh has happend and connected the editor assembly to it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1768
diff changeset
6086
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6087 def setMonospaced(self, on):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6088 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6089 Public method to set/reset a monospaced font.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6090
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6091 @param on flag to indicate usage of a monospace font (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6092 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6093 if on:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6094 f = Preferences.getEditorOtherFonts("MonospacedFont")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6095 self.monospacedStyles(f)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6096 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6097 if not self.lexer_:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6098 self.clearStyles()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6099 self.__setMarginsDisplay()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6100 self.setFont(Preferences.getEditorOtherFonts("DefaultFont"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6101
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6102 self.useMonospaced = on
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6103
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6104 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6105 ## Drag and Drop Support
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6106 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6107
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6108 def dragEnterEvent(self, event):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6109 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6110 Protected method to handle the drag enter event.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6111
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6112 @param event the drag enter event (QDragEnterEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6113 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6114 self.inDragDrop = event.mimeData().hasUrls()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6115 if self.inDragDrop:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6116 event.acceptProposedAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6117 else:
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
6118 super().dragEnterEvent(event)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6119
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6120 def dragMoveEvent(self, event):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6121 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6122 Protected method to handle the drag move event.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6123
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6124 @param event the drag move event (QDragMoveEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6125 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6126 if self.inDragDrop:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6127 event.accept()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6128 else:
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
6129 super().dragMoveEvent(event)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6130
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6131 def dragLeaveEvent(self, event):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6132 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6133 Protected method to handle the drag leave event.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6134
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6135 @param event the drag leave event (QDragLeaveEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6136 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6137 if self.inDragDrop:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6138 self.inDragDrop = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6139 event.accept()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6140 else:
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
6141 super().dragLeaveEvent(event)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6142
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6143 def dropEvent(self, event):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6144 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6145 Protected method to handle the drop event.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6146
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6147 @param event the drop event (QDropEvent)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6148 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6149 if event.mimeData().hasUrls():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6150 for url in event.mimeData().urls():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6151 fname = url.toLocalFile()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6152 if fname:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6153 if not QFileInfo(fname).isDir():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6154 self.vm.openSourceFile(fname)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6155 else:
536
6d8d39753c82 Started replaceing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 535
diff changeset
6156 E5MessageBox.information(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6157 self.trUtf8("Drop Error"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6158 self.trUtf8("""<p><b>{0}</b> is not a file.</p>""")
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6159 .format(fname))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6160 event.acceptProposedAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6161 else:
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
6162 super().dropEvent(event)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6163
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6164 self.inDragDrop = False
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6165
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6166 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6167 ## Support for Qt resources files
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6168 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6169
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6170 def __initContextMenuResources(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6171 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6172 Private method used to setup the Resources context sub menu.
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
6173
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
6174 @return reference to the generated menu (QMenu)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6175 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6176 menu = QMenu(self.trUtf8('Resources'))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6177
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6178 menu.addAction(self.trUtf8('Add file...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6179 self.__addFileResource)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6180 menu.addAction(self.trUtf8('Add files...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6181 self.__addFileResources)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6182 menu.addAction(self.trUtf8('Add aliased file...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6183 self.__addFileAliasResource)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6184 menu.addAction(self.trUtf8('Add localized resource...'),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6185 self.__addLocalizedResource)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6186 menu.addSeparator()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6187 menu.addAction(self.trUtf8('Add resource frame'),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6188 self.__addResourceFrame)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6189
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 460
diff changeset
6190 menu.aboutToShow.connect(self.__showContextMenuResources)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6191
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6192 return menu
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6193
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6194 def __showContextMenuResources(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6195 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6196 Private slot handling the aboutToShow signal of the resources context
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6197 menu.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6198 """
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
6199 self.showMenu.emit("Resources", self.resourcesMenu, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6200
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6201 def __addFileResource(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6202 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6203 Private method to handle the Add file context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6204 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6205 dirStr = os.path.dirname(self.fileName)
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
6206 file = E5FileDialog.getOpenFileName(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6207 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6208 self.trUtf8("Add file resource"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6209 dirStr,
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
6210 "")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6211 if file:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6212 relFile = QDir(dirStr).relativeFilePath(file)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6213 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6214 self.insert(" <file>{0}</file>\n".format(relFile))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6215 self.setCursorPosition(line + 1, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6216
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6217 def __addFileResources(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6218 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6219 Private method to handle the Add files context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6220 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6221 dirStr = os.path.dirname(self.fileName)
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
6222 files = E5FileDialog.getOpenFileNames(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6223 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6224 self.trUtf8("Add file resources"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6225 dirStr,
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
6226 "")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6227 if files:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6228 myDir = QDir(dirStr)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6229 filesText = ""
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6230 for file in files:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6231 relFile = myDir.relativeFilePath(file)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6232 filesText += " <file>{0}</file>\n".format(relFile)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6233 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6234 self.insert(filesText)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6235 self.setCursorPosition(line + len(files), index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6236
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6237 def __addFileAliasResource(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6238 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6239 Private method to handle the Add aliased file context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6240 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6241 dirStr = os.path.dirname(self.fileName)
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
6242 file = E5FileDialog.getOpenFileName(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6243 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6244 self.trUtf8("Add aliased file resource"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6245 dirStr,
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
6246 "")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6247 if file:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6248 relFile = QDir(dirStr).relativeFilePath(file)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 559
diff changeset
6249 alias, ok = QInputDialog.getText(
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6250 self,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6251 self.trUtf8("Add aliased file resource"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6252 self.trUtf8("Alias for file <b>{0}</b>:").format(relFile),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6253 QLineEdit.Normal,
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6254 relFile)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6255 if ok and alias:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6256 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6257 self.insert(' <file alias="{1}">{0}</file>\n'\
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6258 .format(relFile, alias))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6259 self.setCursorPosition(line + 1, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6260
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6261 def __addLocalizedResource(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6262 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6263 Private method to handle the Add localized resource context menu
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6264 action.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6265 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6266 from Project.AddLanguageDialog import AddLanguageDialog
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6267 dlg = AddLanguageDialog(self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6268 if dlg.exec_() == QDialog.Accepted:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6269 lang = dlg.getSelectedLanguage()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6270 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6271 self.insert('<qresource lang="{0}">\n</qresource>\n'.format(lang))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6272 self.setCursorPosition(line + 2, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6273
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6274 def __addResourceFrame(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6275 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6276 Private method to handle the Add resource frame context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6277 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6278 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6279 self.insert('<!DOCTYPE RCC>\n'
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6280 '<RCC version="1.0">\n'
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6281 '<qresource>\n'
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6282 '</qresource>\n'
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6283 '</RCC>\n')
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6284 self.setCursorPosition(line + 5, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6285
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6286 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6287 ## Support for diagrams below
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6288 #################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6289
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6290 def __showClassDiagram(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6291 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6292 Private method to handle the Class Diagram context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6293 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
6294 from Graphics.UMLDialog import UMLDialog
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6295 if not self.checkDirty():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6296 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6297
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6298 self.classDiagram = UMLDialog(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6299 UMLDialog.ClassDiagram, self.project, self.fileName,
2025
8bb085c59cd2 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1978
diff changeset
6300 self, noAttrs=False)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6301 self.classDiagram.show()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6302
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6303 def __showPackageDiagram(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6304 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6305 Private method to handle the Package Diagram context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6306 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
6307 from Graphics.UMLDialog import UMLDialog
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6308 if not self.checkDirty():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6309 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6310
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6311 package = os.path.isdir(self.fileName) and \
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6312 self.fileName or os.path.dirname(self.fileName)
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
6313 res = E5MessageBox.yesNo(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6314 self.trUtf8("Package Diagram"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6315 self.trUtf8("""Include class attributes?"""),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6316 yesDefault=True)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6317 self.packageDiagram = UMLDialog(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6318 UMLDialog.PackageDiagram, self.project, package,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6319 self, noAttrs=not res)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6320 self.packageDiagram.show()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6321
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6322 def __showImportsDiagram(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6323 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6324 Private method to handle the Imports Diagram context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6325 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
6326 from Graphics.UMLDialog import UMLDialog
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6327 if not self.checkDirty():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6328 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6329
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6330 package = os.path.isdir(self.fileName) and self.fileName \
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6331 or os.path.dirname(self.fileName)
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
6332 res = E5MessageBox.yesNo(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6333 self.trUtf8("Imports Diagram"),
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
6334 self.trUtf8("""Include imports from external modules?"""))
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6335 self.importsDiagram = UMLDialog(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6336 UMLDialog.ImportsDiagram, self.project, package,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6337 self, showExternalImports=res)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6338 self.importsDiagram.show()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6339
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6340 def __showApplicationDiagram(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6341 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6342 Private method to handle the Imports Diagram context menu action.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6343 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
6344 from Graphics.UMLDialog import UMLDialog
541
00e1a5d060c5 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
6345 res = E5MessageBox.yesNo(self,
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6346 self.trUtf8("Application Diagram"),
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6347 self.trUtf8("""Include module names?"""),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6348 yesDefault=True)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6349 self.applicationDiagram = UMLDialog(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6350 UMLDialog.ApplicationDiagram, self.project,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6351 self, noModules=not res)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6352 self.applicationDiagram.show()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6353
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6354 def __loadDiagram(self):
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6355 """
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6356 Private slot to load a diagram from file.
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6357 """
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6358 from Graphics.UMLDialog import UMLDialog
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6359 self.loadedDiagram = UMLDialog(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6360 UMLDialog.NoDiagram, self.project, parent=self)
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6361 if self.loadedDiagram.load():
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6362 self.loadedDiagram.show(fromFile=True)
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6363 else:
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6364 self.loadedDiagram = None
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
6365
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6366 #######################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6367 ## Typing aids related methods below
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6368 #######################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6369
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6370 def __toggleTypingAids(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6371 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6372 Private slot to toggle the typing aids.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6373 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6374 if self.menuActs["TypingAidsEnabled"].isChecked():
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6375 self.completer.setEnabled(True)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6376 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6377 self.completer.setEnabled(False)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6378
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6379 #######################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6380 ## Autocompleting templates
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6381 #######################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6382
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6383 def editorCommand(self, cmd):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6384 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6385 Public method to perform a simple editor command.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6386
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6387 @param cmd the scintilla command to be performed
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6388 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6389 if cmd == QsciScintilla.SCI_TAB:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6390 line, index = self.getCursorPosition()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6391 tmplName = self.getWordLeft(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6392 if tmplName:
1002
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6393 if e5App().getObject("TemplateViewer").hasTemplate(
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6394 tmplName, self.getLanguage()):
1723
6e690a8f5971 Fixed an issue in the editor applying templates.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1588
diff changeset
6395 self.__applyTemplate(tmplName, self.getLanguage())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6396 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6397 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6398 templateNames = \
1002
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6399 e5App().getObject("TemplateViewer").getTemplateNames(
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6400 tmplName, self.getLanguage())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6401 if len(templateNames) == 1:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6402 self.__applyTemplate(templateNames[0],
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6403 self.getLanguage())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6404 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6405 elif len(templateNames) > 1:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6406 self.showUserList(TemplateCompletionListID,
429
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
6407 ["{0}?{1:d}".format(t, self.TemplateImageID) \
dcc623c99907 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 404
diff changeset
6408 for t in templateNames])
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6409 return
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6410
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
6411 super().editorCommand(cmd)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6412
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6413 def __completionListSelected(self, id, txt):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6414 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6415 Private slot to handle the selection from the completion list.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6416
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6417 @param id the ID of the user list (should be 1) (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6418 @param txt the selected text (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6419 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6420 if id == TemplateCompletionListID:
1002
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6421 self.__applyTemplate(txt, self.getLanguage())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6422
1002
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6423 def __applyTemplate(self, templateName, language):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6424 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6425 Private method to apply a template by name.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6426
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6427 @param templateName name of the template to apply (string)
1002
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6428 @param language name of the language (group) to get the template
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6429 from (string)
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6430 """
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6431 if e5App().getObject("TemplateViewer").hasTemplate(
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6432 templateName, self.getLanguage()):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6433 self.extendSelectionWordLeft()
1002
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6434 e5App().getObject("TemplateViewer").applyNamedTemplate(
1151d1ea562a Enhanced the autocompletion of templates to observe the language of the current file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 994
diff changeset
6435 templateName, self.getLanguage())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6436
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6437 #######################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6438 ## Project related methods
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6439 #######################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6440
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6441 def __projectPropertiesChanged(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6442 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6443 Private slot to handle changes of the project properties.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6444 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6445 if self.spell:
252
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
6446 pwl, pel = self.project.getProjectDictionaries()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6447 self.__setSpellingLanguage(self.project.getProjectSpellLanguage(),
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6448 pwl=pwl, pel=pel)
253
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
6449
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
6450 self.setEolModeByEolString(self.project.getEolString())
3ccdf551bde7 Changed code to improve development on multiple platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 252
diff changeset
6451 self.convertEols(self.eolMode())
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6452
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6453 def addedToProject(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6454 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6455 Public method to signal, that this editor has been added to a project.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6456 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6457 if self.spell:
252
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
6458 pwl, pel = self.project.getProjectDictionaries()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6459 self.__setSpellingLanguage(self.project.getProjectSpellLanguage(),
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6460 pwl=pwl, pel=pel)
1754
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6461
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6462 self.project.projectPropertiesChanged.connect(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6463 self.__projectPropertiesChanged)
1754
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6464
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6465 def projectOpened(self):
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6466 """
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6467 Public slot to handle the opening of a project.
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6468 """
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6469 if self.fileName and \
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6470 self.project.isProjectSource(self.fileName):
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6471 self.project.projectPropertiesChanged.connect(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6472 self.__projectPropertiesChanged)
1754
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6473 self.setSpellingForProject()
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6474
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6475 def projectClosed(self):
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6476 """
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6477 Public slot to handle the closing of a project.
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6478 """
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6479 try:
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6480 self.project.projectPropertiesChanged.disconnect(
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6481 self.__projectPropertiesChanged)
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6482 except TypeError:
4e2f87d03546 Fixed an issue in the editor caused by double connecting to a signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1723
diff changeset
6483 pass
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6484
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6485 #######################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6486 ## Spellchecking related methods
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6487 #######################################################################
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6488
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6489 def __setSpellingLanguage(self, language, pwl="", pel=""):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6490 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6491 Private slot to set the spell checking language.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6492
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6493 @param language spell checking language to be set (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6494 @keyparam pwl name of the personal/project word list (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6495 @keyparam pel name of the personal/project exclude list (string)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6496 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6497 if self.spell and self.spell.getLanguage() != language:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6498 self.spell.setLanguage(language, pwl=pwl, pel=pel)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6499 self.spell.checkDocumentIncrementally()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6500
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6501 def __setSpelling(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6502 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6503 Private method to initialize the spell checking functionality.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6504 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6505 if Preferences.getEditor("SpellCheckingEnabled"):
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6506 self.__spellCheckStringsOnly = Preferences.getEditor(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6507 "SpellCheckStringsOnly")
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6508 if self.spell is None:
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
6509 from .SpellChecker import SpellChecker
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6510 self.spell = SpellChecker(self, self.spellingIndicator,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6511 checkRegion=self.isSpellCheckRegion)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6512 self.setSpellingForProject()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6513 self.spell.setMinimumWordSize(
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6514 Preferences.getEditor("SpellCheckingMinWordSize"))
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6515
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6516 self.setAutoSpellChecking()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6517 else:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6518 self.spell = None
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6519 self.clearAllIndicators(self.spellingIndicator)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6520
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6521 def setSpellingForProject(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6522 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6523 Public method to set the spell checking options for files belonging
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6524 to the current project.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6525 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6526 if self.fileName and \
252
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
6527 self.project.isOpen() and \
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
6528 self.project.isProjectSource(self.fileName):
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
6529 pwl, pel = self.project.getProjectDictionaries()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6530 self.__setSpellingLanguage(self.project.getProjectSpellLanguage(),
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6531 pwl=pwl, pel=pel)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6532
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6533 def setAutoSpellChecking(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6534 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6535 Public method to set the automatic spell checking.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6536 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6537 if Preferences.getEditor("AutoSpellCheckingEnabled"):
1768
8a04ce23e083 Fixed another issue with a multi-connected signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1762
diff changeset
6538 try:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6539 self.SCN_CHARADDED.connect(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6540 self.__spellCharAdded, Qt.UniqueConnection)
1768
8a04ce23e083 Fixed another issue with a multi-connected signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1762
diff changeset
6541 except TypeError:
8a04ce23e083 Fixed another issue with a multi-connected signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1762
diff changeset
6542 pass
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6543 self.spell.checkDocumentIncrementally()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6544 else:
542
26a79c19993c Fixed a signal/slot issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 541
diff changeset
6545 try:
26a79c19993c Fixed a signal/slot issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 541
diff changeset
6546 self.SCN_CHARADDED.disconnect(self.__spellCharAdded)
26a79c19993c Fixed a signal/slot issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 541
diff changeset
6547 except TypeError:
26a79c19993c Fixed a signal/slot issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 541
diff changeset
6548 pass
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6549 self.clearAllIndicators(self.spellingIndicator)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6550
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6551 def isSpellCheckRegion(self, pos):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6552 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6553 Public method to check, if the given position is within a region, that
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6554 should be spell checked.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6555
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6556 @param pos position to be checked (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6557 @return flag indicating pos is in a spell check region (boolean)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6558 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6559 if self.__spellCheckStringsOnly:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6560 style = self.styleAt(pos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6561 if self.lexer_ is not None:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6562 return self.lexer_.isCommentStyle(style) or \
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6563 self.lexer_.isStringStyle(style)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6564 return True
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6565
1768
8a04ce23e083 Fixed another issue with a multi-connected signal.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1762
diff changeset
6566 @pyqtSlot(int)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6567 def __spellCharAdded(self, charNumber):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6568 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6569 Public slot called to handle the user entering a character.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6570
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6571 @param charNumber value of the character entered (integer)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6572 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6573 if self.spell:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6574 if not chr(charNumber).isalnum():
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6575 self.spell.checkWord(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6576 self.positionBefore(self.currentPosition()), True)
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6577 elif self.hasIndicator(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6578 self.spellingIndicator, self.currentPosition()):
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6579 self.spell.checkWord(self.currentPosition())
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6580
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6581 def checkSpelling(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6582 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6583 Public slot to perform an interactive spell check of the document.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6584 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6585 if self.spell:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6586 cline, cindex = self.getCursorPosition()
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
6587 from .SpellCheckingDialog import SpellCheckingDialog
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6588 dlg = SpellCheckingDialog(self.spell, 0, self.length(), self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6589 dlg.exec_()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6590 self.setCursorPosition(cline, cindex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6591 if Preferences.getEditor("AutoSpellCheckingEnabled"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6592 self.spell.checkDocumentIncrementally()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6593
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6594 def __checkSpellingSelection(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6595 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6596 Private slot to spell check the current selection.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6597 """
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
6598 from .SpellCheckingDialog import SpellCheckingDialog
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6599 sline, sindex, eline, eindex = self.getSelection()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6600 startPos = self.positionFromLineIndex(sline, sindex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6601 endPos = self.positionFromLineIndex(eline, eindex)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6602 dlg = SpellCheckingDialog(self.spell, startPos, endPos, self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6603 dlg.exec_()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6604
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6605 def __checkSpellingWord(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6606 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6607 Private slot to check the word below the spelling context menu.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6608 """
2409
df3820f08247 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2391
diff changeset
6609 from .SpellCheckingDialog import SpellCheckingDialog
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6610 line, index = self.lineIndexFromPosition(self.spellingMenuPos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6611 wordStart, wordEnd = self.getWordBoundaries(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6612 wordStartPos = self.positionFromLineIndex(line, wordStart)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6613 wordEndPos = self.positionFromLineIndex(line, wordEnd)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6614 dlg = SpellCheckingDialog(self.spell, wordStartPos, wordEndPos, self)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6615 dlg.exec_()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6616
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6617 def __showContextMenuSpelling(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6618 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6619 Private slot to set up the spelling menu before it is shown.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6620 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6621 self.spellingMenu.clear()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6622 self.spellingSuggActs = []
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6623 line, index = self.lineIndexFromPosition(self.spellingMenuPos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6624 word = self.getWord(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6625 suggestions = self.spell.getSuggestions(word)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6626 for suggestion in suggestions[:5]:
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6627 self.spellingSuggActs.append(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6628 self.spellingMenu.addAction(suggestion))
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6629 if suggestions:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6630 self.spellingMenu.addSeparator()
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6631 self.spellingMenu.addAction(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6632 UI.PixmapCache.getIcon("spellchecking.png"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6633 self.trUtf8("Check spelling..."), self.__checkSpellingWord)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6634 self.spellingMenu.addAction(self.trUtf8("Add to dictionary"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6635 self.__addToSpellingDictionary)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6636 self.spellingMenu.addAction(self.trUtf8("Ignore All"),
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6637 self.__ignoreSpellingAlways)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6638
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 486
diff changeset
6639 self.showMenu.emit("Spelling", self.spellingMenu, self)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6640
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6641 def __contextMenuSpellingTriggered(self, action):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6642 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6643 Private slot to handle the selection of a suggestion of the spelling
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6644 context menu.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6645
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6646 @param action reference to the action that was selected (QAction)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6647 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6648 if action in self.spellingSuggActs:
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6649 replacement = action.text()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6650 line, index = self.lineIndexFromPosition(self.spellingMenuPos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6651 wordStart, wordEnd = self.getWordBoundaries(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6652 self.setSelection(line, wordStart, line, wordEnd)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6653 self.beginUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6654 self.removeSelectedText()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6655 self.insert(replacement)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6656 self.endUndoAction()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6657
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6658 def __addToSpellingDictionary(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6659 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6660 Private slot to add the word below the spelling context menu to the
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6661 dictionary.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6662 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6663 line, index = self.lineIndexFromPosition(self.spellingMenuPos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6664 word = self.getWord(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6665 self.spell.add(word)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6666
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6667 wordStart, wordEnd = self.getWordBoundaries(line, index)
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6668 self.clearIndicator(self.spellingIndicator, line, wordStart,
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6669 line, wordEnd)
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6670 if Preferences.getEditor("AutoSpellCheckingEnabled"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6671 self.spell.checkDocumentIncrementally()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6672
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6673 def __removeFromSpellingDictionary(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6674 """
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6675 Private slot to remove the word below the context menu to the
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6676 dictionary.
92
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6677 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6678 line, index = self.lineIndexFromPosition(self.spellingMenuPos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6679 word = self.getWord(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6680 self.spell.remove(word)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6681
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6682 if Preferences.getEditor("AutoSpellCheckingEnabled"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6683 self.spell.checkDocumentIncrementally()
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6684
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6685 def __ignoreSpellingAlways(self):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6686 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6687 Private to always ignore the word below the spelling context menu.
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6688 """
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6689 line, index = self.lineIndexFromPosition(self.spellingMenuPos)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6690 word = self.getWord(line, index)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6691 self.spell.ignoreAlways(word)
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6692 if Preferences.getEditor("AutoSpellCheckingEnabled"):
30ffedc3e418 Refined the flakes integration code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 88
diff changeset
6693 self.spell.checkDocumentIncrementally()
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6694
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6695 #######################################################################
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6696 ## Cooperation related methods
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6697 #######################################################################
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6698
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6699 def getSharingStatus(self):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6700 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6701 Public method to get some share status info.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6702
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6703 @return tuple indicating, if the editor is sharable, the sharing
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6704 status, if it is inside a locally initiated shared edit session
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
6705 and if it is inside a remotely initiated shared edit session
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6706 (boolean, boolean, boolean, boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6707 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
6708 return self.fileName is not None and \
252
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
6709 self.project.isOpen() and \
05692e3d37bf Some code cleanup in Editor.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 245
diff changeset
6710 self.project.isProjectFile(self.fileName), \
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6711 self.__isShared, self.__inSharedEdit, self.__inRemoteSharedEdit
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6712
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6713 def shareConnected(self, connected):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6714 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6715 Public slot to handle a change of the connected state.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6716
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6717 @param connected flag indicating the connected state (boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6718 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6719 if not connected:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6720 self.__inRemoteSharedEdit = False
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6721 self.setReadOnly(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6722 self.__updateReadOnly()
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6723 self.cancelSharedEdit(send=False)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6724 self.__isSyncing = False
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6725 self.__receivedWhileSyncing = []
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6726
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6727 def shareEditor(self, share):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6728 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6729 Public slot to set the shared status of the editor.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6730
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6731 @param share flag indicating the share status (boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6732 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6733 self.__isShared = share
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6734 if not share:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6735 self.shareConnected(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6736
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6737 def startSharedEdit(self):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6738 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6739 Public slot to start a shared edit session for the editor.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6740 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6741 self.__inSharedEdit = True
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6742 self.__savedText = self.text()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6743 hash = str(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6744 QCryptographicHash.hash(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6745 Utilities.encode(self.__savedText, self.encoding)[0],
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6746 QCryptographicHash.Sha1).toHex(),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6747 encoding="utf-8")
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6748 self.__send(Editor.StartEditToken, hash)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6749
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6750 def sendSharedEdit(self):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6751 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6752 Public slot to end a shared edit session for the editor and
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6753 send the changes.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6754 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6755 commands = self.__calculateChanges(self.__savedText, self.text())
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6756 self.__send(Editor.EndEditToken, commands)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6757 self.__inSharedEdit = False
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6758 self.__savedText = ""
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6759
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6760 def cancelSharedEdit(self, send=True):
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6761 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6762 Public slot to cancel a shared edit session for the editor.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6763
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6764 @keyparam send flag indicating to send the CancelEdit command (boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6765 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6766 self.__inSharedEdit = False
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6767 self.__savedText = ""
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6768 if send:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6769 self.__send(Editor.CancelEditToken)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6770
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6771 def __send(self, token, args=None):
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6772 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6773 Private method to send an editor command to remote editors.
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6774
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6775 @param token command token (string)
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6776 @param args arguments for the command (string)
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6777 """
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6778 if self.vm.isConnected():
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6779 msg = ""
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6780 if token in (Editor.StartEditToken,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6781 Editor.EndEditToken,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6782 Editor.RequestSyncToken,
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6783 Editor.SyncToken):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6784 msg = "{0}{1}{2}".format(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6785 token,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6786 Editor.Separator,
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6787 args
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6788 )
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6789 elif token == Editor.CancelEditToken:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6790 msg = "{0}{1}c".format(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6791 token,
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6792 Editor.Separator
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6793 )
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6794
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6795 self.vm.send(self.fileName, msg)
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6796
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6797 def receive(self, command):
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6798 """
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6799 Public slot to handle received editor commands.
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6800
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6801 @param command command string (string)
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6802 """
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6803 if self.__isShared:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6804 if self.__isSyncing and \
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6805 not command.startswith(Editor.SyncToken + Editor.Separator):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6806 self.__receivedWhileSyncing.append(command)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6807 else:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6808 self.__dispatchCommand(command)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6809
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6810 def __dispatchCommand(self, command):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6811 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6812 Private method to dispatch received commands.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6813
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6814 @param command command to be processed (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6815 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6816 token, argsString = command.split(Editor.Separator, 1)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6817 if token == Editor.StartEditToken:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6818 self.__processStartEditCommand(argsString)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6819 elif token == Editor.CancelEditToken:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6820 self.shareConnected(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6821 elif token == Editor.EndEditToken:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6822 self.__processEndEditCommand(argsString)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6823 elif token == Editor.RequestSyncToken:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6824 self.__processRequestSyncCommand(argsString)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6825 elif token == Editor.SyncToken:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6826 self.__processSyncCommand(argsString)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6827
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6828 def __processStartEditCommand(self, argsString):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6829 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
6830 Private slot to process a remote StartEdit command.
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6831
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6832 @param argsString string containing the command parameters (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6833 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6834 if not self.__inSharedEdit and not self.__inRemoteSharedEdit:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6835 self.__inRemoteSharedEdit = True
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6836 self.setReadOnly(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6837 self.__updateReadOnly()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6838 hash = str(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6839 QCryptographicHash.hash(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6840 Utilities.encode(self.text(), self.encoding)[0],
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6841 QCryptographicHash.Sha1).toHex(),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6842 encoding="utf-8")
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6843 if hash != argsString:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6844 # text is different to the remote site, request to sync it
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6845 self.__isSyncing = True
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6846 self.__send(Editor.RequestSyncToken, argsString)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6847
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6848 def __calculateChanges(self, old, new):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6849 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6850 Private method to determine change commands to convert old text into
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6851 new text.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6852
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6853 @param old old text (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6854 @param new new text (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6855 @return commands to change old into new (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6856 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6857 oldL = old.splitlines()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6858 newL = new.splitlines()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6859 matcher = difflib.SequenceMatcher(None, oldL, newL)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6860
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6861 formatStr = "@@{0} {1} {2} {3}"
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6862 commands = []
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6863 for token, i1, i2, j1, j2 in matcher.get_opcodes():
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6864 if token == "insert":
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6865 commands.append(formatStr.format("i", j1, j2 - j1, -1))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6866 commands.extend(newL[j1:j2])
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6867 elif token == "delete":
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6868 commands.append(formatStr.format("d", j1, i2 - i1, -1))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6869 elif token == "replace":
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6870 commands.append(formatStr.format("r", j1, i2 - i1, j2 - j1))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6871 commands.extend(newL[j1:j2])
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6872
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6873 return "\n".join(commands) + "\n"
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6874
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6875 def __processEndEditCommand(self, argsString):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6876 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
6877 Private slot to process a remote EndEdit command.
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6878
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6879 @param argsString string containing the command parameters (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6880 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6881 commands = argsString.splitlines()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6882 sep = self.getLineSeparator()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6883 cur = self.getCursorPosition()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6884
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6885 self.setReadOnly(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6886 self.beginUndoAction()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6887 while commands:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6888 commandLine = commands.pop(0)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6889 if not commandLine.startswith("@@"):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6890 continue
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6891
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6892 command, *args = commandLine.split()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6893 pos, l1, l2 = [int(arg) for arg in args]
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6894 if command == "@@i":
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6895 txt = sep.join(commands[0:l1]) + sep
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6896 self.insertAt(txt, pos, 0)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6897 del commands[0:l1]
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6898 elif command == "@@d":
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6899 self.setSelection(pos, 0, pos + l1, 0)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6900 self.removeSelectedText()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6901 elif command == "@@r":
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6902 self.setSelection(pos, 0, pos + l1, 0)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6903 self.removeSelectedText()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6904 txt = sep.join(commands[0:l2]) + sep
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6905 self.insertAt(txt, pos, 0)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6906 del commands[0:l2]
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6907 self.endUndoAction()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6908 self.__updateReadOnly()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6909 self.__inRemoteSharedEdit = False
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6910
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6911 self.setCursorPosition(*cur)
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 128
diff changeset
6912
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6913 def __processRequestSyncCommand(self, argsString):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6914 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
6915 Private slot to process a remote RequestSync command.
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6916
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6917 @param argsString string containing the command parameters (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6918 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6919 if self.__inSharedEdit:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6920 hash = str(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6921 QCryptographicHash.hash(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6922 Utilities.encode(self.__savedText, self.encoding)[0],
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6923 QCryptographicHash.Sha1).toHex(),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6924 encoding="utf-8")
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6925
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6926 if hash == argsString:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6927 self.__send(Editor.SyncToken, self.__savedText)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6928
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6929 def __processSyncCommand(self, argsString):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6930 """
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2959
diff changeset
6931 Private slot to process a remote Sync command.
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6932
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6933 @param argsString string containing the command parameters (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6934 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6935 if self.__isSyncing:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6936 cur = self.getCursorPosition()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6937
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6938 self.setReadOnly(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6939 self.beginUndoAction()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6940 self.selectAll()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6941 self.removeSelectedText()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6942 self.insertAt(argsString, 0, 0)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6943 self.endUndoAction()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6944 self.setReadOnly(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6945
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6946 self.setCursorPosition(*cur)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6947
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6948 while self.__receivedWhileSyncing:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 939
diff changeset
6949 command = self.__receivedWhileSyncing.pop(0)
826
2e3e2055e715 Fixed a few PEP 8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 825
diff changeset
6950 self.__dispatchCommand(command)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 156
diff changeset
6951
718
979d6e242404 Fixed an issue in the editor saving files without extension on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 564
diff changeset
6952 self.__isSyncing = False
2213
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6953
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6954 #######################################################################
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6955 ## Special search related methods
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6956 #######################################################################
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6957
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6958 def searchCurrentWordForward(self):
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6959 """
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6960 Public slot to search the current word forward.
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6961 """
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6962 self.__searchCurrentWord(forward=True)
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6963
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6964 def searchCurrentWordBackward(self):
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6965 """
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6966 Public slot to search the current word backward.
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6967 """
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6968 self.__searchCurrentWord(forward=False)
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6969
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6970 def __searchCurrentWord(self, forward=True):
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6971 """
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6972 Public slot to search the next occurrence of the current word.
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6973
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6974 @param forward flag indicating the search direction (boolean)
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6975 """
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6976 line, index = self.getCursorPosition()
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6977 word = self.getCurrentWord()
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6978 wordStart, wordEnd = self.getCurrentWordBoundaries()
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6979 wordStartPos = self.positionFromLineIndex(line, wordStart)
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6980 wordEndPos = self.positionFromLineIndex(line, wordEnd)
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6981
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6982 regExp = re.compile(r"\b{0}\b".format(word))
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6983 if forward:
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6984 startPos = wordEndPos
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6985 else:
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6986 startPos = wordStartPos
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6987
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6988 matches = [m for m in regExp.finditer(self.text())]
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6989 if matches:
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6990 if forward:
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6991 matchesAfter = [m for m in matches if m.start() >= startPos]
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6992 if matchesAfter:
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6993 match = matchesAfter[0]
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6994 else:
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6995 # wrap around
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6996 match = matches[0]
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6997 else:
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6998 matchesBefore = [m for m in matches if m.start() < startPos]
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
6999 if matchesBefore:
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
7000 match = matchesBefore[-1]
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
7001 else:
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
7002 # wrap around
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
7003 match = matches[-1]
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
7004 line, index = self.lineIndexFromPosition(match.start())
022f4ad3ed19 Added actions to search for the next/previous occurence of the current word (default shortcuts Ctrl+. and Ctrl+,).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2189
diff changeset
7005 self.setSelection(line, index + len(match.group(0)), line, index)
2589
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7006
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7007 #######################################################################
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7008 ## Sort related methods
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7009 #######################################################################
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7010
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7011 def sortLines(self):
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7012 """
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7013 Public slot to sort the lines spanned by a rectangular selection.
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7014 """
2590
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7015 if not self.selectionIsRectangle():
2589
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7016 return
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7017
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7018 from .SortOptionsDialog import SortOptionsDialog
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7019 dlg = SortOptionsDialog()
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7020 if dlg.exec_() == QDialog.Accepted:
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7021 ascending, alnum, caseSensitive = dlg.getData()
2590
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7022 origStartLine, origStartIndex, origEndLine, origEndIndex = \
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7023 self.getRectangularSelection()
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7024 # convert to upper-left to lower-right
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7025 startLine = min(origStartLine, origEndLine)
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7026 startIndex = min(origStartIndex, origEndIndex)
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7027 endLine = max(origStartLine, origEndLine)
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7028 endIndex = max(origStartIndex, origEndIndex)
2589
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7029
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
7030 # step 1: extract the text of the rectangular selection and
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
7031 # the lines
2589
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7032 selText = {}
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7033 txtLines = {}
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7034 for line in range(startLine, endLine + 1):
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7035 txtLines[line] = self.text(line)
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7036 txt = txtLines[line][startIndex:endIndex].strip()
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7037 if not alnum:
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7038 try:
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7039 txt = float(txt)
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7040 except ValueError:
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7041 E5MessageBox.critical(self,
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7042 self.trUtf8("Sort Lines"),
3011
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
7043 self.trUtf8(
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
7044 """The selection contains illegal data for a"""
18292228c724 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2994
diff changeset
7045 """ numerical sort."""))
2589
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7046 return
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7047
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7048 if txt in selText:
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7049 selText[txt].append(line)
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7050 else:
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7051 selText[txt] = [line]
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7052
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7053 # step 2: calculate the sort parameters
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7054 reverse = not ascending
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7055 if alnum and not caseSensitive:
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7056 keyFun = str.lower
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7057 else:
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7058 keyFun = None
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7059
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7060 # step 3: sort the lines
2590
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7061 eol = self.getLineSeparator()
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7062 lastWithEol = True
2589
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7063 newLines = []
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7064 for txt in sorted(selText.keys(), key=keyFun, reverse=reverse):
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7065 for line in selText[txt]:
2590
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7066 txt = txtLines[line]
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7067 if not txt.endswith(eol):
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7068 lastWithEol = False
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7069 txt += eol
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7070 newLines.append(txt)
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7071 if not lastWithEol:
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7072 newLines[-1] = newLines[-1][:-len(eol)]
2589
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7073
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7074 # step 4: replace the lines by the sorted ones
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7075 self.setSelection(startLine, 0, endLine + 1, 0)
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7076 self.beginUndoAction()
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7077 self.replaceSelectedText("".join(newLines))
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7078 self.endUndoAction()
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7079
a51b0c113ed7 Added the capability to sort lines spanned by a rectangular selection based on the selected text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2517
diff changeset
7080 # step 5: reset the rectangular selection
2590
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7081 self.setRectangularSelection(origStartLine, origStartIndex,
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7082 origEndLine, origEndIndex)
abe9b3e04381 Finished the sort implementation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2589
diff changeset
7083 self.selectionChanged.emit()

eric ide

mercurial