Ligm.Editor designed to demonstrate the integration of a simple editor into PyQt applications.
Built-in editor allows you to work:
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, [Shift-] F 3 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).
Editor appearance:
Fig. 1 - example of a document with a table and picture
Fig. 2 - example of correcting errors in the text
Fig. 3 - example source code (Python)
Fig. 4 - example source code (SQL)
Dependencies.
It required Python 3.7+, PyQt5.
Installation.
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
Example of use.
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()
Class ligm.core.text.TextEditor:
Parameters of class constructor:
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
get_option(name) - return the state of the editor
name="word-wrap" - status word wrap mode
name="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.