use strict; use Wx qw(:everything); use Wx::Perl::Carp; use XML::Simple; package Content_App; use vars '@ISA'; @ISA = 'Wx::App'; sub OnInit { my $self = shift; my $frame = MyTreeChecker_Frame->new('Wx::Perl::TreeChecker', Wx::wxDefaultPosition(), [450,450]); $self -> SetTopWindow ($frame); $frame -> Show(1); 1; } package MyTreeChecker_Frame; use vars '@ISA'; @ISA = 'Wx::Frame'; use Wx qw(:sizer :misc wxOK wxICON_INFORMATION wxBITMAP_TYPE_ICO wxID_ANY); use Wx::Perl::TreeChecker; sub new { my $class = shift; my ($title, $pos, $size) = @_; my $self = $class->SUPER::new (undef, -1, $title, $pos, $size); $self -> SetIcon (Wx::Icon->new("Resources\\Graphics\\main.ico", wxBITMAP_TYPE_ICO)); my $filemenu = new Wx::Menu; my $menubar = new Wx::MenuBar; $filemenu -> Append (1, 'E&xit'); $menubar -> Append ($filemenu, '&File'); $self -> SetMenuBar ($menubar); use Wx::Event 'EVT_MENU', 'EVT_BUTTON', 'EVT_RIGHT_UP', 'EVT_RIGHT_DOWN', 'EVT_TREE_ITEM_RIGHT_CLICK'; EVT_MENU ($self, 1, \&OnQuit); EVT_MENU ($self, 2, \&OnToggleMultiple); EVT_MENU ($self, 3, \&OnToggleItems); EVT_MENU ($self, 4, \&OnToggleContainers); EVT_MENU ($self, 5, \&OnToggleSelectAll); my $panel = new Wx::Panel ($self); my $sizer = new Wx::BoxSizer (wxVERTICAL); $self -> {treechecker} = new Wx::Perl::TreeChecker ($panel, -1, wxDefaultPosition, wxDefaultSize); $sizer -> Add ($self -> {treechecker}, 1, wxGROW); $panel -> SetSizer ($sizer); $self -> fill_treechecker(); EVT_RIGHT_DOWN ( $self->{treechecker} , \&RightClickMenu); $self->{treechecker}->items_only(1); $self->{treechecker} -> allow_multiple(0); Wx::Event::EVT_TREELIST_ITEM_EXPANDING($self, $self->{treechecker}, \&OnItemExpanding); Wx::Event::EVT_TREELIST_ITEM_EXPANDED($self, $self->{treechecker}, \&OnItemExpanded); #Wx::Log::SetActiveTarget (new Wx::LogTextCtrl ($self -> {textctrl})); return $self; } sub fill_treechecker { my $self = shift; my $treechecker = $self -> {treechecker}; our %scapHash = (); my $xml = XML::Simple::XMLin("modified_options.xml", ForceArray => 1); foreach my $stream (@{$xml->{contents}}) { for my $content_name (@{$stream->{content}}) { for my $profile (@{$content_name->{profiles}}) { for my $profile_name (@{$profile->{profile}}) { push @{$scapHash{"$content_name->{stream}->[0]"}}, $profile_name; } } } } _populate_tree($treechecker, "", \%scapHash); } sub _populate_tree { my ($tree, $id, $data) = @_; my $root; #recursively build a tree control return unless $data && ref $data; if (ref($data) eq 'HASH') { foreach my $stream (sort keys %$data) { print "\n". $stream . "\n"; my $stream_id = $tree -> AddRoot($stream); #my $container = $tree -> AppendContainer($stream_id, $stream, td($stream)); _populate_tree($tree, $stream_id, $data->{$stream}); } } elsif (ref $data eq 'ARRAY') { foreach my $profile (@$data) { print "\t$profile\n"; $tree-> AppendItem ($id, $profile, td($profile)); } } #$tree -> Expand ($id); } sub td { return new Wx::TreeItemData(shift); } sub OnQuit { my ($self, $evt) = @_; $self -> Close (1); } sub OnToggleMultiple { my ($self, $evt) = @_; my $tree = $self -> {treechecker}; $tree -> UnselectAll(); $tree -> allow_multiple($evt->IsChecked); } sub OnToggleItems { my ($self, $evt) = @_; my $tree = $self -> {treechecker}; $tree -> UnselectAll(); $tree -> containers_only(0); $tree -> items_only(1); } sub OnToggleContainers { my ($self, $evt) = @_; my $tree = $self -> {treechecker}; $tree -> UnselectAll(); $tree -> items_only(0); $tree -> containers_only(1); } sub OnToggleSelectAll { my ($self, $evt) = @_; my $tree = $self -> {treechecker}; $tree -> UnselectAll(); $tree -> items_only(1); $tree -> containers_only(0); } sub RightClickMenu { my( $self, $event ) = @_; my $menu = Wx::Menu->new( "" ); $menu->Append(7, "Select All", sub {$self->{treechecker}->UnselectAll(); $self->{treechecker}->items_only(1);}); $menu->AppendSeparator(); $menu->Append(8, "Clear All", sub {$self->{treechecker}->UnselectAll(); $self->{treechecker}->items_only(1);} ); $self->PopupMenu( $menu , $event->GetX, $event->GetY); } sub OnItemExpanded { my ($self, $event) = @_; my $item = $event->GetItem; my $itemtext = $self->{treechecker}->GetItemText($item); print('Evt Item has expanded : %s', $itemtext); } sub OnItemExpanding { my ($self, $event) = @_; my $item = $event->GetItem; my $itemtext = $self->{treechecker}->GetItemText($item); print "\n $itemtext"; Wx::LogMessage('Evt Item is expanding : %s', $itemtext); } ############################################################################## package main; my $sample = new Content_App; $sample -> MainLoop; #### 2017-03-30T10:07:38 stream_1 no_profile_selected profile_1 stream_2 no_profile_selected profile_1 stream_3 profile_1 profile_2 profile_3 profile_4 profile_5 stream_4 profile_1 profile_1 profile_2 profile_3 profile_4 profile_5 stream_5 profile_1 profile_2 profile_3 profile_4 profile_5 stream_6 profile_1 profile_2 profile_3 profile_4 profile_5 stream_7 profile_1 profile_2 profile_3 profile_4 profile_5