Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Log4perl and Tkx

by Anonymous Monk
on Nov 24, 2011 at 00:43 UTC ( [id://939779]=note: print w/replies, xml ) Need Help??


in reply to Log4perl and Tkx

Yeah, Log::Log4perl::Appender::String isn't quite right for the job, and text widget doesn't support -textvariable

Here is a start, run with it :)

use strict; use warnings; use Tkx; use Log::Log4perl; Main( @ARGV ); exit( 0 ); sub Main { $Tkx::TRACE=64; Tkx::package_require('tile'); Tkx::ttk__setTheme('xpnative');#Tkx::tile__setTheme('xpnative'); my $logger = Log::Log4perl->get_logger; $logger ->level( $Log::Log4perl::INFO ); ## HA! my $appender = Log::Log4perl::Appender::String2->new; $logger->add_appender($appender); my $mw = Tkx::widget->new("."); my $t = $mw->new_text( -padx => 5, -pady => 5, #~ -textvariable => $appender->string_ref, # text doesn't have + textvariable, grr -background => "white", ); $t->g_pack; $appender->tktext( $t ); # text doesn't have textvariable, grr my $b = $mw->new_ttk__button( -text => 'Hello, world', -command => sub { $logger->info("hi"); #~ $mw->g_destroy; }, ); $b->g_pack; $b->configure(); $logger->info("it begins"); Tkx::MainLoop(); } BEGIN { #~ $INC{'TextTextVariable.pm'} = __FILE__; ## http://wiki.tcl.tk/1917# Text variable for text widget $INC{'Log/Log4perl/Appender/String2.pm'} = __FILE__; package Log::Log4perl::Appender::String2; use Log::Log4perl::Appender; our @ISA = qw(Log::Log4perl::Appender); ################################################## # Log dispatcher writing to a string buffer ################################################## ################################################## sub new { ################################################## my $proto = shift; my $class = ref $proto || $proto; my %params = @_; my $self = { name => "unknown name", string => "", %params, }; bless $self, $class; } ################################################## sub log { ################################################## #~ my $self = shift; #~ my %params = @_; # copied from Log::Log4perl::Appender::Str +ing, wtf my ($self, $p, $category, $level, $cache) = @_; my %params = %$p; if( my $status_text = $self->{tktext} ){ warn "wtf is wtf "; # text control has to be enabled to write to it. $status_text->configure(-state => "normal"); $status_text->insert("end", $params{message} ); $status_text->see("end"); # Don't want the user editing this... $status_text->configure(-state => "disabled"); eval { $status_text->update(); 1} or eval { Tkx::update(); + }; } else { $self->{string} .= $params{message}; } } ################################################## sub string { ################################################## my($self, $new) = @_; if(defined $new) { $self->{string} = $new; } return $self->{string}; } ################################################## sub tktext { ################################################## my($self, $new) = @_; if(defined $new) { $self->{tktext} = $new; } return $self->{tktext}; } ################################################## sub string_ref { ################################################## my($self ) = @_; return if $self->{tktext}; return \$self->{string}; } 1; }

Replies are listed 'Best First'.
Re^2: Log4perl and Tkx
by jellisii2 (Hermit) on Jun 18, 2012 at 19:58 UTC

    Sadly, I'm not currently smart enough to do so.

    I've decided to go a different route, (which I'm ALSO having problems with) and will have a string appender tied to a label (which does use a textvariable), but currently I can't seem to get l4p to populate the string appender as I expect it to.

    To view the log, I'm just going to place a button on the UI to open the file in a text editor that can be set from a conf file.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://939779]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-26 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found