source: extensions/pLoader/trunk/src/Uploader/GUI/wxPropertyGridPanel.pm @ 4779

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

Change copyright notice to add 2010.

  • Property svn:eol-style set to LF
File size: 5.6 KB
Line 
1# +-----------------------------------------------------------------------+
2# | pLoader - a Perl photo uploader for Piwigo                            |
3# +-----------------------------------------------------------------------+
4# | Copyright(C) 2008-2010 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         /;
26use Wx::Locale qw/:default/;
27use base qw/Wx::Dialog Uploader::Object2/;
28
29use Wx::Event qw/
30   EVT_GRID_CMD_CELL_CHANGE
31/;
32use Data::Dumper;
33__PACKAGE__->mk_accessors(     
34    qw/
35        renderer
36        editor
37        properties
38        grid
39      /
40);
41
42
43
44sub new {
45    my ($this, $params) = @_;
46    #on recupere le nom de la classe en fonction du type d'appel de la méthode.
47    my $class = ref($this) || $this;
48
49
50    my $self = $class->SUPER::new( undef, -1, "PropertyGrid", wxDefaultPosition, wxDefaultSize );
51    $self->grid(
52        Wx::Grid->new($self, -1, wxDefaultPosition, wxDefaultSize)
53    );
54
55    $self->renderer(
56        {
57            Bool     => sub { Wx::GridCellBoolRenderer->new },
58            Number   => sub { Wx::GridCellNumberRenderer->new },
59            Float    => sub { Wx::GridCellFloatRenderer->new(-1, 2) },
60            LongText => sub { Wx::GridCellAutoWrapStringRenderer->new },
61        }
62    );
63
64    $self->editor(
65        {
66            Bool     => sub { Wx::GridCellBoolEditor->new },
67            Number   => sub { Wx::GridCellNumberEditor->new },
68            Float    => sub { Wx::GridCellFloatEditor->new(-1, 2) },
69            Choice   => sub { Wx::GridCellChoiceEditor->new(@_) },
70            LongText => sub { Wx::GridCellAutoWrapStringEditor->new },
71        }
72    );
73
74
75    $self->properties(
76        $params->{properties}
77    );
78   
79    $self->Initialize;
80     
81    EVT_GRID_CMD_CELL_CHANGE( $self, $self->grid, \&OnCellChanged );
82    $self;   
83}
84
85sub Initialize {
86    my ( $self ) = @_; 
87
88
89  $self->grid->CreateGrid( scalar @{$self->properties}, 2 );
90 
91
92  $self->grid->SetRowLabelSize(0);
93  $self->grid->SetColLabelSize(0);
94  $self->grid->SetColSize( 0, 200 );
95  $self->grid->SetColSize( 1, 200 );
96 
97  $self->_init_property_grid();
98
99}
100
101sub Refresh {
102    my ( $self ) = @_;
103   
104    $self->grid->ClearGrid;
105
106    my $row = 0;
107    map {
108        eval {
109
110            $self->grid->SetCellValue(
111                $row,
112                0,
113                $_->{label},
114            ); 
115
116
117            $self->grid->SetCellValue(
118                $row,
119                1,
120                exists $_->{choice} ? gettext($_->{value}->()) : $_->{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->grid->SetCellEditor(
139                $row,
140                1,
141                &{
142                    sub { $self->editor->{
143                        $_->{type}
144                    }->( $_->{choice} ) },
145                },         
146            ) if $self->editor->{$_->{type}};
147
148            $self->grid->SetCellRenderer(
149                $row,
150                1,
151                &{
152                    $self->renderer->{
153                        $_->{type}
154                    }
155                },         
156            ) if $self->renderer->{$_->{type}};
157
158            $self->grid->SetReadOnly(
159                $row,
160                0,
161            );
162
163            $self->grid->SetCellValue(
164                $row,
165                0,
166                $_->{label},
167            ); 
168
169            $self->grid->SetCellValue(
170                $row,
171                1,
172                exists $_->{choice} ? gettext($_->{value}->()) : $_->{value}->(),
173            ); 
174
175            $self->grid->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->grid->GetCellValue(
196        $row,
197        $col,
198    );
199
200    # if we need to preprocess the value
201    $value = $self->properties->[$row]->{pre_process}->($value) if exists
202        $self->properties->[$row]->{pre_process}; 
203
204    # set property
205    $self->properties->[$row]->{value}->($value);
206printf("property value %s\n",     $self->properties->[$row]->{value}->());
207   
208    # execute the corresponding frame callback
209    $self->properties->[$row]->{frame_callback}->() if exists
210        $self->properties->[$row]->{frame_callback}; 
211}
212
213
2141;
Note: See TracBrowser for help on using the repository browser.