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

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

merge back r4321, sorry for the mistake

  • Property svn:eol-style set to LF
File size: 5.4 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         /;
26use Wx::Locale qw/:default/;
27use base qw/Wx::Grid 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      /
39);
40
41
42
43sub new {
44    my ($this, $params) = @_;
45    #on recupere le nom de la classe en fonction du type d'appel de la méthode.
46    my $class = ref($this) || $this;
47
48
49    my $self = $class->SUPER::new( $params->{parentwnd}, -1, wxDefaultPosition, wxDefaultSize );
50
51    $self->renderer(
52        {
53            Bool     => sub { Wx::GridCellBoolRenderer->new },
54            Number   => sub { Wx::GridCellNumberRenderer->new },
55            Float    => sub { Wx::GridCellFloatRenderer->new(-1, 2) },
56            LongText => sub { Wx::GridCellAutoWrapStringRenderer->new },
57        }
58    );
59
60    $self->editor(
61        {
62            Bool     => sub { Wx::GridCellBoolEditor->new },
63            Number   => sub { Wx::GridCellNumberEditor->new },
64            Float    => sub { Wx::GridCellFloatEditor->new(-1, 2) },
65            Choice   => sub { Wx::GridCellChoiceEditor->new(@_) },
66            LongText => sub { Wx::GridCellAutoWrapStringEditor->new },
67        }
68    );
69
70
71    $self->properties(
72        $params->{properties}
73    );
74   
75    $self->Initialize;
76     
77    EVT_GRID_CMD_CELL_CHANGE( $self, $self, \&OnCellChanged );
78    $self;   
79}
80
81sub Initialize {
82    my ( $self ) = @_; 
83
84
85  $self->CreateGrid( scalar @{$self->properties}, 2 );
86 
87
88  $self->SetRowLabelSize(0);
89  $self->SetColLabelSize(0);
90  $self->SetColSize( 0, 200 );
91  $self->SetColSize( 1, 200 );
92 
93  $self->_init_property_grid();
94
95}
96
97sub Refresh {
98    my ( $self ) = @_;
99   
100    $self->ClearGrid;
101
102    my $row = 0;
103    map {
104        eval {
105
106            $self->SetCellValue(
107                $row,
108                0,
109                $_->{label},
110            ); 
111
112
113            $self->SetCellValue(
114                $row,
115                1,
116                exists $_->{choice} ? gettext($_->{value}->()) : $_->{value}->(),
117            ); 
118
119
120
121        };
122        $row++;
123    }@{$self->properties};
124       
125}
126
127sub _init_property_grid {
128    my ( $self ) = @_;
129
130    my $row = 0;
131    #print Dumper $self->properties;
132    map {
133        eval {
134            $self->SetCellEditor(
135                $row,
136                1,
137                &{
138                    sub { $self->editor->{
139                        $_->{type}
140                    }->( $_->{choice} ) },
141                },         
142            ) if $self->editor->{$_->{type}};
143
144            $self->SetCellRenderer(
145                $row,
146                1,
147                &{
148                    $self->renderer->{
149                        $_->{type}
150                    }
151                },         
152            ) if $self->renderer->{$_->{type}};
153
154            $self->SetReadOnly(
155                $row,
156                0,
157            );
158
159            $self->SetCellValue(
160                $row,
161                0,
162                $_->{label},
163            ); 
164
165            $self->SetCellValue(
166                $row,
167                1,
168                exists $_->{choice} ? gettext($_->{value}->()) : $_->{value}->(),
169            ); 
170
171            $self->SetReadOnly(
172                $row,
173                1,
174            ) if $_->{readonly};       
175
176
177        };
178        $row++;
179    }@{$self->properties};
180       
181}
182
183sub OnCellChanged {
184    my ( $self, $event ) = @_;
185
186    my( $row, $col ) = ( 
187        $event->GetRow,
188        $event->GetCol,
189    );
190   
191    my $value = $self->GetCellValue(
192        $row,
193        $col,
194    );
195
196    # if we need to preprocess the value
197    $value = $self->properties->[$row]->{pre_process}->($value) if exists
198        $self->properties->[$row]->{pre_process}; 
199
200    # set property
201    $self->properties->[$row]->{value}->($value);
202printf("property value %s\n",     $self->properties->[$row]->{value}->());
203   
204    # execute the corresponding frame callback
205    $self->properties->[$row]->{frame_callback}->() if exists
206        $self->properties->[$row]->{frame_callback}; 
207}
208
209
2101;
Note: See TracBrowser for help on using the repository browser.