Thread Subject: twelti

Subject: twelti

From: Todd Welti

Date: 6 Nov, 2008 20:55:04

Message: 1 of 6

I have a strange problem. I have a gui, with an edit box, with some default text in it. The callback of the edit box executes when I click inside the box and then click outside the box, even though the text in the text box has not changed. so: i open the gui, click on the first text bx, then click outside it, and the callback always executes, even though no change to the content of that text field. I thought that somewhere, some other code was changing the contents of that field during initialization of the gui (perhaps a CreateFcn from another gui object), but i dont see that anywhere in the code.

anyone ever had this problem?

Subject: twelti

From: Walter Roberson

Date: 6 Nov, 2008 21:26:10

Message: 2 of 6

Todd Welti wrote:
> I have a strange problem. I have a gui, with an edit box, with some default text in it.
> The callback of the edit box executes when I click inside the box and then click
> outside the box, even though the text in the text box has not changed.

That behaviour is consistent with the documentation for the Callback property of
uicontrols:

>>> To execute the callback routine for an edit text control, type in the desired
>>> text and then do one of the following:
>>>
>>> Click another component, the menu bar, or the background of the GUI.
>>>
>>> For a single line editable text box, press Enter.
>>>
>>> For a multiline editable text box, press Ctl+Enter.

You activated the control, you typed in the desired new text (which
happened to be empty), and you clicked another component, the menu bar,
or the background of the GUI, so as documented, the Callback fired.

If it is presenting a problem, store the previous String value in the User
field of the edit control, and when the Callback fires, get() the User field
and compare it to the current String value, and if they are the same, return
without doing anything (and if they differ, remember to save the new String
into the User field.)

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: twelti

From: Todd Welti

Date: 6 Nov, 2008 22:11:02

Message: 3 of 6

Walter Roberson <roberson@hushmail.com> wrote in message <lhJQk.379$JW.62@newsfe01.iad>...
> Todd Welti wrote:
> > I have a strange problem. I have a gui, with an edit box, with some default text in it.
> > The callback of the edit box executes when I click inside the box and then click
> > outside the box, even though the text in the text box has not changed.
>
> That behaviour is consistent with the documentation for the Callback property of
> uicontrols:
>
> >>> To execute the callback routine for an edit text control, type in the desired
> >>> text and then do one of the following:
> >>>
> >>> Click another component, the menu bar, or the background of the GUI.
> >>>
> >>> For a single line editable text box, press Enter.
> >>>
> >>> For a multiline editable text box, press Ctl+Enter.
>
> You activated the control, you typed in the desired new text (which
> happened to be empty), and you clicked another component, the menu bar,
> or the background of the GUI, so as documented, the Callback fired.
>
> If it is presenting a problem, store the previous String value in the User
> field of the edit control, and when the Callback fires, get() the User field
> and compare it to the current String value, and if they are the same, return
> without doing anything (and if they differ, remember to save the new String
> into the User field.)
>
> --
> .signature note: I am now avoiding replying to unclear or ambiguous postings.
> Please review questions before posting them. Be specific. Use examples of what you mean,
> of what you don't mean. Specify boundary conditions, and data classes and value
> relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

I thought I was clear, the text in the box did not change, I simply clicked in the box, then outside it.

According to the documentation:

Triggering Callback Execution

If the contents of the edit text component have been changed, clicking inside the GUI but outside the edit text causes the edit text callback to execute. The user can also press Enter for an edit text that allows only a single line of text, or Ctrl+Enter for an edit text that allows multiple lines.

Subject: twelti

From: Walter Roberson

Date: 6 Nov, 2008 23:47:44

Message: 4 of 6

Todd Welti wrote:

> According to the documentation:
>
> Triggering Callback Execution
>
> If the contents of the edit text component have been changed, clicking inside the GUI [...]

You are perhaps reading summary documentation that is incorrect. The documentation I
quoted was taken directly from the R2008a uicontrol properties page; I see that the
R2008b documentation is substantially the same:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uicontrol_props.html

The reference documentation for any particular function must be considered to
override any summary documentation or user guide.

> I thought I was clear, the text in the box did not change, I simply clicked in the box,
> then outside it.

Yep, and as I quoted,

>>> To execute the callback routine for an edit text control, type in the desired text and

You -did- type in your desired text, which happened to be the empty set of text.

Suppose the postman walks up to your mailbox, opens it up, pulls bundle of letters out of
his (or her) sack to put in your mailbox, takes a second glance at the letters and realizes
that they are for next-door instead, and so closes your mailbox and leaves again. Zero
letters (the empty set of letters) would have been transfered to your mailbox, but the
mailbox would still have been opened by the postman. And if you have your mailbox rigged
to ring a bell inside "when you get new letters" then chances are that it is really
rigged to detect the mailbox opening and closing rather than the presence of letters.


If that isn't enough of an explanation:

Suppose you click in an edit control and you move the cursor around and you type new
things and you delete old things, and at the end of all of your changes, the new text
happens to be -exactly- the same as the old text. Then the content hasn't changed relative
to what it used to be, right? But the control doesn't know that: all that it knows is
that you went in and you did -something- (even if it was just clicking around and
not doing any typing... well, keyboard isn't proof since you might have used mouse or
you might have used voice commands to make your changes). Controls -could- keep track
of their previous content and -could- compare the old content against the new content
and skip the callback if the content was identical, but it simply isn't worth the trouble
or the extra storage to do so in general. You can follow the procedure I outlined before if
the extra execution is a serious problem.

If you really really don't like the way it is handled, then you can file an enhancement
request (but don't seriously expect that Mathworks will actually change the behaviour
considering the cost of that storage and the low gain involved). Or you could look up old
postings written by Yair Altman and find out how to customize uicontrol behaviours at
the Java level.

The behaviour you are seeing is standard Matlab uicontrol('Style','edit') behaviour.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: twelti

From: Todd Welti

Date: 7 Nov, 2008 01:07:02

Message: 5 of 6

Walter Roberson <roberson@hushmail.com> wrote in message <3mLQk.1735$Bp.1425@newsfe01.iad>...
> Todd Welti wrote:
>
> > According to the documentation:
> >
> > Triggering Callback Execution
> >
> > If the contents of the edit text component have been changed, clicking inside the GUI [...]
>
> You are perhaps reading summary documentation that is incorrect. The documentation I
> quoted was taken directly from the R2008a uicontrol properties page; I see that the
> R2008b documentation is substantially the same:
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uicontrol_props.html
>
> The reference documentation for any particular function must be considered to
> override any summary documentation or user guide.
>
> > I thought I was clear, the text in the box did not change, I simply clicked in the box,
> > then outside it.
>
> Yep, and as I quoted,
>
> >>> To execute the callback routine for an edit text control, type in the desired text and
>
> You -did- type in your desired text, which happened to be the empty set of text.
>
> Suppose the postman walks up to your mailbox, opens it up, pulls bundle of letters out of
> his (or her) sack to put in your mailbox, takes a second glance at the letters and realizes
> that they are for next-door instead, and so closes your mailbox and leaves again. Zero
> letters (the empty set of letters) would have been transfered to your mailbox, but the
> mailbox would still have been opened by the postman. And if you have your mailbox rigged
> to ring a bell inside "when you get new letters" then chances are that it is really
> rigged to detect the mailbox opening and closing rather than the presence of letters.
>
>
> If that isn't enough of an explanation:
>
> Suppose you click in an edit control and you move the cursor around and you type new
> things and you delete old things, and at the end of all of your changes, the new text
> happens to be -exactly- the same as the old text. Then the content hasn't changed relative
> to what it used to be, right? But the control doesn't know that: all that it knows is
> that you went in and you did -something- (even if it was just clicking around and
> not doing any typing... well, keyboard isn't proof since you might have used mouse or
> you might have used voice commands to make your changes). Controls -could- keep track
> of their previous content and -could- compare the old content against the new content
> and skip the callback if the content was identical, but it simply isn't worth the trouble
> or the extra storage to do so in general. You can follow the procedure I outlined before if
> the extra execution is a serious problem.
>
> If you really really don't like the way it is handled, then you can file an enhancement
> request (but don't seriously expect that Mathworks will actually change the behaviour
> considering the cost of that storage and the low gain involved). Or you could look up old
> postings written by Yair Altman and find out how to customize uicontrol behaviours at
> the Java level.
>
> The behaviour you are seeing is standard Matlab uicontrol('Style','edit') behaviour.
>
> --


The text from Uicontrol Properties::Functions, is similar to what I quoted, in that it doesn't really say specifically that just clicking in the box "modifies" the data in it. In any case this can't be right because it only happens the first time after i load the GUI! After the first time, it does not cause the callback to execute. Matlab tech support sent me a simple gui that did not exhibit this behaviour. I think that there is somehting in the initialization of the gui that causes the edit box data to appear to have been changed.

I will check out the java customization, sounds interesting.

Subject: twelti

From: Todd Welti

Date: 10 Nov, 2008 17:28:02

Message: 6 of 6

"Todd Welti" <twelti@harman.com> wrote in message <gevlj8$fpq$1@fred.mathworks.com>...
> I have a strange problem. I have a gui, with an edit box, with some default text in it. The callback of the edit box executes when I click inside the box and then click outside the box, even though the text in the text box has not changed. so: i open the gui, click on the first text bx, then click outside it, and the callback always executes, even though no change to the content of that text field. I thought that somewhere, some other code was changing the contents of that field during initialization of the gui (perhaps a CreateFcn from another gui object), but i dont see that anywhere in the code.
>
> anyone ever had this problem?


Further:

Hello Todd,

This is definitely a bug. I am reporting this to our developers. Thank you for bringing this up.

As a workaround, I have modified your file a little. I am storing the original string content ot edit2 as a guidata. Second, in the callback for edit2, I compare this with the current value of 'String'. If you have modified the content, only then the callback will execute.

Please let me know of your thoughts on this.

Sincerely,
Aditya Joshi

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
gui Todd Welti 6 Nov, 2008 16:01:31
callback Todd Welti 6 Nov, 2008 16:01:31
text edit Todd Welti 6 Nov, 2008 16:01:31
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com