IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques Perl Discussion :

MainLoop dans un package


Sujet :

Interfaces Graphiques Perl

  1. #1
    Membre à l'essai
    Inscrit en
    Octobre 2008
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Octobre 2008
    Messages : 19
    Points : 12
    Points
    12
    Par défaut MainLoop dans un package
    Bonjour,
    Je developpe un GUI en perl Tk. Naturellement j'ai une MainLoop dans le programme principal du GUI.
    J'ai egalement developpé un package permettant de lancer des widgets plus particuliers qui communiquent entre eux.
    Pour developper ce package, je le lancais juste a partir d'un petit programme perl ou il n'y avait pas de MainLoop.
    Maintenant je souhaiterai utiliser ce package dans mon GUI existant, le probleme est que le package prend en compte la MainLoop du GUI et non celle du package. Du coup le code s'execute sans attendre le fermeture des widgets du package et les valeurs ainsi retournées par le package sont toutes fausses.
    Si quelqu'un sait comment forcer le package a utiliser sa MainLoop ca serait génial!!
    Merci d'avance

  2. #2
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    Peux tu nous donner des exemples de codes ?
    Sinon, utilises tu les Toplevel ?
    Tu peux aussi utiliser les méthodes waitVariable

  3. #3
    Membre à l'essai
    Inscrit en
    Octobre 2008
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Octobre 2008
    Messages : 19
    Points : 12
    Points
    12
    Par défaut
    J'ai résumé mon probleme avec ce code. Voici mon programme principal(simplifié) qui ouvre une fenetre. En cliquant sur le bouton, on appelle une fonction qui fait appelle a une autre fonction d'un package.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    #!/opt/perl_5.8.8/bin/perl -w
    use setSetting;
    use Tk;
     
    my $win=new MainWindow();
    my $frame=$win->Frame(-relief=>'groove',  -borderwidth=>3)->pack();
    my $label1=$frame->Label(-text=>'Press The Button')->pack();
    my $B=$frame -> Button( -text => "Next", -command => \&Set, )-> pack();
     
    MainLoop;
     
    print "ooooooooooooo  $choice  ooooooooooooooooooo\n";
    exit 0;
     
    sub Set(){$choice=setSetting::init('localRSF','drc');}

    Voici le code résumé du package:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
     
     
    package setSetting;
    use Tk;
    use Tk::FileSelect;
    use Tk::ItemStyle;
    use Tk::HList;
    use Tk::JComboBox;
    use vars qw($choice);
     
    sub init(){
     
    	($setting,$task) = @_;
    	eval "require $task";
     
    	%settings = map { $_->getName => $_ } $task->getTaskSettings();
    	$defaultVal = $settings{$setting}-> getDefault;
    	$type = $settings{$setting}-> getType;
    	$settingName = $settings{$setting}-> getName;
    	@values = $settings{$setting}-> getValues;
    	$choice=$defaultVal;
     
     
    	$mw = new MainWindow(-bg => 'alice blue');
    	$mw -> title( 'Demonstrator: Set Settings -Wotan2.2' );
    	$mw->fontCreate("lucida", -family=>'lucida', -size=>'12');
     
    	if($type eq 'text'){popText();}
    	if($type eq 'file'){popFile();}
    	if($type eq 'singleValue'){popSingleValue();}
    	if($type eq 'multiValue'){popMultiValue();}
    #ces fonctions ouvrent simplement des widgets, propose des choix a 
    #l'utilisateur et set la variable globale $choice, je n'ai pas trouvé util de
    #mettre leur code ici bien qu'il sot présent dans le package
    	MainLoop;
    	my @err = $settings{$setting}->validateValues($choice);
    	if(defined $err[0]){print "@err\n";}
    	return ($choice);
    }
    1;
    Le programme principal appel donc la fonction init du package cette fonction en appel d'autres qui display des widgets proposant des choix a l'utilisateur afin de mettre a jour la variable $choice setter par l'utilisateur.
    Le probleme est que le package prend en compte la MainLoop du 1er programme et non celle du package, du coup l'execution dans le package se fait d'une traite sans attendre la fermeture des fenetres, la valeur $choice est donc retournée avant que l'utilisateur ait fait son choix ce qui n'est pas bon.

  4. #4
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    1- Pense à toujours mettre ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    use warnings;
    use strict;
    2- Evite le prototypage des procédures.

    et non
    3- Déclare ta variable $choice.

    Maintenant, voici comment moi je fonctionne régulièrement si j'ai des packages.
    Je passe $win par exemple en argument à ma fonction init (pour prendre ton exemple.

    Et si j'ai des widgets à créer, je crée des Toplevel.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    my $NouveauWidget = $win->Toplevel();

  5. #5
    Membre à l'essai
    Inscrit en
    Octobre 2008
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Octobre 2008
    Messages : 19
    Points : 12
    Points
    12
    Par défaut
    Merci pour les conseils.
    J'ai fait les modifications indiquées, cependant je ne vois pas comment utiliser un Toplevel a la place de la MainWindow pourrait m'aider a résoudre mon probleme avec les mainLoop et effectivement ces changements n'apportent aucune modification dans le comportement du programme.

  6. #6
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    Est ce possible de mettre ton code ou non (ne serait que temporairement)?
    histoire que puisse le tester?

  7. #7
    Membre à l'essai
    Inscrit en
    Octobre 2008
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Octobre 2008
    Messages : 19
    Points : 12
    Points
    12
    Par défaut
    Voici le code pour tester le package, ce n'est pas le vrai code, c'est juste un code mettant en evidence le probleme auquel je suis confronté
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    #!/opt/perl_5.8.8/bin/perl -w
    use setSetting;
    use Tk;
    use Tk::FileSelect;
    use Tk::ItemStyle;
    use Tk::HList;
    use Tk::JComboBox;
     
    my $win=new MainWindow(-bg => 'alice blue');
    my $frame=$win->Frame(-relief=>'groove', -background => 'azure2', -borderwidth=>3)->pack(-side=>'top', -fill=> 'x');
    my $label1=$frame->Label(-text=>'Press The Button', -background => 'azure2', -foreground => 'black')->pack(-side=>'left');
    my $B=$frame -> Button( -text => "Next", -command => \&Set, -bg => 'ghost white')-> pack( -side => 'left', -padx => 85, -pady => 5 );
     
    MainLoop;
     
    print "ooooooooooooo  $choice  ooooooooooooooooooo\n";
    exit 0;
     
    sub Set(){
    print "Hello\n";
    my %setting=setSetting::initTask('drc');
    foreach my $elmts(sort keys %setting){print "$elmts\n";}
     
    $choice=setSetting::init('localRSF','drc',$win);
    }
    et voici le code du package:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
     
    package setSetting;
     
    use lib '.';
    use Cwd qw(abs_path);
    use FindBin qw($Bin);
    use lib "$Bin/../lib/perl";
    use Thread::Semaphore;
     
    use Tk;
    use Tk::FileSelect;
    use Tk::ItemStyle;
    use Tk::HList;
    use Tk::JComboBox;
    use strict;
    use warnings;
     
    my ($settingName, $choice, $defaultVal, @values, %choices,$mw);
     
    sub initTask{
    	my $task=shift;
    	eval "require $task";
    	my %settings = map { $_->getName => $_ } $task->getTaskSettings();
    	return(%settings);
    }
     
    sub init{
     
    	my ($setting,$task,$win) = @_;
    	eval "require $task";
     
    	my %settings = map { $_->getName => $_ } $task->getTaskSettings();
     
    	my $desc = $settings{$setting}-> getDescription;
    	my $type = $settings{$setting}-> getType;
    	my $mandatory = $settings{$setting}-> isMandatory;
    	$settingName = $settings{$setting}-> getName;
    	@values = $settings{$setting}-> getValues;
    	$defaultVal = $settings{$setting}-> getDefault;
     
    	$mw=$win->Toplevel();
    	#$mw = new MainWindow(-bg => 'alice blue');
    	$mw -> title( 'Demonstrator: Set Settings -Wotan2.2' );
    	$mw->fontCreate("lucida", -family=>'lucida', -size=>'12');
    	$mw->minsize(350,100);
     
    	if($type eq 'text'){popText();}
    	if($type eq 'file'){popFile();}
    	if($type eq 'singleValue'){popSingleValue();}
    	if($type eq 'multiValue'){popMultiValue();}
     	MainLoop;
     	if(defined $err[0]){print "@err\n";}
     
     	return ($choice);
     
    }
     
    sub getFile(){
    	my $f=$mw->getOpenFile( -title => "Select the file you want to use for $settingName");
    	if(defined $f){$choice=$f;$mw -> destroy;return;}
    }
     
    sub popText(){
    	my $frame=$mw->Frame(-relief=>'groove', -background => 'light cyan', -borderwidth=>3)->pack(-side=>'top', -fill=> 'x');
    	my $label=$frame->Label(-text=>'', -background => 'light cyan', -foreground => 'black')->pack(-side=>'left');
    	my $ent=$frame->Entry(-width => , -background=>'white', -textvariable=>)->pack(-side=>'left', -pady=>3, -padx=>135);
    	return;
    }
     
    sub popFile(){
    	my $frame=$mw->Frame(-relief=>'groove', -background => 'light cyan', -borderwidth=>3)->pack(-side=>'top', -fill=> 'both', -expand=> 1);
    	my $label=$frame->Label(-font=> 'lucida',-text=>"set the value of the setting $settingName", -background => 'light cyan', -foreground => 'black')->pack(-side=>'left', -padx=> 10);
     	my $ent=$frame->Entry(-background=>'white', -textvariable=>\$choice, -width => length($defaultVal)-26)->pack(-side=>'left', -pady=>3, -padx=>10);
    	my $Btt1=$frame->Button( -text => "Browse", -command => \&getFile)-> pack(-side=> 'right', -pady=> 10, -padx=> 10);
    	my $Btt2=$frame->Button( -text => "OK", -command => sub {$mw->destroy ;return})-> pack(-side=> 'right', -pady=> 10, -padx=> 10);
    	return;
    }
     
    sub popSingleValue(){
    	my $answer;
    	my $frame=$mw->Frame(-relief=>'groove', -background => 'azure2', -borderwidth=>3)->pack(-side=>'top', -fill=> 'x');
    	my $label=$frame->Label(-font => 'lucida', -text=>"set the value of the setting $settingName", -background => 'azure2', -foreground => 'black')->pack(-side=>'left');
    	my $jcb = $frame->JComboBox(-entrybackground => 'white',     -mode => 'readonly',     -relief => 'sunken',-textvariable=>\$answer,-choices => \@values)->pack;
    	my $frame2=$mw->Frame(-relief=>'groove', -background => 'alice blue', -borderwidth=>3)->pack(-side=>'top', -fill=> 'both', -expand=> '1');
    	#my $Btt1=$frame2->Button( -text => "OK", -command => sub {$choice=$answer;$s->up;$mw->destroy;})-> pack(-side=> 'left', -pady=> 10, -padx=> 70);
    	my $Btt1=$frame2->Button( -text => "OK", -command => sub {$choice=$answer;$mw->destroy;})-> pack(-side=> 'left', -pady=> 10, -padx=> 70);
    	my $Btt2=$frame2->Button( -text => "Cancel", -command => sub {$choice="$defaultVal";$mw->destroy;})-> pack(-side=> 'right',-after=>$Btt1, -pady=> 10, -padx=> 70);
    }
     
    sub popMultiValue(){
    	my $frame=$mw->Frame(-relief=>'groove', -background => 'azure2', -borderwidth=>3)->pack(-side=>'top', -fill=> 'x');
    	my $label=$frame->Label(-font=>'lucida', -text=>"set the value of the setting $settingName :", -background => 'azure2', -foreground => 'black')->pack(-side=>'top');
    	foreach(@values){
    		$choices{$_} = 0;
    		$frame->Checkbutton(-textvariable=>\$_, -variable=>\$choices{$_}, -bg => 'ghost white')->pack(-side=>'top', -pady=>5);
    	}
    	my $Btt1=$frame->Button( -text => "OK", -command => sub {finalizeMultiOption();$mw->destroy;return;})-> pack(-side=> 'left', -pady=> 10, -padx=> 70);
    	my $Btt2=$frame->Button( -text => "Cancel", -command => sub {$choice="$defaultVal";$mw->destroy;return;})-> pack(-side=> 'right',-after=>$Btt1, -pady=> 10, -padx=> 70);
    }
     
    sub finalizeMultiOption{
    	if(%choices){
    		$choice='';
    		my $flag=0;
    		foreach(@values){
    			if($choices{$_} == 1){
    				if($choice eq ''){$choice=$_;}
    				else{$choice=$choice.' '.$_;}
    				$flag=1;
    			}
    		}
    		if($flag==0){$choice=$defaultVal;}
    	}
    	return;
    }
    1;

  8. #8
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 498 771
    Points
    498 771
    Par défaut
    Bon, c'est impossible de tester ton code car il y a des message d'erreur, des variables non déclarées, etc etc.

    Bon, pour essayer de faire avec dans un premier temps, voici ce que tu peux faire :
    J'ai réindenté ton code, enlevé le mainloop du package inutile.
    J'ai enlevé tous les () des tes sub toto() ...


    Script principal

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    #!/opt/perl_5.8.8/bin/perl
    use setSetting;
    use Tk;
    use Tk::FileSelect;
    use Tk::ItemStyle;
    use Tk::HList;
    use Tk::JComboBox;
     
    use warnings;
    use strict;
     
    my $choice;
     
    my $win = new MainWindow( -bg => 'alice blue' );
    my $frame = $win->Frame(
      -relief      => 'groove',
      -background  => 'azure2',
      -borderwidth => 3
    )->pack( -side => 'top', -fill => 'x' );
    my $label1 = $frame->Label(
      -text       => 'Press The Button',
      -background => 'azure2',
      -foreground => 'black'
    )->pack( -side => 'left' );
    my $B = $frame->Button(
      -text    => "Next",
      -command => [\&Set, $win, \$choice],
      -bg      => 'ghost white'
    )->pack( -side => 'left', -padx => 85, -pady => 5 );
     
    MainLoop;
     
    print "ooooooooooooo  $choice  ooooooooooooooooooo\n";
    exit 0;
     
    sub Set {
      my ( $WidgetPrincipal, $RefChoice ) = @_;
     
      print "Hello\n";
      my %setting = setSetting::initTask('drc');
     
      foreach my $elmts ( sort keys %setting ) { 
        print "$elmts\n"; 
      }
     
      ${$RefChoice} = setSetting::init( 'localRSF', 'drc', $WidgetPrincipal );
    }
    package
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    package setSetting;
     
    use lib '.';
    use Cwd qw(abs_path);
    use FindBin qw($Bin);
    use lib "$Bin/../lib/perl";
    use Thread::Semaphore;
     
    use Tk;
    use Tk::FileSelect;
    use Tk::ItemStyle;
    use Tk::HList;
    use Tk::JComboBox;
    use strict;
    use warnings;
     
    my ( $settingName, $choice, $defaultVal, @values, %choices, $mw );
     
    sub initTask {
      my $task = shift;
      eval "require $task";
      my %settings = map { $_->getName => $_ } $task->getTaskSettings();
      return (%settings);
    }
     
    sub init {
     
      my ( $setting, $task, $win ) = @_;
      eval "require $task";
     
      my %settings = map { $_->getName => $_ } $task->getTaskSettings();
     
      my $desc      = $settings{$setting}->getDescription;
      my $type      = $settings{$setting}->getType;
      my $mandatory = $settings{$setting}->isMandatory;
      $settingName = $settings{$setting}->getName;
      @values      = $settings{$setting}->getValues;
      $defaultVal  = $settings{$setting}->getDefault;
     
      $mw = $win->Toplevel();
     
      #$mw = new MainWindow(-bg => 'alice blue');
      $mw->title('Demonstrator: Set Settings -Wotan2.2');
      $mw->fontCreate( "lucida", -family => 'lucida', -size => '12' );
      $mw->minsize( 350, 100 );
     
      if ( $type eq 'text' )        { popText(); }
      if ( $type eq 'file' )        { popFile(); }
      if ( $type eq 'singleValue' ) { popSingleValue(); }
      if ( $type eq 'multiValue' )  { popMultiValue(); }
      if ( defined $err[0] ) { print "@err\n"; }
     
      return ($choice);
     
    }
     
    sub getFile {
      my $f = $mw->getOpenFile(
        -title => "Select the file you want to use for $settingName" );
      if ( defined $f ) { $choice = $f; $mw->destroy; return; }
    }
     
    sub popText {
      my $frame = $mw->Frame(
        -relief      => 'groove',
        -background  => 'light cyan',
        -borderwidth => 3
      )->pack( -side => 'top', -fill => 'x' );
      my $label = $frame->Label(
        -text       => '',
        -background => 'light cyan',
        -foreground => 'black'
      )->pack( -side => 'left' );
      my $ent
          = $frame->Entry( -width =>, -background => 'white', -textvariable => )
          ->pack( -side => 'left', -pady => 3, -padx => 135 );
      return;
    }
     
    sub popFile {
      my $frame = $mw->Frame(
        -relief      => 'groove',
        -background  => 'light cyan',
        -borderwidth => 3
      )->pack( -side => 'top', -fill => 'both', -expand => 1 );
      my $label = $frame->Label(
        -font       => 'lucida',
        -text       => "set the value of the setting $settingName",
        -background => 'light cyan',
        -foreground => 'black'
      )->pack( -side => 'left', -padx => 10 );
      my $ent = $frame->Entry(
        -background   => 'white',
        -textvariable => \$choice,
        -width        => length($defaultVal) - 26
      )->pack( -side => 'left', -pady => 3, -padx => 10 );
      my $Btt1 = $frame->Button( -text => "Browse", -command => \&getFile )
          ->pack( -side => 'right', -pady => 10, -padx => 10 );
      my $Btt2 = $frame->Button(
        -text    => "OK",
        -command => sub { $mw->destroy; return }
      )->pack( -side => 'right', -pady => 10, -padx => 10 );
      return;
    }
     
    sub popSingleValue {
      my $answer;
      my $frame = $mw->Frame(
        -relief      => 'groove',
        -background  => 'azure2',
        -borderwidth => 3
      )->pack( -side => 'top', -fill => 'x' );
      my $label = $frame->Label(
        -font       => 'lucida',
        -text       => "set the value of the setting $settingName",
        -background => 'azure2',
        -foreground => 'black'
      )->pack( -side => 'left' );
      my $jcb = $frame->JComboBox(
        -entrybackground => 'white',
        -mode            => 'readonly',
        -relief          => 'sunken',
        -textvariable    => \$answer,
        -choices         => \@values
      )->pack;
      my $frame2 = $mw->Frame(
        -relief      => 'groove',
        -background  => 'alice blue',
        -borderwidth => 3
      )->pack( -side => 'top', -fill => 'both', -expand => '1' );
     
    #my $Btt1=$frame2->Button( -text => "OK", -command => sub {$choice=$answer;$s->up;$mw->destroy;})-> pack(-side=> 'left', -pady=> 10, -padx=> 70);
      my $Btt1 = $frame2->Button(
        -text    => "OK",
        -command => sub { $choice = $answer; $mw->destroy; }
      )->pack( -side => 'left', -pady => 10, -padx => 70 );
      my $Btt2 = $frame2->Button(
        -text    => "Cancel",
        -command => sub { $choice = "$defaultVal"; $mw->destroy; }
      )->pack( -side => 'right', -after => $Btt1, -pady => 10, -padx => 70 );
    }
     
    sub popMultiValue {
      my $frame = $mw->Frame(
        -relief      => 'groove',
        -background  => 'azure2',
        -borderwidth => 3
      )->pack( -side => 'top', -fill => 'x' );
      my $label = $frame->Label(
        -font       => 'lucida',
        -text       => "set the value of the setting $settingName :",
        -background => 'azure2',
        -foreground => 'black'
      )->pack( -side => 'top' );
      foreach (@values) {
        $choices{$_} = 0;
        $frame->Checkbutton(
          -textvariable => \$_,
          -variable     => \$choices{$_},
          -bg           => 'ghost white'
        )->pack( -side => 'top', -pady => 5 );
      }
      my $Btt1 = $frame->Button(
        -text    => "OK",
        -command => sub { finalizeMultiOption(); $mw->destroy; return; }
      )->pack( -side => 'left', -pady => 10, -padx => 70 );
      my $Btt2 = $frame->Button(
        -text    => "Cancel",
        -command => sub { $choice = "$defaultVal"; $mw->destroy; return; }
      )->pack( -side => 'right', -after => $Btt1, -pady => 10, -padx => 70 );
    }
     
    sub finalizeMultiOption {
      if (%choices) {
        $choice = '';
        my $flag = 0;
        foreach (@values) {
          if ( $choices{$_} == 1 ) {
            if   ( $choice eq '' ) { $choice = $_; }
            else                   { $choice = $choice . ' ' . $_; }
            $flag = 1;
          }
        }
        if ( $flag == 0 ) { $choice = $defaultVal; }
      }
      return;
    }
    1;
    Essaye de voir à quoi ressemble mes modifications et teste le

Discussions similaires

  1. [Debutant(e)]comme utiliser un .jar dans un package
    Par dietrich dans le forum Eclipse Java
    Réponses: 13
    Dernier message: 22/12/2005, 14h57
  2. Dans quel package se trouve les fonctions C ??
    Par red210 dans le forum Linux
    Réponses: 9
    Dernier message: 18/12/2005, 20h16
  3. Problème déclaration de variable dans un package
    Par LE NEINDRE dans le forum Modules
    Réponses: 3
    Dernier message: 23/08/2005, 18h26
  4. [3.0.2]Détection des erreurs dans le Package Explorer
    Par willowII dans le forum Eclipse Java
    Réponses: 5
    Dernier message: 18/08/2005, 18h46
  5. [VB.NET] Inclure MSDE dans le package
    Par SergeF dans le forum EDI/Outils
    Réponses: 4
    Dernier message: 24/06/2004, 21h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo