def interpreter_log_default_exception(self, exception): if not self.wasStoped: self.mainW.ui.statusbar.showMessage(QtCore.QString (i18n('Was occurred an error'))) self.showInLog(i18n('Was occurred an error')) self.log(exception.msg) self.mainW.resetButtonsRunAndStop()
def success(self, board_string, result): if not self.interactiveRunning: if not self.wasStoped: self.mainW.ui.statusbar.showMessage( QtCore.QString(i18n('Execution completed'))) self.results = Results(self.mainW) board = self.prepareString(board_string) self.results.setInitialBoard( BoardViewer(self, self.mainW.initialBoardGenerator.board, self.mainW.getClothing())) self.results.setFinalBoard( BoardViewer(self, parseABoardString(board), self.mainW.getClothing())) self.results.setRetVars(result) self.setCodeInResults() self.results.ui.tabWidgetResults.setCurrentIndex(2) self.results.show() self.mainW.resetButtonsRunAndStop() self.showInLog(i18n('Execution completed')) self.log('----------------' + str(datetime.datetime.now())[:19] + '-----------------\n') else: self.mainW.ui.statusbar.showMessage( QtCore.QString(i18n('Execution completed'))) self.showInLog(i18n('Execution completed')) self.log('----------------' + str(datetime.datetime.now())[:19] + '-----------------\n') self.interactiveW.setStatusMessage(' ' + i18n('Execution completed')) self.mainW.resetButtonsRunAndStop() self.wasStoped = False self.isOpenInteractiveW = False self.interactiveRunning = False
def checkWasChangesInFiles(self): if self.mainW.ui.textEditFile.document().isModified(): val = QMessageBox.question( self.mainW, i18n("Save changes?"), i18n("The file %s was changed, Do you save changes?") % (self.mainW.ui.tabWidgetEditors.tabText(0)[3:]), QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel, ) if val == QMessageBox.Yes: if not self.saveFile(): return QMessageBox.Cancel if self.mainW.ui.textEditLibrary.document().isModified(): val = QMessageBox.question( self.mainW, i18n("Save changes?"), i18n("The file %s was changed, Do you save changes?") % (self.mainW.ui.tabWidgetEditors.tabText(1)[3:]), QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel, ) if val == QMessageBox.Yes: if not self.saveFile(): return QMessageBox.Cancel return val
def success(self, board_string, result): self.mainW.ui.statusbar.showMessage( QtCore.QString(i18n('Check completed'))) self.showInLog(i18n('Check completed, program is OK')) self.log('----------------' + str(datetime.datetime.now())[:19] + '-----------------\n') self.mainW.resetButtonsRunAndStop()
def init_combo_box_options(self): self.connect(self.ui.combo_box_options, QtCore.SIGNAL('activated(QString)'), self.combo_box_options_chosen) self.ui.combo_box_options.addItem(i18n('Options')) self.ui.combo_box_options.addItem(i18n('Options Board')) self.ui.combo_box_options.addItem(i18n('User Options'))
def interpreter_log_default_exception(self, exception): if not self.wasStoped: self.mainW.ui.statusbar.showMessage( QtCore.QString(i18n('Was occurred an error'))) self.showInLog(i18n('Was occurred an error')) self.log(exception.msg) self.mainW.resetButtonsRunAndStop()
def openSelectBoardSizeWindow(self, function, title): self.widgetSize = QtGui.QDialog(self) self.widgetSize.setWindowTitle(i18n(title)) self.widgetSize.setGeometry(500, 300, 180, 180) self.widgetSize.setMaximumSize(280, 200) self.setStyleSheet("background-color:'white'") widthL = QtGui.QLabel(self.widgetSize) widthL.setText(i18n('input') + ' x') widthL.move(20, 20) self.widthLE = QtGui.QLineEdit(self.widgetSize) self.widthLE.setGeometry(20, 45, 80, 30) heightL = QtGui.QLabel(self.widgetSize) heightL.setText(i18n('input')+ ' y') heightL.move(20, 70) self.heightLE = QtGui.QLineEdit(self.widgetSize) self.heightLE.setGeometry(20, 95, 80, 30) hLayout = QtGui.QHBoxLayout() hLayout.addStretch(1) acceptButton = QtGui.QPushButton(i18n('Accept')) acceptButton.clicked.connect(function) hLayout.addWidget(acceptButton) vLayout = QtGui.QVBoxLayout() vLayout.addStretch(1) vLayout.addLayout(hLayout) self.widgetSize.setLayout(vLayout) self.widgetSize.exec_()
def success(self, board_string, result): if not self.interactiveRunning: if not self.wasStoped: self.mainW.ui.statusbar.showMessage(QtCore.QString (i18n('Execution completed'))) self.results = Results(self.mainW) board = self.prepareString(board_string) self.results.setInitialBoard(BoardViewer(self, self.mainW.initialBoardGenerator.board, self.mainW.getClothing())) self.results.setFinalBoard(BoardViewer(self, parseABoardString(board), self.mainW.getClothing())) self.results.setRetVars(result) self.setCodeInResults() self.results.ui.tabWidgetResults.setCurrentIndex(2) self.results.show() self.mainW.resetButtonsRunAndStop() self.showInLog(i18n('Execution completed')) self.log('----------------'+ unicode(datetime.datetime.now())[:19] + '-----------------\n') else: self.mainW.ui.statusbar.showMessage(QtCore.QString (i18n('Execution completed'))) self.showInLog(i18n('Execution completed')) self.log('----------------'+ unicode(datetime.datetime.now())[:19] + '-----------------\n') self.interactiveW.setStatusMessage(' ' + i18n('Execution completed')) self.mainW.resetButtonsRunAndStop() self.wasStoped = False self.isOpenInteractiveW = False self.interactiveRunning = False
def __init__(self, parent): super(SearchWidget, self).__init__(parent) self.setWindowTitle(i18n('Search')) self.resize(QtCore.QSize(300, 80)) self.setModal(False) self.textEditor = self.setEditor() labelSearch = QtGui.QLabel(i18n('Search')) self.text = QtGui.QLineEdit() self.text.textChanged.connect(self.search) prevButton = QtGui.QPushButton() prevButton.setIcon(QtGui.QIcon(':/prev.png')) nextButton = QtGui.QPushButton() nextButton.setIcon(QtGui.QIcon(':/next.png')) layout = QtGui.QHBoxLayout() layout.addWidget(labelSearch) layout.addWidget(self.text) layout.addWidget(prevButton) layout.addWidget(nextButton) self.setLayout(layout) nextButton.clicked.connect(self.next) prevButton.clicked.connect(self.prev) self.setStyleSheet( "QDialog {background-color:'white'; border:2px solid #4682b4; border-color:'#4682b4';}" )
def success(self, board_string, result): self.mainW.ui.statusbar.showMessage(QtCore.QString(i18n('Check completed'))) self.showInLog(i18n('Check completed, program is OK')) self.log('----------------' + unicode(datetime.datetime.now())[:19] + '-----------------\n') self.mainW.resetButtonsRunAndStop()
def fail_handler(exception): self.mainW.ui.statusbar.showMessage(QtCore.QString(i18n('Check failed'))) self.showInLog(i18n('Check failed:')) self.showRowAndColError(exception) self.log(exception.msg) self.log('----------------' + unicode(datetime.datetime.now())[:19] + '-----------------\n')
def init_combo_box_persist(self): self.connect(self.ui.combo_box_persist, QtCore.SIGNAL('activated(QString)'), self.combo_box_persist_chosen) self.ui.combo_box_persist.addItem(i18n('Persist board')) self.ui.combo_box_persist.addItem(i18n('Set as initial board')) self.ui.combo_box_persist.addItem(i18n('Save board to disk')) self.ui.combo_box_persist.addItem(i18n('Save board to image'))
def setCodeInResults(self): fileCode = QtGui.QTextDocument( i18n('### FILE CODE ###\n\n') + self.mainW.ui.textEditFile.document().toPlainText()) libraryCode = QtGui.QTextDocument( i18n('### LIBRARY CODE ###\n\n') + self.mainW.ui.textEditLibrary.document().toPlainText()) self.results.setSourceCode(fileCode, libraryCode)
def fail_handler(exception): self.mainW.ui.statusbar.showMessage( QtCore.QString(i18n('Check failed'))) self.showInLog(i18n('Check failed:')) self.showRowAndColError(exception) self.log(exception.msg) self.log('----------------' + str(datetime.datetime.now())[:19] + '-----------------\n')
def stop(self): self.guiInterpreterHandler.initialStatus() self.runButton.stopInterpreter() self.resetButtonsRunAndStop() self.ui.statusbar.showMessage(QtCore.QString (i18n('Execution interrupted by the user'))) self.guiInterpreterHandler.showInLog(i18n( 'Execution interrupted by the user')) self.guiInterpreterHandler.log('----------------' + unicode(datetime.datetime.now())[:19] + '-----------------')
def stop(self): self.guiInterpreterHandler.initialStatus() self.runButton.stopInterpreter() self.resetButtonsRunAndStop() self.ui.statusbar.showMessage( QtCore.QString(i18n('Execution interrupted by the user'))) self.guiInterpreterHandler.showInLog( i18n('Execution interrupted by the user')) self.guiInterpreterHandler.log('----------------' + str(datetime.datetime.now())[:19] + '-----------------')
def check(self): self.ui.actionStop.setEnabled(True) self.ui.actionCheck.setEnabled(False) self.ui.actionRun.setEnabled(False) self.guiInterpreterHandler.showInLog(i18n( 'Start check || Languaje: ') + self.lang) self.guiInterpreterHandler.log('----------------' + unicode(datetime.datetime.now())[:19] + '-----------------') self.ui.statusbar.showMessage(QtCore.QString(i18n('Checking...'))) self.checkButton = CheckButton(self) self.checkButton.start()
def check(self): self.ui.actionStop.setEnabled(True) self.ui.actionCheck.setEnabled(False) self.ui.actionRun.setEnabled(False) self.guiInterpreterHandler.showInLog( i18n('Start check || Languaje: ') + self.lang) self.guiInterpreterHandler.log('----------------' + str(datetime.datetime.now())[:19] + '-----------------') self.ui.statusbar.showMessage(QtCore.QString(i18n('Checking...'))) self.checkButton = CheckButton(self) self.checkButton.start()
def retranslateUi(self, results): results.setWindowTitle(QtGui.QApplication.translate("results", i18n('Mode Results'), None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonSaveResults.setToolTip(QtGui.QApplication.translate("results", i18n('Save in file the final board'), None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonSaveResults.setText(QtGui.QApplication.translate("results", i18n('Save Final Board'), None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonSwitchViews.setToolTip(QtGui.QApplication.translate("switchViews", i18n('Switch between Gobstones Standard view and selected custom view'), None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonSwitchViews.setText(QtGui.QApplication.translate("switchViews", i18n('Switch Views'), None, QtGui.QApplication.UnicodeUTF8)) #self.tabWidgetResults.setTabText(self.tabWidgetResults.indexOf(self.tabInitialBoard), QtGui.QApplication.translate("results", i18n('Initial Board'), None, QtGui.QApplication.UnicodeUTF8)) #self.tabWidgetResults.setTabText(self.tabWidgetResults.indexOf(self.tabFinalBoard), QtGui.QApplication.translate("results", i18n('Final Board'), None, QtGui.QApplication.UnicodeUTF8)) self.tabWidgetResults.setTabText(self.tabWidgetResults.indexOf(self.splitter), QtGui.QApplication.translate("results", i18n('Source Code'), None, QtGui.QApplication.UnicodeUTF8)) self.labelResults.setText(QtGui.QApplication.translate("results", i18n('Results'), None, QtGui.QApplication.UnicodeUTF8)) self.labelViews.setText(QtGui.QApplication.translate("results", i18n('Select View'), None, QtGui.QApplication.UnicodeUTF8))
def closeApp(self, event): if self.mainW.ui.textEditFile.document().isModified( ) or self.mainW.ui.textEditLibrary.document().isModified(): val = QMessageBox.question( self.mainW, i18n('Save changes?'), i18n( 'There are unsaved files, you want to close the application?' ), QMessageBox.Yes, QMessageBox.No) if val == QMessageBox.Yes: event.accept() else: event.ignore()
def closeApp(self, event): if self.mainW.ui.textEditFile.document().isModified() or self.mainW.ui.textEditLibrary.document().isModified(): val = QMessageBox.question( self.mainW, i18n("Save changes?"), i18n("There are unsaved files, you want to close the application?"), QMessageBox.Yes, QMessageBox.No, ) if val == QMessageBox.Yes: event.accept() else: event.ignore()
def setFinalBoard(self, boardV): boardV.setParent(self.ui.tabWidgetResults) self.ui.tabWidgetResults.insertTab(2,boardV,i18n('Final Board')) if not boardV.is_board_error(): self.finalBoard = boardV.getBoard() else: self.ui.pushButtonSaveResults.setVisible(False)
def setFinalBoard(self, boardV): boardV.setParent(self.ui.tabWidgetResults) self.ui.tabWidgetResults.insertTab(2, boardV, i18n('Final Board')) if not boardV.is_board_error(): self.finalBoard = boardV.getBoard() else: self.ui.pushButtonSaveResults.setVisible(False)
def retranslateUi(self, Form): Form.setWindowTitle( QtGui.QApplication.translate("Form", i18n("Interactive Mode"), None, QtGui.QApplication.UnicodeUTF8)) self.label.setText( QtGui.QApplication.translate( "Form", ' ' + i18n("Press a key to Continue"), None, QtGui.QApplication.UnicodeUTF8)) self.pushButton.setText( QtGui.QApplication.translate("Form", i18n('Switch Views'), None, QtGui.QApplication.UnicodeUTF8)) self.labelViews.setText( QtGui.QApplication.translate("results", i18n('Select View'), None, QtGui.QApplication.UnicodeUTF8)) self.labelResults.setText( QtGui.QApplication.translate("results", i18n('Interactive'), None, QtGui.QApplication.UnicodeUTF8))
def acceptBoardSize(self): y = self.heightLE.text() x = self.widthLE.text() if (self.isValidInt(x, 1) and self.isValidInt(y, 1)): self.setBoardSize(int(self.widthLE.text()), int(self.heightLE.text())) self.widgetSize.close() else: ErrorWindow(i18n("You must enter integers greater than zero!"))
def makeRelationshipBetweenSizeAndHead(self, s): if(s == 'dimensions random'): self.ui.comboBox_3.clear() self.ui.comboBox_3.addItem(i18n('head random')) if(s == 'enter dimensions' or s == 'current conservation dimensions'): self.ui.comboBox_3.clear() self.initCombo3HeadPosition() self.ui.comboBox_3.update()
def makeRelationshipBetweenHeadAndSize(self, s): if(s == 'enter coordinate' or s == 'current conservation coordinate'): self.ui.comboBox_2.clear() self.ui.comboBox_2.addItem(i18n('current conservation dimensions')) if(s == 'head random'): self.ui.comboBox_2.clear() self.initCombo2SizeDimensions() self.ui.comboBox_2.update()
def newFile(self): if self.mainW.ui.textEditFile.document().isModified(): val = QMessageBox.question( self.mainW, i18n('Save changes?'), i18n('The file %s was changed, Do you save changes?') % (self.mainW.ui.tabWidgetEditors.tabText(0)[3:]), QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel) if val == QMessageBox.Yes: self.saveFile() elif val == QMessageBox.Cancel: return self.moduleFile = None self.clearCurrentModule() if clothing_dir_for_file(str(self.moduleFile)): self.updateClothingOptions() self.mainW.setClothing('Gobstones.xml')
def run(self): self.ui.logger.clear() if MainWindow.getPreference('logger') == False: self.setPreference('logger', True) self.initLoggerSize() self.guiInterpreterHandler.wasStoped = False self.guiInterpreterHandler.showInLog( i18n('Start execution || Languaje: ') + self.lang) self.guiInterpreterHandler.log('----------------' + str(datetime.datetime.now())[:19] + '-----------------') self.ui.logger.show() self.ui.actionStop.setEnabled(True) self.ui.actionCheck.setEnabled(False) self.ui.statusbar.showMessage(QtCore.QString(i18n('Processing...'))) self.programRun.handler = self.guiInterpreterHandler self.runButton.start(self.programRun)
def run(self): self.ui.logger.clear() if MainWindow.getPreference('logger') == False: self.setPreference('logger', True) self.initLoggerSize() self.guiInterpreterHandler.wasStoped = False self.guiInterpreterHandler.showInLog(i18n( 'Start execution || Languaje: ') + self.lang) self.guiInterpreterHandler.log('----------------' + unicode(datetime.datetime.now())[:19] + '-----------------') self.ui.logger.show() self.ui.actionStop.setEnabled(True) self.ui.actionCheck.setEnabled(False) self.ui.statusbar.showMessage(QtCore.QString(i18n('Processing...'))) self.programRun.handler = self.guiInterpreterHandler self.runButton.start(self.programRun)
def acceptHeadPosition(self): y = self.heightLE.text() x = self.widthLE.text() if (self.isValidIntAndPosition(x,y)): self.initialBoardGenerator.setHead(int(x), int(y)) self.widgetSize.close() else: ErrorWindow(i18n("You must enter integers less or equal than ({0},{1})"). format(self.initialBoardGenerator.board.getX()-1,self.initialBoardGenerator.board.getY()-1))
def __init__(self, mainW): super(PreferencesWindow, self).__init__() self.mainW = mainW self.setGeometry(300, 300, 300, 150) self.setMaximumSize(300,150) self.setWindowTitle(i18n('Preferences')) self.setStyleSheet("QDialog {background-color:'white'; border:2px solid #4682b4; border-color:'#4682b4';}") self.initActions() self.exec_()
def initialStatus(self, partialBoard): if (self.load_views is None) or (self.load_views != root_path()): self.reset_clothing() self.loadViewAlternatives() self.load_views = root_path() self.boardV = BoardViewer(self, parseABoardString(partialBoard), self.mainW.getClothing()) self.boardV.setParent(self.ui.boardViewer) self.ui.boardViewer.removeTab(0) self.ui.boardViewer.insertTab(0, self.boardV, i18n('Board')) self.setPressAKeyState() self.init_switcher()
def __init__(self, mainW): super(PreferencesWindow, self).__init__() self.mainW = mainW self.setGeometry(300, 300, 300, 150) self.setMaximumSize(300, 150) self.setWindowTitle(i18n('Preferences')) self.setStyleSheet( "QDialog {background-color:'white'; border:2px solid #4682b4; border-color:'#4682b4';}" ) self.initActions() self.exec_()
def checkWasChangesInFiles(self): if self.mainW.ui.textEditFile.document().isModified(): val = QMessageBox.question( self.mainW, i18n('Save changes?'), i18n('The file %s was changed, Do you save changes?') % (self.mainW.ui.tabWidgetEditors.tabText(0)[3:]), QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel) if val == QMessageBox.Yes: if not self.saveFile(): return QMessageBox.Cancel if self.mainW.ui.textEditLibrary.document().isModified(): val = QMessageBox.question( self.mainW, i18n('Save changes?'), i18n('The file %s was changed, Do you save changes?') % (self.mainW.ui.tabWidgetEditors.tabText(1)[3:]), QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel) if val == QMessageBox.Yes: if not self.saveFile(): return QMessageBox.Cancel return val
def newFile(self): if self.mainW.ui.textEditFile.document().isModified(): val = QMessageBox.question( self.mainW, i18n("Save changes?"), i18n("The file %s was changed, Do you save changes?") % (self.mainW.ui.tabWidgetEditors.tabText(0)[3:]), QMessageBox.Yes, QMessageBox.No, QMessageBox.Cancel, ) if val == QMessageBox.Yes: self.saveFile() elif val == QMessageBox.Cancel: return self.moduleFile = None self.clearCurrentModule() if clothing_dir_for_file(str(self.moduleFile)): self.updateClothingOptions() self.mainW.setClothing("Gobstones.xml")
def openFiles(self): if self.mainW.ui.textEditFile.document().isModified() or self.mainW.ui.textEditLibrary.document().isModified(): val = QMessageBox.question( self.mainW, i18n("Warning!"), i18n("There are unsaved files, to load a new module changes will be lost, continue?"), QMessageBox.Yes, QMessageBox.Cancel, ) if val == QMessageBox.Cancel: return False filename = openFileName(self.mainW, "*.gbs") if not filename == "": if not self.wantOpenLibrary(filename): self.moduleFile = filename fname = open(filename) data = fname.read() string = QtCore.QString() data = string.fromUtf8(data) self.mainW.ui.textEditFile.setPlainText(data) self.setTabsNamesAndLabelButtonNameAndSetCurrentPathDirectory(filename) self.loadLibrary() fname.close() else: QMessageBox.question( self.mainW, i18n("Error loading the file"), i18n("Must load a file different to library") + "\n" + i18n("If you want edit the library, use the corresponding tab"), QMessageBox.Ok, ) return False self.createInitialsFoldersAndFiles() self.updateClothingOptions() return True
def updateClothingOptions(self): if clothing_for_file_exists(str(self.moduleFile)): path = clothing_dir_for_file(str(self.moduleFile)) files = os.listdir(path) else: files = [] self.mainW.ui.menuSelectResultView.clear() self.filesNames = [] for f in files: fileName, fileExtension = os.path.splitext(os.path.join(path, f)) if fileExtension == ".xml": self.filesNames.append(os.path.join(path, fileName)) self.mapper = QtCore.QSignalMapper(self.mainW) self.actions = {} for fn in self.filesNames: (filepath, filename) = os.path.split(fn) self.addClothing(fn, filename) self.addClothing("Gobstones", i18n("Gobstones Standard")) self.addClothing("PixelBoard", i18n("Pixel Board")) self.mapper.mapped["QString"].connect(self.handleButton)
def updateClothingOptions(self): if clothing_for_file_exists(str(self.moduleFile)): path = clothing_dir_for_file(str(self.moduleFile)) files = os.listdir(path) else: files = [] self.mainW.ui.menuSelectResultView.clear() self.filesNames = [] for f in files: fileName, fileExtension = os.path.splitext(os.path.join(path, f)) if fileExtension == '.xml': self.filesNames.append(os.path.join(path, fileName)) self.mapper = QtCore.QSignalMapper(self.mainW) self.actions = {} for fn in self.filesNames: (filepath, filename) = os.path.split(fn) self.addClothing(fn, filename) self.addClothing('Gobstones', i18n('Gobstones Standard')) self.addClothing('PixelBoard', i18n('Pixel Board')) self.mapper.mapped['QString'].connect(self.handleButton)
def __init__(self, parent): super(SearchWidget, self).__init__(parent) self.setWindowTitle(i18n('Search')) self.resize(QtCore.QSize(300, 80)) self.setModal(False) self.textEditor = self.setEditor() labelSearch = QtGui.QLabel(i18n('Search')) self.text = QtGui.QLineEdit() self.text.textChanged.connect(self.search) prevButton = QtGui.QPushButton() prevButton.setIcon(QtGui.QIcon(':/prev.png')) nextButton = QtGui.QPushButton() nextButton.setIcon(QtGui.QIcon(':/next.png')) layout = QtGui.QHBoxLayout() layout.addWidget(labelSearch) layout.addWidget(self.text) layout.addWidget(prevButton) layout.addWidget(nextButton) self.setLayout(layout) nextButton.clicked.connect(self.next) prevButton.clicked.connect(self.prev) self.setStyleSheet("QDialog {background-color:'white'; border:2px solid #4682b4; border-color:'#4682b4';}")
def openFiles(self): if self.mainW.ui.textEditFile.document().isModified( ) or self.mainW.ui.textEditLibrary.document().isModified(): val = QMessageBox.question( self.mainW, i18n('Warning!'), i18n( 'There are unsaved files, to load a new module changes will be lost, continue?' ), QMessageBox.Yes, QMessageBox.Cancel) if val == QMessageBox.Cancel: return False filename = openFileName(self.mainW, '*.gbs') if not filename == "": if not self.wantOpenLibrary(filename): self.moduleFile = filename fname = open(filename) data = fname.read() string = QtCore.QString() data = string.fromUtf8(data) self.mainW.ui.textEditFile.setPlainText(data) self.setTabsNamesAndLabelButtonNameAndSetCurrentPathDirectory( filename) self.loadLibrary() fname.close() else: QMessageBox.question( self.mainW, i18n('Error loading the file'), i18n('Must load a file different to library') + '\n' + i18n( 'If you want edit the library, use the corresponding tab' ), QMessageBox.Ok) return False self.createInitialsFoldersAndFiles() self.updateClothingOptions() return True
def initMessageAndAcceptButton(self, text): hLayoutMessage = QtGui.QHBoxLayout() message = QtGui.QLabel(text) hLayoutMessage.addWidget(message) hLayoutButton = QtGui.QHBoxLayout() acceptButton = QtGui.QPushButton(i18n("Accept"), self) acceptButton.clicked.connect(self.close) hLayoutButton.addStretch(1) hLayoutButton.addWidget(acceptButton) vLayout = QtGui.QVBoxLayout() vLayout.addLayout(hLayoutMessage) vLayout.addLayout(hLayoutButton) self.setLayout(vLayout)
def loadLibrary(self): '''Purpose: Load library file of a current directory. If not exist the Biblioteca.gbs , then create a new file library ''' if not os.path.exists('Biblioteca.gbs'): fileLibrary = open('Biblioteca.gbs', 'w') fileLibrary.write(i18n('-- New Library')) fileLibrary.close() fileLibrary = open('Biblioteca.gbs') self.libraryFile = os.path.abspath(str('Biblioteca.gbs')) data = fileLibrary.read() string = QtCore.QString() data = string.fromUtf8(data) self.mainW.ui.textEditLibrary.setPlainText(data) fileLibrary.close()
def loadLibrary(self): """Purpose: Load library file of a current directory. If not exist the Biblioteca.gbs , then create a new file library """ if not os.path.exists("Biblioteca.gbs"): fileLibrary = open("Biblioteca.gbs", "w") fileLibrary.write(i18n("-- New Library")) fileLibrary.close() fileLibrary = open("Biblioteca.gbs") self.libraryFile = os.path.abspath(str("Biblioteca.gbs")) data = fileLibrary.read() string = QtCore.QString() data = string.fromUtf8(data) self.mainW.ui.textEditLibrary.setPlainText(data) fileLibrary.close()
def initMessageAndAcceptButton(self, text): hLayoutMessage = QtGui.QHBoxLayout() message = QtGui.QLabel(text) hLayoutMessage.addWidget(message) hLayoutButton = QtGui.QHBoxLayout() acceptButton = QtGui.QPushButton(i18n('Accept'), self) acceptButton.clicked.connect(self.close) hLayoutButton.addStretch(1) hLayoutButton.addWidget(acceptButton) vLayout = QtGui.QVBoxLayout() vLayout.addLayout(hLayoutMessage) vLayout.addLayout(hLayoutButton) self.setLayout(vLayout)
def init_switcher(self): b = self.ui.pushButtonSwitchViews if len(self.filesNames) == 1: self.switcher = Switcher(i18n('Without clothing'), i18n('Without clothing'), b) elif self.current_clothing == "Gobstones.xml": self.switcher = Switcher(i18n('Enable clothing'), i18n('Disable clothing'), b) self.nextView = self.filesNames[1] + '.xml' else: self.switcher = Switcher(i18n('Disable clothing'), i18n('Enable clothing'), b) self.nextView = self.filesNames[1] + '.xml'
def __init__(self, mainW): super(InteractiveWindow, self).__init__() self.setWindowTitle(i18n('Interactive Mode')) self.setGeometry(200, 200, 600, 600) self.ui = Ui_Interactive() self.ui.setupUi(self) self.ui.combo.activated[str].connect(self.onActivated) self.mainW = mainW self.current_clothing = 'Gobstones.xml' self.pressAKey = True self.setModal(True) self.ui.pushButton.clicked.connect(self.switch_view) self.currentImage = ':/ballGreen.png' self.setStyleSheet( "InteractiveWindow{background-image:url(':/backgroundWidget.png');}") self.load_views = None self.forceQuit = False
def init_switcher(self): if len(self.filesNames) == 1: self.next_clothing = None self.switcher = Switcher(i18n('Without clothing'), i18n('Without clothing'), self.ui.pushButton) else: self.current_clothing = self.boardV.getClothing() if self.current_clothing == 'Gobstones.xml': self.next_clothing = self.filesNames[1] self.switcher = Switcher(i18n('Enable clothing'), i18n('Disable clothing'), self.ui.pushButton) else: self.next_clothing = 'Gobstones.xml' self.switcher = Switcher(i18n('Disable clothing'), i18n('Enable clothing'), self.ui.pushButton)
def changeLang(self): if self.lang == GOBSTONES: self.lang = XGOBSTONES self.ui.actionChangeLang.setText("XGobstones") icon = QtGui.QIcon(":/logoXGobstones.png") self.ui.actionChangeLang.setIcon(icon) self.ui.set_highlighter(XGobstonesHighlighter) else: self.lang = GOBSTONES self.ui.actionChangeLang.setText("Gobstones") icon = QtGui.QIcon(":/logoGobstones.png") self.ui.actionChangeLang.setIcon(icon) self.ui.set_highlighter(GobstonesHighlighter) self.guiInterpreterHandler.showInLog( i18n("The languaje was changed to ") + self.lang) self.updateWindowTitle() self.programRun = ProgramRun(self.getLang(), self.guiInterpreterHandler)
def __init__(self, mainW): super(InteractiveWindow, self).__init__() self.setWindowTitle(i18n('Interactive Mode')) self.setGeometry(200, 200, 600, 600) self.ui = Ui_Interactive() self.ui.setupUi(self) self.ui.combo.activated[str].connect(self.onActivated) self.mainW = mainW self.current_clothing = 'Gobstones.xml' self.pressAKey = True self.setModal(True) self.ui.pushButton.clicked.connect(self.switch_view) self.currentImage = ':/ballGreen.png' self.setStyleSheet( "InteractiveWindow{background-image:url(':/backgroundWidget.png');}" ) self.load_views = None self.forceQuit = False
def changeLang(self): if self.lang == GOBSTONES: self.lang = XGOBSTONES self.ui.actionChangeLang.setText("XGobstones") icon = QtGui.QIcon(":/logoXGobstones.png") self.ui.actionChangeLang.setIcon(icon) self.ui.set_highlighter(XGobstonesHighlighter) else: self.lang = GOBSTONES self.ui.actionChangeLang.setText("Gobstones") icon = QtGui.QIcon(":/logoGobstones.png") self.ui.actionChangeLang.setIcon(icon) self.ui.set_highlighter(GobstonesHighlighter) self.guiInterpreterHandler.showInLog(i18n ("The languaje was changed to ") + self.lang) self.updateWindowTitle() self.programRun = ProgramRun(self.getLang(), self.guiInterpreterHandler)
def saveAsFileDialog(self): indexFile = self.mainW.ui.tabWidgetEditors.currentIndex() filename = saveFileName(self.mainW, "*.gbs") if filename == "": return False if indexFile == 0: filename = assure_extension(filename, "gbs") (filep, filen) = os.path.split(str(filename)) if filen == "Biblioteca.gbs" or filen == "Biblioteca": QMessageBox.question( self.mainW, i18n("Error saving the file"), i18n("The file name dont be equals to library") + "\n" + i18n(""), QMessageBox.Ok, ) return False else: self.moduleFile = filename myFile = open(filename, "w") myFile.write(self.mainW.ui.textEditFile.toPlainText().toUtf8()) self.setCurrentPathDirectory(os.path.dirname(filename)) myFile.close() self.mainW.ui.textEditFile.document().setModified(False) self.setTabsNamesAndLabelButtonNameAndSetCurrentPathDirectory(filename) self.loadLibrary() if indexFile == 1: filename = assure_extension(filename, "gbs") (filep, filen) = os.path.split(str(filename)) if not filen.startswith("Biblioteca"): QMessageBox.question( self.mainW, i18n("Error saving the file"), i18n('The file must be named "Library"') + "\n" + i18n(""), QMessageBox.Ok, ) return False elif not os.path.exists("Biblioteca.gbs"): self.libraryFile = filename fileLibrary = open(filename, "w") fileLibrary.write(self.mainW.ui.textEditLibrary.toPlainText().toUtf8()) self.setCurrentPathDirectory(os.path.dirname(filename)) fileLibrary.close() self.mainW.ui.textEditLibrary.document().setModified(False) self.mainW.ui.tabWidgetEditors.setTabText(1, filen) else: self.saveLibrary() self.createInitialsFoldersAndFiles() self.updateClothingOptions() return True
def initActions(self): logger = QtGui.QCheckBox(i18n('show logger'), self) logger.move(20, 20) if gui.mainWindow.MainWindow.getPreference('logger'): logger.toggle() logger.stateChanged.connect(self.activateLogger) roseOfWinds = QtGui.QCheckBox(i18n('show rose of winds image'), self) roseOfWinds.move(20, 40) if gui.mainWindow.MainWindow.getPreference('roseOfWinds'): roseOfWinds.toggle() roseOfWinds.stateChanged.connect(self.activateRoseOfWinds) cellNumbers = QtGui.QCheckBox(i18n('show cell numbers'), self) cellNumbers.move(20, 60) if gui.mainWindow.MainWindow.getPreference('cellNumbers'): cellNumbers.toggle() cellNumbers.stateChanged.connect(self.activateCellNumbers) lineNumbers = QtGui.QCheckBox(i18n('show line numbers'), self) lineNumbers.move(20, 80) if gui.mainWindow.MainWindow.getPreference('lineNumbers'): lineNumbers.toggle() lineNumbers.stateChanged.connect(self.activateLineNumbers) autoIndentation = QtGui.QCheckBox(i18n('enable auto indentation'), self) autoIndentation.move(20, 100) if gui.mainWindow.MainWindow.getPreference('autoIndentation'): autoIndentation.toggle() autoIndentation.stateChanged.connect(self.activateAutoIndentation) vLayout = QtGui.QVBoxLayout() hLayout = QtGui.QHBoxLayout() hLayout.addStretch(1) vCheckLayout = QtGui.QVBoxLayout() acceptButton = QtGui.QPushButton(i18n('Accept'), self) acceptButton.clicked.connect(self.accept) vCheckLayout.addWidget(logger) vCheckLayout.addWidget(roseOfWinds) vCheckLayout.addWidget(cellNumbers) vCheckLayout.addWidget(lineNumbers) vCheckLayout.addWidget(autoIndentation) hLayout.addWidget(acceptButton) vLayout.addLayout(vCheckLayout) vLayout.addLayout(hLayout) self.setLayout(vLayout)
def saveAsFileDialog(self): indexFile = self.mainW.ui.tabWidgetEditors.currentIndex() filename = saveFileName(self.mainW, '*.gbs') if filename == "": return False if indexFile == 0: filename = assure_extension(filename, 'gbs') (filep, filen) = os.path.split(str(filename)) if filen == "Biblioteca.gbs" or filen == "Biblioteca": QMessageBox.question( self.mainW, i18n('Error saving the file'), i18n('The file name dont be equals to library') + '\n' + i18n(''), QMessageBox.Ok) return False else: self.moduleFile = filename myFile = open(filename, 'w') myFile.write(self.mainW.ui.textEditFile.toPlainText().toUtf8()) self.setCurrentPathDirectory(os.path.dirname(filename)) myFile.close() self.mainW.ui.textEditFile.document().setModified(False) self.setTabsNamesAndLabelButtonNameAndSetCurrentPathDirectory( filename) self.loadLibrary() if indexFile == 1: filename = assure_extension(filename, 'gbs') (filep, filen) = os.path.split(str(filename)) if not filen.startswith('Biblioteca'): QMessageBox.question( self.mainW, i18n('Error saving the file'), i18n('The file must be named "Library"') + '\n' + i18n(''), QMessageBox.Ok) return False elif not os.path.exists('Biblioteca.gbs'): self.libraryFile = filename fileLibrary = open(filename, 'w') fileLibrary.write( self.mainW.ui.textEditLibrary.toPlainText().toUtf8()) self.setCurrentPathDirectory(os.path.dirname(filename)) fileLibrary.close() self.mainW.ui.textEditLibrary.document().setModified(False) self.mainW.ui.tabWidgetEditors.setTabText(1, filen) else: self.saveLibrary() self.createInitialsFoldersAndFiles() self.updateClothingOptions() return True
def __init__(self, parent): super(ReplaceWidget, self).__init__(parent) self.setWindowTitle(i18n('Search and replace')) self.resize(QtCore.QSize(300, 120)) self.setModal(False) self.textEditor = self.setEditor() self.textEditor.moveCursor(QtGui.QTextCursor.Start) labelSearch = QtGui.QLabel(i18n('Search')) self.textOld = QtGui.QLineEdit() labelReplace = QtGui.QLabel(i18n('Replace with')) self.textNew = QtGui.QLineEdit() searchButton = QtGui.QPushButton(i18n('Search')) replaceButton = QtGui.QPushButton(i18n('Replace')) replaceAllButton = QtGui.QPushButton(i18n('Replace all')) layout = QtGui.QVBoxLayout() layout2 = QtGui.QGridLayout() layout2.addWidget(labelSearch, 0, 0) layout2.addWidget(self.textOld, 0, 1) layout2.addWidget(labelReplace, 1, 0) layout2.addWidget(self.textNew, 1, 1) layout3 = QtGui.QHBoxLayout() layout3.addWidget(replaceButton) layout3.addWidget(replaceAllButton) layout3.addWidget(searchButton) layout.addLayout(layout2) layout.addLayout(layout3) self.setLayout(layout) self.setStyleSheet( "QDialog {background-color:'white'; border:2px solid #4682b4; border-color:'#4682b4';}" ) searchButton.clicked.connect(self.search) replaceButton.clicked.connect(self.replace) replaceAllButton.clicked.connect(self.replaceAll)