pyqode.core.managers

The managers package contains a series of managers classes for CodeEdit.

A manager is class that takes care of a specific aspect of CodeEdit:

  • FileManager: open, save, encoding detection
  • BackendManager: manage the backend process (start the process and handle communication through sockets).
  • ModesManager: manage the list of modes of an editor
  • PanelsManager: manage the list of panels and draw them into the editor margins.
  • DecorationManager: manage text decorations
class pyqode.core.managers.BackendManager(editor)

Bases: pyqode.core.api.manager.Manager

The backend controller takes care of controlling the client-server architecture.

It is responsible of starting the backend process and the client socket and exposes an API to easily control the backend:

  • start
  • stop
  • send_request
send_request(worker_class_or_function, args, on_receive=None)

Request some work to be done server side. You can get notified of the work results by passing a callback (on_receive).

Param:

editor: editor instance

Parameters:
  • worker_class_or_function – Worker class or function
  • args – worker args, any Json serializable objects
  • on_receive – an optional callback executed when we receive the worker’s results. The callback will be called with two arguments: the status (bool) and the results (object)
Raise:

backend.NotConnected if the server cannot be reached.

start(script, interpreter='/usr/bin/python', args=None, port=None)

Starts the backend server process.

The server is a python script that starts a pyqode.core.backend.JsonServer. You must write the server script so that you can apply your own configuration on the server side.

The script can be run with a custom interpreter. The default is to use sys.executable.

Parameters:
  • script – Path to the server main script.
  • interpreter – The python interpreter to use to run the server script. If None, sys.executable is used unless we are in a frozen application (frozen servers do not require an interpreter).
  • args – list of additional command line args to use to start the server process.
  • port – The tcp port to use. Pass None to use a free random port.
stop()

Stop backend process (by terminating it).

connected

Checks if the client socket is connected to a backend server.

class pyqode.core.managers.FileManager(editor, replace_tabs_by_spaces=True)

Bases: pyqode.core.api.manager.Manager

Helps manage file operations:
  • open
  • save
  • provide icon
  • detect encoding
  • detect mimetype

Example of usage:

editor = CodeEdit()
assert editor.file.path == ''
editor.open(__file__)
assert editor.file.path == __file__
print(editor.file.encoding)
close()
Close the file open in the editor:
  • clear editor content
  • reset file attributes to their default values
detect_encoding(path)

Detects file encoding

Parameters:path – file path
Returns:detected encoding
static get_mimetype(path)

Guesses the mime type of a file. If mime type cannot be detected, plain text is assumed.

Parameters:path – path of the file
Returns:the corresponding mime type.
open(path)

Open a file and set its content on the editor widget.

Parameters:path – Path of the file to open.
save(path=None, encoding=None)

Save the editor content to a file.

Parameters:
  • path – optional file path. Set it to None to save using the current path (save), set a new path to save as.
  • encoding – optional encoding, will use the current file encoding if None.
dirname

Gets the file directory name

encoding

Gets the file encoding

extension

Gets the file path

icon

Gets the file icon, provided by _get_icon

name

Gets the file base name

path

Gets the file path

class pyqode.core.managers.ModesManager(editor)

Bases: pyqode.core.api.manager.Manager

Manages the list of modes of the code edit widget.

append(mode)

Adds a mode to the editor.

Parameters:mode – The mode instance to append.
clear()

Removes all modes from the editor. All modes are removed from list and deleted.

get(name_or_klass)

Gets a mode by name (or class)

Parameters:name_or_klass (str or type) – The name or the class of the mode to get
Return type:pyqode.core.api.Mode
remove(name_or_klass)

Removes a mode from the editor.

Parameters:name – The name (or class) of the mode to remove.
Returns:The removed mode.
class pyqode.core.managers.PanelsManager(editor)

Bases: pyqode.core.api.manager.Manager

Manages the list of panels and draws them inised the margin of the code edit widget.

append(panel, position=1)

Install a panel on the editor.

Parameters:
  • panel – Panel to install
  • position – Panel position
Returns:

The installed panel

clear()

Removes all panel from the editor.

get(name_or_klass)

Gets a specific panel instance.

Parameters:name_or_klass – Name or class of the panel to retrieve.
Returns:The specified panel instance.
margin_size(position=1)

Gets the size of a specific margin.

Parameters:position – Margin position. See pyqode.core.api.Panel.Position
Returns:The size of the specified margin
Return type:float
panels_for_zone(zone)

Gets the list of panels attached to the specified zone.

Parameters:zone – Panel position.
Returns:List of panels instances.
refresh()

Refreshes the editor panels (resize and update margins)

remove(name_or_klass)

Removes the specified panel.

Parameters:name_or_klass – Name or class of the panel to remove.
Returns:The removed panel
resize()

Resizes panels

update(rect, delta_y, force_update_margins=False)

Updates panels