3 # A GTK based console program
5 # Copyright (c) 2001-6 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 = 'gb7djk.dxcluster.net';
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, xalign => 1.0);
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 $dxlist->set_rules_hint(1);
153 my $dxscroll = Gtk2::ScrolledWindow->new (undef, undef);
154 $dxscroll->set_shadow_type ('etched-out');
155 $dxscroll->set_policy ('never', 'automatic');
156 #$dxscroll->set_size_request (700, 400);
157 $dxscroll->add($dxlist);
158 $dxscroll->set_border_width(5);
159 $lhvbox->pack_start($dxscroll, 1, 1, 0);
162 my $cmdlist = Gtk2::SimpleList->new(
166 my $cmdscroll = Gtk2::ScrolledWindow->new (undef, undef);
167 $cmdscroll->set_shadow_type ('etched-out');
168 $cmdscroll->set_policy ('never', 'automatic');
169 #$cmdscroll->set_size_request (700, 400);
170 $cmdscroll->add($cmdlist);
171 $cmdscroll->set_border_width(5);
172 $lhvbox->pack_start($cmdscroll, 1, 1, 0);
175 # nice little separator
176 $lhvbox->pack_start(Gtk2::HSeparator->new, 0, 1, 0 );
178 # callsign and current date and time
179 my $hbox = new Gtk2::HBox;
180 my $calllabel = new Gtk2::Label($call);
181 my $date = new Gtk2::Label(cldatetime(time));
182 $date->{tick} = Glib::Timeout->add(1000, \&updatetime, 0);
183 $hbox->pack_start( $calllabel, 0, 1, 0 );
184 $hbox->pack_end($date, 0, 1, 0);
185 $lhvbox->pack_start($hbox, 0, 1, 0);
186 $lhvbox->pack_start(Gtk2::HSeparator->new, 0, 1, 0);
189 my $bot = new Gtk2::Entry;
190 $bot->set_editable(1);
191 $bot->signal_connect('activate', \&bothandler);
192 $bot->can_default(1);
193 $lhvbox->pack_end($bot, 0, 1, 0);
201 my $annlist = Gtk2::SimpleList->new(
205 Announcement => 'tt',
207 $annlist->set_rules_hint(1);
208 my $annscroll = Gtk2::ScrolledWindow->new (undef, undef);
209 $annscroll->set_shadow_type ('etched-out');
210 $annscroll->set_policy ('automatic', 'automatic');
211 #$annscroll->set_size_request (700, 400);
212 $annscroll->add($annlist);
213 $annscroll->set_border_width(5);
214 $rhvbox->pack_start($annscroll, 0, 1, 0);
217 my $wwvlist = Gtk2::SimpleList->new(
226 $wwvlist->set_rules_hint(1);
227 my $wwvscroll = Gtk2::ScrolledWindow->new (undef, undef);
228 $wwvscroll->set_shadow_type ('etched-out');
229 $wwvscroll->set_policy ('never', 'automatic');
230 #$wwvscroll->set_size_request (700, 200);
231 $wwvscroll->add($wwvlist);
232 $wwvscroll->set_border_width(5);
233 $rhvbox->pack_start($wwvscroll, 1, 1, 0);
236 my $wcylist = Gtk2::SimpleList->new(
249 $wcylist->set_rules_hint(1);
250 my $wcyscroll = Gtk2::ScrolledWindow->new (undef, undef);
251 $wcyscroll->set_shadow_type ('etched-out');
252 $wcyscroll->set_policy ('never', 'automatic');
253 #$wcyscroll->set_size_request (700, 200);
254 $wcyscroll->add($wcylist);
255 $wcyscroll->set_border_width(5);
256 $rhvbox->pack_start($wcyscroll, 1, 1, 0);
258 my $sock_helper = Gtk2::Helper->add_watch($sock->fileno, 'in', \&tophandler, $sock);
272 $date->set_text(cldatetime(time));
278 my ($self, $data) = @_;
279 my $msg = $self->get_text;
290 my ($fd, $condx, $socket) = @_;
292 my $offset = length $rbuf;
293 my $l = sysread($socket, $rbuf, 1024, $offset);
296 while ($rbuf =~ s/^([^\015\012]*)\015?\012//) {
314 # this is truely evil and I bet there is a better way...
317 if ($line =~ /^'\w{2,4}',/) {
318 $list = eval qq([$line]);
320 $list = ['cmd', $line];
324 my $cmd = shift @$list;
325 my $handle = "handle_$cmd";
326 if (__PACKAGE__->can($handle)) {
327 __PACKAGE__->$handle($list);
330 __PACKAGE__->handle_def($list);
339 my ($t, $ts) = (time, '');
341 $s = ref $ref ? join ', ',@$ref : $ref;
343 if (($cmdscroll->{lasttime}||0) != $t) {
345 $cmdscroll->{lasttime} = $t;
349 push @{$cmdlist->{data}}, [$ts, $s];
357 $s = ref $ref ? join ', ',@$ref : $ref;
358 my ($t, $ts) = (time, '');
360 if (($cmdscroll->{lasttime}||0) != $t) {
362 $cmdscroll->{lasttime} = $t;
366 push @{$cmdlist->{data}}, [$ts, $s];
373 my ($t, $ts) = (time, '');
375 if (($dxscroll->{lasttime}||0) != $t) {
377 $dxscroll->{lasttime} = $t;
379 push @{$dxlist->{data}}, [$ts, @$ref[0,1,15,3,4,16], stim($ref->[2]) ];
387 my ($t, $ts) = (time, '');
389 $s = ref $ref ? join ', ',@$ref : $ref;
391 if (($annscroll->{lasttime}||0) != $t) {
393 $annscroll->{lasttime} = $t;
397 push @{$annlist->{data}}, [$ts, @$ref[0,1,2]];
405 $s = ref $ref ? join ', ',@$ref : $ref;
408 push @{$wcylist->{data}}, [tim(), @$ref[10,4,5,3,6,2,7,8,9,1] ];
416 $s = ref $ref ? join ', ',@$ref : $ref;
419 push @{$wwvlist->{data}}, [tim(), @$ref[6,2,3,4,5,1] ];
434 my ($let, $msg) = @_;
435 # $msg =~ s/([\%\x00-\x1f\x7f-\xff])/sprintf("%%%02X", ord($1))/eg;
436 # $sock->print("$let$call|$msg\n");
437 $sock->print("$msg\n");
442 my $t = shift || time;
443 return sprintf "%02d:%02d:%02d", (gmtime($t))[2,1,0];
448 my $t = shift || time;
449 return sprintf "%02d:%02d", (gmtime($t))[2,1];