I have create a module which set themes in your Tk widget and its
children.
This module allows you to set a theme in your widget by using one of
different default themes or by loading a new theme.
A theme contains all options that you want to use to configure the Tk
widgets (colour of buttons, of Entry, ...) in an ini file.
Everybody can participate to increase the themes of this module by
propose a theme that will be
store in the module because each theme is stored in an ini file.
How can I call it before upload it in CPAN ? Tk::Dressing,
Tk::LookAndFeel, Tk::Design, Tk::Themes or other name ?
What do you think about this module ?
That is the synopsis of the module
SYNOPSIS
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::NEWMODULE;
my $mw = new MainWindow( -title => "Theme in Tk widget", );
$mw->minsize(300,100);
my $bouton = $mw->Button(
-text => 'Close widget',
-command => sub { exit; },
)->pack( qw/ -side bottom -pady 10 / );
my $Message = "Hello everybody\n\nWelcome to Perl/Tk and themes\n
\n";
$mw->Label( -text => $Message, -anchor => 'center' )->pack( qw/ -
side top -padx 10 -pady 10 / );
$mw->Label( -text => 'Example : ', -anchor => 'center' )->pack( qw/ -
side left -padx 10 -pady 10 / );
$mw->Entry( -text => 'test',)->pack( qw/ -side left -padx 10 -pady
10 / );
# Set theme
my $TkNEWMODULE = new Tk::NEWMODULE;
$TkNEWMODULE->design_widget(
-widget => $mw,
-theme => 'djibel',
);
MainLoop();
Best Regards,
Djibril
I think this is one of rare case where the name may depend on the
details of implementation of the customization. So: how do you do it?
E.g., in MP3::Tag, I do customizations like this: the default
implementation of a method is not in TOPLEVEL_NAME, but in
TOPLEVEL_NAME::Implementation. Therefore all methods calls go through
@TOPLEVEL_NAME::ISA, which is set to
TOPLEVEL_NAME::User TOPLEVEL_NAME::Site
TOPLEVEL_NAME::Vendor TOPLEVEL_NAME::Implementation
So there are 3 different levels where a method call may be
intercepted (lousely based on different semantic of who may improve
the implementation: Vendor/Site/User). For Tk, I do not think 3
levels would be enough; A user may want to install several different
embelishment "hooks". So one would need an infinite number of
possible intermediate levels (a floating number for the "level").
I suspect that you do your interception via some modification of @ISA
as well. Do you?
Ilya
Dear Ilya,
I have used for an example Tk::Dressing module name. The module have
just one .pm file
called Dressing.pm. In the lib directory, I have create a directory
named DressingThemes
which contains all .ini files (each file contains a theme
configuration).
In my Module::build, I have added code to allow Makefile.PL to create
the directory.
My MANIFEST is :
Changes
demo/test.pl
lib/Tk/Dressing.pm
lib/Tk/DressingThemes/black.ini
lib/Tk/DressingThemes/blue.ini
lib/Tk/DressingThemes/djibel.ini
lib/Tk/DressingThemes/tutu.ini
lib/Tk/DressingThemes/toto.ini
MANIFEST
README
t/00-load.t
t/boilerplate.t
t/manifest.t
t/pod-coverage.t
t/pod.t
TODO
Makefile.PL
META.yml
when I try to install it in Windows OS, it is ok. Perl install the
module in
C:\Perl\site\lib\Tk :
C:\Perl\site\lib\Tk\Dressing.pm
C:\Perl\site\lib\Tk\DressingThemes\black.ini
C:\Perl\site\lib\Tk\DressingThemes\blue.ini
C:\Perl\site\lib\Tk\DressingThemes\djibel.ini
C:\Perl\site\lib\Tk\DressingThemes\tutu.ini
C:\Perl\site\lib\Tk\DressingThemes\toto.ini
in Linux system, it is ok too
/usr/lib/perl5/site_perl/5.12.1/Tk/Dressing.pm
/usr/lib/perl5/site_perl/5.12.1/Tk/DressingThemes
/usr/lib/perl5/site_perl/5.12.1/Tk/black.ini
/usr/lib/perl5/site_perl/5.12.1/Tk/blue.ini
/usr/lib/perl5/site_perl/5.12.1/Tk/djibel.ini
/usr/lib/perl5/site_perl/5.12.1/Tk/tutu.ini
/usr/lib/perl5/site_perl/5.12.1/Tk/toto.ini
Then I think I don't need 3 level ?
=head1 How to participate to module to increase number of themes ?
The first aim of Tk::Dressing is to allow user to choice between theme
proposed. But it is important
to Tk::Dressing to propose a lot of theme then, your help is welcome.
Send me an .ini file and the name of your theme
by email address or through the web interface at : L<http://
rt.cpan.org/NoAuth/ReportBug.html?Queue=Tk-Dressing>
and I will be add it in the module.
Do you think it is ok ?
Tk::LookAndFeel, Tk::Design, Tk::Themes or other name ?
Any suggestion about this module ?
That is an example of some lines of an ini file
[Button]
-activebackground: #7F80C0
-background: #7F80C0
-foreground: white
-disabledforeground: white
-activeforeground: white
[Canvas]
-background: #697E6D
[Checkbutton]
-highlightbackground: #68676C
-activebackground: #68676C
-background: #68676C
-foreground: white
-disabledforeground: white
-activeforeground: white
-selectcolor: #697E6D
...
...
Best regards,
Djibril
>> I think this is one of rare case where the name may depend on the
>> details of implementation of the customization. So: how do you do it?
> I have used for an example Tk::Dressing module name. The module have
> just one .pm file
> called Dressing.pm. In the lib directory, I have create a directory
> named DressingThemes
> which contains all .ini files (each file contains a theme
> configuration).
> In my Module::build, I have added code to allow Makefile.PL to create
> the directory.
Sorry if I was not clear enough. I do not care now about how you
store your code on file system.
Consider your example: it loads Tk::Dressing, but then makes no calls
mentioning Tk::Dressing. This means that just loading Tk::Dressing
CHANGES how OTHER method calls behave. (THIS is what I called
"interception".)
My question was: what is the mechanism of this interception?
Thanks,
Ilya
Sorry, I am not understand what is your interception process. Which
load Tk::Dressing ? Do you speak about installation, using module in a
program toto.pl ?
Best regards,
Djibril
> Sorry, I am not understand what is your interception process. Which
> load Tk::Dressing ? Do you speak about installation, using module in a
> program toto.pl ?
As I said, I do not care now about how things are organized on your
file system. It was a question about how PERL CODE WORKS.
Subsctitute `loads' by `use()s' if it would make my question clearer.
Yours,
Ilya
Tk::Dressing has 5 public methods. To use it, you have to load it (use
Tk::Dressing;) AND create the object.
If user just load Tk::Dressing, nothing will be happened with the
others Tk module.
The only way to change the design (color theme) of your widget is to
call design_widget method like this :
my $TkDressing = new Tk::Dressing;
$TkDressing->design_widget(
-widget => $mw,
-theme => 'djibel',
);
About the name of the module, what is your suggestion :
Tk::LookAndFeel, Tk::Design,
Tk::Themes, Tk::Dressing, Tk::Style or other one ?
Best regards,
Djibril
At the risk of wading in too late, I would like to know from Ilya how
the naming of the module should be affected by it's design? I would
rather it be named based on "what it does" as opposed to "how it works".
I know you likely have a very good reason to ask. I just don't
understand it.
Djibril - As for answering your question about naming - I would NOT use
Theme. This could be mistaken for "real" themes/tiles that have already
been implemented in Tcl/Tk. Without seeing your code - I am guessing
that you will provide methods for creating, storing and loading these
"ini" files containing the information needed to change the "look" of
each widget.
Are you aware of some other Tk modules that aid in configuring the
various options for widgets?
Tk::Cmdline..
Tk already supports .Xresource/.Xdefault files and there is Tk::Cmdline
that allows access to those (this works in Windows too).
Tk::Preferences..
This module looks to be very close to what you described in your
original post. What is missing here is the persistent state in storing
the data to a file. The author gives an option in the documentation by
using Data::DumpXML, but he doesn't include a permanent solution in the
module.
I'm not trying to dissuade you from uploading - just making sure you are
aware of what exists already. I personally would not use any of the
names you have provided. None of them really describes what your module
does. Tk::Preferences is pretty good to describe what it does.
What about something like Tk::Favorite or Tk::Customize? Actually -
Tk::Dressing is beginning to grow on me in the time it took to write this.
Good luck.
Jack
Thank you Jack for your answer,
Before creation of this module I have seen what already exists in
CPAN :-).
Tk::CmdLine is good. But it is not easy to use for a newbie. We have
to set
declaration before each MainWindows and it is very global. But it is
very good.
Tk::Preferences : I have used this module in several perl/tk
application that I have created but,
I have see some bugs for some widgets or children widgets. I have
submitted a patch
in 2009 but no answer. The concept of my module is very similar to
this module by
using configure method to change configuration of a widget parent
( MainWidows, TopLevel, Frame, ...)
or children (button, entrey, ...).
Some change in code have been set. The Data::DumpXML is not clear and
I think using an xml to set configuration is not good.
A ini file is simple and sufficient to store configuration.
These 2 modules does not propose some default configuration files and
I think it can be a good idea.
Allow user to send sometimes an ini file configuration to add theme in
module can be good.
That is why I have decided to upload this module to CPAN.
Do you think it is a good idea to upload this module to CPAN ?
About name of module, Tk::Customize or Tk::Dressing why not, my
favorite is Tk::Dressing :-), and you ?
Best regards,
Djibril
For me, it looks absolutely backward. What is bad with
$mw->Tk::Dressing::dress -theme => 'djibel';
or just
$mw->Tk::Dressing::theme 'djibel';
??? Or, if setting a theme is the only thing one can do with a
widget,
$mw->Tk::FooTheme->set 'djibel';
Ilya
I don't want this code because it is mean that I have to pollute Tk
name space.
Djibril
Looks like you have not read what I wrote...
Ilya
That is the POD. If not any suggestion, I will upload the module.
Tk::Dressing - Set a theme in your widget.
* NAME
* SYNOPSIS
* DESCRIPTION
* CONSTRUCTOR/METHODS
o new
o clear
o design_widget
o get_all_theme
o get_current_theme
o get_default_theme_file
o load_theme_file
* How to participate to module to increase number of default
themes ?
* SEE ALSO
* AUTHOR
* BUGS
* SUPPORT
* ACKNOWLEDGEMENTS
* LICENSE AND COPYRIGHT
NAME
Tk::Dressing - Set a theme in your widget.
SYNOPSIS
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::Dressing;
use Tk::BrowseEntry;
my $TkDressing = new Tk::Dressing;
my $mw = new MainWindow( -title => "Dressing widget", );
$mw->minsize( 300, 100 );
my $BrowseEntryTheme = $mw->BrowseEntry(
-label => "Select a theme : ",
-state => 'readonly',
-choices => [ 'clear dressing', sort $TkDressing->get_all_theme ],
)->pack;
my $Message = "Hello everybody\n\nWelcome to Perl/Tk and Tk::Dressing
\n\n";
$mw->Label( -text => $Message, -anchor => 'center' )->pack(qw/ -
side top -padx 10 -pady 10 /);
$mw->Label( -text => 'Example : ', -anchor => 'center' )->pack(qw/ -
side left -padx 10 -pady 10 /);
$mw->Entry( -text => 'test', )->pack(qw/ -side left -padx 10 -pady
10 /);
$BrowseEntryTheme->configure(
-browse2cmd => sub {
my $theme = $BrowseEntryTheme->Subwidget('entry')->get;
if ( $theme eq 'clear dressing' ) { $TkDressing->clear($mw);
return; }
$TkDressing->design_widget(
-widget => $mw,
-theme => $theme,
);
},
);
MainLoop();
DESCRIPTION
Tk::Dressing allows you to set a theme in your widget by using one of
different default themes or by loading a new theme. A theme contains
all options that you want to use to configure the Tk widgets (color of
buttons, of Entry, ...).
Everybody can participate to increase the themes of this module by
proposing a theme that will be store in the module because each theme
is stored in an ini file.
CONSTRUCTOR/METHODS
new
This constructor allows you to create a new Tk::Dressing object.
$TkDressing = new Tk::Dressing
The new() method is the main constructor for the Tk::Dressing module.
# Create Tk::Dressing constructor
my $TkDressing = new Tk::Dressing;
clear
This method allow you to replace your last theme set by the default
look and feel of your widget.
$TkDressing->clear( $Widget )
$TkDressing->clear($mw);
design_widget
Set the theme on your widget and its children.
$TkDressing->design_widget( -widget => $Widget, -theme => $ThemeName )
-widget => $Widget
Specifies the widget. The widget can be a Toplevel, Frame,
Button, ...
-widget => $mw,
-theme => string
Specifies the theme name between defaults themes of module. If you
have loaded a theme before, you can choose it.
-theme => 'starwars',
Default : djibel
$TkDressing->design_widget(
-widget => $mw,
-theme => 'djibel',
);
get_all_theme
Get all theme available and loaded in you Widget.
my @all_themes = $TkDressing->get_all_theme;
get_current_theme
Get the theme in used in your widget.
my $current_theme = $TkDressing->get_current_theme;
get_default_theme_file
Get a .ini file of one of default themes of module.
$file = $TkDressing->get_default_theme_file($theme, $directory)
my $file = $TkDressing->get_default_theme_file('djibel', '/home/
user');
# $file will be contain /home/user/djibel.ini
load_theme_file
Loads your own theme file to design your widget.
$TkDressing->load_theme_file($theme, $theme_file);
Your file must be an .ini file and must contain sections. Each section
correspond to a widget, that is an example.
[BrowseEntry]
-background: #697E6D
-foreground: white
-disabledbackground: #697E6D
-disabledforeground: white
[Button]
-activebackground: #7F80C0
-background: #7F80C0
-foreground: white
-disabledforeground: white
-activeforeground: white
[Canvas]
-background: #697E6D
[Checkbutton]
-highlightbackground: #68676C
-activebackground: #68676C
-background: #68676C
-foreground: white
-disabledforeground: white
-activeforeground: white
-selectcolor: #697E6D
[ColoredButton]
-highlightbackground: #68676C
-background: #68676C
-autofit: 1
[DirTree]
-highlightbackground: #68676C
-background: #697E6D
-foreground: white
-highlightcolor: #68676C
-selectforeground: white
-selectbackground: #68676C
[Entry]
-highlightbackground: #68676C
-background: #697E6D
-disabledbackground: #697E6D
-foreground: white
-readonlybackground: #697E6D
-disabledforeground: white
-insertbackground: white
How to participate to module to increase number of default themes ?
The first aim of Tk::Dressing is to allow user to choice between theme
proposed. But it is important to Tk::Dressing to propose a lot of
default themes then, your help is welcome. Send me an .ini file and
the name of your theme by email address or through the web interface
at : http://rt.cpan.org/NoAuth/ReportBug.html and I will be add it in
the module in a new release.