]> scm.dxcluster.org Git - spider.git/blob - gtkconsole/Screen.pm
add CTY-2705 prefixes
[spider.git] / gtkconsole / Screen.pm
1 #
2 # This produces the Gtk for all the little sub-screens
3 #
4 #
5 #
6 # Copyright (c) 2006 Dirk Koopman G1TLH
7 #
8
9 use strict;
10
11 package Screen;
12
13 use Gtk2;
14 use Gtk2::SimpleList;
15 use Text::Wrap;
16
17 INIT {
18         Gtk2::SimpleList->add_column_type( 'qrg',
19                                                                            type     => 'Glib::Scalar',
20                                                                            renderer => 'Gtk2::CellRendererText',
21                                                                            attr     => sub {
22                                                                                    my ($treecol, $cell, $model, $iter, $col_num) = @_;
23                                                                                    my $info = $model->get ($iter, $col_num);
24                                                                                    $cell->set(text => sprintf("%.1f", $info), xalign => 1.0);
25                                                                            }
26                                                                          );
27
28
29         Gtk2::SimpleList->add_column_type( 'tt',
30                                                                            type     => 'Glib::Scalar',
31                                                                            renderer => 'Gtk2::CellRendererText',
32                                                                            attr     => sub {
33                                                                                    my ($treecol, $cell, $model, $iter, $col_num) = @_;
34                                                                                    my $info = $model->get ($iter, $col_num);
35                                                                                    $cell->set(text => $info);
36                                                                            }
37                                                                          );
38
39         Gtk2::SimpleList->add_column_type( 'ttlong',
40                                                                            type     => 'Glib::Scalar',
41                                                                            renderer => 'Gtk2::CellRendererText',
42                                                                            attr     => sub {
43                                                                                    my ($treecol, $cell, $model, $iter, $col_num) = @_;
44                                                                                    my $info = $model->get ($iter, $col_num);
45                                                                                    $Text::Wrap::columns = 80;
46                                                                                    $cell->set(text => join("\n",wrap("","",$info)));
47                                                                            }
48                                                                          );
49
50         Gtk2::SimpleList->add_column_type( 'ttlesslong',
51                                                                            type     => 'Glib::Scalar',
52                                                                            renderer => 'Gtk2::CellRendererText',
53                                                                            attr     => sub {
54                                                                                    my ($treecol, $cell, $model, $iter, $col_num) = @_;
55                                                                                    my $info = $model->get ($iter, $col_num);
56                                                                                    $Text::Wrap::columns = 65;
57                                                                                    $cell->set(text => join("\n",wrap("","",$info)));
58                                                                            }
59                                                                          );
60
61         Gtk2::SimpleList->add_column_type( 'ttshort',
62                                                                            type     => 'Glib::Scalar',
63                                                                            renderer => 'Gtk2::CellRendererText',
64                                                                            attr     => sub {
65                                                                                    my ($treecol, $cell, $model, $iter, $col_num) = @_;
66                                                                                    my $info = $model->get ($iter, $col_num);
67                                                                                    $Text::Wrap::columns = 30;
68                                                                                    $cell->set(text => join("\n",wrap("","",$info)));
69                                                                            }
70                                                                          );
71
72 }
73
74 sub new
75 {
76         my $pkg = shift;
77         my $class = ref $pkg || $pkg;
78         return bless {@_}, $class;
79 }
80
81 sub widget
82 {
83         return $_[0]->{widget};
84 }
85
86 1;
87
88 package Screen::List;
89
90 our @ISA = qw(Screen);
91
92 sub _row_inserted
93 {
94         my ($liststore, $path, $iter, $self) = @_;
95         $self->{list}->scroll_to_cell($path);
96 }
97
98 sub new
99 {
100         my $pkg = shift;
101         my %args = @_;
102
103         my $list = Gtk2::SimpleList->new(@{$args{fields}});
104         $list->set_rules_hint(1) if $args{hint};
105         $list->set_name($args{pkgname} || __PACKAGE__);
106
107         my $scroll = Gtk2::ScrolledWindow->new (undef, undef);
108         $scroll->set_shadow_type ($args{shadow_type} || 'etched-out');
109         $scroll->set_policy (exists $args{policy} ? @{$args{policy}} : qw(automatic automatic));
110         $scroll->set_size_request (@{$args{size}}) if exists $args{size};
111         $scroll->add($list);
112         $scroll->set_border_width(exists $args{border_width} ? $args{border_width} : 2);
113
114         my $self = $pkg->SUPER::new(scroller => $scroll, list => $list, widget => $scroll, maxsize => ($args{maxsize} || 100));
115
116         $list->get_model->signal_connect('row-inserted', \&_row_inserted, $self);
117
118         if ($args{frame}) {
119                 my $frame = Gtk2::Frame->new($args{frame});
120                 $frame->add($scroll);
121                 $self->{widget} = $self->{frame} = $frame;
122         }
123         return $self;
124 }
125
126 sub add_data
127 {
128         my $self = shift;
129         my $list = $self->{list};
130
131         push @{$list->{data}}, ref $_[0] ? $_[0] : [ @_ ];
132         shift @{$list->{data}} if @{$list->{data}} > $self->{maxsize};
133 }
134 1;