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 :

récupération de valeurs dans un sous-programme


Sujet :

Interfaces Graphiques Perl

  1. #1
    Membre émérite
    Avatar de Jasmine80
    Femme Profil pro
    Bioinformaticienne
    Inscrit en
    Octobre 2006
    Messages
    3 157
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 44
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Bioinformaticienne
    Secteur : Santé

    Informations forums :
    Inscription : Octobre 2006
    Messages : 3 157
    Points : 2 673
    Points
    2 673
    Par défaut récupération de valeurs dans un sous-programme
    Je n'arrive pas à récupérer les valeurs :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    sub Output_file {
    	my ($main, $ref_filetypes, $output_file) = @_;

    Code complèt :
    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
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    #!/usr/bin/perl
     
    use strict;
    use warnings;
    # use utf8;
     
    use Bio::SeqIO;
    use FileHandle;
    use List::MoreUtils qw(any);
    use File::Basename;
     
     
    use Tk;
    use Tk::BrowseEntry; 
     
     
     
    # correspondances types de fichiers et extensions
    my %correspondence = (
    	abi => ['.ab', '.abi1'],
    	ace => '.ace',
    	agave => '.xml',
    	alf => '.alf',
    	bsml => '.bsml',
    	bsml_sax => '.bsml', 
    	chaosxml => '.xml',
    	ctf => '.ctf',
    	embl => ['.ebl', '.emb', '.dat'],
    	excelx => '.exl', 
    	exp => '.exp ',
    	fasta => ['.fsa', '.fast', '.seq', '.fa', '.nt', '.aa'],
    	fastq => '.fastq',
    	flybase_chadoxml => '.xml',
    	game => '.xml',
    	gcg => '.gcg',
    	genbank => ['.gbank', '.genbank'],
    	interpro => '.xml',
    	phd => '.phred',
    	pir => '.pir',
    	pln => '.pln',
    	raw => '.txt',
    	scf => '.scf',
    	swiss => '.SwissProt',
    	tab => '.txt',
    	tigr => '.xml',
    	tigrxml => '.xml',
    	tigr => '.xml',
    	ncbi => '.xml',
    	ztr => '.ztr', 
    );
     
    my @filetypes;
    foreach ( sort keys %correspondence ) {
      push @filetypes, [$_, $correspondence{$_} ];
    }
    push @filetypes, [ 'Tous les fichiers', '*' ];
     
    my $main = MainWindow->new(
        -background => 'blue',
        -title      => 'Formatage de fichier',
    );
    $main->minsize( 250, 150 );
     
     
    my $InFileLabel = $main->Label(
        -text       => "Fichier d'entrée : ",
        -background => 'blue',
        -foreground => 'white',
        -justify    => 'left',
    );
     
     
    my $input_file;
     
    my $InputLabel = $main->Button(
        -text             => 'sélection',
        -activeforeground => 'red',
        -borderwidth      => 5,
        -command          => [ \&Input_file, $main, \@filetypes, \$input_file],
    );
     
     
    my $InTypeLabel = $main->Label(
        -text       => "Type du fichier d'entrée : ",
        -background => 'blue',
        -foreground => 'white',
    );
     
    my $in_format;
     
    my $InTypeEntry = $main->BrowseEntry(-variable => \$in_format);
     
    $InTypeEntry->insert("end", sort keys %correspondence);
     
     
     
     
     
    my $OutTypeLabel = $main->Label(
        -text       => "Type du fichier de sortie : ",
        -background => 'blue',
        -foreground => 'white',
    );
     
    my $output_file;
     
    my $OutputLabel = $main->Button(
        -text             => 'sélection',
        -activeforeground => 'red',
        -borderwidth      => 5,
        -command          => [ \&Output_file, $main, \@filetypes, \$output_file],
    ); 
     
    my $OutFileLabel = $main->Label(
        -text       => "Fichier de sortie : ",
        -background => 'blue',
        -foreground => 'white',
        -justify    => 'left',
    );
     
     
     
    my $out_format;
     
    my $OutTypeEntry = $main->BrowseEntry(-variable => \$out_format);
    $OutTypeEntry->insert("end", sort keys %correspondence);
     
    # bouton calculer
    my $btn_execute = $main->Button(
        -text             => 'Formatage',
        -activeforeground => 'red',
        -borderwidth      => 5,
        -command          => [ \&Execute, $main, \$input_file, $in_format, \$output_file, $out_format],
    );
     
    # bouton quitter
    my $btn_quitter = $main->Button(
        -text             => 'Quitter',
        -activeforeground => 'red',
        -borderwidth      => 5,
        -command          => \&Quitter,
    );
     
    # Effet clavier, touche entrée
    $main->bind( 'Tk::Entry','<Return>', sub { $btn_execute->invoke(); } );
     
    # Placement de mes widgets
     
    $InFileLabel->grid( -row => 0, -column => 0, -sticky => 'w' );
    $InputLabel->grid( -row => 0, -column => 1, -sticky => 'w', -pady => 20,);
     
    $InTypeLabel->grid( -row => 1, -column => 0, -sticky => 'w' );
    $InTypeEntry->grid( -row => 1, -column => 1, -sticky => 'w', -columnspan => 2);
     
    $OutFileLabel->grid( -row => 2, -column => 0, -sticky => 'w');
    $OutputLabel->grid( -row => 2, -column => 1, -sticky => 'w', -pady => 20,);
     
    $OutTypeLabel->grid( -row => 3, -column => 0, -sticky => 'w' );
    $OutTypeEntry->grid( -row => 3, -column => 1, -sticky => 'w', -columnspan => 2);
     
    $btn_execute->grid( -row => 4, -column => 0, -pady => 20, );
    $btn_quitter->grid( -row => 4, -column => 2, -pady => 20 );
     
     
     
    MainLoop;
     
     
    sub Quitter {
        exit(0);
    }
     
    sub Input_file {
    	my ($main, $ref_filetypes, $input_file) = @_;
     
    	${$input_file} = $main->getOpenFile(
    	  -filetypes => $ref_filetypes,
    	);
    }
     
     
    sub Output_file {
    	my ($main, $ref_filetypes, $output_file) = @_;
     
    	${$output_file} = $main->getSaveFile(
    	  -filetypes => $ref_filetypes,
    	);
    }
     
     
    sub Error {
     
    	my ($main, $message) = @_;
     
            # fenêtre d'erreur
            #--------------------
            my $error_frame = $main->Toplevel(
                -title      => 'MESSAGE D\'ERREUR',
                -background => 'red',
            );
            $error_frame->minsize( 250, 50 );
     
            $error_frame->Label(
                -text =>
                    "Le fichier $message est invalide",
                -background => 'red',
    	    -font => "courrier 10 bold",
                -foreground => 'black',
            )->pack;
     
    }
    sub Execute {
     
    	my ($main, $input_file, $in_format, $output_file, $out_format) = @_;
     
    	if (! -e ${$input_file}){
    		&Error ($main, "d'entrée :  $input_file");
    	}
     
    	if (! -e ${$output_file}){
    		&Error ($main, "de sortie :  $output_file");	
    	}
     
    	# récupération des fichiers
    	#----------------------------
     
    	my ( $in_name, $in_dir, $in_ext ) = fileparse( ${$input_file}, qr/\.[^.]*/ );
     
    	# extension choisie par l'utilisateur : $out_ext_cho
    	my ( $out_name, $out_dir, $out_ext_cho ) = fileparse( ${$output_file}, qr/\.[^.]*/ );
     
     
     
    	# vérification que $infile et $in_format correspondent
    	# ne se fait automatiquement via Bio::SeqIO qui ne renvoie
    	# pas de message d'erreur 
    	if (defined $in_ext){
     
    		# plusieurs possibilités d'extension
    		if ( ref($correspondence{$in_format}) eq 'ARRAY' ){
    			# si l'extension n'est pas valide, on affiche un message d'erreur
    			unless (any { $in_format =~ m/$_/ } @{$correspondence{$in_format}}){
    				&Error ($main, "d'entrée :  type $in_format ne correspond pas à l'extension $in_format\n");	
    			}
    		}
    		# une seule possibilité d'extension
    		elsif ($in_ext ne $correspondence{$in_format}){
    			&Error ($main, "d'entrée :  type $in_format ne correspond pas à l'extension $in_format\n");		
    		}		
    	}
     
    	# vérification que $in_format et $out_format soient différents
     
     
     
     
     
     
    	# extension imposée : $out_ext (si l'extension choisie n'est pas valide)
    	my $out_ext;
     
    	# vérification que $out_ext_cho soit défini
    	# vérification que l'extension choisie pour 
    	# le fichier de sortie soit possible
    	if (defined $out_ext_cho){
     
    		# plusieurs possibilités d'extension
    		if ( ref($correspondence{$out_format}) eq 'ARRAY' ){
    			# si l'extension est valide, on garde le choix de l'utilisateur
    			if (any { $out_format =~ m/$_/ } @{$correspondence{$out_format}}){
    				$out_ext = $out_ext_cho;
    			}
    			# sinon, on prend la première de la liste
    			else {
    				$out_ext = $correspondence{$out_format}->[0];
    			}
    		}
    		# une seule possibilité d'extension
    		else{
    				$out_ext = $correspondence{$out_format};
    		}		
    	}
    	# aucune extension n'a été définie par l'utilisateur
    	else{
     
    		# recherche de l'extension du fichier de sortie
    		# si plusieurs sont possibles, création d'une liste déroulante
    		# permettant le choix à l'utilisateur
    		if ( ref($correspondence{$out_format}) eq 'ARRAY' ){
     
    			$out_ext = $correspondence{$out_format}->[0];
    		}
    		else{
    			$out_ext = $correspondence{$out_format};
    		}
    	}
     
     
    	# création des 2 objets Bio::SeqIO
    	my $in  = Bio::SeqIO->new(-file => ${$input_file} , '-format' => $in_format);
    	my $out = Bio::SeqIO->new(-file => '>'.${$output_file} , '-format' => $out_format);
     
    	# récupération et formatage des données
    	while ( my $seq = $in->next_seq() ) {
    		$out->write_seq($seq);
    	}
     
    }
    Où est mon erreur? Merci.

  2. #2
    Membre actif

    Profil pro
    Inscrit en
    Août 2009
    Messages
    156
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 156
    Points : 211
    Points
    211
    Par défaut
    Bonjour,
    Que te donne l'affichage de cette fonction getDisplayAnyVar sur ton @_
    -ou tout autre debug sur le @_-, les paramètres passés n'arrivent pas ou ils ont un format non conforme ?

    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
     
    ################################################################################
    # getDisplayAnyVar
    ################################################################################
    # Input: var, compact_mode, html_on
    # Output: HTLM string
    # Description: Build a string representing the var given as argument.
    # If variable is a structure (array or hash), each element is displayed on a
    # new line. You can avoid this by setting compact_mode to 1.
    ################################################################################
    BEGIN {
    # "static" var for this function
    my $level = -1;
    my @color = ("FF0000","00FF00","0000FF","CCCCCC","770000");
    sub getDisplayAnyVar {
            my ($thing_to_display, $compact_mode, $html_on) = @_;
            my ($text, $value, $key, $space, $return);
     
      # Set compact_mode to 1 (False) if it is not equal to 0 (true)
      if ($compact_mode != 0) { $compact_mode = 1; }
      # Set $html_on to 1 (False) if it is not equal to 0 (true)
      if ($html_on != 0) { $html_on = 1; }
     
      # Parameters depending on HTML or not
      if ($html_on == 0) {
            $space = "&nbsp;";
            $return= "<br>\n";
        }
      else {
        $space = " ";
        $return= "\n";
        }
     
      $text = "";
    #       &printDebug("Thing is:".ref($thing_to_display));
      #############################################################################
      # Array display
      if (ref($thing_to_display) eq "ARRAY") {
        if (@$thing_to_display > 0) {
                #########################################################################
                # Return Array content
                if ($html_on == 0) { ($text .= "</font>") };
                $text .= $return;
          $level++;
          if ($html_on == 0) { $text .= "<font color='#".$color[$level]."'>" };
                for (my $i = 0; $i < $level; $i++) {
                            $text .= $space.$space.$space.$space;
                        }
                $text .= "[";
                      foreach $value (@$thing_to_display) {
                        if ($compact_mode == 1) {
                          for (my $k = 0; $k < $level; $k++) {
                $text .= $return;
                $text .= $space.$space.$space.$space;
                            }
                          }
                        $text .= "'".getDisplayAnyVar($value,
                                                      $compact_mode,
                                                      $html_on)."', ";
                        }
                $level--;
                $text .= "]";
                if ($html_on == 0) { $text .= "</font>"; }
                $text .= $return;
                if ($html_on == 0) { $text .= "<font color='#".$color[$level]."'>"; }
                for (my $i = 0; $i < $level; $i++) {
                  $text .= $space.$space.$space.$space;
                  }
          $text .= "$space";
                      }
              else {
                #########################################################################
                # Empty array
                $text = "[ ]";
                }
        }
      #############################################################################
      # Hashes display
            elsif (ref($thing_to_display) eq "HASH") {
        #########################################################################
        # Return hashes content
        if (defined(%$thing_to_display)) {
    #      &printDebug(ref($thing_to_display));
          if ($html_on == 0) { $text .= "</font>"; }
          $text .= $return;
          $level++;
          if ($html_on == 0) { $text .= "<font color='#".$color[$level]."'>"; }
          for (my $i = 0; $i < $level; $i++) {
            $text .= $space.$space.$space.$space;
            }
                $text .= "(";
          foreach $key (sort keys %$thing_to_display) {
            if ($compact_mode == 1) {
                $text .= $return;
                for (my $k = 0; $k < $level; $k++) {
                $text .= $space.$space.$space.$space;
                }
              }
                  $text .= $key."=>'".getDisplayAnyVar($thing_to_display->{$key},
                                                       $compact_mode,
                                                       $html_on)."', ";
                  }
          $level--;
          $text .= ")";
          if ($html_on == 0) { $text .= "</font>"; }
          $text .= $return;
          if ($html_on == 0) { $text .= "<font color='#".$color[$level]."'>"; }
          for (my $i = 0; $i < $level; $i++) {
            $text .= $space.$space.$space.$space;
            }
          $text .= "$space";
          }
        #########################################################################
        # Hashes is empty
         else {
            $text .= "( )";
         }
            }
            else {
    #               &printDebug($thing_to_display);
                    $text = $thing_to_display;
            }
            return $text;
    }
    } # End of the BEGIN

  3. #3
    Membre émérite
    Avatar de Jasmine80
    Femme Profil pro
    Bioinformaticienne
    Inscrit en
    Octobre 2006
    Messages
    3 157
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 44
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Bioinformaticienne
    Secteur : Santé

    Informations forums :
    Inscription : Octobre 2006
    Messages : 3 157
    Points : 2 673
    Points
    2 673
    Par défaut
    Merci de me répondre, je vais essayer ton code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    	my ($main, $input_file, $in_format, $output_file, $out_format) = @_;
     
    	print "=> IF : $input_file\n if : $in_format\n OF : $output_file\n of : $out_format\n\n";
    me donne
    => IF : SCALAR(0x20e034c)
    if :
    OF : SCALAR(0x20e0604)
    of :

  4. #4
    Membre émérite
    Avatar de Jasmine80
    Femme Profil pro
    Bioinformaticienne
    Inscrit en
    Octobre 2006
    Messages
    3 157
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 44
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Bioinformaticienne
    Secteur : Santé

    Informations forums :
    Inscription : Octobre 2006
    Messages : 3 157
    Points : 2 673
    Points
    2 673
    Par défaut
    Je pense que l'erreur vient de la récupération de ma variable :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    my $in_format;
     
    my $InTypeEntry = $main->BrowseEntry(-variable => \$in_format);

  5. #5
    Membre actif

    Profil pro
    Inscrit en
    Août 2009
    Messages
    156
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 156
    Points : 211
    Points
    211
    Par défaut
    Bien, je suis content d'avoir pu aider même si j'ai bien l'impression d'avoir affaire à bien meilleur que moi en Perl. :-)

  6. #6
    Membre émérite
    Avatar de Jasmine80
    Femme Profil pro
    Bioinformaticienne
    Inscrit en
    Octobre 2006
    Messages
    3 157
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 44
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Bioinformaticienne
    Secteur : Santé

    Informations forums :
    Inscription : Octobre 2006
    Messages : 3 157
    Points : 2 673
    Points
    2 673
    Par défaut
    J'ai résolu le problème en passant des références au sous programme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
        -command          => [ \&Execute, $main, \$input_file, \$in_format, \$output_file, \$out_format],

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. récupération de la valeur d'un sous-programme
    Par Jasmine80 dans le forum Interfaces Graphiques
    Réponses: 2
    Dernier message: 10/08/2009, 15h11
  2. récupération de valeur dans un sous-formulaire
    Par Sebastien_INR59 dans le forum Access
    Réponses: 2
    Dernier message: 05/06/2006, 11h48
  3. Réponses: 4
    Dernier message: 09/01/2006, 01h24
  4. Envoi d'informations dans un sous programme
    Par Tanguy Sarela dans le forum Linux
    Réponses: 3
    Dernier message: 22/12/2005, 16h57
  5. Récupération de valeurs dans logiciel de bourse
    Par david0280 dans le forum MFC
    Réponses: 25
    Dernier message: 28/03/2005, 20h28

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