v2.0.0
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) Sebastiaan MathĂ´t http://www.cogsci.nl/smathot
- 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.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.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
- class QProgEdit.QLexer
- class QProgEdit.QProgEdit
- function QProgEdit.QProgEdit.__init__(tabManager, title=u'Empty document', dPrint=None, **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 QProgEdit.QTabCornerWidget
- class QProgEdit.QTabManager
- function QProgEdit.QTabManager.__init__(tabsClosable=False, handlerButtonText=None, parent=None, cfg=<QProgEdit._qeditorcfg.QEditorCfg object at 0x7f56df4a6c30>, msg=None, tabsMovable=False)
- function QProgEdit.QTabManager.addTab(select=True, title=u'Empty document')
- function QProgEdit.QTabManager.applyCfg()
- function QProgEdit.QTabManager.closeTab(index=None)
- function QProgEdit.QTabManager.isAnyModified()
- function QProgEdit.QTabManager.selectTab(index)
- 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)
- module QProgEdit.py3
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 sip
sip.setapi('QString', 1)
import sys
from PyQt4 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):
treeWidgetItem.activate()
def main():
"""Runs a simple QProgEdit demonstration."""
validate.addPythonBuiltins(['builtin_var'])
app = QtGui.QApplication(sys.argv)
treeWidgetItem1 = QtGui.QTreeWidgetItem([u'Tab 1'])
treeWidgetItem3 = QtGui.QTreeWidgetItem([u'Tab 3'])
symbolTree = QtGui.QTreeWidget()
symbolTree.addTopLevelItem(treeWidgetItem1)
symbolTree.addTopLevelItem(treeWidgetItem3)
symbolTree.itemActivated.connect(activateSymbolTree)
tabManager = QTabManager(handlerButtonText=u'apply')
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)
tab = tabManager.addTab(u'Tab 1')
tab.setLang(u'Python')
tab.setSymbolTree(treeWidgetItem1)
tab.setText(open(__file__).read())
print tab.symbols()
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)
tab.setText(
u'def test():\n\tprint undefined_var\n\tbuiltin_var\n\ntest()\n')
print tab.symbols()
layout = QtGui.QHBoxLayout()
layout.addWidget(symbolTree)
layout.addWidget(tabManager)
container = QtGui.QWidget()
container.setLayout(layout)
container.show()
sys.exit(app.exec_())
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:
line
-- The line number.- Type: int
margin
-- The margin number.- Type: int
state
-- The keyboard state.- Type: int
Re-implements the paste method to allow modification of paste content.
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 the 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.- Default: <class 'QProgEdit._qsymboltreewidgetitem.QSymbolTreeWidgetItem'>
- Type: type
Sets the editor contents.
Arguments:
text
-- A text string. This can be a str object, which is assumed to be in utf-8 encoding, a Unicode object, or a QString.- Type: str, unicode, QString
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.- Default: None
- Type: QWidget, NoneType
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
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.- Default: u''
- Type: unicode
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
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:
index
-- The column number.- Default: 0
- Type: int
line
-- The line number.- Default: 0
- Type: int
The language selection menu.
Select a new language for the selected tab.
Arguments:
action
-- No description- Type: QAction
A themeable wrapper around the standard Lexer system.
Constructor.
Arguments:
editor
-- The parent QEditor.- Type: QEditor
Keywords:
lang
-- The language.- Default: u'text'
- Type: unicode
colorScheme
-- The color scheme.- Default: u'Default'
- Type: unicode
Gives a style description for the generic Lexer.
Arguments:
style
-- The style number.- Type: int
Returns:
The 'Default' QString for style 0 and empty QStrings for all other styles.
- Type: QString
A single editor window, with preferences widget and search functionality.
function QProgEdit.QProgEdit.__init__(tabManager, title=u'Empty document', dPrint=None, **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:
visible
-- A boolean indicating the visibility of the widget.widget
-- A QWidget.
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:
argSpec
-- The symbol's argument specification.- Type: unicode
lineNo
-- A line number.- Type: int
_type
-- The symbol type, such as 'class' or 'def'- Type: unicode
name
-- The symbol name- Type: unicode
editor
-- The editor widget.- Type: QEditor
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.
Constructor.
Arguments:
tabManager
-- A tab manager.- Type: QTabManager
Keywords:
msg
-- An informative text message.- Default: None
- Type: str, unicode, NoneType
handlerButtonText
-- Text for a top-right button, which can be clicked to call the handler, or None for no button.- Default: None
- Type: str, unicode, NoneType
Is called when the handler button is clicked and emits the relevant signals.
Updates widget to reflect document contents.
A tab manager that contains multiple QProgEdit tabs.
function QProgEdit.QTabManager.__init__(tabsClosable=False, handlerButtonText=None, parent=None, cfg=<QProgEdit._qeditorcfg.QEditorCfg object at 0x7f56df4a6c30>, msg=None, tabsMovable=False)
Constructor.
Keywords:
tabsClosable
-- Indicates whether a close button should be shown on tabs.- Default: False
- Type: bool
handlerButtonText
-- Text for a top-right button, which can be clicked to call the handler, or None for no button.- Default: None
- Type: str, unicode, NoneType
parent
-- The parent widget.- Default: None
- Type: QWidget
msg
-- An informative message for the corner widget.- Default: None
- Type: str, unicode, NoneType
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 0x7f56df4a6c30>
tabsMovable
-- Indicates whether tabs can be re-ordered.- Default: False
- Type: bool
Adds an empty document tab.
Keywords:
select
-- Indicates whether the newly created tab should be selected.- Default: True
- Type: bool
title
-- A tab title.- Default: u'Empty document'
- Type: unicode, str
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
Switches to a specific tab.
Arguments:
index
-- A tab index, as understood by tabIndex.
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.- Default: None
- Type: int, str, unicode, NoneType
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.- Default: None
- Type: int, str, unicode, NoneType
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
This modules defines some built-ins that are not available in Python 3, but are assumed to exist by QProgEdit.