-
Notifications
You must be signed in to change notification settings - Fork 0
/
steno-ui.pl
executable file
·72 lines (66 loc) · 1.76 KB
/
steno-ui.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl
#See https://docstore.mik.ua/orelly/perl3/tk/index.htm
use warnings;
use strict;
use Tk;
use File::stat;
use Fcntl;
binmode STDOUT, ":utf8";
use utf8;
use JSON;
my $data;
{
local $/;
open my $fh, "<", "test.json";
$data = <$fh>;
close $fh;
}
my $json = decode_json($data);
my $mw = tkinit;
$mw->update;
my $number;
my $filename = 'test.json';
my $newUpdateTime;
my $lastUpdateTime = (stat($filename)->mtime);
notify( $mw, "Steno UI started", 2000 );
my $ui = $mw->Toplevel();
initUi( $ui, $mw);
$mw->repeat(
2000,
sub {
$newUpdateTime = (stat($filename)->mtime);
if ($newUpdateTime > $lastUpdateTime) {
notify( $mw, "Mode $json->{'mode'} $lastUpdateTime", 2000 );
if ($json->{'command'} eq "close"){
$ui->destroy;
$mw->destroy;
}
if ($json->{'command'} eq "hide"){
}
if ($json->{'command'} eq "show"){
}
$lastUpdateTime = $newUpdateTime;
}
}
);
MainLoop;
sub notify {
my ( $mw, $message, $ms ) = @_;
my $notification = $mw->Toplevel();
$notification->transient($mw);
$notification->overrideredirect(1);
$notification->Popup( -popanchor => 'c' );
$notification->geometry("-0+60");
my $frame = $notification->Frame( -border => 5, -relief => 'groove' )->pack;
$frame->Label( -text => $message, )->pack( -padx => 5 );
$notification->after( $ms, sub { $notification->destroy } );
}
sub initUi {
my ( $ui, $mw ) = @_;
$ui->transient($mw);
$ui->overrideredirect(1);
$ui->Popup( -popanchor => 'c' );
$ui->geometry("-0+20");
my $frame = $ui->Frame( -border => 5, -relief => 'groove' )->pack;
$frame->Label( -text => "Status", )->pack( -padx => 5 );
}