|
19 | 19 | from contextlib import contextmanager |
20 | 20 | from functools import partial |
21 | 21 |
|
| 22 | +import Qt as Qt_py |
22 | 23 | import six |
23 | | -from Qt import QtCompat |
24 | 24 | from Qt.QtCore import Property, QEvent, QPoint, Qt, Signal |
25 | | -from Qt.QtGui import QColor, QFont, QFontMetrics, QIcon |
| 25 | +from Qt.QtGui import QColor, QFont, QFontMetrics, QIcon, QKeySequence |
26 | 26 | from Qt.QtWidgets import ( |
27 | 27 | QAction, |
28 | 28 | QApplication, |
@@ -173,37 +173,53 @@ def __init__(self, parent, filename='', lineno=0, delayable_engine='default'): |
173 | 173 | commands = self.standardCommands() |
174 | 174 | # Remove the Ctrl+/ "Move left one word part" shortcut so it can be used to |
175 | 175 | # comment |
| 176 | + if Qt_py.IsPyQt6: |
| 177 | + # In Qt6 enums are not longer simple ints. boundTo still requires ints |
| 178 | + def to_int(shortcut): |
| 179 | + return shortcut.toCombined() |
| 180 | + |
| 181 | + else: |
| 182 | + |
| 183 | + def to_int(shortcut): |
| 184 | + return shortcut |
| 185 | + |
176 | 186 | command = commands.boundTo( |
177 | | - Qt.KeyboardModifier.ControlModifier | Qt.Key.Key_Slash |
| 187 | + to_int(Qt.KeyboardModifier.ControlModifier | Qt.Key.Key_Slash) |
178 | 188 | ) |
179 | 189 | if command is not None: |
180 | 190 | command.setKey(0) |
181 | 191 |
|
182 | 192 | for command in commands.commands(): |
183 | 193 | if command.description() == 'Move selected lines up one line': |
184 | 194 | command.setKey( |
185 | | - Qt.KeyboardModifier.ControlModifier |
186 | | - | Qt.KeyboardModifier.ShiftModifier |
187 | | - | Qt.Key.Key_Up |
| 195 | + to_int( |
| 196 | + Qt.KeyboardModifier.ControlModifier |
| 197 | + | Qt.KeyboardModifier.ShiftModifier |
| 198 | + | Qt.Key.Key_Up |
| 199 | + ) |
188 | 200 | ) |
189 | 201 | if command.description() == 'Move selected lines down one line': |
190 | 202 | command.setKey( |
191 | | - Qt.KeyboardModifier.ControlModifier |
192 | | - | Qt.KeyboardModifier.ShiftModifier |
193 | | - | Qt.Key.Key_Down |
| 203 | + to_int( |
| 204 | + Qt.KeyboardModifier.ControlModifier |
| 205 | + | Qt.KeyboardModifier.ShiftModifier |
| 206 | + | Qt.Key.Key_Down |
| 207 | + ) |
194 | 208 | ) |
195 | 209 | if command.description() == 'Duplicate selection': |
196 | 210 | command.setKey( |
197 | | - Qt.KeyboardModifier.ControlModifier |
198 | | - | Qt.KeyboardModifier.ShiftModifier |
199 | | - | Qt.Key.Key_D |
| 211 | + to_int( |
| 212 | + Qt.KeyboardModifier.ControlModifier |
| 213 | + | Qt.KeyboardModifier.ShiftModifier |
| 214 | + | Qt.Key.Key_D |
| 215 | + ) |
200 | 216 | ) |
201 | 217 | if command.description() == 'Cut current line': |
202 | 218 | command.setKey(0) |
203 | 219 |
|
204 | 220 | # Add QShortcuts |
205 | 221 | self.uiShowAutoCompleteSCT = QShortcut( |
206 | | - Qt.Modifier.CTRL | Qt.Key.Key_Space, |
| 222 | + QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_Space), |
207 | 223 | self, |
208 | 224 | context=Qt.ShortcutContext.WidgetShortcut, |
209 | 225 | ) |
@@ -885,13 +901,18 @@ def initSettings(self, first_time=False): |
885 | 901 |
|
886 | 902 | self.setEdgeMode(QsciScintilla.EdgeMode.EdgeNone) |
887 | 903 |
|
888 | | - # set autocompletion settings |
| 904 | + # set auto-completion settings |
889 | 905 | self.setAutoCompletionSource(QsciScintilla.AutoCompletionSource.AcsAll) |
890 | 906 | self.setAutoCompletionThreshold(3) |
891 | 907 |
|
892 | 908 | self.setFont(self.documentFont) |
893 | 909 | self.setMarginsFont(self.marginsFont()) |
894 | | - self.setMarginWidth(0, QFontMetrics(self.marginsFont()).width('0000000') + 5) |
| 910 | + metric = QFontMetrics(self.marginsFont()) |
| 911 | + if Qt_py.IsPyQt4: |
| 912 | + width = metric.width('0000000') |
| 913 | + else: |
| 914 | + width = metric.horizontalAdvance('0000000') |
| 915 | + self.setMarginWidth(0, width + 5) |
895 | 916 |
|
896 | 917 | def markerNext(self): |
897 | 918 | line, index = self.getCursorPosition() |
@@ -1105,7 +1126,7 @@ def saveAs(self, filename='', setFilename=True): |
1105 | 1126 | if not filename: |
1106 | 1127 | newFile = True |
1107 | 1128 | filename = self.filename() |
1108 | | - filename, extFilter = QtCompat.QFileDialog.getSaveFileName( |
| 1129 | + filename, extFilter = Qt_py.QtCompat.QFileDialog.getSaveFileName( |
1109 | 1130 | self.window(), 'Save File as...', filename |
1110 | 1131 | ) |
1111 | 1132 |
|
|
0 commit comments