示例#1
0
    def __init__(self, parent=None):
        super().__init__()
        self.parent = parent
        self.pressed = False
        self.font = QFont()
        self.dialog = MessageBox(self)
        self.font.setFamily(editor["editorFont"])
        self.font.setPointSize(12)
        self.layout = QVBoxLayout()

        self.setLayout(self.layout)
        self.output = None
        self.setFocusPolicy(Qt.StrongFocus)
        self.error = None
        self.finished = False
        self.clicked = False
        self.editor = OutputTextEdit(self)

        self.process = QProcess()
        self.state = None

        self.editor.userInputSignal.connect(self.attemptToWriteDataIntoProcess)
        self.process.readyReadStandardError.connect(
            self.onReadyReadStandardError)
        self.process.readyReadStandardOutput.connect(
            self.onReadyReadStandardOutput)
        self.process.finished.connect(self.finishedProcess)
        self.add()  # Add items to the layout
示例#2
0
    def __init__(self, callback, app=None, palette=None):
        super().__init__()

        directoryFont = QFont()
        self.app = app
        self.palette = palette

        self.currentPath: str = ""
        self.indexPath: str = ""

        directoryFont.setFamily(editor["directoryFont"])
        directoryFont.setPointSize(editor["directoryFontSize"])
        self.open_callback = callback
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.openMenu)
        self.setFont(directoryFont)
        self.layout = QHBoxLayout()
        self.model = QFileSystemModel()
        self.setModel(self.model)
        self.model.setRootPath(QDir.rootPath())
        self.setMaximumWidth(300)
        self.setIndentation(10)
        self.setAnimated(True)
        self.newFile()
        self.deleteFile()
        self.setSortingEnabled(True)
        self.setWindowTitle("Dir View")
        self.hideColumn(1)
        self.resize(200, 600)
        self.hideColumn(2)
        self.confirmation = MessageBox(self)
        self.hideColumn(3)
        self.doubleClicked.connect(self.openFile)
示例#3
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.fileName = None
        self.parent = parent
        self.debugging = False
        self.line = None
        self.column = None

        self.wordlist = []
        self.searchtext = None

        self.font = QFont()
        self.font.setFamily("Inconsolata")
        self.pointSize = editor["pointSize"]
        self.font.setPointSize(self.pointSize)
        self.dialog = MessageBox(self)
        self.verticalScrollBar().setStyleSheet("""
            background-color: transparent;
            """)

        self.horizontalScrollBar().setStyleSheet("""
            background-color: transparent;
            """)

        self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.setCaretForegroundColor(QColor("#FFFFFF"))
        self.setEdgeColumn(121)
        self.setEdgeMode(1)
        self.setEdgeColor(QColor("#8c8c8c"))
        self.setFont(self.font)
        self.setMarginSensitivity(1, True)
        self.markerDefine(QsciScintilla.RightArrow, 8)
        self.setMarkerBackgroundColor(QColor("#FF0000"), 8)
        self.indicator_number = 0
        self.indicator_value = 222
        self.indicator_color = QColor("#FF0000")
        self.draw_under_text = True
        # Initializing some stuff
        self.set_brace_colors(QColor("#98b4f9"), QColor("#edf40e"),
                              QColor("#98b4f9"), QColor("red"))

        self.cursorPositionChanged.connect(self.change_col)
        self.textChanged.connect(self.check_lines)

        self.set_linenumbers(QFontMetrics(self.font))
        self.setFoldMarginColors(QColor("#212121"), QColor("#212121"))
        self.set_indentation_settings()
示例#4
0
    def __init__(self, app, palette, editor, parent=None):
        super().__init__(parent)

        self.editor = editor  # Current config chosen (can be one of 3 config<N>.json)
        self.onStart(choiceIndex)  # Initializing config options
        self.status = QStatusBar(
            self
        )  # Status bar for displaying useful info like update found etc

        # Initializing the main widget where text is displayed
        self.tab = Tabs(self.cleanOpen, app, palette, self)
        # self.tabsOpen = []

        self.pic_opened = False  # This is used to open pictures but right now that feature is disabled
        self.dialog = MessageBox(
            self
        )  # Handles dialogs, for now it only creates the create new project dialog

        self.setWindowIcon(QIcon("resources/Python-logo-notext.svg_.png")
                           )  # Setting the window icon

        self.setWindowTitle("Hydra")  # Setting the window title

        self.status_font = QFont(
            editor["statusBarFont"],
            editor["statusBarFontSize"])  # Status bar font

        self.os = platform.system()

        self.tab.tabs.currentChanged.connect(
            self.fileNameChange
        )  # To change the title of the window when tab changes
        self.search = DocumentSearch(
        )  # To find documents in the whole system, also not quite working today

        # Initializing QActions that can be triggered from a QMenu or via keyboard shortcuts
        self.openterm()
        self.openterminal()
        # self.split2Tabs()
        self.new()
        self.newProject()
        self.findDocument()

        self.openProjectF()
        self.open()
        self.save()
        self.saveAs()
        self.exit()

        self.thread = UpdateThread(
        )  # Update checking runs on its own thread to prevent main GUI from blocking
        self.thread.start()

        # Data retrieved from the update thread gets processed check_updates
        self.thread.textSignal.connect(self.check_updates)

        # Attributes to manage opening directories and such
        self.dir_opened = False
        self._dir = None

        self.update_progress = QProgressBar()
        self.update_progress.setMaximumWidth(225)

        self.update_progress.setStyleSheet(self.update_progress.styleSheet())

        self.setCentralWidget(self.tab)  # QMainWindow's central widget

        self.files = None  # Tracking the current file that is open

        self.dead_code_thread = DeadCodeCheker()  # This checks for dead code

        self.dead_code_thread.infoSignal.connect(self.write_dead_code_info)

        self.stack = []  # Used for tracking when to check for dead code

        self.tab_to_write_to = None

        self.tagInfo = StatusLabel(text="", font=self.status_font)

        self.initUI()  # Main UI
示例#5
0
    def __init__(self, callback, app, palette, parent=None):
        super().__init__()
        self.app = app
        self.parent = parent
        self.palette = palette
        self.terminal = Terminal(self, False)
        self.tool_layout = QVBoxLayout()
        self.tool_layout_bar = QHBoxLayout()
        self.layout = QVBoxLayout(self)
        # Initialize tab screen
        self.tabs = QTabWidget()
        self.events = Events()
        self.tabs.setStyleSheet("""
           QTabWidget::pane { /* The tab widget frame */
                border-top: 0.5px solid #2c2c2c;
            }
            
            QTabWidget::tab-bar {
                
            }
            
            /* Style the tab using the tab sub-control. Note that
                it reads QTabBar _not_ QTabWidget */
            QTabBar::tab {
                background: #212121;
                border-bottom: 2px solid #303030;
                border-bottom-color: #434343;
                min-width: 8ex;
                margin-left: 10px;
                padding-left: 25px;
                padding-right: 20px;
                padding-top: 3px;
                padding-bottom: 3px;
            }
            
            QTabBar::tab:selected, QTabBar::tab:hover {
                background: #212121;
            }
            QToolTip {
                padding: 3px;
                font-family: \"Iosevka\";
                font-size: 14px; 
                color: #FFFFFF;
                background: #2c2c2c;
                
            }
            QTabBar::tab:selected {
                border-bottom-color: #FFFFFF; /* same as pane color */
            }
            """)
        font = QFont(editor["tabFont"])
        font.setPointSize(
            editor["tabFontSize"])  # This is the tab font and font size
        self.tabs.setFont(font)
        self.status = QStatusBar(self)
        self.dialog = MessageBox(self)
        self.tabs.usesScrollButtons()
        self.filelist = []

        self.tabSaved = False

        self.Console = Console(
            self)  # This is the terminal widget and the SECOND thread
        self.directory = Directory(callback, self.app,
                                   self.palette)  # TODO: This is top left
        self.directory.clearSelection()
        self.tabCounter = []
        # Add tabs
        self.tab_layout = QHBoxLayout(
        )  # Create new layout for original tab layout
        self.tab_layout.addWidget(self.tabs)  # Add tab widget to tab layout
        self.search_layout = QHBoxLayout()

        self.tabs.setTabsClosable(True)
        self.tabs.setMovable(
            editor["tabMovable"])  # Let's you make the tabs movable

        if (editor["tabShape"] is
                True):  # If tab shape is true then they have this rounded look
            self.tabs.setTabShape(1)

        else:
            self.tabs.setTabShape(0)  # If false, it has this boxy look

        self.tabs.tabCloseRequested.connect(self.closeTab)

        # Build Layout
        self.layout.addLayout(
            self.tab_layout)  # Adds 'TOP' layout : tab + directory
        self.layout.addLayout(self.search_layout)

        # Creating horizontal splitter
        self.splitterH = QSplitter(Qt.Horizontal)

        # Creating vertical splitter
        self.splitterV = QSplitter(Qt.Vertical)

        self.splitterV2 = QSplitter(Qt.Vertical)

        self.splitterV.addWidget(self.splitterH)
        self.layout.addWidget(self.splitterV)
        self.splitterV.setSizes([400, 10])
        self.setLayout(self.layout)  # Sets layout of QWidget

        self.closeShortcut = QShortcut(
            QKeySequence(editor["closeTabShortcut"]), self)
        self.closeShortcut.activated.connect(self.closeTabShortcut)

        self.getAllOpenTabs = QShortcut(QKeySequence("Ctrl+Shift+W"), self)
        self.getAllOpenTabs.activated.connect(self.getAllOpenTabsFunc)

        currentTab = self.tabs.currentWidget()
        self.layout.addLayout(self.tool_layout)
        self.layout.addWidget(self.splitterV)
        self.hideDirectory()
示例#6
0
class Tabs(QWidget):
    def __init__(self, callback, app, palette, parent=None):
        super().__init__()
        self.app = app
        self.parent = parent
        self.palette = palette
        self.terminal = Terminal(self, False)
        self.tool_layout = QVBoxLayout()
        self.tool_layout_bar = QHBoxLayout()
        self.layout = QVBoxLayout(self)
        # Initialize tab screen
        self.tabs = QTabWidget()
        self.events = Events()
        self.tabs.setStyleSheet("""
           QTabWidget::pane { /* The tab widget frame */
                border-top: 0.5px solid #2c2c2c;
            }
            
            QTabWidget::tab-bar {
                
            }
            
            /* Style the tab using the tab sub-control. Note that
                it reads QTabBar _not_ QTabWidget */
            QTabBar::tab {
                background: #212121;
                border-bottom: 2px solid #303030;
                border-bottom-color: #434343;
                min-width: 8ex;
                margin-left: 10px;
                padding-left: 25px;
                padding-right: 20px;
                padding-top: 3px;
                padding-bottom: 3px;
            }
            
            QTabBar::tab:selected, QTabBar::tab:hover {
                background: #212121;
            }
            QToolTip {
                padding: 3px;
                font-family: \"Iosevka\";
                font-size: 14px; 
                color: #FFFFFF;
                background: #2c2c2c;
                
            }
            QTabBar::tab:selected {
                border-bottom-color: #FFFFFF; /* same as pane color */
            }
            """)
        font = QFont(editor["tabFont"])
        font.setPointSize(
            editor["tabFontSize"])  # This is the tab font and font size
        self.tabs.setFont(font)
        self.status = QStatusBar(self)
        self.dialog = MessageBox(self)
        self.tabs.usesScrollButtons()
        self.filelist = []

        self.tabSaved = False

        self.Console = Console(
            self)  # This is the terminal widget and the SECOND thread
        self.directory = Directory(callback, self.app,
                                   self.palette)  # TODO: This is top left
        self.directory.clearSelection()
        self.tabCounter = []
        # Add tabs
        self.tab_layout = QHBoxLayout(
        )  # Create new layout for original tab layout
        self.tab_layout.addWidget(self.tabs)  # Add tab widget to tab layout
        self.search_layout = QHBoxLayout()

        self.tabs.setTabsClosable(True)
        self.tabs.setMovable(
            editor["tabMovable"])  # Let's you make the tabs movable

        if (editor["tabShape"] is
                True):  # If tab shape is true then they have this rounded look
            self.tabs.setTabShape(1)

        else:
            self.tabs.setTabShape(0)  # If false, it has this boxy look

        self.tabs.tabCloseRequested.connect(self.closeTab)

        # Build Layout
        self.layout.addLayout(
            self.tab_layout)  # Adds 'TOP' layout : tab + directory
        self.layout.addLayout(self.search_layout)

        # Creating horizontal splitter
        self.splitterH = QSplitter(Qt.Horizontal)

        # Creating vertical splitter
        self.splitterV = QSplitter(Qt.Vertical)

        self.splitterV2 = QSplitter(Qt.Vertical)

        self.splitterV.addWidget(self.splitterH)
        self.layout.addWidget(self.splitterV)
        self.splitterV.setSizes([400, 10])
        self.setLayout(self.layout)  # Sets layout of QWidget

        self.closeShortcut = QShortcut(
            QKeySequence(editor["closeTabShortcut"]), self)
        self.closeShortcut.activated.connect(self.closeTabShortcut)

        self.getAllOpenTabs = QShortcut(QKeySequence("Ctrl+Shift+W"), self)
        self.getAllOpenTabs.activated.connect(self.getAllOpenTabsFunc)

        currentTab = self.tabs.currentWidget()
        self.layout.addLayout(self.tool_layout)
        self.layout.addWidget(self.splitterV)
        self.hideDirectory()

    @pyqtSlot()
    def closeTabShortcut(self):
        self.index = self.tabs.currentIndex()
        self.closeTab(self.index)

    def getAllOpenTabsFunc(self):
        word = "import"
        for tab in range(self.tabs.count()):
            file = self.tabs.widget(tab).fileName
            if file not in self.filelist:
                self.filelist.append(file)

        for file in self.filelist:
            openedFileContents = open(file, "r").read()

    def closeTab(self, index):
        try:

            tab = self.tabs.widget(index)

            if tab.saved is True and tab.modified is False:
                tab.deleteLater()
                self.tabCounter.pop(index)
                self.filelist.pop(index)
                self.tabs.removeTab(index)

            elif tab.modified is True:
                self.dialog.saveMaybe(tab, self.tabCounter, self.tabs, index)

        except (AttributeError, IndexError) as E:
            try:
                tab.deleteLater()
                self.tabCounter.pop(index)
                self.filelist.pop(index)
                self.tabs.removeTab(index)
            except (AttributeError, IndexError) as E:
                print(E, " on line 175 in the file Tabs.py")

    def showDirectory(self):
        self.directory.setVisible(True)
        self.tab_layout.removeWidget(self.tabs)
        self.splitterV2.addWidget(self.directory)
        self.splitterV2.addWidget(self.events)
        self.splitterH.addWidget(self.splitterV2)
        self.splitterH.addWidget(
            self.tabs
        )  # Adding tabs, now the directory tree will be on the left

    def hideDirectory(self):
        self.tab_layout.removeWidget(self.directory)
        self.directory.setVisible(False)

    """
    Because the root layouts are set all you have to do now is just add/remove widgets from the parent layout associated
    This keeps the UI order set as intended as built above when initialized.
    """

    def hideConsole(self):
        self.splitterV.setSizes([0, 0])

    def showConsole(self):
        self.splitterV.addWidget(self.terminal)
        self.splitterV.setSizes([400, 10])
        self.terminal.clicked = False

    def hideFileExecuter(self):
        self.splitterV.setSizes([0, 0])

    def showFileExecuter(self):
        self.splitterV.addWidget(self.Console)
        self.splitterV.setSizes([400, 10])
        self.Console.clicked = False

    def currentTab(self):
        return self.tabs.currentWidget()
示例#7
0
class Console(QWidget):
    errorSignal = pyqtSignal(str)
    outputSignal = pyqtSignal(str)

    def __init__(self, parent=None):
        super().__init__()
        self.parent = parent
        self.pressed = False
        self.font = QFont()
        self.dialog = MessageBox(self)
        self.font.setFamily(editor["editorFont"])
        self.font.setPointSize(12)
        self.layout = QVBoxLayout()

        self.setLayout(self.layout)
        self.output = None
        self.setFocusPolicy(Qt.StrongFocus)
        self.error = None
        self.finished = False
        self.clicked = False
        self.editor = OutputTextEdit(self)

        self.process = QProcess()
        self.state = None

        self.editor.userInputSignal.connect(self.attemptToWriteDataIntoProcess)
        self.process.readyReadStandardError.connect(
            self.onReadyReadStandardError)
        self.process.readyReadStandardOutput.connect(
            self.onReadyReadStandardOutput)
        self.process.finished.connect(self.finishedProcess)
        self.add()  # Add items to the layout

    def attemptToWriteDataIntoProcess(self, input: str) -> None:

        if self.process.state() == QProcess.Running:
            self.process.write(input.encode())
            self.process.write(b"\n")

    def finishedProcess(self, exitCode: int, exitStatus: QProcess.ExitStatus):

        self.editor.setReadOnly(True)
        self.editor.appendPlainText(
            "\nProcess finished with exit code {}".format(exitCode))
        self.parent.tabs.currentWidget().editor.setFocus()

    def ispressed(self):
        return self.pressed

    def added(self):
        self.pressed = True

    def remove(self):
        self.parent.hideFileExecuter()
        self.clicked = True

    def hideTerminalClicked(self):
        return self.clicked

    def onReadyReadStandardError(self):
        try:
            try:
                self.error = self.process.readAllStandardError().data().decode(
                )
            except (UnicodeDecodeError) as e:
                print(e)
                self.error = ""
            self.editor.appendPlainText(self.error)

            self.errorSignal.emit(self.error)
            if self.error == "":
                pass
            else:
                self.error = self.error.split(os.linesep)[-2]
                self.dialog.helpword = str(self.error)
                self.dialog.getHelp(self.parent.parent)
        except (IndexError, UnicodeDecodeError) as E:

            print(E)

    def onReadyReadStandardOutput(self):
        try:
            self.result = self.process.readAllStandardOutput().data().decode()

            toIgnore: int = len(self.result.split("\n")[-1])
            self.editor.setIgnoreLength(toIgnore)

        except UnicodeDecodeError as E:
            print(E)
        try:
            self.editor.appendPlainText(self.result.strip("\n"))
            self.state = self.process.state()
        except RuntimeError:
            pass

        self.outputSignal.emit(self.result)

    def ifFinished(self, exitCode, exitStatus):
        self.finished = True

    def add(self):
        """Executes a system command."""
        # clear previous text
        self.added()
        self.button = QPushButton("Hide terminal")
        self.button.setFont(QFont("Iosevka", 11))
        self.button.setStyleSheet("""
                height: 20;
                background-color: #212121;

                """)

        self.terminateButton = QPushButton("   Stop")
        self.terminateButton.setIcon(QIcon("resources/square.png"))
        self.terminateButton.setFont(QFont("Iosevka", 11))
        self.terminateButton.clicked.connect(self.terminate)
        self.button.setFixedWidth(120)
        self.h_layout = QHBoxLayout()
        self.editor.setReadOnly(True)
        self.editor.setFont(self.font)
        self.layout.addWidget(self.button)
        self.layout.addWidget(self.editor)
        # self.layout.addWidget(self.terminateButton)
        self.button.clicked.connect(self.remove)

    def run(self, command,
            path):  # Takes in the command and the path of the file
        try:
            os.chdir(
                os.path.dirname(path)
            )  # We need to change the path to the path where the file is being ran from
        except Exception as E:
            print(E)

        self.editor.clear()

        if self.process.state() == 1 or self.process.state() == 2:

            self.process.kill()
            self.editor.setPlainText("Process already started, terminating")

        else:
            self.editor.setReadOnly(False)

            commands: list = command.split(" ")
            commands.insert(1, "-u")
            self.process.start(" ".join(commands))
            self.editor.appendPlainText("{} {}".format(commands[0],
                                                       commands[-1]))

            self.editor.setFocus()

    def terminate(self):
        if self.process.state() == 2:
            self.process.kill()
示例#8
0
class Directory(QTreeView):
    def __init__(self, callback, app=None, palette=None):
        super().__init__()

        directoryFont = QFont()
        self.app = app
        self.palette = palette

        self.currentPath: str = ""
        self.indexPath: str = ""

        directoryFont.setFamily(editor["directoryFont"])
        directoryFont.setPointSize(editor["directoryFontSize"])
        self.open_callback = callback
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.openMenu)
        self.setFont(directoryFont)
        self.layout = QHBoxLayout()
        self.model = QFileSystemModel()
        self.setModel(self.model)
        self.model.setRootPath(QDir.rootPath())
        self.setMaximumWidth(300)
        self.setIndentation(10)
        self.setAnimated(True)
        self.newFile()
        self.deleteFile()
        self.setSortingEnabled(True)
        self.setWindowTitle("Dir View")
        self.hideColumn(1)
        self.resize(200, 600)
        self.hideColumn(2)
        self.confirmation = MessageBox(self)
        self.hideColumn(3)
        self.doubleClicked.connect(self.openFile)

    def newFile(self):

        self.newAct = QAction("New")
        self.newAct.setStatusTip("Create a new file")
        self.newAct.triggered.connect(lambda: print("new"))

    def deleteFile(self):

        self.deleteFileAct = QAction("Delete file")
        self.deleteFileAct.triggered.connect(self.delete)

    def delete(self):

        if len(self.indexPath) != 0:

            if os.path.isdir(self.indexPath):
                os.rmdir(self.indexPath)
            else:
                os.remove(self.indexPath)

    def openMenu(self, position):

        indexes = self.selectedIndexes()
        if len(indexes) > 0:
            level = 0
            index = indexes[0]
            while index.parent().isValid():
                index = index.parent()
                level += 1

        filePath = self.currentPath + "/" + indexes[0].data()
        self.indexPath = filePath
        menu = QMenu()
        menu.addAction(
            self.newAct
        )  # TODO: Add more context menu stuff and make them functional
        menu.addAction(self.deleteFileAct)
        menu.exec_(self.viewport().mapToGlobal(position))

    def focusInEvent(self, event):
        # If we are focused then we change the selected item highlighting color
        self.focused = True
        self.palette.setColor(QPalette.Highlight,
                              QColor(editor["HighlightColor"]).lighter())

        self.app.setPalette(self.palette)

    def focusOutEvent(self, event):
        # If we un focus from the QTreeView then we make the highlighted item color white
        self.palette.setColor(
            QPalette.Highlight,
            QColor(editor["UnfocusedHighlightColor"]).lighter())
        # self.clearSelection() Uncomment this if you want to remove all highlighting when unfocused
        self.app.setPalette(self.palette)

    def openDirectory(self, path):
        self.setRootIndex(self.model.index(path))
        self.currentPath = path

    def openFile(self, signal):
        file_path = self.model.filePath(signal)
        if file_path[-3:] in ["gif", "png", "jpg", "bmp"
                              ] or file_path[-4:] in ["jpeg"]:
            pic_opened = True
        else:
            pic_opened = False
        self.open_callback(file_path, pic_opened)
        return file_path

    def keyPressEvent(self, event):
        key = event.key()
        if key == Qt.Key_Delete:

            try:
                self.fileObject = self.selectedIndexes()[0]
                fileName = self.model.filePath(self.fileObject)
                self.confirmation.run("Are you sure you want to delete ",
                                      str(fileName))

            except IndexError:
                print("No file selected")
示例#9
0
class Editor(QsciScintilla):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.fileName = None
        self.parent = parent
        self.debugging = False
        self.line = None
        self.column = None

        self.wordlist = []
        self.searchtext = None

        self.font = QFont()
        self.font.setFamily("Inconsolata")
        self.pointSize = editor["pointSize"]
        self.font.setPointSize(self.pointSize)
        self.dialog = MessageBox(self)
        self.verticalScrollBar().setStyleSheet("""
            background-color: transparent;
            """)

        self.horizontalScrollBar().setStyleSheet("""
            background-color: transparent;
            """)

        self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.setCaretForegroundColor(QColor("#FFFFFF"))
        self.setEdgeColumn(121)
        self.setEdgeMode(1)
        self.setEdgeColor(QColor("#8c8c8c"))
        self.setFont(self.font)
        self.setMarginSensitivity(1, True)
        self.markerDefine(QsciScintilla.RightArrow, 8)
        self.setMarkerBackgroundColor(QColor("#FF0000"), 8)
        self.indicator_number = 0
        self.indicator_value = 222
        self.indicator_color = QColor("#FF0000")
        self.draw_under_text = True
        # Initializing some stuff
        self.set_brace_colors(QColor("#98b4f9"), QColor("#edf40e"),
                              QColor("#98b4f9"), QColor("red"))

        self.cursorPositionChanged.connect(self.change_col)
        self.textChanged.connect(self.check_lines)

        self.set_linenumbers(QFontMetrics(self.font))
        self.setFoldMarginColors(QColor("#212121"), QColor("#212121"))
        self.set_indentation_settings()

    def set_up_tooltips(self):
        self.setCallTipsStyle(QsciScintilla.CallTipsNoContext)
        self.setCallTipsVisible(0)

        self.setCallTipsPosition(QsciScintilla.CallTipsAboveText)
        self.setCallTipsBackgroundColor(QColor("#FF0000"))

        self.setCallTipsForegroundColor(QColor("#FF0000"))
        self.setCallTipsHighlightColor(QColor("#FF0000"))

    def set_brace_colors(self,
                         matched_B=None,
                         matched_F=None,
                         unmatched_B=None,
                         unmatched_F=None):

        self.setMatchedBraceBackgroundColor(matched_B)
        self.setMatchedBraceForegroundColor(matched_F)
        self.setUnmatchedBraceBackgroundColor(unmatched_B)
        self.setUnmatchedBraceForegroundColor(unmatched_F)

        self.setBraceMatching(QsciScintilla.SloppyBraceMatch)

    def set_linenumbers(self, fontmetrics):
        self.setMarginsFont(self.font)

        self.setMarginWidth(0, fontmetrics.width("00000"))
        self.setMarginLineNumbers(0, True)

        self.setMarginsBackgroundColor(QColor("#212121"))
        self.setMarginsForegroundColor(QColor("#FFFFFF"))

    def set_indentation_settings(self):
        self.setIndentationsUseTabs(False)
        self.setTabWidth(4)

        self.SendScintilla(QsciScintilla.SCI_SETUSETABS, False)
        self.setAutoIndent(True)

        self.setTabIndents(True)

    def check_lines(self):
        line_n = self.lines()
        for i in range(line_n):
            if self.lineLength(i) > 121:
                # TODO: Make a character format or something
                pass
                #  print("Line over 121 characters on line", str(i+1))
                # self.setCursorPosition(i, 120)

    def python_highlighter(self):
        self.lexer = PythonLexer()
        self.lexer.setFoldComments(True)
        self.setCaretLineVisible(True)

        self.setDefaultSettings(self.lexer)
        self.setPythonAutocomplete()
        self.setFold()

    def json_highlighter(self):
        lexer = QsciLexerJSON()
        self.setDefaultSettings(lexer)

    def c_highlighter(self):
        lexer = QsciLexerCPP()
        self.setDefaultSettings(lexer)

    def xml_highlighter(self):
        lexer = QsciLexerXML()
        self.setDefaultSettings(lexer)

    def html_highlighter(self):
        lexer = QsciLexerHTML()
        self.setDefaultSettings(lexer)

    def setDefaultSettings(self, lexer):
        # self.setAutoIndent(True)
        lexer.setFont(self.font)

        lexer.setColor(QColor("white"), 0)  # default
        lexer.setColor(QColor("#6B6E6C"), PythonLexer.Comment)  # = 1
        lexer.setColor(QColor("#ADD4FF"), 2)  # Number = 2
        lexer.setColor(QColor("#38ef7d"), 3)  # DoubleQuotedString
        lexer.setColor(QColor("#38ef7d"), 4)  # SingleQuotedString
        lexer.setColor(QColor("#F6DC74"), 5)  # Keyword
        lexer.setColor(QColor("#38ef7d"), 6)  # TripleSingleQuotedString
        lexer.setColor(QColor("#38ef7d"), 7)  # TripleDoubleQuotedString
        lexer.setColor(QColor("#74F6C3"), 8)  # ClassName
        lexer.setColor(QColor("#FF6666"), 9)  # FunctionMethodName
        lexer.setColor(QColor("magenta"), 10)  # Operator
        lexer.setColor(QColor("white"), 11)  # Identifier
        lexer.setColor(QColor("gray"), 12)  # CommentBlock
        lexer.setColor(QColor("#a8ff78"), 13)  # UnclosedString
        lexer.setColor(QColor("gray"), 14)  # HighlightedIdentifier
        lexer.setColor(QColor("#FF00E7"), 15)  # Decorator

        lexer.setFont(QFont("Iosevka", weight=QFont.Bold), 5)
        self.setCaretLineBackgroundColor(QColor("#3C3B3F"))
        self.setLexer(lexer)

    def setPythonAutocomplete(self):
        self.autocomplete = QsciAPIs(self.lexer)
        self.keywords = wordList

        for word in self.keywords:
            self.autocomplete.add(word)

        self.setAutoCompletionThreshold(2)

        self.setAutoCompletionSource(QsciScintilla.AcsAPIs)
        self.updateAutoComplete(self.parent.fileName)

        self.autocomplete.prepare()

    def setFold(self):
        # setup Fold Styles for classes and functions ...
        x = self.FoldStyle(self.FoldStyle(5))
        # self.textPad.folding()
        if not x:
            self.foldAll(False)

        self.setFolding(x)
        # self.textPad.folding()

    def unsetFold(self):
        self.setFolding(0)

    def updateAutoComplete(self, file_path=None):

        for i in tokenize(file_path):
            for j in i:
                if j not in self.wordlist:
                    self.wordlist.append(j)
        for word in self.wordlist:
            self.autocomplete.add(word)

        self.autocomplete.prepare()

    def change_col(self, line,
                   column):  # Responsible for changing the column bar.
        self.line = line
        self.column = column

    def check_if_func(self, word):  # Checks if a word is a built in function
        word_array = list(word)
        for wo in word_array:
            if wo in ["{", "}", "'", '"', "[", "]", "(", ")"]:
                word_array.remove(wo)
        for w in funcList:
            if w == "".join(word_array):
                return True

    def check_if_error(self, word):
        if word in errorList:  # This is the list where all possible errors are defined
            return True

    def keyReleaseEvent(self, e):
        if e.key() == Qt.Key_Return:
            try:
                self.updateAutoComplete(self.parent.fileName)
            except AttributeError as E:
                print(E, "on line 210 in TextEditor.py")

        if e.key() == Qt.Key_Backspace:
            pass

    def mousePressEvent(self, e):
        super().mousePressEvent(e)

        if QGuiApplication.queryKeyboardModifiers() == Qt.ControlModifier:
            word = self.wordAtLineIndex(self.getCursorPosition()[0],
                                        self.getCursorPosition()[1])
            print(word)
            if self.check_if_func(word):
                url = "https://docs.python.org/3/library/functions.html#" + word
                self.parent.parent.openBrowser(
                    url, word)  # Runs the openBrowser function in Main class
            elif self.check_if_error(word):
                url = "https://docs.python.org/3/library/exceptions.html#" + word
                print(url)

                self.parent.parent.openBrowser(url, word)

    def keyPressEvent(self, e):
        if e.modifiers() == Qt.ControlModifier and e.key() == Qt.Key_F:
            text, okPressed = QInputDialog.getText(self, "Find", "Find what: ")

            self.setSelectionBackgroundColor(QColor("#6be585"))

            if okPressed:
                if text == "":
                    text = " "
                    self.dialog.noMatch(text)

                self.searchtext = text
                """
                This is the way to implement a search function using QScintilla 
                http://pyqt.sourceforge.net/Docs/QScintilla2/classQsciScintilla.html#a37ac2bea94eafcfa639173557a821200
                """

                if self.findFirst(self.searchtext, False, True, False, True,
                                  True, -1, -1, True, False):
                    pass
                else:
                    self.dialog.noMatch(self.searchtext)

        if e.key() == Qt.Key_F3:
            self.findNext()
            self.setSelectionBackgroundColor(QColor("#6be585"))

        if e.modifiers() == Qt.ControlModifier and e.key() == Qt.Key_L:
            self.setCursorPosition(self.line, self.column + 1)
            return
        if e.modifiers() == Qt.ControlModifier and e.key() == 77:

            self.setCursorPosition(self.line + 1, self.column)
            return
        if e.modifiers() == Qt.ControlModifier and e.key() == Qt.Key_J:
            self.setCursorPosition(self.line, self.column - 1)

        if e.modifiers() == Qt.ControlModifier and e.key() == Qt.Key_I:
            self.setCursorPosition(self.line - 1, self.column)

        if e.modifiers() == Qt.ControlModifier and e.key() == Qt.Key_T:
            self.parent.parent.realterminal()
            return

        super().keyPressEvent(e)