45 class MiniScintilla(QsciScintillaCompat): |
45 class MiniScintilla(QsciScintillaCompat): |
46 """ |
46 """ |
47 Class implementing a QsciScintillaCompat subclass for handling focus |
47 Class implementing a QsciScintillaCompat subclass for handling focus |
48 events. |
48 events. |
49 """ |
49 """ |
|
50 EncloseChars = { |
|
51 '"': '"', |
|
52 "'": "'", |
|
53 "(": "()", |
|
54 ")": "()", |
|
55 "{": "{}", # __IGNORE_WARNING_M613__ |
|
56 "}": "{}", # __IGNORE_WARNING_M613__ |
|
57 "[": "[]", |
|
58 "]": "[]", |
|
59 "<": "<>", |
|
60 ">": "<>", |
|
61 } |
|
62 |
50 def __init__(self, parent=None): |
63 def __init__(self, parent=None): |
51 """ |
64 """ |
52 Constructor |
65 Constructor |
53 |
66 |
54 @param parent parent widget (QWidget) |
67 @param parent parent widget |
|
68 @type QWidget |
55 """ |
69 """ |
56 super(MiniScintilla, self).__init__(parent) |
70 super(MiniScintilla, self).__init__(parent) |
57 |
71 |
58 self.mw = parent |
72 self.mw = parent |
59 |
73 |
60 def getFileName(self): |
74 def getFileName(self): |
61 """ |
75 """ |
62 Public method to return the name of the file being displayed. |
76 Public method to return the name of the file being displayed. |
63 |
77 |
64 @return filename of the displayed file (string) |
78 @return filename of the displayed file |
|
79 @rtype str |
65 """ |
80 """ |
66 return self.mw.getFileName() |
81 return self.mw.getFileName() |
|
82 |
|
83 def keyPressEvent(self, ev): |
|
84 """ |
|
85 Protected method to handle the user input a key at a time. |
|
86 |
|
87 @param ev key event |
|
88 @type QKeyEvent |
|
89 """ |
|
90 def encloseSelectedText(encString): |
|
91 """ |
|
92 Local function to enclose the current selection with some |
|
93 characters. |
|
94 |
|
95 @param encString string to use to enclose the selection |
|
96 (one or two characters) |
|
97 @type str |
|
98 """ |
|
99 startChar = encString[0] |
|
100 if len(encString) == 2: |
|
101 endChar = encString[1] |
|
102 else: |
|
103 endChar = startChar |
|
104 |
|
105 sline, sindex, eline, eindex = self.getSelection() |
|
106 replaceText = startChar + self.selectedText() + endChar |
|
107 self.beginUndoAction() |
|
108 self.replaceSelectedText(replaceText) |
|
109 self.endUndoAction() |
|
110 self.setSelection(sline, sindex + 1, eline, eindex + 1) |
|
111 |
|
112 txt = ev.text() |
|
113 |
|
114 # See it is text to insert. |
|
115 if len(txt) and txt >= " ": |
|
116 if self.hasSelectedText(): |
|
117 if txt in MiniScintilla.EncloseChars: |
|
118 encloseSelectedText(MiniScintilla.EncloseChars[txt]) |
|
119 ev.accept() |
|
120 return |
|
121 |
|
122 super(MiniScintilla, self).keyPressEvent(ev) |
|
123 else: |
|
124 ev.ignore() |
67 |
125 |
68 def focusInEvent(self, event): |
126 def focusInEvent(self, event): |
69 """ |
127 """ |
70 Protected method called when the editor receives focus. |
128 Protected method called when the editor receives focus. |
71 |
129 |
72 This method checks for modifications of the current file and |
130 This method checks for modifications of the current file and |
73 rereads it upon request. The cursor is placed at the current position |
131 rereads it upon request. The cursor is placed at the current position |
74 assuming, that it is in the vicinity of the old position after the |
132 assuming, that it is in the vicinity of the old position after the |
75 reread. |
133 reread. |
76 |
134 |
77 @param event the event object (QFocusEvent) |
135 @param event the event object |
|
136 @type QFocusEvent |
78 """ |
137 """ |
79 self.mw.editorActGrp.setEnabled(True) |
138 self.mw.editorActGrp.setEnabled(True) |
80 try: |
139 try: |
81 self.setCaretWidth(self.mw.caretWidth) |
140 self.setCaretWidth(self.mw.caretWidth) |
82 except AttributeError: |
141 except AttributeError: |
334 """ |
394 """ |
335 Private slot to show a little About message. |
395 Private slot to show a little About message. |
336 """ |
396 """ |
337 E5MessageBox.about( |
397 E5MessageBox.about( |
338 self, |
398 self, |
339 self.tr("About eric6 Mini Editor"), |
399 self.tr("About eric Mini Editor"), |
340 self.tr( |
400 self.tr( |
341 "The eric6 Mini Editor is an editor component" |
401 "The eric Mini Editor is an editor component" |
342 " based on QScintilla. It may be used for simple" |
402 " based on QScintilla. It may be used for simple" |
343 " editing tasks, that don't need the power of" |
403 " editing tasks, that don't need the power of" |
344 " a full blown editor.")) |
404 " a full blown editor.")) |
345 |
405 |
346 def __aboutQt(self): |
406 def __aboutQt(self): |
347 """ |
407 """ |
348 Private slot to handle the About Qt dialog. |
408 Private slot to handle the About Qt dialog. |
349 """ |
409 """ |
350 E5MessageBox.aboutQt(self, "eric6 Mini Editor") |
410 E5MessageBox.aboutQt(self, "eric Mini Editor") |
351 |
411 |
352 def __whatsThis(self): |
412 def __whatsThis(self): |
353 """ |
413 """ |
354 Private slot called in to enter Whats This mode. |
414 Private slot called in to enter Whats This mode. |
355 """ |
415 """ |
464 self.__createHelpActions() |
524 self.__createHelpActions() |
465 self.__createSearchActions() |
525 self.__createSearchActions() |
466 self.__createViewActions() |
526 self.__createViewActions() |
467 |
527 |
468 # read the keyboard shortcuts and make them identical to the main |
528 # read the keyboard shortcuts and make them identical to the main |
469 # eric6 shortcuts |
529 # eric shortcuts |
470 for act in self.helpActions: |
530 for act in self.helpActions: |
471 self.__readShortcut(act, "General") |
531 self.__readShortcut(act, "General") |
472 for act in self.editActions: |
532 for act in self.editActions: |
473 self.__readShortcut(act, "Edit") |
533 self.__readShortcut(act, "Edit") |
474 for act in self.fileActions: |
534 for act in self.fileActions: |
3182 |
3242 |
3183 @param filename filename used to determine the associated lexer |
3243 @param filename filename used to determine the associated lexer |
3184 language (string) |
3244 language (string) |
3185 @param initTextDisplay flag indicating an initialization of the text |
3245 @param initTextDisplay flag indicating an initialization of the text |
3186 display is required as well (boolean) |
3246 display is required as well (boolean) |
3187 @keyparam pyname name of the pygments lexer to use (string) |
3247 @param pyname name of the pygments lexer to use (string) |
3188 """ |
3248 """ |
3189 self.__bindLexer(filename, pyname=pyname) |
3249 self.__bindLexer(filename, pyname=pyname) |
3190 self.__textEdit.recolor() |
3250 self.__textEdit.recolor() |
3191 self.__checkLanguage() |
3251 self.__checkLanguage() |
3192 |
3252 |