Hardware-iButton

 view release on metacpan or  search on metacpan

examples/buttonmaster.pl  view on Meta::CPAN

#			       print "event: foo\n";
#			       });
    $clist->signal_connect("select_row", 
#			   sub {
#			       my($list, $row, $col, $event) = @_;
#			       print "row $row selected\n";
#			       }
			   \&handle_select,
			  );
#    $clist->signal_connect("button_press_event", \&press);
    $clist->signal_connect("click_column", \&sortby);
    $clist->show(); 
    $vbox->pack_start($clist, 1, 1, 0);

    $status = Gtk::Statusbar->new();
    #$status->set_usize(100, -1); # -1 means leave height alone
    $status->show(); 
    $vbox->pack_start($status, 0, 0, 0);
    
    my $hbox = Gtk::HBox->new(0,0);
    $hbox->show();
    $vbox->pack_start($hbox, 0, 0, 2);

    my $quit_button = Gtk::Widget->new("GtkButton",
				       -label => "Quit",
				       -clicked => sub { $mw->destroy; },
				       -visible => 1);
    $quit_button->show();
    $hbox->pack_start($quit_button, 1, 0, 2);
    my $about_button = Gtk::Widget->new("GtkButton",
					-label => "About",
				       -clicked => \&do_about,
				       -visible => 1);
    $about_button->show();
    $hbox->pack_start($about_button, 1, 0, 2);
    $scan_button = Gtk::Widget->new("GtkButton",
				    -label => "Scan",
				    -clicked => \&do_scan,
				    -visible => 1);
    $scan_button->show();
    $hbox->pack_start($scan_button, 1, 0, 2);
    $vbox->show();
    $mw->add($vbox);
    $mw->show();
}

sub clear_ref {
    my($widget, $ref) = @_;
    $$ref = undef;
    0;
}

my $aboutbox;
sub do_about {
    # put up an about box
    if ($aboutbox) {
	print "hey, cut it out\n";
	return; # don't do it twice
    }
    $aboutbox = Gtk::Widget->new("GtkWindow",
				 -type => 'toplevel', # toplevel, dialog, popup
				 # popup: no decorations, at 0,0
				 # dialog: decorations, at 0,0
				 # toplevel: decorations, normal placement
				 -title => 'about',
				);
    my $vbox = Gtk::VBox->new(0,0);
    my $text = Gtk::Label->new("iButton Master\nby\nBrian Warner\n<warner\@lothar.com>");
    #$text->border_width(5); # labels can't do this
    $text->show();
    $vbox->pack_start($text, 1, 1, 0);
    my $button = Gtk::Widget->new("GtkButton",
				  -label => "Dismiss",
				  -visible => 1,
				  -border_width => 2,
				 );
    # when the box gets destroyed, clear the $aboutbox variable so that we
    # know to rebuild it next time
    $aboutbox->signal_connect("destroy", \&clear_ref, \$aboutbox);
    # when the button gets hit, tell $aboutbox to destroy itself
    $button->signal_connect("clicked", sub {$aboutbox->destroy});
				  
    $button->show();
    $vbox->pack_start($button, 1, 1, 2);
    $vbox->show();
    $aboutbox->add($vbox);
    $aboutbox->show();
}
				      

$scan_context = $status->get_context_id("scan context");

sub do_scan {
    $status->push($scan_context, "scanning.."); # this doesn't quite work..
    # update screen
    while(Gtk::Gdk->events_pending) {
	Gtk->main_iteration();
    }
    @buttons = $c->scan();
    $status->pop($scan_context);
    sortby("dummy", $sort_order);
}

#my(@buttons) = ({ serial => "000001CE65EF",
#		  model => "DS1996",
#		  family => "1C",
#		 },
#		{ serial => "000003FF8902", 
#		  model => "DS1920",
#		  family => "04",
#		},
#		{ serial => "000235AA65EF", 
#		  model => "Javabutton", 
#		  family => "14",
#		},
#	       );

$sort_order = 0;

sub sortby {
    my($list, $col) = @_;
    # $col was clicked. Rearrange the rows to sort by that column.



( run in 2.491 seconds using v1.01-cache-2.11-cpan-364913b4093 )