PascalABC GraphABC module in Python
Project description
PascalABC::GraphABC for Python
A simple, education-oriented graphics module for Python --- a wrapper around Raylib
Inspired by GraphABC module from PascalABC.NET
This package is neither performant nor feature-rich, nor is it supposed to be. Please consider
using Raylib if your requirements no longer fit this package. Or maybe
try 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 should be installed automatically as a dependency. Please consult raylib-python-cffi troubleshooting guide 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 for more examples)
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
- tkinter
- turtle
- pyglet
- arcade
- pygame
- pillow
- kivy
- wxPython
- matplotlib
- 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
tkinterandturtle, are not well-suited for debugging: in my experience, debuggingturtlecommands 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, an educational programming environment originating in Russia and widely used in Russian schools, is a wonderful choice as the first programming language of a student. This environment provides the GraphABC 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
API alterations wrt the original library:
-
GraphABCExceptionexception type dropped -
RedrawProccallback dropped -
DrawInBuffermode dropped --- buffer is always used -
PutPixeldropped (alias) -
FillRectdropped (alias) -
TextOutofint/floattypes not supported, use type casting / string interpolation -
DrawTextCenteredofint/floattypes not supported, use type casting / string interpolation -
Global function
Penrenamed toGetPen.Pennow refers to the type. -
New function
SetPenallows to setup and use a number of presets -
Functions
PenColor,PenWidth, andPenStyleare renamed toGetPenColor,GetPenWidth, andGetPenStylerespectively -
Pen::NETPenandPen::Modedropped -
Global function
Brushrenamed toGetBrush.Brushnow refers to the type. -
New function
SetBrushallows to setup and use a number of presets -
Functions
BrushColor,BrushStyle,BrushHatch,HatchBrushBackgroundColor, andGradientBrushSecondColorare renamed toGetBrushColor,GetBrushStyle,GetBrushHatch,GetHatchBrushBackgroundColor, andGetGradientBrushSecondColorrespectively -
Brush::NETBrushdropped -
Added new brush style
bsPicture -
Added new brush style
bsReplacewhich ignores alpha channel and replaces a region with specified brush instead -
Global function
Fontrenamed toGetFont.Fontnow refers to the type. -
SetFontName()is dropped --- instance new fonts instead usingFont('<path>/<name>') -
Font::Nameis read-only -
Functions
FontName,FontColor,FontSize, andFontStyleare renamed toGetFontName,GetFontColor,GetFontSize, andGetFontStylerespectively -
Font::NETFontdropped -
Picture::Createrenamed toPicture::__init__(), and only supports loading from file -
All pictures have an alpha channel, thus the
Transparent/TransparentColorproperties have been dropped -
Picturenow has propertiesX,Yalong withWidth,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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphabc-0.0.5.tar.gz.
File metadata
- Download URL: graphabc-0.0.5.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41543a299c4993e378d7ca88df34eaa2cbbe99b2add91fa8cbb4cba2b36307f0
|
|
| MD5 |
03b33d44e4ddfaacada03fe1e66cca67
|
|
| BLAKE2b-256 |
f5b851db1e8ac2d21943f7ce10a125be7883e2cfdc6cd246a084aaede3bad4b1
|
File details
Details for the file graphabc-0.0.5-py3-none-any.whl.
File metadata
- Download URL: graphabc-0.0.5-py3-none-any.whl
- Upload date:
- Size: 25.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b170ec2dd22d8be2122d45c452975c4948441a39097f5db7c99a14993e04199
|
|
| MD5 |
52db3cac2859c737a871bd83c3e7e226
|
|
| BLAKE2b-256 |
98fa1198991228f62c54124c0d54c8e518b5d49d3f670d0764c9681406d47e9a
|