2
# __init__.py (metagui)
4
"""A simplified GUI-writing module.
9
This module demonstrates a simplified approach to creating GUIs for
10
command-line programs. It's designed so _anyone_ can easily write their
11
own GUI, without having any programming experience.
13
It assumes your GUI is a direct frontend to one or more command-line programs,
14
with each command-line option having an associated GUI control widget. Several
15
kinds of widget are provided, for setting Filename, Color, Number or Font, or
16
for picking a Choice or Flag.
18
You probably know of a handful of command-line applications that would be
19
much better with a GUI, even a cheesy-looking Tkinter one. This module makes
20
it easy to create one.
25
Say, if you have a program that takes input and output filenames:
27
$ tovid -in movie.avi -out movie_encoded
29
then you can create GUI widgets for those options like this:
31
Filename('-in', "Input filename")
32
Filename('-out', "Output prefix")
34
These have the general format:
36
Control('-option', "Label", ...)
40
Control is a Control subclass, such as Filename, Choice, or Number,
41
describing what type of value is being controlled;
42
'option' is a command-line option (without the leading '-'),
43
whose value is set by the Control; and
44
"Label" is the text that should appear next to the GUI Control.
46
Other parameters include default value, help/tooltip text to show, allowable
47
values, and hints about how to draw the GUI control widget; they are specific
48
to the flavor of Control being used. Here's a sampling:
50
Choice Multiple-choice values
51
Color Color selection button
52
Filename Type or [Browse] a filename
53
FileList Add/remove/rearrange filename list
54
Flag Check box, yes or no
55
Font Font selection button
56
List Space-separated list
57
Number Number between A and B
60
For a full list of available Control subclasses and how to use them,
61
see libtovid/metagui/control.py.
66
First, give your Controls a place to live, in a Panel:
68
general = Panel("General",
69
Filename('-bgaudio', "Background audio file"),
70
Flag('-submenus', "Create submenus"),
71
Number('-menu-length', "Length of menu (seconds)", 0, 120)
74
This will create three GUI widgets in a Panel labeled "General": one for typing
75
or browsing to a filename, one for enabling or disabling submenus, and another
76
for setting menu length to a number between 0 and 120. You can nest panels
77
inside one another for grouping; sub-Panels have their own label and list of
78
Controls or sub-Panels.
80
Once you have a Panel, you can create an Application:
82
app = Application('todisc', [general])
84
This says your application will run the 'todisc' command-line program,
85
passing options set by the "General" panel. Now, create the GUI:
87
gui = GUI('MyGUI', [app])
90
This creates the GUI, draws all the widgets, and will run your command-line
91
program at the push of a button.
94
CREATE A MULTI-PANEL GUI
96
If your program has a lot of options, one panel may not be enough to hold them
97
all without looking cluttered, so you may break them down into multiple Panels,
98
which will be shown in the GUI as tabs that you can switch between. Create
101
thumbs = Panel("Thumbnails",
102
Color('-thumb-mist-color', ...),
106
Font('-menu-font', ...),
107
Number('-menu-fontsize', ...)
110
then, create the Application and GUI:
112
todisc = Application('todisc', [thumbs, text])
113
gui = GUI('MyGUI', [todisc])
116
If multiple panels are given to Application, a tabbed interface is created,
117
with one tab for each panel.
120
CREATE A MULTI-APPLICATION GUI
122
If your GUI needs to be able to run several different command-line programs,
123
you can create a multi-application GUI. Create panels for each application,
124
then create the applications:
126
todisc = Application('todisc', [todisc_panel1, todisc_panel2])
127
tovid = Application('tovid', [tovid_panel1, tovid_panel2])
131
gui = GUI('MultiGUI', [todisc, tovid])
134
See the apps/ directory for example GUIs.
137
# Export everything from support, control, and gui modules
138
# (Open to suggestion about more elegant ways to do this...)
139
from support import *
140
from control import *
142
from support import __all__ as all_support
143
from control import __all__ as all_control
144
from gui import __all__ as all_gui
152
'widget'] + all_support + all_control + all_gui