Domanda

Sto avendo questo codice Perl:

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

use Gtk2 '-init';

my $data;

my $builder_file = "lists.glade";

my $builder = Gtk2::Builder->new();
$builder->add_from_file( $builder_file )
    or die "Couldn't read $builder_file";
$builder->connect_signals( undef );


my $window = $builder->get_object( "top_window" )
    or die "Error while setting up GUI";

$window->show_all();

# Dealloc builder
$builder = undef;

Gtk2->main();

sub top_window_destroy_cb
{
    Gtk2->main_quit();
}

sub on_radiobutton1_group_changed
{
    my ($self, $choice) = @_;

    print Dumper($self, $choice, $choice->get_text());
}

e questo file costruttore:

<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.16"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="top_window">
    <signal name="destroy" handler="top_window_destroy_cb"/>
    <child>
      <object class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkVButtonBox" id="vbuttonbox1">
            <property name="visible">True</property>
            <property name="orientation">vertical</property>
            <child>
              <object class="GtkRadioButton" id="radiobutton1">
                <property name="label" translatable="yes">Pera</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">False</property>
                <property name="active">True</property>
                <property name="draw_indicator">True</property>
                <signal name="group_changed" handler="on_radiobutton1_group_changed" object="choice"/>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkRadioButton" id="radiobutton2">
                <property name="label" translatable="yes">Mika</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">False</property>
                <property name="draw_indicator">True</property>
                <property name="group">radiobutton1</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="choice">
            <property name="visible">True</property>
            <property name="label" translatable="yes">Choice</property>
          </object>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>

Ma falsamente collega "on_radiobutton1_group_changed" con il segnale "distruggere" da "top_window". Lo so perché esegue "Dumper stampa ..." unica dichiarazione quando la finestra di chiusura. Qualcuno ha idea di cosa sto facendo male?

È stato utile?

Soluzione

  

Il segnale "gruppo-cambiato"

     

emessa quando il gruppo di pulsanti che appartiene un pulsante a cambiamenti. Questo viene emesso quando un pulsante passa da prendere solo a far parte di un gruppo di 2 o più pulsanti, o viceversa, e quando un pulsante viene spostato da un gruppo di 2 o più pulsanti a un altro, ma non quando la composizione del gruppo che un pulsante appartiene ai cambiamenti.

In realtà non suona come quello che si vuole. Sto indovinando che è chiamata la distruzione della finestra.

Ho aggiunto il seguente sub

sub on_radiobutton_toggled {
    my $self = shift;
    if ($self->get_active) {
        print Dumper($self, $self->get_label);
    }
}

e impostare il segnale commutato di ogni pulsante radio (sotto GtkToggleButton) per on_radiobutton_toggled, che ora fa quello che si vuole.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top