def __init__(self, dialog): cls() Ui_Dialog.__init__(self) self.setupUi(dialog) dialog.setWindowTitle("Password generator by Griba") self.checkBox_1.setText(strings(65, 65 + 26)) # string.ascii_letters self.checkBox_2.setText(strings(97, 97 + 26)) # string.ascii_letters self.checkBox_3.setText(strings(48, 48 + 10)) # string.digits self.checkBox_4.setText(strings(33, 33 + 15)) # string.punctuation self.checkBox_5.setText(strings(58, 58 + 7)) # string.punctuation self.lineEdit_1.setText("8") self.lineEdit_2.setText("5") self.pushButton_1.clicked.connect(self.generate) self.pushButton_3.clicked.connect(self.txtbr_cls) self.pushButton_4.clicked.connect(self.copy) self.lineEdit_1.textEdited.connect(self.edit_colors) self.lineEdit_2.textEdited.connect(self.edit_colors) #checkBox_1.stateChanged.connect(self.check) for i in range(1, 6): getattr(self, "checkBox_" + str(i)).stateChanged.connect(self.check)
class mainWindow(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Dialog() self.ui.setupUi(self) # Set your serial Port/Baudrate/time between two value changes(in second) Here. self.device = copter('/dev/ttyUSB0', 19200, 0) #def event(self, event): #print event.type() #if (event.type()==QtCore.QEvent.KeyPress) and (event.key()==QtCore.Qt.Key_Tab): #self.emit(QtCore.SIGNAL("tabPressed")) #return True #QtCore.QObject.connect(self.ui.verticalSlider, QtCore.SIGNAL("sliderMoved(int)"), self.adjust_rotor) #QtCore.QObject.connect(self.ui.verticalSlider, QtCore.SIGNAL("valueChanged(int)"), self.adjust_rotor) QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), QtCore.QCoreApplication.instance().quit) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("leftPressed"), lambda: self.device.adjust_direction('x', '-')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("rightPressed"), lambda: self.device.adjust_direction('x', '+')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("downPressed"), lambda: self.device.adjust_direction('y', '-')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("upPressed"), lambda: self.device.adjust_direction('y', '+')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("rotorUp"), lambda: self.device.adjust_rotor('+')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("rotorDown"), lambda: self.device.adjust_rotor('-')) QtCore.QObject.connect(self.ui.dial, QtCore.SIGNAL("directionReleased"), self.device.init_direction) def adjust_rotor(self, value): self.ui.label_2.setText(str(value)) self.device.adjust_rotor(value)
def __init__(self): super(SuperUIForm, self).__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.searchmode_w.toggled.connect(self.__searchMode) self.ui.searchmode_c.toggled.connect(self.__searchMode) self.ui.headsel.toggled.connect(self.__sel_HeadChar) self.ui.tailsel.toggled.connect(self.__sel_TailChar) self.ui.lengthsel.toggled.connect(self.__sel_SoliLen) self.ui.headchar_in.textChanged.connect(self.__set_HeadChar) self.ui.tailchar_in.textChanged.connect(self.__set_TailChar) self.ui.length_in.textChanged.connect(self.__set_SoliLen) self.ui.search_Button.clicked.connect(self.__click_search) self.ui.address_input.textChanged.connect(self.__set_Path) self.ui.byHand.toggled.connect(self.__inputMode) self.ui.byFile.toggled.connect(self.__inputMode) self.ui.export_Button.clicked.connect(self.__export_result) self.__wsearch = False self.__csearch = False self.__set_headchar = False self.__set_tailchar = False self.__set_solilen = False self.__inputbyhand = False self.__inputbyfile = False self.__filepath = '' self.__headchar = '' self.__tailchar = '' self.__solilen = 0 self.__rawlist = [] self.__result = [] self.__core = Core()
def __init__(self): super(Ui, self).__init__() self.cypher = NumberplateCypher() self.ui = Ui_Dialog() self.ui.setupUi(self) self.setWindowTitle(f"Number Plate Anonymiser v{__version__}") self.encrypt_button = self.findChild(QtWidgets.QPushButton, "encrypt_button") self.encrypt_button.clicked.connect( self.encrypt ) # Remember to pass the definition/method, not the return value! self.refresh_button = self.findChild(QtWidgets.QPushButton, "refresh_button") self.refresh_button.clicked.connect(self.refresh) self.refresh_button = self.findChild(QtWidgets.QPushButton, "copy_button") self.refresh_button.clicked.connect(self.copy_output) self.input = self.findChild(QtWidgets.QPlainTextEdit, "plate_no_box") self.output = self.findChild(QtWidgets.QPlainTextEdit, "results_window") self.output.setReadOnly(True) self.show() # Show the GUI
def __init__(self): QtGui.QMainWindow.__init__(self) self.ui = Ui_Dialog() self.ui.setupUi(self) #SD Card Management self.ui.btnCardLocation.clicked.connect(self.btnCardLocation_Clicked) self.ui.btnMIDILocation.clicked.connect(self.btnMIDILocation_Clicked) self.ui.btnUpload.clicked.connect(self.btnUpload_Clicked) self.ui.checkMIDI.toggled.connect(self.checkMidi_Checked) self.ui.tabFileType.activated.connect(self.FileType) self.ui.selectInstrument.activated.connect(self.selectInstrument) #Orchestra Settings self.ui.btnPlay.clicked.connect(self.btnPlay_Clicked) self.ui.btnStop.clicked.connect(self.btnStop_Clicked) self.ui.checKeyboard.toggled.connect(self.checkKeyboard_Checked) self.ui.checkStepper.toggled.connect(self.checkStepper_Checked) self.ui.checkTesla.toggled.connect(self.checkTesla_Checked) self.ui.checkXylophone.toggled.connect(self.checkXylophone_Checked) self.ui.checkAll.toggled.connect(self.checkAll_Checked) shelfFile = shelve.open('GUIconfig') if (not '__SONGS__' in shelfFile.keys()): shelfFile['__SONGS__'] = {} __SONGS_temp_ = shelfFile['__SONGS__'] shelfFile.close() self.ui.SelectSong.clear() self.ui.SelectSong.addItems(list(__SONGS_temp_.keys())) #executes when box is clicked self.ui.SelectSong.activated.connect(self.SongSelection)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.train_btn.clicked.connect(self.Train) #self.ui.BrowseFile_btn.clicked.connect(self.selectFile) self.ui.predict_btn.clicked.connect(self.Test)
class Ui(QtWidgets.QDialog): def __init__(self): super(Ui, self).__init__() self.cypher = NumberplateCypher() self.ui = Ui_Dialog() self.ui.setupUi(self) self.setWindowTitle(f"Number Plate Anonymiser v{__version__}") self.encrypt_button = self.findChild(QtWidgets.QPushButton, "encrypt_button") self.encrypt_button.clicked.connect( self.encrypt ) # Remember to pass the definition/method, not the return value! self.refresh_button = self.findChild(QtWidgets.QPushButton, "refresh_button") self.refresh_button.clicked.connect(self.refresh) self.refresh_button = self.findChild(QtWidgets.QPushButton, "copy_button") self.refresh_button.clicked.connect(self.copy_output) self.input = self.findChild(QtWidgets.QPlainTextEdit, "plate_no_box") self.output = self.findChild(QtWidgets.QPlainTextEdit, "results_window") self.output.setReadOnly(True) self.show() # Show the GUI def encrypt(self): plates = self.input.toPlainText().splitlines() anonymised = "\n".join( [self.cypher.anonymise(plate) for plate in plates]) self.output.clear() self.output.insertPlainText(anonymised) self.copy_output() def copy_output(self): pyperclip.copy(self.output.toPlainText()) messagebox.showinfo("Copy complete!", "Output copied to clipboard", parent=parent) def refresh(self): okcancel = messagebox.askokcancel( "Refresh Cypher", "Are you sure you want to refresh the cypher?", parent=parent, ) # OK / Cancel if okcancel: self.cypher.randomise_cyphers() self.output.setText("") self.input.setText("")
def __init__(self,parent=None): QtGui.QWidget.__init__(self, parent) ui = Ui_Dialog() ui.setupUi(self) ui.EncryptButton.clicked.connect(partial(self.handleEncryptButton,ui)) ui.DecryptButton.clicked.connect(partial(self.handleDecryptButton,ui)) ui.Text_Go_Btn.clicked.connect(partial(self.handleText_GO_BTN,ui)) ui.Sel_File_Btn.clicked.connect(partial(self.set_filePath,ui)) ui.File_Go_Btn.clicked.connect(partial(self.handleFile_GO_BTN,ui)) ui.lineEdit_6.setText("0000000000000000") ui.comboBox.currentIndexChanged.connect(partial(self.vectordeactivate,ui)) ui.AlgoBox.currentIndexChanged.connect(partial(self.changeLabels,ui)) ui.KCVButton.clicked.connect(partial(self.KCVOnly,ui)) ui.Check_Parity_BTN.clicked.connect(partial(self.checkParity,ui)) ui.COMP_PArity_Btn.clicked.connect(partial(self.computeParity,ui))
def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.show() self.ui.mainBtn.clicked.connect(self.polacz) self.ui.btn1.clicked.connect(self.graj) self.ui.btn2.clicked.connect(self.graj) self.ui.btn3.clicked.connect(self.graj) self.ui.btn4.clicked.connect(self.graj) self.ui.btn5.clicked.connect(self.graj) self.ui.btn6.clicked.connect(self.graj) self.ui.btn7.clicked.connect(self.graj) self.ui.btn8.clicked.connect(self.graj) self.ui.btn9.clicked.connect(self.graj)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.btnSend.clicked.connect(self.sendClicked) self.ui.btnRefresh.clicked.connect(self.refreshClients) self.ui.btnRefresh.setIcon(QtGui.QIcon(QtGui.QPixmap('refresh.png'))) self.ui.lblStatus.setVisible(False)
class StartQT4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.btnSend.clicked.connect(self.sendClicked) self.ui.btnRefresh.clicked.connect(self.refreshClients) self.ui.btnRefresh.setIcon(QtGui.QIcon(QtGui.QPixmap('refresh.png'))) self.ui.lblStatus.setVisible(False) def sendClicked(self): msg = self.ui.txtMessage.text() client = self.ui.cmbNodes.currentText() print 'client', client print self.ui.cmbNodes.currentText() msg = str(client).lstrip("'").rstrip("'")+"$"+str(msg) print msg s.send(msg) def refreshClients(self): global socketLock while(socketLock): print socketLock sleep(0.5) a=1 socketLock = True s.send("LIST") data = s.recv(BUFFER_SIZE) socketLock = False print data[0:4].lstrip("['").rstrip("']") if(data[0:4].lstrip("['").rstrip("']") == "LIST"): self.ui.cmbNodes.clear() for i in data.split('$')[1:]: self.ui.cmbNodes.addItem(i)
def __init__(self, dialog): super(Main, self).__init__(dialog) Ui_Dialog.__init__(self) self.log = logger_win32.Log( ) # log input events and active window title self.unit_multiplier = 1 self.unit_multiplier_minutes = 60 self.progDir = os.path.dirname(os.path.realpath(__file__)) self.pm_is_working = False self.pm_qtimer = QtCore.QTimer(self) self.pm_qtimer.timeout.connect(self.pm_timer_display_timeout) self.pm_secs_left_int = 0 self.setupUi(dialog) self.icon = QtGui.QIcon( os.path.join(self.progDir + os.path.sep + 'ic.png')) self.menu = QtWidgets.QMenu() self.createInterface()
# modals from PyQt5 import QtGui, QtWidgets from PyQt5.QtWidgets import QMessageBox from gui import Ui_Dialog import sys # application app = QtWidgets.QApplication(sys.argv) # Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) Dialog.show() def introduction(): ''' Hello there! To create formulas for tests you have to go 205 line. Please keep track of data types. Then you will already ready to put answer in box, you have to change data type to STR. For example: ui.textEdit.setText(str(int(a+b)) + " this answer " + " :^) ") ''' class control_the_programm(): ''' To avoid errors, don't change the structure of the programme.
def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.show()
class AppWindow(QDialog): def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.show()
class MyDialog(QDialog): def __init__(self, parent=None): QWidget.__init__(self, parent) self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.train_btn.clicked.connect(self.Train) #self.ui.BrowseFile_btn.clicked.connect(self.selectFile) self.ui.predict_btn.clicked.connect(self.Test) def Train(self): train.runscript() def Test(self): result_string = "" mresult_string = "" with open("test_files.txt", "r") as fp3: test_files = joblib.load(fp3) print "metadata model testing" for x in users: filename = x + "model.pkl" metamodel[x] = joblib.load(filename) test_data = pd.read_csv('test_data.csv') with open("features1.txt", "r") as fp: features1 = pickle.load(fp) x_metatest = test_data[list(features1)].values for x in users: print x meta_prediction.append(metamodel[x].predict(x_metatest)) print metamodel[x].predict(x_metatest) mmodel.append(metamodel[x].predict(x_metatest)) for y in range(len(test_files)): mresult = "File " + test_files[y] + " is recommended to " for z in range(len(users)): if mmodel[z][y] == 1: mresult += users[z] mresult += ", " mresult_string += mresult mresult_string += "\n" #cf_prediction.append(cfmodel[x].predict(x_cftest)) #print cf_prediction #self.ui.result.setText(mresult_string) print mresult_string print "collaboration model testing" with open("features2.txt", "r") as fp: features2 = pickle.load(fp) for x in users: filename = x + "cfmodel.pkl" cfmodel[x] = joblib.load(filename) test_data2 = pd.read_csv('test_data2.csv') x_cftest = test_data2[list(features2)].values for x in users: print x print cfmodel[x].predict(x_cftest) model.append(cfmodel[x].predict(x_cftest)) for y in range(len(test_files)): result = "File " + test_files[y] + " is recommended to " for z in range(len(users)): if model[z][y] == 1: result += users[z] result += ", " result_string += result result_string += "\n" #cf_prediction.append(cfmodel[x].predict(x_cftest)) #print cf_prediction self.ui.result.setText(result_string) print result_string print "finished testing"
class SuperUIForm(QWidget): def __init__(self): super(SuperUIForm, self).__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.ui.searchmode_w.toggled.connect(self.__searchMode) self.ui.searchmode_c.toggled.connect(self.__searchMode) self.ui.headsel.toggled.connect(self.__sel_HeadChar) self.ui.tailsel.toggled.connect(self.__sel_TailChar) self.ui.lengthsel.toggled.connect(self.__sel_SoliLen) self.ui.headchar_in.textChanged.connect(self.__set_HeadChar) self.ui.tailchar_in.textChanged.connect(self.__set_TailChar) self.ui.length_in.textChanged.connect(self.__set_SoliLen) self.ui.search_Button.clicked.connect(self.__click_search) self.ui.address_input.textChanged.connect(self.__set_Path) self.ui.byHand.toggled.connect(self.__inputMode) self.ui.byFile.toggled.connect(self.__inputMode) self.ui.export_Button.clicked.connect(self.__export_result) self.__wsearch = False self.__csearch = False self.__set_headchar = False self.__set_tailchar = False self.__set_solilen = False self.__inputbyhand = False self.__inputbyfile = False self.__filepath = '' self.__headchar = '' self.__tailchar = '' self.__solilen = 0 self.__rawlist = [] self.__result = [] self.__core = Core() def __clear(self): self.__rawlist.clear() self.__result.clear() return def __click_search(self): self.__clear() if not self.__wsearch and not self.__csearch: self.__prompt_warning( _Main='Illegal running parameter!', _Detail='A type of search mode must be selected!') return if not self.__inputbyfile and not self.__inputbyhand: self.__prompt_warning( _Main='Missing input Method!', _Detail='A type of input method must be selected!') return if self.__set_headchar and (not self.__headchar.isalpha() or len(self.__headchar) != 1): self.__prompt_warning( _Main='Illegal head character!', _Detail= 'The assigned head of the chain must be a single alphabet!') return if self.__set_tailchar and (not self.__tailchar.isalpha() or len(self.__tailchar) != 1): self.__prompt_warning( _Main='Illegal tail character!', _Detail= 'The assigned tail of the chain must be a single alphabet!') return if self.__set_solilen and self.__solilen <= 1: self.__prompt_warning( _Main='IIlegal input number!', _Detail='The assigned length of the chain must be above 1!') return if self.__inputbyfile: self.__set_Path() go_on, self.__rawlist = self.__read_file(self.__filepath) if not go_on: return elif self.__inputbyhand: buffer = self.ui.inputarea.toPlainText() is_reading = False tmp_word = '' for char in buffer: if char.isalpha(): is_reading = True tmp_word += char.lower() elif is_reading: is_reading = False if not tmp_word in self.__rawlist: self.__rawlist.append(tmp_word) tmp_word = '' try: self.__chain_search() self.__print_result() except inputError as error: msgbox = QMessageBox() msgbox.setWindowTitle("Error!") msgbox.setIcon(QMessageBox.Critical) msgbox.setText("Input error for core detected!") msgbox.setInformativeText(error.msg) msgbox.setStandardButtons(QMessageBox.Ok) msgbox.setDefaultButton(QMessageBox.Ok) msgbox.exec() except syntaxError as error: msgbox = QMessageBox() msgbox.setWindowTitle("Error!") msgbox.setIcon(QMessageBox.Critical) msgbox.setText("Syntax error for core detected!") msgbox.setInformativeText(error.msg) msgbox.setStandardButtons(QMessageBox.Ok) msgbox.setDefaultButton(QMessageBox.Ok) msgbox.exec() except runtimeError as error: msgbox = QMessageBox() msgbox.setWindowTitle("Error!") msgbox.setIcon(QMessageBox.Critical) msgbox.setText(error.msg) msgbox.setInformativeText(error.detail) msgbox.setStandardButtons(QMessageBox.Ok) msgbox.setDefaultButton(QMessageBox.Ok) msgbox.exec() return def __export_result(self): outfilepath = self.ui.result_output.text() try: outfile = open(outfilepath, 'w+') outfile.write(self.ui.outputarea.toPlainText()) except IOError: msg = QMessageBox() msg.setWindowTitle("Error") msg.setIcon(QMessageBox.Critical) msg.setText("Export Error!") msg.setInformativeText("Cannot write to this file!") msg.setStandardButtons(QMessageBox.Ok) msg.setDefaultButton(QMessageBox.Ok) return msg.exec() finally: outfile.close() def __read_file(self, _filename): if _filename[0] != '/' and _filename[0:2] != './': msg = QMessageBox() msg.setWindowTitle("Warning") msg.setText("Non absolute address detected!") msg.setInformativeText( "Click \"Ok\" to continue the search on current directory or \"Cancel\" to re-enter the address." ) msg.setIcon(QMessageBox.Warning) msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) msg.setDefaultButton(QMessageBox.Ok) go_on = msg.exec() if go_on == QMessageBox.Cancel: return False, [] else: _filename = "./" + _filename try: in_file = open(_filename, 'r') is_reading = False tmpword = '' wordlist = [] while True: tmpchar = in_file.read(1) if tmpchar == '': break elif tmpchar.isalpha(): is_reading = True tmpword += tmpchar.lower() elif is_reading: is_reading = False if not tmpword in wordlist: wordlist.append(tmpword) tmpword = '' in_file.close() return True, wordlist except IOError: self.__prompt_warning( _Main="File operation error!", _Detail="Cannot open file! Please check the address.") return False, [] def __chain_search(self): if not self.__set_solilen: if self.__csearch: self.__core.chain_char(self.__rawlist, self.__headchar, self.__tailchar) self.__result = self.__core.get_result() elif self.__wsearch: self.__core.chain_word(self.__rawlist, self.__headchar, self.__tailchar) self.__result = self.__core.get_result() else: self.__core.chain_num(self.__rawlist, self.__headchar, self.__tailchar, self.__solilen, self.__wsearch) self.__result = self.__core.get_result() def __print_result(self): self.ui.outputarea.clear() if not self.__solilen: if len(self.__result) == 1 and self.__result[0].wordcnt == 0: self.ui.outputarea.setText( "There isn't a solitaire that matches the input requirements." ) else: print_chain = self.__result[0] self.ui.outputarea.setText( "-----------------------------------") if print_chain.wordcnt >= 1: self.ui.outputarea.append( "The length of this solitaire is %d." % print_chain.wordcnt) else: self.ui.outputarea.append("The solitaire is empty.") if print_chain.charcnt == 1: self.ui.outputarea.append( "There is only one character in the solitaire.") else: self.ui.outputarea.append( "There are %d characters in the solitaire.\n" % print_chain.charcnt) for word in print_chain.searchchain: self.ui.outputarea.append(word.member.word()) else: if len(self.__result) == 1 and self.__result[0].wordcnt == 0: self.ui.outputarea.setText( "There isn't a solitaire that matches the input requirements." ) else: self.ui.outputarea.setText("Total solitaire number: %d" % len(self.__result)) for i, print_chain in enumerate(self.__result): self.ui.outputarea.append( "-----------------------------------") self.ui.outputarea.append("No: %d" % (i + 1)) if print_chain.wordcnt >= 1: self.ui.outputarea.append( "The length of this solitaire is %d." % print_chain.wordcnt) else: self.ui.outputarea.append("The solitaire is empty.") if print_chain.charcnt == 1: self.ui.outputarea.append( "There is only one character in the solitaire.") else: self.ui.outputarea.append( "There are %d characters in the solitaire.\n" % print_chain.charcnt) for word in print_chain.searchchain: self.ui.outputarea.append(word.member.word()) self.ui.outputarea.append('\n') return def __prompt_warning(self, _Title="Warning", _Main='', _Detail=''): msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setWindowTitle(_Title) msg.setText(_Main) msg.setInformativeText(_Detail) msg.setStandardButtons(QMessageBox.Ok) msg.setDefaultButton(QMessageBox.Ok) return msg.exec() def __set_Path(self): self.__filepath = self.ui.address_input.text() def __searchMode(self): self.__wsearch = self.ui.searchmode_w.isChecked() self.__csearch = not self.__wsearch def __sel_HeadChar(self): self.__set_headchar = self.ui.headsel.isChecked() def __set_HeadChar(self): self.__headchar = self.ui.headchar_in.text() def __sel_TailChar(self): self.__set_tailchar = self.ui.tailsel.isChecked() def __set_TailChar(self): self.__tailchar = self.ui.tailchar_in.text() def __sel_SoliLen(self): self.__set_solilen = self.ui.lengthsel.isChecked() def __set_SoliLen(self): inputtmp = self.ui.length_in.text() if inputtmp.isdigit(): self.__solilen = int(inputtmp) else: self.__solilen = 0 def __inputMode(self): self.__inputbyhand = self.ui.byHand.isChecked() self.__inputbyfile = not self.__inputbyhand
class Main(QtGui.QDialog): def SongSelection(self): print("select song") os.chdir(pathToMain) shelfFile = shelve.open('GUIconfig') __SONGS_temp_ = shelfFile['__SONGS__'] try: settings[6] = __SONGS_temp_[self.ui.SelectSong.currentText()] except Exception: pass shelfFile.close() def btnCardLocation_Clicked(self): try: savePath = str(QFileDialog.getSaveFileName(self, "Save as")) tempPath = savePath if len(savePath ) > 8: #teensy requires names of less than 8 characters savePath = os.path.join(os.path.dirname(savePath), os.path.basename(savePath)[:8]) __SONGS_temp_ = { os.path.basename(tempPath): os.path.basename(savePath) } settings[0] = savePath if not os.path.exists(settings[0]): os.makedirs(settings[0]) shelfFile = shelve.open('GUIconfig') if (not '__SONGS__' in shelfFile.keys()): shelfFile['__SONGS__'] = {} __SONGS_temp_2 = shelfFile['__SONGS__'] if not list(__SONGS_temp_.keys())[0] in list( __SONGS_temp_2.keys()): __SONGS_temp_2.update(__SONGS_temp_) shelfFile['__SONGS__'] = __SONGS_temp_2 self.ui.SelectSong.addItems(list(__SONGS_temp_.keys())) else: pass # print("key exists not adding") shelfFile.close() self.ui.lineEdit.setText(os.path.basename(tempPath)) except Exception as e: pass def btnMIDILocation_Clicked(self): midiPath = QtGui.QFileDialog.getOpenFileName(self, 'Single File', "~/Desktop", '*.mid') if (os.path.exists(midiPath)): settings[1] = midiPath self.ui.lineEdit_2.setText(os.path.basename(midiPath)) def btnUpload_Clicked(self): if (None in settings[0:4]): print(settings[0]) print(settings[1]) print(settings[2]) print(settings[3]) print("Make sure all the necessary fields are filled") self.ui.lineEdit_3.setText( "ERROR: Make sure all the necessary fields are filled.") else: display = ('''Saving as: {} MIDI track: {} Instrument: {} Format: {} ''').format(os.path.basename(settings[0]), os.path.basename(settings[1]), instruments[settings[2] - 1], settings[3]) self.ui.textEdit_2.setText(display) self.ui.textEdit_2.append( "Converting MIDI file to {}. . . .".format(settings[3])) if (settings[3] == 'binary'): print("to binary") saveToSD_BINARY.downloadToSD(settings[0], settings[1], settings[2], settings[0]) self.ui.textEdit_2.append("File successfully converted.") if (settings[3] == 'text'): print("to text") saveToSD_TEXT.downloadToSD(settings[0], settings[1], settings[2], settings[0]) self.ui.textEdit_2.append("File successfully converted.") def btnPlay_Clicked(self): os.chdir(pathToMain) if settings[6] == None: settings[6] = self.ui.SelectSong.currentText()[:8] if settings[5] == None: self.ui.lineEdit_3.setText("ERROR: Please select an instrument.") print("Select instrument") else: shelfFile = shelve.open('GUIconfig') __SONGS_temp_ = shelfFile['__SONGS__'] conductor.MQTT_publish("PLAY", track=settings[6], topic=settings[5]) time.sleep(3) print("Transmitting START signal") conductor.MQTT_publish("START", topic=settings[5]) songName = [ k for k, v in __SONGS_temp_.items() if v == settings[6] ] self.ui.lineEdit_3.setText("PLAYING {} on {}".format( __SONGS_temp_[songName[0]], instruments[settings[5]])) def btnStop_Clicked(self): if (settings[5] == None): self.ui.lineEdit_3.setText("ERROR: Please select an instrument.") print("Make sure all the necessary fields are filled") else: conductor.MQTT_publish("STOP", topic=settings[5]) self.ui.lineEdit_3.setText("STOPPING {}".format( instruments[settings[5]])) pass def checkMidi_Checked(self): settings[4] = 1 #copy midi files pass def checkAll_Checked(self): settings[5] = -1 pass def checkKeyboard_Checked(self): settings[5] = 2 pass def checkStepper_Checked(self): settings[5] = 0 pass def checkTesla_Checked(self): settings[5] = 3 pass def checkXylophone_Checked(self): settings[5] = 1 pass def FileType(self, index): if index == 0: ##binary settings[3] = 'binary' pass else: ##text settings[3] = 'text' pass def selectInstrument(self, index): if index == 0: #key settings[2] = 3 pass elif index == 1: #xylo settings[2] = 2 pass elif index == 2: #stepper settings[2] = 1 pass else: #tesla settings[2] = 4 pass def __init__(self): QtGui.QMainWindow.__init__(self) self.ui = Ui_Dialog() self.ui.setupUi(self) #SD Card Management self.ui.btnCardLocation.clicked.connect(self.btnCardLocation_Clicked) self.ui.btnMIDILocation.clicked.connect(self.btnMIDILocation_Clicked) self.ui.btnUpload.clicked.connect(self.btnUpload_Clicked) self.ui.checkMIDI.toggled.connect(self.checkMidi_Checked) self.ui.tabFileType.activated.connect(self.FileType) self.ui.selectInstrument.activated.connect(self.selectInstrument) #Orchestra Settings self.ui.btnPlay.clicked.connect(self.btnPlay_Clicked) self.ui.btnStop.clicked.connect(self.btnStop_Clicked) self.ui.checKeyboard.toggled.connect(self.checkKeyboard_Checked) self.ui.checkStepper.toggled.connect(self.checkStepper_Checked) self.ui.checkTesla.toggled.connect(self.checkTesla_Checked) self.ui.checkXylophone.toggled.connect(self.checkXylophone_Checked) self.ui.checkAll.toggled.connect(self.checkAll_Checked) shelfFile = shelve.open('GUIconfig') if (not '__SONGS__' in shelfFile.keys()): shelfFile['__SONGS__'] = {} __SONGS_temp_ = shelfFile['__SONGS__'] shelfFile.close() self.ui.SelectSong.clear() self.ui.SelectSong.addItems(list(__SONGS_temp_.keys())) #executes when box is clicked self.ui.SelectSong.activated.connect(self.SongSelection)
class AppWindow(QDialog, QWidget): kolej = False pob = False dane = None gracz = None def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.show() self.ui.mainBtn.clicked.connect(self.polacz) self.ui.btn1.clicked.connect(self.graj) self.ui.btn2.clicked.connect(self.graj) self.ui.btn3.clicked.connect(self.graj) self.ui.btn4.clicked.connect(self.graj) self.ui.btn5.clicked.connect(self.graj) self.ui.btn6.clicked.connect(self.graj) self.ui.btn7.clicked.connect(self.graj) self.ui.btn8.clicked.connect(self.graj) self.ui.btn9.clicked.connect(self.graj) def keyPressEvent(self, QKeyEvent): if QKeyEvent.key() == Qt.Key_Escape: self.close() def pobierzdane(self): if self.pob: dane = baza.pobierz(self.dane[0]) if dane == self.dane: pass else: for i in range(len(dane)): if dane[i] == self.dane[i]: pass else: zmiana = False if i == 1: self.ui.btn1.setText(dane[1]) zmiana = True if i == 2: self.ui.btn2.setText(dane[2]) zmiana = True if i == 3: self.ui.btn3.setText(dane[3]) zmiana = True if i == 4: self.ui.btn4.setText(dane[4]) zmiana = True if i == 5: self.ui.btn5.setText(dane[5]) zmiana = True if i == 6: self.ui.btn6.setText(dane[6]) zmiana = True if i == 7: self.ui.btn7.setText(dane[7]) zmiana = True if i == 8: self.ui.btn8.setText(dane[8]) zmiana = True if i == 9: self.ui.btn9.setText(dane[9]) zmiana = True if i == 10 or i == 11: if dane[i] == '0' and self.dane[i] == '1': QMessageBox.about(self, "Uwaga!", "Przeciwnik rozłączyl się!") elif dane[i] == '1' and self.dane[i] == '0': QMessageBox.about(self, "Uwaga!", "Przeciwnik połączył się!") if zmiana: self.pob = False self.ui.label.setText("Teraz Twoja kolej!") self.dane = dane spr = self.sprawdz() if spr == True: baza.usun(self.dane[0]) self.rzl() self.ui.label.setText("Remis!") elif spr == "X" and self.gracz == 1 or spr == "O" and self.gracz == 2: baza.usun(self.dane[0]) self.rzl() self.ui.label.setText("Wygrałeś!") elif spr == "X" or spr == "O": baza.usun(self.dane[0]) self.rzl() self.ui.label.setText("Wygrywa przeciwnik!") else: pass def polacz(self): sender = self.sender() if sender.text() == "Połącz": id, okPressed = QInputDialog.getText(self, "Połącz", "Wprowadź ID pokoju:", QLineEdit.Normal, "") if okPressed and id != "": id = id.replace(" ", "_") out, gracz = baza.pol(id) if out == None: QMessageBox.about(self, "Bląd!", "Pokój jest pełny!") else: self.dane = out ##################print(self.dane) self.ui.label.setText("Połączono!") self.ui.mainBtn.setText("Rozłącz") self.gracz = gracz self.ustaw() else: QMessageBox.about(self, "Bląd!", "Nazwa nie może być pusta!") elif sender.text() == "Rozłącz": self.rozlacz() def setInterval(self, func, time): e = threading.Event() while not e.wait(time): func() def ustaw(self): if self.dane[1] != 'A': self.ui.btn1.setText(self.dane[1]) if self.dane[2] != 'A': self.ui.btn2.setText(self.dane[2]) if self.dane[3] != 'A': self.ui.btn3.setText(self.dane[3]) if self.dane[4] != 'A': self.ui.btn4.setText(self.dane[4]) if self.dane[5] != 'A': self.ui.btn5.setText(self.dane[5]) if self.dane[6] != 'A': self.ui.btn6.setText(self.dane[6]) if self.dane[7] != 'A': self.ui.btn7.setText(self.dane[7]) if self.dane[8] != 'A': self.ui.btn8.setText(self.dane[8]) if self.dane[9] != 'A': self.ui.btn9.setText(self.dane[9]) if self.dane[12] == 'X' and self.gracz == 1 or self.dane[ 12] == 'O' and self.gracz == 2: self.ui.label.setText("Twoja kolej!") elif self.gracz == 1: self.pob = True self.ui.label.setText("Kolej gracza O") elif self.gracz == 2: self.pob = True self.ui.label.setText("Kolej gracza X") def rzl(self): self.pob = False self.ui.mainBtn.setText("Połącz") self.ui.btn1.setText("") self.ui.btn2.setText("") self.ui.btn3.setText("") self.ui.btn4.setText("") self.ui.btn5.setText("") self.ui.btn6.setText("") self.ui.btn7.setText("") self.ui.btn8.setText("") self.ui.btn9.setText("") self.dane = None self.gracz = None self.kolej = False def rozlacz(self): baza.rozlacz(self.dane[0], self.gracz) self.pob = False self.ui.mainBtn.setText("Połącz") self.ui.btn1.setText("") self.ui.btn2.setText("") self.ui.btn3.setText("") self.ui.btn4.setText("") self.ui.btn5.setText("") self.ui.btn6.setText("") self.ui.btn7.setText("") self.ui.btn8.setText("") self.ui.btn9.setText("") self.ui.label.setText("") self.dane = None self.gracz = None self.kolej = False def graj(self): sender = self.sender() print(self.dane[12], self.gracz) if self.dane[12] == 'X' and self.gracz == 1: if sender.text() == "": obj = sender.objectName() obj = obj.replace("btn", "") obj = int(obj) if obj == 1: self.ui.btn1.setText('X') self.dane[1] = 'X' baza.updt(self.dane[0], 'x1', 'X', 'O') if obj == 2: self.ui.btn2.setText("X") self.dane[2] = 'X' baza.updt(self.dane[0], 'x2', 'X', 'O') if obj == 3: self.ui.btn3.setText("X") self.dane[3] = 'X' baza.updt(self.dane[0], 'x3', 'X', 'O') if obj == 4: self.ui.btn4.setText("X") self.dane[4] = 'X' baza.updt(self.dane[0], 'x4', 'X', 'O') if obj == 5: self.ui.btn5.setText("X") self.dane[5] = 'X' baza.updt(self.dane[0], 'x5', 'X', 'O') if obj == 6: self.ui.btn6.setText("X") self.dane[6] = 'X' baza.updt(self.dane[0], 'x6', 'X', 'O') if obj == 7: self.ui.btn7.setText("X") self.dane[7] = 'X' baza.updt(self.dane[0], 'x7', 'X', 'O') if obj == 8: self.ui.btn8.setText("X") self.dane[8] = 'X' baza.updt(self.dane[0], 'x8', 'X', 'O') if obj == 9: self.ui.btn9.setText("X") self.dane[9] = 'X' baza.updt(self.dane[0], 'x9', 'X', 'O') self.ui.label.setText("Teraz kolej gracza O") self.dane[12] = 'O' self.pob = True if self.dane[12] == 'O' and self.gracz == 2: if sender.text() == "": obj = sender.objectName() obj = obj.replace("btn", "") obj = int(obj) if obj == 1: self.ui.btn1.setText("O") self.dane[1] = 'O' baza.updt(self.dane[0], 'x1', 'O', 'X') if obj == 2: self.ui.btn2.setText("O") self.dane[2] = 'O' baza.updt(self.dane[0], 'x2', 'O', 'X') if obj == 3: self.ui.btn3.setText("O") self.dane[3] = 'O' baza.updt(self.dane[0], 'x3', 'O', 'X') if obj == 4: self.ui.btn4.setText("O") self.dane[4] = 'O' baza.updt(self.dane[0], 'x4', 'O', 'X') if obj == 5: self.ui.btn5.setText("O") self.dane[5] = 'O' baza.updt(self.dane[0], 'x5', 'O', 'X') if obj == 6: self.ui.btn6.setText("O") self.dane[6] = 'O' baza.updt(self.dane[0], 'x6', 'O', 'X') if obj == 7: self.ui.btn7.setText("O") self.dane[7] = 'O' baza.updt(self.dane[0], 'x7', 'O', 'X') if obj == 8: self.ui.btn8.setText("O") self.dane[8] = 'O' baza.updt(self.dane[0], 'x8', 'O', 'X') if obj == 9: self.ui.btn9.setText("O") self.dane[9] = 'O' baza.updt(self.dane[0], 'x9', 'O', 'X') self.ui.label.setText("Teraz kolej gracza X") self.dane[12] = 'X' self.pob = True spr = self.sprawdz() print(spr) if spr == True: self.ui.label.setText("Remis!") self.rzl() elif spr == "X" and self.gracz == 1 or spr == "O" and self.gracz == 2: self.ui.label.setText("Wygrałeś!") self.rzl() elif spr == "X" or spr == "O": self.ui.label.setText("Wygrywa przeciwnik!") self.rzl() else: pass def sprawdz(self): xo = [['A', 'A', 'A'], ['A', 'A', 'A'], ['A', 'A', 'A']] xo[0][0] = self.ui.btn1.text() xo[0][1] = self.ui.btn2.text() xo[0][2] = self.ui.btn3.text() xo[1][0] = self.ui.btn4.text() xo[1][1] = self.ui.btn5.text() xo[1][2] = self.ui.btn6.text() xo[2][0] = self.ui.btn7.text() xo[2][1] = self.ui.btn8.text() xo[2][2] = self.ui.btn9.text() for x in range(0, 3): if xo[x][0] == "X" and xo[x][1] == "X" and xo[x][2] == "X": return 'X' elif xo[0][x] == "X" and xo[1][x] == "X" and xo[2][x] == "X": return 'X' elif xo[0][0] == "X" and xo[1][1] == "X" and xo[2][2] == "X": return 'X' elif xo[0][2] == "X" and xo[1][1] == "X" and xo[2][0] == "X": return 'X' elif xo[x][0] == "O" and xo[x][1] == "O" and xo[x][2] == "O": return 'O' elif xo[0][x] == "O" and xo[1][x] == "O" and xo[2][x] == "O": return 'O' elif xo[0][0] == "O" and xo[1][1] == "O" and xo[2][2] == "O": return 'O' elif xo[0][2] == "O" and xo[1][1] == "O" and xo[2][0] == "O": return 'O' for i in range(0, 3): for j in range(0, 3): if xo[i][j] == "": return False return True def closeEvent(self, QCloseEvent): if self.dane != None: self.rozlacz() QCloseEvent.accept() else: QCloseEvent.accept()