NAME
Tk::GtkSettings - Give Tk applications the looks of Gtk applications
SYNOPSIS
use Tk::GtkSettings;
applyGtkSettings;
#or
use Tk::GtkSettings qw(initDefaults export2xrdb);
initDefaults;
#do your adjustments here
export2xrdb;
#then initialize your perl/Tk app.
use Tk;
my $w = new MainWindow;
#Do your stuff here
$w->MainLoop;
ABSTRACT
Apply Gtk colors and fonts to your perl/Tk application
DESCRIPTION
Tk::GtkSettings attempts to overcome some very old complaints about Tk:
- It's ugly!
- It's complicated to adjust colors and fonts to your desktop style
Tk::GtkSettings loads your Gtk configuration files and applies it's font and color settings to your perl/Tk application.
initDefaults loads some nice (at least we think so) default settings that copies your Gtk theme pretty well.
However, it gives plenty of tools for you to adjust it and mess it up any way you like.
It is harmless to install on Windows or Mac. It just will not do anything on these systems. That makes it smooth to add as a dependency to your own package if you want it to be able to run on Windows and Mac as well.
In working with colors it assumes 8-bit color depth.
EXPORTS
- $delete_output
-
Usefull for testing and debugging. export2xrdb exports to a file which then is sent to xrdb. It checks if this file should be deleted when done. Default value is 1.
- $gtkpath
-
Usefull for testing. Default value is ~/.config/gtk-3.0/. That is the location where the Gtk configuration files reside. This variable is not defined when on Windows or Mac.
- $out_file
-
Default value ~/.tkgtksettings. Used by export2xrdb. This variable is not defined on Windows or Mac.
- $verbose
-
Usefull for testing and debugging. Default value is 0. If set Tk::GtkSettings will complain about everything not in order. Otherwise it will quietly fail.
- alterColor($hexcolor, $offset)
-
Adjusts $hexcolor by $offset. It takes every color chanel and adds or substracts $offset. If the channel value is greater than 127 it will substract, otherwise it will add.
alterColor('#000000', 1) returns #010101 alterColor('#FFFFFF', 1) returns #FEFEFE
- applyGtkSettings
-
Just making life easy. Call this one and your done, unless you require adjustments. It calls initDefaults and exports the whole bunch to xrdb. Exported by default.
- appName($name)
-
Sets and returns your application name. By default it is set to the basename of what is in $0. Your Gtk settings will only be applied to your application in xrdb. You can set it to an empty string. Then it will apply your Gtk settings to all your perl/Tk applications.
- convertColorCode('rgb(255, 0, 0)')
-
Some color settings in the Gtk configuration files are in the format 'rgb(255, 255, 255)'. convertColorCode converts these to a hex color string.
- decodeFont($gtkfontstring)
-
Converts the font string in gtk to something Tk can handle
- export2file($file, ?$removeflag?)
-
Exports your Gtk settings to $file in a format recognized by xrdb. It looks for a section in the file marked by appName . "Tk::GtkSettings section\n". If it finds it it will replace this section. Otherwise it will append your Gtk settings to the end of the file. If $file does not yet exist it will create it. if $removeflag is true it will not export but remove the section from $file.
- export2Xdefaults(?$removeflag?)
-
Same as export2file, however the file is always '~/.Xdefaults'.
- export2Xresources(?$removeflag?)
-
Same as export2file, however the file is always '~/.Xresources'.
- export2xrdb
-
exports your Gtk settings directly to the xrdb database.
- generateOutput
-
Generates the output used by the export functions. Returns a string.
- groupAdd($groupname, \@members, \%options)
-
Adds $groupname to the groups hash. If @members or %options are not specified, it will leave them empty.
- groupAll
-
Returns a list of all available groups.
- groupDelete($groupname)
-
Removes $groupsname from the groups hash. You cannot delete the 'main' group.
- groupExists($groupname)
-
Returns true if $groupname is available.
- groupMembers($groupname)
-
Returns the list of existing members of $groupname. It will return an empty list if $groupname equals 'main'.
- groupMembersAdd($groupname, @newmembers)
-
Adds new members to $groupname. You cannot add members to the 'main' group.
- groupMembersReplace($groupname, @members)
-
Replaces the list of members in $groupsname by @members. You cannot modify the members list of the 'main' group.
- groupOption($groupname, $option, ?$value?)
-
Sets and returns the value of $option in $groupname. $value should be a corresponding key from the Gtk hash. If that key is not found, it assumes a direct value.
- groupOptionAll($groupname)
-
Returns a list of all available options in $groupname.
- groupOptionDelete($groupname, $option)
-
Removes $option from $groupname
- gtkKey($key, ?$value?)
-
Sets and returns the value of $key in the Gtk hash
- gtkKeyAll
-
Returns a list of all available keys in the Gtk hash.
- gtkKeyDelete($key)
-
Delets $key from the Gtk hash.
- hex2rgb($hex_color)
-
Returns and array with the decimal values of red, green and blue.
- hexstring($num)
-
Return the hexadecimal representation of $num in a two character string.
- initDefaults
-
Initializes some sensible defaults. Also does a full reset and loads Gtk configuration files.
- loadGtkInfo
-
Empties the Gtk hash and (re)loads the Gtk configuration files.
- platformPermitted
-
Returns true if you are not on Windows or Mac.
- removeFromfile($file)
-
Same as export2file($file, 1)
- removeFromXdefaults
-
Same as export2Xdefaults(1)
- removeFromXresources
-
Same as export2Xresources(1)
- removeFromxrdb
-
Removes all the settings previously defined from the xrdb database
- resetAll
-
Removes all groups and options. The group 'main' will remain, but all its options are also deleted. This does not affect the Gtk hash.
- rgb2hex($red, $green, $blue)
-
Converts the decimval values $red, $green and $blue into a hex color string.
COPYRIGHT AND LICENSE
Copyright 2022 - 2023 by Hans Jeuken
Same as Perl, in your option.
AUTHOR
Hans Jeuken (jeuken dot hans at gmail dot com)
BUGS AND CAVEATS
If you find any bugs, please contact the author.
TODO
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 307:
'=item' outside of any '=over'