Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Feedback for programming a UI in Perl

by james28909 (Deacon)
on Aug 29, 2016 at 00:43 UTC ( [id://1170641]=note: print w/replies, xml ) Need Help??


in reply to Feedback for programming a UI in Perl

If you have already dove into Wx, I would suggest sticking with it. once you learn the syntax it is actually pretty easy to use. Im sure everyone will have their own opinion though!
  • Comment on Re: Feedback for programming a UI in Perl

Replies are listed 'Best First'.
Re^2: Feedback for programming a UI in Perl
by stevieb (Canon) on Aug 29, 2016 at 01:13 UTC

    code snips welcome:

    • two or more panels
    • if a trigger is on, text green, off, text red
    • display small image

    If you're recommending one UI distribution over another, for this thread, I'd like real-world examples as to why. Particularly, situations where documentation of any dist excels beyond others.

      I usually use Tk or a local webserver. If you want to see how Tk works and how its code looks like, intall it and run widget . I don't know what you mean by "panel" or "trigger", so I can't show you the snippets.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      There is actually a demo in the distribution im pretty sure. You can always check that out as well.

      EDIT: Also did you see my reply to your other question?

      I don't know what you mean by trigger.

      #!/usr/bin/perl # http://perlmonks.org/?node_id=1170638 use strict; use warnings; use Tk; use Tk::JPEG; use Image::Size; my $file = '../smalltux.gif'; my ($w, $h) = imgsize($file); my $mw = new MainWindow; my $one = $mw->Frame()->pack; my $labelone = $one->Label(-text => 'Panel One', -fg => 'red', )->pack(-side => 'left'); $one->Button(-text => 'On', -command => sub { $labelone->configure(-fg => 'green')}, )->pack(-side => 'left'); $one->Button(-text => 'Off', -command => sub { $labelone->configure(-fg => 'red')}, )->pack(-side => 'left'); my $c = $mw->Canvas(-width => $w, -height => $h )->pack(); my $im = $c->Photo(-file =>$file); $c->createImage(0, 0, -image => $im, -anchor => 'nw'); my $two = $mw->Frame()->pack; my $labeltwo = $two->Label(-text => 'Panel One', -fg => 'red', )->pack(-side => 'left'); $two->Button(-text => 'On', -command => sub { $labeltwo->configure(-fg => 'green')}, )->pack(-side => 'left'); $two->Button(-text => 'Off', -command => sub { $labeltwo->configure(-fg => 'red')}, )->pack(-side => 'left'); MainLoop;

        I like Tk because it lets me write a 15 puzzle in 15 lines :)

        #!/usr/bin/perl use Tk; use strict; my @a = map $_->[0], sort {$a->[1] <=> $b->[1]} map [$_, rand], 0..15; my ($mw, $hole) = new MainWindow; sub xy { -row => $_[0] % 4, -column => int $_[0] / 4 } for my $ii (0..15) { my ($num, $i, $but) = ($a[$ii], $ii); $hole = $i, next unless $num; $but = $mw->Button(-text => $num, -width => 2, -height => 2, -comman +d => sub { $but->grid(xy(($i,$hole) = ($hole,$i))) if abs $i - $hole == 4 or abs $i - $hole == 1 and int $i/4 == int $hole/4 })->grid(xy $i); } MainLoop;

        hehehe

        I wrote a Battleship generator for Battleship solitaire puzzle generator

        Then I thought about this node and added the Tk portion for a better display, also clicking a button exposes the data under it.

        #!/usr/bin/perl # http://perlmonks.org/?node_id=1170733 use strict; use warnings; my $sea = (('~' x 10) . "\n") x 10; sub transpose { local $_ = $sea; tr/<>^v/^v<>/; $sea = ''; $sea .= "\n" while s/^(.)/ $sea .= $1; '' /gem; } for my $ship ( 4,3,3,2,2,2,1,1,1,1 ) { my @places; push @places, $-[0] while $sea =~ /(?=~{$ship})/g; substr $sea, $places[rand @places], $ship, ('O', '<>', '<#>', '<##>' )[$ship - 1]; transpose; } 0.5 < rand and transpose; # for random direction start print $sea; my @chars = $sea =~ /./g; use Tk; # for http://perlmonks.org/?node_id=1170638 my $mw = new MainWindow; for my $y (0..9) { for my $x (0..9) { my $char = shift @chars; my $b = $mw->Button( -font => 'courier 24', -text => ' ', )->grid(-row => $y, -column => $x); $b->configure(-command => sub {$b->configure(-text => $char) }); } } MainLoop;

        Oops, typo in second panel

      I too, usually use Tk. There is a simple GU code generator for it called vptk that I also use. Also, I created a menu builder "super widget".

      Also, I've heard good things about the WxWidgets GTK toolkit and the Glade GUI builder for it (there are modules for generating Perl code from Glade description files). Not yet tried it.

      Update: I meant GTK, not WxWidgets.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-24 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found