Re: CellRendererSpinButton

On Jul 8, 2004, at 7:20 PM, Jens Wilke wrote:

i wasn't able to figure out how to set the size of the entry box, when the spinbutton is drawn. Any ideas welcome :)

the treeview sets the size of the CellEditable object when it maps it as part of the editable cell code. you shouldn't need to do anything to set its size, as the widget will be sized to fit the cell.

what are you wanting to do with this size? can you not get it normally, e.g. $spin_button->allocation?

I changed the event handler from "key_press" to "focus_out" to have better usability:

how do you mean better usability? the code you posted makes the up and down arrows close the editor widget rather than change the value, and using the arrow keys to change the value was a rather nice touch, i thought. in the setup as it was, you could use the arrow keys to navigate to a cell, hit enter, use the arrow keys to adjust the value, and then hit enter again to commit that value. hitting esc leaves the value unedited. if you want, you could even handle tab specially; commit the value and close the editor, and even trigger editing on the next cell.

  $spin_button -> signal_connect(key_press_event => sub {
    my (undef, $event) = @_;

    # grab this for later.
    my $parent = $spin_button->get_parent;

    if ($event -> keyval == $Gtk2::Gdk::Keysyms{ Return } ||
        $event -> keyval == $Gtk2::Gdk::Keysyms{ KP_Enter } ||
        $event -> keyval == $Gtk2::Gdk::Keysyms{ Tab }) {
      $spin_button -> update();
$cell -> signal_emit(edited => $path, $spin_button -> get_value());
      $spin_button -> destroy();
      if ($event -> keyval == $Gtk2::Gdk::Keysyms{ Tab } &&
          $parent -> isa ('Gtk2::TreeView')) {
        # tab is usually used to switch between widgets, so take this
        # opportunity to start editing the next cell.
        my ($path, $focus_column) = $parent->get_cursor;
        my @cols = $parent->get_columns;
        my $next_col = undef;
        foreach my $i (0..$#cols) {
          if ($cols[$i] == $focus_column) {
            if ($event->state >= 'shift-mask') {
              # go backwards
              $next_col = $cols[$i-1] if $i > 0;
            } else {
              # go forwards
              $next_col = $cols[$i+1] if $i < $#cols;
        $parent->set_cursor ($path, $next_col, 1)
          if $next_col;
      return 1;
    elsif ($event -> keyval == $Gtk2::Gdk::Keysyms{ Up }) {
$spin_button -> spin('step-forward', ($spin_button -> get_increments())[0]);
      return 1;
    elsif ($event -> keyval == $Gtk2::Gdk::Keysyms{ Down }) {
$spin_button -> spin('step-backward', ($spin_button -> get_increments())[0]);
      return 1;

    return 0;

in fact, i rather like this now that i've played with it for a few minutes, and i think i'll commit it (unless anyone can point out flaws).

$spin_button -> signal_connect(focus_out_event => sub {
     my ($event_box, $event) = @_;
     if($event -> in == 0){
      $spin_button -> update();
      $cell -> signal_emit(edited => $path, $spin_button ->
      $spin_button -> destroy();
      return 1;
    return 0;
this code works fine but produces: Gtk-CRITICAL **: file gtkcontainer.c:
line 984 (gtk_container_remove): assertion `widget->parent ==
GTK_WIDGET (container)' failed at .

this appears to be because the process of emitting the edited signal on the cell causes the editable to be unparented. i'm not sure why connecting to the focus event causes this to come up.

"Quit hittin' yourself!  Quit hittin' yourself!"
   -- Elysse, playing with a newborn baby.

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