# PascalABC::GraphABC for Python

A simple, education-oriented graphics module for Python --- a wrapper around Raylib
Inspired by [GraphABC module from PascalABC.NET](https://www.pascalabc.net/downloads/pabcnethelp/topics/PABCUnits/GraphABC/index.html)
This package is neither performant nor feature-rich, nor is it supposed to be. Please consider
using [Raylib](https://www.raylib.com) if your requirements no longer fit this package. Or maybe
try [rlzero](https://github.com/electronstudio/rlzero) from the author of `raylib-python-cffi`.
## Installation
*Your IDE should have already set up `pip` and `python` for you. If not, try setting up `.venv` as shown below*
First make sure you have the latest pip installed:
pip install --upgrade pip
Then install this package
pip install graphabc
[raylib-python-cffi](https://pypi.org/project/raylib/) should be installed automatically as a
dependency. Please consult [raylib-python-cffi troubleshooting guide](https://github.com/electronstudio/raylib-python-cffi?tab=readme-ov-file#problems)
if you have problems with installation of raylib bindings.
#### Installation --- setting up `.venv`
```
python -m venv .venv
. ./.venv/bin/activate
```
## Example code
(Check out [/test](test) for more examples)
```python
from graphabc import *
R = 10.
def draw(x, y):
global R
R *= 1.05
SetColor(clRandom())
Circle(x, y, int(R))
def click_cb(x, y, mb):
if mb != MB_Left:
return
draw(x, y)
def move_cb(x, y, mbm):
if not mbm & MBM_Left:
return
draw(x, y)
SetOnMouseDown(click_cb)
SetOnMouseMove(move_cb)
```
# Why does this exist?
There are already a plethora of well-known, production-quality graphics packages for Python:
- [raylib-python-cffi](https://github.com/electronstudio/raylib-python-cffi)
- [tkinter](https://docs.python.org/3/library/tkinter.html)
- [turtle](https://docs.python.org/3/library/turtle.html)
- [pyglet](https://github.com/pyglet/pyglet)
- [arcade](https://github.com/pythonarcade/arcade)
- [pygame](https://github.com/pygame/pygame)
- [pillow](https://github.com/python-pillow/Pillow)
- [kivy](https://github.com/kivy/kivy)
- [wxPython](https://github.com/wxWidgets/Phoenix)
- [matplotlib](https://github.com/matplotlib/matplotlib)
- [graphics.py](https://mcsp.wartburg.edu/zelle/python/graphics.py) (apparently EoL)
These are all amazing projects with vast adoption, extensive featuresets, and/or good performace. Please
consider using them for your project if you need a robust graphics dependency. However, they might
not be the best choice for students just starting to learn Python for the following reasons:
- **Boilerplate**: Making a project in these libraries requires writing a varying amount of
boilerplate code, which might make students anxious about not understanding the code they are
writing.
- **Ease of debugging**: Some of these packages, especially `tkinter` and `turtle`, are not
well-suited for debugging: in my experience, debugging `turtle` commands is pretty much
impossible --- some technical difficulties inevitably arise.
- **Object orientation**: Object orientation is a somewhat advanced concept, not available for
students just starting out their Python course.
- **Being a framework**: see "boilerplate" and "object orientation" above.
[PascalABC.NET](https://www.pascalabc.net/), an educational programming environment originating in
[Russia](https://en.wikipedia.org/wiki/Russia) and widely used in Russian schools, is a wonderful
choice as the first programming language of a student. This environment provides
the [GraphABC](https://www.pascalabc.net/downloads/pabcnethelp/topics/PABCUnits/GraphABC/index.html) module,
which is simple, easy to understand, and debuggable. Thus this project was created as an adaptation
of GraphABC for the more popular Python programming language.
### Target audience
This package is meant for students and tutors of entry-level CompSci/"Informatics"
# API differences
API is closely resembling that of [GraphABC unit of PascalABC programming language/runtime environment](https://pascalabc.net/downloads/pabcnethelp/topics/PABCUnits/GraphABC/index.html)
API alterations wrt the original library:
- `GraphABCException` exception type dropped
- `RedrawProc` callback dropped
- `DrawInBuffer` mode dropped --- buffer is always used
- `PutPixel` dropped (alias)
- `FillRect` dropped (alias)
- `TextOut` of `int`/`float` types not supported, use type casting / string interpolation
- `DrawTextCentered` of `int`/`float` types not supported, use type casting / string interpolation
- Global function `Pen` renamed to `GetPen`. `Pen` now refers to the type.
- New function `SetPen` allows to setup and use a number of presets
- Functions `PenColor`, `PenWidth`, and `PenStyle` are renamed to `GetPenColor`, `GetPenWidth`, and `GetPenStyle` respectively
- `Pen::NETPen` and `Pen::Mode` dropped
- Global function `Brush` renamed to `GetBrush`. `Brush` now refers to the type.
- New function `SetBrush` allows to setup and use a number of presets
- Functions `BrushColor`, `BrushStyle`, `BrushHatch`, `HatchBrushBackgroundColor`, and `GradientBrushSecondColor` are renamed to `GetBrushColor`, `GetBrushStyle`, `GetBrushHatch`, `GetHatchBrushBackgroundColor`, and `GetGradientBrushSecondColor` respectively
- `Brush::NETBrush` dropped
- Added new brush style `bsPicture`
- Added new brush style `bsReplace` which ignores alpha channel and replaces a region with specified brush instead
- Global function `Font` renamed to `GetFont`. `Font` now refers to the type.
- `SetFontName()` is dropped --- instance new fonts instead using `Font('<path>/<name>')`
- `Font::Name` is read-only
- Functions `FontName`, `FontColor`, `FontSize`, and `FontStyle` are renamed to `GetFontName`, `GetFontColor`, `GetFontSize`, and `GetFontStyle` respectively
- `Font::NETFont` dropped
- `Picture::Create` renamed to `Picture::__init__()`, and only supports loading from file
- All pictures have an alpha channel, thus the `Transparent`/`TransparentColor` properties have been dropped
- `Picture` now has properties `X`, `Y` along with `Width`, `Height`. They are used for selecting a part of original picture
- Drawing on pictures is not supported. Use Raylib if you need to draw on pictures.
- Instead of setting event callbacks directly, use `SetOn*()`
- `OnMouseDown()`, `OnMouseUp()`, `OnMouseMove()` pass virtual codes instead of 0/1/2
- `OnKeyPress()` not supported
## Unimplemented (planned) functionality
If some functionality is denoted as "dropped" above in the list of alterations, there are no plans
of implementing it. Still, some other functionality isn't yet supported and might be added later:
- Freehand shapes (`*ClosedCurve`, `Curve`, `*Polygon`, `Polyline`)
- `FloodFill`
- Any text / font functions
- Pen styles & width
- Brush styles
- Custom window coordinates
# Warning: Bad code inside
The original `PascalABC::GraphABC` API is built atop the Win32 API or a similar retained-mode
graphics toolset. Raylib, however, prefers immediate-mode drawing to the window instead. This forced
a rather awkward approach of using threading for connecting the two together.
Also, not all original functionality has a one-to-one mapping in Raylib --- thus some of it has to
be implemented manually.
Raw data
{
"_id": null,
"home_page": "https://github.com/Toideng/python-graphabc",
"name": "graphabc",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8.1",
"maintainer_email": null,
"keywords": "pascal, pascalabc, pascalabc.net, graphics, education",
"author": "Toideng",
"author_email": "<toideng@toideng.com>",
"download_url": "https://files.pythonhosted.org/packages/c8/a3/f3f728cd55ab38699a388a4fb5cfd5aa95935905bdd10b432a98f9137798/graphabc-0.0.6.tar.gz",
"platform": null,
"description": "# PascalABC::GraphABC for Python\n\n\n\nA simple, education-oriented graphics module for Python --- a wrapper around Raylib\n\nInspired by [GraphABC module from PascalABC.NET](https://www.pascalabc.net/downloads/pabcnethelp/topics/PABCUnits/GraphABC/index.html)\n\nThis package is neither performant nor feature-rich, nor is it supposed to be. Please consider\nusing [Raylib](https://www.raylib.com) if your requirements no longer fit this package. Or maybe\ntry [rlzero](https://github.com/electronstudio/rlzero) from the author of `raylib-python-cffi`.\n\n\n\n## Installation\n\n*Your IDE should have already set up `pip` and `python` for you. If not, try setting up `.venv` as shown below*\n\nFirst make sure you have the latest pip installed:\n\n pip install --upgrade pip\n\nThen install this package\n\n pip install graphabc\n\n[raylib-python-cffi](https://pypi.org/project/raylib/) should be installed automatically as a\ndependency. Please consult [raylib-python-cffi troubleshooting guide](https://github.com/electronstudio/raylib-python-cffi?tab=readme-ov-file#problems)\nif you have problems with installation of raylib bindings.\n\n#### Installation --- setting up `.venv`\n\n```\npython -m venv .venv\n. ./.venv/bin/activate\n```\n\n\n\n## Example code\n\n(Check out [/test](test) for more examples)\n\n```python\nfrom graphabc import *\n\nR = 10.\n\ndef draw(x, y):\n\tglobal R\n\tR *= 1.05\n\tSetColor(clRandom())\n\tCircle(x, y, int(R))\n\ndef click_cb(x, y, mb):\n\tif mb != MB_Left:\n\t\treturn\n\tdraw(x, y)\n\ndef move_cb(x, y, mbm):\n\tif not mbm & MBM_Left:\n\t\treturn\n\tdraw(x, y)\n\nSetOnMouseDown(click_cb)\nSetOnMouseMove(move_cb)\n```\n\n\n\n# Why does this exist?\n\nThere are already a plethora of well-known, production-quality graphics packages for Python:\n- [raylib-python-cffi](https://github.com/electronstudio/raylib-python-cffi)\n- [tkinter](https://docs.python.org/3/library/tkinter.html)\n- [turtle](https://docs.python.org/3/library/turtle.html)\n- [pyglet](https://github.com/pyglet/pyglet)\n- [arcade](https://github.com/pythonarcade/arcade)\n- [pygame](https://github.com/pygame/pygame)\n- [pillow](https://github.com/python-pillow/Pillow)\n- [kivy](https://github.com/kivy/kivy)\n- [wxPython](https://github.com/wxWidgets/Phoenix)\n- [matplotlib](https://github.com/matplotlib/matplotlib)\n- [graphics.py](https://mcsp.wartburg.edu/zelle/python/graphics.py) (apparently EoL)\n\nThese are all amazing projects with vast adoption, extensive featuresets, and/or good performace. Please\nconsider using them for your project if you need a robust graphics dependency. However, they might\nnot be the best choice for students just starting to learn Python for the following reasons:\n\n- **Boilerplate**: Making a project in these libraries requires writing a varying amount of\n boilerplate code, which might make students anxious about not understanding the code they are\n writing.\n- **Ease of debugging**: Some of these packages, especially `tkinter` and `turtle`, are not\n well-suited for debugging: in my experience, debugging `turtle` commands is pretty much\n impossible --- some technical difficulties inevitably arise.\n- **Object orientation**: Object orientation is a somewhat advanced concept, not available for\n students just starting out their Python course.\n- **Being a framework**: see \"boilerplate\" and \"object orientation\" above.\n\n[PascalABC.NET](https://www.pascalabc.net/), an educational programming environment originating in\n[Russia](https://en.wikipedia.org/wiki/Russia) and widely used in Russian schools, is a wonderful\nchoice as the first programming language of a student. This environment provides\nthe [GraphABC](https://www.pascalabc.net/downloads/pabcnethelp/topics/PABCUnits/GraphABC/index.html) module,\nwhich is simple, easy to understand, and debuggable. Thus this project was created as an adaptation\nof GraphABC for the more popular Python programming language.\n\n### Target audience\n\nThis package is meant for students and tutors of entry-level CompSci/\"Informatics\"\n\n\n\n# API differences\n\nAPI is closely resembling that of [GraphABC unit of PascalABC programming language/runtime environment](https://pascalabc.net/downloads/pabcnethelp/topics/PABCUnits/GraphABC/index.html)\n\nAPI alterations wrt the original library:\n\n- `GraphABCException` exception type dropped\n- `RedrawProc` callback dropped\n- `DrawInBuffer` mode dropped --- buffer is always used\n\n- `PutPixel` dropped (alias)\n- `FillRect` dropped (alias)\n- `TextOut` of `int`/`float` types not supported, use type casting / string interpolation\n- `DrawTextCentered` of `int`/`float` types not supported, use type casting / string interpolation\n\n- Global function `Pen` renamed to `GetPen`. `Pen` now refers to the type.\n- New function `SetPen` allows to setup and use a number of presets\n- Functions `PenColor`, `PenWidth`, and `PenStyle` are renamed to `GetPenColor`, `GetPenWidth`, and `GetPenStyle` respectively\n- `Pen::NETPen` and `Pen::Mode` dropped\n\n- Global function `Brush` renamed to `GetBrush`. `Brush` now refers to the type.\n- New function `SetBrush` allows to setup and use a number of presets\n- Functions `BrushColor`, `BrushStyle`, `BrushHatch`, `HatchBrushBackgroundColor`, and `GradientBrushSecondColor` are renamed to `GetBrushColor`, `GetBrushStyle`, `GetBrushHatch`, `GetHatchBrushBackgroundColor`, and `GetGradientBrushSecondColor` respectively\n- `Brush::NETBrush` dropped\n- Added new brush style `bsPicture`\n- Added new brush style `bsReplace` which ignores alpha channel and replaces a region with specified brush instead\n\n- Global function `Font` renamed to `GetFont`. `Font` now refers to the type.\n- `SetFontName()` is dropped --- instance new fonts instead using `Font('<path>/<name>')`\n- `Font::Name` is read-only\n- Functions `FontName`, `FontColor`, `FontSize`, and `FontStyle` are renamed to `GetFontName`, `GetFontColor`, `GetFontSize`, and `GetFontStyle` respectively\n- `Font::NETFont` dropped\n\n- `Picture::Create` renamed to `Picture::__init__()`, and only supports loading from file\n- All pictures have an alpha channel, thus the `Transparent`/`TransparentColor` properties have been dropped\n- `Picture` now has properties `X`, `Y` along with `Width`, `Height`. They are used for selecting a part of original picture\n- Drawing on pictures is not supported. Use Raylib if you need to draw on pictures.\n\n- Instead of setting event callbacks directly, use `SetOn*()`\n- `OnMouseDown()`, `OnMouseUp()`, `OnMouseMove()` pass virtual codes instead of 0/1/2\n- `OnKeyPress()` not supported\n\n\n\n## Unimplemented (planned) functionality\n\nIf some functionality is denoted as \"dropped\" above in the list of alterations, there are no plans\nof implementing it. Still, some other functionality isn't yet supported and might be added later:\n\n- Freehand shapes (`*ClosedCurve`, `Curve`, `*Polygon`, `Polyline`)\n- `FloodFill`\n- Any text / font functions\n- Pen styles & width\n- Brush styles\n- Custom window coordinates\n\n\n\n# Warning: Bad code inside\n\nThe original `PascalABC::GraphABC` API is built atop the Win32 API or a similar retained-mode\ngraphics toolset. Raylib, however, prefers immediate-mode drawing to the window instead. This forced\na rather awkward approach of using threading for connecting the two together.\n\nAlso, not all original functionality has a one-to-one mapping in Raylib --- thus some of it has to\nbe implemented manually.\n",
"bugtrack_url": null,
"license": "LGPLv3+",
"summary": "PascalABC GraphABC module in Python",
"version": "0.0.6",
"project_urls": {
"Homepage": "https://github.com/Toideng/python-graphabc"
},
"split_keywords": [
"pascal",
" pascalabc",
" pascalabc.net",
" graphics",
" education"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bfe7b07f4f9080b1b50ff768061e4c053cf5d9bfcf7329afbb0fd741821a461b",
"md5": "63c0e93a94204b06b6c46d2607a0333e",
"sha256": "4a8f62d68f25c803881a5d45b1991f5171b27408ea2070366ceeed6dc3be3547"
},
"downloads": -1,
"filename": "graphabc-0.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "63c0e93a94204b06b6c46d2607a0333e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.1",
"size": 28043,
"upload_time": "2025-03-28T22:48:50",
"upload_time_iso_8601": "2025-03-28T22:48:50.279113Z",
"url": "https://files.pythonhosted.org/packages/bf/e7/b07f4f9080b1b50ff768061e4c053cf5d9bfcf7329afbb0fd741821a461b/graphabc-0.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c8a3f3f728cd55ab38699a388a4fb5cfd5aa95935905bdd10b432a98f9137798",
"md5": "8d660bfb48c473eb31982b82c312366f",
"sha256": "ee524abc7db5998cb4d82d70bf7379c4fe2b8b34ca382a6a0cb3684c057ae345"
},
"downloads": -1,
"filename": "graphabc-0.0.6.tar.gz",
"has_sig": false,
"md5_digest": "8d660bfb48c473eb31982b82c312366f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.1",
"size": 25733,
"upload_time": "2025-03-28T22:48:52",
"upload_time_iso_8601": "2025-03-28T22:48:52.236878Z",
"url": "https://files.pythonhosted.org/packages/c8/a3/f3f728cd55ab38699a388a4fb5cfd5aa95935905bdd10b432a98f9137798/graphabc-0.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-28 22:48:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Toideng",
"github_project": "python-graphabc",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "graphabc"
}