Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Log4perl and Tkx

by Anonymous Monk
on Nov 24, 2011 at 00:43 UTC ( #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
Node Status?
node history
Node Type: note [id://939779]
help
Chatterbox?
[Corion]: Heh - vroom came with interesting news - the site will likely be migrated away from *BSD to Ubuntu soonish... Hopefully I can give the new environment a test drive before it spins up :)
[Corion]: Also, that likely means we'll get a newer Perl, so we could then move the codebase to newer features ;)
[Discipulus]: urrah!
[marto]: Hmm, I sometimes wonder if moving to a new framework (such as mojo) would encourage more developers
[Corion]: marto: Yes, that's the long game, but before that, I want to move away from our custom source code control and move to git, and before that, I want to get the test environment back up running. I have it running at home, but I want/need to set it up ...
[Corion]: ... on a public host again.
[Discipulus]: for sure, but who'll make the initial migration?
[ambrus]: hi all
[Corion]: I don't think that Mojo or whatever would bring much, as the site is heavy on nested templates, but there are some things that could/should be eliminated ;)
[Corion]: Hi ambrus!

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2018-07-19 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (404 votes). Check out past polls.

    Notices?