def keywords(self, keyset): """return standard keywords and extra keywords.""" if keyset == 1: return ' '.join(self.extraKeywords1) + ' ' + QsciLexerPython.keywords(self, keyset) elif keyset == 2: return ' '.join(self.extraKeywords2) return QsciLexerPython.keywords(self, keyset)
def defaultKeywords(self, kwSet): """ Public method to get the default keywords. @param kwSet number of the keyword set (integer) @return string giving the keywords (string) or None """ if kwSet == 1: if self.language() in ["Python", "Python2"]: keywords = ("and as assert break class continue def del elif " "else except exec finally for from global if " "import in is lambda not or pass print raise " "return try while with yield") elif self.language() == "Python3": keywords = ("False None True and as assert break class " "continue def del elif else except finally for " "from global if import in is lambda nonlocal not " "or pass raise return try while with yield") elif self.language() == "Cython": keywords = ("False None True and as assert break class " "continue def del elif else except finally for " "from global if import in is lambda nonlocal not " "or pass raise return try while with yield " "cdef cimport cpdef ctypedef") else: keywords = QsciLexerPython.keywords(self, kwSet) else: keywords = QsciLexerPython.keywords(self, kwSet) return keywords
def setupEditor(self): self.editor.setFont(QFont("Times New Roman", 12)) self.editor.setMargins(2) self.editor.setMarginType(0, QsciScintilla.NumberMargin) self.editor.setMarginType(1, QsciScintilla.SymbolMargin) self.editor.setMarginWidth(0, "000") self.editor.setMarginWidth(1, "00") self.editor.markerDefine(QsciScintilla.RightTriangle, 1) if system() == "Windows": self.editor.setEolMode(QsciScintilla.EolWindows) elif system() == "Linux": self.editor.setEolMode(QsciScintilla.EolUnix) elif system() == "Mac": self.editor.setEolMode(QsciScintilla.EolMac) else: print("Using Windows EOL") self.editor.setEolMode(QsciScintilla.EolWindows) self.editor.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.editor.setIndentationsUseTabs(True) self.editor.setTabWidth(4) self.editor.setIndentationGuides(True) self.editor.setTabIndents(True) self.editor.setAutoIndent(True) self.editor.setCaretForegroundColor(QColor("#ff11214b")) self.editor.setCaretLineVisible(True) self.editor.setCaretLineBackgroundColor(QColor("#1f0000ff")) self.editor.setUtf8(True) self.editor.setMarginSensitivity(1, True) self.editor.marginClicked.connect(self.margin_clicked) self.editor.marginRightClicked.connect(self.margin_right_clicked) self.lexer = QsciLexerPython() self.lexer.setFont(QFont("Times New Roman", 12)) self.editor.setLexer(self.lexer) self.editor.textChanged.connect(self.fileChanged)
def lock(self): """ Sets the default properties for the Python lexer. """ # Lexer Initialization lexer = QsciLexerPython(self.ui.code_editor) lexer.setDefaultFont(self.font) self.ui.code_editor.setLexer(lexer) # Auto Completion api = QsciAPIs(lexer) for var in dir(builtins): if not (var[0] == "_"): api.add(var) api.prepare() self.ui.code_editor.setAutoCompletionThreshold(1) self.ui.code_editor.setAutoCompletionSource(QsciScintilla.AcsAPIs) # Auto Indentation self.ui.code_editor.setAutoIndent(True) self.ui.code_editor.setIndentationGuides(True) self.ui.code_editor.setIndentationsUseTabs(True) self.ui.code_editor.setIndentationWidth(4) # Font Settings font_metrics = QFontMetrics(self.font) self.ui.code_editor.setMinimumSize(int(font_metrics.width("0" * 80)), 0)
def __init__(self, code): super(QDialog, self).__init__() self.codeEdit = QsciScintilla() self.codeEdit.setText(code) fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.codeEdit.setFont(fixedWidthFont) fontmetrics = QFontMetrics(fixedWidthFont) self.codeEdit.setMarginWidth(0, fontmetrics.width("000")) self.codeEdit.setMarginLineNumbers(0, True) self.codeEdit.setMarginsBackgroundColor(QColor("#cccccc")) self.codeEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.codeEdit.setCaretLineVisible(True) self.codeEdit.setCaretLineBackgroundColor(QColor("#ffe4e4")) lexer = QsciLexerPython() lexer.setDefaultFont(fixedWidthFont) self.codeEdit.setLexer(lexer) self.codeEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.codeEdit.setUtf8(True) self.codeEdit.setTabWidth(4) self.codeEdit.setIndentationsUseTabs(True) self.codeEdit.setIndentationGuides(True) self.codeEdit.setTabIndents(True) self.codeEdit.setAutoIndent(True) verticalLayout = QVBoxLayout() verticalLayout.addWidget(self.codeEdit) self.setLayout(verticalLayout) self.codeEdit.textChanged.connect(self.changeCode)
def __init__(self, name, currentValue): super(QDialog, self).__init__() self.setWindowTitle(name) self.resize(800, 600) self.codeEdit = QsciScintilla() self.codeEdit.setText(currentValue) fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.codeEdit.setFont(fixedWidthFont) fontmetrics = QFontMetrics(fixedWidthFont) self.codeEdit.setMarginWidth(0, fontmetrics.width("000")) self.codeEdit.setMarginLineNumbers(0, True) self.codeEdit.setMarginsBackgroundColor(QColor("#cccccc")) self.codeEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.codeEdit.setCaretLineVisible(True) self.codeEdit.setCaretLineBackgroundColor(QColor("#ffe4e4")) lexer = QsciLexerPython() lexer.setDefaultFont(fixedWidthFont) self.codeEdit.setLexer(lexer) self.codeEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.codeEdit.setUtf8(True) self.codeEdit.setTabWidth(4) self.codeEdit.setIndentationsUseTabs(True) self.codeEdit.setIndentationGuides(True) self.codeEdit.setTabIndents(True) self.codeEdit.setAutoIndent(True) self.cancelButton = QPushButton('Cancel') self.cancelButton.clicked.connect(self.cancel) self.acceptButton = QPushButton('Accept') self.acceptButton.clicked.connect(self.accept) self.pythonButton = QRadioButton('Python') self.pythonButton.setChecked(True) self.pythonButton.clicked.connect(self.pythonClicked) self.cppButton = QRadioButton('C++') self.cppButton.clicked.connect(self.cppClicked) hLayout0 = QHBoxLayout() hLayout0.addWidget(self.pythonButton) hLayout0.addWidget(self.cppButton) container0 = QWidget() container0.setLayout(hLayout0) verticalLayout = QVBoxLayout() verticalLayout.addWidget(container0) verticalLayout.addWidget(self.codeEdit) container = QWidget() hLayout =QHBoxLayout() hLayout.addWidget(self.cancelButton) hLayout.addWidget(self.acceptButton) container.setLayout(hLayout) verticalLayout.addWidget(container) self.setLayout(verticalLayout) self.language = 'python'
def __init__(self, name, currentValue): super(QDialog, self).__init__() self.setWindowTitle(name) self.resize(800, 600) self.codeEdit = QsciScintilla() self.codeEdit.setText(currentValue) fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.codeEdit.setFont(fixedWidthFont) fontmetrics = QFontMetrics(fixedWidthFont) self.codeEdit.setMarginWidth(0, fontmetrics.width("000")) self.codeEdit.setMarginLineNumbers(0, True) self.codeEdit.setMarginsBackgroundColor(QColor("#cccccc")) self.codeEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.codeEdit.setCaretLineVisible(True) self.codeEdit.setCaretLineBackgroundColor(QColor("#ffe4e4")) lexer = QsciLexerPython() lexer.setDefaultFont(fixedWidthFont) self.codeEdit.setLexer(lexer) self.codeEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.codeEdit.setUtf8(True) self.codeEdit.setTabWidth(4) self.codeEdit.setIndentationsUseTabs(True) self.codeEdit.setIndentationGuides(True) self.codeEdit.setTabIndents(True) self.codeEdit.setAutoIndent(True) self.cancelButton = QPushButton('Cancel') self.cancelButton.clicked.connect(self.cancel) self.acceptButton = QPushButton('Accept') self.acceptButton.clicked.connect(self.accept) self.pythonButton = QRadioButton('Python') self.pythonButton.setChecked(True) self.pythonButton.clicked.connect(self.pythonClicked) self.cppButton = QRadioButton('C++') self.cppButton.clicked.connect(self.cppClicked) hLayout0 = QHBoxLayout() hLayout0.addWidget(self.pythonButton) hLayout0.addWidget(self.cppButton) container0 = QWidget() container0.setLayout(hLayout0) verticalLayout = QVBoxLayout() verticalLayout.addWidget(container0) verticalLayout.addWidget(self.codeEdit) container = QWidget() hLayout = QHBoxLayout() hLayout.addWidget(self.cancelButton) hLayout.addWidget(self.acceptButton) container.setLayout(hLayout) verticalLayout.addWidget(container) self.setLayout(verticalLayout) self.language = 'python'
def _init_lexer(self): """ 初始化语法解析器 Returns: """ self._lexer = QsciLexerPython(self.textEdit) self._lexer.setFont(self.textEdit.font()) self.textEdit.setLexer(self._lexer)
def __init__(self, parent=None): super(EditWindow, self).__init__(parent) # Set the default font font = QtGui.QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = QtGui.QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("00000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QtGui.QColor("#cccccc")) self.setIndentationsUseTabs(False) self.setIndentationWidth(4) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) self.marginClicked.connect(self.on_margin_clicked) # debug marker self.markerDefine(QsciScintilla.Circle, self.DEBUG_MARKER_NUM) self.setMarkerBackgroundColor(QtGui.QColor("#1111ee"), self.DEBUG_MARKER_NUM) # execute marker self.markerDefine(QsciScintilla.Circle, self.EXEC_MARKER_NUM) self.setMarkerBackgroundColor(QtGui.QColor("#11ee11"), self.EXEC_MARKER_NUM) # crash marker self.markerDefine(QsciScintilla.Circle, self.CRASH_MARKER_NUM) self.setMarkerBackgroundColor(QtGui.QColor("#ee1111"), self.CRASH_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position # self.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4")) # Set Python lexer lexer = QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) text = bytearray(str.encode("Arial")) self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, text) # not too small self.setMinimumSize(600, 450) self.last_exec_line = 0
def __init__(self): self.lexer = QsciLexerPython() self.apis = QsciAPIs(self.lexer) self.lexer.setAPIs(self.apis) self.apis.apiPreparationFinished.connect( self.slotApiPreparationFinished) for fn in API_FILES: ok = self.apis.load(PATH + '/api_raw/' + fn) self.apis.prepare()
def __init__(self, parent=None): super().__init__(parent) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(12) self.setFont(font) self.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("0000")) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#cccccc")) self.setTabWidth(4) # # Clickable margin 1 for showing markers # self.setMarginSensitivity(1, True) # self.marginClicked.connect(self.on_margin_clicked) # self.markerDefine(QsciScintilla.RightArrow, # self.ARROW_MARKER_NUM) # self.setMarkerBackgroundColor(QColor("#ee1111"), # self.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position # self.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. # lexer = QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) text = bytearray(str.encode("Courier")) self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, text) self.SendScintilla(QsciScintilla.SCI_STYLESETSIZE, 1, 12) # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented # here: http://www.scintilla.org/ScintillaDoc.html) self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.setScrollWidth(1)
def __init__(self, variant="", parent=None): """ Constructor @param variant name of the language variant (string) @param parent parent widget of this lexer """ QsciLexerPython.__init__(self, parent) Lexer.__init__(self) self.variant = variant self.commentString = "#"
def __init__(self, parent=None): super(PythonSTC, self).__init__(parent) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("00000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#cccccc")) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) self.marginClicked[int, int, Qt.KeyboardModifiers].connect(self.on_margin_clicked) self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position # self.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. # lexer = QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, b'Courier') # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented # here: http://www.scintilla.org/ScintillaDoc.html) self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) # not too small self.setMinimumSize(600, 450)
def __init__(self, parent): QsciLexerPython.__init__(self, parent) self.setFont(QtGui.QFont('Consolas', 14)) # 设置默认字体 self.setColor(QColor(0, 0, 0)) # 设置默认的字体颜色 self.setPaper(QColor(255, 255, 255)) # 设置底色 self.setColor(QColor("#B0171F"), QsciLexerPython.Keyword) self.setColor(QColor("#008000"), QsciLexerPython.Comment) # 文档注释 /**开头的颜色 self.setColor(QColor("#008000"), QsciLexerPython.Comment) # 块注释 的颜色 self.setColor(QColor("#007f7f"), QsciLexerPython.Number) # 数字 的颜色 self.setColor(QColor("#ff00ff"), QsciLexerPython.DoubleQuotedString) # 双引号字符串的颜色 self.setColor(QColor("#ff00ff"), QsciLexerPython.SingleQuotedString) # 单引号字符的颜色 self.setColor(QColor("#191970"), QsciLexerPython.Operator) self.setColor(QColor("#0000FF"), QsciLexerPython.UnclosedString) # 未完成输入的字符串的颜色
def __init__(self): QsciLexerPython.__init__(self) for key, attrib in self.default_style.items(): value = self.token_id[key] self.setColor(QColor(attrib[1]), value) self.setEolFill(True, value) self.setPaper(QColor(attrib[5]), value) self.setPaper(QColor(attrib[5]), value) font = QFont(attrib[0], attrib[2]) font.setBold(attrib[3]) font.setItalic(attrib[4]) self.setFont(font, value) self.setDefaultPaper(QColor("#ffffff"))
class Main(): def __init__(self): self.lexer = QsciLexerPython() self.apis = QsciAPIs(self.lexer) self.lexer.setAPIs(self.apis) self.apis.apiPreparationFinished.connect( self.slotApiPreparationFinished) for fn in API_FILES: ok = self.apis.load(PATH + '/api_raw/' + fn) self.apis.prepare() def slotApiPreparationFinished(self): self.apis.savePrepared(PATH + '/prepared.api') print('Done.') QApplication.quit()
def createCodeGroupBox(self, parent): yPos = const.GROUP_BOX_MARGIN_TOP width = AlgorithmDescDialog.WINDOW_WIDTH - const.PADDING * 4 box = WidgetUtil.createGroupBox(parent, title="代码实现", minSize=QSize(width, AlgorithmDescDialog.DESC_GROUP_BOX_HEIGHT)) # sizePolicy = WidgetUtil.createSizePolicy() splitter = WidgetUtil.createSplitter(box, geometry=QRect(const.PADDING, yPos, width - const.PADDING * 2, 330)) tabWidget = WidgetUtil.createTabWidget(splitter) if self.javaCode: tabWidget.addTab(self.createTabWidget(self.javaCode, QsciLexerJava()), "Java") if self.javaScriptCode: tabWidget.addTab(self.createTabWidget(self.javaScriptCode, QsciLexerJavaScript()), "JavaScript") if self.pythonCode: tabWidget.addTab(self.createTabWidget(self.pythonCode, QsciLexerPython()), "Python") if self.cCode: tabWidget.addTab(self.createTabWidget(self.cCode, QsciLexerCPP()), "C") if self.cppCode: tabWidget.addTab(self.createTabWidget(self.cppCode, QsciLexerCPP()), "C++") if self.swiftCode: tabWidget.addTab(self.createTabWidget(self.swiftCode, QsciLexerCPP()), "Swift") return box
def set_lexer(self, language): r""" 多语法代码高亮 :param language: :return: """ font = self.font_content['font'] size = int(self.font_content['size']) lexer_font = QFont(font, size) if language == 'py': self.lxr = QsciLexerPython() self.lxr.setFont(lexer_font) self.setLexer(self.lxr) self.__pythonCompletion() elif language == 'c': self.lxr = QsciLexerCPP() self.lxr.setFont(lexer_font) self.setLexer(self.lxr) self.__cCompletion() elif language == 'md': self.lxr = QsciLexerMarkdown() self.lxr.setFont(lexer_font) self.setLexer(self.lxr) else: self.setLexer(None) self.setText(self.text())
def Setup(self): # Setting the size to be fixed self.setFixedSize(800, 800) # adding the the custom editor of QsciScintilla self.editor = QsciScintilla() self.editor.setGeometry(25, 25, 750, 750) # adding text to the ditro self.editor.append("print('Hello World!') # this is just a test") # this is i am not sure yet but i think its for the syntax self.python_syntax = QsciLexerPython() self.editor.setLexer(self.python_syntax) self.editor.setUtf8(True) # Set encoding to UTF-8 # setting editor position # adding font self.Font = QFont() # adding text size self.Font.setPointSize(16) # applying font self.editor.setFont(self.Font) # Will be overridden by lexer! # adding the editor to te form self.layout().addWidget(self.editor) # showing ui self.show()
def defaultKeywords(self, kwSet): """ Public method to get the default keywords. @param kwSet number of the keyword set (integer) @return string giving the keywords (string) or None """ return QsciLexerPython.keywords(self, kwSet)
def __init__(self): super().__init__() self.dir = path.join(path.dirname(__file__), "../data/custompreview") self.file = path.join(self.dir, "__init__.py") self.cachedir = path.join(self.dir, "../cache") self.cachefile = path.join(self.cachedir, "custom.py") self.setLexer(QsciLexerPython(self)) self.load(self.file) self.custom = None
def language(self): """ Public method to get the lexer language. @return lexer language (string) """ if not self.variant: return QsciLexerPython.language(self) else: return self.variant
def __init__(self): super(PyOneScript, self).__init__() self.setAttribute(Qt.WA_DeleteOnClose) self.isUntitled = True font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) self.setMarginSensitivity(1, True) self.marginClicked.connect(self.on_margin_clicked) self.markerDefine(QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) self.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.setEolMode(Qsci.QsciScintilla.EolUnix) self.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll) self.setAutoCompletionThreshold(1) self.setAutoIndent(True) self.setIndentationsUseTabs(True) self.setTabWidth(4) self.setAutoCompletionFillupsEnabled(True) self.setBraceMatching(Qsci.QsciScintilla.StrictBraceMatch) self.setMarginLineNumbers(1, 1) self.setMarginWidth(1, 35) self.setUtf8(True) self.setEolVisibility(False) self.setMinimumSize(600, 450) self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#ffe4e4")) self.lexer = QsciLexerPython() self.lexer.setDefaultFont(font) self.setLexer(self.lexer) self.sense = Qsci.QsciAPIs(self.lexer) self.sense.prepare() self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
def __init__(self, parent=None): super(PMPythonEditor, self).__init__(parent, comment_string='#') self._extension_names.append('.py') self._init_editor() self._init_lexer(QsciLexerPython(self.textEdit)) self._init_apis() self._init_actions() self._init_signals() # 编辑器主题 self.slot_set_theme(self._theme) self.last_hint = ''
def onSet(self): #from subprocess import call #call("notepad ./Project/Sequences/DefaultSequence.py") self.editor = QsciScintilla() # define the font to use font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) # the font metrics here will help # building the margin width later fm = QFontMetrics(font) ## set the default font of the editor ## and take the same font for line numbers self.editor.setFont(font) self.editor.setMarginsFont(font) ## Line numbers # conventionnaly, margin 0 is for line numbers self.editor.setMarginWidth(0, fm.width("00000") + 5) self.editor.setMarginLineNumbers(0, True) ## Edge Mode shows a red vetical bar at 80 chars self.editor.setEdgeMode(QsciScintilla.EdgeLine) self.editor.setEdgeColumn(80) self.editor.setEdgeColor(QColor("#FF0000")) ## Folding visual : we will use boxes self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) ## Braces matching self.editor.setBraceMatching(QsciScintilla.SloppyBraceMatch) ## Editing line color self.editor.setCaretLineVisible(True) self.editor.setCaretLineBackgroundColor(QColor("#CDA869")) ## Margins colors # line numbers margin self.editor.setMarginsBackgroundColor(QColor("#333333")) self.editor.setMarginsForegroundColor(QColor("#CCCCCC")) # folding margin colors (foreground,background) self.editor.setFoldMarginColors(QColor("#99CC66"), QColor("#333300")) ## Choose a lexer lexer = QsciLexerPython() lexer.setDefaultFont(font) api = QsciStrictAPIs(lexer) api.prepare() lexer.setDefaultFont(font) self.editor.setLexer(lexer) self.editor.setMinimumSize(1024, 768) self.editor.show() ## Show this file in the editor text = open("./Project/Sequences/DefaultSequence.py").read() self.editor.setText(text)
def checkExtensionToHighlight(self, path, editor): _, extension = os.path.splitext(path) if extension == '.py': editor.setLexer(QsciLexerPython(self)) elif extension == '.html': editor.setLexer(QsciLexerHTML(self)) elif extension == '.java': editor.setLexer(QsciLexerJava(self)) elif extension == '.cs': editor.setLexer(QsciLexerCSharp(self)) elif extension == '.bat': editor.setLexer(QsciLexerBatch(self))
def __init__(self, parent=None): super(CodeEditor, self).__init__(parent) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) self.setTabWidth(4) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("00000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#90FF90")) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) self.marginClicked.connect(self.on_margin_clicked) # Brace matching: enable for a brace immediately before or after the current position self.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width courier. lexer = QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) text = bytearray(str.encode("Arial")) # 32, "Courier New" self.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, text) # Don't want to see the horizontal scrollbar at all self.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)
def create_qscintilla_code_view(): """ Create a QScintilla based view containing a copy of this source code. """ from PyQt5.Qsci import QsciLexerPython, QsciScintilla view = QsciScintilla() view.setReadOnly(True) view.setUtf8(True) view.setLexer(QsciLexerPython()) view.setFolding(QsciScintilla.PlainFoldStyle) view.setText(get_source_code()) return view
def __init__(self, style, paper): QsciLexerPython.__init__(self) self.lexerPaper = paper for key, attrib in style.items(): value = propertyID[key] self.setColor(QtGui.QColor(attrib[1]), value) self.setEolFill(True, value) self.setPaper(QtGui.QColor(attrib[5]), value) if self.lexerPaper[0] == "Plain": self.setPaper(QtGui.QColor(attrib[5]), value) else: self.setPaper(QtGui.QColor(self.lexerPaper[1]), value) font = QtGui.QFont(attrib[0], attrib[2]) font.setBold(attrib[3]) font.setItalic(attrib[4]) self.setFont(font, value) if self.lexerPaper[0] == "Plain": self.setDefaultPaper(QtGui.QColor("#ffffff")) else: self.setDefaultPaper(QtGui.QColor(self.lexerPaper[1]))
def __init__(self): """ Invoked to return the default editor widget. """ from PyQt5.Qsci import QsciLexerPython, QsciScintilla editor = QsciScintilla() # Configure the editor for Python. editor.setUtf8(True) editor.setLexer(QsciLexerPython(editor)) editor.setFolding(QsciScintilla.PlainFoldStyle, 1) editor.setIndentationGuides(True) editor.setIndentationWidth(4) self.editor = editor
def __init__(self, layout_dir: str, title: str, initial_value: str = '', lexer=''): super().__init__(layout_dir) self.on_check_callback = None self.prefix = QLabel(text=title) entryLayout = QHBoxLayout() entryLayout.setContentsMargins(0, 0, 0, 0) self.ctrl = QsciScintilla() if lexer == 'python': self.ctrl.setLexer(QsciLexerPython()) self.ctrl.setText(initial_value) # self.ctrl.textChanged.connect(self.ontext) # self.postfix = lab_unit = QLabel(text=unit) self.central_layout.addWidget(self.prefix) self.central_layout.addLayout(entryLayout) entryLayout.addWidget(self.ctrl) self.set_value(initial_value)
def pythonClicked(self): fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont) lexer = QsciLexerPython() lexer.setDefaultFont(fixedWidthFont) self.codeEdit.setLexer(lexer) self.language = 'python'
def keywords(self, order: int) -> str: if order == 2: return "self True False" else: return QsciLexerPython.keywords(self, order)
def __init__(self, *args): QsciLexerPython.__init__(self, *args) self.setIndentationWarning(QsciLexerPython.Tabs)
class Ui_MainWindow(object): ARROW_MARKER_NUM = 8 def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(640, 480) self.vindu = QtWidgets.QWidget(MainWindow) self.vindu.setStyleSheet(_fromUtf8("notusedasyet")) # MainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) self.filename = "" self.vindu.setObjectName(_fromUtf8("vindu")) self.verticalLayout = PyQt5.QtWidgets.QVBoxLayout(self.vindu) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/ico/python.png")), QtGui.QIcon.Normal, QtGui.QIcon.On) MainWindow.setWindowIcon(icon) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setSpacing(0) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.codebox = Qsci.QsciScintilla(self.vindu) self.codebox.setToolTip(_fromUtf8("")) self.codebox.setWhatsThis(_fromUtf8("")) self.codebox.setAutoFillBackground(False) self.codebox.setFrameShape(QtWidgets.QFrame.NoFrame) self.codebox.setObjectName(_fromUtf8("codebox")) self.verticalLayout.addWidget(self.codebox) MainWindow.setCentralWidget(self.vindu) # toolbar self.toolBar = QtWidgets.QToolBar(MainWindow) self.toolBar.setAutoFillBackground(False) self.toolBar.setIconSize(QtCore.QSize(32, 32)) self.toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) self.toolBar.setObjectName(_fromUtf8("toolBar2")) MainWindow.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolBar) self.toolBar.addSeparator() # toolbar2 debugger # self.toolBar2 = QtGui.QToolBar(MainWindow) # self.toolBar2.setAutoFillBackground(False) # self.toolBar2.setIconSize(QtCore.QSize(32, 32)) # self.toolBar2.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) # self.toolBar2.setObjectName(_fromUtf8("toolBar")) # MainWindow.addToolBar(QtCore.Qt.RightToolBarArea, self.toolBar2) # self.toolBar2.addSeparator() # getting ready for debugger self.codebox.setMarginSensitivity(1, True) self.codebox.marginClicked.connect(self.on_margin_clicked) self.codebox.markerDefine(QsciScintilla.FullRectangle, self.ARROW_MARKER_NUM) self.codebox.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) # first action Newfile self.toolBar.newAction = QtWidgets.QAction(QtGui.QIcon(":/ico/new.png"), "New", self.toolBar) self.toolBar.newAction.setStatusTip("Clear TextBox or make new document.") self.toolBar.newAction.setShortcut("Ctrl+N") self.toolBar.newAction.triggered.connect(self.newfile) # second Action OpenFile self.toolBar.secondAction = QtWidgets.QAction(QtGui.QIcon(":/ico/open.png"), "Open", self.toolBar) self.toolBar.secondAction.setStatusTip("Create a new document from scratch.") self.toolBar.secondAction.setShortcut("Ctrl+O") self.toolBar.secondAction.triggered.connect(self.open) # action 3 save file self.toolBar.Action3 = QtWidgets.QAction(QtGui.QIcon(":/ico/save.png"), "Save", self.toolBar) self.toolBar.Action3.setStatusTip("Save Your File.") self.toolBar.Action3.setShortcut("Ctrl+S") self.toolBar.Action3.triggered.connect(self.savefile) # action 4 run file self.toolBar.Action4 = QtWidgets.QAction(QtGui.QIcon(":/ico/run32.png"), "Run", self.toolBar) self.toolBar.Action4.setStatusTip("Run") self.toolBar.Action4.setShortcut("Ctrl+E") self.toolBar.Action4.triggered.connect(self.runto) # action 21 debug # self.toolBar2.Action21 = QtGui.QAction(QtGui.QIcon(":/ico/run32.png"),"Debug",self.toolBar) # self.toolBar2.Action21.setStatusTip("Debug File.") # self.toolBar2.Action21.setShortcut("Ctrl+7") # self.toolBar2.Action21.triggered.connect(self.debugto) # action 6 undo self.toolBar.Action6 = QtWidgets.QAction(QtGui.QIcon(":/ico/undo.png"), "Redo", self.toolBar) self.toolBar.Action6.setStatusTip("Undo.") self.toolBar.Action6.setShortcut("Ctrl+Z") self.toolBar.Action6.triggered.connect(self.codebox.undo) # action 7 redo self.toolBar.Action7 = QtWidgets.QAction(QtGui.QIcon(":/ico/redo.png"), "Redo", self.toolBar) self.toolBar.Action7.setStatusTip("Redo.") self.toolBar.Action7.setShortcut("Ctrl+Y") self.toolBar.Action7.triggered.connect(self.codebox.redo) # action8 rerset Folding self.toolBar.Action8 = QtWidgets.QAction(QtGui.QIcon(":/ico/align-justify.png"), "Reset Folding", self.toolBar) self.toolBar.Action8.setStatusTip("Reset Folding.") self.toolBar.Action8.setShortcut("Ctrl+R") self.toolBar.Action8.triggered.connect(self.nofoldingl) # actions9 CircledTreeFoldStyle self.toolBar.Action9 = QtWidgets.QAction(QtGui.QIcon(":/ico/bullet.png"), "Circled Tree Folding", self.toolBar) self.toolBar.Action9.setStatusTip("Circled Tree Folding.") self.toolBar.Action9.setShortcut("Ctrl+C") self.toolBar.Action9.triggered.connect(self.Circledfold) # actions10 plainFoldStyle self.toolBar.Action10 = QtWidgets.QAction(QtGui.QIcon(":/ico/number.png"), "Plain Folding", self.toolBar) self.toolBar.Action10.setStatusTip("Plain Folding") self.toolBar.Action10.setShortcut("Ctrl+P") self.toolBar.Action10.triggered.connect(self.plainfold) # fonts self.toolBar.Action21 = QtWidgets.QAction(QtGui.QIcon(":/ico4/font.png"), "Fonts", self.toolBar) self.toolBar.Action21.setStatusTip("Fonts") self.toolBar.Action21.setShortcut("Ctrl+F") self.toolBar.Action21.triggered.connect(self.font_choice) # web baby self.toolBar.Action11 = QtWidgets.QAction(QtGui.QIcon(":/ico/web.png"), "Hex-rays Homepage", self.toolBar) self.toolBar.Action11.setStatusTip("Home of Hex-rays") self.toolBar.Action11.setShortcut("Ctrl+W") self.toolBar.Action11.triggered.connect(self.webopen) # irc self.toolBar.Action12 = QtWidgets.QAction( QtGui.QIcon(":/ico3/settings.png"), "Open Ida Pro Python SDK", self.toolBar ) self.toolBar.Action12.setStatusTip("Ida Pro Python SDK") self.toolBar.Action12.setShortcut("Ctrl+I") self.toolBar.Action12.triggered.connect(self.sdkopen) # github Python self.toolBar.Action14 = QtWidgets.QAction(QtGui.QIcon(":/ico/github.png"), "Open git python", self.toolBar) self.toolBar.Action14.setStatusTip("Open git python") self.toolBar.Action14.setShortcut("Ctrl+G") self.toolBar.Action14.triggered.connect(self.gitopen) # auther me :) self.toolBar.Action15 = QtWidgets.QAction(QtGui.QIcon(":/ico/auth.png"), "Author", self.toolBar) self.toolBar.Action15.setStatusTip("Author") self.toolBar.Action15.setShortcut("Ctrl+B") self.toolBar.Action15.triggered.connect(self.Author) # toggle off code regonision self.toolBar.Action16 = QtWidgets.QAction( QtGui.QIcon(":/ico2/pythonminus.png"), "Disable Code recognition", self.toolBar ) self.toolBar.Action16.setStatusTip("Disable Code recognition") self.toolBar.Action16.setShortcut("Alt+D") self.toolBar.Action16.triggered.connect(self.Diablecode) # toogle on self.toolBar.Action17 = QtWidgets.QAction( QtGui.QIcon(":/ico2/pypluss.png"), "Enable Code recognition", self.toolBar ) self.toolBar.Action17.setStatusTip("Enable Code recognition") self.toolBar.Action17.setShortcut("Alt+E") self.toolBar.Action17.triggered.connect(self.Reiablecode) # zoom in self.toolBar.Action18 = QtWidgets.QAction(QtGui.QIcon(":/ico3/in.png"), "Zoom In", self.toolBar) self.toolBar.Action18.setStatusTip("Zoom In") self.toolBar.Action18.setShortcut("CTRL+SHIFT++") self.toolBar.Action18.triggered.connect(self.udder) # zoom out self.toolBar.Action19 = QtWidgets.QAction(QtGui.QIcon(":/ico3/out.png"), "Zoom Out", self.toolBar) self.toolBar.Action19.setStatusTip("Zoom Out") self.toolBar.Action19.setShortcut("CTRL+SHIFT+-") self.toolBar.Action19.triggered.connect(self.odder) self.toolBar.Action20 = QtWidgets.QAction(QtGui.QIcon(":/ico3/10.png"), "Profile Code", self.toolBar) self.toolBar.Action20.setStatusTip("Profile Code") self.toolBar.Action20.setShortcut("CTRL+SHIFT+E") self.toolBar.Action20.triggered.connect(self.runtoprob) # actions self.toolBar.addAction(self.toolBar.newAction) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.secondAction) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action3) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action4) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action6) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action7) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action8) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action9) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action10) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action21) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action11) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action12) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action14) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action15) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action16) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action17) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action18) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action19) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action20) # self.toolBar2.addAction(self.toolBar.Action21) # self.toolBar2.addSeparator() # font self.skrift = QFont() self.skrift.setFamily("Consolas") self.skrift.setFixedPitch(True) self.skrift.setPointSize(12) self.codebox.setFont(self.skrift) # python style self.lexer = QsciLexerPython(self.codebox) self.lexer.setFont(self.skrift) self.lexer.setEolFill(True) # api test not working api = Qsci.QsciAPIs(self.lexer) API_FILE = dn + "\\Python.api" API_FILE2 = dn + "\\idc.api" API_FILE3 = dn + "\\idaapi.api" api.load(API_FILE) api.load(API_FILE2) api.load(API_FILE3) api.prepare() self.codebox.setAutoCompletionThreshold(0) self.codebox.setAutoCompletionThreshold(6) self.codebox.setAutoCompletionThreshold(8) self.codebox.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs) self.lexer.setDefaultFont(self.skrift) self.codebox.setLexer(self.lexer) self.codebox.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, "Consolas") # line numbers fontmetrics = QFontMetrics(self.skrift) self.codebox.setMarginsFont(self.skrift) self.codebox.setMarginWidth(0, fontmetrics.width("00000") + 6) self.codebox.setTabWidth(4) # brace self.codebox.setBraceMatching(QsciScintilla.SloppyBraceMatch) # auto line tab =4 self.codebox.setAutoIndent(True) # scroolbar self.codebox.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 1) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(_translate("MainWindow", "Ida Pro Python Script Editor", None)) self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar", None)) def udder(self): self.codebox.zoomIn() def odder(self): self.codebox.zoomOut() def newfile(self): self.codebox.clear() def open(self): self.path = QtCore.QFileInfo(self.filename).path() # Get filename and show only .writer files (self.filename, _) = QtWidgets.QFileDialog.getOpenFileName( self.vindu, "Open File", self.path, "Python Files (*.py *.pyc *.pyw)", "" ) if self.filename: with open(self.filename, "r") as self.file: self.codebox.setText(self.file.read()) os.chdir(str(self.path)) def savefile(self): self.path = QtCore.QFileInfo(self.filename).path() (self.filename, _) = QtWidgets.QFileDialog.getSaveFileName( self.vindu, "Save as", self.path, "Python Files (*.py *.pyc *.pyw)" ) if self.filename: self.savetext(self.filename) os.chdir(str(self.path)) def savetext(self, fileName): textout = self.codebox.text() file = QtCore.QFile(fileName) if file.open(QtCore.QIODevice.WriteOnly): QtCore.QTextStream(file) << textout else: QtWidgets.QMessageBox.information(self.vindu, "Unable to open file", file.errorString()) os.chdir(str(self.path)) def runto(self): self.path = QtCore.QFileInfo(self.filename).path() g = globals() os.chdir(str(self.path)) script = str(self.codebox.text()) try: os.chdir(str(self.path)) os.path.join(os.path.expanduser("~"), os.path.expandvars(str(self.path))) sys.path.insert(0, str(self.path)) exec (script, g) except Exception as e: print e.__doc__ print e.message else: exec (script, g) def runtoprob(self): try: self.path = QtCore.QFileInfo(self.filename).path() self.path = QtCore.QFileInfo(self.filename).path() g = globals() os.chdir(str(self.path)) script = str(self.codebox.text()) import cProfile cProfile.run(script) except Exception as e: print e.__doc__ print e.message else: import cProfile cProfile.run(script) def Diablecode(self): self.codebox.setAutoCompletionSource(Qsci.QsciScintilla.AcsNone) def Reiablecode(self): self.codebox.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs) def nofoldingl(self): self.codebox.setFolding(QsciScintilla.NoFoldStyle) def Circledfold(self): self.codebox.setFolding(QsciScintilla.CircledTreeFoldStyle) def plainfold(self): self.codebox.setFolding(QsciScintilla.PlainFoldStyle) def webopen(self): import webbrowser webbrowser.open("https://www.hex-rays.com/") def sdkopen(self): import webbrowser webbrowser.open("https://www.hex-rays.com/products/ida/support/idapython_docs/") def gitopen(self): import webbrowser webbrowser.open("https://github.com/idapython/src/tree/build-1.7.2") def Author(self): import webbrowser webbrowser.open("https://github.com/techbliss") def font_choice(self): self.lbl = self.lexer font, ok = QtWidgets.QFontDialog.getFont() if ok: self.lbl.setFont(font) def on_margin_clicked(self, nmargin, nline, modifiers): # Toggle marker for the line the margin was clicked on if self.codebox.markersAtLine(nline) != 0: self.codebox.markerDelete(nline, self.ARROW_MARKER_NUM) else: self.codebox.markerAdd(nline, self.ARROW_MARKER_NUM)
def initialize_editor(self): self.editor = QsciScintilla() # self.editor.cursorPositionChanged.connect(self.e) # self.editor.copyAvailable.connect(self.e) # self.editor.indicatorClicked.connect(self.e) # self.editor.indicatorReleased.connect(self.e) # self.editor.linesChanged.connect(self.e) # self.editor.marginClicked.connect(self.e) # self.editor.modificationAttempted.connect(self.e) # self.editor.modificationChanged.connect(self.e) # self.editor.selectionChanged.connect(self.e) # self.editor.textChanged.connect(self.e) # self.editor.userListActivated.connect(self.e) if self.editor.__class__.__name__ == "LineTextWidget": return # When using PySide without QSciScintilla # define the font to use font = QFont() font.setFamily("Consolas") font.setFixedPitch(True) font.setPointSize(10) # the font metrics here will help # building the margin width later fm = QFontMetrics(font) # set the default font of the self.editor # and take the same font for line numbers self.editor.setFont(font) self.editor.setMarginsFont(font) # Line numbers # conventionnaly, margin 0 is for line numbers self.editor.setMarginWidth(0, fm.width("00000") + 5) self.editor.setMarginLineNumbers(0, True) self.editor.setTabWidth(4) # Folding visual : we will use boxes self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) self.editor.setAutoIndent(True) # Braces matching self.editor.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Editing line color self.editor.setCaretLineVisible(True) self.editor.setCaretLineBackgroundColor(QColor("#CDA869")) # Margins colors # line numbers margin self.editor.setMarginsBackgroundColor(QColor("#333333")) self.editor.setMarginsForegroundColor(QColor("#CCCCCC")) # folding margin colors (foreground,background) self.editor.setFoldMarginColors(QColor("#99CC66"), QColor("#333300")) # Choose a lexer self.lexer = QsciLexerPython() self.lexer.setDefaultFont(font) # Set the length of the string before the editor tries to autocomplete # In practise this would be higher than 1 # But its set lower here to make the autocompletion more obvious self.editor.setAutoCompletionThreshold(1) # Tell the editor we are using a QsciAPI for the autocompletion self.editor.setAutoCompletionSource(QsciScintilla.AcsAPIs) self.editor.setLexer(self.lexer) self.editor.setCallTipsStyle(QsciScintilla.CallTipsContext) # self.editor.setCallTipsVisible(0) # Create an API for us to populate with our autocomplete terms self.api = QsciAPIs(self.lexer) # Compile the api for use in the lexer self.api.prepare()
class ScriptTab(QWidget,): autocomplete_lst = [] def __init__(self, parent, name, script="", filemodified=0): QWidget.__init__(self) self.parent = parent self.tabWidget = self.parent.ui.tabWidget self.gridlayout = QGridLayout(self) self._dirty = False self.initialize_editor() self.gridlayout.addWidget(self.editor) self.setAcceptDrops(True) self.filename = name self.filemodified = filemodified if self.is_file(): self.title = os.path.basename(name) # if self.equals_saved(): # self.filemodified = os.path.getmtime(self.filename) else: self.filename = "" self.title = name # Show this file in the self.editor self.editor.setText(script) self.clean_txt = self.saved() self.update_dirty() self.editor.keyPressEvent = self.key_press_event @property def scriptRunner(self): return self.parent.controller.scriptRunner def wheelEvent(self, event): if event.modifiers() == Qt.ControlModifier: if event.delta() > 0: self.editor.zoomIn() else: self.editor.zoomOut() return QWidget.wheelEvent(self, event) def initialize_editor(self): self.editor = QsciScintilla() # self.editor.cursorPositionChanged.connect(self.e) # self.editor.copyAvailable.connect(self.e) # self.editor.indicatorClicked.connect(self.e) # self.editor.indicatorReleased.connect(self.e) # self.editor.linesChanged.connect(self.e) # self.editor.marginClicked.connect(self.e) # self.editor.modificationAttempted.connect(self.e) # self.editor.modificationChanged.connect(self.e) # self.editor.selectionChanged.connect(self.e) # self.editor.textChanged.connect(self.e) # self.editor.userListActivated.connect(self.e) if self.editor.__class__.__name__ == "LineTextWidget": return # When using PySide without QSciScintilla # define the font to use font = QFont() font.setFamily("Consolas") font.setFixedPitch(True) font.setPointSize(10) # the font metrics here will help # building the margin width later fm = QFontMetrics(font) # set the default font of the self.editor # and take the same font for line numbers self.editor.setFont(font) self.editor.setMarginsFont(font) # Line numbers # conventionnaly, margin 0 is for line numbers self.editor.setMarginWidth(0, fm.width("00000") + 5) self.editor.setMarginLineNumbers(0, True) self.editor.setTabWidth(4) # Folding visual : we will use boxes self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle) self.editor.setAutoIndent(True) # Braces matching self.editor.setBraceMatching(QsciScintilla.SloppyBraceMatch) # Editing line color self.editor.setCaretLineVisible(True) self.editor.setCaretLineBackgroundColor(QColor("#CDA869")) # Margins colors # line numbers margin self.editor.setMarginsBackgroundColor(QColor("#333333")) self.editor.setMarginsForegroundColor(QColor("#CCCCCC")) # folding margin colors (foreground,background) self.editor.setFoldMarginColors(QColor("#99CC66"), QColor("#333300")) # Choose a lexer self.lexer = QsciLexerPython() self.lexer.setDefaultFont(font) # Set the length of the string before the editor tries to autocomplete # In practise this would be higher than 1 # But its set lower here to make the autocompletion more obvious self.editor.setAutoCompletionThreshold(1) # Tell the editor we are using a QsciAPI for the autocompletion self.editor.setAutoCompletionSource(QsciScintilla.AcsAPIs) self.editor.setLexer(self.lexer) self.editor.setCallTipsStyle(QsciScintilla.CallTipsContext) # self.editor.setCallTipsVisible(0) # Create an API for us to populate with our autocomplete terms self.api = QsciAPIs(self.lexer) # Compile the api for use in the lexer self.api.prepare() # def tefocusInEvent(self, event): # self.parent.focusInEvent(event) # return QTextEdit.focusInEvent(self.textEditScript, event) def is_file(self): return os.path.isfile(self.filename) def is_modified(self): if self.is_file(): if self.equals_saved(): self.filemodified = os.path.getmtime(self.filename) return str(os.path.getmtime(self.filename)) != str(self.filemodified) else: return False def saved(self): if self.is_file(): f = open(self.filename) saved = f.read() f.close() return saved.strip() else: return "" def equals_saved(self): curr_lines = self.get_script().strip().splitlines() saved_lines = self.saved().strip().splitlines() if len(curr_lines) != len(saved_lines): return False for cl, sl in zip(curr_lines, saved_lines): if cl.strip() != sl.strip(): return False return True @property def dirty(self): if not self._dirty: self.dirty = self.clean_txt != self.get_script() return self._dirty @dirty.setter def dirty(self, dirty): if dirty is False: self.clean_txt = self.get_script() if self._dirty != dirty: self._dirty = dirty self.filename_changed() def update_dirty(self): return self.dirty def index(self): return self.tabWidget.indexOf(self) def filename_changed(self): index = self.parent.ui.tabWidget.indexOf(self) if self.dirty: self.tabWidget.setTabText(index, "%s*" % self.title) else: self.tabWidget.setTabText(index, self.title) def reload(self): self.set_script(self.parent._load_script(self.filename)) self.filemodified = os.path.getmtime(self.filename) def close(self): while self.dirty is True: # While avoids data loss, in case save operation is aborted if self.filename == "": text = "Save unsaved changes?" else: text = "Save %s?" % self.filename ans = QMessageBox.question(self, 'Save', text, QMessageBox.Yes, QMessageBox.Cancel, QMessageBox.No) if ans == QMessageBox.Cancel: return elif ans == QMessageBox.Yes: self.parent.actionSave(False) elif ans == QMessageBox.No: break self.tabWidget.removeTab(self.index()) def _save(self,): f = open(self.filename, 'w') f.write(self.get_script()) f.close() self.title = os.path.basename(self.filename) self.dirty = False def key_press_event(self, event): self.update_dirty() if self.editor.__class__.__name__ == "LineTextWidget": return self.editor.edit.keyReleaseEvent(event) # When using PySide without QSciScintilla QsciScintilla.keyPressEvent(self.editor, event) linenr, pos_in_line = self.editor.getCursorPosition() line = str(self.editor.text(linenr)[:pos_in_line]) if event.key() == Qt.Key_F1: try: self.parent.show_documentation(getattr(self.scriptRunner, str(self.editor.selectedText()))) except AttributeError: pass if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return: for tip in self.autocomplete_lst: try: if line.endswith(tip[:tip.index('(') ]): self.editor.insert(tip[tip.index('('):]) parent, residual = self.scriptRunner.split_line(line) self.parent.show_documentation(self.scriptRunner.get_function_dict(parent, residual)[residual]) return except ValueError: pass if event.key() < 100 or event.key() in [Qt.Key_Backspace, Qt.Key_Shift]: linenr, pos_in_line = self.editor.getCursorPosition() line = str(self.editor.text(linenr)[:pos_in_line]) lst = self.scriptRunner.get_autocomplete_list(line) if lst is not None: self.api.clear() list(map(self.api.add, lst)) self.api.prepare() if len(lst) > 0: self.autocomplete_lst = lst self.editor.autoCompleteFromAll() shift_event = QKeyEvent(QEvent.KeyPress, Qt.Key_Shift, Qt.NoModifier) QsciScintilla.keyPressEvent(self.editor, shift_event) # show autocomplete list def set_script(self, script): self.editor.setText(script) def get_script(self): return str(self.editor.text()).replace("\r", "").replace(">>> ", "").replace("\t", " ") def dropHandler(self, dataItemList, ctrl, shift, event): pass
def __init__(self, name, transition): super(QDialog, self).__init__() self.transition = transition self.setWindowTitle(name) self.resize(800, 600) self.codeEdit = QsciScintilla() self.codeEdit.setText(self.transition.getCode()) fixedWidthFont = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.codeEdit.setFont(fixedWidthFont) fontmetrics = QFontMetrics(fixedWidthFont) self.codeEdit.setMarginWidth(0, fontmetrics.width("000")) self.codeEdit.setMarginLineNumbers(0, True) self.codeEdit.setMarginsBackgroundColor(QColor("#cccccc")) self.codeEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch) self.codeEdit.setCaretLineVisible(True) self.codeEdit.setCaretLineBackgroundColor(QColor("#ffe4e4")) lexer = QsciLexerPython() lexer.setDefaultFont(fixedWidthFont) self.codeEdit.setLexer(lexer) self.codeEdit.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0) self.codeEdit.setUtf8(True) self.codeEdit.setTabWidth(4) self.codeEdit.setIndentationsUseTabs(True) self.codeEdit.setIndentationGuides(True) self.codeEdit.setTabIndents(True) self.codeEdit.setAutoIndent(True) self.cancelButton = QPushButton('Cancel') self.cancelButton.clicked.connect(self.cancel) self.acceptButton = QPushButton('Accept') self.acceptButton.clicked.connect(self.accept) self.language = 'python' self.pythonButton = QRadioButton('Python') self.pythonButton.setChecked(True) self.pythonButton.clicked.connect(self.pythonClicked) self.cppButton = QRadioButton('C++') self.cppButton.clicked.connect(self.cppClicked) codeLanguageContainer = QWidget() hLayout0 = QHBoxLayout() hLayout0.addWidget(self.pythonButton) hLayout0.addWidget(self.cppButton) codeLanguageContainer.setLayout(hLayout0) self.temporalButton = QRadioButton('Temporal', self) self.temporalButton.toggled.connect(self.temporalToggled) self.conditionalButton = QRadioButton('Conditional', self) self.conditionalButton.toggled.connect(self.conditionalToggled) radioButtonContainer = QGroupBox() radioButtonContainer.setTitle('Transition Type') vLayout = QVBoxLayout() vLayout.addWidget(self.temporalButton) vLayout.addWidget(self.conditionalButton) radioButtonContainer.setLayout(vLayout) self.transitionTypeCode = QTextEdit() self.transitionTypeCode.setFont(fixedWidthFont) self.transitionGroupBox = QGroupBox() self.transitionGroupBox.setTitle('Temporal (number in ms)') h3Layout = QHBoxLayout() h3Layout.addWidget(self.transitionTypeCode) self.transitionGroupBox.setLayout(h3Layout) typeContainer = QWidget() h2Layout = QHBoxLayout() h2Layout.addWidget(radioButtonContainer) h2Layout.addWidget(self.transitionGroupBox) typeContainer.setLayout(h2Layout) verticalLayout = QVBoxLayout() verticalLayout.addWidget(typeContainer) verticalLayout.addWidget(codeLanguageContainer) verticalLayout.addWidget(self.codeEdit) container = QWidget() hLayout =QHBoxLayout() hLayout.addWidget(self.cancelButton) hLayout.addWidget(self.acceptButton) container.setLayout(hLayout) verticalLayout.addWidget(container) self.setLayout(verticalLayout) if self.transition.getType() == TransitionType.CONDITIONAL: self.conditionalButton.setChecked(True) self.conditionalToggled() elif self.transition.getType() == TransitionType.TEMPORAL: self.temporalButton.setChecked(True) self.temporalToggled()
def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(640, 480) self.vindu = QtWidgets.QWidget(MainWindow) self.vindu.setStyleSheet(_fromUtf8('notusedasyet')) #MainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) self.filename = "" self.vindu.setObjectName(_fromUtf8("vindu")) self.verticalLayout = PyQt5.QtWidgets.QVBoxLayout(self.vindu) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/ico/python.png")), QtGui.QIcon.Normal, QtGui.QIcon.On) MainWindow.setWindowIcon(icon) self.verticalLayout.setContentsMargins(0,0,0,0) self.verticalLayout.setSpacing(0) self.verticalLayout.setObjectName(_fromUtf8('verticalLayout')) self.codebox = Qsci.QsciScintilla(self.vindu) self.codebox.setToolTip(_fromUtf8("")) self.codebox.setWhatsThis(_fromUtf8("")) self.codebox.setAutoFillBackground(False) self.codebox.setFrameShape(QtWidgets.QFrame.NoFrame) self.codebox.setObjectName(_fromUtf8("codebox")) self.verticalLayout.addWidget(self.codebox) MainWindow.setCentralWidget(self.vindu) #toolbar self.toolBar = QtWidgets.QToolBar(MainWindow) self.toolBar.setAutoFillBackground(False) self.toolBar.setIconSize(QtCore.QSize(32, 32)) self.toolBar.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) self.toolBar.setObjectName(_fromUtf8("toolBar2")) MainWindow.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolBar) self.toolBar.addSeparator() #toolbar2 debugger #self.toolBar2 = QtGui.QToolBar(MainWindow) #self.toolBar2.setAutoFillBackground(False) #self.toolBar2.setIconSize(QtCore.QSize(32, 32)) #self.toolBar2.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) #self.toolBar2.setObjectName(_fromUtf8("toolBar")) # MainWindow.addToolBar(QtCore.Qt.RightToolBarArea, self.toolBar2) # self.toolBar2.addSeparator() #getting ready for debugger self.codebox.setMarginSensitivity(1, True) self.codebox.marginClicked.connect(self.on_margin_clicked) self.codebox.markerDefine(QsciScintilla.FullRectangle, self.ARROW_MARKER_NUM) self.codebox.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) #first action Newfile self.toolBar.newAction = QtWidgets.QAction(QtGui.QIcon(":/ico/new.png"),"New",self.toolBar) self.toolBar.newAction.setStatusTip("Clear TextBox or make new document.") self.toolBar.newAction.setShortcut("Ctrl+N") self.toolBar.newAction.triggered.connect(self.newfile) #second Action OpenFile self.toolBar.secondAction = QtWidgets.QAction(QtGui.QIcon(":/ico/open.png"),"Open",self.toolBar) self.toolBar.secondAction.setStatusTip("Create a new document from scratch.") self.toolBar.secondAction.setShortcut("Ctrl+O") self.toolBar.secondAction.triggered.connect(self.open) # action 3 save file self.toolBar.Action3 = QtWidgets.QAction(QtGui.QIcon(":/ico/save.png"),"Save",self.toolBar) self.toolBar.Action3.setStatusTip("Save Your File.") self.toolBar.Action3.setShortcut("Ctrl+S") self.toolBar.Action3.triggered.connect(self.savefile) #action 4 run file self.toolBar.Action4 = QtWidgets.QAction(QtGui.QIcon(":/ico/run32.png"),"Run",self.toolBar) self.toolBar.Action4.setStatusTip("Run") self.toolBar.Action4.setShortcut("Ctrl+E") self.toolBar.Action4.triggered.connect(self.runto) #action 21 debug #self.toolBar2.Action21 = QtGui.QAction(QtGui.QIcon(":/ico/run32.png"),"Debug",self.toolBar) #self.toolBar2.Action21.setStatusTip("Debug File.") #self.toolBar2.Action21.setShortcut("Ctrl+7") #self.toolBar2.Action21.triggered.connect(self.debugto) #action 6 undo self.toolBar.Action6 = QtWidgets.QAction(QtGui.QIcon(":/ico/undo.png"),"Redo",self.toolBar) self.toolBar.Action6.setStatusTip("Undo.") self.toolBar.Action6.setShortcut("Ctrl+Z") self.toolBar.Action6.triggered.connect(self.codebox.undo) #action 7 redo self.toolBar.Action7 = QtWidgets.QAction(QtGui.QIcon(":/ico/redo.png"),"Redo",self.toolBar) self.toolBar.Action7.setStatusTip("Redo.") self.toolBar.Action7.setShortcut("Ctrl+Y") self.toolBar.Action7.triggered.connect(self.codebox.redo) #action8 rerset Folding self.toolBar.Action8 = QtWidgets.QAction(QtGui.QIcon(":/ico/align-justify.png"),"Reset Folding",self.toolBar) self.toolBar.Action8.setStatusTip("Reset Folding.") self.toolBar.Action8.setShortcut("Ctrl+R") self.toolBar.Action8.triggered.connect(self.nofoldingl) #actions9 CircledTreeFoldStyle self.toolBar.Action9 = QtWidgets.QAction(QtGui.QIcon(":/ico/bullet.png"),"Circled Tree Folding",self.toolBar) self.toolBar.Action9.setStatusTip("Circled Tree Folding.") self.toolBar.Action9.setShortcut("Ctrl+C") self.toolBar.Action9.triggered.connect(self.Circledfold) #actions10 plainFoldStyle self.toolBar.Action10 = QtWidgets.QAction(QtGui.QIcon(":/ico/number.png"),"Plain Folding",self.toolBar) self.toolBar.Action10.setStatusTip("Plain Folding") self.toolBar.Action10.setShortcut("Ctrl+P") self.toolBar.Action10.triggered.connect(self.plainfold) # fonts self.toolBar.Action21 = QtWidgets.QAction(QtGui.QIcon(":/ico4/font.png"), "Fonts", self.toolBar) self.toolBar.Action21.setStatusTip("Fonts") self.toolBar.Action21.setShortcut("Ctrl+F") self.toolBar.Action21.triggered.connect(self.font_choice) #web baby self.toolBar.Action11 = QtWidgets.QAction(QtGui.QIcon(":/ico/web.png"),"Hex-rays Homepage",self.toolBar) self.toolBar.Action11.setStatusTip("Home of Hex-rays") self.toolBar.Action11.setShortcut("Ctrl+W") self.toolBar.Action11.triggered.connect(self.webopen) #irc self.toolBar.Action12 = QtWidgets.QAction(QtGui.QIcon(":/ico3/settings.png"),"Open Ida Pro Python SDK",self.toolBar) self.toolBar.Action12.setStatusTip("Ida Pro Python SDK") self.toolBar.Action12.setShortcut("Ctrl+I") self.toolBar.Action12.triggered.connect(self.sdkopen) #github Python self.toolBar.Action14 = QtWidgets.QAction(QtGui.QIcon(":/ico/github.png"),"Open git python",self.toolBar) self.toolBar.Action14.setStatusTip("Open git python") self.toolBar.Action14.setShortcut("Ctrl+G") self.toolBar.Action14.triggered.connect(self.gitopen) #auther me :) self.toolBar.Action15 = QtWidgets.QAction(QtGui.QIcon(":/ico/auth.png"),"Author",self.toolBar) self.toolBar.Action15.setStatusTip("Author") self.toolBar.Action15.setShortcut("Ctrl+B") self.toolBar.Action15.triggered.connect(self.Author) #toggle off code regonision self.toolBar.Action16 = QtWidgets.QAction(QtGui.QIcon(":/ico2/pythonminus.png"),"Disable Code recognition",self.toolBar) self.toolBar.Action16.setStatusTip("Disable Code recognition") self.toolBar.Action16.setShortcut("Alt+D") self.toolBar.Action16.triggered.connect(self.Diablecode) #toogle on self.toolBar.Action17 = QtWidgets.QAction(QtGui.QIcon(":/ico2/pypluss.png"),"Enable Code recognition",self.toolBar) self.toolBar.Action17.setStatusTip("Enable Code recognition") self.toolBar.Action17.setShortcut("Alt+E") self.toolBar.Action17.triggered.connect(self.Reiablecode) # zoom in self.toolBar.Action18 = QtWidgets.QAction(QtGui.QIcon(":/ico3/in.png"),"Zoom In",self.toolBar) self.toolBar.Action18.setStatusTip("Zoom In") self.toolBar.Action18.setShortcut("CTRL+SHIFT++") self.toolBar.Action18.triggered.connect(self.udder) #zoom out self.toolBar.Action19 = QtWidgets.QAction(QtGui.QIcon(":/ico3/out.png"),"Zoom Out",self.toolBar) self.toolBar.Action19.setStatusTip("Zoom Out") self.toolBar.Action19.setShortcut("CTRL+SHIFT+-") self.toolBar.Action19.triggered.connect(self.odder) self.toolBar.Action20 = QtWidgets.QAction(QtGui.QIcon(":/ico3/10.png"),"Profile Code",self.toolBar) self.toolBar.Action20.setStatusTip("Profile Code") self.toolBar.Action20.setShortcut("CTRL+SHIFT+E") self.toolBar.Action20.triggered.connect(self.runtoprob) #actions self.toolBar.addAction(self.toolBar.newAction) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.secondAction) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action3) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action4) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action6) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action7) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action8) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action9) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action10) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action21) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action11) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action12) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action14) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action15) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action16) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action17) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action18) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action19) self.toolBar.addSeparator() self.toolBar.addAction(self.toolBar.Action20) #self.toolBar2.addAction(self.toolBar.Action21) #self.toolBar2.addSeparator() #font self.skrift = QFont() self.skrift.setFamily('Consolas') self.skrift.setFixedPitch(True) self.skrift.setPointSize(12) self.codebox.setFont(self.skrift) #python style self.lexer = QsciLexerPython(self.codebox) self.lexer.setFont(self.skrift) self.lexer.setEolFill(True) #api test not working api = Qsci.QsciAPIs(self.lexer) API_FILE = dn+'\\Python.api' API_FILE2 = dn+'\\idc.api' API_FILE3 = dn+'\\idaapi.api' api.load(API_FILE) api.load(API_FILE2) api.load(API_FILE3) api.prepare() self.codebox.setAutoCompletionThreshold(0) self.codebox.setAutoCompletionThreshold(6) self.codebox.setAutoCompletionThreshold(8) self.codebox.setAutoCompletionSource(Qsci.QsciScintilla.AcsAPIs) self.lexer.setDefaultFont(self.skrift) self.codebox.setLexer(self.lexer) self.codebox.SendScintilla(QsciScintilla.SCI_STYLESETFONT, 1, 'Consolas') #line numbers fontmetrics = QFontMetrics(self.skrift) self.codebox.setMarginsFont(self.skrift) self.codebox.setMarginWidth(0, fontmetrics.width("00000") + 6) self.codebox.setTabWidth(4) #brace self.codebox.setBraceMatching(QsciScintilla.SloppyBraceMatch) #auto line tab =4 self.codebox.setAutoIndent(True) #scroolbar self.codebox.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 1) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)