Gtk3-Ex-DBI
view release on metacpan or search on metacpan
lib/Gtk3/Ex/DBI/Datasheet.pm view on Meta::CPAN
[qw(readable writable)]
)
];
use constant x_padding => 2;
use constant y_padding => 3;
use constant arrow_width => 15;
use constant arrow_height => 15;
sub hide_popup {
my ( $cell ) = @_;
Gtk3->grab_remove( $cell->{ _popup } );
$cell->{ _popup }->hide();
}
sub get_today {
my ( $cell ) = @_;
my ( $day, $month, $year ) = (localtime())[3, 4, 5];
$year += 1900;
lib/Gtk3/Ex/DBI/Datasheet.pm view on Meta::CPAN
my ( $cell, $year, $month, $day ) = @_;
return ( $year, sprintf("%02d", $month), sprintf("%02d", $day) );
}
sub INIT_INSTANCE {
my ( $cell ) = @_;
my $popup = Gtk3::Window->new ('popup');
my $vbox = Gtk3::VBox->new( 0, 0 );
my $calendar = Gtk3::Calendar->new();
#$calendar->modify_font( Gtk3::Pango::FontDescription->from_string( "Arial " . $cell->get( "font" ) ) );
$calendar->modify_font( Pango::FontDescription::from_string( "Arial " . $cell->get( "font" ) ) );
my $hbox = Gtk3::HBox->new( 0, 0 );
my $today = Gtk3::Button->new('Today');
lib/Gtk3/Ex/DBI/Datasheet.pm view on Meta::CPAN
$hbox->pack_start( $today, 1, 1, 0 );
$hbox->pack_start( $none, 1, 1, 0 );
$vbox->pack_start( $calendar, 1, 1, 0 );
$vbox->pack_start( $hbox, 0, 0, 0 );
# Find out if the click happended outside of our window. If so, hide it.
# Largely copied from Planner (the former MrProject).
# Implement via Gtk3::get_event_widget?
$popup->signal_connect( button_press_event => sub {
my ( $popup, $event ) = @_;
if ( $event->button() == 1 ) {
my ( $x, $y ) = ( $event->x_root(), $event->y_root() );
my ( $xoffset, $yoffset ) = $popup->window()->get_root_origin();
my $allocation = $popup->allocation();
my $x1 = $xoffset + 2 * $allocation->x();
my $y1 = $yoffset + 2 * $allocation->y();
my $x2 = $x1 + $allocation->width();
my $y2 = $y1 + $allocation->height();
unless ( $x > $x1 && $x < $x2 && $y > $y1 && $y < $y2 ) {
$cell->hide_popup();
return 1;
}
}
return 0;
} );
$popup->add( $vbox );
$cell->{ _popup } = $popup;
$cell->{ _calendar } = $calendar;
}
sub START_EDITING {
my ( $cell, $event, $view, $path, $background_area, $cell_area, $flags ) = @_;
my $popup = $cell -> { _popup };
my $calendar = $cell->{ _calendar };
# Specify the callbacks. Will be called by the signal handlers set up in
# INIT_INSTANCE.
$cell->{ _today_clicked_callback } = sub {
my ($button) = @_;
my ($year, $month, $day) = $cell -> get_today();
$cell->signal_emit( edited=>$path, join( "-", $cell->add_padding( $year, $month, $day ) ) );
$cell->hide_popup();
};
$cell->{ _none_clicked_callback } = sub {
my ( $button ) = @_;
$cell->signal_emit( edited=>$path, "" );
$cell->hide_popup();
};
$cell->{ _day_selected_double_click_callback } = sub {
my ( $calendar ) = @_;
my ( $year, $month, $day ) = $calendar->get_date();
$cell->signal_emit( edited => $path, join( "-", $cell -> add_padding( $year, ++$month, $day ) ) );
$cell->hide_popup();
};
$cell->{ _month_changed } = sub {
my ( $calendar ) = @_;
my ( $selected_year, $selected_month ) = $calendar->get_date();
my ( $current_year, $current_month, $current_day ) = $cell->get_today();
lib/Gtk3/Ex/DBI/Datasheet.pm view on Meta::CPAN
$calendar->unmark_day( $current_day );
}
};
my ( $year, $month, $day ) = $cell->get_date();
$calendar->select_month( $month - 1, $year );
$calendar->select_day( $day );
# Necessary to get the correct allocation of the popup.
$popup->move( -500, -500 );
$popup->show_all();
# Figure out where to put the popup - ie don't put it offscreen,
# as it's not movable ( by the user )
my $screen_height = $popup->get_screen->get_height;
my $requisition = $popup->size_request();
my $popup_width = $requisition->width;
my $popup_height = $requisition->height;
my ( $x_origin, $y_origin ) = $view->get_bin_window()->get_origin();
my ( $popup_x, $popup_y );
$popup_x = $x_origin + $cell_area->{x} + $cell_area->{width} - $popup_width;
$popup_x = 0 if $popup_x < 0;
$popup_y = $y_origin + $cell_area->{y} + $cell_area->{height};
if ( $popup_y + $popup_height > $screen_height ) {
$popup_y = $y_origin + $cell_area->{y} - $popup_height;
}
$popup->move( $popup_x, $popup_y );
# Grab the focus and the pointer.
#Gtk3->grab_add( $popup );
$popup->grab_add;
$popup->grab_focus();
# Gtk3::Gdk::pointer_grab(
# $popup,
# 1,
# [ qw( button-press-mask button-release-mask pointer-motion-mask ) ],
# undef,
# undef,
# 0
# );
return;
}
lib/Gtk3/Ex/DBI/Datasheet.pm view on Meta::CPAN
# Glib::ParamSpec->string( "time", "Time", "What's the time again?", "", [qw(readable writable)] ),
# ]
#;
#
#use constant x_padding => 2;
#use constant y_padding => 3;
#
#use constant arrow_width => 15;
#use constant arrow_height => 15;
#
#sub hide_popup {
#
# my $cell = shift;
#
# Gtk3->grab_remove( $cell->{ _popup } );
# $cell->{ _popup }->hide();
#
#}
#
#sub get_time {
#
# my $cell = shift;
#
# my $text = $cell->get( "time" );
# my ( $h, $m, $s ) = split( /:/, $text );
#
lib/Gtk3/Ex/DBI/Datasheet.pm view on Meta::CPAN
# my ( $cell, $h, $m, $s ) = @_;
#
# return ( sprintf( "%02d",$h ), sprintf( "%02d", $m ), sprintf( "%02d", $s ) );
#
#}
#
#sub INIT_INSTANCE {
#
# my $cell = shift;
#
# my $popup = Gtk3::Window->new( 'popup' );
# my $vbox = Gtk3::VBox->new( 0, 0 );
#
# my $h_spinbutton = Gtk3::SpinButton -> new_with_range( 0, 23, 1 );
# my $m_spinbutton = Gtk3::SpinButton -> new_with_range( 0, 59, 1 );
# my $s_spinbutton = Gtk3::SpinButton -> new_with_range( 0, 59, 1 );
# my $colon_1 = Gtk3::Label->new( ":" );
# my $colon_2 = Gtk3::Label->new( ":" );
#
# my $spin_hbox = Gtk3::HBox->new( 0, 0 );
# my $buttons_hbox = Gtk3::HBox->new( 0, 0 );
lib/Gtk3/Ex/DBI/Datasheet.pm view on Meta::CPAN
#
# $ok->signal_connect( clicked => sub {
# $cell->{ _ok_clicked_callback }->( @_ )
# if ( exists( $cell->{ _ok_clicked_callback } ) );
# } );
#
# # Find out if the click happended outside of our window. If so, hide it.
# # Largely copied from Planner (the former MrProject).
#
# # Implement via Gtk3::get_event_widget?
# $popup -> signal_connect( button_press_event => sub {
# my ( $popup, $event ) = @_;
# if ( $event->button() == 1 ) {
# my ( $x, $y ) = ( $event->x_root, $event->y_root );
# my ( $xoffset, $yoffset ) = $popup->window->get_root_origin;
# my $allocation = $popup->allocation;
# my $x1 = $xoffset + 2 * $allocation->x;
# my $y1 = $yoffset + 2 * $allocation->y;
# my $x2 = $x1 + $allocation->width;
# my $y2 = $y1 + $allocation->height;
# unless ( $x > $x1 && $x < $x2 && $y > $y1 && $y < $y2 ) {
# $cell->hide_popup;
# return 1;
# }
# }
# return 0;
# } );
#
# $popup->add( $vbox );
#
# $cell->{ _popup } = $popup;
# $cell->{ _h_spinbutton } = $h_spinbutton;
# $cell->{ _m_spinbutton } = $m_spinbutton;
# $cell->{ _s_spinbutton } = $s_spinbutton;
#
#}
#
#sub START_EDITING {
#
# my ( $cell, $event, $view, $path, $background_area, $cell_area, $flags ) = @_;
#
# my $popup = $cell->{ _popup };
# my $h_spinbutton = $cell->{ _h_spinbutton };
# my $m_spinbutton = $cell->{ _m_spinbutton };
# my $s_spinbutton = $cell->{ _s_spinbutton };
#
# my ( $h, $m, $s ) = $cell->get_time;
#
# $h_spinbutton->set_value( $h );
# $m_spinbutton->set_value( $m );
# $s_spinbutton->set_value( $s );
#
lib/Gtk3/Ex/DBI/Datasheet.pm view on Meta::CPAN
# my ( $button ) = @_;
# my $h = $h_spinbutton->get_text;
# my $m = $m_spinbutton->get_text;
# my $s = $s_spinbutton->get_text;
#
# $cell->signal_emit(
# edited => $path,
# join( ":", $cell -> add_padding( $h, $m, $s ) )
# );
#
# $cell->hide_popup;
#
# };
#
# # Necessary to get the correct allocation of the popup.
# $popup->move( -500, -500 );
# $popup->show_all;
#
# # Figure out where to put the popup - ie don't put it offscreen,
# # as it's not movable ( by the user )
# my $screen_height = $popup->get_screen->get_height;
# my $requisition = $popup->size_request;
# my $popup_width = $requisition->width;
# my $popup_height = $requisition->height;
# my ( $x_origin, $y_origin ) = $view->get_bin_window->get_origin;
# my ( $popup_x, $popup_y );
#
# $popup_x = $x_origin + $cell_area->{x} + $cell_area->{width} - $popup_width;
# $popup_x = 0 if $popup_x < 0;
#
# $popup_y = $y_origin + $cell_area->{y} + $cell_area->{height};
#
# if ( $popup_y + $popup_height > $screen_height ) {
# $popup_y = $y_origin + $cell_area->{y} - $popup_height;
# }
#
# $popup -> move( $popup_x, $popup_y );
#
# # Grab the focus and the pointer.
# Gtk3->grab_add( $popup );
# $popup->grab_focus;
#
# Gtk3::Gdk->pointer_grab(
# $popup->window,
# 1,
# [ qw( button-press-mask button-release-mask pointer-motion-mask ) ],
# undef,
# undef,
# 0
# );
#
# return;
#
#}
lib/Gtk3/Ex/DBI/Form.pm view on Meta::CPAN
}
if ( ! $self->{skip_query} ) {
$self->query;
}
# We connect a few little goodies to various widgets ...
# - Connect our 'changed' method to whatever signal each widget emits when it's 'changed'
# - Use the populate-popup signal of Gtk3::Entry widgets to add the 'find' menu item
# - Connect to the 'key-press-event' signal of various widgets to move the focus along
# ( ie as if the TAB key was pressed )
# We also keep an array of widgets and signal ids so that we can disconnect all signal handlers
# and cleanly destroy ourselves when requested
# We also set up input / output formatters based on widget ( ie $self->{widgets} )
# Set up some defaults for different widget types
lib/Gtk3/Ex/DBI/Form.pm view on Meta::CPAN
} elsif ( $type eq "Gtk3::CheckButton" ) {
push @signals, $widget->signal_connect_after(
toggled => sub { $self->changed( $fieldname ) } );
} elsif ( $type eq "Gtk3::Entry" ) {
push @signals, $widget->signal_connect_after(
changed => sub { $self->changed( $fieldname ) } );
push @signals, $widget->signal_connect_after(
'populate-popup' => sub { $self->build_entry_right_click_menu(@_) } );
push @signals, $widget->signal_connect(
'activate' => sub { $self->{window}->child_focus('tab-forward') } );
} elsif ( $type eq "Gtk3::Combo" ) {
push @signals, $widget->signal_connect_after(
'button-press' => sub { $self->on_combo_button_press_event(@_) } );
} elsif ( $type eq "Gtk3::SpinButton" ) {
push @signals, $widget->signal_connect_after(
changed => sub { $self->changed( $fieldname ) } );
push @signals, $widget->signal_connect_after(
'populate-popup' => sub { $self->build_entry_right_click_menu(@_) } );
push @signals, $widget->signal_connect(
'key-press-event' => sub { $self->process_entry_keypress(@_) } );
} else {
push @signals, $widget->signal_connect_after(
changed => sub { $self->changed( $fieldname ) } );
}
# ... and then warn() some info about what we're doing, and also append
( run in 1.215 second using v1.01-cache-2.11-cpan-364913b4093 )