MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / AddressBookCompleter

Class AddressBookCompleter

src/bitmessageqt/foldertree.py:495–546  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493 self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
494
495class AddressBookCompleter(QtGui.QCompleter):
496 def __init__(self):
497 super(QtGui.QCompleter, self).__init__()
498 self.cursorPos = -1
499
500 def onCursorPositionChanged(self, oldPos, newPos):
501 if oldPos != self.cursorPos:
502 self.cursorPos = -1
503
504 def splitPath(self, path):
505 stringList = []
506 text = unicode(path.toUtf8(), encoding="UTF-8")
507 splitIndex = rfind(text[0:self.widget().cursorPosition()], ";") + 1
508 str = text[splitIndex:self.widget().cursorPosition()]
509 str = rstrip(lstrip(str))
510 stringList.append(str)
511 return stringList
512
513 def pathFromIndex(self, index):
514 autoString = unicode(index.data(QtCore.Qt.EditRole).toString().toUtf8(), encoding="UTF-8")
515 text = unicode(self.widget().text().toUtf8(), encoding="UTF-8")
516
517 # If cursor position was saved, restore it, else save it
518 if self.cursorPos != -1:
519 self.widget().setCursorPosition(self.cursorPos)
520 else:
521 self.cursorPos = self.widget().cursorPosition()
522
523 # Get current prosition
524 curIndex = self.widget().cursorPosition()
525
526 # prev_delimiter_index should actually point at final white space AFTER the delimiter
527 # Get index of last delimiter before current position
528 prevDelimiterIndex = rfind(text[0:curIndex], ";")
529 while text[prevDelimiterIndex + 1] == " ":
530 prevDelimiterIndex += 1
531
532 # Get index of first delimiter after current position (or EOL if no delimiter after cursor)
533 nextDelimiterIndex = find(text, ";", curIndex)
534 if nextDelimiterIndex == -1:
535 nextDelimiterIndex = len(text)
536
537 # Get part of string that occurs before cursor
538 part1 = text[0:prevDelimiterIndex + 1]
539
540 # Get string value from before auto finished string is selected
541 pre = text[prevDelimiterIndex + 1:curIndex - 1];
542
543 # Get part of string that occurs AFTER cursor
544 part2 = text[nextDelimiterIndex:]
545
546 return part1 + autoString + part2;

Callers 1

setupUiMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected