in reply to Re: Feedback for programming a UI in Perl in thread Feedback for programming a UI in Perl
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.
Re^3: Feedback for programming a UI in Perl
by choroba (Cardinal) on Aug 29, 2016 at 01:37 UTC
|
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,
| [reply] [d/l] [select] |
Re^3: Feedback for programming a UI in Perl
by james28909 (Deacon) on Aug 29, 2016 at 01:40 UTC
|
| [reply] |
Re^3: Feedback for programming a UI in Perl
by Anonymous Monk on Aug 29, 2016 at 03:34 UTC
|
#!/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;
| [reply] [d/l] |
|
#!/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
| [reply] [d/l] |
|
| [reply] [d/l] |
|
#!/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;
| [reply] [d/l] |
|
| [reply] |
|
|
|
|
| [reply] |
Re^3: Feedback for programming a UI in Perl
by RonW (Parson) on Aug 29, 2016 at 19:14 UTC
|
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.
| [reply] |
|
|