def chooseFont(self): font, ok = QFontDialog.getFont() if ok: config.font = font try: self.getEditor(self.tab.currentIndex()).lexer().setFont( config.font) except AttributeError: self.getEditor(self.tab.currentIndex()).setLang( QsciLexerText()) #print self.getEditor(self.tab.currentIndex()).lexer() self.getEditor(self.tab.currentIndex()).lexer().setFont( config.font)
def initUI(self): # Create first qsplitter for sidebar self.treeSplit = QSplitter() self.treeSplit.setOrientation(Qt.Horizontal) # Create second qsplitter (Allows split screen for terminal) self.termSplit = QSplitter() self.termSplit.setOrientation(Qt.Vertical) # Add a termSplit to the treeSplit self.treeSplit.addWidget(self.termSplit) self.setCentralWidget(self.treeSplit) # Create everything else self.initTabs() self.initActions() self.initMenubar() # Create terminal widget and automatically hide it because otherwise # it will awkwardly hover in the corner self.term = Terminal() #self.term.hide() # x and y coordinates on the screen, width, height self.setGeometry(100, 100, 800, 630) self.setWindowTitle("Codex") # Move up to the parent directory and set the window icons. # Without os.path it will look for icons in src/ self.setWindowIcon( QIcon( os.path.join(os.path.dirname(__file__)) + "/icons/256x256/codex.png")) # Open any documents that were open before closing and restore settings QTimer.singleShot(0, self.loadDocs) self.readSettings() # Show the terminal/tree if necessary. self.loadTermAndTree() # If there are no documents to load set the language as plain text # If there are documents to load guess lexers for them if len(config.docList) == 0: self.getEditor(self.tabNum).setLang(QsciLexerText()) self.noLexAct.setChecked(True) else: self.guessLexer() # Set font self.getEditor(self.tab.currentIndex()).lexer.setFont(config.font)
def initActions(self): self.newAction = QAction("New Window", self) self.newAction.setShortcut("Ctrl+N") self.newAction.triggered.connect(self.new) self.newTabAction = QAction("New Tab", self) self.newTabAction.setShortcut("Ctrl+T") self.newTabAction.triggered.connect(self.newTab) self.openAction = QAction("Open file", self) self.openAction.setShortcut("Ctrl+O") self.openAction.triggered.connect(self.openFile) self.saveAction = QAction("Save", self) self.saveAction.setShortcut("Ctrl+S") self.saveAction.triggered.connect(self.saveFile) self.saveasAction = QAction("Save As", self) self.saveasAction.setShortcut("Ctrl+Shift+S") self.saveasAction.triggered.connect(self.saveFileAs) self.cutAction = QAction("Cut", self) self.cutAction.setShortcut("Ctrl+X") self.cutAction.triggered.connect( lambda cut: self.getEditor(self.tab.currentIndex()).cut) self.copyAction = QAction("Copy", self) self.copyAction.setShortcut("Ctrl+C") self.copyAction.triggered.connect( lambda copy: self.getEditor(self.tab.currentIndex()).copy) self.pasteAction = QAction("Paste", self) self.pasteAction.setShortcut("Ctrl+V") self.pasteAction.triggered.connect( lambda paste: self.getEditor(self.tab.currentIndex()).paste) self.undoAction = QAction("Undo", self) self.undoAction.setShortcut("Ctrl+Z") self.undoAction.triggered.connect( lambda undo: self.getEditor(self.tab.currentIndex()).undo) self.redoAction = QAction("Redo", self) self.redoAction.setShortcut("Ctrl+Y") self.redoAction.triggered.connect( lambda redo: self.getEditor(self.tab.currentIndex()).redo) self.aboutAction = QAction("About Codex", self) self.aboutAction.triggered.connect(self.about) self.noLexAct = QAction("Plain Text", self) self.noLexAct.triggered.connect(lambda noLex: self.getEditor(self.tab.currentIndex()).\ setLexer(QsciLexerText())) self.termAct = QAction("Terminal", self) self.termAct.setCheckable(True) self.termAct.triggered.connect(self.toggleTerm) self.treeAct = QAction("File Tree", self) self.treeAct.setCheckable(True) self.treeAct.triggered.connect(self.toggleTree) self.toggleIntAct = QAction("Indentation Guides", self) self.toggleIntAct.triggered.connect(self.toggleIntGuide) self.toggleIntAct.setCheckable(True) self.toggleIntAct.setChecked(True) self.toggleLNAct = QAction("Line Numbers", self) self.toggleLNAct.triggered.connect(self.toggleLN) self.toggleLNAct.setCheckable(True) self.toggleLNAct.setChecked(True) self.FRAct = QAction("Find and Replace", self) self.FRAct.triggered.connect(self.fr) self.FRAct.setShortcut("Ctrl+F") self.fontAct = QAction("Choose Font", self) self.fontAct.triggered.connect(self.chooseFont) self.dirAct = QAction("Choose Project Directory", self) self.dirAct.triggered.connect(self.setProDir)
def guessLexer(self): try: x = config.docList[self.tab.currentIndex() + 1] n, e = os.path.basename(x).lower().split(".") if e == "sh" or e == "bsh": self.getEditor(self.tabNum).setLang("Bash") elif e == "cmd" or e == "bat" or e == "btm" or e == "nt": self.getEditor(self.tabNum).setLang("Batch") elif e == "cmake" or e == "cmakelists": self.getEditor(self.tabNum).setLang("CMake") elif e == "cpp" or e == "cxx" or e == "cc" or e == "c" or e == "h"\ or e == "hh" or e == "hpp": self.getEditor(self.tabNum).setLang("C++") elif e == "cs": self.getEditor(self.tabNum).setLang("C#") elif e == "css": self.getEditor(self.tabNum).setLang("CSS") elif e == "d": self.getEditor(self.tabNum).setLang("D") elif e == "diff" or e == "patch": self.getEditor(self.tabNum).setLang("Diff") elif e == "f90" or e == "f95" or e == "f2k" or e == "f03" or e == "f15": self.getEditor(self.tabNum).setLang("Fortran") elif e == "f" or e == "for": self.getEditor(self.tabNum).setLang("Fortran77") elif e == "html" or e == "htm": self.getEditor(self.tabNum).setLang("HTML") elif e == "java": self.getEditor(self.tabNum).setLang("Java") elif e == "js": self.getEditor(self.tabNum).setLang("JavaScript") elif e == "lua": self.getEditor(self.tabNum).setLang("Lua") elif e == "mak" or n == "gnumakefile" or n == "makefile": self.getEditor(self.tabNum).setLang("Makefile") elif e == "m": self.getEditor(self.tabNum).setLang("MATLAB") elif e == "pas" or e == "inc": self.getEditor(self.tabNum).setLang("Pascal") elif e == "ps": self.getEditor(self.tabNum).setLang("PostScript") elif e == "pov" or e == "tga": self.getEditor(self.tabNum).setLang("POV-Ray") elif e == "py" or e == "pyw": self.getEditor(self.tabNum).setLang("Python") #print "p" elif e == "rb" or e == "rbw": self.getEditor(self.tabNum).setLang("Ruby") elif e == "cir": self.getEditor(self.tabNum).setLang("Spice") elif e == "sql": self.getEditor(self.tabNum).setLang("SQL") elif e == "tcl": self.getEditor(self.tabNum).setLang("TCL") elif e == "tex": self.getEditor(self.tabNum).setLang("TeX") elif e == "v" or e == "sv" or e == "vh" or e == "svh": self.getEditor(self.tabNum).setLang("Verilog") elif e == "vhd" or e == "vhdl": self.getEditor(self.tabNum).setLang("VHDL") elif e == "xml" or e == "xsl" or e == "xsml" or e == "xsd" or \ e == "kml" or e == "wsdl" or e == "xlf" or e == "xliff": self.getEditor(self.tabNum).setLang("XML") elif e == "yml": self.getEditor(self.tabNum).setLang("YML") except (ValueError, IndexError): self.lexer = QsciLexerText() self.lexer.setDefaultFont(config.font) self.lexer.setDefaultColor(QColor("Black")) self.getEditor(self.tabNum).setLexer(self.lexer) self.noLexAct.setChecked(True)
""" import sys, os from PyQt5.Qsci import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtGui import * from lexers.TextLexer import QsciLexerText LEXERS = { 'PHP': QsciLexerHTML(), 'Python': QsciLexerPython(), } docList = [] if sys.platform.startswith("linux"): font = QFont("DejaVu Sans Mono", 10, 50) elif sys.platform.startswith("darwin"): font = QFont("Menlo", 10, 50) elif sys.platform.startswith("win"): font = QFont("Courier New", 10, 50) lexer = QsciLexerText() proDir = "" def getWorkingDir(): return os.getcwd() from window import mainWindow m = mainWindow()