def act(self): if self.cmd == 'exit': self._teardown_plugins() self.client.stop() QApplication.quit() if self.cmd in self.plugins: self.plugins[self.cmd].act()
def eventFilter(self, o, e): if e.type() == QEvent.KeyPress: if e.key() == Qt.Key_Tab or e.key() == Qt.Key_J and e.modifiers() & Qt.ControlModifier: ne = QKeyEvent( QEvent.KeyPress, Qt.Key_Down, e.modifiers(), '' ) QApplication.sendEvent(o, ne) return True elif e.key() == Qt.Key_Tab or e.key() == Qt.Key_K and e.modifiers() & Qt.ControlModifier: ne = QKeyEvent( QEvent.KeyPress, Qt.Key_Up, e.modifiers(), e.text(), e.isAutoRepeat(), e.count() ) QApplication.sendEvent(o, ne) return True elif e.key() == Qt.Key_Up and self.attop: ne = QKeyEvent( QEvent.KeyPress, Qt.Key_End, Qt.ControlModifier ) QApplication.sendEvent(o, ne) return True elif e.key() == Qt.Key_Down and self.atbottom: ne = QKeyEvent( QEvent.KeyPress, Qt.Key_Home, Qt.ControlModifier ) QApplication.sendEvent(o, ne) return True return self.super.eventFilter(o, e)
if __name__ == '__main__': logging.basicConfig( filename=os.path.expanduser('~/.lit.log'), filemode='w', format='%(asctime)s - %(levelname)s - %(message)s', level=logging.DEBUG ) client = None try: start_server() import sys argv = sys.argv app = QApplication(argv) STYLESHEET = 'style.css' set_app_info(app, 'lit') app.setQuitOnLastWindowClosed(False) # style with open(STYLESHEET, 'r') as f: app.setStyleSheet(f.read()) worker = Worker() from client import Client client = Client() QMetaObject.invokeMethod( client, 'start',
def _move_to_center(self): desktop = QApplication.desktop() self.move( (desktop.width() - self.width()) // 2, (desktop.height() - self.height()) // 2 )
def eventFilter(self, o, e): #if e.type() == QEvent.MouseButtonPress: ##self.popup.hide() #self.editor.setFocus() #return True if o == self.popup: if not self.popup.underMouse() and e.type() in ( QEvent.MouseButtonPress, #QEvent.MouseButtonRelease, #QEvent.MouseButtonDblClick, #QEvent.MouseMove ): self.popup.hide() #self.editor.setFocus() #QApplication.sendEvent(self.editor, e) return False elif e.type() == QEvent.KeyPress: key = e.key() if e.key() == Qt.Key_Tab or e.key() == Qt.Key_J and e.modifiers() & Qt.ControlModifier: ne = QKeyEvent( QEvent.KeyPress, Qt.Key_Down, e.modifiers(), '' ) QApplication.sendEvent(o, ne) return True elif e.key() == Qt.Key_Tab or e.key() == Qt.Key_K and e.modifiers() & Qt.ControlModifier: ne = QKeyEvent( QEvent.KeyPress, Qt.Key_Up, e.modifiers(), e.text(), e.isAutoRepeat(), e.count() ) QApplication.sendEvent(o, ne) return True elif e.key() == Qt.Key_Up and self.attop: ne = QKeyEvent( QEvent.KeyPress, Qt.Key_End, Qt.ControlModifier ) QApplication.sendEvent(o, ne) return True elif e.key() == Qt.Key_Down and self.atbottom: ne = QKeyEvent( QEvent.KeyPress, Qt.Key_Home, Qt.ControlModifier ) QApplication.sendEvent(o, ne) return True elif key in (Qt.Key_Enter, Qt.Key_Return): self.done(self.popup.currentIndex()) return True #elif key in (Qt.Key_Escape, ): #self.editor.setFocus() #self.popup.hide() #return True #elif key in ( #Qt.Key_Home, #Qt.Key_End, #): #QApplication.sendEvent(self.editor, e) #return True #elif key in ( #Qt.Key_Up, #Qt.Key_Down, #Qt.Key_Home, #Qt.Key_End, #Qt.Key_PageUp, #Qt.Key_PageDown #): #pass else: #self.editor.setFocus() #self.editor.event(e) #TODO: why HOME and END not processed by editor? QApplication.sendEvent(self.editor, e) #self.popup.hide() return self.super.eventFilter(o, e)