Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The Perl debugger will not run on a 19,000 line program for a specialized text editor that I am trying to refactor. I believe the program occurs when one custom widget delegates to another custom subwidget. The first widget is called TextUnicode based on TextEdit with special methods to handle Unicode files. The second is called LineNumberText based on ROText to provide line numbers down the right hand side of the screen. Does this diagnosis sound correct and is there a simple fix I could use? Or do I need to combine these two widgets into one to avoid teh double delegation issue? The code can be found here:http://guiguts.svn.sourceforge.net/viewvc/guiguts/branches/devel/lib/Guiguts/. Here is the beginning of the two widgets:
package TextUnicode; use base qw(Tk::TextEdit); use File::Temp qw/tempfile/; use File::Basename; Construct Tk::Widget 'TextUnicode'; sub Load {... sub SaveUTF {... ---------------------------- package Guiguts::LineNumberText; use Tk; use Tk::widgets qw(ROText); use base qw(Tk::Frame); Construct Tk::Widget 'LineNumberText'; sub Populate { my ( $self, $args ) = @_; $self->SUPER::Populate($args); $self->{'minwidth'} = 5; $self->{'linenumshowing'} = 0; my $widget; if ( $widget = delete $args->{-widget} ) { $widget = 'TextUnicode'; } else { $widget = 'Text'; } my $ltext = $self->ROText( -takefocus => 0, -cursor => 'X_cursor', -bd => 2, -relief => 'flat', -width => $self->{'minwidth'}, -wrap => 'none', ); $ltext->{_MENU_} = (); $self->{'ltext'} = $ltext; $ltext->tagConfigure( 'CURLINE', -data => 1 ); $ltext->tagConfigure( 'RIGHT', -justify => 'right' ); my $ftext = $self->Scrolled($widget) ->grid( -row => 0, -column => 1, -sticky => 'nsew' ); $self->{'rtext'} = my $rtext = $ftext->Subwidget('scrolled'); $self->gridColumnconfigure( 1, -weight => 1 ); $self->gridRowconfigure( 0, -weight => 1 ); $self->Advertise( 'yscrollbar', $ftext->Subwidget('yscrollbar') ); $self->Advertise( 'xscrollbar', $ftext->Subwidget('xscrollbar') ); $self->Advertise( 'corner', $ftext->Subwidget('corner') ); $self->Advertise( 'frame', $ftext ); $self->Advertise( 'scrolled', $rtext ); $self->Advertise( 'text', $rtext ); $self->Advertise( 'linenum', $ltext ); # Set scrolling command to run the lineupdate.. my $yscroll = $self->Subwidget('yscrollbar'); my $scrollcommand = $yscroll->cget( -command ); $yscroll->configure( -command => sub { $scrollcommand->Call(@_); $self->_lineupdate; } ); $self->ConfigSpecs( -linenumside => [ 'METHOD', undef, undef, 'left' ] +, -linenumbg => [ 'METHOD', 'numlinebg', 'numLinebg', '#eaeaea +' ], -linenumfg => [ 'METHOD', 'numlinefg', 'numLinefg', '#000000 +' ], -curlinehighlight => [ 'PASSIVE', undef, undef, 1 ], -curlinebg => [ 'METHOD', undef, undef, '#00ffff' ], -curlinefg => [ 'METHOD', undef, undef, '#000000' ], -background => [ $ftext, undef, undef, undef ], -foreground => [ $ftext, undef, undef, undef ], -scrollbars => [ $ftext, undef, undef, 'se' ], -font => ['CHILDREN'], -spacing1 => ['CHILDREN'], -spacing2 => ['CHILDREN'], -spacing3 => ['CHILDREN'], 'DEFAULT' => [$rtext], ); $self->Delegates( 'DEFAULT' => 'scrolled' ); #Bindings $ltext->bind( '<FocusIn>', sub { $rtext->focus } ); $ltext->bind( '<Map>', sub { $self->_lineupdate } ); $rtext->bind( '<Configure>', sub { $self->_lineupdate } ); $rtext->bind( '<KeyPress>', sub { $self->_lineupdate } ); $rtext->bind( '<ButtonPress>', sub { $self->{'rtext'}->{'origx'} = undef; $self->_lineupdate; } ); $rtext->bind( '<Return>', sub { $self->_lineupdate } ); $rtext->bind( '<ButtonRelease-2>', sub { $self->_lineupdate } ); $rtext->bind( '<B2-Motion>', sub { $self->_lineupdate } ); $rtext->bind( '<B1-Motion>', sub { $self->_lineupdate } ); $rtext->bind( '<<autoscroll>>', sub { $self->_lineupdate } ); $rtext->bind( '<MouseWheel>', sub { $self->_lineupdate } ); if ( $Tk::platform eq 'unix' ) { $rtext->bind( '<4>', sub { $self->_lineupdate } ); $rtext->bind( '<5>', sub { $self->_lineupdate } ); } my @textMethods = qw/insert delete Delete deleteBefore Contents deleteSelected deleteTextTaggedwith deleteToEndofLine FindAndReplaceAll GotoL +ineNumber Insert InsertKeypress InsertSelection insertTab openLine yview + ReplaceSelectionsWith Transpose see/; if ( ref($rtext) eq 'TextUnicode' ) { push( @textMethods, 'Load', 'SaveUTF', 'IncludeFile', 'ntinsert', 'ntdelete', 'replacewith' ); } for my $method (@textMethods) { no strict 'refs'; *{$method} = sub { my $cw = shift; my @arr = $cw->{'rtext'}->$method(@_); $cw->_lineupdate; @arr; }; } } # end Populate

In reply to Perl Debugger with Two Customs Tk Widgets by hmonroe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-20 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found