def outputError(self, error): font = QtGui.QFont() font.setBold(True) lineEdit = SpeakingLineEdit(self.Universe, None)#QtGui.QLineEdit() lineEdit.setText(error) lineEdit.setFont(font) css = """ QLineEdit { background-color: "red"; color: "white"; }""" lineEdit.setStyleSheet(css) return lineEdit
def __init__(self, Universe): QtGui.QMainWindow.__init__(self) self.setWindowTitle("n v c l i") self.resize(600, 600) self.Universe = Universe self.speak_multiple_rows_thread_exit = False self.speak_multiple_rows_thread_running = False self.history_oldstring = "" self.history_old_start_string = "" self.history_counter = 0 #self.mime_list = [] #self.spell = Spell(self.Universe) name = self.Universe.Language.getString("tabwidget") body = SpeakingTableWidget(0, 1, self.Universe, name) self.Universe.Body = body #self.Universe.Body.resizeColumnsToContents() #self.Universe.Body.setColumnWidth( 2, 100) self.Universe.Body.setShowGrid(False) #self.Universe.Body.verticalHeader().hide() self.Universe.Body.horizontalHeader().hide() self.Universe.Body.horizontalHeader().setStretchLastSection(True) # self.charCounter = 0 # self.currentLine = "" #from core_gui.myWidgets import MyLineEdit #self.inputline = MyLineEdit(self) inputline_name = self.Universe.Language.getString("inputline") self.inputline = SpeakingLineEdit(self.Universe, inputline_name) self.Universe.InputLine = self.inputline vkeybd_button = SpeakingPushButton("тМи", self.Universe) inputline_name = self.Universe.Language.getString("vkeybd") vkeybd_button.setName(inputline_name) inputWidget = QtGui.QWidget() inputGridLayout = QtGui.QGridLayout() inputGridLayout.addWidget(self.Universe.InputLine, 0, 0) inputGridLayout.addWidget(vkeybd_button, 0, 1) inputWidget.setLayout(inputGridLayout) self.Universe.Core = self self.outputHandler = OutputHandler(self.Universe) gridLayout = QtGui.QGridLayout() centralWidget = QtGui.QWidget() gridLayout.addWidget(self.Universe.Body, 0, 0) gridLayout.addWidget(inputWidget, 1, 0) #gridLayout.addWidget(vkeybd_button, 1, 1) self.setCentralWidget(centralWidget) centralWidget.setLayout(gridLayout) self.inputline.setFocus() self.interpreter = Interpreter(self.Universe) self.mime_interpreter = MimeInterpreter(self.Universe.SpeakOut) self.connect(self.inputline, QtCore.SIGNAL("returnPressed()"), self.onCILEnterPressed) self.connect(self.Universe.Body, QtCore.SIGNAL("returnPressed()"), self.bodyReturnPressed) # self.connect(self.inputline, QtCore.SIGNAL("editingFinished()"), self.inputlineLostFocus) # self.connect(self.inputline, QtCore.SIGNAL("focusInEvent()"), self.cilFocusIn) self.connect(self.Universe.Body, QtCore.SIGNAL("tabPressedEvent()"), self.bodyTabPressed) self.connect(self.Universe.Body, QtCore.SIGNAL("returnPressedEvent()"), self.bodyReturnPressed) # self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_alt_key_left()"), self.tWKeyLeft) # self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_alt_key_right()"), self.tWKeyRight) # self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_ctrl_key_left()"), self.tWCtrlKeyLeft) # self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_ctrl_key_right()"), self.tWCtrlKeyRight) self.connect(self.inputline, QtCore.SIGNAL("lineEdit_ctrl_key_home()"), self.tWKeyHome) self.connect(self.inputline, QtCore.SIGNAL("lineEdit_ctrl_key_end()"), self.tWKeyEnd) self.connect(self.inputline, QtCore.SIGNAL("lineEdit_ctrl_up()"), self.historyUp) self.connect(self.inputline, QtCore.SIGNAL("lineEdit_ctrl_down()"), self.historyDown) self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_key_home()"), self.tWKeyHome) self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_key_end()"), self.tWKeyEnd) self.connect(vkeybd_button, QtCore.SIGNAL("clicked()"), self.vkeybd)
class CoreWindow(QtGui.QMainWindow): def __init__(self, Universe): QtGui.QMainWindow.__init__(self) self.setWindowTitle("n v c l i") self.resize(600, 600) self.Universe = Universe self.speak_multiple_rows_thread_exit = False self.speak_multiple_rows_thread_running = False self.history_oldstring = "" self.history_old_start_string = "" self.history_counter = 0 #self.mime_list = [] #self.spell = Spell(self.Universe) name = self.Universe.Language.getString("tabwidget") body = SpeakingTableWidget(0, 1, self.Universe, name) self.Universe.Body = body #self.Universe.Body.resizeColumnsToContents() #self.Universe.Body.setColumnWidth( 2, 100) self.Universe.Body.setShowGrid(False) #self.Universe.Body.verticalHeader().hide() self.Universe.Body.horizontalHeader().hide() self.Universe.Body.horizontalHeader().setStretchLastSection(True) # self.charCounter = 0 # self.currentLine = "" #from core_gui.myWidgets import MyLineEdit #self.inputline = MyLineEdit(self) inputline_name = self.Universe.Language.getString("inputline") self.inputline = SpeakingLineEdit(self.Universe, inputline_name) self.Universe.InputLine = self.inputline vkeybd_button = SpeakingPushButton("тМи", self.Universe) inputline_name = self.Universe.Language.getString("vkeybd") vkeybd_button.setName(inputline_name) inputWidget = QtGui.QWidget() inputGridLayout = QtGui.QGridLayout() inputGridLayout.addWidget(self.Universe.InputLine, 0, 0) inputGridLayout.addWidget(vkeybd_button, 0, 1) inputWidget.setLayout(inputGridLayout) self.Universe.Core = self self.outputHandler = OutputHandler(self.Universe) gridLayout = QtGui.QGridLayout() centralWidget = QtGui.QWidget() gridLayout.addWidget(self.Universe.Body, 0, 0) gridLayout.addWidget(inputWidget, 1, 0) #gridLayout.addWidget(vkeybd_button, 1, 1) self.setCentralWidget(centralWidget) centralWidget.setLayout(gridLayout) self.inputline.setFocus() self.interpreter = Interpreter(self.Universe) self.mime_interpreter = MimeInterpreter(self.Universe.SpeakOut) self.connect(self.inputline, QtCore.SIGNAL("returnPressed()"), self.onCILEnterPressed) self.connect(self.Universe.Body, QtCore.SIGNAL("returnPressed()"), self.bodyReturnPressed) # self.connect(self.inputline, QtCore.SIGNAL("editingFinished()"), self.inputlineLostFocus) # self.connect(self.inputline, QtCore.SIGNAL("focusInEvent()"), self.cilFocusIn) self.connect(self.Universe.Body, QtCore.SIGNAL("tabPressedEvent()"), self.bodyTabPressed) self.connect(self.Universe.Body, QtCore.SIGNAL("returnPressedEvent()"), self.bodyReturnPressed) # self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_alt_key_left()"), self.tWKeyLeft) # self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_alt_key_right()"), self.tWKeyRight) # self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_ctrl_key_left()"), self.tWCtrlKeyLeft) # self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_ctrl_key_right()"), self.tWCtrlKeyRight) self.connect(self.inputline, QtCore.SIGNAL("lineEdit_ctrl_key_home()"), self.tWKeyHome) self.connect(self.inputline, QtCore.SIGNAL("lineEdit_ctrl_key_end()"), self.tWKeyEnd) self.connect(self.inputline, QtCore.SIGNAL("lineEdit_ctrl_up()"), self.historyUp) self.connect(self.inputline, QtCore.SIGNAL("lineEdit_ctrl_down()"), self.historyDown) self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_key_home()"), self.tWKeyHome) self.connect(self.Universe.Body, QtCore.SIGNAL("tableWidget_key_end()"), self.tWKeyEnd) self.connect(vkeybd_button, QtCore.SIGNAL("clicked()"), self.vkeybd) def vkeybd(self): self.callTheInterpreter("kbd") def cancelMulitpleRows(self): self.speak_multiple_rows_thread_exit = True def speakMultipleRows(self, start_row, row_count): self.speak_multiple_rows_thread_exit = False i = -1 while i < (row_count - start_row): #for i in range(row_count -start_row): if self.speak_multiple_rows_thread_exit: self.espeakCancel() self.espeak_status = False self.speak_multiple_rows_thread_running = False thread.exit() else: time.sleep(.1) self.espeak_status = self.espeakIsPlaying() if not self.espeak_status: i+=1 #self.Universe.Body.selectRow(start_row + i) self.Universe.Body.setCurrentCell(start_row + i, 0) outline = self.Universe.Body.currentItem().text() self.espeak_status = self.espeakOut( str(outline.toUtf8())) #self.espeak_status = False self.espeak_status = self.espeakIsPlaying() def tWKeyHome(self): #self.Universe.Body.selectRow(self.oldRowCount) self.Universe.Body.selectRow(self.outputHandler.oldRowCount) def tWKeyEnd(self): row_count = self.Universe.Body.rowCount() self.Universe.Body.selectRow(row_count -1 ) def historyHelper(self, index): input = str( self.inputline.text().toUtf8() ) if self.history_old_start_string != input: self.history_old_start_string = input result = self.Universe.History.history(index, input) self.inputline.clear() self.inputline.setText( result.decode("utf8") ) self.Universe.SpeakOut.synthCancel() self.Universe.SpeakOut.synthOut(result) def historyUp(self): try: self.historyHelper(self.history_counter + 1) self.history_counter +=1 except IndexError: self.Universe.SpeakOut.synthOut(self.Universe.Language.getString("end")) self.inputline.clear() def historyDown(self): if self.history_counter > 0: self.history_counter -= 1 self.historyHelper(self.history_counter) def callTheInterpreter(self, input_value): try: returnvalue, line = self.interpreter.interpreter(input_value) except NoReturnValue: self.Universe.InputLine.clear() else: self.outputHandler.handleReturnValue(input_value, returnvalue, line) def onCILEnterPressed(self): self.history_counter = 0 self.history_old_start_string = "" #self.oldRowCount = self.Universe.Body.rowCount() self.speak_multiple_rows_thread_exit = True input_value = self.inputline.text() self.Universe.History.historyWrite(str(input_value.toUtf8())) current_index = self.Universe.TabWidget.currentIndex() self.Universe.TabWidget.setTabText(current_index, unicode(input_value.toUtf8())) self.callTheInterpreter( input_value.toUtf8().data().decode("utf8") ) self.inputline.clear() def subTableTabPressed(self): self.Universe.Body.setFocus() # def currentCellChanged(self): # outline = self.Universe.Body.currentItem().text() # # self.currentLine = str(outline.toUtf8()) # self.charCounter = -1 # # self.espeakOut(str(outline.toUtf8())) def keyPressEvent(self, e): if e.key() == QtCore.Qt.Key_Escape: self.inputline.setFocus() elif e.key() == QtCore.Qt.Key_Space: self.espeakOut("leerzeichen") elif e.key() == QtCore.Qt.Key_Up: self.cancelMulitpleRows() #self.espeakCancel() #self.speak_multiple_rows_thread_exit = True #time.sleep(.1) self.Universe.Body.keyPressEvent(e) elif e.key() == QtCore.Qt.Key_Down: self.cancelMulitpleRows() #self.espeakCancel() #self.speak_multiple_rows_thread_exit = True #time.sleep(.1) self.Universe.Body.keyPressEvent(e) elif e.key() == QtCore.Qt.Key_PageUp: self.Universe.Body.keyPressEvent(e) elif e.key() == QtCore.Qt.Key_PageDown: self.Universe.Body.keyPressEvent(e) elif e.key() == QtCore.Qt.Key_F3: self.speak_multiple_rows_thread_exit = True self.espeakCancel() #elif e.key() == QtCore.Qt.Key_F2: # print self.inputline.cursorPosition() # print self.inputline.end(False) elif e.key() == QtCore.Qt.Key_F9: if not self.speak_multiple_rows_thread_running: current_row = self.Universe.Body.currentRow() row_count = self.Universe.Body.rowCount() self.espeak_status = self.espeakIsPlaying() if self.espeak_status: current_row = current_row +1 else: pass thread.start_new_thread(self.speakMultipleRows, (current_row, row_count-1)) self.speak_multiple_rows_thread_running = True elif e.key() == QtCore.Qt.Key_F10: #self.outputLine(self.mime_list) desc = self.Universe.Body.getDescriptionList() print len(desc) for i in range(len(desc)-1): print i+1, desc[i][0].ExecuteCommand, desc[i][0].Language def bodyTabPressed(self): #print "change FOCUS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" self.inputline.setFocus() def bodyReturnPressed(self): current_row = self.Universe.Body.row( self.Universe.Body.currentItem() ) current_description = self.Universe.Body.getDescription(current_row, 0) #current_text = str(self.Universe.Body.currentItem().text().toUtf8()) current_text = str(self.Universe.Body.currentItem().text()) #print "current description:", current_description try: print "current meta data Language:", current_description.Language, "ExecuteCommand:", current_description.ExecuteCommand, "CurrentRow:", current_row except: print "NO META DATA OBJECT" #result_string = self.mime_interpreter.mimeInterpreter(self.Universe.Body, current_row, current_description, current_text) #if result_string == "msg/unknown": # self.espeakOut(self.Universe.Language.getString("type_unknown")) #else: # self.callTheInterpreter(result_string) # pass command = current_description.ExecuteCommand if command != None: if command == "%CONTENT%": print "fffffffffffffffffffffffffff IF" print "CALLING COMMAND: ", current_text self.callTheInterpreter(current_text) else: print "eeeeeeeeeeeeeeeeeeeeeeeeeeeee ELSE" command = command.replace("%CONTENT%", current_text) print "CALLING COMMAND: ", command self.callTheInterpreter(command)# + " " + current_text) else: self.espeakOut(self.Universe.Language.getString("type_unknown")) def espeakOut(self, string): self.espeakCancel() return self.Universe.SpeakOut.synthOut(string) def espeakCancel(self): self.Universe.SpeakOut.synthCancel() # void -> boolean def espeakIsPlaying(self): return self.Universe.SpeakOut.isPlaying()