How can I enhance the look of the Perl/TK GUI under Perl 5.004? - perl

I have an application that is built to work on Windows, Linux, and Solaris that uses the Perl/TK GUI. Due to constraints, we are limited to Perl/TK only. Moreover, we are limited to an old Perl/Tk version, 5.00404.
I'd like to work within these limitations to make the GUI look as nice and modern as possible.
Are there any web-resources that have TK design schemes (for buttons, frames, colors, etc) that could assist me in this endeavor?
I am also looking for modernization advices like the one that I found here:
If you're finding that your Tk apps look a little ugly on X-based systems, try adding the following lines to the top of your script:
$mw->optionAdd("*font", "-*-arial-normal-r-*-*-*-120-*-*-*-*-*-*");
$mw->optionAdd("*borderWidth", 1);

Try using images instead of button elements, then you can have whatever style you like and the fonts can be baked in. This will work for pretty much any element where the contents are not dynamic - including backgrounds on panes and such. Granted it's more work but it does solve your problem, especially if you have a competent artist in your project group.

You could use the Tk theme engine to give your app better looks.

Using optionAdd to tweak defaults through the option database
is a reasonable start. A thread about this can be found at:
http://tcl.projectforum.com/tk/221
Download griffin.kit from there, use the sdx tool to unwrap it and locate
griffin.tcl to get a good set of option settings.
http://wiki.tcl.tk/3411 for the sdx tool.

Since in Linux the background of Tk::Entry and Tk::Text is grey i would also use the following two lines.
$mw->optionAdd( '*Entry.background', 'snow1' );
$mw->optionAdd( '*Text.background', 'snow1' );
Replace 'snow1' with a color of your choice. You can also use the hex representation(RGB) of the colors like '#ff9696'.

The Tile themeable engine for Tk makes it look much prettier. However, Perl/Tk has lagged far behind Tk's development, and can't take advantage of Tile and other advancements.
You should investigate whether Tkx is an option for you. It's not completely compatible with Perl/Tk, but the API is pretty close. It's a bridge between Perl and Tcl/Tk, so it can use all of the modern Tcl/Tk features (like Tile) while still having application logic coded in Perl. Quite a few of ActiveState's own graphical utilities use Tkx, with fairly good-looking results.
(source: activestate.com)
Perl 5.00404 is incredibly ancient, though. The Tkx dist claims to depend on Perl≥5.008... I don't have an old enough Perl to see how accurate that is.

Related

Create option to switch language for Glade 3 GTK 3.1x PyGObject program

I am looking for an example application that has an options menu, in which the language of the program can be switched manually. QGIS for example has such an option:
Is there a program using Glade 3, GTK 3.1x and PyGObject out there which shows a good way of doing this?
This isn't usually an option in applications, because, honestly, it's not a feature that many people will use. Most programs will use the system language setting to determine what language to display their UI in, and that's what Glade/GTK/Python makes it easy to do.
Most people won't have a need to run their program in a different language from the main system UI, and most people certainly won't need to change the program's language while using it.
It's certainly possible, as QGIS does: you have to either destroy and recreate the GUI when you switch languages, or keep track of which GUI widgets have localizable text in them, and change the text. But it's a very complex feature that brings little benefit, some would argue, and you should think about whether your user base actually needs it.

What module to use for perl GUI on linux? [duplicate]

I'd like to write some interactive GUIs in Perl. I've used TclTk but it looks dated. I've written QT code for C++, but the PerlTk module hasn't had a release in several years. Googling around I see other possible options.
What are good packages for this, including basic windowing, menus, drawing canvas, scrollbars, and so on.
Gtk2 has glade2 which can write out an XML file usable by Gtk2::GladeXML. Here is an example of how to bundle the XML with the app in the same file.
I misread the question at first. I thought you wanted a GUI editor for making GUIs (which is what glade2 is). You can also create GUIs using Gtk2 without glade2:
#!/usr/bin/perl
use strict;
use warnings;
use Gtk2;
Gtk2->init;
my $window = Gtk2::Window->new;
my $vbox = Gtk2::VBox->new;
my $label = Gtk2::Label->new("Hello World");
my $button = Gtk2::Button->new("Press me");
$window->add($vbox);
$vbox->add($label);
$vbox->add($button);
$window->set_default_size(200, 200);
$window->signal_connect(
destroy => sub {
Gtk2->main_quit;
}
);
my $i = 0;
$button->signal_connect(
clicked => sub {
$label->set_text("button pressed " . ++$i . " times");
}
);
$window->show_all;
Gtk2->main;
Try wxPerl!
From the web site:
wxPerl is an extension module allowing
the creation of GUI (Graphical User
Interface) from Perl; it is built as a
wrapper for the awesome wxWidgets C++
GUI toolkit.
Echoing Chas Owens, glade is quite usable with Gtk2 in Perl. In addition, Gtk2 also supports GtkBuilder files (which you can create the latest glade too).
The main problem with wxPerl (and wxWidgets itself) is that it doesn't let you install file event watchers into its main loop (it only has GUI, Socket and Timer events), unlike Tk and Gtk.
The Qt, Tk and Gtk2 event loops can be used in Perl with AnyEvent, and Gtk2 can be hooked into applications running the Event or Ev mainloop with Glib::Event and Glib::EV modules.
A GUI builder for WxPerl would be wxGlade or wxFormBuilder, both open-source.
I would probably use Gtk2, but Tk is definitely not dead. The lack of releases is due to the bugs being ironed out over the years. A lot of people still use it, and it generally works fine. (Tk's event loop is somewhat silly, but that is a detail that probably shouldn't concern you.) The only disadvantage is that your GUI looks like it is from 1996, but who cares?
(The gitk tool included with git showed that Tk GUIs look fine as long as they're useful.)
Recently I was made aware of another GUI toolkit for Perl called Prima. Its claim to fame is that it was written in C especially for Perl, not a port from TCL or bindings to something else. Assuming you have some rather standard libraries on your system, it will install directly from CPAN and its cross-platform!
David Mertens has been writing a new plotting library for PDL using it, and a REPL too!
Regarding quality of widgets, all three gtk2, wx and qt4 are equally good -- gtk2 is fastest, qt4 has best resolution, whereas wx is somewhere between the two in terms of both the parameters.
But tk is behind all the three both in terms of speed and resolution, but remains firstly because it is the original widget for all unix based interpreted languages, and secondly because it is native-widget of freebsd.
As on today in case of perl, documentation of perl-gtk2 is slightly more developed than both perl-qt4 which is in turn is more developed than wxperl. In fact, if you browse the web, you will find that tutorials for perl-gtk2 is more extensively available than even pygtk (which is also very well established) and ruby-gtk2. In case of python, wxpython documentation leads over PyQt and pygtk, whereas in case of ruby, ruby-qt4 leads over ruby-gtk2 and wxruby. However, others are developing very fast (e.g. ruby-gtk2) and after some time all nine will be equal in all aspects.
The perl-qt4 specific problem is: In case of non-kde desktops, perl-qt4 may not run. I tried running all in ubuntu and sabayon and found that perl-gtk2 and even wxperl (and wxruby also) runs fine whereas I'm not able to run even a single perl-qt4 programs in gnome-desktop where I have installed complete qt4 support without kde.
perl-qt4 asks for installation of not just qt4-libraries, but also kde-desktop libraries. This problem is uniquely perl-qt4-specific, does not exist in case of PyQt and rubyqt4 since they both run fine with qt4 runtime under gnome.
Hence, in this way eight (plus three tk) out of nine options did well (I havent tested PySide yet).
In case of perl-tk, widget is well developed and established and unlike tkinter, pmw and rubytk, its documentation is the best among all of these mentioned above.
But maybe after some time all the documentations become developed and any would become equally good.
After taking a balance between speed, clarity and cross-platform into consideration choose either perl-gtk2, or perl-qt4 or wxperl.
perl-tk, perl-gtk2 and perl-qt4 syntaxes nicely go well with perl programming language syntax, whereas wxperl syntax look more like proper c++ blended into perl which is different from the respective language syntax (just like in case of wxpython and wxruby).
But if you are already keeping in mind that wx code is uniquely different then you can straightaway begin with wxperl.
Otherwise, best way out is: begin with perl-tk, then switch over to perl-gtk2 then perl-qt4 or wxperl alike but make sure that you learn all four instead of only one (the same sequence should also apply to python and ruby too despite the fact that documentation support is reverse, but in case of perl even for this aspect it is same).
I don't have a real answer for you, but often you have to consider your deployment targets. Some of the GUI libraries are very nice, but only if you can get them to work on your operating system. I don't necessarily think that all frameworks need to be cross-platform compatible, a very laudable goal to work toward in a perfect world, as long as the one you choose doesn't lock out a significant portion of your users because the foundation GUIs libraries are hard to install or support on a particular platform.
I just want to let everyone know PerlQt is great and this site has a lot of tutorials on how to use it and lots of examples to download.
PerlQt Wiki tutorial
PerlQt is a very fast and easy way to create great looking GUI programs using the Qt drag and drop form designer and Perl. PerlQt is powerful enough for advanced developers and easy for beginners as well.
The solution I'm going with is Gtk-Perl. At first I had difficulty installing it, but in the end I found Camelbox Perl+Gtk2 in one package.
I have used Tk, but in the last few days I have been playing around with Continuity (CPAN entry), a stateful (persistent state per user) web application/server, and it could easily be a way to add "GUI" features into an application, while making it multi-user and portable at the same time.
Edit: At the time I wrote this, I was most interested in the fact that Continuity had its own built-in webserver. This is now true of other webframeworks for Perl as well. I have been using Mojolicious though I hear good things about Dancer too.

Need Help With Gtk+ Text Editor

I am creating a GTK+ text editor called Quick-Ed Pro. It was originally designed to be a cross-platform version of Quick-Ed , a text editor I wrote in raw Win Api. But after finding the awesome capabilities of GTK+ , Quick-Ed Pro emerged as an entirely different program with advanced GUI capabilities way better than Quick-Ed. But now Im stuck with a few problems.
Problems:
1- I want to make my editor multi-tabular like notepad++ or gedit. I dont know how to do this. What widget should I use?
2- GtkTextView does not seem to have any undo / redo functions. How can I make my own? (examples appreciated)
3- Gtk+ has a long startup time, usually 2-4 seconds unlike win api which started up in less than a second, so how can I create a small popup loading bar like the one in GIMP or Code::Blocks?
4-URL of my project: http://code.google.com/p/quick-ed/
URL of the WinApi Quick-Ed : http://code.google.com/p/burningprodigy ... e&can=2&q=
Any help will be appreciated. I need contributors. Please lend me a hand.
1) Tabs: You will need to write your own widget for this. No toolkit i know has one that is flexible enough to handle what is required in a good editor. But you can start with GtkNotebook for a quick prototype.
2) Yes this is a FAQ and imho bad that it is not solved directly in GTK. If you use gtkmm you can use http://view.sourceforge.net/classes.php otherwise look into the library to see how it is implemented and port it into C. There are other implementations for example for python available on the net.
3) You have to write a small dialog using the WinAPI and show this before you call the first GTK function. Usually i wouldn't recommend to do it - after the windows file cache has the files (or you have a SSD) loading speed is okay.
You should look into http://projects.gnome.org/gtksourceview/ to get a good editor. The GtkTextView is definitely not able to work as a source code editor. I'm maintaining a commerical IDE and Editor and by the way the most code is outside the editor widget anyway.

What should I use to create a Windows GUI?

I'm an experienced UNIX programmer.
Now I want to develop a simple Windows application; the programming part would be very easy with almost any tool (it might be C, Perl, or something else).
However, I wonder what tool to use in order to have some simple GUI around it?
I've read a little about Perl/TK, but understood that it's too old, and
Visual Studio requirement seems a little over-kill.
WxPerl is presently the widely used GUI toolkit in the Perl community.
I'd suggest having another look at Perl/Tk. Tk is old but nothing else have managed to do what it does best: being a simple, easy to use but powerful UI library (note its strengths in that order, note also I didn't mention speed).
Unix programmers both love (simple!) and hate (ugly!) Tk. But Tk is only really ugly on Unixen because it defaults to a Motif theme (modern Tk is/should be replaced by TTk which is themeable). Under Windows, Tk uses native widgets so look and feel is not so much of an issue like it is on Unix.
As for the other suggested libraries, QT feels alien under Windows (from your user's perspective) reflecting its Linux heritage but WxWidgets looks right at home reflecting its mostly Windows heritage.
I suggest you use QT (C/C++), more info here: http://qt.nokia.com/products/platform/qt-for-windows/
If you want good portablity between operating systems, os native (or other) styling, and installation without C/C++ compilation, you can take a look at the module I've been writing, XUL::Gui on CPAN. It uses Firefox as its rendering engine. Here's a quick example:
use XUL::Gui;
display Window title=>'my window',
H2('events!'),
Button(
label => 'click me',
oncommand => sub {
my ($self, $event) = #_;
$self->label = 'ouch!';
}
);
There are more detailed examples on CPAN. Let me know if you have any questions.
For a windows GUI use Win32::GUI and possibly Win32::GUI::XMLBuilder

What are good interactive GUI builder packages for Perl?

I'd like to write some interactive GUIs in Perl. I've used TclTk but it looks dated. I've written QT code for C++, but the PerlTk module hasn't had a release in several years. Googling around I see other possible options.
What are good packages for this, including basic windowing, menus, drawing canvas, scrollbars, and so on.
Gtk2 has glade2 which can write out an XML file usable by Gtk2::GladeXML. Here is an example of how to bundle the XML with the app in the same file.
I misread the question at first. I thought you wanted a GUI editor for making GUIs (which is what glade2 is). You can also create GUIs using Gtk2 without glade2:
#!/usr/bin/perl
use strict;
use warnings;
use Gtk2;
Gtk2->init;
my $window = Gtk2::Window->new;
my $vbox = Gtk2::VBox->new;
my $label = Gtk2::Label->new("Hello World");
my $button = Gtk2::Button->new("Press me");
$window->add($vbox);
$vbox->add($label);
$vbox->add($button);
$window->set_default_size(200, 200);
$window->signal_connect(
destroy => sub {
Gtk2->main_quit;
}
);
my $i = 0;
$button->signal_connect(
clicked => sub {
$label->set_text("button pressed " . ++$i . " times");
}
);
$window->show_all;
Gtk2->main;
Try wxPerl!
From the web site:
wxPerl is an extension module allowing
the creation of GUI (Graphical User
Interface) from Perl; it is built as a
wrapper for the awesome wxWidgets C++
GUI toolkit.
Echoing Chas Owens, glade is quite usable with Gtk2 in Perl. In addition, Gtk2 also supports GtkBuilder files (which you can create the latest glade too).
The main problem with wxPerl (and wxWidgets itself) is that it doesn't let you install file event watchers into its main loop (it only has GUI, Socket and Timer events), unlike Tk and Gtk.
The Qt, Tk and Gtk2 event loops can be used in Perl with AnyEvent, and Gtk2 can be hooked into applications running the Event or Ev mainloop with Glib::Event and Glib::EV modules.
A GUI builder for WxPerl would be wxGlade or wxFormBuilder, both open-source.
I would probably use Gtk2, but Tk is definitely not dead. The lack of releases is due to the bugs being ironed out over the years. A lot of people still use it, and it generally works fine. (Tk's event loop is somewhat silly, but that is a detail that probably shouldn't concern you.) The only disadvantage is that your GUI looks like it is from 1996, but who cares?
(The gitk tool included with git showed that Tk GUIs look fine as long as they're useful.)
Recently I was made aware of another GUI toolkit for Perl called Prima. Its claim to fame is that it was written in C especially for Perl, not a port from TCL or bindings to something else. Assuming you have some rather standard libraries on your system, it will install directly from CPAN and its cross-platform!
David Mertens has been writing a new plotting library for PDL using it, and a REPL too!
Regarding quality of widgets, all three gtk2, wx and qt4 are equally good -- gtk2 is fastest, qt4 has best resolution, whereas wx is somewhere between the two in terms of both the parameters.
But tk is behind all the three both in terms of speed and resolution, but remains firstly because it is the original widget for all unix based interpreted languages, and secondly because it is native-widget of freebsd.
As on today in case of perl, documentation of perl-gtk2 is slightly more developed than both perl-qt4 which is in turn is more developed than wxperl. In fact, if you browse the web, you will find that tutorials for perl-gtk2 is more extensively available than even pygtk (which is also very well established) and ruby-gtk2. In case of python, wxpython documentation leads over PyQt and pygtk, whereas in case of ruby, ruby-qt4 leads over ruby-gtk2 and wxruby. However, others are developing very fast (e.g. ruby-gtk2) and after some time all nine will be equal in all aspects.
The perl-qt4 specific problem is: In case of non-kde desktops, perl-qt4 may not run. I tried running all in ubuntu and sabayon and found that perl-gtk2 and even wxperl (and wxruby also) runs fine whereas I'm not able to run even a single perl-qt4 programs in gnome-desktop where I have installed complete qt4 support without kde.
perl-qt4 asks for installation of not just qt4-libraries, but also kde-desktop libraries. This problem is uniquely perl-qt4-specific, does not exist in case of PyQt and rubyqt4 since they both run fine with qt4 runtime under gnome.
Hence, in this way eight (plus three tk) out of nine options did well (I havent tested PySide yet).
In case of perl-tk, widget is well developed and established and unlike tkinter, pmw and rubytk, its documentation is the best among all of these mentioned above.
But maybe after some time all the documentations become developed and any would become equally good.
After taking a balance between speed, clarity and cross-platform into consideration choose either perl-gtk2, or perl-qt4 or wxperl.
perl-tk, perl-gtk2 and perl-qt4 syntaxes nicely go well with perl programming language syntax, whereas wxperl syntax look more like proper c++ blended into perl which is different from the respective language syntax (just like in case of wxpython and wxruby).
But if you are already keeping in mind that wx code is uniquely different then you can straightaway begin with wxperl.
Otherwise, best way out is: begin with perl-tk, then switch over to perl-gtk2 then perl-qt4 or wxperl alike but make sure that you learn all four instead of only one (the same sequence should also apply to python and ruby too despite the fact that documentation support is reverse, but in case of perl even for this aspect it is same).
I don't have a real answer for you, but often you have to consider your deployment targets. Some of the GUI libraries are very nice, but only if you can get them to work on your operating system. I don't necessarily think that all frameworks need to be cross-platform compatible, a very laudable goal to work toward in a perfect world, as long as the one you choose doesn't lock out a significant portion of your users because the foundation GUIs libraries are hard to install or support on a particular platform.
I just want to let everyone know PerlQt is great and this site has a lot of tutorials on how to use it and lots of examples to download.
PerlQt Wiki tutorial
PerlQt is a very fast and easy way to create great looking GUI programs using the Qt drag and drop form designer and Perl. PerlQt is powerful enough for advanced developers and easy for beginners as well.
The solution I'm going with is Gtk-Perl. At first I had difficulty installing it, but in the end I found Camelbox Perl+Gtk2 in one package.
I have used Tk, but in the last few days I have been playing around with Continuity (CPAN entry), a stateful (persistent state per user) web application/server, and it could easily be a way to add "GUI" features into an application, while making it multi-user and portable at the same time.
Edit: At the time I wrote this, I was most interested in the fact that Continuity had its own built-in webserver. This is now true of other webframeworks for Perl as well. I have been using Mojolicious though I hear good things about Dancer too.