QScintilla/QsciScintillaCompat.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3393
080ace4829b4
child 3515
1b8381afe38f
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
67 self.__targetSearchFlags = 0 67 self.__targetSearchFlags = 0
68 self.__targetSearchExpr = "" 68 self.__targetSearchExpr = ""
69 self.__targetSearchStart = 0 69 self.__targetSearchStart = 0
70 self.__targetSearchEnd = -1 70 self.__targetSearchEnd = -1
71 self.__targetSearchActive = False 71 self.__targetSearchActive = False
72
73 self.__modified = False
74
75 self.userListActivated.connect(self.__completionListSelected)
76 self.modificationChanged.connect(self.__modificationChanged)
77
78 def __modificationChanged(self, m):
79 """
80 Private slot to handle the modificationChanged signal.
81
82 @param m modification status (boolean)
83 """
84 self.__modified = m
85
86 def isModified(self):
87 """
88 Public method to return the modification status.
89
90 @return flag indicating the modification status (boolean)
91 """
92 return self.__modified
93
94 def setModified(self, m):
95 """
96 Public slot to set the modification status.
97
98 @param m new modification status (boolean)
99 """
100 self.__modified = m
101 super(QsciScintillaCompat, self).setModified(m)
102 self.modificationChanged.emit(m)
72 103
73 def setLexer(self, lex=None): 104 def setLexer(self, lex=None):
74 """ 105 """
75 Public method to set the lexer. 106 Public method to set the lexer.
76 107
1179 Public method called when the editor loses focus. 1210 Public method called when the editor loses focus.
1180 1211
1181 @param event event object (QFocusEvent) 1212 @param event event object (QFocusEvent)
1182 """ 1213 """
1183 if self.isListActive(): 1214 if self.isListActive():
1184 self.cancelList() 1215 if event.reason() == Qt.ActiveWindowFocusReason:
1216 aw = QApplication.activeWindow()
1217 if aw is None or aw.parent() is not self:
1218 self.cancelList()
1219 else:
1220 self.cancelList()
1221
1222 if self.isCallTipActive():
1223 if event.reason() == Qt.ActiveWindowFocusReason:
1224 aw = QApplication.activeWindow()
1225 if aw is None or aw.parent() is not self:
1226 self.SendScintilla(QsciScintilla.SCI_CALLTIPCANCEL)
1227 else:
1228 self.SendScintilla(QsciScintilla.SCI_CALLTIPCANCEL)
1185 1229
1186 super(QsciScintillaCompat, self).focusOutEvent(event) 1230 super(QsciScintillaCompat, self).focusOutEvent(event)
1187 1231
1188 def event(self, evt): 1232 def event(self, evt):
1189 """ 1233 """
1195 @param evt event object to handle (QEvent) 1239 @param evt event object to handle (QEvent)
1196 @return result of the event handling (boolean) 1240 @return result of the event handling (boolean)
1197 """ 1241 """
1198 return QsciScintillaBase.event(self, evt) 1242 return QsciScintillaBase.event(self, evt)
1199 1243
1200 # TODO: adjust this once we have a working QScintilla version
1201 if "inputMethodEvent" in QsciScintillaBase.__dict__ and \ 1244 if "inputMethodEvent" in QsciScintillaBase.__dict__ and \
1202 QSCINTILLA_VERSION() < 0x020900: 1245 QSCINTILLA_VERSION() < 0x020801:
1203 def inputMethodEvent(self, evt): 1246 def inputMethodEvent(self, evt):
1204 """ 1247 """
1205 Protected method to cope with a glitch in some Qscintilla versions 1248 Protected method to cope with a glitch in some Qscintilla versions
1206 handling input events. 1249 handling input events.
1207 1250
1246 1289
1247 ########################################################################### 1290 ###########################################################################
1248 ## replacements for buggy methods 1291 ## replacements for buggy methods
1249 ########################################################################### 1292 ###########################################################################
1250 1293
1251 def showUserList(self, id, lst): 1294 if "showUserList" not in QsciScintilla.__dict__:
1252 """ 1295 def showUserList(self, id, lst):
1253 Public method to show a user supplied list. 1296 """
1254 1297 Public method to show a user supplied list.
1255 @param id id of the list (integer) 1298
1256 @param lst list to be show (list of strings) 1299 @param id id of the list (integer)
1257 """ 1300 @param lst list to be show (list of strings)
1258 if id <= 0: 1301 """
1259 return 1302 if id <= 0:
1260 1303 return
1261 self.SendScintilla(QsciScintilla.SCI_AUTOCSETSEPARATOR, 1304
1262 ord(self.UserSeparator)) 1305 self.SendScintilla(
1263 self.SendScintilla(QsciScintilla.SCI_USERLISTSHOW, id, 1306 QsciScintilla.SCI_AUTOCSETSEPARATOR,
1264 self._encodeString(self.UserSeparator.join(lst))) 1307 ord(self.UserSeparator))
1308 self.SendScintilla(
1309 QsciScintilla.SCI_USERLISTSHOW, id,
1310 self._encodeString(self.UserSeparator.join(lst)))
1311
1312 ###########################################################################
1313 ## work-arounds for buggy behavior
1314 ###########################################################################
1315
1316 def __completionListSelected(self, id, txt):
1317 """
1318 Private slot to handle the selection from the completion list.
1319
1320 Note: This works around an issue of some window managers taking
1321 focus away from the application when clicked inside a completion
1322 list but not giving it back when an item is selected via a
1323 double-click.
1324
1325 @param id the ID of the user list (integer)
1326 @param txt the selected text (string)
1327 """
1328 self.activateWindow()
1265 1329
1266 ########################################################################### 1330 ###########################################################################
1267 ## utility methods 1331 ## utility methods
1268 ########################################################################### 1332 ###########################################################################
1269 1333
1300 # Allow for multi-byte characters 1364 # Allow for multi-byte characters
1301 for i in range(index): 1365 for i in range(index):
1302 pos = self.positionAfter(pos) 1366 pos = self.positionAfter(pos)
1303 1367
1304 return pos 1368 return pos
1369
1370 elif QSCINTILLA_VERSION() >= 0x020700:
1371 def positionFromLineIndex(self, line, index):
1372 """
1373 Public method to convert line and index to an absolute position.
1374
1375 @param line line number (integer)
1376 @param index index number (integer)
1377 @return absolute position in the editor (integer)
1378 """
1379 pos = self.SendScintilla(QsciScintilla.SCI_POSITIONFROMLINE, line)
1380 return pos + index
1305 1381
1306 if "lineIndexFromPosition" not in QsciScintilla.__dict__: 1382 if "lineIndexFromPosition" not in QsciScintilla.__dict__:
1307 def lineIndexFromPosition(self, pos): 1383 def lineIndexFromPosition(self, pos):
1308 """ 1384 """
1309 Public method to convert an absolute position to line and index. 1385 Public method to convert an absolute position to line and index.
1328 1404
1329 linpos = new_linpos 1405 linpos = new_linpos
1330 indx += 1 1406 indx += 1
1331 1407
1332 return lin, indx 1408 return lin, indx
1409
1410 elif QSCINTILLA_VERSION() >= 0x020700:
1411 def lineIndexFromPosition(self, pos):
1412 """
1413 Public method to convert an absolute position to line and index.
1414
1415 @param pos absolute position in the editor (integer)
1416 @return tuple of line number (integer) and index number (integer)
1417 """
1418 lin = self.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, pos)
1419 linpos = self.SendScintilla(
1420 QsciScintilla.SCI_POSITIONFROMLINE, lin)
1421 return lin, pos - linpos
1333 1422
1334 if "contractedFolds" not in QsciScintilla.__dict__: 1423 if "contractedFolds" not in QsciScintilla.__dict__:
1335 def contractedFolds(self): 1424 def contractedFolds(self):
1336 """ 1425 """
1337 Public method to get a list of line numbers of collapsed folds. 1426 Public method to get a list of line numbers of collapsed folds.

eric ide

mercurial