source: extensions/pLoader/trunk/src/Uploader/GUI/DlgCommon.pm @ 4475

Last change on this file since 4475 was 4475, checked in by ronosman, 14 years ago

Feature 1318 added : new photo properties panel with Piwigo metadata and tags.

File size: 3.0 KB
Line 
1package Uploader::GUI::DlgCommon;
2use strict;
3
4use base qw/
5               Class::Accessor::Fast
6           /; 
7
8__PACKAGE__->mk_accessors(     
9    qw/
10        properties
11      /
12);
13
14sub InitHandler {
15    my ( $self ) = @_;
16
17        # to connect the right event handler to each control
18        my $ctrl_handlers = {
19            'Wx::TextCtrl' => sub { my ( $ctrl ) = @_; Wx::Event::EVT_TEXT( $ctrl, $ctrl, sub { $self->OnTextCtrl(@_) } ); },
20        };
21       
22        map {
23        my $ctrl =$self->FindWindow($_);
24        if(defined $ctrl){
25                    $ctrl_handlers->{ ref $ctrl}->($ctrl) if exists $ctrl_handlers->{ ref $ctrl};
26                }
27    }
28        keys %{$self->properties};
29       
30
31}
32
33# what does happen when the text changes
34sub OnTextCtrl {
35    my ( $self, $ctrl, $event ) = @_;
36       
37        printf("OnTextCtrl %s, %s\n", $ctrl->GetId, $event->GetString);
38    my $id = $ctrl->GetId;
39    # change the property value
40        $self->properties->{$id}->{value}->(
41        $event->GetString
42    ) if exists $self->properties->{$id}->{value};
43
44    # exec the callback
45    $self->properties->{$id}->{frame_callback}->() if exists
46        $self->properties->{$id}->{frame_callback};     
47       
48}
49
50my $change_value = {
51    'Wx::TextCtrl' => sub { my ($ctrl, $value ) = @_; $ctrl->ChangeValue($value)},
52    'Wx::CheckBox' => sub { my ($ctrl, $value ) = @_; $ctrl->SetValue($value)},
53};     
54
55sub SetProperties {
56    my ( $self ) = @_;
57       
58        map {
59        my $ctrl =$self->FindWindow($_);
60        #printf("ctrl %s : %s\n", $_, $ctrl);           
61        if(defined $ctrl){
62                # checkbox, static text
63            $change_value->{ref $ctrl}->(
64                        $ctrl,
65                $self->properties->{$_}->{value}->()
66                    ) if exists $self->properties->{$_}->{value};
67                    # only works for control with items
68                    $ctrl->SetSelection(
69                        $self->properties->{$_}->{selection}->()                       
70                    ) if exists $self->properties->{$_}->{selection};
71                }
72    }
73        keys %{$self->properties};
74}
75
76sub InitLabels {
77    my ( $self ) = @_;
78       
79        map {
80        my $ctrl =$self->FindWindow($_);
81        #printf("ctrl %s : %s\n", $_, $ctrl);           
82        if(defined $ctrl){
83                # checkbox, static text
84                    $ctrl->SetLabel(
85               $self->properties->{$_}->{label}
86                    ) if exists $self->properties->{$_}->{label};
87               
88            # radiobox
89            my $labels =$self->properties->{$_}->{labels};
90                    $labels||=[];
91                    for(my $i=0; $i < scalar @$labels ; $i++){
92                        $ctrl->SetItemLabel($i, $labels->[$i]);
93                    }
94                }
95    }
96        keys %{$self->properties};
97
98}
99
100sub GetProperties {
101    my ( $self ) = @_;
102
103        map {
104        my $ctrl = $self->FindWindow($_);
105        #printf("ctrl %s : %s\n", $_, $ctrl);           
106        if(defined $ctrl){
107                # checkbox, static text
108
109        $self->properties->{$_}->{value}->(
110            $ctrl->GetValue()
111                ) if exists $self->properties->{$_}->{value};
112
113        $self->properties->{$_}->{selection}->(
114                    $ctrl->GetSelection()                       
115                ) if exists $self->properties->{$_}->{selection};
116               
117                }
118    }
119        keys %{$self->properties};
120}
121
1221;
Note: See TracBrowser for help on using the repository browser.