As part of my MacOS X conference tutorial (Programming Perl on MacOS X), I want to show off my Mac::iTunes module which does various iTunes sorts of things from Perl.
Mac::iTunes can communicate with iTunes through AppleScript, which can be really handy, and now that it works decently, I can finally control iTunes remotely (Apache module in the works...). Within my home network I can use my Tk version of iTunes (which I will release after I show it off at MacOS X Conference---register now to see if before it makes it to CPAN!).
The problem with programming user interfaces is that you have to program user interfaces. Since I add to Mac::iTunes as I find features I want in TkiTunes, the actions of my button widgets get really complex.
The basic button creation is a simple Tk construct that sets a few attributes and packs the widget.
$frame->Button( -text => $title, -command => $sub, -background => "#$color", )->pack( -anchor => 'w', -side => 'top', -fill => 'both', );
my $sub = sub {
$Controller->play;
$State->reset_time;
$State->reset_scale;
...
};
%Actions = (
play => sub { $C->play },
pause => sub { $C->pause },
back_track => sub { $C->back_track },
'next' => sub { $C->next },
previous => sub { $C->previous },
stop => sub { $C->stop },
reset_time => sub { ... },
reset_scale => sub { ... },
);
my @pipeline = qw(play reset_time reset_scale);
my $sub = make_action( \@pipeline );
sub make_action { my $pipeline = shift;
my $sub = sub { foreach my $action ( @$pipeline ) { $Actions{$action}->(); } };
return $sub; }