]> jfr.im git - irc/xchat.git/commitdiff
Sample script on making use of the get_info( "win_ptr" )
authorlsitu <redacted>
Wed, 6 May 2009 23:41:09 +0000 (23:41 +0000)
committerlsitu <redacted>
Wed, 6 May 2009 23:41:09 +0000 (23:41 +0000)
git-svn-id: svn://svn.code.sf.net/p/xchat/svn@1340 893a96be-7f27-4fdf-9d1e-6aeec9d3cce1

plugins/perl/char_count.pl [new file with mode: 0644]

diff --git a/plugins/perl/char_count.pl b/plugins/perl/char_count.pl
new file mode 100644 (file)
index 0000000..0605f3c
--- /dev/null
@@ -0,0 +1,82 @@
+
+use strict;
+use warnings;
+use Xchat qw(:all);
+use Glib;
+use Gtk2 -init;
+
+sub get_inputbox {
+       my $widget = Glib::Object->new_from_pointer( get_info( "win_ptr" ), 0 );
+       my $input_box;
+
+       my @containers = ($widget);
+
+       while( @containers ) {
+               my $container = shift @containers;
+
+               for my $child ( $container->get_children ) {
+                       if( $child->get( "name" ) eq 'xchat-inputbox' ) {
+                               $input_box = $child;
+                               last;
+                       } elsif( $child->isa( "Gtk2::Container" ) ) {
+                               push @containers, $child;
+                       }
+               }
+       }
+       return $input_box;
+}
+
+sub get_hbox {
+       my $widget = shift;
+       my $hbox;
+
+       while( $widget->parent ) {
+               if( $widget->parent->isa( "Gtk2::HBox" ) ) {
+                       return $widget->parent;
+               }
+               $widget = $widget->parent;
+       }
+
+}
+
+my $input_box = get_inputbox();
+
+if( $input_box ) {
+       my $hbox = get_hbox( $input_box );
+       if( $hbox ) {
+               my $label = Gtk2::Label->new();
+               $hbox->pack_end( $label, 0, 0, 5 );
+               $label->show();
+
+               hook_print( "Key Press",
+                       sub {
+                               my $ctx_type = context_info->{"type"};
+                               if( $ctx_type == 2 || $ctx_type == 3 ) {
+                                       my $count = length get_info "inputbox";
+                                       $label->set_text( $count ? $count : "" );
+                               } else {
+                                       $label->set_text( "" );
+                               }
+                               return EAT_NONE;
+                       }
+               );
+
+               hook_command( "",
+                       sub {
+                               $label->set_text( "" );
+                               return EAT_NONE;
+                       }
+               );
+               register( "Character Counter", "1.0.0",
+                       "Display the number of characters in the inputbox",
+                       sub {
+                               $hbox->remove( $label );
+                       }
+               );
+       } else {
+               prnt "Counldn't find hbox";
+       }
+
+} else {
+       prnt "Couldn't fint input box";
+}