1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="generator" content="Movable Type 5.2.3" />
8 <link rel="stylesheet" href="http://defaria.com/blogs/Status/styles-site.css" type="text/css" />
9 <link rel="alternate" type="application/atom+xml" title="Atom" href="http://defaria.com/blogs/Status/atom.xml" />
10 <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://defaria.com/blogs/Status/index.xml" />
12 <title>Status for Andrew DeFaria: CreateWOR: Subclassing TextUndo</title>
14 <link rel="start" href="http://defaria.com/blogs/Status/" title="Home" />
15 <link rel="prev" href="http://defaria.com/blogs/Status/archives/000684.html" title="CreateWOR" />
16 <link rel="next" href="http://defaria.com/blogs/Status/archives/000686.html" title="cqtalk" />
19 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
20 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
21 xmlns:dc="http://purl.org/dc/elements/1.1/">
23 rdf:about="http://defaria.com/blogs/Status/archives/000685.html"
24 trackback:ping="http://defaria.com/mt/mt-tb.cgi/72"
25 dc:title="CreateWOR: Subclassing TextUndo"
26 dc:identifier="http://defaria.com/blogs/Status/archives/000685.html"
27 dc:subject="General Dynamics"
28 dc:description=" Added onChange like callbacks to CreateWOR's text field and text widget. This required subclassing the TextUndo class and properly handling the call back...."
30 dc:date="2007-10-03T11:17:48-06:00" />
37 <script type="text/javascript" src="http://defaria.com/blogs/Status/mt-site.js"></script>
39 <body class="layout-one-column" onload="individualArchivesOnLoad(commenter_name)">
41 <div id="container-inner" class="pkg">
44 <div id="banner-inner" class="pkg">
45 <h1 id="banner-header"><a href="http://defaria.com/blogs/Status/" accesskey="1">Status for Andrew DeFaria</a></h1>
46 <h2 id="banner-description">Searchable status reports and work log</h2>
51 <div id="pagebody-inner" class="pkg">
53 <div id="alpha-inner" class="pkg">
55 <p class="content-nav">
56 <a href="http://defaria.com/blogs/Status/archives/000684.html">« CreateWOR</a> |
57 <a href="http://defaria.com/blogs/Status/">Main</a>
58 | <a href="http://defaria.com/blogs/Status/archives/000686.html">cqtalk »</a>
62 <div class="entry" id="entry-685">
63 <h3 class="entry-header">CreateWOR: Subclassing TextUndo</h3>
64 <div class="entry-content">
65 <div class="entry-body">
67 <li>Added onChange like callbacks to CreateWOR's text field and text widget. This required subclassing the TextUndo class and properly handling the call back.</li>
70 <div id="more" class="entry-more">
71 <h3>Subclassing TextUndo</h3>
73 <p>This is not working exactly as it should. I can't seem to store things like the onChange callback and a scalar representing the contents of the TextUndo widget in the new MyText object. I rely on overriding the methods InsertKeypress, insert, delete and replace in order to trap when modifications are made to the text, changing the $text member and to call the appropriate callback, but the object that's passed in is different than the object as it was in new and member variables for $text and $modified_CB are missing! So instead I use a package global but this means that only one, the same one, $modification_CB is used for all instantiations of MyText and the $text variable doesn't work at all. Instead one must call get_text in the &$modified_CB:</p>
76 # Subclass TextUndo widget to trap and call subroutine when text changes
80 use base qw/Tk::TextUndo/;
82 Construct Tk::Widget "MyText";
91 $modified_CB = delete $parms{-modified} if $parms{-modified};
92 $self->{text} = delete $parms{-text} if $parms{-text};
94 $class->SUPER::new ($self, %parms);
100 return $self->{text};
106 $self->SUPER::InsertKeypress (@_);
107 $self->{text} = $self->get ("1.0", "end");
108 &$modified_CB ($self) if $modified_CB;
114 $self->SUPER::insert (@_);
115 $self->{text} = $self->get ("1.0", "end");
121 $self->SUPER::delete (@_);
122 $self->{text} = $self->get ("1.0", "end");
123 &$modified_CB ($self) if $modified_CB;
129 $self->SUPER::replace (@_);
130 $self->{text} = $self->get ("1.0", "end");
131 &$modified_CB ($self) if $modified_CB;
137 <p class="entry-footer">
138 <span class="post-footers">Posted by on October 3, 2007 11:17 AM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000685.html">Permalink</a>
143 <div class="trackbacks">
144 <h3 id="trackback" class="trackbacks-header">TrackBack</h3>
145 <div id="trackbacks-info">
146 <p>TrackBack URL for this entry:<br />http://defaria.com/mt/mt-tb.cgi/72</p>
148 <div class="trackbacks-content">