Ignore:
Timestamp:
Dec 27, 2009, 9:28:03 AM (14 years ago)
Author:
ronosman
Message:

Feature 1346 added : new global settings management.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/pLoader/trunk/src/Uploader/GUI/DlgCommon.pm

    r4478 r4569  
    22use strict;
    33use Wx::Calendar;
     4use Wx::Locale qw/:default/;
    45
    56use base qw/
     
    1617    my ( $self ) = @_;
    1718
    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
     44sub 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
    3560
    3661# what does happen when the text changes
    3762sub OnTextCtrl {
    3863    my ( $self, $ctrl, $event ) = @_;
    39        
    40     my $id = $ctrl->GetId;
    41     # change the property value
    42         $self->properties->{$id}->{value}->(
     64   
     65    my $id = $ctrl->GetId;
     66    # change the property value
     67    $self->properties->{$id}->{value}->(
    4368        $event->GetString
    4469    ) if exists $self->properties->{$id}->{value};
    4570
    4671    # 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
     78sub 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
    5194
    5295sub OnChoice {
    5396    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
    59107    ) if exists $self->properties->{$id}->{selection};
    60108
    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;
    65119}
    66120
    67121sub OnDatePicker {
    68122    my ( $self, $ctrl, $event ) = @_;
    69        
    70     my $id = $ctrl->GetId;
    71 
    72     # change the property value
    73         $self->properties->{$id}->{value}->(
     123   
     124    my $id = $ctrl->GetId;
     125
     126    # change the property value
     127    $self->properties->{$id}->{value}->(
    74128        $event->GetDate->FormatISODate
    75129    ) if exists $self->properties->{$id}->{value};
    76130    # 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;
    80135}
    81136
    82137
    83138my $change_value = {
     139    'Wx::SpinCtrl' => sub { my ($ctrl, $value ) = @_; $ctrl->SetValue($value)},
    84140    'Wx::TextCtrl' => sub { my ($ctrl, $value ) = @_; $ctrl->ChangeValue($value)},
    85141    'Wx::CheckBox' => sub { my ($ctrl, $value ) = @_; $ctrl->SetValue($value)},
    86142    'Wx::DatePickerCtrl' => sub { my ($ctrl, $value ) = @_;
    87                                   my $date = Wx::DateTime->new; 
     143                                  my $date = Wx::DateTime->new;   
    88144                                  my ($yyyy, $mm, $dd, $hh, $mi, $ss ) = split(/[:\/\\\-\.\s]/, $value);
    89                                                                   $date->ParseDate(
    90                                                                       sprintf("%s/%s/%s", $yyyy, $mm, $dd)
    91                                                                   );
    92                                       $ctrl->SetValue($date);
    93                                     },
    94 };     
     145                                  $date->ParseDate(
     146                                    sprintf("%s/%s/%s", $yyyy, $mm, $dd)
     147                                  );
     148                                  $ctrl->SetValue($date);
     149                                },
     150};
    95151
    96152my $clear_value = {
     
    98154    'Wx::CheckBox' => sub { my ($ctrl) = @_; $ctrl->SetValue(0)},
    99155    'Wx::DatePickerCtrl' => sub { my ($ctrl) = @_; $ctrl->SetValue(Wx::DateTime->new->SetToCurrent)},
    100 };     
     156};   
    101157
    102158sub SetProperties {
    103159    my ( $self ) = @_;
    104        
    105         map {
    106         my $ctrl =$self->FindWindow($_);
    107         if(defined $ctrl){
    108                 # checkbox, static text
     160   
     161    map {
     162        my $ctrl =$self->FindWindow($_);
     163        if(defined $ctrl){
     164            # checkbox, static text
    109165            $change_value->{ref $ctrl}->(
    110                         $ctrl,
     166                $ctrl,
    111167                $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};
    120182}
    121183
    122184sub InitLabels {
    123185    my ( $self ) = @_;
    124        
    125         map {
    126         my $ctrl =$self->FindWindow($_);
    127         #printf("ctrl %s : %s\n", $_, $ctrl);           
    128         if(defined $ctrl){
    129                 # checkbox, static text
    130                     $ctrl->SetLabel(
     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(
    131193               $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       
    134200            # radiobox
    135201            my $labels =$self->properties->{$_}->{labels};
    136                     $labels||=[];
    137                     for(my $i=0; $i < scalar @$labels ; $i++){
    138                         $ctrl->SetItemLabel($i, $labels->[$i]);
    139                     }
    140                 }
    141     }
    142         keys %{$self->properties};
     202            $labels||=[];
     203            for(my $i=0; $i < scalar @$labels ; $i++){
     204                $ctrl->SetItemLabel($i, $labels->[$i]);
     205            }
     206        }
     207    }
     208    keys %{$self->properties};
    143209
    144210}
     
    147213    my ( $self ) = @_;
    148214
    149                 map {
    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);       
    152218        if(defined $ctrl){
    153219            # choice
    154220            my $choices =$self->properties->{$_}->{choices};
    155                     $choices||=[];
    156                     map{
    157                         $ctrl->Append($_);
    158                     }@$choices;
    159                 }
    160     }
    161         keys %{$self->properties};
     221            $choices||=[];
     222            map{
     223                $ctrl->Append($_);
     224            }@$choices;
     225        }
     226    }
     227    keys %{$self->properties};
    162228
    163229}
     
    166232    my ( $self ) = @_;
    167233
    168         map {
     234    map {
    169235        my $ctrl = $self->FindWindow($_);
    170         #printf("ctrl %s : %s\n", $_, $ctrl);           
    171         if(defined $ctrl){
    172                 # checkbox, static text
     236        #printf("ctrl %s : %s\n", $_, $ctrl);       
     237        if(defined $ctrl){
     238        # checkbox, static text
    173239            $self->properties->{$_}->{value}->(
    174240                $ctrl->GetValue()
    175                     ) if exists $self->properties->{$_}->{value};
     241            ) if exists $self->properties->{$_}->{value};
    176242
    177243            $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};
    183253}
    184254
    185255sub ClearProperties {
    186256    my ( $self ) = @_;
    187        
    188         map {
    189         my $ctrl =$self->FindWindow($_);
    190         if(defined $ctrl){
    191                 # checkbox, static text
     257   
     258    map {
     259        my $ctrl =$self->FindWindow($_);
     260        if(defined $ctrl){
     261             # checkbox, static text
    192262            $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};
    202276
    203277}
Note: See TracChangeset for help on using the changeset viewer.