Bonjour,
je pensais qu'il était possible de récupérer le retour d'une fonction de callback d'un bouton mais au lieu de ca je récupère une table de HASH (button.frame.frame) bref ce n'est pas ce que j’espérais...
Dans mon exemple je crée une fenêtre de navigation pour récupérer un fichier.
Prog principale:
Module IHM:
Code : Sélectionner tout - Visualiser dans une fenêtre à part my $xorPath = &CREATE_WINDOW;
$gds1 est une variable exportée depuis un autre module soit elle vaut le path choisi dans mon navigateur soit elle vaut none cela fonctionne mais je trouve cette méthode assez peu élégante...
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 sub CREATE_WINDOW { my $mw = MainWindow->new( -background => $window_color, -title => "Add Xor GDS" ); # Give a modern look & feel to the Tk GUI : anti-alias font and a thin border $mw->optionAdd("*font", "-*-arial-normal-r-*-*-*-120-*-*-*-*-*-*"); $mw->optionAdd("*borderWidth", 1); #$mw->geometry("700x720"); $mw->geometry("500x150"); my $mw_scrolled = $mw->Scrolled( "Pane", -scrollbars => 'e', -borderwidth => 2, -relief => 'groove', -sticky => 'nwse', -background => $window_color ); $mw_scrolled->pack( -in => $mw, -fill => 'both', -expand => 1 ); $mw_scrolled->{SubWidget}->{yscrollbar}->configure( -width => 10, -background => $button_color ); my $Menu_techno_scrolled = &CREATE_WINDOW_COMMON($mw_scrolled, $directory, $directory ); $mw_scrolled->Button( -text => "Save", -command => [\&save_xorgds, $mw], -background => $button_color, -font => $font ) ->grid( -columnspan => 2, -sticky => "nsew", -padx => 5, -pady => 5 ); $mw_scrolled->Button( -text => "Exit", -command => [\&close_xor_ihm, $mw], -background => $button_color, -font => $font ) ->grid( -columnspan => 2, -sticky => "nsew", -padx => 5, -pady => 5 ); # Run GUI !! MainLoop; return $gds1; } sub save_xorgds { my $mw = shift; # Destruction de l'interface graphique, mais pas arrêt du programme Perl $mw->destroy; } sub close_xor_ihm { $gds1 = "none"; my $mw = shift; # Destruction de l'interface graphique, mais pas arrêt du programme Perl $mw->destroy; }
Au départ j'avais en tete de récupérer le retour d'une fonction de callback bouton et en fonction traiter l’événement, mais je n'ai pas réussi a manipuler le retour correctement...
Je voulais faire quelques choses comme ca:
Prog principale:
Module IHM:
Code : Sélectionner tout - Visualiser dans une fenêtre à part my $xorPath = &CREATE_WINDOW;
Avec $tmp modifier dans save_xorgds recuperer la variable modifiée dans $ex puis retourner $ex mais ca ne marche pas...
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 my tmp = ""; sub CREATE_WINDOW { my $mw = MainWindow->new( -background => $window_color, -title => "Add Xor GDS" ); # Give a modern look & feel to the Tk GUI : anti-alias font and a thin border $mw->optionAdd("*font", "-*-arial-normal-r-*-*-*-120-*-*-*-*-*-*"); $mw->optionAdd("*borderWidth", 1); #$mw->geometry("700x720"); $mw->geometry("500x150"); my $mw_scrolled = $mw->Scrolled( "Pane", -scrollbars => 'e', -borderwidth => 2, -relief => 'groove', -sticky => 'nwse', -background => $window_color ); $mw_scrolled->pack( -in => $mw, -fill => 'both', -expand => 1 ); $mw_scrolled->{SubWidget}->{yscrollbar}->configure( -width => 10, -background => $button_color ); my $Menu_techno_scrolled = &CREATE_WINDOW_COMMON($mw_scrolled, $directory, $directory ); my $ex = $mw_scrolled->Button( -text => "Save", -command => [\&save_xorgds, $mw, $tmp], -background => $button_color, -font => $font ) ->grid( -columnspan => 2, -sticky => "nsew", -padx => 5, -pady => 5 ); $mw_scrolled->Button( -text => "Exit", -command => [\&close_xor_ihm, $mw], -background => $button_color, -font => $font ) ->grid( -columnspan => 2, -sticky => "nsew", -padx => 5, -pady => 5 ); # Run GUI !! MainLoop; return $ex; } sub save_xorgds { my $mw = shift; my $tmp = shift; $tmp = $gds1; # Destruction de l'interface graphique, mais pas arrêt du programme Perl $mw->destroy; return $tmp } sub close_xor_ihm { my $mw = shift; # Destruction de l'interface graphique, mais pas arrêt du programme Perl $mw->destroy; }
Partager