Esempio n. 1
0
	def openFile(self):
		file_path =  QtGui.QFileDialog.getOpenFileName(self,u'打开文件',"" ,u"All Files(*.*);;纯文本 (*.txt)")
		self.setWindowTitle(file_path+"  - Raymond Text")
		self.NewTab = QtGui.QWidget()
		#显示右键菜单
		self.NewTab.customContextMenuRequested.connect(self.TabRightMenu)
		self.loxLayout = QtGui.QVBoxLayout(self.NewTab)
		self.loxLayout.setContentsMargins(0, 0, 0, 0)
		self.textEdit = QsciScintilla(self.NewTab)
		self.textEdit.setToolTip(_fromUtf8(""))
		self.textEdit.setWhatsThis(_fromUtf8(""))
		if file_path:
			self.loxLayout.addWidget(self.textEdit)
			self.tabWidget.addTab(self.NewTab, _fromUtf8(""))
			self.textEdit.setText(open(file_path,'r').read())
			#获取文件名称
			file_name=os.path.basename(str(file_path))
			con=connect(self.dataBaseName)
			cur=con.cursor()
			res=(file_name,str(file_path),0,0)
			cur.execute('insert into grouping_data (name,address,groupid,iconPath) values (?,?,?,?)',res)
			con.commit()
			con.close()
			self.tabWidget.setTabText(self.tabWidget.indexOf(self.NewTab), _translate("MainWindow", file_name, None))
			self.tabWidget.setCurrentIndex(self.tabWidget.currentIndex()+1)
			self.setTextEdit()
Esempio n. 2
0
	def newFile(self,file):
		# self.tabWidget.setTabBar(HorizontalTabBar())
		#获取QtabBar id信号槽
		self.NewTab = QtGui.QWidget()
		#显示右键菜单
		self.NewTab.setContextMenuPolicy(3)
		self.NewTab.customContextMenuRequested.connect(self.TabRightMenu)
		self.loxLayout = QtGui.QVBoxLayout(self.NewTab)
		self.loxLayout.setContentsMargins(0, 0, 0, 0)
		self.textEdit = QsciScintilla(self.NewTab)
		self.textEdit.setToolTip(_fromUtf8(""))
		self.textEdit.setWhatsThis(_fromUtf8(""))
		if file:
			self.loxLayout.addWidget(self.textEdit)
			self.tabWidget.addTab(self.NewTab, _fromUtf8(""))
			self.textEdit.setText(open(file,'r').read())
			#获取文件名称
			file_name = os.path.basename(file)
			self.tabWidget.setTabText(self.tabWidget.indexOf(self.NewTab), _translate("MainWindow", file_name, None))
			self.setWindowTitle(file+"  - Raymond Text")
		else:
			self.loxLayout.addWidget(self.textEdit)
			self.tabWidget.addTab(self.NewTab, _fromUtf8(""))
			self.tabWidget.setTabText(self.tabWidget.indexOf(self.NewTab), _translate("MainWindow", "新建文件", None))
			self.setWindowTitle(u"Raymond Text")
		# self.tabWidget.setStatusTip(u'行 113, 列 55')
		self.tabWidget.setCurrentIndex(self.tabWidget.currentIndex()+1)
		self.setTextEdit()
Esempio n. 3
0
    def get_editor(self):
        """
        Return an editor object based on QScintilla if available.
        Else, return a standard editor.
        """

        try:
            from PyQt4.Qsci import QsciScintilla, QsciLexerPython, QsciAPIs
            
            textedit = QsciScintilla(self)
            textedit.setAutoIndent(True)
            textedit.setAutoCompletionThreshold(2)
            textedit.setAutoCompletionSource(QsciScintilla.AcsDocument)

            # API
            lex = QsciLexerPython(textedit)
            textedit.setLexer(lex)

#             apis = QsciAPIs(lex)
#             apis.prepare()
            
            textedit.setMinimumWidth(250)
            textedit.setMinimumHeight(250)
            
        except ImportError:
            textedit = qt.QtGui.QTextEdit(self)
            textedit.setLineWrapMode(qt.QtGui.QTextEdit.NoWrap)
            textedit.setMinimumWidth(200)
            textedit.setMinimumHeight(200)

        return textedit
Esempio n. 4
0
    def __init__(self, filename='', parent=None):
        '''
        Constructor
        '''
        QWidget.__init__(self, parent)

        self.filename = filename
        self.label = 'untitled'
        self.modified = False

        self.layout = QVBoxLayout(self)
        self.editor = QsciScintilla()
        self.layout.addWidget(self.editor, stretch=1)

        # Give the editor its content
        if len(filename) > 0:
            # Open the file and read in its contents
            f = open(filename, 'r')
            contents = f.read()
            self.editor.setText(contents)
            f.close()

            self.label = os.path.basename(filename)

        # Setup the features of the editor
        lexer = QsciLexerJavaScript()
        self.editor.setLexer(lexer)

        # Connect signals
        self.editor.textChanged.connect(self.onTextChanged)
Esempio n. 5
0
 def __init__(self):
     QMainWindow.__init__(self)
     self.setWindowTitle('Custom Lexer For Config Files')
     self.setGeometry(50, 200, 400, 400)
     self.editor = QsciScintilla(self)
     self.editor.setUtf8(True)
     self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle)
     self.setCentralWidget(self.editor)
     self.lexer = ConfigLexer(self.editor)
     self.editor.setLexer(self.lexer)
     self.editor.setText(_sample)
Esempio n. 6
0
    def newtab(self, tw, tname):
        newtab = QtGui.QWidget()
        vlayout = QtGui.QVBoxLayout()
        vlayout.setMargin(0)

        neweditor = QsciScintilla(newtab)
        neweditor.setStyleSheet("border:0")
        self.setupui(neweditor, self.font)
        neweditor.setLexer(self.lexer)

        vlayout.addWidget(neweditor)
        newtab.setLayout(vlayout)

        return tw.addTab(newtab, os.path.basename(str(tname))), neweditor
Esempio n. 7
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowTitle('Custom Lexer For Config Files')
        self.setGeometry(50, 200, 400, 400)
        self.editor = QsciScintilla(self)
        self.editor.setUtf8(True)

        # LINES' NUMBER IN THE MARGIN
        self.editor.setMarginLineNumbers(1, True)
        self.editor.setMarginWidth(1, QString("-------"))
        # OK for 3 digits. This was found by direct tests...
        # WRAPING
        self.editor.setWrapMode(True)

        self.setCentralWidget(self.editor)
        self.lexer = ConfigLexer(self.editor)
        self.editor.setLexer(self.lexer)
        self.editor.setText(_sample)
Esempio n. 8
0
    def _initEditor(self):
        self.ui.sqlEditor = QsciScintilla(self)
        self.ui.sqlEditor.textChanged.connect(self.setValidQuery)
        # Don't want to see the horizontal scrollbar at all
        self.ui.sqlEditor.SendScintilla(QsciScintilla.SCI_SETHSCROLLBAR, 0)

        self.ui.sqlEditor.setMarginLineNumbers(0, True)
        self.ui.sqlEditor.setMarginWidth(0, "000")
        self.ui.sqlEditor.setMarginsForegroundColor(QColor("#2468A7"))

        # Brace matching: enable for a brace immediately before or after
        # the current position.
        self.ui.sqlEditor.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        # Current line visible with special background color
        self.ui.sqlEditor.setCaretLineVisible(True)
        self.ui.sqlEditor.setCaretLineBackgroundColor(QColor("#E4EEFF"))

        lexer = QsciLexerSQL()
        self.ui.sqlEditor.setLexer(lexer)
        ''' TODO autocomplete.
        api = QsciAPIs(lexer)
        api.add('aLongString')
        api.add('aLongerString')
        api.add('aDifferentString')
        api.add('sOmethingElse')
        api.prepare()

        self.ui.sqlEditor.setAutoCompletionThreshold(1)
        self.ui.sqlEditor.setAutoCompletionSource(QsciScintilla.AcsAPIs)
        '''

        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ui.sqlEditor.sizePolicy().hasHeightForWidth())
        self.ui.sqlEditor.setSizePolicy(sizePolicy)

        self.ui.splitter.setSizes(
            [self.size().width() * 0.6,
             self.size().height() * 0.4])
        self.ui.leftContainer.insertWidget(1, self.ui.sqlEditor)
Esempio n. 9
0
 def createTab(self, py_de, ext, filename=""):
     newTabName = "tab" + str(self.centralwidget.count())
     newTextEditName = "textEdit" + str(self.centralwidget.count())
     print "createTab(): creating tab %s" % (newTabName)
     self.tab = QtGui.QWidget()
     self.tab.setObjectName(newTabName)
     self.tablayout = QtGui.QGridLayout(self.tab)
     self.centralwidget.addTab(self.tab,"")
     newTabIndex = self.centralwidget.indexOf(self.tab)
     if filename == "":
         filename = "Untitled" + str((newTabIndex + 1))
     newTabTitle = str(filename) + str(ext)
     self.centralwidget.setCurrentIndex(self.centralwidget.indexOf(self.tab))
     self.centralwidget.setTabText(newTabIndex, QtGui.QApplication.translate("py_de", newTabTitle, None, QtGui.QApplication.UnicodeUTF8))
     self.textEdit = QsciScintilla(self.tab)
     self.textEdit.setFont(self.font)
     self.textEdit.setMarginsFont(self.font)
     self.textEdit.setMarginWidth(0, self.fm.width( "00000" ) + 5)
     self.textEdit.setMarginLineNumbers(0, True)
     self.textEdit.setEdgeMode(QsciScintilla.EdgeLine)
     self.textEdit.setEdgeColumn(80)
     self.textEdit.setEdgeColor(QtGui.QColor("#FF0000"))
     self.textEdit.setFolding(QsciScintilla.BoxedTreeFoldStyle)
     self.textEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)
     self.textEdit.setCaretLineVisible(True)
     self.textEdit.setCaretLineBackgroundColor(QtGui.QColor("#CDA869"))
     self.textEdit.setMarginsBackgroundColor(QtGui.QColor("#333333"))
     self.textEdit.setMarginsForegroundColor(QtGui.QColor("#CCCCCC"))
     self.textEdit.setFoldMarginColors(QtGui.QColor("#99CC66"),QtGui.QColor("#333300"))
     lexer = QsciLexerPython()
     lexer.setDefaultFont(self.font)
     self.textEdit.setLexer(lexer)
     self.textEdit.show()
     sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Policy(1),QtGui.QSizePolicy.Policy(1))
     sizePolicy.setHorizontalStretch(0)
     sizePolicy.setVerticalStretch(0)
     sizePolicy.setHeightForWidth(self.textEdit.sizePolicy().hasHeightForWidth())
     self.textEdit.setSizePolicy(sizePolicy)
     self.textEdit.setObjectName(newTextEditName)
     self.tablayout.addWidget(self.textEdit, 0, 0, 1, 1)
Esempio n. 10
0
    def setDefaultShortcuts(self):
        reply = QtGui.QMessageBox.warning(self, "Default Keymap",
                                          "Setting keymap to default will wipe away your current keymap.\n\nProceed?",
                                          QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
        if reply == QtGui.QMessageBox.Yes:
            for key, value in self.useData.DEFAULT_SHORTCUTS['Ide'].items():
                default = self.useData.DEFAULT_SHORTCUTS['Ide'][key]
                self.useData.CUSTOM_SHORTCUTS['Ide'][key] = default

            sc = QsciScintilla()
            standardCommands = sc.standardCommands()

            for key, value in self.useData.DEFAULT_SHORTCUTS['Editor'].items():
                default = self.useData.DEFAULT_SHORTCUTS['Editor'][key]
                command = standardCommands.find(default[1])
                keyValue = command.key()
                self.useData.CUSTOM_SHORTCUTS[
                    'Editor'][key] = [default[0], keyValue]
            self.save()
            self.useData.loadKeymap()
            self.updateShortcutsView()
        else:
            return
Esempio n. 11
0
    def __init__(self, _parent):
        MDialog.__init__(self, _parent)
        from PyQt4.Qsci import QsciScintilla, QsciLexerPython, QsciAPIs

        if isActivePyKDE4:
            self.setButtons(MDialog.NoDefault)
        self.sciCommand = QsciScintilla()
        self.sciCommand.setUtf8(True)
        self.sciCommand.setAutoIndent(True)
        self.sciCommand.setIndentationGuides(True)
        self.sciCommand.setIndentationsUseTabs(True)
        self.sciCommand.setCaretLineVisible(True)
        self.sciCommand.setAutoCompletionThreshold(2)
        self.sciCommand.setAutoCompletionSource(QsciScintilla.AcsDocument)
        self.sciCommand.setLexer(QsciLexerPython(self))
        self.sciCommand.setMarginLineNumbers(1, True)
        self.sciCommand.setMarginWidth(1, '0000')
        self.sciCommand.setEolMode(QsciScintilla.EolUnix)
        self.sciCommand.setWrapMode(QsciScintilla.WrapWord)
        lblScriptList = MLabel(translate("ScriptManager", "Script List : "))
        self.currentScriptFileName = None
        self.lwScriptList = Options.MyListWidget(self, [], _currentRowChanged=self.getFromScriptList)
        self.refreshScriptList()
        pbtnCreate = MPushButton(translate("ScriptManager", "Create"))
        pbtnDelete = MPushButton(translate("ScriptManager", "Delete"))
        pbtnSave = MPushButton(translate("ScriptManager", "Save"))
        pbtnScriptManagerAndClose = MPushButton(translate("ScriptManager", "Run And Close"))
        pbtnScriptManager = MPushButton(translate("ScriptManager", "Run"))
        pbtnClose = MPushButton(translate("ScriptManager", "Close"))
        pbtnClear = MPushButton(translate("ScriptManager", "Clear"))
        self.cckbIsAutoSaveScripts = Options.MyCheckBox(self, translate("ScriptManager", "Auto Save"), 2,
                                                        "isAutoSaveScripts")
        self.connect(pbtnCreate, SIGNAL("clicked()"), self.create)
        self.connect(pbtnDelete, SIGNAL("clicked()"), self.delete)
        self.connect(pbtnSave, SIGNAL("clicked()"), self.save)
        self.connect(pbtnScriptManagerAndClose, SIGNAL("clicked()"), self.runScriptAndClose)
        self.connect(pbtnScriptManager, SIGNAL("clicked()"), self.runScript)
        self.connect(pbtnClose, SIGNAL("clicked()"), self.close)
        self.connect(pbtnClear, SIGNAL("clicked()"), self.clear)
        pnlMain = MWidget(self)
        vblMain = MVBoxLayout(pnlMain)
        vbox = MVBoxLayout()
        vbox.addWidget(lblScriptList)
        vbox.addWidget(self.lwScriptList)
        hbox2 = MHBoxLayout()
        hbox2.addWidget(pbtnCreate)
        hbox2.addWidget(pbtnDelete)
        vbox.addLayout(hbox2)
        hbox0 = MHBoxLayout()
        hbox0.addLayout(vbox)
        hbox0.addWidget(self.sciCommand)
        hbox1 = MHBoxLayout()
        hbox1.addWidget(self.cckbIsAutoSaveScripts)
        hbox1.addStretch(1)
        hbox1.addWidget(pbtnClear, 1)
        hbox1.addWidget(pbtnSave, 1)
        hbox1.addWidget(pbtnScriptManager, 1)
        hbox1.addWidget(pbtnScriptManagerAndClose, 1)
        hbox1.addWidget(pbtnClose, 1)
        vblMain.addLayout(hbox0)
        vblMain.addLayout(hbox1)
        if isActivePyKDE4:
            self.setMainWidget(pnlMain)
        else:
            self.setLayout(vblMain)
        self.setWindowTitle(translate("ScriptManager", "Script Manager"))
        self.setWindowIcon(MIcon("Images:scriptManager.png"))
        self.lwScriptList.setMaximumWidth(150)
        self.setMinimumWidth(650)
        self.setMinimumHeight(450)
        self.show()
Esempio n. 12
0
from PyQt4 import QtGui,QtCore
from PyQt4.Qsci import QsciScintilla, QsciLexerCPP
import sys

app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()

scint = QsciScintilla(window)
lex = QsciLexerCPP(window,False)
scint.setLexer(lex)
window.show()

sys.exit( app.exec_() )
Esempio n. 13
0
 def gettabtext(self):
     ctab = self.tabWidget.currentWidget()
     for idx, child in enumerate(ctab.children()):
         if type(child) is type(QsciScintilla()):
             return child.text()
Esempio n. 14
0
    def __init__(self, parent, main, arduino_mode=False):
        QtGui.QWidget.__init__(self)

        self.main = main
        self.current_file_path = None

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.setContentsMargins(0, 0, 0, 0)
        mainLayout.setSpacing(0)
        self.setLayout(mainLayout)

        ##############################################################
        ### File Info Bar
        ##############################################################
        hbox = QtGui.QHBoxLayout()
        mainLayout.addLayout(hbox)

        self.lblFileName = QtGui.QLabel(self)
        self.lblFileName.setText("Filename")
        style_grad = "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #efefef, stop: 1 %s);" % "#6A7885"
        style_grad += "font-weight: bold; border: 1px outset #41484E; padding: 3px;"
        self.lblFileName.setStyleSheet(style_grad)
        hbox.addWidget(self.lblFileName, 4)

        self.lblFileSize = GenericWidgets.StatusLabel(self, "Size")
        hbox.addWidget(self.lblFileSize, 1)

        self.lblFileModified = GenericWidgets.StatusLabel(self, "Modified")
        hbox.addWidget(self.lblFileModified, 2)

        ##############################################################
        ### Arduino Compiler
        ##############################################################
        if arduino_mode:
            toolbar = QtGui.QToolBar()
            toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
            mainLayout.addWidget(toolbar)

            ## spacer for right
            toolbar.addWidget(GenericWidgets.ToolBarSpacer(self))

            ### Action Buttons
            buttz = []
            buttz.append(['Compile', Ico.Compile])
            buttz.append(['Upload', Ico.Upload])
            buttz.append(['Compile Upload', Ico.CompileUpload])
            self.buttCompileGroup = QtGui.QButtonGroup()
            self.connect(self.buttCompileGroup,
                         QtCore.SIGNAL("buttonClicked (QAbstractButton *)"),
                         self.on_compile_group_button)
            ## TODO connect
            for caption, ico in buttz:
                butt = QtGui.QPushButton()
                butt.setText(caption)
                butt.setIcon(Icon(ico))
                toolbar.addWidget(butt)
                self.buttCompileGroup.addButton(butt)
            toolbar.addSeparator()

        ####################################################
        ## Source Editor
        ####################################################
        self.editor = QsciScintilla(self)
        self.editor.setUtf8(True)
        self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle)
        self.editor.setMarginLineNumbers(1, True)
        self.editor.setAutoIndent(True)
        mainLayout.addWidget(self.editor, 3)

        ## The Syntax Higlighter = standard CPP atmo = cish
        #self.lexer = ArduinoLexer(self)
        #self.editor.setLexer(self.lexer)

        ## Aarduino API Functions
        #self.arduinoFunctionsAPI = QsciAPIs(self.lexer)
        #keywords_file = self.main.settings.api_path().append("/autocomplete.txt")

        #self.arduinoFunctionsAPI.load(keywords_file)
        #self.arduinoFunctionsAPI.prepare()
        #self.lexer.setAPIs(self.arduinoFunctionsAPI)

        #self.editor.setAutoCompletionThreshold(1);
        #self.editor.setAutoCompletionSource(QsciScintilla.AcsAPIs);

        if arduino_mode:
            self.terminalWidget = TerminalWidget(self, self.main)
            mainLayout.addWidget(self.terminalWidget, 1)
Esempio n. 15
0
    def initEditor(self):
        editor = QsciScintilla()

        ## define the font to use
        font = QtGui.QFont()
        #font.setFamily("Consolas")
        font.setFixedPitch(True)
        font.setPointSize(9)
        # the font metrics here will help
        # building the margin width later
        fm = QtGui.QFontMetrics(font)

        ## set the default font of the editor
        ## and take the same font for line numbers
        editor.setFont(font)
        editor.setMarginsFont(font)

        ## Line numbers
        # conventionnaly, margin 0 is for line numbers
        editor.setMarginWidth(0, fm.width("0000"))
        editor.setMarginLineNumbers(0, True)

        ## Edge Mode shows a red vetical bar at 80 chars
        editor.setEdgeMode(QsciScintilla.EdgeLine)
        editor.setEdgeColumn(80)
        editor.setEdgeColor(QtGui.QColor("#FF0000"))

        ## Folding visual : we will use boxes
        editor.setFolding(QsciScintilla.BoxedTreeFoldStyle)

        ## Braces matching
        editor.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        ## Editing line color
        editor.setCaretLineVisible(True)
        #editor.setCaretLineBackgroundColor(QtGui.QColor("#F5F5DC"))

        ## Margins colors
        # line numbers margin
        #editor.setMarginsBackgroundColor(QtGui.QColor("#333333"))
        #editor.setMarginsForegroundColor(QtGui.QColor("#CCCCCC"))

        # folding margin colors (foreground,background)
        #editor.setFoldMarginColors(QtGui.QColor("#99CC66"),QtGui.QColor("#333300"))

        ## Choose a lexer
        lexer = QsciLexerPython()
        lexer.setDefaultFont(font)
        editor.setLexer(lexer)

        ## Render on screen
        #editor.show()

        ## Show this file in the editor
        #editor.setText(open("examples\charriot_obj.txt").read())

        # Show all the methods of the editor
        #methods = sorted(QsciScintilla.__dict__.keys())
        #for m in methods :
        #    print m
        #editor.setWidth(400)

        editor.setEolMode(QsciScintilla.EolUnix)
        return editor
Esempio n. 16
0
    def createNewTab(self, filename, msg, lexer):
        if type(msg) is bytes:
            msg = msg.decode(encoding='utf-8')
        if str(msg).find("\r\n") >= 0:
            msg = msg.replace('\n', '')
        elif str(msg).find("\n") >= 0 and str(msg).find("\r") < 0:
            msg = msg.replace("\n", "\r")
        else:
            print("creatNewTab has other endswith.")

        editor = QsciScintilla()
        editor.setUtf8(True)
        editor.setLexer(lexer)
        editor.setMarginsBackgroundColor(QColor(220, 220, 220))
        editor.setAutoCompletionThreshold(2)
        editor.setAutoCompletionSource(QsciScintilla.AcsAll)
        editor.setEolMode(QsciScintilla.EolUnix)

        if str(filename).find("/") >= 0:
            tabname = filename.split("/")
            tabname = tabname[-1]
        elif str(filename) == "untitled":
            tabname = "untitled"
        else:
            tabname = filename

        self.addTab(editor, tabname)
        self.setTabToolTip(self.count() - 1, filename)

        if filename == "untitled":
            self.tabBar().setTabTextColor(self.count() - 1, QColor(Qt.red))
            self.setTabIcon(self.count() - 1, QIcon(':/pc.png'))
            if self.ui.currentBoard == "microbit":
                msg = "from microbit import *\r#write your program:\r"
        elif str(filename).find(":") > 0:
            self.tabBar().setTabTextColor(self.count() - 1, QColor(Qt.red))
            self.setTabIcon(self.count() - 1, QIcon(':/pc.png'))
        else:
            self.tabBar().setTabTextColor(self.count() - 1, QColor(Qt.blue))
            self.setTabIcon(self.count() - 1, QIcon(':/ic.png'))

        editor.setText(msg)

        editor.setContextMenuPolicy(Qt.CustomContextMenu)
        self.connect(editor,
                     SIGNAL("customContextMenuRequested(const QPoint&)"),
                     self.slotEditorRightClickMenu)

        if self.editorRightMenu == None:
            self.editorRightMenu = QMenu(self)
            self.editorRightMenu.setStyleSheet(
                "QMenu::item{padding:4px 16px;}"
                "QMenu::item::selected{background-color:rgb(135,206,255);}")

            undo = QAction(self.tr("Undo"), self)
            undo.setShortcut("Ctrl+Z")
            self.connect(undo, SIGNAL("triggered()"), self.slotUndo)

            redo = QAction(self.tr("Redo"), self)
            redo.setShortcut("Ctrl+Y")
            self.connect(redo, SIGNAL("triggered()"), self.slotRedo)

            cut = QAction(self.tr("Cut"), self)
            cut.setShortcut("Ctrl+X")
            self.connect(cut, SIGNAL("triggered()"), self.slotCut)

            copy = QAction(self.tr("Copy"), self)
            copy.setShortcut("Ctrl+C")
            self.connect(copy, SIGNAL("triggered()"), self.slotCopy)

            paste = QAction(self.tr("Paste"), self)
            paste.setShortcut("Ctrl+V")
            self.connect(paste, SIGNAL("triggered()"), self.slotPaste)

            self.editorRightMenu.addAction(undo)
            self.editorRightMenu.addAction(redo)
            self.editorRightMenu.addAction(cut)
            self.editorRightMenu.addAction(copy)
            self.editorRightMenu.addAction(paste)

        #set brace match
        editor.setBraceMatching(editor.StrictBraceMatch)

        #set indent replace 4 space
        editor.setIndentationsUseTabs(False)
        editor.setTabWidth(2)

        #The line number display area
        editor.setMarginType(0, QsciScintilla.NumberMargin)
        editor.setMarginLineNumbers(0, True)
        editor.setMarginWidth(0, 30)

        #set auto indentation
        editor.setAutoIndent(True)

        #syntax check
        editor.setMarginType(1, QsciScintilla.SymbolMargin)
        editor.setMarginLineNumbers(1, False)
        editor.setMarginWidth(1, 5)
        editor.setMarginSensitivity(1, False)
        editor.setMarginMarkerMask(1, 0x1FFFFFF)
        editor.markerDefine(QsciScintilla.Background, 1)

        #Automatic folding area
        editor.setFolding(QsciScintilla.CircledFoldStyle)

        #set tab's stylesheet
        editor.setStyleSheet(
            "QWidget{font-size:20px;border: 1px solid white;border-radius:1px}"
        )

        self.setCurrentWidget(editor)
        if filename != "untitled":
            self.fileitem.size += 1
            self.fileitem.list.append(filename)

        self.connect(editor, SIGNAL("textChanged()"), self.editorTextChange)
        self.connect(editor, SIGNAL("selectionChanged()"),
                     self.selectionChanged)
        self.connect(editor, SIGNAL("linesChanged()"), self.linesChanged)
        self.connect(editor, SIGNAL("cursorPositionChanged(int,int)"),
                     self.cursorPositionChanged)
        self.connect(editor, SIGNAL("userListActivated(int,const QString)"),
                     self.userListActivated)
Esempio n. 17
0
    def setupUi(self, py_de):
        self.printer = QPrinter()
        self.imagesDir = "images/"

        ####################################
        ## Set up our initial window object
        ####################################

        py_de.setObjectName("py_de")
        py_de.resize(QtCore.QSize(QtCore.QRect(0, 0, 800, 570).size()).expandedTo(py_de.minimumSizeHint()))

        self.centralwidget = QtGui.QTabWidget(py_de)
        self.centralwidget.setObjectName("centralwidget")

        self.centralwidget.setGeometry(QtCore.QRect(50,50,200,200))

	    ####################################
       	## Set up tabs
       	####################################

        self.tab = QtGui.QWidget()
        self.tab.setObjectName("tab")

        self.tablayout = QtGui.QGridLayout(self.tab)

	    ####################################
        ## The actual text box.
        ####################################

        self.textEdit = QsciScintilla(self.tab)

        #####################################
        ### Set the syntax highlighting.
        #####################################

        ## define the font to use
        self.font = QtGui.QFont()
        self.font.setFamily("Consolas")
        self.font.setFixedPitch(True)
        self.font.setPointSize(10)
        # the font metrics here will help
        # building the margin width later
        self.fm = QtGui.QFontMetrics(self.font)

        ## set the default font of the editor
        ## and take the same font for line numbers
        self.textEdit.setFont(self.font)
        self.textEdit.setMarginsFont(self.font)

        ## Line numbers
        # conventionaly, margin 0 is for line numbers
        self.textEdit.setMarginWidth(0, self.fm.width( "00000" ) + 5)
        self.textEdit.setMarginLineNumbers(0, True)

        ## Edge Mode shows a red vertical bar at 80 chars
        self.textEdit.setEdgeMode(QsciScintilla.EdgeLine)
        self.textEdit.setEdgeColumn(80)
        self.textEdit.setEdgeColor(QtGui.QColor("#FF0000"))

        ## Folding visual : we will use boxes
        self.textEdit.setFolding(QsciScintilla.BoxedTreeFoldStyle)

        ## Braces matching
        self.textEdit.setBraceMatching(QsciScintilla.SloppyBraceMatch)

        ## Editing line color
        self.textEdit.setCaretLineVisible(True)
        self.textEdit.setCaretLineBackgroundColor(QtGui.QColor("#CDA869"))

        ## Margins colors
        # line numbers margin
        self.textEdit.setMarginsBackgroundColor(QtGui.QColor("#333333"))
        self.textEdit.setMarginsForegroundColor(QtGui.QColor("#CCCCCC"))

        # folding margin colors (foreground,background)
        self.textEdit.setFoldMarginColors(QtGui.QColor("#99CC66"),QtGui.QColor("#333300"))

        ## Choose a lexer
        lexer = QsciLexerPython()
        lexer.setDefaultFont(self.font)
        self.textEdit.setLexer(lexer)

        ## Render on screen
        self.textEdit.show()

        ## Show this file in the self.textEdit

        #####################################
        ## end of syntax highlighting.
        #####################################

	    ####################################
        ## Set up the sizes of everything
        ####################################

        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Policy(1),QtGui.QSizePolicy.Policy(1))
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.textEdit.sizePolicy().hasHeightForWidth())
        self.textEdit.setSizePolicy(sizePolicy)
        self.textEdit.setObjectName("textEdit")

        self.tablayout.addWidget(self.textEdit, 0, 0, 1, 1)

        self.centralwidget.addTab(self.tab,"")
        self.centralwidget.setCurrentIndex(0)

        py_de.setCentralWidget(self.centralwidget)

        self.createMenus(py_de)
        self.createActions(py_de)
        self.createToolBar(py_de)

        self.retranslateUi(py_de)

        #self.createTab(py_de)

        conn = QtCore.QObject.connect
        conn(self.actionNewTemplate,QtCore.SIGNAL("activated()"),self.newTemplate)
        conn(self.actionClose,QtCore.SIGNAL("triggered()"),self.closeTab)
        conn(self.actionQuit,QtCore.SIGNAL("activated()"),py_de.close)
        conn(self.actionOpen,QtCore.SIGNAL("activated()"),self.openFile)
        conn(self.actionPrint,QtCore.SIGNAL("activated()"),self.printFile)
        conn(self.actionSave,QtCore.SIGNAL("activated()"),self.saveFile)
        conn(self.actionSave_As,QtCore.SIGNAL("activated()"),self.saveAsFile)
        conn(self.actionSelect_All,QtCore.SIGNAL("activated()"),self.textEdit.selectAll)
        conn(self.actionGoToLine,QtCore.SIGNAL("activated()"),self.goToLine)
        conn(self.actionCopy,QtCore.SIGNAL("activated()"),self.textEdit.copy)
        conn(self.actionCut,QtCore.SIGNAL("activated()"),self.textEdit.cut)
        conn(self.actionPaste,QtCore.SIGNAL("activated()"),self.textEdit.paste)
        conn(self.actionPython_File,QtCore.SIGNAL("activated()"),self.newPythonFile)
        conn(self.actionC,QtCore.SIGNAL("activated()"),self.newCFile)
        conn(self.actionC_Header_File_h,QtCore.SIGNAL("activated()"),self.newCHeaderFile)
        conn(self.actionFortran,QtCore.SIGNAL("activated()"),self.newFortranFile)
        conn(self.actionPython_File,QtCore.SIGNAL("activated()"),lambda x="py":self.template(x))
        conn(self.actionC,QtCore.SIGNAL("activated()"),lambda x="cpp":self.template(x))
        conn(self.actionFortran,QtCore.SIGNAL("activated()"),lambda x="f":self.template(x))


        QtCore.QMetaObject.connectSlotsByName(py_de)
Esempio n. 18
0
    def __init__(self, parent, main, arduino_mode=False):
        QtGui.QWidget.__init__(self)

        self.main = main
        self.current_file_path = None
        self.board = "board_name"
        self.port = "Sanderman"

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.setContentsMargins(0, 0, 0, 0)
        mainLayout.setSpacing(0)
        self.setLayout(mainLayout)

        ##############################################################
        ### File Info Bar at the top
        ##############################################################
        fileInfoBox = QtGui.QHBoxLayout()
        mainLayout.addLayout(fileInfoBox, 0)

        self.lblFileName = QtGui.QLabel(self)
        self.lblFileName.setText("Filename")
        style_grad = "background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #efefef, stop: 1 %s);" % "#6A7885"
        style_grad += "font-weight: bold; border: 1px outset #41484E; padding: 3px;"
        self.lblFileName.setStyleSheet(style_grad)
        fileInfoBox.addWidget(self.lblFileName, 4)

        #########################################
        ## Save Button
        self.buttonSave = QtGui.QPushButton(self)
        self.buttonSave.setText("Save")
        self.buttonSave.setIcon(Icon(Ico.Save))
        fileInfoBox.addWidget(self.buttonSave)
        self.connect(self.buttonSave, QtCore.SIGNAL("clicked()"),
                     self.on_save_button_clicked)

        ###########################################
        ## Actions button with dropdown menu
        buttActions = QtGui.QPushButton(self)
        buttActions.setText("Actions")
        buttActions.setIcon(Icon(Ico.Green))
        fileInfoBox.addWidget(buttActions)

        fileActionsMenu = QtGui.QMenu(buttActions)
        buttActions.setMenu(fileActionsMenu)
        self.fileActionsGroup = QtGui.QActionGroup(self)
        self.connect(self.fileActionsGroup,
                     QtCore.SIGNAL("triggered(QAction*)"), self.on_file_action)
        for act in [['rename', 'Rename'], ['copy', 'Copy'],
                    ['commit', 'Commit']]:
            nuAction = fileActionsMenu.addAction(act[1])
            nuAction.setProperty('action_name', act[0])
            # TODO - maybe this should be in button group

        ####################################################
        ## Scintilla Editor
        ####################################################
        self.editor = QsciScintilla(self)
        self.editor.setUtf8(True)
        self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle)
        self.editor.setMarginLineNumbers(1, True)
        self.editor.setMarginWidth(1, 30)
        self.editor.setAutoIndent(True)
        mainLayout.addWidget(self.editor, 200)

        bottomStatusBar = QtGui.QStatusBar(self)
        mainLayout.addWidget(bottomStatusBar, 0)

        #########################################
        ## File Size and Modified info
        self.lblFileSize = GenericWidgets.StatusLabel(self, "Size")
        bottomStatusBar.addPermanentWidget(self.lblFileSize)

        self.lblFileModified = GenericWidgets.StatusLabel(self, "Modified")
        bottomStatusBar.addPermanentWidget(self.lblFileModified)

        ##############################################################
        ### Arduino Compiler With compile and board selector
        ##############################################################
        """if arduino_mode:
Esempio n. 19
0
            return 'SDR SIR sdr'
        # secondary keywords
        if index == 2:
            return 'SIR ' + keywords
        # doc comment keywords
        if index == 3:
            return keywords
        # global classes
        if index == 4:
            return keywords
        return keywords


if __name__ == "__main__":
    app = QApplication(sys.argv)
    editor = QsciScintilla()

    ## define the font to use
    font = QtGui.QFont()
    font.setFamily("Consolas")
    font.setFixedPitch(True)
    font.setPointSize(10)
    # the font metrics here will help
    # building the margin width later
    fm = QtGui.QFontMetrics(font)

    ## set the default font of the editor
    ## and take the same font for line numbers
    editor.setFont(font)
    editor.setMarginsFont(font)