Re: Is there a really perlish user interface module, or something?
by kvale (Monsignor) on Aug 08, 2004 at 21:16 UTC
|
It can be frustrating switching from an API you know well to one you don't. But Tk has been around a while and will probably do what you want.
For example, take your dialog box example. There is a messageBox method that is nearly as simple.
$answer = $mw->messageBox(
-message => 'Are you sure you want to quit?',
-title => 'Demo dialog',
-type => 'YesNo',
-icon => 'question',
-default => 'yes'
);
If that is still too much typing, put it in a sub with the customized defaults you desire. I do not know how to both derive a title from a main window and not have the dialog derived from a main window; pick one.
As for your browse widget, I've never needed such a thing, but you may want to check out the ListBox widget (chapter 7 of Mastering Perl/Tk is devoted to ListBoxes). Finally, I don't see what is preventing you from validating responses with regular expressions; on the contrary, this is usually encouraged as good defensive coding.
I always thought of the perl/Tk interface as melding very nicely with the rest of perl. The interface has a natural hierarchical, OO structure and after playing with some widgets, it is pretty easy to guess what is needed with new widgets. It does what I mean.
That said, I can see room for improvement. Tk has always been beautiful enough for me, but I recognize that others are more sensitive to GUI fashions. For instance, it would be nice for Tk widgets to be more easily skinnable, in the fashion of GNOME or KDE widgets.
Update: I forgot to mention that the Tab key allows keyboard traversal of widgets in a window.
| [reply] [d/l] |
|
|
Thank you very much for answering.
Actually... I know you guys here are used to get practical tha t need practical, "what to do" questions, but my question is not one of them... :-) Currently I'm much more interested in the theoretical side of the stuff: you have a programming language, which is really very well optimalized for the common case, f.e. the archetypical
while (<>) {
split /;/
programs, which I consider really wonderful and a masterwork of reality-based programming language design. And besides you have a user interface library that totally does not reflect this philosophy. Based on the above example, Perl should have a message function, which if supplied no arguments, then throws a message box of an empty title, a text of $_ , and a button of OK. See my point? That would be perlish.
This is a big contradiction, and I simply don't understand why.
Thanxalot again,
Shenpen | [reply] [d/l] [select] |
Re: Is there a really perlish user interface module, or something?
by hv (Prior) on Aug 09, 2004 at 00:08 UTC
|
I think the main reason you find Tk unperlish is because it isn't actually perl - it is TCL, and perl/Tk is Nick Ing-Simmons' valiant attempt to make the whole of Tk (a large, complex, and entirely TCL-centric library) available to the perl user. I have had very similar reactions to you when using perl/Tk to implement a simple GUI application, enough to put me off trying anything more complex.
I'm not sure why no-one has designed a more perlish programming library for GUIs, but I suspect it is because coming up with a good abstraction for GUIs is hard, and writing the low-level implementation is hard, and finding someone with the right expertise in those two independent domains is inevitably harder still.
If you are considering dragonchild's suggestion, I'd look particularly at the case of perl6 - an exception to prove several rules. It is rare in the open-source world for a well-qualified implementer to volunteer for a project already designed by someone else, as Patrick Michaud has done - most times someone that comes up with a design is ignored unless they also come up with at least a proof-of-concept as implementation.
Look also at the design process: comments were invited far and wide, then Larry went away and did the real design, then some discussion resulted in relatively minor changes to the design. What this is not is design by committee - that only gets you a camel if it was really a horse you needed.
Hugo
| [reply] |
Re: Is there a really perlish user interface module, or something?
by Aristotle (Chancellor) on Aug 09, 2004 at 00:20 UTC
|
Try using Gtk2. The class library is a joy to work with. Glade and Gtk2::GladeXML allow you to design your GUI graphically.
I can't commend the Gtk2-Perl team enough for their superb work brining Gtk+ 2.x to Perl.
Makeshifts last the longest.
| [reply] |
Re: Is there a really perlish user interface module, or something?
by jonadab (Parson) on Aug 09, 2004 at 00:43 UTC
|
But Tk is highly unperlish, IMHO.
I can certainly agree with that. Not only is Tk
unperlish, but it's also unplatformish on many GUI
platforms (unWin32ish on Win32, unMacish on Mac,
unGnomeish on Gnome, and so forth). And that in
itself is unperlish, because Perl goes out of its
way to feel natural on various platforms.
Tk is its own
thing — which is fine as far as it goes,
but that doesn't make it the appropriate tool for
every GUI task, not by a long shot. It's okay for
homebrew stuff that you're going to use yourself, but
I can't imagine deploying a Tk-based GUI to real users.
Even ncurses would be less alien to many people. (I
can think of a GUI toolkit that's even *more* alien
to most people than Tk. It's called Xaw. If you're
not familiar with it, be glad.)
Take, for example, a simple message box. I want to ask my user a simple question. Then I just want to enter something like alert('Are you sure you want to quit?','Yes','No'); and: 1) not necessarily have a parent window 2) if I do have one, then inherit the title from it 3) always have the first button as default 4) have the possibility to change between buttons with the arrows keys and choose with Enter as it's much faster.
It would be easy enough to write a module that uses
one of the available GUIs (Gtk, Win32, Qt, ...) and
provides such an alert function. In fact, if alert
is all that's wanted, it wouldn't even be terribly
hard to write the module so that it would use
whichever of those GUIs was available. I have
thought about doing this, and calling it AnyGUI or
something like that. Of course, this assumes that
the alert function is all you need, and that's a
patently wrong assumption. People would doubtless
keep wanting more and more functionality out of
such a wrapper. (Of course, AnyGUI::Alert could
be kept simple and the more advanced functionality
put in other AnyGUI::Foo modules...)
For myself, I have decided that I currently do not
have time to undertake this project. Alternately, I
don't do enough GUI programming to justify the time
I would spend on it. I can generally get by with
either a commandline interface or CGI/XHTML/CSS,
depending on what I'm doing. YMMV.
I am still holding out hope that Parrot
will provide a decent cross-platform GUI toolkit
that would use the native widgets on whatever platform
it was running on (like wxWindows does), and that a
Perl6 interface to it would be provided that would
feel at home in Perl code. On occasion, it would be
really handy to have a nice Perlish GUI library.
And there are certain kinds of applications that we
really can't write (well) in Perl without this. We
can create modules all day long, OpenOffice,
OpenOffice::Writer, OpenOffice::Calc, et cetera ad
infinitum, but while we can do all kinds of backend
automation things, creating documents automatically
from reports out of databases and that sort of thing,
there are other things we can't do very well, things
that might be better done in Perl than in C/C++/Java,
if only we had a decent GUI kit.
But as far as suggesting one right now, I cannot. I
can tell you what ones are available —
Gtk, Win32::GUI, Qt,
Mac::Carbon, and wx are the
chief ones I know about apart from Tk —
but I cannot tell you that any one of these is
necessarily what you're looking for.
;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print
| [reply] |
Re: Is there a really perlish user interface module, or something?
by dragonchild (Archbishop) on Aug 08, 2004 at 22:18 UTC
|
There isn't one, primarily because no-one has ever cared enough to scratch that itch. I, too, would love to have one, but I use a decent one, called HTML.
I guess I would suggest going ahead and defining what you would like that interface to be. Don't write any code - just a design. Then, post it here for comment and suggestions. Don't be afraid to start small - maybe just what you need. People will add to it. Then, if you're lucky, other people (most likely including you) might go ahead and write the connections between what you want as an interface to Tk or other options. Then, you get to add "Inventor of Blub" to your resume and make a million dollars consulting on how to implement it. :-)
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
| [reply] |
Re: Is there a really perlish user interface module, or something?
by ctilmes (Vicar) on Aug 09, 2004 at 11:25 UTC
|
I agree with the already expressed sentiments about Tk (I've used it a bit and found it useful).
Recently I've been using PerlQt.
The GUI builder (qt designer) is very easy to use and actually works pretty well with Perl.
Here's a program that demonstrates your popup message box:
#!/usr/local/bin/perl
use warnings;
use strict;
use Qt;
my $a = Qt::Application();
my $ret = Qt::MessageBox::information(undef, $0,
'Are you sure you want to quit?'
+,
'Yes', 'No');
exit $ret;
| [reply] [d/l] |
Re: Is there a really perlish user interface module, or something?
by CountZero (Bishop) on Aug 08, 2004 at 21:27 UTC
|
++ for the "Fratres sapientissimi".Update: and the "Fratres Perlis saluto! Update 2: and the ""Fratres reverendissimes"
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] |
Re: Is there a really perlish user interface module, or something?
by Shenpen (Beadle) on Aug 09, 2004 at 19:44 UTC
|
Thank you all very much for answering. I was afraid I am commiting a blasphemy and will receive much flame, now I am very glad have all these friendly and cooperative answers.
To dragonchild: yes, I'am planning to do that. Actually I am much more a software designer than a programmer, so I think I can write a useful spec, but coding this module seems to be beyond my skills. Is a there a spec/design template that the Perl community usually uses, or at least some guidelines how to design Perl modules and start open source projects? And where to post it (besides here)?
To Aristotle and ctilmes: GTK and Qt are useful, of course, the big problem is with portability between Linux and Windows - I use Linux at home and Windows at work - I think this combo is not unheard of ;-) Besides, it also would be important to switch easily (f.e. by a command-line parameter to your program) between GUI and textmode UI, because Perl is often used on Linux servers. I actually don't really like stuff like the Glade designer - IMHO they jacks-of-all-trades and not really optimized for text/data/database applications where Perl excels.
Maybe... maybe there is no need to write a module by hand. Is it possible to make a Perl module from C++ ? From a LIB? If it is, then maybe it is already done.
I will tell you a story.
Long, long ago, in a galaxy far, far away, on a planet called Earth, in a country called Hungary (I am Hungarian) a small company called ComFirm wrote and maintained a very big, hundreds of thousands lines of code banking software called Konto. (No, it was not KDE-based. There still are some words that start with K but have nothing to do with KDE :-)))) ) It was written in Clipper '87. Years gone by and Clipper became obsolete. What to do? Rewrite hundreds of thousands lines of code in another language? No bloody way. They rewrote the language instead. They wrote a precompiler that created C++ code from Clipper code. This was called CCC: Clipper to C++ Compiler. And then the CCC compiler developed on and on, drifted a little bit farther from Clipper, closer to Linux, etc. It is a really cool stuff, I would use it if had a decent regexp engine (this is what I like most in Perl) and would not be supported by only 2 guys. But the important stuff is the UI now. From traditional Clipper code for browse, mask, alert and achoice, the CCC Compiler by a simple compilation directive can compile Linux textmode, Linux FLTK GUI (Fast Light ToolKit), HP-Unix and Solaris textmode, Windows console and Windows GUI and even DOS textmode user interface. By creating LIBs, it may be possible to create Perl modules. Is it? It's C++, not C!
cum venerationie,
Shenpen | [reply] |
|
|
Wx (wxWidgets) is a really nice cross-platform GUI library that uses Gtk, Motif or the platform's native widgets (Win32, MacOS). It has a nice Perl interface, and a very nice GUI designer (wxGlade).
| [reply] |