.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "POE::Component::IRC::Cookbook::Gtk2 3pm" .TH POE::Component::IRC::Cookbook::Gtk2 3pm "2018-01-01" "perl v5.26.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" POE::Component::IRC::Cookbook::Gtk2 \- An IRC client with a Gtk2 interface .SH "SYNOPSIS" .IX Header "SYNOPSIS" This example uses Gtk2 and POE::Loop::Glib to present an event-driven \s-1GUI\s0 to the user. .SH "DESCRIPTION" .IX Header "DESCRIPTION" .Vb 1 \& #!/usr/bin/env perl \& \& use strict; \& use warnings; \& use Gtk2 \-init; \& use Gtk2::SimpleList; \& use IRC::Utils qw(parse_user strip_color strip_formatting decode_irc); \& use POE qw(Loop::Glib Component::IRC::State Component::IRC::Plugin::Connector); \& \& my $channel = "#IRC.pm\-test"; \& my $irc = POE::Component::IRC::State\->spawn( \& nick => \*(Aqgtk\-example\*(Aq, \& server => \*(Aqirc.perl.org\*(Aq, \& port => 6667, \& ircname => \*(AqTesting\*(Aq, \& debug => 1, \& plugin_debug => 1, \& ) or die "Oh noooo! $!"; \& \& POE::Session\->create( \& package_states => [ \& (_\|_PACKAGE_\|_) => [qw( \& _start \& ui_start \& ui_input \& ui_menu_quit \& ui_about \& ui_about_ok \& irc_start \& irc_001 \& irc_public \& irc_notice \& irc_chan_sync \& irc_nick_sync \& irc_join \& irc_msg \& irc_433 \& )], \& ], \& ); \& \& $poe_kernel\->run(); \& \& my $messages; \& my $buffer; \& my $input; \& my $nicks; \& my $window; \& \& sub _start { \& $_[KERNEL]\->yield(\*(Aqui_start\*(Aq); \& $_[KERNEL]\->yield(\*(Aqirc_start\*(Aq); \& } \& \& sub ui_start { \& my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; \& \& my $window = Gtk2::Window\->new("toplevel"); \& $heap\->{main_window} = $window; \& $kernel\->signal_ui_destroy($heap\->{main_window}); \& \& $heap\->{main_window}\->set_size_request(640, 480); \& \& my $box = Gtk2::VBox\->new(0, 0); \& \& my $menu_file = Gtk2::Menu\->new(); \& my $menu_quit = Gtk2::MenuItem\->new(\*(Aq_Exit\*(Aq); \& \& $menu_quit\->signal_connect(activate => $session\->postback(\*(Aqui_menu_quit\*(Aq)); \& \& $menu_file\->append($menu_quit); \& \& my $menu_help = Gtk2::Menu\->new(); \& my $menu_about = Gtk2::MenuItem\->new(\*(Aq_About\*(Aq); \& $menu_about\->signal_connect(activate => $session\->postback(\*(Aqui_about\*(Aq)); \& $menu_help\->append($menu_about); \& \& my $menu_item_file = Gtk2::MenuItem\->new(\*(Aq_Program\*(Aq); \& my $menu_item_help = Gtk2::MenuItem\->new(\*(Aq_Help\*(Aq); \& $menu_item_file\->set_submenu($menu_file); \& $menu_item_help\->set_submenu($menu_help); \& \& my $menu_bar = Gtk2::MenuBar\->new(); \& $menu_bar\->append($menu_item_file); \& $menu_bar\->append($menu_item_help); \& $box\->pack_start($menu_bar, 0, 0, 0); \& $heap\->{main_window}\->add($box); \& \& my $hbox = Gtk2::HBox\->new(0, 0); \& $box\->pack_start($hbox, 1, 1, 0); \& \& $nicks = Gtk2::SimpleList\->new(\*(Aqnickname\*(Aq, \*(Aqtext\*(Aq); \& $nicks\->set_headers_visible(0); \& $nicks\->set_size_request(120, \-1); \& \& $messages = Gtk2::TextView\->new(); \& $messages\->set_editable(0); \& $messages\->set_size_request(600, \-1); \& \& $hbox\->pack_start($messages, 1, 1, 0); \& $hbox\->pack_start(Gtk2::VSeparator\->new(), 0, 1, 4); \& $hbox\->pack_start($nicks, 1, 1, 0); \& \& $messages\->set_cursor_visible(0); \& $buffer = Gtk2::TextBuffer\->new(); \& \& my $blue = $buffer\->create_tag("fg_blue", foreground => "blue"); \& my $yellow = $buffer\->create_tag("fg_yellow", foreground => "yellow"); \& my $orange = $buffer\->create_tag("fg_orange", foreground => "orange"); \& my $pink = $buffer\->create_tag("fg_pink", foreground => "pink"); \& my $red = $buffer\->create_tag("fg_red", foreground => "red"); \& \& $messages\->set_buffer($buffer); \& \& my $label = Gtk2::Label\->new("Counter"); \& \& $heap\->{counter} = 0; \& $heap\->{counter_label} = Gtk2::Label\->new($heap\->{counter}); \& \& $input = Gtk2::Entry\->new; \& $box\->pack_start($input, 0, 0, 4); \& \& $heap\->{main_window}\->show_all(); \& $input\->grab_focus(); \& $input\->signal_connect(activate => $session\->postback(\*(Aqui_input\*(Aq)); \& } \& \& sub push_buffer { \& my ($start, $end) = $buffer\->get_bounds(); \& my $text = strip_color(strip_formatting($_[0])); \& shift; \& $buffer\->insert_with_tags_by_name($end, $text, @_); \& $messages\->scroll_to_iter($end,0, 0, 0, 0); \& } \& \& sub ui_about { \& my $session = $_[SESSION]; \& my $dialog = Gtk2::MessageDialog\->new( \& $window, \& \*(Aqdestroy\-with\-parent\*(Aq, \& \*(Aqinfo\*(Aq, \& \*(Aqok\*(Aq, \& "POE::Component::IRC with Gtk2 example\enAuthor: Damian Kaczmarek" \& ); \& \& $dialog\->signal_connect(response => $session\->postback(\*(Aqui_about_ok\*(Aq)); \& $dialog\->show(); \& } \& \& sub ui_input { \& my ($self, $response) = @{ $_[ARG1] }; \& my $input = $self\->get_text(); \& \& return if $input eq ""; \& \& if (my ($target, $msg) = $input =~ /^\e/msg (\eS+) (.*)$/) { \& $irc\->yield(privmsg => $target, $msg); \& push_buffer("\-> $target \-> $msg\en", "fg_red"); \& } \& else { \& $irc\->yield(privmsg => $channel, $input); \& push_buffer(\*(Aq<\*(Aq.$irc\->nick_name()."> $input\en"); \& } \& \& $self\->set_text(""); \& } \& \& sub ui_about_ok { \& my ($dialog, $response) = @{ $_[ARG1] }; \& $dialog\->destroy; \& } \& \& sub ui_menu_quit { \& $_[HEAP]{main_window}\->destroy(); \& } \& \& sub irc_start { \& $irc\->plugin_add(\*(AqConnector\*(Aq, POE::Component::IRC::Plugin::Connector\->new()); \& $irc\->yield(register => \*(Aqall\*(Aq); \& $irc\->yield(\*(Aqconnect\*(Aq ); \& } \& \& sub irc_msg { \& my ($user, $recipients, $text) = @_[ARG0..ARG2]; \& my $nick = parse_user($user); \& \& push_buffer("PRIV <$nick> $text\en", "fg_red"); \& } \& \& sub irc_join { \& my ($user, $channel) = (@_[ARG0..ARG1]); \& my ($nick, $username, $host) = parse_user($user); \& \& push_buffer("$nick ($host) joined $channel\en", "fg_pink"); \& } \& \& sub irc_chan_sync { \& @{$nicks\->{data}} = map { [$_] } $irc\->channel_list($channel); \& push_buffer("Synchronized to $channel!\en"); \& } \& \& sub irc_nick_sync { \& @{$nicks\->{data}} = map { [$_] } $irc\->channel_list($channel); \& } \& \& sub irc_001 { \& push_buffer("Connected to IRC server!\en"); \& $irc\->yield(join => $channel); \& } \& \& sub irc_notice { \& my ($user, $recipients, $text) = @_[ARG0..ARG2]; \& my $nick = parse_user($user); \& $text = decode_irc($text); \& push_buffer("$nick : $text\en", "fg_orange"); \& } \& \& sub irc_public { \& my ($user, $where, $what) = @_[ARG0 .. ARG2]; \& my $nick = parse_user($user); \& $what = decode_irc($what); \& push_buffer("<$nick> $what\en"); \& } \& \& sub irc_433 { \& my $new_nick = $irc\->nick_name() . "_"; \& $irc\->yield(nick => $new_nick); \& push_buffer("433 Nick taken ... changing to $new_nick\en", "fg_orange"); \& \& } .Ve .SH "AUTHOR" .IX Header "AUTHOR" Damian Kaczmarek