Re: Queries on tree items and signals



On Tue, 2005-03-08 at 12:39 +0530, rashwin wrote:

I am new to the list and I have a couple of queries on the following:

Welcome.

$::button_ok->signal_handlers_destroy();
$::button_cancel->signal_handlers_destroy();

The fact that this worked for you without causing an error, means that
you're using the old and obsolete gtk+ 1.0 bindings, Gtk.  You
shouldn't.  Use the new and shiny gtk+ 2.0 bindings, Gtk2.

With Gtk2 you'd do something like this to achieve what you want:

  Gtk2 -> init();

  my $w = Gtk2::Window -> new;
  my $b = Gtk2::Button -> new("Zoink");

  doit();

  $w -> add($b);
  $w -> show_all();

  Gtk2 -> main();

  sub doit {
    my $id = 0 if 0;
    $b -> signal_handler_disconnect($id) if ($id);
    $id = $b -> signal_connect(clicked => \&doit);
  }


$::button_ok->signal_connect( 'clicked', \&type_direct_apply,$tree,$::external_text,$help_text);

$::button_cancel->signal_connect( 'clicked', \&type_sample_cancel,$tree, $::external_text,$help_text );

In Gtk2, we don't allow more than one user data parameter anymore, so
make that:

  $::button_ok->signal_connect( 'clicked', \&type_direct_apply, [$tree,$::external_text,$help_text]);

  sub type_direct_apply {                                                       
    my ($button, $data) = @_;
    my ($tree, $external, $help) = @$data;

    # ...
  }

2. THis is on dynamically changing labels of tree items.
When you create a tree item the first time and when selecting that tree item,
I want the user to change the label of the tree item on the fly.
Is that possible? What commands to be used for the same?

Gtk2 makes this very easy for you.  Just make the cell renderer
editable, and listen to the "edited" signal:

  $renderer -> set(editable => TRUE);
  $renderer -> signal_connect(edited => sub {
    my ($renderer, $path, $new) = @_;

    # $path contains the stringified tree path of the changed row
    # $new contains the newly entered string

    # If you want to keep the changes, you can store $new in the model 
    # now.  If you do nothing, the change will be discarded.
  }

-- 
Bye,
-Torsten




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]