Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

GUI with clickable/selectable single-line messages

by fcvw (Novice)
on Apr 26, 2005 at 09:58 UTC ( [id://451478]=perlquestion: print w/replies, xml ) Need Help??

fcvw has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I need to build a special server with a GUI, running on *nix and win32 (and maybe the mac). The server I made is working fine. The problem is the GUI. I started with Perl/Tk, but there are some difficulties with the events: the data from the different clients (on different threads) producing single-line messages must be shown on the GUI. The messages must be clickable/selectable to display additional information. Using wxWidgets might be a better option, but I have absolutely no experience with wx and not much time to learn it. Can anyone give me advice on how build a rapid prototype, with the possibility to "get it right/nice"?

Thanks for any help. F.

update: thank you all very much for the advice and *the code*! I will give it all a try.

Edited by Arunbear: Changed title from 'which GUI?', as per Monastery guidelines

Replies are listed 'Best First'.
Re: GUI with clickable/selectable single-line messages
by zentara (Archbishop) on Apr 26, 2005 at 11:43 UTC
    I would bet that Tk can do what you want. Your problem of having single line messages, being clickable, and a callback to display additional data is doable a few ways in Tk. Can you show us some code? If I was going to try an do it, I would print the results to a text widget, and create custom tags for each line printed, and tag that line. Then have a balloon, or mouse enter/clicked bindings on the tags, to display the extra data associated with that line. Here is an example, where you can store "meta-data" for each line, in a tag(or hash), and pop that data up in a balloon when that tagged-line is clicked or enetered. You could also do it with a Canvas, if you wanted to add some graphics.

    This example shows just the basics, I print the data to stdout, instead of a balloon or a toplevel extra-info window. Also, I create 100 tags in a simple loop, but in your situation, you will wnat to tagconfigure each tag, for each line, as they come in and are printed.

    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $t = $mw->Scrolled('Text', -scrollbars => 'osoe' )->pack; for(1..100){ $t->tagConfigure( 'data'.$_, -data => $_ x 20, ); } for(1..100){ $t->insert('end', 'Line'."$_\n", ['datarider','data'.$_ ]); } $t->tagBind( 'datarider', '<Enter>', sub { getdata($t) } ); $t->tagBind( 'datarider', '<Leave>', sub { getdata($t) } ); $t->bind( '<Motion>', sub{ getdata($t) } ); MainLoop; sub getdata { my ( $text_widget ) = @_; my $x = $text_widget->pointerx - $text_widget->rootx; my $y = $text_widget->pointery - $text_widget->rooty; #print "$x $y\n"; my $txt_index = $text_widget->index( '@' . $x . ',' . $y ); #warn $txt_index; my ( $line, $char ) = ( $txt_index =~ /^(.+?)\.(.+?)$/ ); my @tags = $text_widget->tagNames($txt_index); print "@tags\n"; foreach my $tag(@tags){ print $text_widget->tagCget($tag,'data'),"\n"; } }

    I'm not really a human, but I play one on earth. flash japh
Re: GUI with clickable/selectable single-line messages
by samizdat (Vicar) on Apr 26, 2005 at 12:46 UTC
    wx is very cross-platform friendly, but I agree that it has a steeper learning curve. Not sure you can do much on any Win < 2K.

    If the server is acting as a clearinghouse, i.e., the events are reported to it first, the GUI should not have any problems reporting them. If you are in a hurry, that's the first change I'd make: route the messages through a port on the server. Then the GUI becomes much simpler.

    As far as elegance, either way you need to have a resident daemon/process queue with a known address to gather messages. Whether that's an adjunct to your existing server or another process, the function needs to be provided.
Re: GUI with clickable/selectable single-line messages
by Jouke (Curate) on Apr 26, 2005 at 17:58 UTC
    Usually Tk is the easiest way to go. If being platform independent, though still looking native is important, wxWidgets (wxPerl) is the way to go.

    If you're worried about the learningcurve, you could try wxGlade, which allows you to build a GUI easily, and let it generate the code for you.

    You might find the (GUI) Windows Programming FAQ useful...


    Jouke Visser
    Using Perl to enable the disabled: pVoice

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://451478]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-29 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found