pygame-texteditor


Namepygame-texteditor JSON
Version 0.7.3 PyPI version JSON
download
home_page
SummaryA WYSIWYG-texteditor based on pygame.
upload_time2023-07-05 06:50:55
maintainer
docs_urlNone
authorVictor Seifert
requires_python>=3.8,<4.0
licenseMIT
keywords pygame texteditor text editor
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # A WYSIWYG-texteditor based on pygame for pygame

![PyPI](https://img.shields.io/pypi/v/pygame-texteditor?color=%233775A9&label=pypi%20package&style=plastic)
![GitHub](https://img.shields.io/github/license/CribberSix/pygame-texteditor?style=plastic)

## Introduction & examples

The text editor can be inserted into any existing pygame window.
A minimal code example of it being activated within an existing pygame window can be found below.

The code editor comes with line numbers and syntax highlighting for python if enabled:

![](./resources/example_one.png)

Example with default configuration:

![](./resources/example_two.png)

## Usage

The texteditor takes 5 obligatory parameters and 4 optional parameters.

##### Obligatory parameters
- ```offset_X``` : integer - the offset from the left border of the pygame screen
- ```offset_y``` : integer - the offset from the top border of the pygame screen
- ```editor_width``` : integer - the width of texteditor
- ```editor_height``` : integer - the height of texteditor
- ```screen``` : pygame display surface - on which the texteditor is to be displayed

##### Optional Parameters with default values

- ```display_line_numbers``` - a boolean enabling showing line numbers
    > Default: ```False```
- ```style``` - a String setting the color scheme of editor and syntax highlighting
    > Default: ```'dark'```
- ```syntax_highlighting_python``` - a boolean enabling syntax highlighting for Python code
    > Default: ```False```
- ```font_size``` - an integer to set for the font size.
    > Default: ```16```

## Setup and configuration

##### Minimal texteditor setup example

```python
import pygame
from pygame_texteditor import TextEditor

# minimal pygame setup
pygame.init()
screen = pygame.display.set_mode((500, 600))
pygame.display.set_caption("Pygame")
pygame.display.get_surface().fill((200, 200, 200))  # background coloring

# Instantiation & customization of the text editor
TX = TextEditor(
    offset_x=50, offset_y=50, editor_width=500, editor_height=400, screen=pygame.display.get_surface()
)
TX.set_line_numbers(True)
TX.set_syntax_highlighting(True)
TX.set_font_size(18)

# TextEditor in the pygame-loop
while True:
    # INPUT - Mouse + Keyboard
    pygame_events = pygame.event.get()
    pressed_keys = pygame.key.get_pressed()
    mouse_x, mouse_y = pygame.mouse.get_pos()
    mouse_pressed = pygame.mouse.get_pressed()

    # displays editor functionality once per loop
    TX.display_editor(pygame_events, pressed_keys, mouse_x, mouse_y, mouse_pressed)
    pygame.display.flip()  # updates pygame window

```

##### Retrieving text from the editor

The editor offers the function `get_text_as_string()` to retrieve the entire text
as a String from the editor. Lines are separated by the new line character ```\n```.

The editor offers the function `get_text_as_list()` to retrieve the entire text as a list from the editor.
Each String-item in the list represents one line from the editor.

##### Removing text from the editor

The editor offers the function `clear_text()` to clear the editor of any text.

##### Inserting text into the editor

Inserting text can be done by using one of the two available functions:
1. With a list of strings in which each string represents one line, or
2. With a string which includes linebreak characters which get parsed.

```
set_text_from_list(["First line", "Second Line.", "Third Line."]
set_text_from_string("First line.\nSecond line.\nThird Line")
```

## Customization

#### Cursor mode

Cursor mode can either be `static` or `blinking` (=default).

```python
TX = TextEditor(...)
TX.set_cursor_mode("static")
TX.set_cursor_mode("blinking")
```

#### Key repetition speeds

While a key is being held, multiple key events are being triggered.
The delay of the first repetition as well as the interval between all sequential key triggers can be
customized by using the function `set_key_repetition(delay=300, intervall=30)`.

From the [official documentation](http://www.pygame.org/docs/ref/key.html#pygame.key.set_repeat):
> The delay parameter is the number of milliseconds before the first repeated pygame.KEYDOWN event will be sent.
> After that, another pygame.KEYDOWN event will be sent every interval milliseconds.


#### Font Customization

The editor uses a ttf file to set the font for the editor. By default, the Courier monospace font is used.

A custom font can be loaded with the following method, passing an *absolute* path:
- `set_font_from_ttf("X:\path\to\custom\font.ttf")`

DISCLAIMER: As the width of a letter (space) is only calculated once after setting the font_size, any fonts that are not monospace will lead to the editor not working correctly anymore, as it cannot be determined correctly between which letters the user clicked.

#### Font size

Font size can be customized with the command `set_font_size(size)` - the parameter is an integer
with the default value `16` to be able to reset it.

#### Line Numbers
Line numbers can be shown on the left side of the editor. Line numbers begin with 0 as is the Pythonian way.

Line numbers can be enabled and disabled with ```set_line_numbers(Boolean)```.


#### Syntax Highlighting

The editor comes with syntax highlighting for Python code. Tokenization is based on the ```pygment``` package.

Syntax highlighting can be enabled/disabled with ```set_syntax_coloring(boolean_value)```.

The syntax colors being used are also specified in the yml style file.


#### Color-scheme customization

The editor uses a yml file to set the color-scheme for the editor itself and for the syntax coloring.

Two styles are delivered with the editor, they can be activated respectively by:
- `set_colorscheme("dark")`
- `set_colorscheme("bright")`

A custom style can be loaded with the following method from a created yml file:
- `set_colorscheme_from_yaml("X:\path\to\custom\filename.yml")`

All keys must be present with values. Acceptable values are
RGB colors in the following format: ```(255, 255, 255)``` or ```255, 255, 255```.

The following keys are required in the ```stylename.yml``` file, syntax colors are only used if syntax
highlighting is enabled, but are still required to be included.

**Editor colors** (source: bright.yml)

- `codingBackgroundColor: (255, 255, 255)`
- `codingScrollBarBackgroundColor: (49, 50, 50)`
- `lineNumberColor: (255, 255, 255)`
- `lineNumberBackgroundColor: (60, 61, 61)`
- `textColor: (255, 255, 255)`
- `caretColor: (255, 255, 255)`

**Syntax colors** (source: bright.yml)

- `textColor_normal: (0, 255, 255)`
- `textColor_comments: (119, 115, 115)`
- `textColor_quotes: (227, 215, 115)`
- `textColor_operators: (237, 36, 36)`
- `textColor_keywords: (237, 36, 36)`
- `textColor_function: (50, 150, 36)`
- `textColor_builtin: (50, 50, 136)`

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pygame-texteditor",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "pygame,texteditor,text,editor",
    "author": "Victor Seifert",
    "author_email": "seifert.victor@web.de",
    "download_url": "https://files.pythonhosted.org/packages/4b/44/30a36cc464a69f2241549f5caf4f92d330c3906f5925b4a8a8447fb2f3e2/pygame_texteditor-0.7.3.tar.gz",
    "platform": null,
    "description": "# A WYSIWYG-texteditor based on pygame for pygame\n\n![PyPI](https://img.shields.io/pypi/v/pygame-texteditor?color=%233775A9&label=pypi%20package&style=plastic)\n![GitHub](https://img.shields.io/github/license/CribberSix/pygame-texteditor?style=plastic)\n\n## Introduction & examples\n\nThe text editor can be inserted into any existing pygame window.\nA minimal code example of it being activated within an existing pygame window can be found below.\n\nThe code editor comes with line numbers and syntax highlighting for python if enabled:\n\n![](./resources/example_one.png)\n\nExample with default configuration:\n\n![](./resources/example_two.png)\n\n## Usage\n\nThe texteditor takes 5 obligatory parameters and 4 optional parameters.\n\n##### Obligatory parameters\n- ```offset_X``` : integer - the offset from the left border of the pygame screen\n- ```offset_y``` : integer - the offset from the top border of the pygame screen\n- ```editor_width``` : integer - the width of texteditor\n- ```editor_height``` : integer - the height of texteditor\n- ```screen``` : pygame display surface - on which the texteditor is to be displayed\n\n##### Optional Parameters with default values\n\n- ```display_line_numbers``` - a boolean enabling showing line numbers\n    > Default: ```False```\n- ```style``` - a String setting the color scheme of editor and syntax highlighting\n    > Default: ```'dark'```\n- ```syntax_highlighting_python``` - a boolean enabling syntax highlighting for Python code\n    > Default: ```False```\n- ```font_size``` - an integer to set for the font size.\n    > Default: ```16```\n\n## Setup and configuration\n\n##### Minimal texteditor setup example\n\n```python\nimport pygame\nfrom pygame_texteditor import TextEditor\n\n# minimal pygame setup\npygame.init()\nscreen = pygame.display.set_mode((500, 600))\npygame.display.set_caption(\"Pygame\")\npygame.display.get_surface().fill((200, 200, 200))  # background coloring\n\n# Instantiation & customization of the text editor\nTX = TextEditor(\n    offset_x=50, offset_y=50, editor_width=500, editor_height=400, screen=pygame.display.get_surface()\n)\nTX.set_line_numbers(True)\nTX.set_syntax_highlighting(True)\nTX.set_font_size(18)\n\n# TextEditor in the pygame-loop\nwhile True:\n    # INPUT - Mouse + Keyboard\n    pygame_events = pygame.event.get()\n    pressed_keys = pygame.key.get_pressed()\n    mouse_x, mouse_y = pygame.mouse.get_pos()\n    mouse_pressed = pygame.mouse.get_pressed()\n\n    # displays editor functionality once per loop\n    TX.display_editor(pygame_events, pressed_keys, mouse_x, mouse_y, mouse_pressed)\n    pygame.display.flip()  # updates pygame window\n\n```\n\n##### Retrieving text from the editor\n\nThe editor offers the function `get_text_as_string()` to retrieve the entire text\nas a String from the editor. Lines are separated by the new line character ```\\n```.\n\nThe editor offers the function `get_text_as_list()` to retrieve the entire text as a list from the editor.\nEach String-item in the list represents one line from the editor.\n\n##### Removing text from the editor\n\nThe editor offers the function `clear_text()` to clear the editor of any text.\n\n##### Inserting text into the editor\n\nInserting text can be done by using one of the two available functions:\n1. With a list of strings in which each string represents one line, or\n2. With a string which includes linebreak characters which get parsed.\n\n```\nset_text_from_list([\"First line\", \"Second Line.\", \"Third Line.\"]\nset_text_from_string(\"First line.\\nSecond line.\\nThird Line\")\n```\n\n## Customization\n\n#### Cursor mode\n\nCursor mode can either be `static` or `blinking` (=default).\n\n```python\nTX = TextEditor(...)\nTX.set_cursor_mode(\"static\")\nTX.set_cursor_mode(\"blinking\")\n```\n\n#### Key repetition speeds\n\nWhile a key is being held, multiple key events are being triggered.\nThe delay of the first repetition as well as the interval between all sequential key triggers can be\ncustomized by using the function `set_key_repetition(delay=300, intervall=30)`.\n\nFrom the [official documentation](http://www.pygame.org/docs/ref/key.html#pygame.key.set_repeat):\n> The delay parameter is the number of milliseconds before the first repeated pygame.KEYDOWN event will be sent.\n> After that, another pygame.KEYDOWN event will be sent every interval milliseconds.\n\n\n#### Font Customization\n\nThe editor uses a ttf file to set the font for the editor. By default, the Courier monospace font is used.\n\nA custom font can be loaded with the following method, passing an *absolute* path:\n- `set_font_from_ttf(\"X:\\path\\to\\custom\\font.ttf\")`\n\nDISCLAIMER: As the width of a letter (space) is only calculated once after setting the font_size, any fonts that are not monospace will lead to the editor not working correctly anymore, as it cannot be determined correctly between which letters the user clicked.\n\n#### Font size\n\nFont size can be customized with the command `set_font_size(size)` - the parameter is an integer\nwith the default value `16` to be able to reset it.\n\n#### Line Numbers\nLine numbers can be shown on the left side of the editor. Line numbers begin with 0 as is the Pythonian way.\n\nLine numbers can be enabled and disabled with ```set_line_numbers(Boolean)```.\n\n\n#### Syntax Highlighting\n\nThe editor comes with syntax highlighting for Python code. Tokenization is based on the ```pygment``` package.\n\nSyntax highlighting can be enabled/disabled with ```set_syntax_coloring(boolean_value)```.\n\nThe syntax colors being used are also specified in the yml style file.\n\n\n#### Color-scheme customization\n\nThe editor uses a yml file to set the color-scheme for the editor itself and for the syntax coloring.\n\nTwo styles are delivered with the editor, they can be activated respectively by:\n- `set_colorscheme(\"dark\")`\n- `set_colorscheme(\"bright\")`\n\nA custom style can be loaded with the following method from a created yml file:\n- `set_colorscheme_from_yaml(\"X:\\path\\to\\custom\\filename.yml\")`\n\nAll keys must be present with values. Acceptable values are\nRGB colors in the following format: ```(255, 255, 255)``` or ```255, 255, 255```.\n\nThe following keys are required in the ```stylename.yml``` file, syntax colors are only used if syntax\nhighlighting is enabled, but are still required to be included.\n\n**Editor colors** (source: bright.yml)\n\n- `codingBackgroundColor: (255, 255, 255)`\n- `codingScrollBarBackgroundColor: (49, 50, 50)`\n- `lineNumberColor: (255, 255, 255)`\n- `lineNumberBackgroundColor: (60, 61, 61)`\n- `textColor: (255, 255, 255)`\n- `caretColor: (255, 255, 255)`\n\n**Syntax colors** (source: bright.yml)\n\n- `textColor_normal: (0, 255, 255)`\n- `textColor_comments: (119, 115, 115)`\n- `textColor_quotes: (227, 215, 115)`\n- `textColor_operators: (237, 36, 36)`\n- `textColor_keywords: (237, 36, 36)`\n- `textColor_function: (50, 150, 36)`\n- `textColor_builtin: (50, 50, 136)`\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A WYSIWYG-texteditor based on pygame.",
    "version": "0.7.3",
    "project_urls": null,
    "split_keywords": [
        "pygame",
        "texteditor",
        "text",
        "editor"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8dbd0b4f41fba996c40b74aae031846f1ce036a2480c3ae0f6b6669040e1b44e",
                "md5": "4744129ba4518382a1a449cae8760090",
                "sha256": "4f4336165b28cbb5c7ff75108a47b5d0876c77a9047a53959c21ccd364f9a9d6"
            },
            "downloads": -1,
            "filename": "pygame_texteditor-0.7.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4744129ba4518382a1a449cae8760090",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 56021,
            "upload_time": "2023-07-05T06:50:54",
            "upload_time_iso_8601": "2023-07-05T06:50:54.050130Z",
            "url": "https://files.pythonhosted.org/packages/8d/bd/0b4f41fba996c40b74aae031846f1ce036a2480c3ae0f6b6669040e1b44e/pygame_texteditor-0.7.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4b4430a36cc464a69f2241549f5caf4f92d330c3906f5925b4a8a8447fb2f3e2",
                "md5": "9928be053ef30aadafc5c83201a0d59e",
                "sha256": "d0070417296bd470a96496eaf9a1deb2cd7cc1adce604a63a4404f1b0134401f"
            },
            "downloads": -1,
            "filename": "pygame_texteditor-0.7.3.tar.gz",
            "has_sig": false,
            "md5_digest": "9928be053ef30aadafc5c83201a0d59e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 52836,
            "upload_time": "2023-07-05T06:50:55",
            "upload_time_iso_8601": "2023-07-05T06:50:55.390745Z",
            "url": "https://files.pythonhosted.org/packages/4b/44/30a36cc464a69f2241549f5caf4f92d330c3906f5925b4a8a8447fb2f3e2/pygame_texteditor-0.7.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-05 06:50:55",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pygame-texteditor"
}
        
Elapsed time: 0.08406s