ApplyTheme
PowerScript function
Description
Applies a theme to the current application UI. This method should be
called when all windows are closed, in order for windows and controls to
take effect.
Syntax
|
1 |
ApplyTheme ( String theme ) |
|
Argument |
Description |
|---|---|
|
theme |
A string whose value is the theme name (or theme path and The theme path is optional. If not specified, the default The theme name should be the sub-folder name under the In Windows system, the maximum length for a path is |
Return value
Integer. Returns 1 if it succeeds and -1 if it fails. If any
argument’s value is null, the method returns null.
Usage
The ApplyTheme method should be called when all windows are closed,
for example, it can be called in the Application Open event when all of
the child windows are not yet opened.
The theme path and name set by the ApplyTheme function takes
precedence over those selected in the PowerBuilder painter. See the
following code examples for illustration.
The ApplyTheme method is effective to the window, DataWindow, and
all visual controls in your current application, except Line, Oval,
Rectangle, RoundRectangle, Picture, PictureHyperLink, and
Animation.
Once you apply a theme to the application, you should not select the
Windows classic style option in the System Options and/or project painter,
otherwise, the application UI will be rendered in the Windows classic
style instead of the selected theme.
When the application is run in the Windows system and if the Windows
system theme is set to “Windows Classic”, then the application UI will be
rendered in the Windows Classic theme instead of the selected
theme.
The “Use Windows XP style DPI scaling” option in Windows Server 2012
will be automatically selected, if the scaling percentage is set to 125%
or lower. This will prevent the selected theme working correctly. In such
case, you should manually uncheck the “Use Windows XP style DPI scaling”
option.
The ApplyTheme method can apply a theme, but it cannot turn off a
theme. To turn off a theme, you should remove the ApplyTheme method (as
well as the theme settings in the PowerBuilder painter), and then restart
the application for the change to take effect. Or create a custom theme
that has {“drawing”:false} for every control type, and use this theme in
the ApplyTheme method.
Before switching between themes or turning off the theme thru the
ApplyTheme method, it is the best practice to prompt end users to reopen
the current window, in order to refresh the UI correctly.
Example 1
This example applies the “Flat Design Blue” theme (the theme name
selected in the painter will be ignored).
When the app is run from the IDE, the script reads the theme files
from the Theme Path set in the painter; when the app’s executable file is
run, the script reads the theme files from the “theme” folder under the
root of the application installation directory.
|
1 |
ApplyTheme ("Flat Design Blue") |
Example 2
This example applies the “Flat Design Blue” theme and both the theme
path and the theme name selected in the painter will be ignored.
The script reads the theme files from “D:App1SourceCode hemes” no
matter when the app is run from the IDE or when the app’s executable file
is run.
|
1 |
ApplyTheme("D:App1SourceCode hemesFlat Design Blue") |
Example 3
This example applies the “Flat Design Blue” theme and both the theme
path and the theme name selected in the painter will be ignored.
When the app is run from the IDE, the script reads the theme files
from the path relative to the PBT file; when the app’s executable file is
run, the script reads the theme files from the path relative to the root
of the application installation directory.
|
1 |
ApplyTheme(". hemesFlat Design Blue") |
|
1 |
ApplyTheme("... hemesFlat Design Blue") |
|
1 |
ApplyTheme("themesFlat Design Blue") |
See also
Specifying the UI
theme for the application in Users Guide