From Audacity Wiki
Jump to: navigation, search
This page is about the class of that name in Audacity that can make creating dialogs easier.


Earlier versions of Audacity ended up with very turgid code for creating and using dialogs and mapping the widget controls to program variables. ShuttleGui makes that code much shorter and more readable. There are plans to use ShuttleGui more widely in Audacity. The intention is also that classes derived from 'Shuttle' can be used in many places where we need to take simple variables from one place to another, for example from GUI to program variables, to preference variables to command line parameters.

Use in Preferences

Shuttle GUI encourages a style of programming in which one function creates the GUI and also (with different options set) carries information from the GUI to component variables or from component variables to the GUI.

  • In preferences code the one function carries variables to/from the preferences store from/to the GUI.
  • In effects code the intention is that (in time) the handling of command line parameters for effects, which are just parameter settings, will be handled in the same way.

The example below shows some typical use of ShuttleGui. Whilst the braces '{', '}' and indenting are not strictly necessary, they help show the structure of the dialog and help to ensure when coding ShuttleGui that calls are paired when necessary. In the following S is of class ShuttleGui.

        mPlay = S.Id(PlayID).AddChoice(_("&Device") + wxString(wxT(":")),


  • The normal spacing between items in a grid sizer is 5 pixels. Use S.SetBorder(3) for closer spacing and S.SetBorder(5) to restore to normal spacing.
  • S.AddSpace( 20,0 ) can be used to add 20 pixels of x space between items in a horizontal layout. It's a bit of a hack though, and plans are to improve ShuttleGui so that sizing proportions become easy enough to use that quick hacks like that aren't needed anymore.
  • Choice selectors may end up bigger than you would like if the choices in them have short text. After creating them using pSomeChoice = S.Id(...).TieChoice(...), you can fix this using: pSomeChoice->SetSizeHints( 100,-1). The first value is the desired x size (default is 180) the second value is the desired y choice (-1 means use default).
  • You can add a control that is not directly supported by ShuttleGui using S.AddWindow( pYourControl ).

Questions about how to achieve specific results with ShuttleGui can be left here.