Página 2 de 2

Re: Cómo coger datos de un combobox

NotaPublicado: 2009-09-14 13:19 @596
por oihantze
Hola. He puesto el código igual que tú, pero cambio las instrucciones de la subrutina por esto:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use diagnostics;
  6.  
  7. use Gtk2 '-init';
  8. use Glib qw/TRUE FALSE/;
  9.  
  10. my @valores = 1 .. 30;
  11.  
  12. ## Titular
  13. my $frase = Gtk2::Label->new('Indique cuántos documentos desea buscar');
  14.  
  15. ## Lista de opciones
  16. my $comboBox = Gtk2::ComboBox->new_text();
  17. for (@valores) {
  18.         $comboBox->append_text($_);
  19. }
  20. $comboBox->set_active (0);
  21.  
  22. ## Tabla de la lista
  23. my $tabla_combo= Gtk2::Table->new(2,3,TRUE);
  24. $tabla_combo->attach_defaults($comboBox, 1,2,1,2);
  25.  
  26.  
  27. ## Botón Atrás
  28. my $boton_atras = Gtk2::Button->new_with_label('Atras');
  29. $boton_atras->signal_connect(clicked => \&atras);
  30. ## Botón Ok
  31. my $boton_ok = Gtk2::Button->new_from_stock('gtk-ok');
  32. $boton_ok->signal_connect(clicked => \&ir_a);
  33.  
  34. ## Tabla de los botones
  35. my $tabla_botones = Gtk2::Table->new(3,5, TRUE);
  36. $tabla_botones->attach_defaults($boton_atras, 1,2,1,2);
  37. $tabla_botones->attach_defaults($boton_ok, 3,4,1,2);
  38.  
  39. ## Tabla contenedor
  40. my $tabla_contenedor = Gtk2::Table->new(3,7, FALSE);
  41. $tabla_contenedor->attach_defaults($frase, 1,2,1,2);
  42. $tabla_contenedor->attach_defaults($tabla_combo, 1,2,3,4);
  43. $tabla_contenedor->attach_defaults($tabla_botones, 1,2,5,6);
  44.  
  45. ## Ventana principal
  46. my $ventana = Gtk2::Window->new('toplevel');
  47. $ventana->set_title('Documentos');
  48. $ventana->set_border_width(20); # 20px
  49.  
  50. ## Estilo
  51. my $rc_style = Gtk2::RcStyle->new;
  52. $rc_style->bg_pixmap_name('normal', 'fondo.jpg');
  53.  
  54. $ventana->modify_style($rc_style);
  55. $ventana->signal_connect (delete_event => sub {Gtk2->main_quit; TRUE}); # Cierre de la app
  56. $ventana->add($tabla_contenedor);
  57. $ventana->set_default_size(200,200);
  58. $ventana->set_keep_above(TRUE);
  59. $ventana->set_resizable(FALSE);
  60. $ventana->move(380, 300);
  61. $ventana->show_all;
  62.  
  63. Gtk2->main;
  64.  
  65. sub ir_a {
  66.        
  67.         exec "./ejecutando_estoy_en_noja.pl $comboBox->get_active() $_[0] $_[1] $_[2] $_[3] $_[4] $_[5]";      #ESTA
  68.        
  69.         #print 'Índice: ', $comboBox->get_active(),      "\n";
  70.         #print 'Texto : ', $comboBox->get_active_text(), "\n";
  71.  
  72. }
  73.  
  74. sub atras{
  75.         Gtk2->main_quit;
  76.         #my $punto=".";
  77.         #exec "$punto$_[0] $_[1]";
  78. }
  79.  
  80.  
  81. ###########################################3
  82.  
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4


Y me da este error en la consola:

Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
Use of uninitialized value in concatenation (.) or string at ./num_docs.pl line
        67 (#1)
    (W uninitialized) An undefined value was used as if it were already
    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
    To suppress this warning assign a defined value to your variables.
   
    To help you figure out what was undefined, perl tells you what operation
    you used the undefined value in.  Note, however, that perl optimizes your
    program and the operation displayed in the warning may not necessarily
    appear literally in your program.  For example, "that $foo" is
    usually optimized into "that " . $foo, and the warning will refer to
    the concatenation (.) operator, even though there is no . in your
    program.
   
sh: Syntax error: "(" unexpected
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4


¿¿Por qué puede ser??

Re: Cómo coger datos de un combobox

NotaPublicado: 2009-09-14 13:58 @623
por explorer
No puedes meter una llamada a una función dentro de unas dobles comillas.

Cambia
exec "./ejecutando_estoy_en_noja.pl $comboBox->get_active() $_[0] $_[1] $_[2] $_[3] $_[4] $_[5]";
por
exec('./ejecutando_estoy_en_noja.pl', $comboBox->get_active(), "$_[0] $_[1] $_[2] $_[3] $_[4] $_[5]");

Yo incluso me atrevería a poner:
exec('./ejecutando_estoy_en_noja.pl', $comboBox->get_active(), "@_");

Así, @_ pasa todos los argumentos que tenga, sean uno o cinco.

Re: Cómo coger datos de un combobox

NotaPublicado: 2009-11-22 04:23 @224
por visualfree
Acá hice otro ejemplo :), espero igual te ayude.

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2. use Gtk2 '-init';
  3. my @valores =($operaciones);
  4.         $operaciones[0]="Sumar";
  5.         $operaciones[1]="Restar";
  6.         $operaciones[2]="Multiplicar";
  7.         $operaciones[3]="Dividir";
  8.  
  9.         $combo=Gtk2::ComboBox->new_text;
  10.                 $combo->append_text($operaciones[0]);
  11.                 $combo->append_text($operaciones[1]);
  12.                 $combo->append_text($operaciones[2]);
  13.                 $combo->append_text($operaciones[3]);
  14.                 $combo->set_active (0);
  15.  
  16.         $botonMostrar=Gtk2::Button->new('Monstrar');
  17.         $botonSalir=Gtk2::Button->new('Salir');
  18.  
  19.         #Acciones
  20.         $botonMostrar->signal_connect( clicked => \&mostrar);
  21.         $botonSalir->signal_connect( clicked => \&salir);
  22.  
  23.         $vertical=Gtk2::VBox->new(3,FALSE);
  24.         $vertical->pack_start($combo,FALSE,FALSE,FALSE);
  25.         $vertical->pack_start($botonMostrar,FALSE,FALSE,FALSE);
  26.         $vertical->pack_start($botonSalir,FALSE,FALSE,FALSE);
  27.  
  28.         $window=Gtk2::Window->new('toplevel');
  29.         $window->signal_connect( destroy => sub{ Gtk2->main_quit } );
  30.         $window->add($vertical);
  31.         $window->show_all;
  32.         Gtk2->main;
  33.  
  34. sub mostrar{
  35.     print 'Índice: ', $combo->get_active(),      "\n";
  36.     print 'Texto : ', $combo->get_active_text(), "\n";
  37. }
  38.  
  39. sub salir{
  40.         Gtk2->main_quit;
  41. }
  42.  
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4

Re: Cómo coger datos de un combobox

NotaPublicado: 2009-11-22 10:35 @483
por explorer
¿Para que sirve la variable $operaciones, de la línea 3?

Re: Cómo coger datos de un combobox

NotaPublicado: 2009-11-22 17:12 @758
por erv-Z
Jejeje. Parece que se equivocó; lo que quiso hacer seguro era tener un array con diferentes valores y llamarlo por [0], [1], etc.

Te recomiendo, visualfree, que sepas bien la definición de una variable y también cómo funcionan los arrays correctamente porque estás mezclando todo.

Re: Cómo coger datos de un combobox

NotaPublicado: 2009-11-22 17:31 @771
por explorer
Pues a eso me refiero...

En Perl, como es tan liberal, se puede poner casi cualquier cosa, y Perl se lo traga. Incluso hasta lo que pongas demás.

Pero bueno, si funciona... no pasa nada. Lo malo es si crea vicios ocultos.

Yo también tenía muchos malos vicios, hasta que leí el PBP :)

Lo más barato, sin duda, es usar 'strict' y 'warnings'.