Time column in a list



Hello again,

I have time strings in format hh:mm:ss,sss. I would like these to be editable so that one can input only a valid time, meaning that the text should be overwritten and the cursor should jump over the colons and the comma. I got rather good results experimenting with signal 'insert-text' in a regular Gtk2::Entry.

Now I'd like to do the same for a column in a list. I'm assuming I need a custom cell renderer that uses a Gtk2::Entry. I have looked through the examples of various custom cell renderers but I'm still very lost. The code below is a test app I have tried, but it keeps giving the error

`GTK_IS_CELL_EDITABLE (*editable_widget)' failed.

How do I get to edit the text or am I compeletely on the wrong track?

Osmo Salomaa

-------------------

#!/usr/bin/perl

use strict;
use warnings;

#=====================================================================
# CellRenderer for time in format hh:mm:ss,sss =======================
#=====================================================================

package Foo::CellRendererTime;


use Gtk2 -init;
use Gtk2::Gdk::Keysyms;
use Glib qw(TRUE FALSE);

use Glib::Object::Subclass
        'Gtk2::CellRendererText',
;


sub START_EDITING {
        
        my ($cell, $event, $list, $path, $bg_area, $cell_area, $flags) = @_;

        my $entry = Gtk2::Entry->new;
        $entry->set_text($cell->get('text'));
        $entry->set_activates_default(TRUE);
        
        $entry->signal_connect('insert-text' => sub {
                print "Inserted text.\n";
        });
        
        $entry->grab_focus;
        $entry->show;

        return $entry;

}


#=====================================================================
# Test app: ==========================================================
#=====================================================================

package main;


use Gtk2 -init;
use Glib qw(TRUE FALSE);
use Gtk2::SimpleList;


my $window = Gtk2::Window->new;
$window->set_title('Test CR');
$window->signal_connect(delete_event => sub { Gtk2->main_quit });

Gtk2::SimpleList->add_column_type('time',
                type            => 'Glib::Scalar',
                renderer        => 'Foo::CellRendererTime',
                attr            => sub {
                        my ($treecol, $cell, $model, $iter, $col_num) = @_;
                        my $info = $model->get($iter, $col_num);
                        $cell->set(text => $info);
                }
);
        
my $list = Gtk2::SimpleList->new(
                'Time' => 'time',
                'Text' => 'text',
);
        
$list->set_column_editable(0, TRUE);
$list->set_column_editable(1, TRUE);
        
$list->columns_autosize();

push @{$list->{data}}, [ '01:12:25,356', '00:24:05,658' ];

my $scroller = Gtk2::ScrolledWindow->new;
$scroller->set_policy('automatic', 'automatic');
$scroller->add($list);

$window->add($scroller);
$window->set_default_size(200, 100);
$window->set_position('center-always');
$window->show_all;

Gtk2->main;



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