im doing this in python PTQT i have this code for the filter which is both an activity filter to reset a inactivity timer and a filter to react to the Escape key but its not working.
def __init__(self, parent=None):
super(activityFilter, self).__init__(parent)
self.eventaction = turnOffApp()
self.eventexit = MainDisplay()
def eventFilter(self, obj, event):
if event.
type() == QEvent.
KeyPress and event.
key() == Qt.
Key_Escape: self.eventexit.lockNow()
else:
self.eventaction.reset()
return QObject.
eventFilter(self, obj, event
)
class activityFilter(QObject):
def __init__(self, parent=None):
super(activityFilter, self).__init__(parent)
self.eventaction = turnOffApp()
self.eventexit = MainDisplay()
def eventFilter(self, obj, event):
if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Escape:
self.eventexit.lockNow()
else:
self.eventaction.reset()
return QObject.eventFilter(self, obj, event)
To copy to clipboard, switch view to plain text mode
Then at the bottom of the page i call the main Window an put this filter on it
def main():
app.setOrganizationName("random.")
app.setOrganizationDomain("random")
app.setApplicationName("random")
app.
setWindowIcon(QIcon(":/icon.png"))
filename = os.path.join(os.path.dirname(os.path.dirname(__file__)), "dataCache.db")
create
= not
QFile.
exists(filename
)
db.setDatabaseName(filename)
if not db.open():
QString("Database Error: %1").
arg(db.
lastError().
text())) sys.exit(1)
if create:
createDatabaseData()
app.processEvents()
form = MainWindow()
ef = activityFilter()
form.installEventFilter(ef)
form.show()
app.exec_()
main()
def main():
app = QApplication(sys.argv)
app.setOrganizationName("random.")
app.setOrganizationDomain("random")
app.setApplicationName("random")
app.setWindowIcon(QIcon(":/icon.png"))
filename = os.path.join(os.path.dirname(os.path.dirname(__file__)), "dataCache.db")
create = not QFile.exists(filename)
db = QSqlDatabase.addDatabase("QSQLITE")
db.setDatabaseName(filename)
if not db.open():
QMessageBox.warning(None, "Store Application",
QString("Database Error: %1").arg(db.lastError().text()))
sys.exit(1)
if create:
createDatabaseData()
app.processEvents()
form = MainWindow()
ef = activityFilter()
form.installEventFilter(ef)
form.show()
app.exec_()
main()
To copy to clipboard, switch view to plain text mode
the filter calls to other class functions which are definitely working the problem lies in the filter
Bookmarks