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

Dear Monks,

I must confess that I am not a good friend of GUIs. Programming them are tedious and boring (without any ``IDE''). I like very much command line interface, and those hard-to-remember-unix-flavored options...

Indeed, destiny is ironic, and now, I'm Writting an application that must have a Graphical User Interface, of course i've choose to make it in perl.
So for now I'm wondering what perl module can be my best election (I need a simple background image, a progress bar, and some text).

My app, its a very simple one, so i'm considering to use the Xlibs to create a window and paint over there my image ... my problem is that xlibs do not have the appropiate 'progress bar widget', so i must mix it with some other module/toolkit/library ... definitely, a little bit nasty thing ...

Fellow PerlMongers, i would appreciate your oppinions, conseils, recommendations, etc ... for doing this task
Thanks in advance

turo

PD: i do not discard ncurses :-P, but i think that is an bizarre thing to put an image on the background

perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'

Replies are listed 'Best First'.
Re: Graphical User Interface && Perl
by zentara (Cardinal) on Dec 26, 2005 at 19:49 UTC
    Here are a couple of simple examples to help you decide. As you can see, the real problem is how to work your application's output into the progress callback. You can use a IO::Select callback on filehandles, or Tk's fileevent, or many other options. First is a simple Tk example, followed by a better Gtk2 mini-tutorial.

    I'm not really a human, but I play one on earth. flash japh
      Jesus Zentara!, are you human? hahahaha

      I suppose i made a mistake for not giving more details about what i wanted to do; sorry for that. What i wanted to know is which perl modules for graphical user interface are the best ones (or the most easy to use).
      I think, you have convinced me, with the Gtk2 :) ...

      I want my app (i should say part of my app) to get an Ip address using dhcp (worse case, this process takes about a minute). For mataining the user informed, i wanted to show a progress bar for avoiding the user desperation.

      ... $w = CreateWindow(...); # full screen window DrawBackgroundPicture($w,'file.jpg'); $p = CreateProgressBar($w, \&timer); RenderAndPrint("Waiting for a new Ip address", 'verdana'); $p -> Start(); $_ = `dhclient -e eth0 2>&1`; ($ip) = /bound to (\d+\.\d+\.\d+\.\d+)/; $p -> Stop (); unless ( $? ) { NextScreen(...); #we must introduce manual config } else { MsgBox("Configured correctly ..."); } NextScreen(...); #Next Task ... ...

      I will re-read your code, and put my hands-on the Gtk2 stuff. Thanks a lot.

      turo

      perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'
        Jesus Zentara!, are you human?

        Don't be in awe my friend,.... I'm bored, underemployed, and have alot of examples at my disposal. :-)


        I'm not really a human, but I play one on earth. flash japh
Re: Graphical User Interface && Perl
by zentara (Cardinal) on Dec 26, 2005 at 19:32 UTC
    Tk or Gtk2 is your easiest route. Your problem is how to design your app so that it remains responsive while your progressbar updates. There are a few commonly used methods, depending on how you will monitor the program to be run. If you can give more information, monks here can show you a way to do the callback. SDL is more for fast graphics, and would essentially involve reinventing the wheel, to make a progressbar using it.

    So are you going to run your program through a piped open, IPC, thread, or what?

    P.S. If you want an excellent intro to Gtk2, see novell-study-guide


    I'm not really a human, but I play one on earth. flash japh
Re: Graphical User Interface && Perl
by zentara (Cardinal) on Dec 26, 2005 at 22:37 UTC
    Well with your code outline, I can see a problem with using backticks. What will happen, is when you open your window and start your progressbar, things will run fine until you run the backticked program. At that point, the GUI will stop updating (freeze)as the backtick is run. SO.... you have some options.

    1. Run the backticked program in a thread, and signal back to the main GUI when it is done, through a shared variable, or a return value.

    2. If the dhcp client puts out debug information, while it is searching, you can use a "piped open" instead of backticks, and use select or fileevent on the filehandle, and that select callback can be used to update the gui, or tell it when to quit.

    3. You could run the Gtk activity mode progressbar in it's own separate thread. You would have a main script, which starts a thread with the mindless activity indicator going , then run the backticked program from the main script, and the line after it, kill and join the indicator thread.


    I'm not really a human, but I play one on earth. flash japh

      opps, i forgot ...
      I will launch a thread for controlling the progress ... Umm, its a good idea to use the ''popen'' (i didn't thought how can i make the progress bar 'progress' ... so it can be a good thing to take the output, or so, and sums up the current value of the progress bar).

      Thanks again ^_^>

      turo

      PS: I'm reading the tutorial you sent, seems to be pretty cool ...
      PSS: be carefull brother, boring and vice come together :-P ... A master like you may not have problems to find something to do; good luck!

      perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'
Re: Graphical User Interface && Perl
by astroboy (Chaplain) on Dec 27, 2005 at 21:10 UTC