I’m making a similar script like ActiveTypefor maya with PyQt.
Got a problem with my completion, it just shows it every two letters. Of course I want it to display always.
Anyone had the same problem? Any help welcome!
Simple run version:
"""
Execute and type "testing"
"""
import sip
from PyQt4 import QtGui, QtCore
import maya.OpenMayaUI as apiUI
def getMayaWindow():
ptr = apiUI.MQtUtil.mainWindow()
ptr = long(ptr) #Ensure type
return sip.wrapinstance(long(ptr), QtCore.QObject)
class DictionaryCompleter(QtGui.QCompleter):
def __init__(self, parent=None):
QtGui.QCompleter.__init__(self, ["testing1","testing2","testing3"], parent)
class CompletionTextEdit(QtGui.QTextEdit):
def __init__(self, parent=None):
super(CompletionTextEdit, self).__init__(parent)
self.completer = None
self.resize(300, 25)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
def setCompleter(self, completer):
if not completer: return
completer.setWidget(self)
completer.setCompletionMode(QtGui.QCompleter.PopupCompletion)
completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.completer = completer
def textUnderCursor(self):
tc = self.textCursor()
tc.select(QtGui.QTextCursor.WordUnderCursor)
return tc.selectedText()
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Return:
self.close()
return
QtGui.QTextEdit.keyPressEvent(self, event)
completionPrefix = self.textUnderCursor()
if (completionPrefix != self.completer.completionPrefix()):
self.completer.setCompletionPrefix(completionPrefix)
popup = self.completer.popup()
popup.setCurrentIndex(
self.completer.completionModel().index(0,0))
cr = self.cursorRect()
cr.setWidth(self.completer.popup().sizeHintForColumn(0)
+ self.completer.popup().verticalScrollBar().sizeHint().width())
self.completer.complete(cr) ## popup it up!
def mousePressEvent(self, event):
self.close()
class HotboxWidget(QtGui.QDialog):
def __init__(self, parent=getMayaWindow()):
super(HotboxWidget, self).__init__(parent)
self.setWindowFlags(QtCore.Qt.Popup|QtCore.Qt.FramelessWindowHint)
win = HotboxWidget()
completer = DictionaryCompleter()
te = CompletionTextEdit()
te.setCompleter(completer)
te.show()