#!/usr/bin/perl use Gtk; use Lamp; init Gtk; set_locale Gtk; my $False = 0; my $True = 1; LampInit('192.168.45.3'); $ChannelName[0]='TL'; $ChannelName[1]='Christmas lights'; $ChannelName[2]='Mail light'; $ChannelName[3]='Webcam power'; $ChannelName[4]='Christmas tree'; $ChannelName[5]=''; $ChannelName[6]='Curtain motor direction'; $ChannelName[7]='Curtain motor power'; $Wnd = new Gtk::Window('toplevel'); $Wnd->signal_connect('delete_event',\&EventCloseWindow); $Wnd->set_title('Lamp client Perl-GTK GUI'); $VBox = new Gtk::VBox($False,0); $Wnd->add($VBox); for $Channel (0..7) { $ButtonRow = new Gtk::HButtonBox(); $ButtonRow->border_width(5); $ButtonRow->set_layout('start'); $ButtonRow->set_spacing(3); $ButtonRow->show(); for $Command (on,blink,off) { $But = new Gtk::Button($Command); $But->signal_connect('clicked',\&EventButtonClick,$Channel,$Command); $But->show(); $ButtonRow->add($But); } $Name=$ChannelName[$Channel]; if ($Name ne '') { $Frame = new Gtk::Frame("Channel ${Channel} - ${Name}"); } else { $Frame = new Gtk::Frame("Channel ${Channel}"); } $VBox->pack_start($Frame,$True,$True,4); $Frame->add($ButtonRow); } # window attributes $Wnd->border_width(15); $Wnd->show(); $Wnd->show_all(); # Gtk event loop main Gtk; exit(0); sub EventCloseWindow { Gtk->exit(0); } sub EventButtonClick { local ($Button,$Lamp,$Command) = @_; print "set ${Lamp} to ${Command}\n"; LampSet($Lamp,$Command,'default'); }