This package contains a set of widgets that might be useful when writing pyqode applications:
- TextCodeEdit: code edit specialised for plain text
- GenericCodeEdit: generic code edit, using PygmentsSH. Not really fast, not really smart.
- InteractiveConsole: QTextEdit made for running background process interactively. Can be used in an IDE for running programs or to display the compiler output,...
- CodeEditTabWidget: tab widget made to handle CodeEdit instances (or any other object that have the same interface).
- ErrorsTable: a QTableWidget specialised to show CheckerMessage.
Bases: PyQt5.QtWidgets.QComboBox
This combo box display the list of user preferred encoding. The last item let you choose an additional encoding from the list of encodings define in pyqode.core.api.encodings using the EncodingsEditorDialog.
You can also set the current encoding, it will be automatically appended if not in the user list or set as the current index.
Gets/Sets the current encoding
Bases: PyQt5.QtWidgets.QTableWidget
Extends a QtWidgets.QTableWidget to easily show pyqode.core.modes.CheckerMessage.
You add messages to the table using pyqode.core.widgets.ErrorsTable.add_message().
You clear the table using pyqode.core.widgets.ErrorsTable().
Adds a checker message to the table.
Parameters: | msg (pyqode.core.modes.CheckerMessage) – The message to append |
---|
Clears the tables and the message list
Shows the error details.
Signal emitted when a message is activated, the clicked signal is passed as a parameter
Bases: PyQt5.QtWidgets.QTreeView
Extends QtWidgets.QTreeView with a filterable file system model.
To exclude directories or extension, just set FilterProxyModel.ignored_directories and FilterProxyModel.ignored_extensions.
Provides methods to retrieve file info from model index.
By default there is no context menu and no file operations are possible. We provide a standard context menu with basic file system operation ( FileSystemContextMenu) that you can extend and set on the tree view using FileSystemTreeView.set_context_menu()
Bases: PyQt5.QtCore.QSortFilterProxyModel
Excludes ignored_directories and ignored_extensions from the file system model.
Sets the root path to watch. :param path: root path (str).
The list of directories to ignore
The list of file extension to exclude
Gets the file info of the item at the specified index.
Parameters: | index – item index - QModelIndex |
---|---|
Returns: | QFileInfo |
Gets the file path of the item at the specified index.
Parameters: | index – item index - QModelIndex |
---|---|
Returns: | str |
Adds the specified directories to the list of ignored directories.
This must be done before calling set_root_path!
Parameters: | directories – the directories to ignore |
---|
Adds the specified extensions to the list of ignored directories.
This must be done before calling set_root_path!
Parameters: | extensions – the extensions to ignore |
---|
Note
extension must have the dot: ‘.py’ and not ‘py’
Sets the context menu of the tree view.
Parameters: | context_menu – QMenu |
---|
Sets the root path to watch :param path: root path - str :param hide_extra_columns: Hide extra column (size, paths,...)
signal emitted when the user created a file Parameters: - path (str): path of the file that got created
signal emitted when the user deleted a file Parameters: - path (str): path of the file that got deleted
signal emitted when the user renamed a file Parameters: - old (str): old path - new (str): new path
Bases: pyqode.core.api.code_edit.CodeEdit
This generic code edit uses the PygmentSH for syntax highlighting and commpletion engine based on the document words. It is not very smart and is probably 2 times slower than a native specialised code edit. It is meant to be used as a fallback editor in case you’re missing a specialised editor.
Bases: PyQt5.QtWidgets.QTextEdit
An interactive console is a QTextEdit specialised to run a process interactively
The user will see the process outputs and will be able to interact with the process by typing some text, this text will be forwarded to the process stdin.
You can customize the colors using the following attributes:
- stdout_color: color of the process stdout
- stdin_color: color of the user inputs. Green by default
- app_msg_color: color for custom application message ( process started, process finished)
- stderr_color: color of the process stderr
Apply a pygments color scheme to the console.
As there is not a 1 to 1 mapping between color scheme formats and console formats, we decided to make the following mapping (it usually looks good for most of the available pygments styles):
- stdout_color = normal color
- stderr_color = red (lighter if background is dark)
- stdin_color = numbers color
- app_msg_color = string color
- bacgorund_color = background
Parameters: | color_scheme – pyqode.core.api.ColorScheme to apply |
---|
Changes the writer function to handle writing to the text edit.
A writer function must have the following prototype:
def write(text_edit, text, color)
Parameters: | writer – write function as described above. |
---|
Starts a process interactively.
Parameters: |
---|
Stop the process (by killing it).
Default write function. Move the cursor to the end and insert text with the specified color.
Parameters: |
|
---|
Color of the application messages (e.g.: ‘Process started’, ‘Process finished with status %d’)
The console background color. Default is white.
True to clear window when starting a new process. False to accumulate outputs.
Checks if the process is running. :return:
Merge stderr with stdout. Default is False.
If set to true, stderr and stdin will use the same color: stdin_color.
Signal emitted when the process has finished.
Color for stderr output if pyqode.core.widgets.InteractiveConsole.merge_outputs is False.
Default is Red.
STDIN color. Default is green.
STDOUT color. Default is black.
Bases: PyQt5.QtWidgets.QLineEdit
Extends QLineEdit to show a prompt text and a clear icon
Sets the clear button as visible
Parameters: | visible – Visible state (True = visible, False = hidden). |
---|
Signal emitted when the embedded button is clicked
Gets/Sets the prompt text.
Bases: PyQt5.QtCore.QObject
Manages a list of recent files. The list of files is stored in your application QSettings.
Clears recent files in QSettings
Gets the list of recent files. (files that do not exists anymore are automatically filtered)
Reads value from QSettings :param key: value key :param default: default value. :return: value
Returns the path to the last opened file.
Adds a file to the list (and move it to the top of the list if the file already exists)
Parameters: | file – file path to add the list of recent files. |
---|
Remove a file path from the list of recent files. :param filename: Path of the file to remove
Set the recent files value in QSettings. :param key: value key :param value: new value
Maximum number of files kept in the list.
Bases: PyQt5.QtWidgets.QSplitter
A splittable tab widget. The widget is implemented as a splitter which contains a main tab widget and a collection of child SplittableTabWidget.
Widgets added to the the tab widget must have a split method which returns a clone of the widget instance.
You can add new tabs to the main tab widget by using the add_tab method. Tabs are always closable.
To change the underlying tab widget class, just set the tab_widget_klass class attribute.
The splittable tab widget works with any kind of widget. There is a specialisation made specifically for managing a collection code editor widgets: SplittableCodeEditTabWidget.
The implementation uses duck typing and will automatically show a dialog when closing an editor which has a dirty property. To actually save the widget, you must reimplement SplittableTabWidget.save_widget`().
underlying tab widget class
alias of BaseTabWidget
Adds a tab to main tab widget.
Parameters: |
|
---|
Returns the number of widgets currently displayed (takes child splits into account).
Returns a reference to the current widget, i.e. the last widget that got the focus. :return: QWidget
Checks if there are children tab widgets. :return: True if there is at least one tab in the children tab widget.
Split the the current widget in new SplittableTabWidget.
Parameters: |
|
---|---|
Returns: | the new splitter |
Recursively gets the list of widgets.
Parameters: | include_clones – True to retrieve all tabs, including clones, otherwise only original widgets are returned. |
---|
Signal emitted when the active tab changed (takes child tab widgets into account). Parameter is the new tab widget.
Signal emitted when the last tab has been closed.
Bases: pyqode.core.widgets.splittable_tab_widget.SplittableTabWidget
SplittableTabWidget specialised for CodeEdit and subclasses.
Offers some convenience function for opening/saving files.
The widget supports multiple type of code editors. Each editor type must be explicitly registered using register_editor. If there is no registered editor for the given mime-type, fallback_editor is used.
Fallback editor is used in case not editors matching the requested mime-type could not be found in the editors map. By default the fallback_editor is a pyqode.core.widgets.GenericCodeEdit
alias of GenericCodeEdit
the icon provider class to use when creating new document. Must be a subclass of QtWidgets.QFileIconProvider. By default, QFileIconProvider is used.
alias of QFileIconProvider
uses a CodeEditTabWidget which is able to save code editor widgets.
alias of CodeEditTabWidget
Saves dirty editors on close and cancel the event if the user choosed to continue to work.
Parameters: | event – close event |
---|
Closes a text document. :param path: Path of the document to close.
Creates a new document.
The document name will be base_name + count + extension
Parameters: |
|
---|---|
Returns: | Code editor widget instance. |
Opens a document.
Parameters: |
|
---|---|
Returns: | The created code editor |
Register an additional code edit class :param code_edit_class: code edit class to regiter.
Renames an already opened document (this will not rename the file, just update the file path and tab title).
Use that function to update a file that has been renamed externally.
Parameters: |
|
---|
Save all editors.
Save current editor. If the editor.file.path is None, a save as dialog will be shown.
Save current widget as.
signal emitted when the dirty_changed signal of the current editor has been emitted.
Maps a mime-type with an editor type. This map is used to instantiate the proper editor type when opening/creating a document.
Bases: PyQt5.QtWidgets.QTabWidget
QTabWidget specialised to hold CodeEdit instances (or any other object that has the same interace).
It ensures that there is only one open editor tab for a specific file path, it adds a few utility methods to quickly manipulate the current editor widget. It will automatically rename tabs that share the same base filename to include their distinctive parent directory.
It handles tab close requests automatically and show a dialog box when a dirty tab widget is being closed. It also adds a convenience QTabBar with a “close”, “close others” and “close all” menu. (You can add custom actions by using the addAction and addSeparator methods).
It exposes a variety of signal and slots for a better integration with your applications( dirty_changed, save_current, save_all, close_all, close_current, close_others).
Adds an action to the TabBar context menu
Parameters: | action – QAction to append |
---|
Extends QTabWidget.addTab to keep an internal list of added tabs.
Parameters: |
|
---|
Adds a code edit tab, sets its text as the editor.file.name and sets it as the active tab.
The widget is only added if there is no other editor tab open with the same filename, else the already open tab is set as current.
If the widget file path is empty, i.e. this is a new document that has not been saved to disk, you may provided a formatted string such as ‘New document %d.txt’ for the document name. The int format will be automatically replaced by the number of new documents (e.g. ‘New document 1.txt’ then ‘New document 2.txt’ and so on). If you prefer to use your own code to manage the file names, just ensure that the names are unique.
Parameters: |
|
---|---|
Returns: | Tab index |
Adds a separator to the TabBar context menu.
:returns The separator action.
Closes the active editor
Closes all editors
Closes every editors tabs except the current one.
Checks if the path is already open in an editor tab.
Parameters: | path – path to check |
---|---|
Returns: | The tab index if found or -1 |
Removes tab at index index.
This method will emits tab_closed for the removed tab.
Parameters: | index – index of the tab to remove. |
---|
Save all editors.
Save current editor content. Leave file to None to erase the previous file content. If the current editor’s file_path is None and path is None, the function will call QtWidgets.QFileDialog.getSaveFileName to get a valid save filename.
Parameters: | path – path of the file to save, leave it None to overwrite existing file. |
---|
Returns the current editor widget or None if the current tab widget is not a subclass of CodeEdit or if there is no open tab.
Signal emitted when a tab dirty flag changed
Signal emitted when the last tab has been closed
Signal emitted when a tab has been closed
Bases: pyqode.core.api.code_edit.CodeEdit
CodeEdit specialised for plain text.
Especially useful for long text file such as log files because it’s syntax highlighter does not do anything.
Bases: pyqode.core.api.syntax_highlighter.SyntaxHighlighter
Empty highlighter, does not do anything (very fast at loading very big files).
Does nothing