예제 #1
0
    def agregar_tab(self):
        text, okPressed = QInputDialog.getText(self.centralwidget,
                                               "Nuevo archivo", "Nombre:",
                                               QLineEdit.Normal, "")
        if okPressed and text != '':

            tab = QtWidgets.QWidget()
            area = QsciScintilla(tab)
            area.setGeometry(QtCore.QRect(10, 10, 631, 371))
            area.setObjectName("plainTextEdit")
            area.setFont(self.__myFont)
            area.setMarginType(0, QsciScintilla.NumberMargin)
            area.setMarginWidth(0, "00000")
            area.setMarginsForegroundColor(QtGui.QColor("#0C4B72"))
            area.markerDefine(QsciScintilla.RightArrow, 0)
            area.setMarginSensitivity(0, True)
            area.setWrapMode(QsciScintilla.WrapWord)
            area.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
            area.setWrapIndentMode(QsciScintilla.WrapIndentIndented)
            area.setEolMode(QsciScintilla.EolWindows)
            area.setEolVisibility(False)
            area.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
            area.marginClicked.connect(self.on_margin_clicked)
            __lexer = QsciLexerCPP(area)
            area.setLexer(__lexer)
            self.editor.addTab(tab, "")
            area.setObjectName("area")
            self.editor.addTab(tab, text + ".mc")
예제 #2
0
 def abrir_archivo(self):
     try:
         dialog = QtWidgets.QFileDialog().getOpenFileName(
             None, ' Open document', r"C:\Users\\", "All Files (*)")
         ruta = dialog[0]
         trozos = ruta.split("/")
         name = trozos[len(trozos) - 1]
         self.pestañas[name] = ruta
         file = open(ruta, 'r')
         codigo = file.read()
         tab = QtWidgets.QWidget()
         area = QsciScintilla(tab)
         area.setGeometry(QtCore.QRect(10, 10, 631, 371))
         area.setObjectName("plainTextEdit")
         area.setFont(self.__myFont)
         area.setMarginType(0, QsciScintilla.NumberMargin)
         area.setMarginWidth(0, "00000")
         area.setMarginsForegroundColor(QtGui.QColor("#0C4B72"))
         area.markerDefine(QsciScintilla.RightArrow, 0)
         area.setMarginSensitivity(0, True)
         area.setWrapMode(QsciScintilla.WrapWord)
         area.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
         area.setWrapIndentMode(QsciScintilla.WrapIndentIndented)
         area.setEolMode(QsciScintilla.EolWindows)
         area.setEolVisibility(False)
         area.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
         area.marginClicked.connect(self.on_margin_clicked)
         __lexer = QsciLexerCPP(area)
         area.setLexer(__lexer)
         self.editor.addTab(tab, "")
         area.setText(codigo)
         area.setObjectName("area")
         self.editor.addTab(tab, name)
         file.close()
     except:
         em = QtWidgets.QErrorMessage(self.mw)
         em.showMessage("Error al abrir {0}".format(name))
class CustomMainWindow(QMainWindow):
    def __init__(self):
        super(CustomMainWindow, self).__init__()

        # Window setup
        # --------------

        # 1. Define the geometry of the main window
        self.setGeometry(300, 300, 800, 400)
        self.setWindowTitle("QScintilla Test")

        # 2. Create frame and layout
        self.__frm = QFrame(self)
        self.__frm.setStyleSheet("QWidget { background-color: #ffeaeaea }")
        self.__lyt = QVBoxLayout()
        self.__frm.setLayout(self.__lyt)
        self.setCentralWidget(self.__frm)
        self.__myFont = QFont()
        self.__myFont.setPointSize(14)

        # 3. Place a button
        self.__btn = QPushButton("Qsci")
        self.__btn.setFixedWidth(50)
        self.__btn.setFixedHeight(50)
        self.__btn.clicked.connect(self.__btn_action)
        self.__btn.setFont(self.__myFont)
        self.__lyt.addWidget(self.__btn)

        # QScintilla editor setup
        # ------------------------

        # ! Make instance of QsciScintilla class!
        self.__editor = QsciScintilla()
        self.__editor.setText("Hello\n")
        self.__editor.append("world \n")
        self.__editor.setLexer(None)
        self.__editor.setUtf8(True)  # Set encoding to UTF-8
        self.__editor.setFont(self.__myFont)  # Will be overridden by lexer!

        #simple editor options

        self.__editor.setEolVisibility(False) #sets the end of each line with an EOL character
        self.__editor.setIndentationsUseTabs(False) #determines whether indent uses tabs or whitespace char.
        self.__editor.setTabWidth(4)
        self.__editor.setIndentationGuides(True)
        self.__editor.setTabIndents(True)
        self.__editor.setAutoIndent(True)
        self.__editor.setCaretForegroundColor(QColor("#ff0000ff"))
        self.__editor.setCaretLineVisible(True)
        self.__editor.setCaretLineBackgroundColor(QColor("#1fff0000"))
        self.__editor.setCaretWidth(5)

        #Margin SetUp.
        self.__editor.setMarginType(3, self.__editor.NumberMargin)
        self.__editor.setMarginsForegroundColor(QColor("#ff888888"))
        # self.__editor.setMarginType(2, QsciScintilla.TextMargin)
        # Symbol Margin
        sym_0 = QImage("icons/sym_0.png").scaled(QSize(16, 16))
        sym_1 = QImage("icons/sym_1.png").scaled(QSize(16, 16))
        sym_2 = QImage("icons/sym_2.png").scaled(QSize(16, 16))
        sym_3 = QImage("icons/sym_3.png").scaled(QSize(16, 16))
        sym_4 = self.__editor.Circle
        self.__editor.markerDefine(sym_0, 0)
        self.__editor.markerDefine(sym_1, 1)
        self.__editor.markerDefine(sym_2, 2)
        self.__editor.markerDefine(sym_3, 3)
        self.__editor.markerDefine(sym_4, 4)
        self.__editor.setMarginType(3, self.__editor.SymbolMargin)
        # self.__editor.setMarginType(2, QsciScintilla.SymbolMarginDefaultBackgroundColor)
        # self.__editor.setMarginType(3, QsciScintilla.SymbolMarginDefaultForegroundColor)
        self.__editor.setMarginWidth(1, '00000')
        self.__editor.setMarginMarkerMask(1, 0b1111)
        self.__editor.setMarginMarkerMask(2, 0b1111)
        self.__editor.markerAdd(3, 2)
        # Display a few symbols, and keep their handles stored
        self.__editor.markerAdd(0, 0)   # Green dot on line 0+1
        self.__editor.markerAdd(4, 0)   # Green dot on line 4+1
        self.__editor.markerAdd(5, 0)   # Green dot on line 5+1
        self.__editor.markerAdd(8, 3)   # Red arrow on line 8+1
        self.__editor.markerAdd(9, 2)   # Red dot on line 9+1

        self.__editor.setFolding(self.__editor.BoxedFoldStyle, 4)
        self.__editor.SendScintilla(self.__editor.SCI_SETMULTIPLESELECTION, True)
        self.__editor.SendScintilla(self.__editor.SCI_SETMULTIPASTE, 1)
        self.__editor.SendScintilla(self.__editor.SCI_SETADDITIONALSELECTIONTYPING, True)
        self.__editor.SendScintilla(self.__editor.SCI_SETINDENTATIONGUIDES, self.__editor.SC_IV_REAL);
        self.__editor.SendScintilla(self.__editor.SCI_SETTABWIDTH, 4)

        # self.__editor.setMarginsBackgroundColor(QColor("#ff0000ff"))
        self.__editor.setWrapMode(QsciScintilla.WrapWord)
        self.__editor.setWrapIndentMode(QsciScintilla.WrapIndentIndented)

        # available wrap modes: 
        # QsciScintilla.WrapNone, WrapWord, WrapCharacter, WrapWhitespace
        self.__editor.setWrapVisualFlags(
            QsciScintilla.WrapFlagByText,
            startFlag=QsciScintilla.WrapFlagByText,
            indent=4)
        # setWrapVisualFlags(endFlag, startFlag, indent)
        # see: readMe
        self.__editor.setWrapIndentMode(QsciScintilla.WrapIndentIndented)
        self.__editor.textChanged.connect(self.text_changed) #signal typing

        # ! Add editor to layout !
        self.__lyt.addWidget(self.__editor)

        self.show()

    ''''''

    def __btn_action(self):
        self.__editor.append('Voila You just clicked the QSci button! \n')
        print("Hello World!")

    def text_changed(self):
        print({self.__editor.text()})
    ''''''
예제 #4
0
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Untitled")
        icon = os.path.join(BASE_DIR, 'ide/Icon.ico')
        self.setWindowIcon(QIcon(icon))
        self.saveLoad = SaveLoad()
        self.fileName = None
        self.setupUI()

    def setupUI(self):
        centralWidget = QWidget(self)
        layout = QHBoxLayout(centralWidget)
        self.fileSysView = QTreeView(centralWidget)
        self.setupFileSystemViewer()
        self.editor = QsciScintilla(centralWidget)
        self.setupEditor()
        layout.addWidget(self.fileSysView, 1)
        layout.addWidget(self.editor, 3)
        self.setCentralWidget(centralWidget)
        self.setMinimumSize(700, 500)
        self.defaultMenuBar = QMenuBar(self)
        self.setupMenus()
        self.setMenuBar(self.defaultMenuBar)
        self.show()

    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 setupFileSystemViewer(self):
        model = QFileSystemModel()
        model.setRootPath("/")
        self.fileSysView.setModel(model)
        self.fileSysView.hideColumn(1)
        self.fileSysView.hideColumn(2)
        self.fileSysView.hideColumn(3)
        self.fileSysView.doubleClicked.connect(self.openFile)

    def setupMenus(self):
        fileMenu = QMenu(self.defaultMenuBar)
        fileMenu.setTitle("File")
        editMenu = QMenu(self.defaultMenuBar)
        editMenu.setTitle("Edit")
        viewMenu = QMenu(self.defaultMenuBar)
        viewMenu.setTitle("View")
        runMenu = QMenu(self.defaultMenuBar)
        runMenu.setTitle("Run")
        settingsMenu = QMenu(self.defaultMenuBar)
        settingsMenu.setTitle("Settings")
        self.actionNew = QAction(self)
        self.actionNew.setText("New")
        self.actionNew.setShortcut("Ctrl+N")
        self.actionOpen = QAction(self)
        self.actionOpen.setText("Open")
        self.actionOpen.setShortcut("Ctrl+O")
        self.actionSave = QAction(self)
        self.actionSave.setText("Save")
        self.actionSave.setShortcut("Ctrl+S")
        self.actionSaveAs = QAction(self)
        self.actionSaveAs.setText("Save As")
        self.actionSaveAs.setShortcut("Ctrl+Shift+S")
        self.actionExit = QAction(self)
        self.actionExit.setText("Exit")
        self.actionExit.setShortcut("Alt+X")
        self.actionUndo = QAction(self)
        self.actionUndo.setText("Undo")
        self.actionUndo.setShortcut("Ctrl+Z")
        self.actionRedo = QAction(self)
        self.actionRedo.setText("Redo")
        self.actionRedo.setShortcut("Ctrl+Shift+Z")
        self.actionSelectAll = QAction(self)
        self.actionSelectAll.setText("Select all")
        self.actionSelectAll.setShortcut("Ctrl+A")
        self.actionCut = QAction(self)
        self.actionCut.setText("Cut")
        self.actionCut.setShortcut("Ctrl+X")
        self.actionCopy = QAction(self)
        self.actionCopy.setText("Copy")
        self.actionCopy.setShortcut("Ctrl+C")
        self.actionPaste = QAction(self)
        self.actionPaste.setText("Paste")
        self.actionPaste.setShortcut("Ctrl+V")
        self.actionFind = QAction(self)
        self.actionFind.setText("Find")
        self.actionFind.setShortcut("Ctrl+F")
        self.actionReplace = QAction(self)
        self.actionReplace.setText("Replace")
        self.actionReplace.setShortcut("Ctrl+H")
        self.actionRun = QAction(self)
        self.actionRun.setText("Run")
        self.actionRun.setShortcut("F5")
        self.actionRunCustom = QAction(self)
        self.actionRunCustom.setText("Run Customized")
        self.actionRunCustom.setShortcut("Shift+F5")
        self.actionShell = QAction(self)
        self.actionShell.setText("Python shell")
        self.actionShell.setShortcut("Alt+S")
        self.actionFont = QAction(self)
        self.actionFont.setText("Font")
        self.actionEncoding = QAction(self)
        self.actionEncoding.setText("Encoding")
        fileMenu.addAction(self.actionNew)
        fileMenu.addAction(self.actionOpen)
        fileMenu.addAction(self.actionSave)
        fileMenu.addAction(self.actionSaveAs)
        fileMenu.addSeparator()
        fileMenu.addAction(self.actionExit)
        editMenu.addAction(self.actionUndo)
        editMenu.addAction(self.actionRedo)
        editMenu.addSeparator()
        editMenu.addAction(self.actionSelectAll)
        editMenu.addSeparator()
        editMenu.addAction(self.actionCut)
        editMenu.addAction(self.actionCopy)
        editMenu.addAction(self.actionPaste)
        viewMenu.addAction(self.actionFind)
        viewMenu.addAction(self.actionReplace)
        runMenu.addAction(self.actionRun)
        runMenu.addAction(self.actionRunCustom)
        runMenu.addAction(self.actionShell)
        settingsMenu.addAction(self.actionFont)
        settingsMenu.addAction(self.actionEncoding)
        self.defaultMenuBar.addAction(fileMenu.menuAction())
        self.defaultMenuBar.addAction(editMenu.menuAction())
        self.defaultMenuBar.addAction(viewMenu.menuAction())
        self.defaultMenuBar.addAction(runMenu.menuAction())
        self.defaultMenuBar.addAction(settingsMenu.menuAction())
        self.actionNew.triggered.connect(self.new)
        self.actionOpen.triggered.connect(self.open)
        self.actionSave.triggered.connect(self.save)
        self.actionSaveAs.triggered.connect(self.saveAs)
        self.actionExit.triggered.connect(self.close)
        self.actionUndo.triggered.connect(self.editor.undo)
        self.actionRedo.triggered.connect(self.editor.redo)
        self.actionSelectAll.triggered.connect(
            lambda: self.editor.selectAll(True))
        self.actionCut.triggered.connect(self.editor.cut)
        self.actionCopy.triggered.connect(self.editor.copy)
        self.actionPaste.triggered.connect(self.editor.paste)
        self.actionFind.triggered.connect(self.find)
        self.actionReplace.triggered.connect(self.replace)
        self.actionRun.triggered.connect(self.run)
        self.actionRunCustom.triggered.connect(self.runCustom)
        self.actionShell.triggered.connect(self.shell)
        self.actionFont.triggered.connect(self.Font)

    def margin_clicked(self, margin_nr, line_nr, state):
        self.editor.markerAdd(line_nr, margin_nr)

    def margin_right_clicked(self, margin_nr, line_nr, state):
        self.editor.markerDelete(line_nr, margin_nr)

    def new(self):
        if self.windowTitle().endswith("*"):
            if (Dialogs().Question(
                    self, "Do you want to save your file?") == "accept"):
                if self.filename is None:
                    self.saveAs()
                else:
                    self.save()
        self.editor.setText("")
        self.setWindowTitle("Untitled")

    def open(self):
        if self.windowTitle().endswith("*"):
            if (Dialogs().Question(
                    self, "Do you want to save your file?") == "accept"):
                if self.filename is None:
                    self.saveAs()
                else:
                    self.save()
        filename = self.saveLoad.OpenDialog()
        data = Open(filename)
        if data is not None:
            self.editor.setText(data)
            self.setWindowTitle(filename)
            self.filename = filename

    def save(self):
        if self.filename is None:
            self.saveAs()
        else:
            returnval = Save(self.editor.text(), self.filename)
            if (returnval):
                Dialogs().Message(self, "File saved successfully")
                self.setWindowTitle(self.filename)
            else:
                Dialogs().Error(self, "File could not be saved")

    def saveAs(self):
        self.filename = self.saveLoad.SaveDialog()
        returnval = Save(self.editor.text(), self.filename)
        if (returnval):
            Dialogs().Message(self, "File saved successfully")
            self.setWindowTitle(self.filename)
        else:
            Dialogs().Error(self, "File could not be saved")

    def run(self):
        if self.filename is None:
            self.saveAs()
        Runfile(self.filename)

    def runCustom(self):
        if self.filename is None:
            self.saveAs()
        if self.filename != "":
            print(len(self.filename))
            option, ok = QInputDialog().getText(
                self, "Customized run", "Enter parameters for sys.argv",
                QLineEdit.Normal, " ")
            if ok:
                Runfile(self.filename, option)

    def shell(self):
        Shell()

    def Font(self):
        font, ok = QFontDialog.getFont()
        if ok:
            self.editor.setFont(font)
            self.lexer.setFont(font)
            self.editor.setLexer(self.lexer)

    def openFile(self, signal):
        fileName = self.fileSysView.model().filePath(signal)
        if fileName.endswith("py") or fileName.endswith("pyw"):
            if self.windowTitle().endswith("*"):
                if Dialogs().Question(
                        self, "Do you want to save your file?") == "accept":
                    if self.filename is None:
                        self.saveAs()
                    else:
                        self.save()
            data = Open(fileName)
            if data is not None:
                self.editor.setText(data)
                self.setWindowTitle(fileName)
                self.filename = fileName

    def fileChanged(self):
        title = self.windowTitle()
        if not (title.endswith("*")):
            self.setWindowTitle(title + " *")

    def replace(self):
        replaceObj = replaceDialog(self, self.editor)

    def find(self):
        findObj = findDialog(self, self.editor)
class CustomMainWindow(QMainWindow):
    def __init__(self):
        super(CustomMainWindow, self).__init__()

        # -------------------------------- #
        #           Window setup           #
        # -------------------------------- #

        # 1. Define the geometry of the main window
        # ------------------------------------------
        self.setGeometry(300, 300, 800, 400)
        self.setWindowTitle("QScintilla Test")

        # 2. Create frame and layout
        # ---------------------------
        self.__frm = QFrame(self)
        self.__frm.setStyleSheet("QWidget { background-color: #ffeaeaea }")
        self.__lyt = QVBoxLayout()
        self.__frm.setLayout(self.__lyt)
        self.setCentralWidget(self.__frm)
        self.__myFont = QFont()
        self.__myFont.setPointSize(14)

        # 3. Place a button
        # ------------------
        self.__btn = QPushButton("Qsci")
        self.__btn.setFixedWidth(50)
        self.__btn.setFixedHeight(50)
        self.__btn.clicked.connect(self.__btn_action)
        self.__btn.setFont(self.__myFont)
        self.__lyt.addWidget(self.__btn)

        # -------------------------------- #
        #     QScintilla editor setup      #
        # -------------------------------- #

        # ! Make instance of QSciScintilla class!
        # ----------------------------------------
        self.__editor = QsciScintilla()
        self.__editor.setText("This\n")  # Line 1
        self.__editor.append("is\n")  # Line 2
        self.__editor.append("a\n")  # Line 3
        self.__editor.append("QScintilla\n")  # Line 4
        self.__editor.append("test\n")  # Line 5
        self.__editor.append("program\n")  # Line 6
        self.__editor.append("to\n")  # Line 7
        self.__editor.append("illustrate\n")  # Line 8
        self.__editor.append("some\n")  # Line 9
        self.__editor.append("basic\n")  # Line 10
        self.__editor.append("functions.")  # Line 11
        self.__editor.setLexer(None)
        self.__editor.setUtf8(True)  # Set encoding to UTF-8
        self.__editor.setFont(self.__myFont)

        # 1. Text wrapping
        # -----------------
        self.__editor.setWrapMode(QsciScintilla.WrapWord)
        self.__editor.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
        self.__editor.setWrapIndentMode(QsciScintilla.WrapIndentIndented)

        # 2. End-of-line mode
        # --------------------
        self.__editor.setEolMode(QsciScintilla.EolWindows)
        self.__editor.setEolVisibility(False)

        # 3. Indentation
        # ---------------
        self.__editor.setIndentationsUseTabs(False)
        self.__editor.setTabWidth(4)
        self.__editor.setIndentationGuides(True)
        self.__editor.setTabIndents(True)
        self.__editor.setAutoIndent(True)

        # 4. Caret
        # ---------
        self.__editor.setCaretForegroundColor(QColor("#ff0000ff"))
        self.__editor.setCaretLineVisible(True)
        self.__editor.setCaretLineBackgroundColor(QColor("#1f0000ff"))
        self.__editor.setCaretWidth(2)

        # 5. Margins
        # -----------
        # Margin 0 = Line nr margin
        self.__editor.setMarginType(0, QsciScintilla.NumberMargin)
        self.__editor.setMarginWidth(0, "0000")
        self.__editor.setMarginsForegroundColor(QColor("#ff888888"))

        # Margin 1 = Symbol margin
        self.__editor.setMarginType(1, QsciScintilla.SymbolMargin)
        self.__editor.setMarginWidth(1, "00000")
        sym_0 = QImage("icons/sym_0.png").scaled(QSize(16, 16))
        sym_1 = QImage("icons/sym_1.png").scaled(QSize(16, 16))
        sym_2 = QImage("icons/sym_2.png").scaled(QSize(16, 16))
        sym_3 = QImage("icons/sym_3.png").scaled(QSize(16, 16))

        self.__editor.markerDefine(sym_0, 0)
        self.__editor.markerDefine(sym_1, 1)
        self.__editor.markerDefine(sym_2, 2)
        self.__editor.markerDefine(sym_3, 3)

        self.__editor.setMarginMarkerMask(1, 0b1111)

        # 6. Margin mouse clicks
        # -----------------------
        self.__editor.setMarginSensitivity(1, True)
        self.__editor.marginClicked.connect(self.__margin_left_clicked)
        self.__editor.marginRightClicked.connect(self.__margin_right_clicked)

        # ! Add editor to layout !
        # -------------------------
        self.__lyt.addWidget(self.__editor)
        self.show()

    ''''''

    def __margin_left_clicked(self, margin_nr, line_nr, state):
        print("Margin clicked (left mouse btn)!")
        print(" -> margin_nr: " + str(margin_nr))
        print(" -> line_nr:   " + str(line_nr))
        print("")

        if state == Qt.ControlModifier:
            # Show green dot.
            self.__editor.markerAdd(line_nr, 0)

        elif state == Qt.ShiftModifier:
            # Show green arrow.
            self.__editor.markerAdd(line_nr, 1)

        elif state == Qt.AltModifier:
            # Show red dot.
            self.__editor.markerAdd(line_nr, 2)

        else:
            # Show red arrow.
            self.__editor.markerAdd(line_nr, 3)

    ''''''

    def __margin_right_clicked(self, margin_nr, line_nr, state):
        print("Margin clicked (right mouse btn)!")
        print(" -> margin_nr: " + str(margin_nr))
        print(" -> line_nr:   " + str(line_nr))
        print("")

    ''''''

    def __btn_action(self):
        print("Hello World!")

    ''''''
예제 #6
0
class highlightEditor(QMainWindow):
    """
    语法高亮代码框
    """
    def __init__(self, parent=None, lineNumberOn=False):
        super(highlightEditor, self).__init__()

        self.editor = QsciScintilla(parent)
        font = QFont()
        font.setFamily("Consolas")
        font.setPointSize(12)
        font.setFixedPitch(True)
        self.editor.setFont(font)
        self.editor.setObjectName("editor")

        self.editor.setUtf8(True)
        self.editor.setMarginsFont(font)
        if lineNumberOn:
            self.editor.setMarginWidth(
                0,
                len(str(len(self.editor.text().split('\n')))) * 20)
        self.editor.setMarginLineNumbers(0, lineNumberOn)

        self.editor.setBraceMatching(QsciScintilla.StrictBraceMatch)

        self.editor.setIndentationsUseTabs(True)
        self.editor.setIndentationWidth(4)
        self.editor.setTabIndents(True)
        self.editor.setAutoIndent(True)
        self.editor.setBackspaceUnindents(True)
        self.editor.setTabWidth(4)

        self.editor.setCaretLineVisible(True)
        self.editor.setCaretLineBackgroundColor(QColor('#DCDCDC'))

        self.editor.setIndentationGuides(True)

        self.editor.setFolding(QsciScintilla.PlainFoldStyle)
        self.editor.setMarginWidth(2, 12)

        self.editor.markerDefine(QsciScintilla.Minus,
                                 QsciScintilla.SC_MARKNUM_FOLDEROPEN)
        self.editor.markerDefine(QsciScintilla.Plus,
                                 QsciScintilla.SC_MARKNUM_FOLDER)
        self.editor.markerDefine(QsciScintilla.Minus,
                                 QsciScintilla.SC_MARKNUM_FOLDEROPENMID)
        self.editor.markerDefine(QsciScintilla.Plus,
                                 QsciScintilla.SC_MARKNUM_FOLDEREND)

        self.editor.setMarkerBackgroundColor(
            QColor("#FFFFFF"), QsciScintilla.SC_MARKNUM_FOLDEREND)
        self.editor.setMarkerForegroundColor(
            QColor("#272727"), QsciScintilla.SC_MARKNUM_FOLDEREND)
        self.editor.setMarkerBackgroundColor(
            QColor("#FFFFFF"), QsciScintilla.SC_MARKNUM_FOLDEROPENMID)
        self.editor.setMarkerForegroundColor(
            QColor("#272727"), QsciScintilla.SC_MARKNUM_FOLDEROPENMID)
        self.editor.setAutoCompletionSource(QsciScintilla.AcsAll)
        self.editor.setAutoCompletionCaseSensitivity(True)
        self.editor.setAutoCompletionReplaceWord(False)
        self.editor.setAutoCompletionThreshold(1)
        self.editor.setAutoCompletionUseSingle(QsciScintilla.AcusExplicit)
        self.lexer = highlight(self.editor)
        self.editor.setLexer(self.lexer)
        self.__api = QsciAPIs(self.lexer)
        autocompletions = keyword.kwlist + []
        for ac in autocompletions:
            self.__api.add(ac)
        self.__api.prepare()
        self.editor.autoCompleteFromAll()

        self.editor.textChanged.connect(self.changed)

    def changed(self):
        self.editor.setMarginWidth(
            0,
            len(str(len(self.editor.text().split('\n')))) * 20)
예제 #7
0
class Interfaz(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1349, 806)
        self.mw = MainWindow
        self.puntos_break = []
        self.rutaTemp = ""
        self.pestañas = {}
        self.nombre = ""
        self.gc = False

        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255, 128))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255, 128))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive,
                         QtGui.QPalette.PlaceholderText, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled,
                         QtGui.QPalette.PlaceholderText, brush)
        MainWindow.setPalette(palette)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.new_file = QtWidgets.QPushButton(self.centralwidget)
        self.new_file.setGeometry(QtCore.QRect(0, 0, 71, 61))
        self.new_file.setObjectName("new_file")
        self.new_file.clicked.connect(self.agregar_tab)
        self.save_file = QtWidgets.QPushButton(self.centralwidget)
        self.save_file.setGeometry(QtCore.QRect(70, 0, 71, 61))
        self.save_file.setObjectName("save_file")
        self.save_file.clicked.connect(self.guardar)
        self.save_file_as = QtWidgets.QPushButton(self.centralwidget)
        self.save_file_as.setGeometry(QtCore.QRect(140, 0, 71, 61))
        self.save_file_as.setObjectName("save_file_as")
        self.save_file_as.clicked.connect(self.guardar_como)
        #boton ejecutar
        self.ejecutar = QtWidgets.QPushButton(self.centralwidget)
        self.ejecutar.setGeometry(QtCore.QRect(240, 0, 71, 61))
        self.ejecutar.setObjectName("ejecutar")
        self.ejecutar.clicked.connect(self.Traducir_Alto_nivel)
        #end ejecutar
        #inico depurar
        self.depurar = QtWidgets.QPushButton(self.centralwidget)
        self.depurar.setGeometry(QtCore.QRect(310, 0, 71, 61))
        self.depurar.setObjectName("depurar")
        self.depurar.clicked.connect(self.Depurar_Alto_nivel)
        #end depurar
        self.parar = QtWidgets.QPushButton(self.centralwidget)
        self.parar.setGeometry(QtCore.QRect(380, 0, 71, 61))
        self.parar.setObjectName("parar")
        self.parar.clicked.connect(self.detenerEjecucion)
        #end parar
        self.step_step = QtWidgets.QPushButton(self.centralwidget)
        self.step_step.setGeometry(QtCore.QRect(450, 0, 71, 61))
        self.step_step.setObjectName("step_step")
        self.step_step.clicked.connect(self.setStep)
        #end step
        self.continuar = QtWidgets.QPushButton(self.centralwidget)
        self.continuar.setGeometry(QtCore.QRect(520, 0, 71, 61))
        self.continuar.setObjectName("continuar")
        self.continuar.clicked.connect(self.setContinuar)
        #end continuar
        self.tema = QtWidgets.QPushButton(self.centralwidget)
        self.tema.setGeometry(QtCore.QRect(640, 0, 71, 61))
        self.tema.setObjectName("tema")
        self.tema.clicked.connect(self.setLines)
        self.lineas = QtWidgets.QPushButton(self.centralwidget)
        self.lineas.setGeometry(QtCore.QRect(710, 0, 71, 61))
        self.lineas.setObjectName("lineas")
        self.lineas.clicked.connect(self.ms_help)
        self.editor = QtWidgets.QTabWidget(self.centralwidget)
        self.editor.setGeometry(QtCore.QRect(10, 80, 661, 421))
        self.editor.setObjectName("editor")
        self.editor.setTabsClosable(True)
        self.editor.tabCloseRequested.connect(self.closeTab)
        self.tab = QtWidgets.QWidget()
        self.tab.setObjectName("tab")
        self.__myFont = QtGui.QFont()
        self.__myFont.setPointSize(11)
        #Principio
        self.plainTextEdit = QsciScintilla(self.tab)
        self.plainTextEdit.setGeometry(QtCore.QRect(10, 10, 631, 371))
        self.plainTextEdit.setObjectName("plainTextEdit")
        self.plainTextEdit.setFont(self.__myFont)
        self.plainTextEdit.setMarginType(0, QsciScintilla.NumberMargin)
        self.plainTextEdit.setMarginWidth(0, "00000")
        self.plainTextEdit.setMarginsForegroundColor(QtGui.QColor("#0C4B72"))
        self.plainTextEdit.markerDefine(QsciScintilla.RightArrow, 0)
        self.plainTextEdit.setMarginSensitivity(0, True)
        self.plainTextEdit.setWrapMode(QsciScintilla.WrapWord)
        self.plainTextEdit.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
        self.plainTextEdit.setWrapIndentMode(QsciScintilla.WrapIndentIndented)
        self.plainTextEdit.setEolMode(QsciScintilla.EolWindows)
        self.plainTextEdit.setEolVisibility(False)
        self.plainTextEdit.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
        self.plainTextEdit.marginClicked.connect(self.on_margin_clicked)
        self.__lexer = QsciLexerCPP(self.plainTextEdit)
        self.plainTextEdit.setLexer(self.__lexer)
        self.editor.addTab(self.tab, "")
        #end of de evangelion

        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(690, 80, 171, 16))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        self.label.setPalette(palette)
        self.label.setObjectName("label")
        self.codigo_3d = QtWidgets.QListWidget(self.centralwidget)
        self.codigo_3d.setGeometry(QtCore.QRect(680, 100, 211, 401))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
        brush.setStyle(QtCore.Qt.NoBrush)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
        brush.setStyle(QtCore.Qt.NoBrush)
        palette.setBrush(QtGui.QPalette.Inactive,
                         QtGui.QPalette.PlaceholderText, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
        brush.setStyle(QtCore.Qt.NoBrush)
        palette.setBrush(QtGui.QPalette.Disabled,
                         QtGui.QPalette.PlaceholderText, brush)
        self.codigo_3d.setPalette(palette)
        self.codigo_3d.setObjectName("codigo_3d")
        self.consola = PlainTextEdit(self.centralwidget)
        self.consola.setGeometry(QtCore.QRect(10, 530, 661, 221))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(29, 29, 29))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(29, 29, 29))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        ###########################
        self.consola.setPalette(palette)
        self.consola.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self.consola.setObjectName("consola")
        ###########################
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(890, 80, 171, 16))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        self.label_2.setPalette(palette)
        self.label_2.setObjectName("label_2")
        self.tabla_cuadruplos = QtWidgets.QTableWidget(self.centralwidget)
        self.tabla_cuadruplos.setGeometry(QtCore.QRect(680, 530, 431, 221))
        self.tabla_cuadruplos.setObjectName("tabla_cuadruplos")
        self.tabla_cuadruplos.setColumnCount(4)
        self.tabla_cuadruplos.setRowCount(0)
        item = QtWidgets.QTableWidgetItem()
        self.tabla_cuadruplos.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        self.tabla_cuadruplos.setHorizontalHeaderItem(1, item)
        item = QtWidgets.QTableWidgetItem()
        self.tabla_cuadruplos.setHorizontalHeaderItem(2, item)
        item = QtWidgets.QTableWidgetItem()
        self.tabla_cuadruplos.setHorizontalHeaderItem(3, item)
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(690, 510, 71, 16))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        self.label_3.setPalette(palette)
        self.label_3.setObjectName("label_3")
        self.tabla_simbolos = QtWidgets.QTableWidget(self.centralwidget)
        self.tabla_simbolos.setGeometry(QtCore.QRect(1120, 100, 211, 651))
        self.tabla_simbolos.setObjectName("tabla_simbolos")
        self.tabla_simbolos.setColumnCount(2)
        self.tabla_simbolos.setRowCount(0)
        item = QtWidgets.QTableWidgetItem()
        self.tabla_simbolos.setHorizontalHeaderItem(0, item)
        item = QtWidgets.QTableWidgetItem()
        self.tabla_simbolos.setHorizontalHeaderItem(1, item)
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(10, 510, 47, 13))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText,
                         brush)
        self.label_4.setPalette(palette)
        self.label_4.setObjectName("label_4")
        self.codigo_3d_optimizado = QtWidgets.QListWidget(self.centralwidget)
        self.codigo_3d_optimizado.setGeometry(QtCore.QRect(900, 100, 211, 401))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
        brush.setStyle(QtCore.Qt.NoBrush)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText,
                         brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
        brush.setStyle(QtCore.Qt.NoBrush)
        palette.setBrush(QtGui.QPalette.Inactive,
                         QtGui.QPalette.PlaceholderText, brush)
        brush = QtGui.QBrush(QtGui.QColor(120, 120, 120))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 128))
        brush.setStyle(QtCore.Qt.NoBrush)
        palette.setBrush(QtGui.QPalette.Disabled,
                         QtGui.QPalette.PlaceholderText, brush)
        self.codigo_3d_optimizado.setPalette(palette)
        self.codigo_3d_optimizado.setObjectName("codigo_3d_optimizado")
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1349, 21))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        self.menuReporte = QtWidgets.QMenu(self.menubar)
        self.menuReporte.setObjectName("menuReporte")
        self.menuRun = QtWidgets.QMenu(self.menubar)
        self.menuRun.setObjectName("menuRun")
        self.menuayuda = QtWidgets.QMenu(self.menubar)
        self.menuayuda.setObjectName("menuayuda")
        self.menuAUGUS = QtWidgets.QMenu(self.menubar)
        self.menuAUGUS.setObjectName("menuAUGUS")
        MainWindow.setMenuBar(self.menubar)
        self.actionEjecutar = QtWidgets.QAction(MainWindow)
        self.actionEjecutar.setObjectName("actionEjecutar")
        self.actionEjecutar.triggered.connect(self.ejecutar_optimizado)
        self.actionDebug = QtWidgets.QAction(MainWindow)
        self.actionDebug.setObjectName("actionDebug")
        self.actionArbol_Ascendente = QtWidgets.QAction(MainWindow)
        self.actionArbol_Ascendente.setObjectName("actionArbol_Ascendente")
        ############
        self.actionArbol_Ascendente.triggered.connect(self.show_ast)
        ############
        self.actionDGA = QtWidgets.QAction(MainWindow)
        self.actionDGA.setObjectName("actionDGA")
        ############
        self.actionDGA.triggered.connect(self.show_dga)
        ############
        self.actionAbrir = QtWidgets.QAction(MainWindow)
        self.actionAbrir.setObjectName("actionAbrir")
        self.actionAbrir.triggered.connect(self.abrir_archivo)
        self.actionGuardar = QtWidgets.QAction(MainWindow)
        self.actionGuardar.setObjectName("actionGuardar")
        self.actionGuardar_como = QtWidgets.QAction(MainWindow)
        self.actionGuardar_como.setObjectName("actionGuardar_como")
        self.actionBuscar = QtWidgets.QAction(MainWindow)
        self.actionBuscar.setObjectName("actionBuscar")
        self.actionReemplazar = QtWidgets.QAction(MainWindow)
        self.actionReemplazar.setObjectName("actionReemplazar")
        self.actionTabla_de_Simbolos = QtWidgets.QAction(MainWindow)
        self.actionTabla_de_Simbolos.setObjectName("actionTabla_de_Simbolos")
        ############
        self.actionTabla_de_Simbolos.triggered.connect(self.show_TS)
        ############
        self.actionErrores_Lexicos_y_Sintacticos = QtWidgets.QAction(
            MainWindow)
        self.actionErrores_Lexicos_y_Sintacticos.setObjectName(
            "actionErrores_Lexicos_y_Sintacticos")
        ############
        self.actionErrores_Lexicos_y_Sintacticos.triggered.connect(
            self.show_errores)
        ############
        self.actionReporte_Gramatical = QtWidgets.QAction(MainWindow)
        self.actionReporte_Gramatical.setObjectName("actionReporte_Gramatical")
        ############
        self.actionReporte_Gramatical.triggered.connect(self.show_RO)
        ############
        self.actionLexicos_y_Sintacticos = QtWidgets.QAction(MainWindow)
        self.actionLexicos_y_Sintacticos.setObjectName(
            "actionLexicos_y_Sintacticos")
        self.actionSemanticos = QtWidgets.QAction(MainWindow)
        self.actionSemanticos.setObjectName("actionSemanticos")
        self.actionTabla_de_simbolos = QtWidgets.QAction(MainWindow)
        self.actionTabla_de_simbolos.setObjectName("actionTabla_de_simbolos")
        self.actionArbol = QtWidgets.QAction(MainWindow)
        self.actionArbol.setObjectName("actionArbol")
        self.actionGramatical = QtWidgets.QAction(MainWindow)
        self.actionGramatical.setObjectName("actionGramatical")
        self.actionGramatical.triggered.connect(self.show_RG)
        self.menuFile.addAction(self.actionAbrir)
        self.menuFile.addAction(self.actionGuardar)
        self.menuFile.addAction(self.actionGuardar_como)
        self.menuFile.addAction(self.actionBuscar)
        self.menuFile.addAction(self.actionReemplazar)
        self.menuReporte.addAction(self.actionArbol_Ascendente)
        self.menuReporte.addAction(self.actionDGA)
        self.menuReporte.addAction(self.actionTabla_de_Simbolos)
        self.menuReporte.addAction(self.actionErrores_Lexicos_y_Sintacticos)
        self.menuReporte.addAction(self.actionReporte_Gramatical)
        self.menuRun.addAction(self.actionEjecutar)
        self.menuRun.addAction(self.actionDebug)
        self.menuAUGUS.addAction(self.actionLexicos_y_Sintacticos)
        self.menuAUGUS.addAction(self.actionSemanticos)
        self.menuAUGUS.addAction(self.actionTabla_de_simbolos)
        self.menuAUGUS.addAction(self.actionArbol)
        self.menuReporte.addAction(self.actionGramatical)
        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuReporte.menuAction())
        self.menubar.addAction(self.menuRun.menuAction())
        self.menubar.addAction(self.menuAUGUS.menuAction())
        self.menubar.addAction(self.menuayuda.menuAction())

        self.retranslateUi(MainWindow)
        self.editor.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def on_margin_clicked(self, nmargin, nline, modifiers):
        tab = self.editor.widget(self.editor.currentIndex())
        items = tab.children()

        if items[0].markersAtLine(nline) != 0:
            items[0].markerDelete(nline, 0)

        else:
            items[0].markerAdd(nline, 0)

    def Depurar_Alto_nivel(self):
        global traducir
        try:
            self.consola.clear()

            tab = self.editor.widget(self.editor.currentIndex())
            items = tab.children()
            codigo = items[0].text()
            ast = Gramatica.parse(codigo)
            lst_errores = Gramatica.lst_errores
            errores = GraficarError(args=(lst_errores, "Errores"), daemon=True)
            errores.start()
            gda = GramaticaGDA.parse(codigo)
            nodo = GramaticaM.parse(codigo)
            g_ast = GraficarArbol(args=(nodo, "AST"), daemon=True)
            g_ast.start()
            g_gda = GraficarGDA(args=(gda, "GDA"), daemon=True)
            g_gda.start()

            self.codigo_3d.clear()
            self.codigo_3d_optimizado.clear()
            #self.tabla_cuadruplos.clear()
            traducir = Depurar(args=(ast, self.tabla_cuadruplos,
                                     self.codigo_3d, self.consola,
                                     self.tabla_simbolos, items[0],
                                     self.codigo_3d_optimizado),
                               daemon=True)
            traducir.start()
        except:
            print("ERROR EN DEPURACION")

    def ms_help(self):
        msg = QtWidgets.QMessageBox(self.mw)
        msg.setIcon(QtWidgets.QMessageBox.Information)
        msg.setText("201408580")
        msg.setInformativeText("Andree Avalos")
        msg.setWindowTitle("Help")
        msg.setDetailedText(
            "Proyecto realizado para Compiladores 2 \n https://github.com/AndreeAvalos/OLC2-MINORC"
        )
        msg.exec_()

    def setStep(self):
        try:
            traducir.step = True
        except:
            em = QtWidgets.QErrorMessage(self.mw)
            em.setWindowTitle("ERROR!!!")
            em.showMessage("No se ha iniciado ningun proceso")

    def setContinuar(self):
        try:
            traducir.continuar = True
            traducir.step = True
        except:
            em = QtWidgets.QErrorMessage(self.mw)
            em.setWindowTitle("ERROR!!!")
            em.showMessage("No se ha iniciado ningun proceso")

    def detenerEjecucion(self):
        try:
            traducir.stop()
        except:
            em = QtWidgets.QErrorMessage(self.mw)
            em.setWindowTitle("ERROR!!!")
            em.showMessage("No se ha iniciado ningun proceso")

    def setLines(self):
        'cambiar color ide'

    def Traducir_Alto_nivel(self):
        global traducir
        try:
            self.consola.clear()
            #self.tabla_cuadruplos.clear()
            tab = self.editor.widget(self.editor.currentIndex())
            items = tab.children()
            codigo = items[0].text()
            ast = Gramatica.parse(codigo)
            lst_errores = Gramatica.lst_errores
            errores = GraficarError(args=(lst_errores, "Errores"), daemon=True)
            errores.start()
            gda = GramaticaGDA.parse(codigo)
            nodo = GramaticaM.parse(codigo)
            g_ast = GraficarArbol(args=(nodo, "AST"), daemon=True)
            g_ast.start()
            g_gda = GraficarGDA(args=(gda, "GDA"), daemon=True)
            g_gda.start()

            self.codigo_3d.clear()
            self.codigo_3d_optimizado.clear()
            traducir = Traducir(
                args=(ast, self.tabla_cuadruplos, self.codigo_3d, self.consola,
                      self.tabla_simbolos, self.codigo_3d_optimizado),
                daemon=True)
            traducir.start()
        except:
            print("ERROR EN EJECUCION NORMAL")

    def abrir_archivo(self):
        try:
            dialog = QtWidgets.QFileDialog().getOpenFileName(
                None, ' Open document', r"C:\Users\\", "All Files (*)")
            ruta = dialog[0]
            trozos = ruta.split("/")
            name = trozos[len(trozos) - 1]
            self.pestañas[name] = ruta
            file = open(ruta, 'r')
            codigo = file.read()
            tab = QtWidgets.QWidget()
            area = QsciScintilla(tab)
            area.setGeometry(QtCore.QRect(10, 10, 631, 371))
            area.setObjectName("plainTextEdit")
            area.setFont(self.__myFont)
            area.setMarginType(0, QsciScintilla.NumberMargin)
            area.setMarginWidth(0, "00000")
            area.setMarginsForegroundColor(QtGui.QColor("#0C4B72"))
            area.markerDefine(QsciScintilla.RightArrow, 0)
            area.setMarginSensitivity(0, True)
            area.setWrapMode(QsciScintilla.WrapWord)
            area.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
            area.setWrapIndentMode(QsciScintilla.WrapIndentIndented)
            area.setEolMode(QsciScintilla.EolWindows)
            area.setEolVisibility(False)
            area.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
            area.marginClicked.connect(self.on_margin_clicked)
            __lexer = QsciLexerCPP(area)
            area.setLexer(__lexer)
            self.editor.addTab(tab, "")
            area.setText(codigo)
            area.setObjectName("area")
            self.editor.addTab(tab, name)
            file.close()
        except:
            em = QtWidgets.QErrorMessage(self.mw)
            em.showMessage("Error al abrir {0}".format(name))

    def agregar_tab(self):
        text, okPressed = QInputDialog.getText(self.centralwidget,
                                               "Nuevo archivo", "Nombre:",
                                               QLineEdit.Normal, "")
        if okPressed and text != '':

            tab = QtWidgets.QWidget()
            area = QsciScintilla(tab)
            area.setGeometry(QtCore.QRect(10, 10, 631, 371))
            area.setObjectName("plainTextEdit")
            area.setFont(self.__myFont)
            area.setMarginType(0, QsciScintilla.NumberMargin)
            area.setMarginWidth(0, "00000")
            area.setMarginsForegroundColor(QtGui.QColor("#0C4B72"))
            area.markerDefine(QsciScintilla.RightArrow, 0)
            area.setMarginSensitivity(0, True)
            area.setWrapMode(QsciScintilla.WrapWord)
            area.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
            area.setWrapIndentMode(QsciScintilla.WrapIndentIndented)
            area.setEolMode(QsciScintilla.EolWindows)
            area.setEolVisibility(False)
            area.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
            area.marginClicked.connect(self.on_margin_clicked)
            __lexer = QsciLexerCPP(area)
            area.setLexer(__lexer)
            self.editor.addTab(tab, "")
            area.setObjectName("area")
            self.editor.addTab(tab, text + ".mc")

    def closeTab(self, index):
        tab = self.editor.widget(index)
        name = self.editor.tabText(self.editor.currentIndex())
        tab.deleteLater()
        self.editor.removeTab(index)

    def guardar(self):
        indextab = self.editor.tabText(self.editor.currentIndex())
        if indextab.split(".")[0] in self.pestañas:
            ruta = self.pestañas[indextab.split(".")[0]]
            trozos = ruta.split("/")
            name = indextab
            try:
                file = open(ruta, "w")
                tab = self.editor.widget(self.editor.currentIndex())
                items = tab.children()
                codigo = items[0].text()
                file.write(codigo)
                file.close()
            except:
                em = QtWidgets.QErrorMessage(self.mw)
                em.showMessage("No fue posible guardar {0}".format(name))

        else:
            self.gc = True
            self.nombre = indextab
            self.guardar_como()
            self.pestañas[self.nombre] = self.rutaTemp
            self.nombre = ""
            self.gc = False

    def guardar_como(self):

        if not self.gc:
            self.nombre, okPressed = QInputDialog.getText(
                self.centralwidget, "Nuevo archivo", "Nombre:",
                QLineEdit.Normal, "")
        carpeta = QtWidgets.QFileDialog().getExistingDirectory(
            self.centralwidget, "Seleccione carpeta")
        tname = self.nombre.split(".")
        name = tname[0]
        ruta = "{0}/{1}.mc".format(carpeta, name)
        self.nombre = name
        self.rutaTemp = ruta
        try:
            file = open(ruta, "w+")
            tab = self.editor.widget(self.editor.currentIndex())
            items = tab.children()
            codigo = items[0].text()
            file.write(codigo)
            file.close()
        except:
            em = QtWidgets.QErrorMessage(self.mw)
            em.showMessage("No fue posible guardar {0}".format(name))

    def show_ast(self):
        self.show("AST")

    def show_dga(self):
        self.show("GDA")

    def show_errores(self):
        self.show("Errores")

    def show_RO(self):
        self.show("reporteOptimizado")

    def show_TS(self):
        self.show("tabla_traducir")

    def show_RG(self):
        self.show("gramatical")

    def show(self, ruta):
        try:
            Dialog = QtWidgets.QDialog(self.mw)
            ui = Visor()
            ui.setupUi(Dialog, ruta + ".png")
            Dialog.show()
        except:
            em = QtWidgets.QErrorMessage(self.mw)
            em.setWindowTitle("ERROR!!!")
            em.showMessage("No se ha generado ningun reporte")

    def ejecutar_optimizado(self):
        global traducir
        try:
            file = open("codigo_optimizado.txt", "r")
            codigo = file.read()
            ast2 = GramaticaA.parse(codigo)
            ast3 = ast2.instruccion
            ts = TSA()
            recolector = Recolectar(ast3, ts, [])
            recolector.procesar()
            self.consola.clear()
            traducir = Ejecutor(args=(ast3, ts, [], "", self.consola,
                                      self.tabla_simbolos),
                                daemon=True)
            traducir.start()
        except:
            print("ERROR EN EJECUCION DE OPTIMIZADO")

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MinorC"))
        self.new_file.setText(_translate("MainWindow", "Nuevo"))
        self.save_file.setText(_translate("MainWindow", "Save"))
        self.save_file_as.setText(_translate("MainWindow", "Save as.."))
        self.ejecutar.setText(_translate("MainWindow", "Ejecutar"))
        self.depurar.setText(_translate("MainWindow", "Depurar"))
        self.parar.setText(_translate("MainWindow", "Parar"))
        self.step_step.setText(_translate("MainWindow", "->"))
        self.continuar.setText(_translate("MainWindow", "|>"))
        self.tema.setText(_translate("MainWindow", "Lineas"))
        self.lineas.setText(_translate("MainWindow", "Help"))
        self.editor.setTabText(self.editor.indexOf(self.tab),
                               _translate("MainWindow", "Tab 1"))
        self.label.setText(_translate("MainWindow", "Codigo AUGUS"))
        self.label_2.setText(
            _translate("MainWindow", "Codigo AUGUS optimizado"))
        item = self.tabla_cuadruplos.horizontalHeaderItem(0)
        item.setText(_translate("MainWindow", "op"))
        item = self.tabla_cuadruplos.horizontalHeaderItem(1)
        item.setText(_translate("MainWindow", "arg1"))
        item = self.tabla_cuadruplos.horizontalHeaderItem(2)
        item.setText(_translate("MainWindow", "arg2"))
        item = self.tabla_cuadruplos.horizontalHeaderItem(3)
        item.setText(_translate("MainWindow", "result"))
        self.label_3.setText(_translate("MainWindow", "Cuadruplos"))
        item = self.tabla_simbolos.horizontalHeaderItem(0)
        item.setText(_translate("MainWindow", "ID"))
        item = self.tabla_simbolos.horizontalHeaderItem(1)
        item.setText(_translate("MainWindow", "VALOR"))
        self.label_4.setText(_translate("MainWindow", "Consola"))
        self.menuFile.setTitle(_translate("MainWindow", "File"))
        self.menuReporte.setTitle(_translate("MainWindow", "Reporte"))
        self.menuRun.setTitle(_translate("MainWindow", "Run"))
        self.menuayuda.setTitle(_translate("MainWindow", "Help"))
        self.menuAUGUS.setTitle(_translate("MainWindow", "Augus"))
        self.actionEjecutar.setText(_translate("MainWindow", "Ejecutar"))
        self.actionDebug.setText(_translate("MainWindow", "Debug"))
        self.actionArbol_Ascendente.setText(
            _translate("MainWindow", "Arbol Ascendente"))
        self.actionDGA.setText(_translate("MainWindow", "GDA"))
        self.actionAbrir.setText(_translate("MainWindow", "Abrir"))
        self.actionGuardar.setText(_translate("MainWindow", "Guardar"))
        self.actionGuardar_como.setText(
            _translate("MainWindow", "Guardar como.."))
        self.actionBuscar.setText(_translate("MainWindow", "Buscar"))
        self.actionReemplazar.setText(_translate("MainWindow", "Reemplazar"))
        self.actionTabla_de_Simbolos.setText(
            _translate("MainWindow", "Tabla de Simbolos"))
        self.actionErrores_Lexicos_y_Sintacticos.setText(
            _translate("MainWindow", "Errores Lexicos y Sintacticos"))
        self.actionReporte_Gramatical.setText(
            _translate("MainWindow", "Reporte Optimizacion"))
        self.actionLexicos_y_Sintacticos.setText(
            _translate("MainWindow", "Lexicos y Sintacticos"))
        self.actionSemanticos.setText(_translate("MainWindow", "Semanticos"))
        self.actionTabla_de_simbolos.setText(
            _translate("MainWindow", "Tabla de simbolos"))
        self.actionArbol.setText(_translate("MainWindow", "Arbol"))
        self.actionGramatical.setText(_translate("MainWindow", "Gramatical"))
        self.consola.setHtml(
            _translate(
                "MainWindow",
                "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
                "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
                "p, li { white-space: pre-wrap; }\n"
                "</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
                "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:\'MS Shell Dlg 2\';\"><br /></p></body></html>"
            ))
예제 #8
0
class CustomMainWindow(QMainWindow):
    def __init__(self):
        super(CustomMainWindow, self).__init__()

        # -------------------------------- #
        #           Window setup           #
        # -------------------------------- #

        # 1. Define the geometry of the main window
        # ------------------------------------------
        self.setGeometry(300, 300, 800, 400)
        self.setWindowTitle("QScintilla Test")

        # 2. Create frame and layout
        # ---------------------------
        self.__frm = QFrame(self)
        self.__frm.setStyleSheet("QWidget { background-color: #ffeaeaea }")
        self.__lyt = QVBoxLayout()
        self.__frm.setLayout(self.__lyt)
        self.setCentralWidget(self.__frm)
        self.__myFont = QFont()
        self.__myFont.setPointSize(14)

        # 3. Place a button
        # ------------------
        self.__btn = QPushButton("Qsci")
        self.__btn.setFixedWidth(50)
        self.__btn.setFixedHeight(50)
        self.__btn.clicked.connect(self.__btn_action)
        self.__btn.setFont(self.__myFont)
        self.__lyt.addWidget(self.__btn)

        # -------------------------------- #
        #     QScintilla editor setup      #
        # -------------------------------- #

        # ! Make instance of QSciScintilla class!
        # ----------------------------------------
        self.__editor = QsciScintilla()
        self.__editor.setText("This\n")         # Line 1
        self.__editor.append("is\n")            # Line 2
        self.__editor.append("a\n")             # Line 3
        self.__editor.append("QScintilla\n")    # Line 4
        self.__editor.append("test\n")          # Line 5
        self.__editor.append("program\n")       # Line 6
        self.__editor.append("to\n")            # Line 7
        self.__editor.append("illustrate\n")    # Line 8
        self.__editor.append("some\n")          # Line 9
        self.__editor.append("basic\n")         # Line 10
        self.__editor.append("functions.")      # Line 11
        self.__editor.setLexer(None)
        self.__editor.setUtf8(True)             # Set encoding to UTF-8
        self.__editor.setFont(self.__myFont)

        # 1. Text wrapping
        # -----------------
        self.__editor.setWrapMode(QsciScintilla.WrapWord)
        self.__editor.setWrapVisualFlags(QsciScintilla.WrapFlagByText)
        self.__editor.setWrapIndentMode(QsciScintilla.WrapIndentIndented)

        # 2. End-of-line mode
        # --------------------
        self.__editor.setEolMode(QsciScintilla.EolWindows)
        self.__editor.setEolVisibility(False)

        # 3. Indentation
        # ---------------
        self.__editor.setIndentationsUseTabs(False)
        self.__editor.setTabWidth(4)
        self.__editor.setIndentationGuides(True)
        self.__editor.setTabIndents(True)
        self.__editor.setAutoIndent(True)

        # 4. Caret
        # ---------
        self.__editor.setCaretForegroundColor(QColor("#ff0000ff"))
        self.__editor.setCaretLineVisible(True)
        self.__editor.setCaretLineBackgroundColor(QColor("#1f0000ff"))
        self.__editor.setCaretWidth(2)

        # 5. Margins
        # -----------
        # Margin 0 = Line nr margin
        self.__editor.setMarginType(0, QsciScintilla.NumberMargin)
        self.__editor.setMarginWidth(0, "0000")
        self.__editor.setMarginsForegroundColor(QColor("#ff888888"))

        # Margin 1 = Symbol margin
        self.__editor.setMarginType(1, QsciScintilla.SymbolMargin)
        self.__editor.setMarginWidth(1, "00000")
        sym_0 = QImage("icons/sym_0.png").scaled(QSize(16, 16))
        sym_1 = QImage("icons/sym_1.png").scaled(QSize(16, 16))
        sym_2 = QImage("icons/sym_2.png").scaled(QSize(16, 16))
        sym_3 = QImage("icons/sym_3.png").scaled(QSize(16, 16))

        self.__editor.markerDefine(sym_0, 0)
        self.__editor.markerDefine(sym_1, 1)
        self.__editor.markerDefine(sym_2, 2)
        self.__editor.markerDefine(sym_3, 3)

        self.__editor.setMarginMarkerMask(1, 0b1111)

        # Display a few symbols, and keep their handles stored
        handle_01 = self.__editor.markerAdd(0, 0)   # Green dot on line 0+1
        handle_02 = self.__editor.markerAdd(4, 0)   # Green dot on line 4+1
        handle_03 = self.__editor.markerAdd(5, 0)   # Green dot on line 5+1
        handle_04 = self.__editor.markerAdd(8, 3)   # Red arrow on line 8+1
        handle_05 = self.__editor.markerAdd(9, 2)   # Red dot on line 9+1


        # ! Add editor to layout !
        # -------------------------
        self.__lyt.addWidget(self.__editor)
        self.show()

    ''''''

    def __btn_action(self):
        print("Hello World!")

    ''''''