Setup Edit

The current metagui module is installed along with tovid. See Installing tovid for instructions.

After installing, run python and import the metagui module:

$ python
Python 2.5 (r25:51908, Feb 19 2007, 14:25:53)
>>> from libtovid.metagui import *

If this works, you are ready to create your own GUIs.

Create a GUI Edit

Here is a simple GUI for tovid, with controls for input and output files, and a checkbox to enable ffmpeg encoding:

from libtovid.metagui import *

panel = Panel("Main",
    Filename("-in", "Video to encode"),
    Filename("-out", "Output name"),
    Flag("-ffmpeg", "Encode with ffmpeg")
app = Application("tovid", [panel])
gui = GUI("tovid GUI", [app])

Save this as and execute it with:

$ python

Here's a screenshot of the resulting GUI:

Tovid metagui example1

Breaking it down:

panel = Panel("Main",
    Filename("-in", "Video to encode"),
    Filename("-out", "Output name"),
    Flag("-ffmpeg", "Encode with ffmpeg")

This creates a Panel named "Main", with three GUI control widgets. The "Filename" control has a text entry box and "browse" button for setting a filename; the "Flag" control is a checkbox that can be checked or unchecked.

The next line creates an application that runs the command-line program "tovid", with options set by the widgets in "panel":

app = Application("tovid", [panel])

Then, the GUI is created, with "app" as the only application:

gui = GUI("tovid GUI", [app])

Finally, the GUI is run:

That's all there is to it! Most of the complexity is defining the controls associated with each command-line option. This is discussed in more detail in the next section.

Controls Edit

Say, if you have a program that takes input and output filenames:

$ tovid -in movie.avi -out movie_encoded

then you can create GUI widgets for those options like this:

Filename("-in", "Input filename")
Filename("-out", "Output prefix")

These have the general format:

Control("-option", "Label", ...)

where "-option" is a command-line option, Control is a Control subclass, such as Filename, Choice, or Number, describing what type of value the option sets, and "Label" is the text that should appear next to the GUI widget that controls the option's value.

Other parameters include default value, help/tooltip text to show, allowable values, and hints about how to draw the GUI control widget; they are specific to the flavor of Control being used. Here is a partial list of Controls:

  • Choice: Multiple-choice values
  • Color: Color selection button
  • Filename: Type or [Browse] a filename
  • FileList: Add/remove/rearrange filename list
  • Flag: Check box, yes or no
  • Font: Font selection button
  • List: Space-separated list
  • Number: Number between A and B
  • Text: Plain old text

For a complete list, see

Multi-panel GUI Edit

If your program has a lot of options, one panel may not be enough to hold them all without looking cluttered, so you may break them down into multiple Panels, which will be shown in the GUI as tabs that you can switch between. Create Panels like this:

thumbs = Panel("Thumbnails",
    Color('thumb-mist-color', ...),
    Text('wave', ...)
text = Panel("Text and Font",
    Font('menu-font', ...),
    Number('menu-fontsize', ...)

then, create the Application and GUI:

todisc = Application('todisc', [thumbs, text])
gui = GUI('MyGUI', [todisc])

With multiple panels, a tabbed interface is created, with one tab for each panel.

Multi-application GUI Edit

If your GUI needs to be able to run several different command-line programs, you can create a multi-application GUI. Create panels for each application, then create the applications:

todisc = Application('todisc', [todisc_panel1, todisc_panel2])
tovid = Application('tovid', [tovid_panel1, tovid_panel2])

and then the GUI:

gui = GUI('MultiGUI', [todisc, tovid])

Multi-application GUIs include a menu for displaying or hiding each available application, and each application has its own "Run" button.

Community content is available under CC-BY-SA unless otherwise noted.