v3.0.0~pre2
QProgEdit is a PyQt4 widget that implements a full-featured text editor component. It's primary target at the moment is OpenSesame, a graphical experiment builder.
Copyright (2013-2015) Sebastiaan MathĂ´t
- Dependencies
- Example
- class QProgEdit.QEditor
- function QProgEdit.QEditor.__init__(qProgEdit)
- function QProgEdit.QEditor.applyCfg()
- function QProgEdit.QEditor.commentSelection()
- function QProgEdit.QEditor.cursorMoved()
- function QProgEdit.QEditor.focusInEvent(e)
- function QProgEdit.QEditor.focusOutEvent(e)
- function QProgEdit.QEditor.highlightSelection()
- function QProgEdit.QEditor.keyPressEvent(event)
- function QProgEdit.QEditor.lang()
- function QProgEdit.QEditor.onMarginClick(margin, line, state)
- function QProgEdit.QEditor.paste()
- function QProgEdit.QEditor.selectedText(currentLineFallback=False)
- function QProgEdit.QEditor.setKeyBindings()
- function QProgEdit.QEditor.setLang(lang=u'text')
- function QProgEdit.QEditor.setSymbolTree(symbolTree, symbolTreeWidgetItemClass=<class 'QProgEdit._qsymboltreewidgetitem.QSymbolTreeWidgetItem'>)
- function QProgEdit.QEditor.setText(text)
- function QProgEdit.QEditor.symbols()
- function QProgEdit.QEditor.text()
- function QProgEdit.QEditor.uncommentSelection()
- function QProgEdit.QEditor.updateMarginWidth()
- function QProgEdit.QEditor.updateSymbolTree()
- function QProgEdit.QEditor.validate()
- function QProgEdit.QEditor.wheelEvent(event)
- class QProgEdit.QEditorCfg
- class QProgEdit.QEditorFind
- function QProgEdit.QEditorFind.__init__(qProgEdit)
- function QProgEdit.QEditorFind.caseSensitive()
- function QProgEdit.QEditorFind.find()
- function QProgEdit.QEditorFind.findText()
- function QProgEdit.QEditorFind.loadUi(name)
- function QProgEdit.QEditorFind.lock()
- function QProgEdit.QEditorFind.matchWhole()
- function QProgEdit.QEditorFind.replace()
- function QProgEdit.QEditorFind.replaceAll()
- function QProgEdit.QEditorFind.replaceText()
- function QProgEdit.QEditorFind.setFindText(txt=u'')
- function QProgEdit.QEditorFind.unlock()
- function QProgEdit.QEditorFind.unshow()
- class QProgEdit.QEditorPrefs
- class QProgEdit.QEditorStatus
- class QProgEdit.QLangMenu
- function QProgEdit.QLexer(editor, lang=u'text', colorScheme=u'Default')
- class QProgEdit.QProgEdit
- function QProgEdit.QProgEdit.__init__(tabManager, dPrint=None, title=u'Empty document', **editorParams)
- function QProgEdit.QProgEdit.dPrint(msg)
- function QProgEdit.QProgEdit.focusTab()
- function QProgEdit.QProgEdit.tabIndex()
- function QProgEdit.QProgEdit.toggle(widget, visible)
- function QProgEdit.QProgEdit.toggleFind(visible)
- function QProgEdit.QProgEdit.togglePrefs(visible)
- class QProgEdit.QSymbolTreeWidgetItem
- class qtpyabCornerWidget
- class qtpyabManager
- function QProgEdit.QTabManager.__init__(parent=None, cfg=<QProgEdit._qeditorcfg.QEditorCfg object at 0x7f73885d59d0>, tabsClosable=False, tabsMovable=False, msg=None, handlerButtonText=None, runButton=False)
- function QProgEdit.QTabManager.addTab(title=u'Empty document', select=True)
- function QProgEdit.QTabManager.applyCfg()
- function QProgEdit.QTabManager.closeTab(index=None)
- function QProgEdit.QTabManager.isAnyModified()
- function QProgEdit.QTabManager.runSelectedText()
- function QProgEdit.QTabManager.runText()
- function QProgEdit.QTabManager.selectTab(index)
- function QProgEdit.QTabManager.selectedText(index=None, currentLineFallback=False)
- function QProgEdit.QTabManager.setFocus(index=None)
- function QProgEdit.QTabManager.setText(text, index=None)
- function QProgEdit.QTabManager.switchTabLeft()
- function QProgEdit.QTabManager.switchTabRight()
- function QProgEdit.QTabManager.tab(index=None)
- function QProgEdit.QTabManager.tabChanged(index)
- function QProgEdit.QTabManager.tabIndex(index=None)
- function QProgEdit.QTabManager.tabs()
- function QProgEdit.QTabManager.text(index=None)
- function QProgEdit.QTabManager.toggleFind(visible)
- function QProgEdit.QTabManager.togglePrefs(visible)
- class QProgEdit.QUiLoader
PyQt4
Qscintilla2
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
This file is part of QProgEdit.
QProgEdit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QProgEdit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QProgEdit. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import sys
from qtpy import QtGui, QtCore
from QProgEdit import QTabManager, validate
def cursorRowChanged(index, rowFrom, rowTo):
print(u'curorRowChanged(): %d, %d, %d' % (index, rowFrom, rowTo))
def focusLost(index):
print(u'focusOut(): %s' % index)
def focusReceived(index):
print(u'focusReceived(): %s' % index)
def handlerButtonClicked(index):
print(u'handlerButtonClicked(): %s' % index)
def activateSymbolTree(treeWidgetItem):
if hasattr(treeWidgetItem, u'activate'):
treeWidgetItem.activate()
def runSelectedText(s):
print('run:\n%s' % s)
def main():
"""Runs a simple QProgEdit demonstration."""
validate.addPythonBuiltins(['builtin_var'])
app = QtGui.QApplication(sys.argv)
treeWidgetItem1 = QtWidgets.QTreeWidgetItem([u'Tab 1'])
treeWidgetItem3 = QtWidgets.QTreeWidgetItem([u'Tab 3'])
symbolTree = QtWidgets.QTreeWidget()
symbolTree.addTopLevelItem(treeWidgetItem1)
symbolTree.addTopLevelItem(treeWidgetItem3)
symbolTree.itemActivated.connect(activateSymbolTree)
tabManager = QTabManager(handlerButtonText=u'apply', runButton=True)
tabManager.setWindowIcon(QtGui.QIcon.fromTheme(u'accessories-text-editor'))
tabManager.setWindowTitle(u'QProgEdit')
tabManager.resize(800, 600)
tabManager.cursorRowChanged.connect(cursorRowChanged)
tabManager.focusLost.connect(focusLost)
tabManager.focusReceived.connect(focusReceived)
tabManager.handlerButtonClicked.connect(handlerButtonClicked)
tabManager.execute.connect(runSelectedText)
tab = tabManager.addTab(u'Tab 1')
tab.setLang(u'Python')
tab.setSymbolTree(treeWidgetItem1)
tab.setText(open(__file__).read())
tab = tabManager.addTab(u'Tab 2')
tab.setText(u'Some plain text')
tab = tabManager.addTab(u'Tab 3')
tab.setLang(u'Python')
tab.setSymbolTree(treeWidgetItem3)
if os.path.exists(u'content.txt'):
tab.setText(open(u'content.txt').read())
layout = QtWidgets.QHBoxLayout()
layout.addWidget(symbolTree)
layout.addWidget(tabManager)
container = QtWidgets.QWidget()
container.setLayout(layout)
container.show()
res = app.exec_()
open(u'content.txt', u'w').write(tab.text())
sys.exit(res)
if __name__ == '__main__':
main()
A single editor widget, which is embedded in a QProgEdit widget.
Constructor.
Arguments:
qProgEdit
-- The parent QProgEdit.- Type: QProgEdit
Applies the configuration.
Comments out the currently selected text.
Is called whenever the cursor moves, checks whether the cursor has jumped from one line to the next, and, if so, calls the relevant functions.
Called when the editor receives focus.
Arguments:
e
-- No description
Called when the editor loses focus.
Arguments:
e
-- No description
Highlights all parts of the text that match the current selection.
Intercepts certain keypress events to implement custom copy-pasting and zooming.
Arguments:
event
-- No description- Type: QKeyPressEvent
No description specified.
Returns:
The language of the editor.
- Type: unicode
Shows validation errors when the margin symbol is clicked.
Arguments:
margin
-- The margin number.- Type: int
line
-- The line number.- Type: int
state
-- The keyboard state.- Type: int
Re-implements the paste method to allow modification of paste content.
Returns the selected text.
Keywords:
currentLineFallback
-- Indicates whether the current line should be returned if no text has been selected. Otherwise, an empty string is returned.- Type: bool
- Default: False
Returns:
The selected text.
- Type: str
Sets keybindings so that they don't interfere with the default keybindings of OpenSesame, and are more atom-like.
Sets the editor language.
Keywords:
lang
-- A language, used to select a lexer for syntax highlighting, validation, cleaning, etc. if an appropriate lexer isn't found, no error is generated, but syntax highlighting is disabled. For a list of available lexers, refer to theQsci.QsciScintilla documentation.- Default: u'text'
function QProgEdit.QEditor.setSymbolTree(symbolTree, symbolTreeWidgetItemClass=<class 'QProgEdit._qsymboltreewidgetitem.QSymbolTreeWidgetItem'>)
Sets the symbol-tree widget.
Arguments:
symbolTree
-- A symbol-tree widget.- Type: QTreeWidgetItem
Keywords:
symbolTreeWidgetItemClass
-- The class to use for symbol-tree widgets. This should derive from QSymbolTreeWidgetItem.- Type: type
- Default: <class 'QProgEdit._qsymboltreewidgetitem.QSymbolTreeWidgetItem'>
Sets the editor contents.
Arguments:
text
-- A text string. This can be a str object or unicode object.- Type: str, unicode
Returns an up-to-date list of symbols.
Returns:
A list of symbols.
- Type: list
Retrieves the editor contents.
Returns:
The editor contents.
- Type: unicode
Uncomments the currently selected text.
Updates the width of the margin containing the line numbers.
Updates the symbol tree, if any has been specified and a symbol parser is available for the langauage.
Validates the content.
Implements scroll-to-zoom functionality.
Arguments:
event
-- No description- Type: QWheelEvent
A non-persistent configuration object.
Constructor.
Keywords:
parent
-- The parent widget.- Type: QWidget, NoneType
- Default: None
Returns the config version.
A find/ replace widget.
Constructor.
Arguments:
qProgEdit
-- The parent QProgEdit.- Type: QProgEdit
No description specified.
Returns:
True or False, depending on whether we should search case sensitive.
- Type: bool
Finds the current text in the document.
Returns:
True if matching text has been found, False otherwise.
- Type: bool
No description specified.
Returns:
The find text.
- Type: unicode
Load a UI.
Arguments:
name
-- The name of the UI file, without the .ui extension.- Type: unicode
Locks the editor and find widget, so that we don't get into recursion problems during replace actions.
No description specified.
Returns:
True or False, depending on whether we should match whole words only.
- Type: bool
Replaces the first occurence in the document.
Returns:
True if text has been replaced, False otherwise.
- Type: bool
Replaces all occurences in the document.
No description specified.
Returns:
The replace text.
- Type: unicode
Sets the text of the find widget.
Keywords:
txt
-- The text to set.- Type: unicode
- Default: u''
Unlocks the editor and find widget, to resume normal operations after replacing.
Hides the widget.
An editor preferences widget.
Constructor.
Arguments:
qProgEdit
-- The parent QProgEdit.- Type: QProgEdit
Applies the controls.
Keywords:
dummy
-- No description- Default: None
Load a UI.
Arguments:
name
-- The name of the UI file, without the .ui extension.- Type: unicode
Refreshes the controls.
A simple widget that indicates the editor status, which currently corresponds only to the cursor position.
Constructor.
Arguments:
qProgEdit
-- The parent QProgEdit.- Type: QProgEdit
Updates the cursor position.
Keywords:
line
-- The line number.- Type: int
- Default: 0
index
-- The column number.- Type: int
- Default: 0
A factory for a lexer.
Arguments:
editor
-- The parent QEditor.- Type: QEditor
Keywords:
lang
-- The language.- Type: unicode
- Default: u'text'
colorScheme
-- The color scheme.- Type: unicode
- Default: u'Default'
A single editor window, with preferences widget and search functionality.
function QProgEdit.QProgEdit.__init__(tabManager, dPrint=None, title=u'Empty document', **editorParams)
Constructor.
Arguments:
tabManager
-- A tab manager.- Type: QTabManager
Keywords:
dPrint
-- A function to be used for debug printing. Should accept a single parameter, which is the debug message. If no debug function is specified, the standard output is used.- Default: None
title
-- A title for the document.- Default: u'Empty document'
Keyword dict:
**editorParams
: A dictionary with keywords to be passed to QEditor.
Prints a debug message.
Arguments:
msg
-- A debug message.- Type: unicode, str
Focuses the current tab.
Gets the index of the current tab.
Returns:
The tab index.
- Type: int
Toggles the visibility of a widget with a smooth animation.
Arguments:
widget
-- A QWidget.visible
-- A boolean indicating the visibility of the widget.
Toggles the visibility of the find widget.
Arguments:
visible
-- A boolean indicating the visibility of the widget.
Toggles the visibility of the preferences widget
Arguments:
visible
-- A boolean indicating the visibility of the widget.
A symbol-tree widget item to use for symbol overviews.
Constructor.
Arguments:
editor
-- The editor widget.- Type: QEditor
lineNo
-- A line number.- Type: int
_type
-- The symbol type, such as 'class' or 'def'- Type: unicode
name
-- The symbol name- Type: unicode
argSpec
-- The symbol's argument specification.- Type: unicode
Is called when the symbol is activated, to focus the symbol in the editor.
Contains a number of buttons that are displayed in the tab bar.
function QProgEdit.QTabCornerWidget.__init__(tabManager, msg=None, handlerButtonText=None, runButton=False)
Constructor.
Arguments:
tabManager
-- A tab manager.- Type: QTabManager
Keywords:
msg
-- An informative text message.- Type: str, unicode, NoneType
- Default: None
handlerButtonText
-- Text for a top-right button, which can be clicked to call the handler, or None for no button.- Type: str, unicode, NoneType
- Default: None
runButton
-- Indicates whether a run-selected-text button should be shown.- Type: bool
- Default: False
Updates widget to reflect document contents.
A tab manager that contains multiple QProgEdit tabs.
function QProgEdit.QTabManager.__init__(parent=None, cfg=<QProgEdit._qeditorcfg.QEditorCfg object at 0x7f73885d59d0>, tabsClosable=False, tabsMovable=False, msg=None, handlerButtonText=None, runButton=False)
Constructor.
Keywords:
parent
-- The parent widget.- Type: QWidget
- Default: None
cfg
-- A configuration backend. By default QEditorCfg is used. Custom backends must have the same API for getting and setting options.- Default: <QProgEdit._qeditorcfg.QEditorCfg object at 0x7f73885d59d0>
tabsClosable
-- Indicates whether a close button should be shown on tabs.- Type: bool
- Default: False
tabsMovable
-- Indicates whether tabs can be re-ordered.- Type: bool
- Default: False
msg
-- An informative message for the corner widget.- Type: str, unicode, NoneType
- Default: None
handlerButtonText
-- Text for a top-right button, which can be clicked to call the handler, or None for no button.- Type: str, unicode, NoneType
- Default: None
runButton
-- Indicates whether a run-selected-text button should be shown.- Type: bool
- Default: False
Adds an empty document tab.
Keywords:
title
-- A tab title.- Type: unicode, str
- Default: u'Empty document'
select
-- Indicates whether the newly created tab should be selected.- Type: bool
- Default: True
Returns:
The newly added tab widget.
- Type: QProgEdit
Applies the configuration.
Closes a tab.
Keywords:
index
-- A tab index (see tabIndex).- Default: None
Checks if one or more of the tabs have been modified.
Returns:
True if (one of) the tab(s) is modified, False otherwise.
- Type: bool
Emits the execute signal with the selected text.
Emits the execute signal with the current text.
Switches to a specific tab.
Arguments:
index
-- A tab index, as understood by tabIndex.
Returns the selected text for a specific tab.
For details, see QProgEdit.QEditor
.
Keywords:
index
-- A tab index, as understood by tabIndex.- Default: None
currentLineFallback
-- No description- Default: False
Returns:
The selected text.
Focuses a specific tab.
Keywords:
index
-- A tab index, as understood by tabIndex.- Default: None
Sets the text on a specific tab.
Arguments:
text
-- The new text.
Keywords:
index
-- A tab index, as understood by tabIndex.- Default: None
Switches to the tab on the left.
Switches to the tab on the left.
Returns the QProgEdit instance for a given tab.
Keywords:
index
-- Specifies the tab, either by a name (i.e. the name on a tab), an index, or None to get the current tab.- Type: int, str, unicode, NoneType
- Default: None
Returns:
A tab, or None if no matching tab was found.
- Type: QProgEdit, NoneType
Is called when the current tab must be updated, for example because a new tab is selected.
Arguments:
index
-- The index of the newly selected tab.- Type: int
Returns the index for a given tab.
Keywords:
index
-- Specifies the tab, either by a name (i.e. the name on a tab), an index, or None to get the current tab.- Type: int, str, unicode, NoneType
- Default: None
Returns:
A tab index, or None if no matching tab was found.
- Type: int, NoneType
Gets all tabs.
Returns:
A list of all tab widgets.
- Type: list
Gets the text on a specific tab.
Keywords:
index
-- A tab index, as understood by tabIndex.- Default: None
Returns:
The text or None if the tab does not exist.
Toggle the visibility of the find widget.
Arguments:
visible
-- Visibility status.- Type: bool
Toggle the visibility of the preferences widget.
Arguments:
visible
-- Visibility status.- Type: bool
A simple base class that implements dynamic UI loading for widgets.
Load a UI.
Arguments:
name
-- The name of the UI file, without the .ui extension.- Type: unicode