release 1.14pre1
[descalc.git] / 09_disp_qt.pm
1 # Qt I/O for DCT, by Shiar
2
3 # just fiddling, long way from working
4 # 1.12.0 200411032045 - test
5
6 use strict;
7 use warnings;
8
9 use Qt;
10 use Term::ReadKey;
11
12 =cut
13 my $main;
14
15 push @{$hook{init}}, sub {
16         $main = new MainWindow;
17         $main->Label(-text=>"test")->pack;
18         ReadMode 3;  # cbreak mode
19
20         END {
21                 ReadMode 0;
22         } # restore terminal on quit
23
24 #       $set{height} = $LINES-2 if $LINES>=3;
25 #       $set{width} = $COLS if $COLS;
26 }; # init
27
28 = cut
29 push @{$hook{showerror}}, sub {
30         attron(A_REVERSE);
31         addstr(0, 0, shift);
32         attroff(A_REVERSE);
33         clrtoeol;
34         refresh;
35
36         ReadKey; # wait for confirm
37         1 while defined ReadKey(-1); # clear key buffer
38 }; # showerror
39 = cut
40
41 push @{$hook{showstack}}, sub {
42         my $box = $main->Listbox(
43                 -relief => 'sunken', 
44                 -width => -1,  # shrink to fit
45                 -height => 5,
46                 -setgrid => 'yes',
47         );
48 print Dumper \@stack;
49         for (0..@stack-1) {
50                 $box->insert('end', "$_: ".showval($stack[$_], $set{base}));
51 print $_;
52         }
53         $box->pack(-side => 'left', -fill => 'both', -expand => 'yes');
54 #       for (0..@stack-1) {
55 #               addstr($set{height}-$_, 1, "$_: ".showval($stack[$_], $set{base}));
56 #               clrtoeol;
57 #       } # show stack
58 #       clrtoeol($set{height}-@stack, 1);
59 }; # showstack
60
61 push @{$hook{showall}}, sub {
62 #       clear;
63 #       addstr($set{height}+1, 0, "> ");  # prompt
64         $main->Label(-text=>"> ")->pack;
65 }; # showall
66
67 push @{$hook{showentry}}, sub {
68         $main->Label(-text=>$_[0])->pack;
69 #       addstr($set{height}+1, 2, $_[0]);
70 #       clrtoeol;
71 #       refresh;
72 }; # showentry
73 =cut
74
75 $hook{main} = sub {
76         my $a = Qt::Application;
77         my $hello = Qt::PushButton("Hello World!", undef);
78         $hello->show;
79         $a->setMainWidget($hello);      
80         exit $a->exec;
81
82 =cut
83         my $in = $main->Entry(-width=>10);
84         $in->pack;
85         $main->Button(
86                 -text=>'test', 
87                 -command => sub {
88                         onkey($_) for split //, $in->get;
89                         onkey("enter");
90                 }
91         )->pack;
92 =cut
93
94 #       while (1) {
95 #               draw();
96 #
97 #               my $key = ReadKey;  # wait for user input
98 #               if ($key eq chr 27) {
99 #                       $key .= $_ while defined ($_ = ReadKey(-1));  # read additional keys
100 #               } # escape sequence
101 #
102 #               onkey($key);
103 #       } # input loop
104 }; # main
105
106 return {
107         author  => "Shiar",
108         title   => "qt output",
109         version => "1.12",
110 };
111