PrEditor 1.0.0__py3-none-any.whl → 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of PrEditor might be problematic. Click here for more details.

Files changed (57) hide show
  1. preditor/__init__.py +4 -1
  2. preditor/about_module.py +6 -2
  3. preditor/config.py +16 -0
  4. preditor/dccs/.hab.json +10 -0
  5. preditor/dccs/maya/PrEditor_maya.mod +0 -1
  6. preditor/dccs/maya/README.md +22 -0
  7. preditor/dccs/maya/plug-ins/PrEditor_maya.py +32 -1
  8. preditor/dccs/studiomax/PackageContents.xml +32 -0
  9. preditor/dccs/studiomax/PrEditor-PrEditor_Show.mcr +8 -0
  10. preditor/dccs/studiomax/README.md +17 -0
  11. preditor/dccs/studiomax/preditor.ms +16 -0
  12. preditor/dccs/studiomax/preditor_menu.mnx +7 -0
  13. preditor/debug.py +7 -3
  14. preditor/excepthooks.py +15 -6
  15. preditor/gui/app.py +2 -2
  16. preditor/gui/codehighlighter.py +10 -24
  17. preditor/gui/completer.py +17 -6
  18. preditor/gui/console.py +77 -47
  19. preditor/gui/dialog.py +10 -7
  20. preditor/gui/drag_tab_bar.py +7 -7
  21. preditor/gui/errordialog.py +2 -2
  22. preditor/gui/find_files.py +7 -5
  23. preditor/gui/fuzzy_search/fuzzy_search.py +8 -4
  24. preditor/gui/group_tab_widget/__init__.py +4 -4
  25. preditor/gui/group_tab_widget/grouped_tab_models.py +4 -4
  26. preditor/gui/group_tab_widget/grouped_tab_widget.py +6 -4
  27. preditor/gui/level_buttons.py +16 -1
  28. preditor/gui/loggerwindow.py +51 -28
  29. preditor/gui/set_text_editor_path_dialog.py +3 -1
  30. preditor/gui/window.py +4 -4
  31. preditor/gui/workbox_mixin.py +40 -11
  32. preditor/gui/workbox_text_edit.py +5 -3
  33. preditor/gui/workboxwidget.py +16 -12
  34. preditor/logging_config.py +5 -2
  35. preditor/scintilla/__init__.py +19 -1
  36. preditor/scintilla/delayables/smart_highlight.py +7 -4
  37. preditor/scintilla/delayables/spell_check.py +5 -4
  38. preditor/scintilla/documenteditor.py +165 -116
  39. preditor/scintilla/finddialog.py +3 -3
  40. preditor/scintilla/lang/language.py +1 -1
  41. preditor/scintilla/lexers/cpplexer.py +3 -2
  42. preditor/scintilla/lexers/javascriptlexer.py +6 -4
  43. preditor/scintilla/lexers/maxscriptlexer.py +8 -7
  44. preditor/scintilla/lexers/mellexer.py +3 -2
  45. preditor/scintilla/lexers/mulexer.py +3 -2
  46. preditor/scintilla/lexers/pythonlexer.py +7 -6
  47. preditor/utils/cute.py +9 -8
  48. preditor/version.py +16 -3
  49. {preditor-1.0.0.dist-info → preditor-1.2.0.dist-info}/METADATA +69 -32
  50. {preditor-1.0.0.dist-info → preditor-1.2.0.dist-info}/RECORD +56 -47
  51. preditor-1.2.0.dist-info/top_level.txt +3 -0
  52. tests/find_files/test_find_files.py +74 -0
  53. tests/ide/test_delayable_engine.py +171 -0
  54. preditor-1.0.0.dist-info/top_level.txt +0 -1
  55. {preditor-1.0.0.dist-info → preditor-1.2.0.dist-info}/WHEEL +0 -0
  56. {preditor-1.0.0.dist-info → preditor-1.2.0.dist-info}/entry_points.txt +0 -0
  57. {preditor-1.0.0.dist-info → preditor-1.2.0.dist-info}/licenses/LICENSE +0 -0
@@ -19,11 +19,9 @@ from collections import OrderedDict
19
19
  from contextlib import contextmanager
20
20
  from functools import partial
21
21
 
22
- from PyQt5.Qsci import QsciScintilla
23
- from PyQt5.QtCore import QTextCodec
24
- from Qt import QtCompat
25
- from Qt.QtCore import Property, QFile, QPoint, Qt, Signal
26
- from Qt.QtGui import QColor, QFont, QFontMetrics, QIcon
22
+ import Qt as Qt_py
23
+ from Qt.QtCore import Property, QEvent, QPoint, Qt, Signal
24
+ from Qt.QtGui import QColor, QFont, QFontMetrics, QIcon, QKeySequence
27
25
  from Qt.QtWidgets import (
28
26
  QAction,
29
27
  QApplication,
@@ -37,7 +35,8 @@ from .. import osystem, resourcePath
37
35
  from ..delayable_engine import DelayableEngine
38
36
  from ..enum import Enum, EnumGroup
39
37
  from ..gui import QtPropertyInit
40
- from . import lang
38
+ from ..gui.workbox_mixin import WorkboxMixin
39
+ from . import QsciScintilla, lang
41
40
 
42
41
  logger = logging.getLogger(__name__)
43
42
 
@@ -90,7 +89,7 @@ class DocumentEditor(QsciScintilla):
90
89
  self.additionalFilenames = []
91
90
  self._language = ''
92
91
  self._lastSearch = ''
93
- self._textCodec = None
92
+ self._encoding = 'utf-8'
94
93
  self._fileMonitoringActive = False
95
94
  self._marginsFont = self._defaultFont
96
95
  self._lastSearchDirection = SearchDirection.First
@@ -99,21 +98,21 @@ class DocumentEditor(QsciScintilla):
99
98
  self._enableFontResizing = True
100
99
  # QSci doesnt provide accessors to these values, so store them internally
101
100
  self._foldMarginBackgroundColor = QColor(224, 224, 224)
102
- self._foldMarginForegroundColor = QColor(Qt.white)
101
+ self._foldMarginForegroundColor = QColor(Qt.GlobalColor.white)
103
102
  self._marginsBackgroundColor = QColor(224, 224, 224)
104
103
  self._marginsForegroundColor = QColor()
105
104
  self._matchedBraceBackgroundColor = QColor(224, 224, 224)
106
105
  self._matchedBraceForegroundColor = QColor()
107
- self._unmatchedBraceBackgroundColor = QColor(Qt.white)
108
- self._unmatchedBraceForegroundColor = QColor(Qt.blue)
106
+ self._unmatchedBraceBackgroundColor = QColor(Qt.GlobalColor.white)
107
+ self._unmatchedBraceForegroundColor = QColor(Qt.GlobalColor.blue)
109
108
  self._caretForegroundColor = QColor()
110
109
  self._caretBackgroundColor = QColor(255, 255, 255, 255)
111
110
  self._selectionBackgroundColor = QColor(192, 192, 192)
112
- self._selectionForegroundColor = QColor(Qt.black)
113
- self._indentationGuidesBackgroundColor = QColor(Qt.white)
114
- self._indentationGuidesForegroundColor = QColor(Qt.black)
115
- self._markerBackgroundColor = QColor(Qt.white)
116
- self._markerForegroundColor = QColor(Qt.black)
111
+ self._selectionForegroundColor = QColor(Qt.GlobalColor.black)
112
+ self._indentationGuidesBackgroundColor = QColor(Qt.GlobalColor.white)
113
+ self._indentationGuidesForegroundColor = QColor(Qt.GlobalColor.black)
114
+ self._markerBackgroundColor = QColor(Qt.GlobalColor.white)
115
+ self._markerForegroundColor = QColor(Qt.GlobalColor.black)
117
116
 
118
117
  # Setup the DelayableEngine and add the document to it
119
118
  self.delayable_info = OrderedDict()
@@ -134,13 +133,13 @@ class DocumentEditor(QsciScintilla):
134
133
  self.initSettings(first_time=True)
135
134
 
136
135
  # set one time properties
137
- self.setFolding(QsciScintilla.BoxedTreeFoldStyle)
138
- self.setBraceMatching(QsciScintilla.SloppyBraceMatch)
139
- self.setContextMenuPolicy(Qt.CustomContextMenu)
136
+ self.setFolding(QsciScintilla.FoldStyle.BoxedTreeFoldStyle)
137
+ self.setBraceMatching(QsciScintilla.BraceMatch.SloppyBraceMatch)
138
+ self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
140
139
  self.setAcceptDrops(False)
141
140
  # Not supported by older builds of QsciScintilla
142
141
  if hasattr(self, 'setTabDrawMode'):
143
- self.setTabDrawMode(QsciScintilla.TabStrikeOut)
142
+ self.setTabDrawMode(QsciScintilla.TabDrawMode.TabStrikeOut)
144
143
 
145
144
  # create connections
146
145
  self.customContextMenuRequested.connect(self.showMenu)
@@ -173,23 +172,55 @@ class DocumentEditor(QsciScintilla):
173
172
  commands = self.standardCommands()
174
173
  # Remove the Ctrl+/ "Move left one word part" shortcut so it can be used to
175
174
  # comment
176
- command = commands.boundTo(Qt.ControlModifier | Qt.Key_Slash)
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
+
185
+ command = commands.boundTo(
186
+ to_int(Qt.KeyboardModifier.ControlModifier | Qt.Key.Key_Slash)
187
+ )
177
188
  if command is not None:
178
189
  command.setKey(0)
179
190
 
180
191
  for command in commands.commands():
181
192
  if command.description() == 'Move selected lines up one line':
182
- command.setKey(Qt.ControlModifier | Qt.ShiftModifier | Qt.Key_Up)
193
+ command.setKey(
194
+ to_int(
195
+ Qt.KeyboardModifier.ControlModifier
196
+ | Qt.KeyboardModifier.ShiftModifier
197
+ | Qt.Key.Key_Up
198
+ )
199
+ )
183
200
  if command.description() == 'Move selected lines down one line':
184
- command.setKey(Qt.ControlModifier | Qt.ShiftModifier | Qt.Key_Down)
201
+ command.setKey(
202
+ to_int(
203
+ Qt.KeyboardModifier.ControlModifier
204
+ | Qt.KeyboardModifier.ShiftModifier
205
+ | Qt.Key.Key_Down
206
+ )
207
+ )
185
208
  if command.description() == 'Duplicate selection':
186
- command.setKey(Qt.ControlModifier | Qt.ShiftModifier | Qt.Key_D)
209
+ command.setKey(
210
+ to_int(
211
+ Qt.KeyboardModifier.ControlModifier
212
+ | Qt.KeyboardModifier.ShiftModifier
213
+ | Qt.Key.Key_D
214
+ )
215
+ )
187
216
  if command.description() == 'Cut current line':
188
217
  command.setKey(0)
189
218
 
190
219
  # Add QShortcuts
191
220
  self.uiShowAutoCompleteSCT = QShortcut(
192
- Qt.CTRL | Qt.Key_Space, self, context=Qt.WidgetShortcut
221
+ QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_Space),
222
+ self,
223
+ context=Qt.ShortcutContext.WidgetShortcut,
193
224
  )
194
225
  self.uiShowAutoCompleteSCT.activated.connect(lambda: self.showAutoComplete())
195
226
 
@@ -227,11 +258,13 @@ class DocumentEditor(QsciScintilla):
227
258
  self.window(),
228
259
  'Save changes to...',
229
260
  'Do you want to save your changes?',
230
- QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel,
261
+ QMessageBox.StandardButton.Yes
262
+ | QMessageBox.StandardButton.No
263
+ | QMessageBox.StandardButton.Cancel,
231
264
  )
232
- if result == QMessageBox.Yes:
265
+ if result == QMessageBox.StandardButton.Yes:
233
266
  return self.save()
234
- elif result == QMessageBox.Cancel:
267
+ elif result == QMessageBox.StandardButton.Cancel:
235
268
  return False
236
269
  return True
237
270
 
@@ -508,22 +541,22 @@ class DocumentEditor(QsciScintilla):
508
541
  if newlineN != -1 and newlineR != -1:
509
542
  if newlineN == newlineR + 1:
510
543
  # CR LF Windows
511
- return self.EolWindows
544
+ return QsciScintilla.EolMode.EolWindows
512
545
  elif newlineR == newlineN + 1:
513
- # LF CR ACorn and RISC unsuported
546
+ # LF CR ACorn and RISC unsupported
514
547
  return self.eolMode()
515
548
  if newlineN != -1 and newlineR != -1:
516
549
  if newlineN < newlineR:
517
550
  # First return is a LF
518
- return self.EolUnix
551
+ return QsciScintilla.EolMode.EolUnix
519
552
  else:
520
553
  # first return is a CR
521
- return self.EolMac
554
+ return QsciScintilla.EolMode.EolMac
522
555
  if newlineN != -1:
523
- return self.EolUnix
556
+ return QsciScintilla.EolMode.EolUnix
524
557
  if sys.platform == 'win32':
525
- return self.EolWindows
526
- return self.EolUnix
558
+ return QsciScintilla.EolMode.EolWindows
559
+ return QsciScintilla.EolMode.EolUnix
527
560
 
528
561
  def editPermaHighlight(self):
529
562
  text, success = QInputDialog.getText(
@@ -564,7 +597,7 @@ class DocumentEditor(QsciScintilla):
564
597
  self.modificationChanged.connect(self.refreshTitle)
565
598
 
566
599
  def eventFilter(self, object, event):
567
- if event.type() == event.Close and not self.checkForSave():
600
+ if event.type() == QEvent.Type.Close and not self.checkForSave():
568
601
  event.ignore()
569
602
  return True
570
603
  return False
@@ -657,14 +690,8 @@ class DocumentEditor(QsciScintilla):
657
690
  def load(self, filename):
658
691
  filename = str(filename)
659
692
  if filename and os.path.exists(filename):
660
- f = QFile(filename)
661
- f.open(QFile.ReadOnly)
662
- text = f.readAll()
663
- self._textCodec = QTextCodec.codecForUtfText(
664
- text, QTextCodec.codecForName('UTF-8')
665
- )
666
- self.setText(self._textCodec.toUnicode(text))
667
- f.close()
693
+ self._encoding, text = WorkboxMixin.__open_file__(filename)
694
+ self.setText(text)
668
695
  self.updateFilename(filename)
669
696
  self.enableFileWatching(True)
670
697
  self.setEolMode(self.detectEndLine(self.text()))
@@ -719,14 +746,14 @@ class DocumentEditor(QsciScintilla):
719
746
  if find_state.start_pos == find_state.end_pos:
720
747
  return -1
721
748
 
722
- self.SendScintilla(self.SCI_SETTARGETSTART, find_state.start_pos)
723
- self.SendScintilla(self.SCI_SETTARGETEND, find_state.end_pos)
749
+ self.SendScintilla(QsciScintilla.SCI_SETTARGETSTART, find_state.start_pos)
750
+ self.SendScintilla(QsciScintilla.SCI_SETTARGETEND, find_state.end_pos)
724
751
 
725
752
  # scintilla can't match unicode strings, even in python 3
726
753
  # In python 3 you have to cast it to a bytes object
727
754
  expr = bytes(str(find_state.expr).encode("utf-8"))
728
755
 
729
- return self.SendScintilla(self.SCI_SEARCHINTARGET, len(expr), expr)
756
+ return self.SendScintilla(QsciScintilla.SCI_SEARCHINTARGET, len(expr), expr)
730
757
 
731
758
  def find_text(self, find_state):
732
759
  """Finds text in the document without changing the selection.
@@ -739,10 +766,10 @@ class DocumentEditor(QsciScintilla):
739
766
  https://github.com/josephwilk/qscintilla/blob/master/Qt4Qt5/qsciscintilla.cpp
740
767
  """
741
768
  # Set the search flags
742
- self.SendScintilla(self.SCI_SETSEARCHFLAGS, find_state.flags)
769
+ self.SendScintilla(QsciScintilla.SCI_SETSEARCHFLAGS, find_state.flags)
743
770
  # If no end was specified, use the end of the document
744
771
  if find_state.end_pos is None:
745
- find_state.end_pos = self.SendScintilla(self.SCI_GETLENGTH)
772
+ find_state.end_pos = self.SendScintilla(QsciScintilla.SCI_GETLENGTH)
746
773
 
747
774
  pos = self.find_simple(find_state)
748
775
 
@@ -751,12 +778,14 @@ class DocumentEditor(QsciScintilla):
751
778
  if find_state.forward:
752
779
  find_state.start_pos = 0
753
780
  if find_state.start_pos_original is None:
754
- find_state.end_pos = self.SendScintilla(self.SCI_GETLENGTH)
781
+ find_state.end_pos = self.SendScintilla(QsciScintilla.SCI_GETLENGTH)
755
782
  else:
756
783
  find_state.end_pos = find_state.start_pos_original
757
784
  else:
758
785
  if find_state.start_pos_original is None:
759
- find_state.start_pos = self.SendScintilla(self.SCI_GETLENGTH)
786
+ find_state.start_pos = self.SendScintilla(
787
+ QsciScintilla.SCI_GETLENGTH
788
+ )
760
789
  else:
761
790
  find_state.start_pos = find_state.start_pos_original
762
791
  find_state.end_pos = 0
@@ -769,8 +798,8 @@ class DocumentEditor(QsciScintilla):
769
798
  return -1, 0
770
799
 
771
800
  # It was found.
772
- target_start = self.SendScintilla(self.SCI_GETTARGETSTART)
773
- target_end = self.SendScintilla(self.SCI_GETTARGETEND)
801
+ target_start = self.SendScintilla(QsciScintilla.SCI_GETTARGETSTART)
802
+ target_end = self.SendScintilla(QsciScintilla.SCI_GETTARGETEND)
774
803
 
775
804
  # Finally adjust the start position so that we don't find the same one again.
776
805
  if find_state.forward:
@@ -818,10 +847,12 @@ class DocumentEditor(QsciScintilla):
818
847
  self,
819
848
  'No Text Found',
820
849
  msg % (text, line),
821
- buttons=(QMessageBox.Yes | QMessageBox.No),
822
- defaultButton=QMessageBox.Yes,
850
+ buttons=(
851
+ QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
852
+ ),
853
+ defaultButton=QMessageBox.StandardButton.Yes,
823
854
  )
824
- if result == QMessageBox.Yes:
855
+ if result == QMessageBox.StandardButton.Yes:
825
856
  self.goToLine(line)
826
857
  except ValueError:
827
858
  QMessageBox.critical(
@@ -830,20 +861,20 @@ class DocumentEditor(QsciScintilla):
830
861
 
831
862
  def keyPressEvent(self, event):
832
863
  key = event.key()
833
- if key == Qt.Key_Backtab:
864
+ if key == Qt.Key.Key_Backtab:
834
865
  self.unindentSelection()
835
- elif key == Qt.Key_Escape:
866
+ elif key == Qt.Key.Key_Escape:
836
867
  # Using QShortcut for Escape did not seem to work.
837
868
  self.showAutoComplete(True)
838
869
  else:
839
870
  return QsciScintilla.keyPressEvent(self, event)
840
871
 
841
872
  def keyReleaseEvent(self, event):
842
- if event.key() == Qt.Key_Menu:
873
+ if event.key() == Qt.Key.Key_Menu:
843
874
  # Calculate the screen coordinates of the text cursor.
844
875
  position = self.positionFromLineIndex(*self.getCursorPosition())
845
- x = self.SendScintilla(self.SCI_POINTXFROMPOSITION, 0, position)
846
- y = self.SendScintilla(self.SCI_POINTYFROMPOSITION, 0, position)
876
+ x = self.SendScintilla(QsciScintilla.SCI_POINTXFROMPOSITION, 0, position)
877
+ y = self.SendScintilla(QsciScintilla.SCI_POINTYFROMPOSITION, 0, position)
847
878
  # When using the menu key, show the right click menu at the text
848
879
  # cursor, not the mouse cursor, it is not in the correct place.
849
880
  self.showMenu(QPoint(x, y))
@@ -867,15 +898,20 @@ class DocumentEditor(QsciScintilla):
867
898
  self.setShowSmartHighlighting(True)
868
899
  self.setBackspaceUnindents(True)
869
900
 
870
- self.setEdgeMode(self.EdgeNone)
901
+ self.setEdgeMode(QsciScintilla.EdgeMode.EdgeNone)
871
902
 
872
- # set autocompletion settings
873
- self.setAutoCompletionSource(QsciScintilla.AcsAll)
903
+ # set auto-completion settings
904
+ self.setAutoCompletionSource(QsciScintilla.AutoCompletionSource.AcsAll)
874
905
  self.setAutoCompletionThreshold(3)
875
906
 
876
907
  self.setFont(self.documentFont)
877
908
  self.setMarginsFont(self.marginsFont())
878
- 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)
879
915
 
880
916
  def markerNext(self):
881
917
  line, index = self.getCursorPosition()
@@ -910,15 +946,15 @@ class DocumentEditor(QsciScintilla):
910
946
 
911
947
  def multipleSelection(self):
912
948
  """Returns if multiple selection is enabled."""
913
- return self.SendScintilla(self.SCI_GETMULTIPLESELECTION)
949
+ return self.SendScintilla(QsciScintilla.SCI_GETMULTIPLESELECTION)
914
950
 
915
951
  def multipleSelectionAdditionalSelectionTyping(self):
916
952
  """Returns if multiple selection allows additional typing."""
917
- return self.SendScintilla(self.SCI_GETMULTIPLESELECTION)
953
+ return self.SendScintilla(QsciScintilla.SCI_GETMULTIPLESELECTION)
918
954
 
919
955
  def multipleSelectionMultiPaste(self):
920
956
  """Paste into all multiple selections."""
921
- return self.SendScintilla(self.SCI_GETMULTIPASTE)
957
+ return self.SendScintilla(QsciScintilla.SCI_GETMULTIPASTE)
922
958
 
923
959
  def paste(self):
924
960
  text = QApplication.clipboard().text()
@@ -926,9 +962,9 @@ class DocumentEditor(QsciScintilla):
926
962
  return super(DocumentEditor, self).paste()
927
963
 
928
964
  def repForMode(mode):
929
- if mode == self.EolWindows:
965
+ if mode == QsciScintilla.EolMode.EolWindows:
930
966
  return '\r\n'
931
- elif mode == self.EolUnix:
967
+ elif mode == QsciScintilla.EolMode.EolUnix:
932
968
  return '\n'
933
969
  else:
934
970
  return '\r'
@@ -987,11 +1023,11 @@ class DocumentEditor(QsciScintilla):
987
1023
  self.window(),
988
1024
  'File Removed...',
989
1025
  'File: %s has been deleted.\nKeep file in editor?' % self.filename(),
990
- QMessageBox.Yes,
991
- QMessageBox.No,
1026
+ QMessageBox.StandardButton.Yes,
1027
+ QMessageBox.StandardButton.No,
992
1028
  )
993
1029
  self._dialogShown = False
994
- if result == QMessageBox.No:
1030
+ if result == QMessageBox.StandardButton.No:
995
1031
  logger.debug(
996
1032
  'The file was deleted, removing document from editor',
997
1033
  )
@@ -1013,13 +1049,16 @@ class DocumentEditor(QsciScintilla):
1013
1049
  if not self._dialogShown:
1014
1050
  self._dialogShown = True
1015
1051
  if self._autoReloadOnChange or not self.isModified():
1016
- result = QMessageBox.Yes
1052
+ result = QMessageBox.StandardButton.Yes
1017
1053
  else:
1018
1054
  result = QMessageBox.question(
1019
- self.window(), title, message, QMessageBox.Yes | QMessageBox.No
1055
+ self.window(),
1056
+ title,
1057
+ message,
1058
+ QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
1020
1059
  )
1021
1060
  self._dialogShown = False
1022
- if result == QMessageBox.Yes:
1061
+ if result == QMessageBox.StandardButton.Yes:
1023
1062
  return self.load(self.filename())
1024
1063
  return False
1025
1064
 
@@ -1037,7 +1076,9 @@ class DocumentEditor(QsciScintilla):
1037
1076
 
1038
1077
  # replace all of the instances of the text
1039
1078
  if all:
1040
- count = self.text().count(searchtext, Qt.CaseInsensitive)
1079
+ count = self.text().count(
1080
+ searchtext, Qt.CaseSensitivity.CaseInsensitive
1081
+ )
1041
1082
  found = 0
1042
1083
  while self.findFirst(searchtext, False, False, False, True, True):
1043
1084
  if found == count:
@@ -1084,32 +1125,28 @@ class DocumentEditor(QsciScintilla):
1084
1125
  if not filename:
1085
1126
  newFile = True
1086
1127
  filename = self.filename()
1087
- filename, extFilter = QtCompat.QFileDialog.getSaveFileName(
1128
+ filename, extFilter = Qt_py.QtCompat.QFileDialog.getSaveFileName(
1088
1129
  self.window(), 'Save File as...', filename
1089
1130
  )
1090
1131
 
1091
1132
  if filename:
1092
1133
  self._saveTimer = time.time()
1093
1134
  # save the file to disk
1094
- f = QFile(filename)
1095
- f.open(QFile.WriteOnly)
1096
- # make sure the file is writeable
1097
- if f.error() != QFile.NoError:
1098
- logger.debug('An error occured while saving')
1135
+ try:
1136
+ txt = self.text()
1137
+ WorkboxMixin.__write_file__(filename, txt, encoding=self._encoding)
1138
+ with open(filename, "w", encoding=self._encoding) as f:
1139
+ f.write(self.text())
1140
+ except PermissionError as error:
1141
+ logger.debug('An error occurred while saving')
1099
1142
  QMessageBox.question(
1100
1143
  self.window(),
1101
1144
  'Error saving file...',
1102
- 'There was a error saving the file. Error Code: %i' % f.error(),
1103
- QMessageBox.Ok,
1145
+ 'There was a error saving the file. Error: {}'.format(error),
1146
+ QMessageBox.StandardButton.Ok,
1104
1147
  )
1105
- f.close()
1106
1148
  return False
1107
- # Attempt to save the file using the same codec that it used to display it
1108
- if self._textCodec:
1109
- f.write(self._textCodec.fromUnicode(self.text()))
1110
- else:
1111
- self.write(f)
1112
- f.close()
1149
+
1113
1150
  # notify that the document was saved
1114
1151
  self.documentSaved.emit(self, filename)
1115
1152
 
@@ -1165,8 +1202,8 @@ class DocumentEditor(QsciScintilla):
1165
1202
  return False
1166
1203
  # Get the word at the start of selection, if the selection doesn't match
1167
1204
  # its not a word.
1168
- start_pos = self.SendScintilla(self.SCI_WORDSTARTPOSITION, start, True)
1169
- end_pos = self.SendScintilla(self.SCI_WORDENDPOSITION, start, True)
1205
+ start_pos = self.SendScintilla(QsciScintilla.SCI_WORDSTARTPOSITION, start, True)
1206
+ end_pos = self.SendScintilla(QsciScintilla.SCI_WORDENDPOSITION, start, True)
1170
1207
 
1171
1208
  return start == start_pos and end == end_pos
1172
1209
 
@@ -1227,7 +1264,9 @@ class DocumentEditor(QsciScintilla):
1227
1264
  # from a wordCharactersOverride lexer to a lexer that doesn't define custom
1228
1265
  # wordCharacters.
1229
1266
  wordCharacters = self.wordCharacters()
1230
- self.SendScintilla(self.SCI_SETWORDCHARS, wordCharacters.encode('utf8'))
1267
+ self.SendScintilla(
1268
+ QsciScintilla.SCI_SETWORDCHARS, wordCharacters.encode('utf8')
1269
+ )
1231
1270
 
1232
1271
  if lexer:
1233
1272
  lexer.setFont(font)
@@ -1250,7 +1289,7 @@ class DocumentEditor(QsciScintilla):
1250
1289
  ranges by holding down the Ctrl key while dragging with the
1251
1290
  mouse.
1252
1291
  """
1253
- self.SendScintilla(self.SCI_SETMULTIPLESELECTION, state)
1292
+ self.SendScintilla(QsciScintilla.SCI_SETMULTIPLESELECTION, state)
1254
1293
 
1255
1294
  def setMultipleSelectionAdditionalSelectionTyping(self, state):
1256
1295
  """Enables or disables multiple selection allows additional typing.
@@ -1261,7 +1300,7 @@ class DocumentEditor(QsciScintilla):
1261
1300
  simultaneously. Also allows selection and word and line
1262
1301
  deletion commands.
1263
1302
  """
1264
- self.SendScintilla(self.SCI_SETADDITIONALSELECTIONTYPING, state)
1303
+ self.SendScintilla(QsciScintilla.SCI_SETADDITIONALSELECTIONTYPING, state)
1265
1304
 
1266
1305
  def setMultipleSelectionMultiPaste(self, state):
1267
1306
  """Enables or disables multiple selection allows additional typing.
@@ -1272,7 +1311,7 @@ class DocumentEditor(QsciScintilla):
1272
1311
  into each selection with self.SC_MULTIPASTE_EACH.
1273
1312
  self.SC_MULTIPASTE_ONCE is the default.
1274
1313
  """
1275
- self.SendScintilla(self.SCI_SETMULTIPASTE, state)
1314
+ self.SendScintilla(QsciScintilla.SCI_SETMULTIPASTE, state)
1276
1315
 
1277
1316
  def setSmartHighlightingRegEx(
1278
1317
  self, exp=r'[ \t\n\r\.,?;:!()\[\]+\-\*\/#@^%$"\\~&{}|=<>\']'
@@ -1300,9 +1339,9 @@ class DocumentEditor(QsciScintilla):
1300
1339
 
1301
1340
  def setShowWhitespaces(self, state):
1302
1341
  if state:
1303
- self.setWhitespaceVisibility(QsciScintilla.WsVisible)
1342
+ self.setWhitespaceVisibility(QsciScintilla.WhitespaceVisibility.WsVisible)
1304
1343
  else:
1305
- self.setWhitespaceVisibility(QsciScintilla.WsInvisible)
1344
+ self.setWhitespaceVisibility(QsciScintilla.WhitespaceVisibility.WsInvisible)
1306
1345
 
1307
1346
  def spellCheckEnabled(self):
1308
1347
  """Is spellcheck is enabled for this document."""
@@ -1320,13 +1359,13 @@ class DocumentEditor(QsciScintilla):
1320
1359
  self.__speller__.saveAllwords()
1321
1360
  self.spellCheck(0, None)
1322
1361
  self.pos += len(word)
1323
- self.SendScintilla(self.SCI_GOTOPOS, self.pos)
1362
+ self.SendScintilla(QsciScintilla.SCI_GOTOPOS, self.pos)
1324
1363
 
1325
1364
  def correctSpelling(self, action):
1326
- self.SendScintilla(self.SCI_GOTOPOS, self.pos)
1327
- self.SendScintilla(self.SCI_SETANCHOR, self.anchor)
1365
+ self.SendScintilla(QsciScintilla.SCI_GOTOPOS, self.pos)
1366
+ self.SendScintilla(QsciScintilla.SCI_SETANCHOR, self.anchor)
1328
1367
  with undo_step(self):
1329
- self.SendScintilla(self.SCI_REPLACESEL, action.text())
1368
+ self.SendScintilla(QsciScintilla.SCI_REPLACESEL, action.text())
1330
1369
 
1331
1370
  def spellCheck(self, start_pos, end_pos):
1332
1371
  """Check spelling for some text in the document.
@@ -1360,18 +1399,20 @@ class DocumentEditor(QsciScintilla):
1360
1399
  or (mtype & self.SC_MOD_DELETETEXT) == self.SC_MOD_DELETETEXT
1361
1400
  ):
1362
1401
  # Only spell-check if text was inserted/deleted
1363
- line = self.SendScintilla(self.SCI_LINEFROMPOSITION, pos)
1402
+ line = self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, pos)
1364
1403
  # More than one line could have been inserted.
1365
1404
  # If this number is negative it will cause Qt to crash.
1366
1405
  lines_to_check = line + max(0, linesAdded)
1367
1406
  self.spellCheck(
1368
- self.SendScintilla(self.SCI_POSITIONFROMLINE, line),
1369
- self.SendScintilla(self.SCI_GETLINEENDPOSITION, lines_to_check),
1407
+ self.SendScintilla(QsciScintilla.SCI_POSITIONFROMLINE, line),
1408
+ self.SendScintilla(
1409
+ QsciScintilla.SCI_GETLINEENDPOSITION, lines_to_check
1410
+ ),
1370
1411
  )
1371
1412
 
1372
1413
  def showAutoComplete(self, toggle=False):
1373
1414
  # if using autoComplete toggle the autoComplete list
1374
- if self.autoCompletionSource() == QsciScintilla.AcsAll:
1415
+ if self.autoCompletionSource() == QsciScintilla.AutoCompletionSource.AcsAll:
1375
1416
  if self.isListActive(): # is the autoComplete list visible
1376
1417
  if toggle:
1377
1418
  self.cancelList() # Close the autoComplete list
@@ -1389,9 +1430,11 @@ class DocumentEditor(QsciScintilla):
1389
1430
  x = point.x()
1390
1431
  y = point.y()
1391
1432
  wordUnderMouse = self.wordAtPoint(point)
1392
- positionMouse = self.SendScintilla(self.SCI_POSITIONFROMPOINT, x, y)
1433
+ positionMouse = self.SendScintilla(
1434
+ QsciScintilla.SCI_POSITIONFROMPOINT, x, y
1435
+ )
1393
1436
  wordStartPosition = self.SendScintilla(
1394
- self.SCI_WORDSTARTPOSITION, positionMouse, True
1437
+ QsciScintilla.SCI_WORDSTARTPOSITION, positionMouse, True
1395
1438
  )
1396
1439
  spell_check = self.delayable_engine.delayables['spell_check']
1397
1440
  results = spell_check.chunk_re.findall(
@@ -1556,7 +1599,9 @@ class DocumentEditor(QsciScintilla):
1556
1599
  return self.delayable_engine.delayable_enabled('smart_highlight')
1557
1600
 
1558
1601
  def showWhitespaces(self):
1559
- return self.whitespaceVisibility() == QsciScintilla.WsVisible
1602
+ return (
1603
+ self.whitespaceVisibility() == QsciScintilla.WhitespaceVisibility.WsVisible
1604
+ )
1560
1605
 
1561
1606
  def smartHighlightingRegEx(self):
1562
1607
  return self._smartHighlightingRegEx
@@ -1570,7 +1615,10 @@ class DocumentEditor(QsciScintilla):
1570
1615
  self.setSelection(lineFrom, indexFrom, lineTo, indexTo)
1571
1616
 
1572
1617
  def toggleFolding(self):
1573
- self.foldAll(QApplication.instance().keyboardModifiers() == Qt.ShiftModifier)
1618
+ self.foldAll(
1619
+ QApplication.instance().keyboardModifiers()
1620
+ == Qt.KeyboardModifier.ShiftModifier
1621
+ )
1574
1622
 
1575
1623
  def toUpper(self):
1576
1624
  with undo_step(self):
@@ -1710,10 +1758,8 @@ class DocumentEditor(QsciScintilla):
1710
1758
  epos=epos,
1711
1759
  lineCount=eline - sline + 1,
1712
1760
  )
1713
- if self._textCodec and self._textCodec.name() != 'System':
1714
- text = 'Encoding: {enc} {text}'.format(
1715
- enc=self._textCodec.name(), text=text
1716
- )
1761
+ if self._encoding:
1762
+ text = 'Encoding: {enc} {text}'.format(enc=self._encoding, text=text)
1717
1763
  window.uiCursorInfoLBL.setText(text)
1718
1764
 
1719
1765
  def setAutoReloadOnChange(self, state):
@@ -1754,7 +1800,10 @@ class DocumentEditor(QsciScintilla):
1754
1800
  return title
1755
1801
 
1756
1802
  def wheelEvent(self, event):
1757
- if self._enableFontResizing and event.modifiers() == Qt.ControlModifier:
1803
+ if (
1804
+ self._enableFontResizing
1805
+ and event.modifiers() == Qt.KeyboardModifier.ControlModifier
1806
+ ):
1758
1807
  # If used in LoggerWindow, use that wheel event
1759
1808
  # May not want to import LoggerWindow, so perhaps
1760
1809
  # check by str(type())
@@ -35,10 +35,10 @@ class FindDialog(Dialog):
35
35
  def eventFilter(self, object, event):
36
36
  from Qt.QtCore import QEvent, Qt
37
37
 
38
- if event.type() == QEvent.KeyPress:
38
+ if event.type() == QEvent.Type.KeyPress:
39
39
  if (
40
- event.key() in (Qt.Key_Enter, Qt.Key_Return)
41
- and not event.modifiers() == Qt.ShiftModifier
40
+ event.key() in (Qt.Key.Key_Enter, Qt.Key.Key_Return)
41
+ and not event.modifiers() == Qt.KeyboardModifier.ShiftModifier
42
42
  ):
43
43
  self.parent().uiFindNextACT.triggered.emit(True)
44
44
  self.accept()
@@ -8,7 +8,7 @@ try:
8
8
  except ImportError:
9
9
  from ConfigParser import ConfigParser
10
10
 
11
- from PyQt5 import Qsci
11
+ from .. import Qsci
12
12
 
13
13
 
14
14
  class MethodDescriptor(object):
@@ -1,10 +1,11 @@
1
1
  from __future__ import absolute_import
2
2
 
3
- from PyQt5.Qsci import QsciLexerCPP
4
3
  from Qt.QtGui import QColor
5
4
 
5
+ from .. import Qsci
6
6
 
7
- class CppLexer(QsciLexerCPP):
7
+
8
+ class CppLexer(Qsci.QsciLexerCPP):
8
9
  # Items in this list will be highlighted using the color for self.KeywordSet2
9
10
  highlightedKeywords = ''
10
11