ScriptEdit.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. ***************************************************************************
  3. ScriptEdit.py
  4. ---------------------
  5. Date : April 2013
  6. Copyright : (C) 2013 by Alexander Bruy
  7. Email : alexander dot bruy at gmail dot com
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Alexander Bruy'
  18. __date__ = 'April 2013'
  19. __copyright__ = '(C) 2013, Alexander Bruy'
  20. from qgis.PyQt.QtCore import Qt
  21. from qgis.PyQt.QtGui import QKeySequence
  22. from qgis.PyQt.QtWidgets import QShortcut
  23. from qgis.gui import QgsCodeEditorPython
  24. from qgis.PyQt.Qsci import QsciScintilla
  25. class ScriptEdit(QgsCodeEditorPython):
  26. def __init__(self, parent=None):
  27. super().__init__(parent)
  28. self.initShortcuts()
  29. def initShortcuts(self):
  30. (ctrl, shift) = (self.SCMOD_CTRL << 16, self.SCMOD_SHIFT << 16)
  31. # Disable some shortcuts
  32. self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('D') + ctrl)
  33. self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('L') + ctrl)
  34. self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('L') + ctrl
  35. + shift)
  36. self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord('T') + ctrl)
  37. # self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord("Z") + ctrl)
  38. # self.SendScintilla(QsciScintilla.SCI_CLEARCMDKEY, ord("Y") + ctrl)
  39. # Use Ctrl+Space for autocompletion
  40. self.shortcutAutocomplete = QShortcut(QKeySequence(Qt.CTRL
  41. + Qt.Key_Space), self)
  42. self.shortcutAutocomplete.setContext(Qt.WidgetShortcut)
  43. self.shortcutAutocomplete.activated.connect(self.autoComplete)