#!/usr/bin/env python #**************************************************************************** # tmpmultiedit.py, provides a qt2 extended text editor that signals focus loss # # Copyright (C) 2002, Douglas W. Bell # # This is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License, Version 2. This program is # distributed in the hope that it will be useful, but WITTHOUT ANY WARRANTY. #***************************************************************************** from qt import * class TmpTextEdit(QMultiLineEdit): """Gives temporary multi-line editor, signals focus loss & return key""" def __init__(self, text, parent=None, name=None): QMultiLineEdit.__init__(self, parent, name) self.setText(text) self.active = 1 self.origText = text def focusOutEvent(self, event): """Signals to end editing if focus shifts""" QMultiLineEdit.focusOutEvent(self, event) if self.active: self.active = 0 # one signal only self.emit(PYSIGNAL('editDone'), ()) def keyPressEvent(self, event): """Signals return key press""" if event.key() in (Qt.Key_Return, Qt.Key_Enter): if self.active and self.numLines() == self.maxLines(): self.active = 0 # one signal only self.emit(PYSIGNAL('editDone'), ()) else: QMultiLineEdit.keyPressEvent(self, event) elif event.key() in (Qt.Key_Tab, Qt.Key_Escape): if self.active: if event.key() == Qt.Key_Escape: self.setText(self.origText) self.active = 0 # one signal only self.emit(PYSIGNAL('editDone'), ()) else: QMultiLineEdit.keyPressEvent(self, event)