# pyqode.core.widgets

This package contains a set of widgets that might be useful when writing pyqode applications:

> - 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.
> - QPropertyGrid: a simple property grid that works on pure python object made up of primitive types (int, float, list, string).

class `pyqode.core.widgets.``ErrorsTable`(parent=None)

  Bases: `pyqode.core.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.core.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

  `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)

    Starts a process interactively.

    Parameters: | process (str) – Process to run args (list) – List of arguments (list of str) cwd (str) – Working directory

  `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')

  Bases: `pyqode.core.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: `builtins.object`

  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.core.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.

    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
    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.