This section covers advanced topics like the handling of automatically generated source files or escaping of special characters like newline characters or tab characters.
Escape sequences are used to define certain special characters within string literals. wxGlade supports escape sequences generally. The only exception is the null byte (“0”) and the escape sequence (“\0”) belonging to it. wxGlade can't handle null bytes.
Escape sequences like “\n” or “\t” will not touched by wxGlade. Thereby the generated source code contains exactly the same sequence as entered. The language interpreter or compiler will interpret and probably convert the sequence into control characters. For example “\n” will be converted into a line break.
Escape sequences with at least two leading backslashes e.g. “\\n” will be escaped to show exact the same sequence and don't convert it into control characters. Question marks especially double quotes will be escaped also.
These recommendations should help to improve the usability and maintainability of code generated by wxGlade. They combine the experience of many wxGlade users.
wxGlade is able to change the own code inside existing source files to reflect changed designs.
This feature has some limitations. They are detailed discusses in the section called “Shared Control”.
It's common coding practice to separate and encapsulate individual responsibilities. Using a derived class to extend the code e.g. with GUI logic would follow this practice.
This feature is deprecated and will be removed from a future version of wxGlade. Thereby it's advised not to use this feature for new projects. Details about all deprecated features are shown in the section called “Deprecated Features”.
Use the C++ names for all wx identifiers like classes, colours or events of the wx framework. Please don't enter identifiers already formatted in a language specific form. wxGlade is able to transform the entered original identifiers in language-specific terms. You can use your own style for your object certainly.
Example 4.1. Correct entered wx constant
Enter “wxID_CANCEL” even for wxPython instead of “wx.ID_CANCEL”
It's generally recommended to use Unicode encoding for all non-ASCII character sets.
Enable internationalisation support. There are no disadvantages if internationalization is active but not used.
It's hard to add i18n and Unicode afterwards from project point of view.
The wxWidgets are written in C++ and follow the C++ naming convention. This naming convention may differ from the language specific and / or project specific naming convention.
For consistency's sake, it's recommended to use the wxWidgets style.
It's not recommended to use nested classed and functions in combination with disabled feature “Overwrite existing sources”. Use derived classes to implement your functionality. See the section called “Best Practice” also.
The Lisp code generated by wxGlade may or may not working with a current Lisp dialect. Help to improve the Lisp support is really welcome.
Unsupported features in Lisp:
Unicode support
Support for wxWidgets 3.0
The XRC code writer doesn't supports all bitmap path tags described in the section called “Specifying the Path of Bitmaps”.
Just the “art:
” statement is
supported. The remaining bitmap tags will irgnored.
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 5.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 file”option 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.
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.
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.
The source code modifications by wxGlade may incomplete after:
renaming classes and attributes
changes in dependencies are not updated in all use cases
changing the base classes or replace a single base class by multipe base classes or vis-a-vis
nested classed and functions
if the percent sign (“%”) have been added manually
removing event handlers
Additionally there are some internal flaws like the inconsistent design of the begin and end markers, just compare the event handler code generated for Perl and Python. Improving the handling internally would break the backward compatibility.
This feature is deprecated and will be removed from a future version of wxGlade. Thereby it's advised not to use this feature for new projects. Details about all deprecated features are shown in the section called “Deprecated Features”.
“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”).
wxGlade can create 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:
Name
Class
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 4.1. Interaction between properties to generate different types of start code
Name | Class | Top window | Type of application start code to generate |
---|---|---|---|
not selected | not selected | not selected | not generated |
selected | not selected | not selected | not generated |
not selected | selected | not selected | not generated |
selected | selected | not selected | not generated |
selected | not selected | selected | simplified start code |
not selected | selected | selected | not generated |
selected | selected | selected | detailed 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 4.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 4.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(); }
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 4.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 4.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
wxGlade is able to save projects as XRC files and to convert XRC files into wxGlade projects.
One way for converting XRC files is the usage of the Python script xrc2wxg.py at command line. The script is part of wxGlade.
Example 4.6. Converting a XRC file into a wxGlade project
# ./xrc2wxg.py FontColour.xrc # ls -l FontColour.* -rw-r--r-- 1 carsten carsten 5554 Dez 4 20:36 FontColour.wxg -rw-r--r-- 1 carsten carsten 4992 Dez 4 20:13 FontColour.xrc
The “” menu provides a menu item “” to import and open a XRC file directly.
The following example shows how to load and show the frame
“Main” from XRC file
test.xrc
.
Example 4.7. wxPython code to load and show a XRC resource
#!/usr/bin/env python2 import wx from wx import xrc GUI_FILENAME = "test.xrc" GUI_MAINFRAME_NAME = "Main" class MyApp(wx.App): def OnInit(self): self.res = xrc.XmlResource(GUI_FILENAME) self.frame = self.res.LoadFrame(None, GUI_MAINFRAME_NAME) self.frame.Show() return True if __name__ == "__main__": app = MyApp() app.MainLoop()