source: extras/pLoader/trunk/src/Uploader/GUI/wxPropertyGridPanel.pm @ 3222

Last change on this file since 3222 was 3222, checked in by ronosman, 15 years ago

Missing wxPropertyGridPanel.

  • Property svn:eol-style set to LF
File size: 5.0 KB
Line 
1# +-----------------------------------------------------------------------+
2# | pLoader - a Perl photo uploader for Piwigo                            |
3# +-----------------------------------------------------------------------+
4# | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
5# +-----------------------------------------------------------------------+
6# | This program is free software; you can redistribute it and/or modify  |
7# | it under the terms of the GNU General Public License as published by  |
8# | the Free Software Foundation                                          |
9# |                                                                       |
10# | This program is distributed in the hope that it will be useful, but   |
11# | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13# | General Public License for more details.                              |
14# |                                                                       |
15# | You should have received a copy of the GNU General Public License     |
16# | along with this program; if not, write to the Free Software           |
17# | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18# | USA.                                                                  |
19# +-----------------------------------------------------------------------+
20package Uploader::GUI::wxPropertyGridPanel;
21use strict;
22use Wx qw/
23             wxDefaultSize
24             wxDefaultPosition
25         /;
26
27use base qw/Wx::Grid Uploader::Object2/;
28
29use Wx::Event qw/
30   EVT_GRID_CMD_CELL_CHANGE
31/;
32use Data::Dumper;
33
34__PACKAGE__->mk_accessors(     
35    qw/
36        frame_callbacks
37        renderer
38        editor
39        properties
40      /
41);
42
43
44
45sub new {
46    my ($this, $params) = @_;
47    #on recupere le nom de la classe en fonction du type d'appel de la méthode.
48    my $class = ref($this) || $this;
49
50
51    my $self = $class->SUPER::new( $params->{parentwnd}, -1, wxDefaultPosition, wxDefaultSize );
52
53    $self->renderer(
54        {
55            Bool     => sub { Wx::GridCellBoolRenderer->new },
56            Number   => sub { Wx::GridCellNumberRenderer->new },
57            LongText => sub { Wx::GridCellAutoWrapStringRenderer->new },
58        }
59    );
60
61    $self->editor(
62        {
63            Bool   => sub { Wx::GridCellBoolEditor->new },
64            Number => sub { Wx::GridCellNumberEditor->new },
65            Choice => sub { Wx::GridCellChoiceEditor->new(@_) },
66            LongText => sub { Wx::GridCellAutoWrapStringEditor->new },
67        }
68    );
69
70    $self->properties(
71        $params->{properties}
72    );
73   
74    # a frame callback for each property
75    $self->frame_callbacks(
76        $params->{frame_callbacks}
77    );
78   
79    $self->Initialize;
80     
81    EVT_GRID_CMD_CELL_CHANGE( $self, $self, \&OnCellChanged );
82    $self;   
83}
84
85sub Initialize {
86    my ( $self ) = @_; 
87
88
89  $self->CreateGrid( scalar @{$self->properties}, 2 );
90 
91
92  $self->SetRowLabelSize(0);
93  $self->SetColLabelSize(0);
94  $self->SetColSize( 0, 200 );
95  $self->SetColSize( 1, 200 );
96 
97  $self->_init_property_grid();
98
99}
100
101sub Refresh {
102    my ( $self ) = @_;
103   
104    $self->ClearGrid;
105
106    my $row = 0;
107    map {
108        eval {
109
110            $self->SetCellValue(
111                $row,
112                0,
113                $_->{label},
114            ); 
115
116
117            $self->SetCellValue(
118                $row,
119                1,
120                $_->{value}->(),
121            ); 
122
123
124
125        };
126        $row++;
127    }@{$self->properties};
128       
129}
130
131sub _init_property_grid {
132    my ( $self ) = @_;
133
134    my $row = 0;
135    #print Dumper $self->properties;
136    map {
137        eval {
138            $self->SetCellEditor(
139                $row,
140                1,
141                &{
142                    sub { $self->editor->{
143                        $_->{type}
144                    }->( $_->{choice} ) },
145                },         
146            ) if $self->editor->{$_->{type}};
147
148            $self->SetCellRenderer(
149                $row,
150                1,
151                &{
152                    $self->renderer->{
153                        $_->{type}
154                    }
155                },         
156            ) if $self->renderer->{$_->{type}};
157
158            $self->SetReadOnly(
159                $row,
160                0,
161            );
162
163            $self->SetCellValue(
164                $row,
165                0,
166                $_->{label},
167            ); 
168
169            $self->SetCellValue(
170                $row,
171                1,
172                $_->{value}->(),
173            ); 
174
175            $self->SetReadOnly(
176                $row,
177                1,
178            ) if $_->{readonly};       
179
180
181        };
182        $row++;
183    }@{$self->properties};
184       
185}
186
187sub OnCellChanged {
188    my ( $self, $event ) = @_;
189
190    my( $row, $col ) = ( 
191        $event->GetRow,
192        $event->GetCol,
193    );
194   
195    my $value = $self->GetCellValue(
196        $row,
197        $col,
198    );
199   
200    # set property
201    $self->properties->[$row]->{value}->($value);
202
203    $self->properties->[$row]->{value}->($value);
204   
205    # execute the corresponding frame callback
206    $self->frame_callbacks->[$row]->() if defined $self->frame_callbacks->[$row];
207}
208
209
2101;
Note: See TracBrowser for help on using the repository browser.