pyqode.core.widgets¶
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.
- class pyqode.core.widgets.ErrorsTable(parent=None)¶
Bases: pyqode.qt.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().
- add_message(msg)¶
Adds a checker message to the table.
Parameters: msg (pyqode.core.modes.CheckerMessage) – The message to append
- clear(*args, **kwargs)¶
Clears the tables and the message list
- class pyqode.core.widgets.InteractiveConsole(parent=None)¶
Bases: pyqode.qt.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_color_scheme(color_scheme)¶
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
- set_writer(writer)¶
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)
- start_process(process, args=None, cwd=None, env=None)¶
Starts a process interactively.
Parameters:
- stop_process()¶
Stop the process (by killing it).
- static write(text_edit, text, color)¶
Default write function. Move the cursor to the end and insert text with the specified color.
Parameters: - text_edit (pyqode.widgets.QInteractiveConsole) – QInteractiveConsole instance
- text (str) – Text to write
- color (QColor) – Desired text color
- app_msg_color¶
Color of the application messages (e.g.: ‘Process started’, ‘Process finished with status %d’)
- background_color¶
The console background color. Default is white.
- clear_on_start¶
True to clear window when starting a new process. False to accumulate outputs.
- merge_outputs¶
Merge stderr with stdout. Default is False.
If set to true, stderr and stdin will use the same color: stdin_color.
- stderr_color¶
Color for stderr output if pyqode.core.widgets.InteractiveConsole.merge_outputs is False.
Default is Red.
- stdin_color¶
STDIN color. Default is green.
- stdout_color¶
STDOUT color. Default is black.
- class pyqode.core.widgets.MenuRecentFiles(parent, recent_files_manager=None, title='Recent files', icon_provider=None, clear_icon=('edit-clear', ''))¶
Bases: pyqode.qt.QtWidgets.QMenu
Menu that manage the list of recent files.
To use the menu, simply pass connect to the open_requested signal.
- clear_recent_files()¶
Clear recent files and menu.
- update_actions()¶
Updates the list of actions.
- class pyqode.core.widgets.RecentFilesManager(organisation, application)¶
Bases: pyqode.qt.QtCore.QObject
Manages a list of recent files. The list of files is stored in your application QSettings.
- clear()¶
Clears recent files in QSettings
- get_recent_files()¶
Gets the list of recent files. (files that do not exists anymore are automatically filtered)
- open_file(file)¶
Adds a file to the list (and move it to the top of the list if the file already exists)
- class pyqode.core.widgets.TabWidget(parent)¶
Bases: pyqode.qt.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).
- addAction(action)¶
Adds an action to the TabBar context menu
Parameters: action – QAction to append
- addTab(elem, icon, name)¶
Extends QTabWidget.addTab to keep an internal list of added tabs.
- add_code_edit(code_edit, name=None)¶
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: - code_edit (pyqode.core.api.CodeEdit) – The code editor widget tab to append
- name – Name of the tab. Will use code_edit.file.name if None is supplied. Default is None. If this is a new document, you should either pass a unique name or a formatted string (with a ‘%d’ format)
Returns: Tab index
- add_separator()¶
Adds a separator to the TabBar context menu.
:returns The separator action.
- close()¶
Closes the active editor
- closeEvent(event)¶
On close, we try to close dirty tabs and only process the close event if all dirty tabs were closed by the user.
- close_all()¶
Closes all editors
- close_others()¶
Closes every editors tabs except the current one.
- index_from_filename(path)¶
Checks if the path is already open in an editor tab.
Returns: The tab index if found or -1
- removeTab(index)¶
Removes tab at index index.
This method will emits tab_closed for the removed tab.
- save_all()¶
Save all editors.
- save_current(path=None)¶
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.
- active_editor¶
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.
- class pyqode.core.widgets.EncodingsComboBox(parent, default_encoding='UTF-8')¶
Bases: pyqode.qt.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.
- class pyqode.core.widgets.EncodingsMenu(title='Encodings', parent=None, selected_encoding='UTF-8')¶
Bases: pyqode.qt.QtWidgets.QMenu
Implements a menu that show the user preferred encoding and emit reload_requested when the user changed the selected encoding.
This menu is a general purpose menu that you can put anywhere in your application but you will have to manage the reload operation yourself. For an integrated context menu, prefer using pyqode.core.widgets.EncodingsContextMenu.
- current_encoding¶
Gets/Sets the current encoding
- class pyqode.core.widgets.EncodingsContextMenu(title='Encodings', parent=None, selected_encoding='UTF-8')¶
Bases: pyqode.core.widgets.encodings.EncodingsMenu
Extends the encoding menu to be tightly coupled with a CodeEdit instance for an easier integration (automatically reload the editor file content when the encoding changed).
The parent widget of the menu must be set to a CodeEdit instance.
- class pyqode.core.widgets.TextCodeEdit(parent, server_script, interpreter='/home/colin/devenv/bin/python', args=None, create_default_actions=True)¶
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.
- class pyqode.core.widgets.GenericCodeEdit(parent, server_script, interpreter='/home/colin/devenv/bin/python', args=None, create_default_actions=True)¶
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.
- class pyqode.core.widgets.PromptLineEdit(parent=None, prompt_text=' Search', button_icon=None)¶
Bases: pyqode.qt.QtWidgets.QLineEdit
Extends QLineEdit to show a prompt text and a clear icon
- paintEvent(event)¶
QLineEdit.paintEvent implementation. Draws prompt
- resizeEvent(event)¶
QLineEdit.resizeEvent implementation Adjusts Clear button position
Set Clear button visible