def __init__(self, exctype=None, excvalue=None, tracebackobj=None, parent=None, flags=QtCore.Qt.WindowFlags(0), **kwargs): super(QsciExceptionDialog, self).__init__(exctype, excvalue, tracebackobj, parent, flags, False, **kwargs) self.groupboxVerticalLayout.removeWidget(self.tracebackTextEdit) self.tracebackTextEdit.setParent(None) del self.tracebackTextEdit self.tracebackTextEdit = Qsci.QsciScintilla() self.groupboxVerticalLayout.addWidget(self.tracebackTextEdit) self.tracebackTextEdit.setMarginLineNumbers( Qsci.QsciScintilla.NumberMargin, True) self.tracebackTextEdit.setMarginWidth( Qsci.QsciScintilla.NumberMargin, 30) lexer = Qsci.QsciLexerPython() self.tracebackTextEdit.setLexer(lexer) self.tracebackTextEdit.recolor() self.tracebackTextEdit.setReadOnly(True) self.tracebackGroupBox.toggled.connect( self.tracebackTextEdit.setVisible) if not self._excInfoSet(): self.setExcInfo(*sys.exc_info()) else: self._fill()
def set_type(self): try: ext = self.file_name.split(".")[-1] print(ext) except: ext = "" self.text_edit_field.setLexer(Qsci.QsciLexerCPP(self)) pass if ext == "py": self.text_edit_field.setLexer(Qsci.QsciLexerPython(self)) self.hide_web() print("type python") elif ext == "cpp" or ext == "c": self.text_edit_field.setLexer(Qsci.QsciLexerCPP(self)) self.hide_web() print("type cpp") elif ext == "html": self.text_edit_field.setLexer(Qsci.QsciLexerHTML(self)) self.terminal.setHidden(True) self.browser = QWebView(self) self.browser.load(QUrl(self.file_name)) self.browser.move(self.x_y[0] * 66, 30) self.browser.setFixedSize(self.x_y[0] * 0.33, self.x_y[1] - 20) self.browser.show() #self.browser.move(500,0) #self.setGeometry((self.screen.width()-self.wd+200)/2,0,self.wd,self.ht-50) #self.setFixedSize(self.wd+200,self.ht-50) print("type html")
def __init__(self, parent=None): """ very similar to: https://stackoverflow.com/questions/40002373/qscintilla-based-text-editor-in-pyqt5-with-clickable-functions-and-variables """ super(SimplePythonEditorWidget, self).__init__(parent) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) self.set_font(font) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#cccccc")) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) if qt_version == 'pyqt4': self.connect(self, QtCore.SIGNAL('marginClicked(int, int, Qt::KeyboardModifiers)'), self.on_margin_clicked) else: self.marginClicked.connect(self.on_margin_clicked) self.markerDefine(Qsci.QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. lexer = Qsci.QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) if qt_version == 'pyqt4': self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') else: font_style = bytearray(str.encode("Courier")) self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, font_style) # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented # here: http://www.scintilla.org/ScintillaDoc.html) self.SendScintilla(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0)
def __init__(self, parent=None): Qsci.QsciScintilla.__init__(self, parent) self.lex = Qsci.QsciLexerPython() self.setLexer(self.lex) for i in range(5): self.setMarginWidth(i, 0) # Set Dark Color style_obj = set(styleD.keys()).intersection(dir(self.lex)) self.setCaretForegroundColor(QtGui.QColor(255, 255, 255)) shade = 30 self.setCaretLineBackgroundColor(QtGui.QColor(shade, shade, shade)) self.lex.setDefaultPaper(QtGui.QColor(shade, shade, shade)) self.lex.setPaper(QtGui.QColor(shade, shade, shade), self.lex.Default) self.setColor(QtGui.QColor(255, 255, 255)) self.setMarginsBackgroundColor(QtGui.QColor(60, 60, 60)) self.setWhitespaceBackgroundColor(QtGui.QColor(80, 80, 80)) self.setFoldMarginColors(QtGui.QColor(200, 200, 200), QtGui.QColor(90, 90, 90)) ## self.ui.te_sci.setPaper(QColor(80,80,80)) self.setMarginsForegroundColor(QtGui.QColor(200, 200, 200)) ## self.ui.te_sci.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETBACK,Qsci.QsciScintilla.STYLE_DEFAULT,QColor(150,150,150)) self.setMatchedBraceBackgroundColor(QtGui.QColor(shade, shade, shade)) self.setMatchedBraceForegroundColor(QtGui.QColor(170, 0, 255)) self.setUnmatchedBraceBackgroundColor(QtGui.QColor( shade, shade, shade)) # Set defaults for all: style_obj = set(styleD.keys()).intersection(dir(self.lex)) style_obj.remove('Default') style_obj = set(['Default']).union(sorted(style_obj)) for c in sorted(style_obj, reverse=1): clr = styleD[c] if clr == '': clr = styleD['Default'] try: exec('self.lex.setPaper(QtGui.QColor(30,30,30),self.lex.' + c + ')') exec('self.lex.setColor(QtGui.QColor(' + clr + '),self.lex.' + c + ')') except: print 'no keyword', c self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.setMaximumHeight(18) self.setStyleSheet('border:0px;') self.widgetObject = Qsci.QsciScintilla self.type = 'qscintilla'
def __init__(self, parent=None): super(SimplePythonEditorWidget, self).__init__(parent) # Set the default font font = QFont() font.setFamily('Courier') font.setFixedPitch(True) font.setPointSize(10) self.setFont(font) self.setMarginsFont(font) # Margin 0 is used for line numbers fontmetrics = QFontMetrics(font) self.setMarginsFont(font) self.setMarginWidth(0, fontmetrics.width("00000") + 6) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#cccccc")) # Clickable margin 1 for showing markers self.setMarginSensitivity(1, True) self.connect( self, QtCore.SIGNAL( 'marginClicked(int, int, Qt::KeyboardModifiers)'), self.on_margin_clicked) self.markerDefine(Qsci.QsciScintilla.RightArrow, self.ARROW_MARKER_NUM) self.setMarkerBackgroundColor(QColor("#ee1111"), self.ARROW_MARKER_NUM) # Brace matching: enable for a brace immediately before or after # the current position self.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) # Current line visible with special background color self.setCaretLineVisible(True) self.setCaretLineBackgroundColor(QColor("#ffe4e4")) # Set Python lexer # Set style for Python comments (style number 1) to a fixed-width # courier. lexer = Qsci.QsciLexerPython() lexer.setDefaultFont(font) self.setLexer(lexer) self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') # Don't want to see the horizontal scrollbar at all # Use raw message to Scintilla here (all messages are documented # here: http://www.scintilla.org/ScintillaDoc.html) self.SendScintilla(Qsci.QsciScintilla.SCI_SETHSCROLLBAR, 0)
def __init__(self, control, ui_control): print 'Initializing Scripts UI.' inLib.ModuleUI.__init__(self, control, ui_control, 'modules.scripts.scripts_design') self._runner = None self._ui.listWidgetFiles.dragEnterEvent = self._drag_enter_event self._ui.listWidgetFiles.dragMoveEvent = self._drag_move_event self._ui.listWidgetFiles.dropEvent = self._drop_event self._ui.listWidgetFiles.itemClicked.connect(self._on_file_clicked) self._ui.listWidgetFiles.itemActivated.connect(self.run) self._ui.pushButtonRun.clicked.connect(self.run) self._ui.pushButtonSave.clicked.connect(self._on_save_clicked) self._ui.pushButtonNew.clicked.connect(self.new) self._ui.pushButtonLoad.clicked.connect(self.loadFile) self._ui.scintillaScript = Qsci.QsciScintilla() font = QtGui.QFont() font.setFamily('Courier') font.setPointSize(10) self._ui.scintillaScript.setFont(font) self._ui.scintillaScript.setMarginsFont(font) fontmetrics = QtGui.QFontMetrics(font) self._ui.scintillaScript.setMarginWidth(0, fontmetrics.width("000")) self._ui.scintillaScript.setMarginLineNumbers(0, True) self._ui.scintillaScript.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) self._ui.scintillaScript.setCaretLineVisible(True) lexer = Qsci.QsciLexerPython() lexer.setDefaultFont(font) self._ui.scintillaScript.setLexer(lexer) self._ui.scintillaScript.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT,1, 'Courier') self._ui.scintillaScript.SendScintilla(Qsci.QsciScintilla.SCI_SETHSCROLLBAR,0) self._ui.scintillaScript.setTabWidth(4) self._ui.scintillaScript.setIndentationsUseTabs(False) self._ui.scintillaScript.setEolMode(Qsci.QsciScintilla.EolMode(Qsci.QsciScintilla.EolUnix)) self._ui.gridLayout.addWidget(self._ui.scintillaScript, 1, 1) script_path = os.path.join(os.path.dirname(__file__), 'scripts') for element in os.listdir(script_path): element_path = os.path.join(script_path, element) if os.path.isfile(os.path.join(element_path)): if os.path.splitext(element_path)[1] == '.py': self._add_filename(element_path)
def init_ui(self): self.setGeometry(0, 0, self.width, self.height) self.setWindowTitle("OmegaIDE") self.text = Editor(Qsci.QsciLexerPython(self)) self.text.cursorPositionChanged.connect(self.show_cursor_pos) self.setCentralWidget(self.text) self.init_file_manager() self.init_toolbar() self.init_menubar() self.init_status_bar() self.status_bar = self.statusBar() self.status_bar_text = QtGui.QLabel() self.status_bar_text.setText("") self.status_bar.addWidget(self.status_bar_text)
def SetScintillaProperties(framework, scintillaWidget, contentType='html'): lexerInstance = None font = framework.get_font() if 'html' == contentType: lexerInstance = Qsci.QsciLexerHTML(scintillaWidget) elif 'javascript' == contentType: lexerInstance = Qsci.QsciLexerJavaScript(scintillaWidget) elif 'python' == contentType: lexerInstance = Qsci.QsciLexerPython(scintillaWidget) font = framework.get_python_code_font() elif contentType in ('hex', 'monospace'): font = framework.get_monospace_font() else: pass scintillaWidget.setFont(font) scintillaWidget.setWrapMode(1) scintillaWidget.zoomTo(framework.get_zoom_size()) # TOOD: set based on line numbers (size is in pixels) scintillaWidget.setMarginWidth(1, '1000') if lexerInstance is not None: lexerInstance.setFont(font) scintillaWidget.setLexer(lexerInstance)
def __init__(self): QtGui.QWidget.__init__(self) self.setupUi(self) self.stdout = sys.stdout self.stderr = sys.stderr self.connect(self.btnClose, QtCore.SIGNAL('clicked()'), self.close) self.connect(self.btnCopy, QtCore.SIGNAL('clicked()'), self._copy) self.sysout = SysOut(self.sci) self.PLX = Qsci.QsciLexerPython(self) self.ABS = Qsci.QsciAPIs(self.PLX) self.PLX.setAPIs(self.ABS) self.sci.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll) self.sci.setLexer(self.PLX) self.sci.setAutoCompletionThreshold(1) self.sci.setAutoIndent(True) self.sci.setAutoCompletionFillupsEnabled(True) self.sci.setBraceMatching(Qsci.QsciScintilla.StrictBraceMatch) self.sci.setMarginWidth(1, 0) self.sci.setReadOnly(1) print '*** Python %s on %s.***' % (sys.version, sys.platform) self.btnCopy.setEnabled(0)
def __init__(self, parent): WidgetBase.__init__(self, parent) self.parent = parent self.setupUi(self) #Event handlers# self.bt_python_run.clicked.connect(self.onPythonCommand) # Setup namespaces etc, log stufff. self.logPython("Python version:\n" + sys.version, color="green") self.logPython("TrLib version:\n" + TrLib.GetVersion(), color="green") namespace = {"loadPlugins": parent.loadPlugins, "mainWindow": parent} self.logPython("Handle to main window %s stored in name: mainWindow" % repr(parent.__class__), color="brown") self.python_console = EmbedPython.PythonConsole(namespace) self.python_console.executeCode("from TrLib import *") self.logPython( "from TrLib import * - Loading namespace from TrLib.py", color="brown") self.logPython("Type 'example' to run example code", color="blue") self.logPython("Type 'clear' to clear output field", color="blue") # Determine what type the input text field should be and setup its # event handler.... if HAS_QSCI: self.txt_python_in = Qsci.QsciScintilla(self) self.txt_python_in.setLexer(Qsci.QsciLexerPython()) self.txt_python_in.setAutoIndent(True) else: self.txt_python_in = QTextEdit(self) self.layout().addWidget(self.txt_python_in) self.txt_python_in.keyPressEvent = self.onPythonKey if not HAS_QSCI: self.logPython( "Qscintilla not installed. Python input lexer will not work...", color="red") self.python_console.clearCache() self.txt_python_in.setWhatsThis("Enter/edit input python code here")
def __init__(self, parent=None, designMode=False): Qsci.QsciScintilla.__init__(self, parent) self.textEdit = Qsci.QsciScintilla() self.textEdit.setAutoCompletionThreshold(1) self.textEdit.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll) self.textEdit.setAutoIndent(True) self.textEdit.setCallTipsStyle(Qsci.QsciScintilla.CallTipsContext) self.textEdit.setCallTipsVisible(0) self.pythonLexer = Qsci.QsciLexerPython(self.textEdit) self.api = Qsci.QsciAPIs(self.pythonLexer) self.api.add(Qt.QString("dupa(a,b)this is function dupa")) self.api.prepare() self.pythonLexer.setAPIs(self.api) self.textEdit.setLexer(self.pythonLexer) self.newAction = Qt.QAction(getThemeIcon("document-new"), "New", self) self.newAction.triggered.connect(self.newFile) self.newAction.setToolTip("Create new file") self.newAction.setShortcut("Ctrl+N") self.openAction = Qt.QAction(getThemeIcon("document-open"), "Open", self) self.openAction.triggered.connect(self.openFile) self.openAction.setToolTip("Open existing file") self.openAction.setShortcut("Ctrl+O") self.saveAction = Qt.QAction(getThemeIcon("document-save"), "Save", self) self.saveAction.triggered.connect(self.saveFile) self.saveAction.setToolTip("Save document to disk") self.saveAction.setShortcut("Ctrl+S") self.saveAsAction = Qt.QAction(getThemeIcon("document-save-as"), "Save as...", self) self.saveAction.triggered.connect(self.saveFile) self.saveAsAction.setToolTip("Save document under a new name") self.cutAction = Qt.QAction(getThemeIcon("edit-cut"), "Cut", self) self.cutAction.triggered.connect(self.cut) self.cutAction.setToolTip( "Cut current selection's contents to the clipboard") self.cutAction.setShortcut("Ctrl+X") self.cutAction.setEnabled(False) self.copyAction = Qt.QAction(getThemeIcon("edit-copy"), "Copy", self) self.copyAction.triggered.connect(self.copy) self.copyAction.setToolTip( "Copy current selection's contents to the clipboard") self.copyAction.setShortcut("Ctrl+C") self.copyAction.setEnabled(False) self.pasteAction = Qt.QAction(getThemeIcon("edit-paste"), "Paste", self) self.pasteAction.triggered.connect(self.paste) self.pasteAction.setToolTip( "Paste the clipboard's contents into the current selection") self.pasteAction.setShortcut("Ctrl+V") self.aboutAction = Qt.QAction("About", self) self.aboutAction.triggered.connect(self.about) self.aboutAction.setToolTip("Show the application's About box") self.textEdit.copyAvailable.connect(self.cutAction.setEnabled) self.textEdit.copyAvailable.connect(self.copyAction.setEnabled) self.setCurrentFile("")
def initialize(self, *args, **kwargs): " Init Main Class " super(Main, self).initialize(*args, **kwargs) self.scriptPath, self.scriptArgs = "", [] self.profilerPath, self.tempPath = profilerPath, tempPath self.output = " ERROR: FAIL: No output ! " self.process = QProcess() self.process.finished.connect(self.on_process_finished) self.process.error.connect(self.on_process_error) self.tabWidget, self.stat = QTabWidget(), QWidget() self.tabWidget.tabCloseRequested.connect( lambda: self.tabWidget.setTabPosition(1) if self.tabWidget. tabPosition() == 0 else self.tabWidget.setTabPosition(0)) self.tabWidget.setStyleSheet('QTabBar{font-weight:bold;}') self.tabWidget.setMovable(True) self.tabWidget.setTabsClosable(True) self.vboxlayout1 = QVBoxLayout(self.stat) self.hboxlayout1 = QHBoxLayout() self.filterTableLabel = QLabel("<b>Type to Search : </b>", self.stat) self.hboxlayout1.addWidget(self.filterTableLabel) self.filterTableLineEdit = QLineEdit(self.stat) self.filterTableLineEdit.setPlaceholderText(' Type to Search . . . ') self.hboxlayout1.addWidget(self.filterTableLineEdit) self.filterHintTableLabel = QLabel(" ? ", self.stat) self.hboxlayout1.addWidget(self.filterHintTableLabel) self.vboxlayout1.addLayout(self.hboxlayout1) self.tableWidget = QTableWidget(self.stat) self.tableWidget.setAlternatingRowColors(True) self.tableWidget.setColumnCount(8) self.tableWidget.setRowCount(2) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(0, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(1, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(2, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(3, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(4, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(5, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(6, item) item = QTableWidgetItem() self.tableWidget.setHorizontalHeaderItem(7, item) self.tableWidget.itemDoubleClicked.connect( self.on_tableWidget_itemDoubleClicked) self.vboxlayout1.addWidget(self.tableWidget) self.tabWidget.addTab(self.stat, " ? ") self.source = QWidget() self.gridlayout = QGridLayout(self.source) self.scintillaWarningLabel = QLabel( "QScintilla is not installed!. Falling back to basic text edit!.", self.source) self.gridlayout.addWidget(self.scintillaWarningLabel, 1, 0, 1, 2) self.sourceTreeWidget = QTreeWidget(self.source) self.sourceTreeWidget.setAlternatingRowColors(True) self.sourceTreeWidget.itemActivated.connect( self.on_sourceTreeWidget_itemActivated) self.sourceTreeWidget.itemClicked.connect( self.on_sourceTreeWidget_itemClicked) self.sourceTreeWidget.itemDoubleClicked.connect( self.on_sourceTreeWidget_itemClicked) self.gridlayout.addWidget(self.sourceTreeWidget, 0, 0, 1, 1) self.sourceTextEdit = QTextEdit(self.source) self.sourceTextEdit.setReadOnly(True) self.gridlayout.addWidget(self.sourceTextEdit, 0, 1, 1, 1) self.tabWidget.addTab(self.source, " ? ") self.result = QWidget() self.vlayout = QVBoxLayout(self.result) self.globalStatGroupBox = QGroupBox(self.result) self.hboxlayout = QHBoxLayout(self.globalStatGroupBox) self.totalTimeLcdNumber = QLCDNumber(self.globalStatGroupBox) self.totalTimeLcdNumber.setSegmentStyle(QLCDNumber.Filled) self.totalTimeLcdNumber.setNumDigits(7) self.totalTimeLcdNumber.display(1000000) self.totalTimeLcdNumber.setFrameShape(QFrame.StyledPanel) self.totalTimeLcdNumber.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.hboxlayout.addWidget(self.totalTimeLcdNumber) self.tTimeLabel = QLabel("<b>Total Time (Sec)</b>", self.globalStatGroupBox) self.tTimeLabel.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self.hboxlayout.addWidget(self.tTimeLabel) self.numCallLcdNumber = QLCDNumber(self.globalStatGroupBox) self.numCallLcdNumber.setNumDigits(7) self.numCallLcdNumber.display(1000000) self.numCallLcdNumber.setSegmentStyle(QLCDNumber.Filled) self.numCallLcdNumber.setFrameShape(QFrame.StyledPanel) self.numCallLcdNumber.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.hboxlayout.addWidget(self.numCallLcdNumber) self.numCallLabel = QLabel("<b>Number of calls</b>", self.globalStatGroupBox) self.numCallLabel.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self.hboxlayout.addWidget(self.numCallLabel) self.primCallLcdNumber = QLCDNumber(self.globalStatGroupBox) self.primCallLcdNumber.setSegmentStyle(QLCDNumber.Filled) self.primCallLcdNumber.setFrameShape(QFrame.StyledPanel) self.primCallLcdNumber.setNumDigits(7) self.primCallLcdNumber.display(1000000) self.primCallLcdNumber.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.hboxlayout.addWidget(self.primCallLcdNumber) self.primCallLabel = QLabel("<b>Primitive calls (%)</b>", self.globalStatGroupBox) self.primCallLabel.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self.hboxlayout.addWidget(self.primCallLabel) self.vlayout.addWidget(self.globalStatGroupBox) try: from PyKDE4.kdeui import KRatingWidget self.rating = KRatingWidget(self.globalStatGroupBox) self.rating.setToolTip('Profiling Performance Rating') except ImportError: pass self.tabWidget.addTab(self.result, " Get Results ! ") self.resgraph = QWidget() self.vlayout2 = QVBoxLayout(self.result) self.graphz = QGroupBox(self.resgraph) self.hboxlayout2 = QHBoxLayout(self.graphz) try: from PyKDE4.kdeui import KLed KLed(self.graphz) except ImportError: pass self.hboxlayout2.addWidget( QLabel(''' Work in Progress :) Not Ready Yet''')) self.vlayout2.addWidget(self.graphz) self.tabWidget.addTab(self.resgraph, " Graphs and Charts ") self.pathz = QWidget() self.vlayout3 = QVBoxLayout(self.pathz) self.patz = QGroupBox(self.pathz) self.hboxlayout3 = QVBoxLayout(self.patz) self.profilepath = QLineEdit(profilerPath) self.getprofile = QPushButton(QIcon.fromTheme("document-open"), 'Open') self.getprofile.setToolTip( 'Dont touch if you dont know what are doing') self.getprofile.clicked.connect(lambda: self.profilepath.setText( str( QFileDialog.getOpenFileName( self.patz, ' Open the profile.py file ', path.expanduser("~"), ';;(profile.py)')))) self.hboxlayout3.addWidget( QLabel( '<center><b>Profile.py Python Library Full Path:</b></center>') ) self.hboxlayout3.addWidget(self.profilepath) self.hboxlayout3.addWidget(self.getprofile) self.argGroupBox = QGroupBox(self.pathz) self.hbxlayout = QHBoxLayout(self.argGroupBox) self.argLineEdit = QLineEdit(self.argGroupBox) self.argLineEdit.setToolTip( 'Not touch if you dont know what are doing') self.argLineEdit.setPlaceholderText( 'Dont touch if you dont know what are doing') self.hbxlayout.addWidget( QLabel('<b>Additional Profile Arguments:</b>')) self.hbxlayout.addWidget(self.argLineEdit) self.hboxlayout3.addWidget(self.argGroupBox) self.vlayout3.addWidget(self.patz) self.tabWidget.addTab(self.pathz, " Paths and Configs ") self.outp = QWidget() self.vlayout4 = QVBoxLayout(self.outp) self.outgro = QGroupBox(self.outp) self.outgro.setTitle(" MultiProcessing Output Logs ") self.hboxlayout4 = QVBoxLayout(self.outgro) self.outputlog = QTextEdit() self.outputlog.setText(''' I do not fear computers, I fear the lack of them. -Isaac Asimov ''') self.hboxlayout4.addWidget(self.outputlog) self.vlayout4.addWidget(self.outgro) self.tabWidget.addTab(self.outp, " Logs ") self.actionNew_profiling = QAction(QIcon.fromTheme("document-new"), 'New Profiling', self) self.actionLoad_profile = QAction(QIcon.fromTheme("document-open"), 'Open Profiling', self) self.actionClean = QAction(QIcon.fromTheme("edit-clear"), 'Clean', self) self.actionClean.triggered.connect(lambda: self.clearContent) self.actionAbout = QAction(QIcon.fromTheme("help-about"), 'About', self) self.actionAbout.triggered.connect(lambda: QMessageBox.about( self.dock, __doc__, ', '.join( (__doc__, __license__, __author__, __email__)))) self.actionSave_profile = QAction(QIcon.fromTheme("document-save"), 'Save Profiling', self) self.actionManual = QAction(QIcon.fromTheme("help-contents"), 'Help', self) self.actionManual.triggered.connect(lambda: open_new_tab( 'http://docs.python.org/library/profile.html')) self.tabWidget.setCurrentIndex(2) self.globalStatGroupBox.setTitle("Global Statistics") item = self.tableWidget.horizontalHeaderItem(0) item.setText("Number of Calls") item = self.tableWidget.horizontalHeaderItem(1) item.setText("Total Time") item = self.tableWidget.horizontalHeaderItem(2) item.setText("Per Call") item = self.tableWidget.horizontalHeaderItem(3) item.setText("Cumulative Time") item = self.tableWidget.horizontalHeaderItem(4) item.setText("Per Call") item = self.tableWidget.horizontalHeaderItem(5) item.setText("Filename") item = self.tableWidget.horizontalHeaderItem(6) item.setText("Line") item = self.tableWidget.horizontalHeaderItem(7) item.setText("Function") self.tabWidget.setTabText(self.tabWidget.indexOf(self.stat), "Statistics per Function") self.sourceTreeWidget.headerItem().setText(0, "Source files") self.tabWidget.setTabText(self.tabWidget.indexOf(self.source), "Sources Navigator") ####################################################################### self.scrollable, self.dock = QScrollArea(), QDockWidget() self.scrollable.setWidgetResizable(True) self.scrollable.setWidget(self.tabWidget) self.dock.setWindowTitle(__doc__) self.dock.setStyleSheet('QDockWidget::title{text-align: center;}') self.dock.setWidget(self.scrollable) QToolBar(self.dock).addActions( (self.actionNew_profiling, self.actionClean, self.actionSave_profile, self.actionLoad_profile, self.actionManual, self.actionAbout)) self.actionNew_profiling.triggered.connect( self.on_actionNew_profiling_triggered) self.actionLoad_profile.triggered.connect( self.on_actionLoad_profile_triggered) self.actionSave_profile.triggered.connect( self.on_actionSave_profile_triggered) self.locator.get_service('misc').add_widget( self.dock, QIcon.fromTheme("document-open-recent"), __doc__) if QSCI: # Scintilla source editor management self.scintillaWarningLabel.setText(' QScintilla is Ready ! ') layout = self.source.layout() layout.removeWidget(self.sourceTextEdit) self.sourceTextEdit = Qsci.QsciScintilla(self.source) layout.addWidget(self.sourceTextEdit, 0, 1) doc = self.sourceTextEdit doc.setLexer(Qsci.QsciLexerPython(self.sourceTextEdit)) doc.setReadOnly(True) doc.setEdgeMode(Qsci.QsciScintilla.EdgeLine) doc.setEdgeColumn(80) doc.setEdgeColor(QColor("#FF0000")) doc.setFolding(Qsci.QsciScintilla.BoxedTreeFoldStyle) doc.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) doc.setCaretLineVisible(True) doc.setMarginLineNumbers(1, True) doc.setMarginWidth(1, 25) doc.setTabWidth(4) doc.setEolMode(Qsci.QsciScintilla.EolUnix) self.marker = {} for color in COLORS: mnr = doc.markerDefine(Qsci.QsciScintilla.Background) doc.setMarkerBackgroundColor(color, mnr) self.marker[color] = mnr self.currentSourcePath = None # Connect table and tree filter edit signal to unique slot self.filterTableLineEdit.textEdited.connect( self.on_filterLineEdit_textEdited) # Timer to display filter hint message self.filterHintTimer = QTimer(self) self.filterHintTimer.setSingleShot(True) self.filterHintTimer.timeout.connect(self.on_filterHintTimer_timeout) # Timer to start search self.filterSearchTimer = QTimer(self) self.filterSearchTimer.setSingleShot(True) self.filterSearchTimer.timeout.connect( self.on_filterSearchTimer_timeout) self.tabLoaded = {} for i in range(10): self.tabLoaded[i] = False self.backgroundTreeMatchedItems = {} self.resizeWidgetToContent(self.tableWidget)
def setupStyle(self, *kargs): # Customize Python lexer if type(self.lex) == type(Qsci.QsciLexerPython()): if self.ide.theme == 'dark': ## self.ui.te_sci.setCaretLineBackgroundColor(QColor(105,184,221,30)) self.ui.te_sci.setCaretForegroundColor(QColor(255, 255, 255)) shade = 30 self.lex.setDefaultPaper(QColor(shade, shade, shade)) self.lex.setPaper(QColor(shade, shade, shade), self.lex.Default) self.ui.te_sci.setColor(QColor(255, 255, 255)) self.ui.te_sci.setMarginsBackgroundColor(QColor(60, 60, 60)) self.ui.te_sci.setWhitespaceBackgroundColor(QColor(80, 80, 80)) self.ui.te_sci.setFoldMarginColors(QColor(200, 200, 200), QColor(90, 90, 90)) ## self.ui.te_sci.setPaper(QColor(80,80,80)) self.ui.te_sci.setMarginsForegroundColor(QColor(200, 200, 200)) ## self.ui.te_sci.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETBACK,Qsci.QsciScintilla.STYLE_DEFAULT,QColor(150,150,150)) self.ui.te_sci.setMatchedBraceBackgroundColor( QColor(shade, shade, shade)) self.ui.te_sci.setMatchedBraceForegroundColor( QColor(170, 0, 255)) self.ui.te_sci.setUnmatchedBraceBackgroundColor( QColor(shade, shade, shade)) # Set defaults for all: style_obj = set(styleD.keys()).intersection(dir(self.lex)) style_obj.remove('Default') style_obj = set(['Default']).union(sorted(style_obj)) for c in sorted(style_obj, reverse=1): clr = styleD[c] if clr == '': ## clr = '255,255,255' clr = styleD['Default'] ## print c,clr try: exec('self.lex.setPaper(QColor(30,30,30),self.lex.' + c + ')') exec('self.lex.setColor(QColor(' + clr + '),self.lex.' + c + ')') except: print('no keyword', c) else: print 'light theme' self.lex = Qsci.QsciLexerPython() self.lex.setDefaultFont(self.default_font) self.ui.te_sci.setLexer(self.lex) if sys.version_info.major == 3: self.ui.te_sci.SendScintilla( Qsci.QsciScintilla.SCI_STYLESETFONT, 1, bytes('Courier', 'utf-8')) else: ## self.ui.te_sci.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') self.ui.te_sci.SendScintilla( Qsci.QsciScintilla.SCI_STYLESETFONT, 1, self.settings['fontFamily']) # Update From Light style shade = 255 self.lex.setDefaultPaper(QColor(shade, shade, shade)) print self.lex.Default self.lex.setPaper(QColor(shade, shade, shade), self.lex.Default) self.ui.te_sci.setColor(QColor(0, 0, 0)) ## self.ui.te_sci.setMarginsBackgroundColor(QColor(60,60,60)) ## self.ui.te_sci.setWhitespaceBackgroundColor(QColor(80,80,80)) ## self.ui.te_sci.setFoldMarginColors(QColor(200,200,200),QColor(90,90,90)) ## self.ui.te_sci.setPaper(QColor(80,80,80)) ## self.ui.te_sci.setMarginsForegroundColor(QColor(200,200,200)) ## self.ui.te_sci.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETBACK,Qsci.QsciScintilla.STYLE_DEFAULT,QColor(150,150,150)) self.ui.te_sci.setMatchedBraceBackgroundColor( QColor(shade, shade, shade)) self.ui.te_sci.setMatchedBraceForegroundColor( QColor(170, 0, 255)) self.ui.te_sci.setUnmatchedBraceBackgroundColor( QColor(shade, shade, shade)) style_obj = set(styleLightD.keys()).intersection(dir(self.lex)) style_obj.remove('Default') style_obj = set(['Default']).union(sorted(style_obj)) for c in sorted(style_obj, reverse=1): clr = styleLightD[c] if clr == '': ## clr = '255,255,255' clr = styleLightD['Default'] ## print c,clr try: exec( 'self.lex.setPaper(QColor(255,255,255),self.lex.' + c + ')') exec('self.lex.setColor(QColor(' + clr + '),self.lex.' + c + ')') except: print('no keyword', c) self.ui.te_sci.setMarginsBackgroundColor(QColor(200, 200, 200)) self.ui.te_sci.setMarginsForegroundColor(QColor(60, 60, 60)) self.ui.te_sci.setFoldMarginColors(QColor(210, 210, 210), QColor(230, 230, 230))
def Script_Editor(self, source, name): editor = Qsci.QsciScintilla(eval(name)) ## define the font to use font = QtGui.QFont() font.setFamily("Courier") 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) #TODO : Adjust based on operating system editor.convertEols(Qsci.QsciScintilla.EolUnix) editor.setEolMode(Qsci.QsciScintilla.EolUnix) # Was EolUnix #editor.setEolVisibility(True) ## Line numbers # conventionnaly, margin 0 is for line numbers editor.setMarginWidth(0, fm.width("00000")) editor.setMarginLineNumbers(0, True) ## Edge Mode shows a red vetical bar at 80 chars editor.setEdgeMode(Qsci.QsciScintilla.EdgeLine) editor.setEdgeColumn(80) editor.setTabIndents(False) editor.setEdgeColor(QtGui.QColor("#FF0000")) editor.setTabWidth(4) ## Folding visual : we will use boxes editor.setFolding(Qsci.QsciScintilla.BoxedTreeFoldStyle) ## Braces matching editor.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch) ## Editing line color editor.setCaretLineVisible(True) editor.setCaretLineBackgroundColor(QtGui.QColor("#caeee0")) ## Margins colors # line numbers margin editor.setMarginsBackgroundColor(QtGui.QColor("#333333")) editor.setMarginsForegroundColor(QtGui.QColor("#CCCCCC")) # folding margin colors (foreground,background) editor.setFoldMarginColors(QtGui.QColor("#bfe4ea"), QtGui.QColor("#66bfcd")) ## Choose a lexer lexer = Qsci.QsciLexerPython() lexer.setDefaultFont(font) editor.setLexer(lexer) #editor.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, 'Courier') text = """print '///////////////Script Execution Started//////////////////////'\n# Write Your Script here\n\n\n\n\n\n\n\n\n\n\n\n# Uncomment this and add variable to display the figure\n#from matplotlib import pyplot\n#fig=pyplot.figure()\n#pyplot.plot(variable)\n#pyplot.show()\nprint '///////////////Script Execution Ended//////////////////////'""" #encapsulated search function def Search(text=text, search_text=None): print 'searching :', search_text if text == None: return #editor.setIndicatorOutlineColor(QtGui.QColor("#FFE11F")) editor.findFirst(search_text, False, True, False, True) def Search_next(): #editor.setIndicatorOutlineColor(QtGui.QColor("#FFE11F")) editor.findNext() def Open_Search(text=text): value, ok = QtGui.QInputDialog.getText(editor, 'Search', 'Text to search') Search(text=text, search_text=str(value)) def Open_Replace(text=text): def ShowFirstOccurence(): editor.findFirst(inline.text(), False, True, False, True) def OK(): Replace('text', search_text=inline.text(), newtext=outline.text()) def Cancel(): self.wid.close() self.wid = QtGui.QWidget() Vert = QtGui.QVBoxLayout(self.wid) inline = QtGui.QLineEdit() outline = QtGui.QLineEdit() Vert.addWidget(inline) Vert.addWidget(outline) Hor = QtGui.QHBoxLayout() ok = QtGui.QPushButton('OK') cancel = QtGui.QPushButton('Cancel') Hor.addWidget(ok) Hor.addWidget(cancel) Vert.addLayout(Hor) self.wid.show() QtCore.QObject.connect(inline, QtCore.SIGNAL('textEdited(QString)'), ShowFirstOccurence) QtCore.QObject.connect(ok, QtCore.SIGNAL("clicked()"), OK) QtCore.QObject.connect(cancel, QtCore.SIGNAL("clicked()"), Cancel) def Replace(text=text, search_text=None, newtext=None): editor.findFirst(search_text, False, True, False, True) editor.replace(newtext) shcut1 = QtGui.QShortcut(editor) shcut1.setKey("CTRL+F") QtCore.QObject.connect(shcut1, QtCore.SIGNAL("activated()"), Open_Search) shcut1 = QtGui.QShortcut(editor) shcut1.setKey("CTRL+G") QtCore.QObject.connect(shcut1, QtCore.SIGNAL("activated()"), Search_next) shcut1 = QtGui.QShortcut(editor) shcut1.setKey("CTRL+H") QtCore.QObject.connect(shcut1, QtCore.SIGNAL("activated()"), Open_Replace) try: #text=str(open(self.Current_Script_Adress).read()) text = str(open(self.Current_Script_Adress).read()).replace( ' ', ' ') #4 spaces replaced by tab editor.setText(text) return editor except TypeError: text = """print '///////////////Script Execution Started//////////////////////'\n# Write Your Script here\n\n\n\n\n\n\n\n\n\n\n\n# Uncomment this and add variable to display the figure\n#from matplotlib import pyplot\n#fig=pyplot.figure()\n#pyplot.plot(variable)\n#pyplot.show()\nprint '///////////////Script Execution Ended//////////////////////'""" editor.setText(text) return editor except IOError: msgBox = QtGui.QMessageBox() msgBox.setText(""" SynaptiQs was unable to open <b>%s plugin</b> <p>Destination file was maybe renamed or deleted <p>Do not put spaces or special caracters in files names... """ % (source)) msgBox.exec_() return
def __init__(self, parent=None, ShowPrint=True, ShowError=True, StatusBar=None, AsDock=False, SaveLogRefreshDays=30, ScriptsPath='Scripts/', InitalizeScripts=True): ''' Parent - Pass QWIDGET based objects. Else I will create my own. ShowPrint - Redirect standard prints ShowError - Redirect standard errors StatusBar - Attach DevC Invoke button to this status bar else You should invoke DevC explicitly AsDock - If True creates DevC as a dock else as a dialog window ''' if not parent: print 'No parent widget specified! Creating my own parent!' prn = QtGui.QWidget() prn.setObjectName('DevC') self.standalone = 1 else: prn = parent self.standalone = 0 if not hasattr(prn, 'addDockWidget') and not self.standalone: AsDock = False print 'Current parent does not support dock!' if ShowPrint: sys.stdout = self if ShowError: sys.stderr = self winObj = str(prn.objectName()) setattr(__builtin__, winObj if winObj else 'mainwin', prn) if AsDock: self.win = QtGui.QDockWidget(prn) base = QtGui.QWidget() self.setupUi(base) self.win.setWidget(base) prn.addDockWidget(QtCore.Qt.DockWidgetArea(2), self.win) else: self.win = QtGui.QDialog(prn) self.setupUi(self.win) self.parent = prn self.inter = InteractiveInterpreter() self.inter.locals['dev'] = self self.inter.locals['self'] = self.parent self.win.setWindowIcon(prn.windowIcon()) self.win.setWindowTitle('K Python Interpreter') self.PLX = Qsci.QsciLexerPython(self.win) self.ABS = Qsci.QsciAPIs(self.PLX) self.PLX.setAPIs(self.ABS) self.sciInput.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll) self.sciInput.setLexer(self.PLX) self.sciInput.setAutoCompletionThreshold(1) self.sciInput.setAutoIndent(True) self.sciInput.setAutoCompletionFillupsEnabled(True) self.sciInput.setBraceMatching(Qsci.QsciScintilla.StrictBraceMatch) self.sciInput.setMarginLineNumbers(1, 1) self.sciInput.setMarginWidth(1, 45) self.sciOutput.setReadOnly(1) self.sciOutput.setAutoCompletionSource(Qsci.QsciScintilla.AcsAll) self.sciOutput.setLexer(self.PLX) self.sciOutput.setAutoCompletionThreshold(1) self.sciOutput.setAutoIndent(True) self.sciOutput.setAutoCompletionFillupsEnabled(True) self.sciOutput.setBraceMatching(Qsci.QsciScintilla.StrictBraceMatch) self.sciOutput.setMarginLineNumbers(1, 1) self.sciOutput.setMarginWidth(1, 45) #Connections self.parent.connect(self.btnClearInput, QtCore.SIGNAL('clicked()'), self.btnRedirector) self.parent.connect(self.btnClearOutput, QtCore.SIGNAL('clicked()'), self.btnRedirector) self.parent.connect(self.btnExecute, QtCore.SIGNAL('clicked()'), self.btnRedirector) self.parent.connect(self.btnLoadScript, QtCore.SIGNAL('clicked()'), self.btnRedirector) self.parent.connect(self.btnSaveScript, QtCore.SIGNAL('clicked()'), self.btnRedirector) self.parent.connect(self.cline, QtCore.SIGNAL('returnPressed()'), self.commandLineExecute) if StatusBar: self.stsBtnDebugger = QtGui.QToolButton() self.stsBtnDebugger.setText('DevConsole') self.stsBtnDebugger.setToolTip('DevConsole') self.stsBtnDebugger.setAutoRaise(1) self.stsBtnDebugger.setMaximumHeight(18) StatusBar.addPermanentWidget(self.stsBtnDebugger, 0) self.parent.connect(self.stsBtnDebugger, QtCore.SIGNAL('clicked()'), self.btnRedirector) else: self.stsBtnDebugger = None self.win.hide() print 'Simple Python Scripting Environment (SPSE)' print '--------------------------------' print 'Initiated!' print '\nLog Start Time: ' + str(strftime("%Y/%m/%d %H:%M:%S")) print '\n---------------------------------------\n' print '*** Python %s on %s.***' % (sys.version, sys.platform) print sys.copyright print '' print 'Platform: ' + sys.platform print 'Version: ' + str(sys.getwindowsversion()) print 'FileSys encodeing: ' + str(sys.getfilesystemencoding()) print '\n---------------------------------------\n' self.credit = '\n---------------------------------------\nAbout Python Interactive Interpreter! \nExpreimental Feature developed by \nL.Kumaresan \nFor ABX Studios\n---------------------------------------\n ' self.InitalizeScripts = InitalizeScripts self.SaveLogRefreshDays = SaveLogRefreshDays self.scriptPath = ScriptsPath if self.scriptPath: if self.InitalizeScripts and self.scriptPath and not os.path.exists( self.scriptPath): os.makedirs(self.scriptPath) else: print 'Invalid script path!' try: if self.InitalizeScripts: self.execStartUp() except: print errorReport() print 'Error on startup'