Before you start making any changes there's a few things you need to consider. If you're writing a GUI that is only ever going to be used by yourself and will only ever be used on one platform, then feel free to go to town with whatever colours, fonts, sizes and so on that suit your personal taste. If, as is more likely the case, you want to show (give/sell/etc.) your GUI to anybody else, then you should resist the urge to make direct changes within your code (e.g. Button(-background => '#ff0000')).
Perl/Tk GUIs will, in general, take on the look-and-feel of the underlying system (colours, fonts, scrollbars, menus, window decorations and so on) and most users will have set that up for their own person tastes and requirements. Bear in mind that people's eyesight varies and, accordingly, they will have set up, for instance, different sized fonts, contrasting text, background and foreground colour combinations; a sizeable proportion (I think the number is around 5-10%) of the human population is colour blind to some degree, so what looks like, say, a pleasant woodland theme to you is just a blur to someone else; there's also cultural differences: what appears as a fun or happy set of colours to you could well be funereal to the next person.
On Unix systems, you can set up one or more themes that could be added to the .Xdefaults file - you could distribute these with your GUI. There's possibly similar facilities for other systems but that's an area I'm unfamiliar with.
For changes you wish to apply within your code, you should aim to use the Option Database - see Tk::option (and note this is different from the similarly named Tk::options). This will allow users of your GUI to override your settings with their personal preferences. As an example, I find the default borders around buttons to be somewhat chunky, so I include code like this:
my $priority = q{startupFile};
...
$mw->optionAdd('*Button*borderWidth', 1, $priority);
$mw->optionAdd('*Button*activeBorderWidth', 1, $priority);
For fonts (see Tk::font), consider building these from components rather than specifying every attribute for every font. Here's some example code:
my %default_style = (
-size => 10,
-weight => 'normal',
-slant => 'roman',
-underline => 0,
-overstrike => 0,
);
my %serif_default_style = (-family => 'Times', %default_style);
my %mono_default_style = (-family => 'Courier', %default_style);
my $serif_default_font = $mw->fontCreate(%serif_default_style);
my $serif_bold_font = $mw->fontCreate(%serif_default_style, -weight =>
+ q{bold});
By doing this, if you decide you want your default size to be 12 instead of 10, you only need to make 1 change rather than having to edit every font you've created.
When changing window dimensions, bear in mind that screens come in many different sizes. You can use methods such as screenheight() and screenwidth() (see Tk::Widget) to set an appropriate geometry() for any screen.
Finally, for actually selecting a default theme for your GUI, I'd suggest using whatever tool comes with your system for creating custom themes. These tools typically have some sort of change/preview facility which should be a lot easier to use than manually changing your code and then running your application to see how it looks. Remember to always change background and foreground colours in pairs - it's a common mistake to set the background to, say, black and then later find text insertion appears to be broken when, in fact, the text is fine except it still has its original black colour and is therefore invisible.
|