Using the source code

There are a lot of options to control the source code generation process. They are bundled in the Application page of the Properties window (see Figure 3.6, “Project Properties - Application settings”). Let's talk about three of those options -Single file, Separate file for each class and Overwrite existing sources.

The first two options triggers wxGlade to generate one file with all classes inside or multiple files - one per class/widget. The Single fileoption includes source and header file for C++ certainly.

The third option Overwrite existing sources is just about control - Full control by wxGlade and Shared control. It separated the two ways to work with wxGlade.

Full control by wxGlade

If Overwrite existing sources is set, wxGlade will re-generated all source files and drop potential manual changes. You've to include the generated source files and use derived classes for implementing changes.

The files written by wxGlade are consistent always. Also if e.g. classes or attributes are renamed. Rewriting the whole files is less error-prone in comparison with the section called “Shared control”. That is the advantages of this method.

This method is the recommended one.

Shared control

Manual changes in the source files won't be overwritten if Overwrite existing sources isn't set. You can safely edit the source code of the generated class. This is because wxGlade marks the untouchable code with the special comments begin wxGlade and end wxGlade. So you can edit all you need outside these two tags. When you make changes in your forms, a new code generation will not modify the user code. wxGlade is applying most of the changes but not all changes. Especially renamed classes and attributes need additional attention.

Note

Overwriting multiple files is not recommended as well as overwriting of files with percent character (%) inside is not supported.

Note

This feature is deprecated now und will be removed within the next releases.

Output path and filenames

Output path specifies the name of the output file for Single file projects or the output directory for multi-file projects (Separate file for each class). The filename has to include the appropriate suffix of the programming language always. An exception is the Output path for Single file C++ projects. Filename don't contains the filename extension now. The extension for C++ source and header files will be appended later automatically.

Automatically created wxApp instance

wxGlade can create an additional code to start an instance of projects Top window.

There are two types of application start code:

  • simplified application start code

  • detailed application start code

The application start code generation is controlled by three properties:

  1. Name

  2. Class

  3. Top window

Those properties are explained in the section called “Application Properties”. Different combinations of those attributes generated different application start code. The table below shows the type of application start code resulting from different combinations of the three properties. The Enable gettext support property just triggers i18n-enabled source code.

Table 2.1. Interaction between properties to generate different types of start code

NameClassTop windowType of application start code to generate
not selectednot selectednot selectednot generated
selectednot selectednot selectednot generated
not selectedselectednot selectednot generated
selectedselectednot selectednot generated
selectednot selectedselectedsimplified start code
not selectedselectedselectednot generated
selectedselectedselecteddetailed start code

The application start code of a multi-file project will be recreated every time the code generation is running.

In opposition the application start code of single-file projects will not updated if the name of the Top window has changed and Overwrite existing sources is not set.

Example 2.2. Detailed application start code in Perl

package MyApp;
use base qw(Wx::App);
use strict;
sub OnInit {
        my( $self ) = shift;
        Wx::InitAllImageHandlers();
        my $frame_1 = MyFrame->new();
        $self->SetTopWindow($frame_1);
        $frame_1->Show(1);
        return 1;
}
# end of class MyApp
package main;
unless(caller){
        my $local = Wx::Locale->new("English", "en", "en"); # replace with ??
        $local->AddCatalog("app"); # replace with the appropriate catalog name
        my $app = MyApp->new();
        $app->MainLoop();
}


Example 2.3. Simplified application start code in Perl

package main;
unless(caller){
        my $local = Wx::Locale->new("English", "en", "en"); # replace with ??
        $local->AddCatalog("PlOgg1_app"); # replace with the appropriate catalog name
        local *Wx::App::OnInit = sub{1};
        my $PlOgg1_app = Wx::App->new();
        Wx::InitAllImageHandlers();
        my $Mp3_To_Ogg = PlOgg1_MyDialog->new();
        $PlOgg1_app->SetTopWindow($Mp3_To_Ogg);
        $Mp3_To_Ogg->Show(1);
        $PlOgg1_app->MainLoop();
}

Compiling C++ code

You can compile your wxGlade project after the generation of the C++ source and header files. The following examples demonstrate compiling on Linux command line using g++.

Example 2.4. Compiling a single file C++ project on Linux

# g++ FontColour.cpp $(wx-config --libs) $(wx-config --cxxflags) -o FontColour
# ll FontColour*
-rwxr-xr-x 1 carsten carsten 72493 Jun 15 09:22 FontColour
-rwxr-xr-x 1 carsten carsten  1785 Mai 11 19:24 FontColour.cpp
-rwxr-xr-x 1 carsten carsten  1089 Jun 11 07:09 FontColour.h

Example 2.5. Compiling a multi file C++ project on Linux

# g++  CPPOgg2_main.cpp $(wx-config --libs) $(wx-config --cxxflags) \
       -o CPPOgg2_main CPPOgg2_MyDialog.cpp CPPOgg2_MyFrame.cpp
# ll CPPOgg2*
-rwxr-xr-x 1 carsten carsten 108354 Jun 15 09:33 CPPOgg2_main
-rwxr-xr-x 1 carsten carsten    844 Mai 11 19:25 CPPOgg2_main.cpp
-rw-r--r-- 1 carsten carsten   5287 Mai 18 19:06 CPPOgg2_MyDialog.cpp
-rw-r--r-- 1 carsten carsten   1829 Jun 11 07:11 CPPOgg2_MyDialog.h
-rw-r--r-- 1 carsten carsten   1785 Mai 11 19:25 CPPOgg2_MyFrame.cpp
-rw-r--r-- 1 carsten carsten   1290 Jun 11 07:10 CPPOgg2_MyFrame.h