Text widget: <<Modified>> and the "edit modified" command

Text widget: <<Modified>> and the "edit modified" command

Post by cattaghi » Sun, 29 Mar 2009 07:05:20


Dear TCLers,

From Tk 8.5 Reference about the text widget: "...The flag can be
queried, set and cleared programmatically as well. Whenever the flag
changes state a <<Modified>> virtual event is generated."

Well, this is more or less what I did in two procedures, both under
the same namespace (I don't know if this makes a difference, but
however):

proc ns::TextWdgSetup { txtwdg } {
...
bind $txtwdg <<Modified>> "[namespace code StatusChange] %W"
}

proc ns::StatusChange {txtwdg} {
# Test line:
set status [$txtwdg edit modified]
puts "New status: $status"
.....
}

Ok. When I load content to the text widget, the StatusChange
procedure is called and prints "New status: 1" in the console.
Expected, right? But right after, in the same proc which filled the
text widget, I reset the modified flag to 0 -- and, not as expected,
StatusChange is *not* invoked by that. It is called only when I type
something in the text widget (always printing "New status: 1", of
course).

I thought it might be something in the command to reset the flag, and
I tried both:

eval "$txtwdg edit modified 0"

and simply

$txtwdg edit modified 0

with same results.

So I ask: what the *** y %$#@ am I doing wrong again? Or, in opposite
to what may be inferred by the reference page, the <<Modified>> event
really does NOT happen when the "edit modified" flag is changed
programmatically??

Thank you all in advance!

Fabricio Rocha
Brasilia, Brasil
 
 
 

Text widget: <<Modified>> and the "edit modified" command

Post by Gerry Snyd » Sun, 29 Mar 2009 07:54:33


Have you tried changing the flag from 0 to 1 programatically?


Gerry

 
 
 

Text widget: <<Modified>> and the "edit modified" command

Post by cattaghi » Sun, 29 Mar 2009 21:44:32

Nice tip, Gerry. I have just tested it, putting a line "$txtwdg edit
modified 1" right after the "$txtwdg edit modified 0".

And YES -- the callback procedure WAS called with that new line. It
means that the <<Modified>> event is being triggered only in one way.
IMHO, it is an inconsistency. Maybe we have found a bug?

Thank you very much and regards!

Fabricio Rocha
Brasilia, Brasil
 
 
 

Text widget: <<Modified>> and the "edit modified" command

Post by Gerry Snyd » Mon, 30 Mar 2009 00:41:02


Fabricio,

To me it seems like a bug in the documentation, perhaps because the flag
and the event work in a way that feels right to me.

In an application of mine, when a user edits the content of the text
widget, I use the <<Modified>> event to enable a Save button. When the
Save button is pushed I save the data, disable the button, and reset the
modified flag. If this last action triggered another <<Modified>> event,
my code would have to check which way the flag changed (or unbind the
<<Modified>> event temporarily when I reset the flag). So the current
actions are right for the simple needs of my task.

But I can certainly imagine other applications where actions would be
required for a change in the flag in either direction.

A workaround for you might be to call the StatusChange command
explicitly whenever you reset the modified flag.


Glad I could help a little, and hope this helps a little more.

Gerry
 
 
 

Text widget: <<Modified>> and the "edit modified" command

Post by cattaghi » Mon, 30 Mar 2009 01:05:25

Sure, Gerry, thanks again! I will have to create a workaround more or
less like this you have mentioned. And maybe you are right about the
bug in documentation, but I still think that it would be more
consistent to have te <<Modified>> event fired in both situations.
Actually my callback was written with this in mind, as it verified the
status flag -- if 0 do this, if 1 do that. I may be wrong, but I
presume that the <<Modified>> event was supposed to work that way...
avoiding code duplication seems to be a strong purpose for that.

Thanks!

Fabricio Rocha
Brasilia, Brasil
 
 
 

Text widget: <<Modified>> and the "edit modified" command

Post by cattaghi » Mon, 30 Mar 2009 04:09:16

Updating: I have just discovered that the "undo mechanism" in the text
widget triggers the <<Modified>> event after setting the "edit
modified" flag to 0.
 
 
 

Text widget: <<Modified>> and the "edit modified" command

Post by Francois V » Mon, 30 Mar 2009 17:51:15

I have filed this issue in the tracker before I think:

https://sourceforge.net/tracker/index.php?func=detail&aid=1871474&group_id=12997&atid=112997

Francois
 
 
 

Text widget: <<Modified>> and the "edit modified" command

Post by cattaghi » Tue, 31 Mar 2009 01:05:37


And it was MORE THAN ONE YEAR AGO and classified as "obsolete"!!
 
 
 

Text widget: <<Modified>> and the "edit modified" command

Post by Don Porte » Tue, 31 Mar 2009 01:19:03


No.

That bug is still Open.

The "obsolete" term describes the release Tk 8.5.0 which
is obsolete because Tk 8.5.6 is available.

DGP
 
 
 

Text widget: <<Modified>> and the "edit modified" command

Post by cattaghi » Tue, 31 Mar 2009 07:40:10

Thanks and sorry for the misinterpretation, TCT Porter!
By the way, 8.5.6 is the version I use, if the information is useful.