New GUI support
So you want to make your own widgets, eh?
You can look at this guide!
Ideas
There are plenty of ideas:
Directory tree
Editable list
etc...
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:
Color scheme, including auto color
Widgets
Startup
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:
__init__
: Modify args and kwds to modify the parent option and take out the specific styles (w_styles
keyword). Modify the "parent" option (specified byParent_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.Parent_ArgName (attribute): What to describe this? Read the
__init__
function above.Frame (attribute): See the
__init__
function above._Frame (attribute): It's the class for the Frame attribute. Whatever a class or a function, but don't put () after it, okay? You should be laughed at if you do that. For example this is not valid:
_Frame = something() << that "()"
Styles (attribute): Widget's custom flags.
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:
How it works
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.
What else?
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.
Last updated