#!/usr/bin/perl # # Alert daemon and GUI v0.0.5 # Copyright (C) 2003, 2004, 2005 Stian Skjæveland # # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # use strict; use Tk; require Tk::Dialog; my ($textentry, $timeentry, $mainwindow, $timelabel, $textlabel, $text, $alert, $mw, $buf, $dialog ); my $wait_sec=10; &main_window(); sub main_window() { $mainwindow=MainWindow->new; $mainwindow->title("$0: Insert data"); $text="Type your message here"; $alert="hh:mm"; $mainwindow->Button(-text => "ok", -command => \&alert_window)->pack(-side => 'right'); $mainwindow->Button(-text => "Exit", -command => sub { exit; })->pack(-side => 'right'); $textlabel=$mainwindow->Label(-text => "Text: ")->pack(-side => 'top', -anchor => 'w'); $textentry=$mainwindow->Entry(-textvariable => \$text)->pack(-side => 'top', -anchor => 'w', -fill => 'x', -expand => 1); $timelabel=$mainwindow->Label(-text => "Time: ")->pack(-side => 'top', -anchor => 'w'); $timeentry=$mainwindow->Entry(-textvariable => \$alert)->pack(-side => 'top', -anchor => 'w', -fill => 'x', -expand => 1); MainLoop; } sub alert_window() { if (!($alert=~/(\d\d):(\d\d)/)) { &error_window(); } for (;;) { $buf=`date`; sleep $wait_sec; if ($buf=~/$alert/) { $dialog = $mainwindow->Dialog( -title => "Remember:", -text => $text, -default_button => "ok", ); $dialog->Show; exit(0); } } } sub error_window() { $dialog = $mainwindow->Dialog( -title => "Error", -bitmap => 'error', -text => "Use hh:mm when setting time", -default_button => "ok", ); $dialog->Show; exit(0); }