3 # A GTK based console program
5 # Copyright (c) 2001 Dirk Koopman G1TLH
10 # search local then perl directories
12 # root of directory tree for this system
14 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
16 unshift @INC, "$root/perl"; # this IS the right way round!
17 unshift @INC, "$root/gtkconsole";
18 unshift @INC, "$root/local";
28 use vars qw(@modules $font);
30 @modules = (); # is the list of modules that need init calling
31 # on them. It is set up by each 'use'ed module
32 # that has Gtk stuff in it
42 my $call = uc shift @ARGV if @ARGV;
43 $call = uc $main::myalias unless $call;
44 my ($scall, $ssid) = split /-/, $call;
45 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
47 $ssid = 15 if $ssid > 15;
48 $call = "$scall-$ssid";
51 die "You cannot connect as your cluster callsign ($main::mycall)\n" if $call eq $main::mycall;
53 my $host = 'localhost';
56 my $sock = IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port);
57 die "Cannot connect to $host/$port ($!)\n" unless $sock;
59 sendmsg('I', 'set/gtk');
60 #sendmsg('A', 'local');
62 sendmsg('I', 'set/page 500');
63 sendmsg('I', 'set/nobeep');
71 # +--------+-------+------------------------------------------------------------------------------------+
73 # +--------+-------+------------------------------------------------------------------------------------+
76 my $main = new Gtk2::Window('toplevel');
77 $main->set_default_size(600, 600);
78 $main->signal_connect('delete_event', sub { Gtk2->main_quit; });
79 $main->set_title("gtkconsole - The DXSpider Console - $call");
82 my $vbox = new Gtk2::VBox(0, 1);
88 {path => '/_File', type => '<Branch>'},
89 {path => '/_File/Quit', callback => sub {Gtk2->main_quit}},
90 {path => '/_Help', type => '<LastBranch>'},
91 {path => '/_Help/About'},
93 my $itemf = new Gtk2::ItemFactory('Gtk2::MenuBar', '<main>');
94 $itemf->create_items(@menu);
95 my $menu = $itemf->get_widget('<main>');
96 $vbox->pack_start($menu, 0, 1, 0);
99 # another hbox is packed as the bottom of the vbox
100 my $bhbox = Gtk2::HBox->new(0, 1);
101 $vbox->pack_end($bhbox, 1, 1, 0);
103 # now pack two vboxes into the hbox
104 my $lhvbox = Gtk2::VBox->new(0, 1);
105 my $rhvbox = Gtk2::VBox->new(0, 1);
106 $bhbox->pack_start($lhvbox, 1, 1, 5);
107 $bhbox->pack_start(Gtk2::VSeparator->new, 0, 1, 0);
108 $bhbox->pack_end($rhvbox, 1, 1, 5);
110 # first add a column type for the QRG
111 my $font = 'monospace 10';
112 my $oddbg = 'light blue';
113 my $evenbg = 'white';
115 Gtk2::SimpleList->add_column_type( 'qrg',
116 type => 'Glib::Scalar',
117 renderer => 'Gtk2::CellRendererText',
119 my ($treecol, $cell, $model, $iter, $col_num) = @_;
120 my $info = $model->get ($iter, $col_num);
121 $cell->set(text => sprintf("%.1f", $info), font => $font);
126 Gtk2::SimpleList->add_column_type( 'tt',
127 type => 'Glib::Scalar',
128 renderer => 'Gtk2::CellRendererText',
130 my ($treecol, $cell, $model, $iter, $col_num) = @_;
131 my $info = $model->get ($iter, $col_num);
132 $cell->set(text => $info, font => $font);
142 my $dxlist = Gtk2::SimpleList->new(
152 my $dxscroll = Gtk2::ScrolledWindow->new (undef, undef);
153 $dxscroll->set_shadow_type ('etched-out');
154 $dxscroll->set_policy ('never', 'automatic');
155 #$dxscroll->set_size_request (700, 400);
156 $dxscroll->add($dxlist);
157 $dxscroll->set_border_width(5);
158 $lhvbox->pack_start($dxscroll, 1, 1, 0);
161 my $cmdlist = Gtk2::SimpleList->new(
165 my $cmdscroll = Gtk2::ScrolledWindow->new (undef, undef);
166 $cmdscroll->set_shadow_type ('etched-out');
167 $cmdscroll->set_policy ('never', 'automatic');
168 #$cmdscroll->set_size_request (700, 400);
169 $cmdscroll->add($cmdlist);
170 $cmdscroll->set_border_width(5);
171 $lhvbox->pack_start($cmdscroll, 1, 1, 0);
174 # nice little separator
175 $lhvbox->pack_start(Gtk2::HSeparator->new, 0, 1, 0 );
177 # callsign and current date and time
178 my $hbox = new Gtk2::HBox;
179 my $calllabel = new Gtk2::Label($call);
180 my $date = new Gtk2::Label(cldatetime(time));
181 $date->{tick} = Glib::Timeout->add(1000, \&updatetime, 0);
182 $hbox->pack_start( $calllabel, 0, 1, 0 );
183 $hbox->pack_end($date, 0, 1, 0);
184 $lhvbox->pack_start($hbox, 0, 1, 0);
185 $lhvbox->pack_start(Gtk2::HSeparator->new, 0, 1, 0);
188 my $bot = new Gtk2::Entry;
189 $bot->set_editable(1);
190 $bot->signal_connect('activate', \&bothandler);
191 $bot->can_default(1);
192 $lhvbox->pack_end($bot, 0, 1, 0);
200 my $annlist = Gtk2::SimpleList->new(
204 Announcement => 'tt',
206 my $annscroll = Gtk2::ScrolledWindow->new (undef, undef);
207 $annscroll->set_shadow_type ('etched-out');
208 $annscroll->set_policy ('automatic', 'automatic');
209 #$annscroll->set_size_request (700, 400);
210 $annscroll->add($annlist);
211 $annscroll->set_border_width(5);
212 $rhvbox->pack_start($annscroll, 0, 1, 0);
215 my $wwvlist = Gtk2::SimpleList->new(
224 my $wwvscroll = Gtk2::ScrolledWindow->new (undef, undef);
225 $wwvscroll->set_shadow_type ('etched-out');
226 $wwvscroll->set_policy ('never', 'automatic');
227 #$wwvscroll->set_size_request (700, 200);
228 $wwvscroll->add($wwvlist);
229 $wwvscroll->set_border_width(5);
230 $rhvbox->pack_start($wwvscroll, 1, 1, 0);
233 my $wcylist = Gtk2::SimpleList->new(
246 my $wcyscroll = Gtk2::ScrolledWindow->new (undef, undef);
247 $wcyscroll->set_shadow_type ('etched-out');
248 $wcyscroll->set_policy ('never', 'automatic');
249 #$wcyscroll->set_size_request (700, 200);
250 $wcyscroll->add($wcylist);
251 $wcyscroll->set_border_width(5);
252 $rhvbox->pack_start($wcyscroll, 1, 1, 0);
254 my $sock_helper = Gtk2::Helper->add_watch($sock->fileno, 'in', \&tophandler, $sock);
268 $date->set_text(cldatetime(time));
274 my ($self, $data) = @_;
275 my $msg = $self->get_text;
286 my ($fd, $condx, $socket) = @_;
288 my $offset = length $rbuf;
289 my $l = sysread($socket, $rbuf, 1024, $offset);
292 while ($rbuf =~ s/^([^\015\012]*)\015?\012//) {
310 # this is truely evil and I bet there is a better way...
313 if ($line =~ /^'\w{2,4}',/) {
314 $list = eval qq([$line]);
316 $list = ['cmd', $line];
320 my $cmd = shift @$list;
321 my $handle = "handle_$cmd";
322 if (__PACKAGE__->can($handle)) {
323 __PACKAGE__->$handle($list);
326 __PACKAGE__->handle_def($list);
335 my ($t, $ts) = (time, '');
337 $s = ref $ref ? join ', ',@$ref : $ref;
339 if (exists $cmdlist->{lasttime} != $t) {
341 $cmdlist->{lasttime} = $t;
345 push @{$cmdlist->{data}}, [$ts, $s];
353 $s = ref $ref ? join ', ',@$ref : $ref;
354 my ($t, $ts) = (time, '');
356 if (exists $cmdlist->{lasttime} != $t) {
358 $cmdlist->{lasttime} = $t;
362 push @{$cmdlist->{data}}, [$ts, $s];
369 my ($t, $ts) = (time, '');
371 if (exists $dxlist->{lasttime} != $t) {
373 $dxlist->{lasttime} = $t;
375 push @{$dxlist->{data}}, [$ts, @$ref[0,1,15,3,4,16], stim($ref->[2]) ];
383 my ($t, $ts) = (time, '');
385 $s = ref $ref ? join ', ',@$ref : $ref;
387 if (exists $cmdlist->{lasttime} != $t) {
389 $cmdlist->{lasttime} = $t;
393 push @{$cmdlist->{data}}, [$ts, @$ref[0,1,2]];
401 $s = ref $ref ? join ', ',@$ref : $ref;
404 push @{$cmdlist->{data}}, [tim(), @$ref[10,4,5,3,6,2,7,8,9,1] ];
412 $s = ref $ref ? join ', ',@$ref : $ref;
415 push @{$cmdlist->{data}}, [tim(), @$ref[6,2,3,4,5,1] ];
430 my ($let, $msg) = @_;
431 # $msg =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
432 # $sock->print("$let$call|$msg\n");
433 $sock->print("$msg\n");
438 my $t = shift || time;
439 return sprintf "%02d:%02d:%02d", (gmtime($t))[2,1,0];
444 my $t = shift || time;
445 return sprintf "%02d:%02d", (gmtime($t))[2,1];