libtextworker 0.1.4
Cross-platform, free and open library for Python projects
|
So you want to make your own widgets, eh?
You can look at this guide!
There are plenty of ideas:
The percentage of a successful widget depends on the writer's skill, and the power of the target toolkit.
Normally a GUI support in libtextworker has:
Look for the libtextworker.interface.base
module first, then your toolkit support in libtextworker.interface
. Can you see your idea there?
Widgets inside libtextworker.interface.base
are intended to help other people implementing the widget in their desired GUI as a skeleton, and therefore is recommended.
The WidgetBase
class is used as a base for every other GUI classes here, has the following:
Parent_ArgName
) will lead to the actual widget to be placed in a frame/panel object (or whatever else), which is made as the Frame attribute. Returns the modified parementers._Frame = something() << that "()"
WidgetBase.__init__ is perfect now, you don't need to overwrite it.
To make a new flags class: Import Flag, auto from enum
module, create a Flag-derived _FLAGS class, with auto() instances named <widget_shortname>_<widget_option>.
If you want to create a skeleton, it's fine. Please check out our skeletons to see what you need to do (at least).
Create a new folder with your toolkit name (e.g pyqt5) in libtextworker.interface
. Don't forget to make __init__.py!
This is the skeleton for a GUI class:
In the code above, AW_FLAGS
is an enum.Flag-derived class with AW_FLAG*
variable as the flags for "AWonderfulIdea" widget.
AWonderfulThing: The base skeleton for a widget. Default styles and actions. Don't need to derive WidgetBase.__init__.
AWonderfulIdea: Derived from a GUI object and WidgetBase, when called it will ask WidgetBase to put itself in a frame, class defined by _Frame property. WidgetBase.__init__ gets args
and kwds
, get styles passed by the "w_styles" kwds keyword (default is the Styles attribute), put the widget in a frame (if appalicable), remove the parent widget option from args/kwds, and return modified items.
Remember our flags? It's time to use them: all flags are stored in self.Styles, so just check if the desired flag is here:
Even the widget you make has its flags inherited from its parent too, you can make equaliment to them by making a dictionary[your_flags, toolkit_flags], make a new styles
keyword (that is an enum.auto
object) by checking if any of your_flags
is in self.Styles.