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