def text_setting(self, text): # set font font = QtGui.QFont() font.setFamily ('Consolas') font.setBold(True) font.setFixedPitch(True) font.setPointSize(12) # set lex lex = Qsci.QsciLexerCPP() lex.setFont(font) text.setLexer(lex) text.setTabWidth(4) text.setUtf8(True) text.setFolding(Qsci.QsciScintilla.BoxedTreeFoldStyle) # set indentation text.setIndentationWidth(4) text.setIndentationGuides(True) text.setAutoIndent(True) text.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll); text.setAutoCompletionThreshold(3) # set brace matching text.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # set Margins text.setMarginsFont(font) fontmetrics = QtGui.QFontMetrics(font) text.setMarginWidth(0, fontmetrics.width("00") + 6) text.setMarginLineNumbers(0, True)
def set_Lexer(self, type=2): #设置解释器 dic = { 0: Qsci.QsciLexerBash(), 1: Qsci.QsciLexerCPP(), 2: Qsci.QsciLexerPython(), 3: Qsci.QsciLexerJava(), } textLexer = dic[type] # textLexer->setColor(QColor(Qt:: yellow), QsciLexerCPP::CommentLine); // 设置自带的注释行为绿色 self.setLexer(textLexer)
def __init__(self, *args, action, **kwargs): self._action = action super().__init__(*args, **kwargs) self._sci = Qsci.QsciScintilla(self) self._sci.setUtf8(True) self._sci.setEolMode(self._sci.EolUnix) self._sci.setIndentationsUseTabs(True) self._sci.setIndentationGuides(True) self._sci.setCaretLineVisible(True) self._sci.setMargins(1) self._sci.setMarginType(0, self._sci.NumberMargin) self._sci.setMarginWidth(0, '000') self._sci.setLexer(Qsci.QsciLexerCPP(self._sci)) self._sci.setText(self._action.source()) self._report = QtWidgets.QTreeWidget(self) self._report.setColumnCount(2) self._report.setHeaderHidden(True) self._report.itemClicked.connect(self._reportClicked) self._errorMarker = self._sci.markerDefine(self._sci.Background) self._sci.setMarkerBackgroundColor(QtCore.Qt.red, self._errorMarker) self._warningMarker = self._sci.markerDefine(self._sci.Background) self._sci.setMarkerBackgroundColor(QtCore.Qt.yellow, self._warningMarker) btnOK = QtWidgets.QPushButton(_('Done'), self) btnCancel = QtWidgets.QPushButton(_('Cancel'), self) bld = LayoutBuilder(self) with bld.vbox() as vbox: vbox.addWidget(self._sci, stretch=5) vbox.addWidget(self._report, stretch=1) with bld.hbox() as buttons: buttons.addStretch(1) buttons.addWidget(btnCancel) buttons.addWidget(btnOK) btnOK.clicked.connect(self.accept) btnCancel.clicked.connect(self.reject) with Settings().grouped('IDE') as settings: if settings.contains('WindowGeometry'): self.restoreGeometry(settings.value('WindowGeometry')) else: self.resize(1024, 768) self._timer = QtCore.QTimer(self) self._timer.timeout.connect(self._tryCompile) self._timer.setSingleShot(True) self._sci.textChanged.connect(self._onTextChanged) self._tryCompile()
def __initScintilla(self): # delete text editor placeholder scintilla = Qsci.QsciScintilla(self) ######################## # setup scintilla # set default font font = QtGui.QFont() font.setFamily('Deja Vu Sans Mono') font.setFixedPitch(True) font.setPointSize(11) # brace matching scintilla.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # set lexer lexer = Qsci.QsciLexerCPP() lexer.setDefaultFont(font) lexer.setFont(font) scintilla.setLexer(lexer) scintilla.setLexer(lexer) scintilla.__myLexer = lexer # save reference to retain scope # auto-completion api scintilla.__myApi = Qsci.QsciAPIs(lexer) scintilla.setAutoCompletionThreshold(1) scintilla.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs) # remove horizontal scrollbar scintilla.SendScintilla(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0) # display default line numbers fm = QtGui.QFontMetrics(font) scintilla.setMarginWidth(0, fm.width("00000")) scintilla.setMarginLineNumbers(0, True) ######################## # insert widget into main vlayout self.ui.vlayout.addWidget(scintilla) self.__scintilla = scintilla
def __init__(self, parent=None): QtWidgets.QMainWindow.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) if getattr(sys, 'frozen', False): iconpath = os.path.join( os.path.dirname(sys.executable), "asc", "data", "icon.svg") pixmap = QtGui.QPixmap(iconpath) else: icon = pkgutil.get_data('asc', os.path.join('data', 'icon.svg')) pixmap = QtGui.QPixmap() pixmap.loadFromData(icon) icon = QtGui.QIcon() icon.addPixmap(pixmap, QtGui.QIcon.Normal, QtGui.QIcon.Off) self.setWindowIcon(icon) # Script mode selector self.ui.modeGroup = QtWidgets.QActionGroup(self) self.ui.actionModeOW = QtWidgets.QAction("OW Script Mode", self) self.ui.actionModeOW.setCheckable(True) self.ui.actionModeAI = QtWidgets.QAction("AI Script Mode", self) self.ui.actionModeAI.setCheckable(True) self.ui.menuSettings.addAction(self.ui.actionModeOW) self.ui.menuSettings.addAction(self.ui.actionModeAI) self.ui.modeGroup.addAction(self.ui.actionModeOW) self.ui.modeGroup.addAction(self.ui.actionModeAI) self.ui.actionModeOW.setChecked(True) self.mode = "ow" cons = ((self.ui.actionOpen, self.load_file), (self.ui.actionNew, self.new_file), (self.ui.actionSave, self.save_file), (self.ui.actionSave_As, self.save_as), (self.ui.actionLoad_ROM, self.load_rom), (self.ui.actionQuit, self.close), (self.ui.actionDecompile, self.decompile), (self.ui.actionCompile, self.action_compile), (self.ui.actionDebug, self.action_debug), (self.ui.actionCut, self.ui.textEdit.cut), (self.ui.actionCopy, self.ui.textEdit.copy), (self.ui.actionPaste, self.ui.textEdit.paste), (self.ui.actionDelete, self.ui.textEdit.removeSelectedText), (self.ui.actionUndo, self.ui.textEdit.undo), (self.ui.actionRedo, self.ui.textEdit.redo), (self.ui.actionFind, self.find), (self.ui.actionInsert_String, self.insert_string), (self.ui.actionAbout, self.help_about), (self.ui.actionModeOW, self.set_mode_ow), (self.ui.actionModeAI, self.set_mode_ai)) for action, function in cons: action.triggered.connect(function) self.rom_file_name = "" self.file_name = "" # QScintilla self.ui.textEdit.setMarginLineNumbers(1, True) self.ui.textEdit.setMarginWidth(1, 30) self.font = QtGui.QFont("mono", 10) self.ui.textEdit.setFont(self.font) lexer = Qsci.QsciLexerCPP() lexer.setDefaultFont(self.font) self.ui.textEdit.setLexer(lexer) self.ui.textEdit.setText(asc.get_canvas())