Changeset 4569 for extensions/pLoader/trunk/src/Uploader/GUI/DlgCommon.pm
- Timestamp:
- Dec 27, 2009, 9:28:03 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/pLoader/trunk/src/Uploader/GUI/DlgCommon.pm
r4478 r4569 2 2 use strict; 3 3 use Wx::Calendar; 4 use Wx::Locale qw/:default/; 4 5 5 6 use base qw/ … … 16 17 my ( $self ) = @_; 17 18 18 # to connect the right event handler to each control 19 my $ctrl_handlers = { 20 'Wx::TextCtrl' => sub { my ( $ctrl ) = @_; Wx::Event::EVT_TEXT( $ctrl, $ctrl, sub { $self->OnTextCtrl(@_) } ); }, 21 'Wx::Choice' => sub { my ( $ctrl ) = @_; Wx::Event::EVT_CHOICE( $ctrl, $ctrl, sub { $self->OnChoice(@_) } ); }, 22 'Wx::DatePickerCtrl' => sub { my ( $ctrl ) = @_; Wx::Event::EVT_DATE_CHANGED( $ctrl, $ctrl, sub { $self->OnDatePicker(@_) } ); }, 23 }; 24 25 map { 26 my $ctrl =$self->FindWindow($_); 27 if(defined $ctrl){ 28 $ctrl_handlers->{ ref $ctrl}->($ctrl) if exists $ctrl_handlers->{ ref $ctrl}; 29 } 30 } 31 keys %{$self->properties}; 32 33 34 } 19 # to connect the right event handler to each control 20 my $ctrl_handlers = { 21 'Wx::SpinCtrl' => sub { my ( $ctrl ) = @_; Wx::Event::EVT_SPINCTRL( $ctrl, $ctrl, sub { $self->OnSpinCtrl(@_) } ); }, 22 'Wx::TextCtrl' => sub { my ( $ctrl ) = @_; Wx::Event::EVT_TEXT( $ctrl, $ctrl, sub { $self->OnTextCtrl(@_) } ); }, 23 'Wx::Choice' => sub { my ( $ctrl ) = @_; Wx::Event::EVT_CHOICE( $ctrl, $ctrl, sub { $self->OnChoice(@_) } ); }, 24 'Wx::CheckBox' => sub { my ( $ctrl ) = @_; Wx::Event::EVT_CHECKBOX( $ctrl, $ctrl, sub { $self->OnCheckBox(@_) } ); }, 25 'Wx::DatePickerCtrl' => sub { my ( $ctrl ) = @_; Wx::Event::EVT_DATE_CHANGED( $ctrl, $ctrl, sub { $self->OnDatePicker(@_) } ); }, 26 }; 27 28 map { 29 my $ctrl =$self->FindWindow($_); 30 if(defined $ctrl){ 31 $ctrl_handlers->{ ref $ctrl}->($ctrl) if exists $ctrl_handlers->{ ref $ctrl}; 32 33 $ctrl->SetValidator( 34 $self->properties->{$_}->{validator} 35 ) if exists $self->properties->{$_}->{validator}; 36 } 37 } 38 keys %{$self->properties}; 39 40 41 } 42 43 # what does happen when the text changes 44 sub OnCheckBox { 45 my ( $self, $ctrl, $event ) = @_; 46 47 my $id = $ctrl->GetId; 48 # change the property value 49 $self->properties->{$id}->{value}->( 50 $event->IsChecked 51 ) if exists $self->properties->{$id}->{value}; 52 53 # exec the callback 54 $self->properties->{$id}->{frame_callback}->($self, $ctrl, $event) if exists 55 $self->properties->{$id}->{frame_callback}; 56 57 $event->Skip; 58 } 59 35 60 36 61 # what does happen when the text changes 37 62 sub OnTextCtrl { 38 63 my ( $self, $ctrl, $event ) = @_; 39 40 my $id = $ctrl->GetId; 41 # change the property value 42 64 65 my $id = $ctrl->GetId; 66 # change the property value 67 $self->properties->{$id}->{value}->( 43 68 $event->GetString 44 69 ) if exists $self->properties->{$id}->{value}; 45 70 46 71 # exec the callback 47 $self->properties->{$id}->{frame_callback}->() if exists 48 $self->properties->{$id}->{frame_callback}; 49 50 } 72 $self->properties->{$id}->{frame_callback}->($self, $ctrl, $event) if exists 73 $self->properties->{$id}->{frame_callback}; 74 75 $event->Skip; 76 } 77 78 sub OnSpinCtrl { 79 my ( $self, $ctrl, $event ) = @_; 80 81 my $id = $ctrl->GetId; 82 # change the property value 83 $self->properties->{$id}->{value}->( 84 $event->GetInt 85 ) if exists $self->properties->{$id}->{value}; 86 87 # exec the callback 88 $self->properties->{$id}->{frame_callback}->($self, $ctrl, $event) if exists 89 $self->properties->{$id}->{frame_callback}; 90 91 $event->Skip; 92 } 93 51 94 52 95 sub OnChoice { 53 96 my ( $self, $ctrl, $event ) = @_; 54 55 my $id = $ctrl->GetId; 56 # change the property value 57 $self->properties->{$id}->{selection}->( 58 $event->GetSelection 97 98 my $id = $ctrl->GetId; 99 100 # if a preprocess value is required 101 my $value = exists $self->properties->{$id}->{string_selection} ? $event->GetString : $event->GetSelection; 102 $value = $self->properties->{$id}->{pre_process}->( $value ) if exists 103 $self->properties->{$id}->{pre_process}; 104 # change the property value. use the index selection 105 $self->properties->{$id}->{selection}->( 106 $value 59 107 ) if exists $self->properties->{$id}->{selection}; 60 108 61 # exec the callback 62 $self->properties->{$id}->{frame_callback}->() if exists 63 $self->properties->{$id}->{frame_callback}; 64 109 # change the property value. use the string 110 $self->properties->{$id}->{string_selection}->( 111 $value 112 ) if exists $self->properties->{$id}->{string_selection}; 113 114 # exec the callback 115 $self->properties->{$id}->{frame_callback}->($self, $ctrl, $event) if exists 116 $self->properties->{$id}->{frame_callback}; 117 118 $event->Skip; 65 119 } 66 120 67 121 sub OnDatePicker { 68 122 my ( $self, $ctrl, $event ) = @_; 69 70 my $id = $ctrl->GetId; 71 72 # change the property value 73 123 124 my $id = $ctrl->GetId; 125 126 # change the property value 127 $self->properties->{$id}->{value}->( 74 128 $event->GetDate->FormatISODate 75 129 ) if exists $self->properties->{$id}->{value}; 76 130 # exec the callback 77 $self->properties->{$id}->{frame_callback}->() if exists 78 $self->properties->{$id}->{frame_callback}; 79 131 $self->properties->{$id}->{frame_callback}->($self, $ctrl, $event) if exists 132 $self->properties->{$id}->{frame_callback}; 133 134 $event->Skip; 80 135 } 81 136 82 137 83 138 my $change_value = { 139 'Wx::SpinCtrl' => sub { my ($ctrl, $value ) = @_; $ctrl->SetValue($value)}, 84 140 'Wx::TextCtrl' => sub { my ($ctrl, $value ) = @_; $ctrl->ChangeValue($value)}, 85 141 'Wx::CheckBox' => sub { my ($ctrl, $value ) = @_; $ctrl->SetValue($value)}, 86 142 'Wx::DatePickerCtrl' => sub { my ($ctrl, $value ) = @_; 87 my $date = Wx::DateTime->new; 143 my $date = Wx::DateTime->new; 88 144 my ($yyyy, $mm, $dd, $hh, $mi, $ss ) = split(/[:\/\\\-\.\s]/, $value); 89 90 91 92 93 94 }; 145 $date->ParseDate( 146 sprintf("%s/%s/%s", $yyyy, $mm, $dd) 147 ); 148 $ctrl->SetValue($date); 149 }, 150 }; 95 151 96 152 my $clear_value = { … … 98 154 'Wx::CheckBox' => sub { my ($ctrl) = @_; $ctrl->SetValue(0)}, 99 155 'Wx::DatePickerCtrl' => sub { my ($ctrl) = @_; $ctrl->SetValue(Wx::DateTime->new->SetToCurrent)}, 100 }; 156 }; 101 157 102 158 sub SetProperties { 103 159 my ( $self ) = @_; 104 105 106 my $ctrl =$self->FindWindow($_); 107 if(defined $ctrl){ 108 160 161 map { 162 my $ctrl =$self->FindWindow($_); 163 if(defined $ctrl){ 164 # checkbox, static text 109 165 $change_value->{ref $ctrl}->( 110 166 $ctrl, 111 167 $self->properties->{$_}->{value}->() 112 ) if exists $self->properties->{$_}->{value}; 113 # only works for control with items 114 $ctrl->SetSelection( 115 $self->properties->{$_}->{selection}->() 116 ) if exists $self->properties->{$_}->{selection}; 117 } 118 } 119 keys %{$self->properties}; 168 ) if exists $self->properties->{$_}->{value}; 169 # only works for control with items 170 $ctrl->SetSelection( 171 $self->properties->{$_}->{selection}->() 172 ) if exists $self->properties->{$_}->{selection}; 173 174 $ctrl->SetStringSelection( 175 gettext( 176 $self->properties->{$_}->{string_selection}->() 177 ) 178 ) if exists $self->properties->{$_}->{string_selection}; 179 } 180 } 181 keys %{$self->properties}; 120 182 } 121 183 122 184 sub InitLabels { 123 185 my ( $self ) = @_; 124 125 126 my $ctrl =$self->FindWindow($_) ;127 #printf("ctrl %s : %s\n", $_, $ctrl); 128 if(defined $ctrl){ 129 130 186 187 map { 188 my $ctrl =$self->FindWindow($_)||$self->{$_}; 189 #printf("ctrl %s : %s\n", $_, $ctrl); 190 if(defined $ctrl){ 191 # checkbox, static text 192 $ctrl->SetLabel( 131 193 $self->properties->{$_}->{label} 132 ) if exists $self->properties->{$_}->{label}; 133 194 ) if exists $self->properties->{$_}->{label}; 195 196 $ctrl->GetStaticBox->SetLabel( 197 $self->properties->{$_}->{staticbox_label} 198 ) if exists $self->properties->{$_}->{staticbox_label}; 199 134 200 # radiobox 135 201 my $labels =$self->properties->{$_}->{labels}; 136 137 138 139 140 141 } 142 202 $labels||=[]; 203 for(my $i=0; $i < scalar @$labels ; $i++){ 204 $ctrl->SetItemLabel($i, $labels->[$i]); 205 } 206 } 207 } 208 keys %{$self->properties}; 143 209 144 210 } … … 147 213 my ( $self ) = @_; 148 214 149 150 my $ctrl =$self->FindWindow($_); 151 #printf("ctrl %s : %s\n", $_, $ctrl); 215 map { 216 my $ctrl =$self->FindWindow($_); 217 #printf("ctrl %s : %s\n", $_, $ctrl); 152 218 if(defined $ctrl){ 153 219 # choice 154 220 my $choices =$self->properties->{$_}->{choices}; 155 156 157 158 159 160 } 161 221 $choices||=[]; 222 map{ 223 $ctrl->Append($_); 224 }@$choices; 225 } 226 } 227 keys %{$self->properties}; 162 228 163 229 } … … 166 232 my ( $self ) = @_; 167 233 168 234 map { 169 235 my $ctrl = $self->FindWindow($_); 170 #printf("ctrl %s : %s\n", $_, $ctrl); 171 if(defined $ctrl){ 172 236 #printf("ctrl %s : %s\n", $_, $ctrl); 237 if(defined $ctrl){ 238 # checkbox, static text 173 239 $self->properties->{$_}->{value}->( 174 240 $ctrl->GetValue() 175 241 ) if exists $self->properties->{$_}->{value}; 176 242 177 243 $self->properties->{$_}->{selection}->( 178 $ctrl->GetSelection() 179 ) if exists $self->properties->{$_}->{selection}; 180 } 181 } 182 keys %{$self->properties}; 244 $ctrl->GetSelection() 245 ) if exists $self->properties->{$_}->{selection}; 246 247 $self->properties->{$_}->{string_selection}->( 248 $ctrl->GetStringSelection() 249 ) if exists $self->properties->{$_}->{string_selection}; 250 } 251 } 252 keys %{$self->properties}; 183 253 } 184 254 185 255 sub ClearProperties { 186 256 my ( $self ) = @_; 187 188 189 my $ctrl =$self->FindWindow($_); 190 if(defined $ctrl){ 191 257 258 map { 259 my $ctrl =$self->FindWindow($_); 260 if(defined $ctrl){ 261 # checkbox, static text 192 262 $clear_value->{ref $ctrl}->( 193 $ctrl 194 ) if exists $clear_value->{ref $ctrl}; 195 # only works for control with items 196 $ctrl->SetSelection( 197 -1 198 ) if exists $self->properties->{$_}->{selection}; 199 } 200 } 201 keys %{$self->properties}; 263 $ctrl 264 ) if exists $clear_value->{ref $ctrl}; 265 # only works for control with items 266 $ctrl->SetSelection( 267 -1 268 ) if exists $self->properties->{$_}->{selection}; 269 } 270 271 $ctrl->SetStringSelection( 272 -1 273 ) if exists $self->properties->{$_}->{string_selection}; 274 } 275 keys %{$self->properties}; 202 276 203 277 }
Note: See TracChangeset
for help on using the changeset viewer.