Creating a custom widget - Part 1
Creating a custom widget is really easy. In part one we will create the basics and build on it for the next tutorials
Start by creating an empty python file call it widget1.py. Now open it in your python editor of choice. Please note the IDLE and possibly other editors has problems running uxPython programs.
Now put the following code:
This will import the base classes and utilities you need.
Next create a class named uMyWidget that inherits from uBase. Take note of the constructor syntax, it's the same with all widgets so you can just copy and paste.
The above can be used as it is now. But it won't display anything, since there is no render method. The render method in uxPython is called renderctx that takes a cairo context to draw to.
In the below code we just create a rectangle the same size as the widget and fill it with black. Cairo is powerful 2D library so the kind of things you can do is almost limitless. see cairographics.org for samples and documentation
Putting it all together we have our first widget!Now run it using a simple main script as follows: runner.py; Note that you can put both in one file, there is no restriction preventing that but it is recommended.
And that's it for now. In part 2 of this tutorial we explore using styles and layout managers.