49 """ |
49 """ |
50 def __init__(self, parent=None): |
50 def __init__(self, parent=None): |
51 """ |
51 """ |
52 Constructor |
52 Constructor |
53 |
53 |
54 @param parent parent widget (QWidget) |
54 @param parent parent widget |
|
55 @type QWidget |
55 """ |
56 """ |
56 super(MiniScintilla, self).__init__(parent) |
57 super(MiniScintilla, self).__init__(parent) |
57 |
58 |
58 self.mw = parent |
59 self.mw = parent |
59 |
60 |
60 def getFileName(self): |
61 def getFileName(self): |
61 """ |
62 """ |
62 Public method to return the name of the file being displayed. |
63 Public method to return the name of the file being displayed. |
63 |
64 |
64 @return filename of the displayed file (string) |
65 @return filename of the displayed file |
|
66 @rtype str |
65 """ |
67 """ |
66 return self.mw.getFileName() |
68 return self.mw.getFileName() |
|
69 |
|
70 def keyPressEvent(self, ev): |
|
71 """ |
|
72 Protected method to handle the user input a key at a time. |
|
73 |
|
74 @param ev key event |
|
75 @type QKeyEvent |
|
76 """ |
|
77 txt = ev.text() |
|
78 |
|
79 # See it is text to insert. |
|
80 if len(txt) and txt >= " ": |
|
81 if txt in ('"', "'") and self.hasSelectedText(): |
|
82 sline, sindex, eline, eindex = self.getSelection() |
|
83 replaceText = txt + self.selectedText() + txt |
|
84 self.beginUndoAction() |
|
85 self.replaceSelectedText(replaceText) |
|
86 self.endUndoAction() |
|
87 self.setSelection(sline, sindex + 1, eline, eindex + 1) |
|
88 ev.accept() |
|
89 return |
|
90 |
|
91 super(MiniScintilla, self).keyPressEvent(ev) |
|
92 else: |
|
93 ev.ignore() |
67 |
94 |
68 def focusInEvent(self, event): |
95 def focusInEvent(self, event): |
69 """ |
96 """ |
70 Protected method called when the editor receives focus. |
97 Protected method called when the editor receives focus. |
71 |
98 |
72 This method checks for modifications of the current file and |
99 This method checks for modifications of the current file and |
73 rereads it upon request. The cursor is placed at the current position |
100 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 |
101 assuming, that it is in the vicinity of the old position after the |
75 reread. |
102 reread. |
76 |
103 |
77 @param event the event object (QFocusEvent) |
104 @param event the event object |
|
105 @type QFocusEvent |
78 """ |
106 """ |
79 self.mw.editorActGrp.setEnabled(True) |
107 self.mw.editorActGrp.setEnabled(True) |
80 try: |
108 try: |
81 self.setCaretWidth(self.mw.caretWidth) |
109 self.setCaretWidth(self.mw.caretWidth) |
82 except AttributeError: |
110 except AttributeError: |
88 |
116 |
89 def focusOutEvent(self, event): |
117 def focusOutEvent(self, event): |
90 """ |
118 """ |
91 Protected method called when the editor loses focus. |
119 Protected method called when the editor loses focus. |
92 |
120 |
93 @param event the event object (QFocusEvent) |
121 @param event the event object |
|
122 @type QFocusEvent |
94 """ |
123 """ |
95 self.mw.editorActGrp.setEnabled(False) |
124 self.mw.editorActGrp.setEnabled(False) |
96 self.setCaretWidth(0) |
125 self.setCaretWidth(0) |
97 |
126 |
98 super(MiniScintilla, self).focusOutEvent(event) |
127 super(MiniScintilla, self).focusOutEvent(event) |