| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: display a Forest::Tree as a gtk tree view |
|
2
|
|
|
|
|
|
|
package Forest::Tree::Viewer::Gtk2; |
|
3
|
1
|
|
|
1
|
|
28405
|
use Gtk2; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Moose; |
|
5
|
|
|
|
|
|
|
has tree=>(is=>'ro'); |
|
6
|
|
|
|
|
|
|
has column_name=>(is=>'ro',default=>"?"); |
|
7
|
|
|
|
|
|
|
sub _append_to_tree_store { |
|
8
|
|
|
|
|
|
|
my ($tree,$tree_store,$parent) = @_; |
|
9
|
|
|
|
|
|
|
my $iter = $tree_store->append($parent); |
|
10
|
|
|
|
|
|
|
$tree_store->set($iter,0=>,$tree->node); |
|
11
|
|
|
|
|
|
|
for (@{$tree->children}) { |
|
12
|
|
|
|
|
|
|
_append_to_tree_store($_,$tree_store,$iter); |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
sub tree_store { |
|
16
|
|
|
|
|
|
|
my ($self) = @_; |
|
17
|
|
|
|
|
|
|
my $tree_store = Gtk2::TreeStore->new(qw/Glib::String/); |
|
18
|
|
|
|
|
|
|
_append_to_tree_store($self->tree,$tree_store); |
|
19
|
|
|
|
|
|
|
$tree_store; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
sub view { |
|
22
|
|
|
|
|
|
|
my ($self) = @_; |
|
23
|
|
|
|
|
|
|
my $tree_view = Gtk2::TreeView->new($self->tree_store); |
|
24
|
|
|
|
|
|
|
$tree_view->append_column (_create_column($self->column_name,0)); |
|
25
|
|
|
|
|
|
|
$tree_view; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
sub _create_column { |
|
29
|
|
|
|
|
|
|
my ($text,$column) = @_; |
|
30
|
|
|
|
|
|
|
my $tree_column = Gtk2::TreeViewColumn->new(); |
|
31
|
|
|
|
|
|
|
$tree_column->set_title ($text); |
|
32
|
|
|
|
|
|
|
my $renderer = Gtk2::CellRendererText->new; |
|
33
|
|
|
|
|
|
|
$tree_column->pack_start ($renderer,'FALSE'); |
|
34
|
|
|
|
|
|
|
$tree_column->add_attribute($renderer, text => $column); |
|
35
|
|
|
|
|
|
|
$tree_column; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
1; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
use Gtk2 -init; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use Forest::Tree; |
|
44
|
|
|
|
|
|
|
use Forest::Tree::Viewer::Gtk2; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $tree = Forest::Tree->new(node=>'root',children=>[ |
|
47
|
|
|
|
|
|
|
Forest::Tree->new(node=>'child1'), |
|
48
|
|
|
|
|
|
|
Forest::Tree->new(node=>'child2'), |
|
49
|
|
|
|
|
|
|
]); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $viewer = Forest::Tree::Viewer::Gtk2->new(tree=>$tree); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# wrap the tree view in a simple gtk2 application |
|
54
|
|
|
|
|
|
|
my $window = Gtk2::Window->new('toplevel'); |
|
55
|
|
|
|
|
|
|
$window->add($viewer->view); |
|
56
|
|
|
|
|
|
|
$window->show_all; |
|
57
|
|
|
|
|
|
|
Gtk2->main; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Forest::Tree::Viewer::Gtk2 - a simple Gtk2 using tree viewer |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=over 4 |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item B<tree> |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The tree we want to display |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=back |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over 4 |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item B<view> |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Return the Gtk2::TreeView for our tree |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item B<tree_store> |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Return the Gtk2::TreeStore for our tree |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=back |
|
86
|
|
|
|
|
|
|
|