Ligm.Editor designed to demonstrate the integration of a simple editor into PyQt applications.
Built-in editor allows you to work:
- with text files with the ability to highlight the syntax of the code (currently implemented highlighting SQL and Python)
- with files containing formatted HTML text (in WYSIWYG mode). The editor has only the most basic elements of text formatting, such as font, size, color, etc. In addition to simple text formatting, work with HTML tables (insert tables, add/remove rows and columns) and images (insert, change the size) is implemented.
In both modes (text and HTML) there is a possibility of spell checking for English and Russian languages, preview and print the document, export to pdf. Ctrl-F, Ctrl-R, F3 (Shift-F3) are used to search and replace text. In addition to these combinations, there are combinations Ctrl-S and F 2 to save, Ctrl-D, Ctrl-T to insert the date and time, Ctrl-P-to print.
If the system is set to Russian locale by default, it works automatically switching the input language (Ctrl-L-enable / disable automatic replacement) and replacing the text typed in the wrong encoding (F12).
Example of a document with a table and picture:
Example of correcting errors in the text
It required Python 3.7+, PyQt5.
pip install ligm.editor
pip install ligm.spell (dictionaries for spell checking)
After install, run in the terminal ligm.editor
to start the demo application.
To install only the embedded editor, without the demo application:
pip install ligm.core
from PyQt5.Qt import QApplication
from ligm.core.text import TextEditor
from ligm.core.qt import install_translators
from ligm.core.common import SimpleConfig
filename= "example.html"
def load():
with open(filename, encoding="utf-8") as f:
return f.read()
def save(txt):
with open(filename, "w", encoding="utf-8") as f:
f.write(txt)
app = QApplication([])
install_translators()
cfg = SimpleConfig()
editor = TextEditor(None, cfg, save=save, load=load, auto_load=True)
editor.setGeometry(100, 100, 600, 500)
editor.show()
app.exec()
Parameters of class constructor:
parent
- parent widgetconfig
- the configuration classformat
- the format of the text (default is HTML)save
- method to save the textload
- method to load textmargins
- borders to display the widget in the parent widgetspell
- class spell checker (if not specified, a new class is created), to disable spell checking, you must explicitly specifyspell=False
auto_key_switch
- enable automatic correction of the encoding of the typed text (if the locale in the system is English, this function will be disabled)layout
- if this option is specified, the editor widget will be automatically added to the specified widgetauto_load
- automatic call to load text after creating the widget (otherwise you will need to call the method:editor.load()
)
save(txt) - saving text (calls the method passed in the constructor, if the method return a value other than None, it is assumed that it was called unsuccessfully)
load - loading text into the editor (calls the method passed in the constructor)
set_option - set the status of the editor
retranslate=""
- perform for all GUI elements the translation in the resp. with the current translatorformat="HTML"
- set HTML/TEXT formathighlighter="..."
- activate specified syntax highlighting (--no--, Python, SQL)invisible_symbol=""
- toggle the display of invisible charactersword_wrap=""
- switch the word wrap modebtn_save_visible=True/False
- show/hide Save buttonreadonly=True/False
- enable / disable read-only modeauto_save=True/False
- auto-save data after each changemargin_line=column
- position of drawing the right border in text modeshow_status_bar=True/False
- show / hide status bar
get_option(name) - return the state of the editor
name="word-wrap"
- status word wrap modename="readonly"
- read-only mode state
search(text="", show_msg=True) - starts searching for the text passed in the text parameter or (if text="") specified in the search string
get_text() - text in the editor (depends on the format).
is_empty() - checking document is empty or not.