#!/usr/bin/env perl use strict; use warnings; use diagnostics; use feature qw(say); use utf8; use Gtk3; use Readonly; Readonly my @LINKS => ( { url => 'http://www.seznam.cz/', title => 'Seznam.cz', }, { url => 'http://www.google.cz/', title => 'Google', }, { url => 'http://www.next-url.cz/', title => 'Next URL', }, ); # Links to display Readonly my %CONST => ( WINDOW_TITLE => 'Clipboard', WINDOW_BORDER_WIDTH => 10, WINDOW_WIDTH => 500, WINDOW_HEIGHT => 300, SPACING => 10, # All these numbers are in pixels ); # Some constants for better understanding Gtk3->init; # Initialize Gtk3 my $window = Gtk3::Window->new('toplevel'); my $scrolledwin = Gtk3::ScrolledWindow->new(undef, undef); my $pressed_ctrl = 0; my $store = Gtk3::ListStore->new('Glib::String', 'Glib::String'); my $view = Gtk3::TreeView->new; my $renderer = Gtk3::CellRendererText->new; my $vbox_main = Gtk3::Box->new('vertical', $CONST{SPACING}); my $hbox_bla = Gtk3::Box->new('horizontal', $CONST{SPACING}); my $button_copy = Gtk3::Button->new; my $column; my $iter; for my $item (@LINKS) { $iter = $store->append; $store->set($iter, 0 => $item->{title}, 1 => $item->{url}); } $view->set_model($store); $column = Gtk3::TreeViewColumn->new_with_attributes( 'Title of page', $renderer, text => 0 ); $view->append_column($column); $column = Gtk3::TreeViewColumn->new_with_attributes( 'URL of page', $renderer, text => 1 ); $view->append_column($column); $scrolledwin->add($view); $button_copy->set_label('Copy URL to clipboard'); $button_copy->signal_connect(clicked => sub { my $selection = $view->get_selection; my @selpaths = $selection->get_selected_rows; for my $tpath ($selpaths[0]) { say '$tpath --> ', $tpath; for my $tp (@$tpath) { say '$tp --> ', $tp; my $iter = $store->get_iter($tp); my $col0content = $store->get($iter, 0); my $col1content = $store->get($iter, 1); say '$col0content --> ', $col0content; say '$col1content --> ', $col1content; my $clipboard = Gtk3::Clipboard->get; # XXX $clipboard->set_text($col1content); } } return; }); $vbox_main->pack_start($scrolledwin, 1, 1, 0); $vbox_main->pack_start($hbox_bla, 0, 0, 0); $hbox_bla->pack_start($button_copy, 0, 0, 0); $window->set_title($CONST{WINDOW_TITLE}); $window->set_border_width($CONST{WINDOW_BORDER_WIDTH}); $window->set_default_size($CONST{WINDOW_WIDTH}, $CONST{WINDOW_HEIGHT}); $window->signal_connect(destroy => sub { Gtk3->main_quit; return; }); $window->signal_connect(key_press_event => sub { my $self = shift; my $event = shift; $event = $event->keyval; if ($event == Gtk3::Gdk::KEY_Control_L or $event == Gtk3::Gdk::KEY_Control_R ) { $pressed_ctrl = 1; return; } if ($event == Gtk3::Gdk::KEY_w or $event == Gtk3::Gdk::KEY_q ) { if ($pressed_ctrl) { Gtk3->main_quit; return; } return; } return; }); $window->signal_connect(key_release_event => sub { my $self = shift; my $event = shift; $event = $event->keyval; if ($event == Gtk3::Gdk::KEY_Control_L or $event == Gtk3::Gdk::KEY_Control_R ) { $pressed_ctrl = 0; return; } return; }); $window->add($vbox_main); $window->show_all; Gtk3->main; # Gtk3 main loop #### $ perl clipboard.pl $tpath --> ARRAY(0x9f46000) $tp --> Gtk3::TreePath=SCALAR(0x9f45ff0) $col0content --> Seznam.cz $col1content --> http://www.seznam.cz/ *** unhandled exception in callback: *** Cannot convert scalar a4a8bf0 to an object of type Gtk3::Gdk::Atom at clipboard.pl line 86. *** ignoring at /usr/share/perl5/vendor_perl/Gtk3.pm line 321.