Pull Down Menu button error?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Pull Down Menu button error?

Post by snm »

I have clean new stack and one card with pullDown menu button with text:

Code: Select all

All
-
Active
Not Active
The script of this button is:

Code: Select all

on menuPick pItemName
   switch pItemName
      case "All"
         answer "All"
         break
      case "Active"
         answer "Active"
         break
      default
         answer "default" 
   end switch
end menuPick
It's working as expected until the label of this button is empty or contains only ASCII characters. But if the label has any accented character like:
Pokaż:
the only answer I get is "default" - doesn't matter what I choose from the menu.

Is it known bug, or do I something wrong?
Why the text of button label could be the reason of such behaviour?

Marek
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Pull Down Menu button error?

Post by bn »

Hi Marek,

I have pasted Pokaż into the menu as line 1. Then I looked at the pItemName in the debugger and shure enough it was not what I expected. Testing against the pasted "Pokaż" in the script was different from pItemName.

I am afraid it is the unicode problem again.

could'nt you use menuHistory instead and compare it to your list of menuItems? MenuHistory gives the number of the line which is chosen.

Code: Select all

on menuPick 
   put the menuHistory of me into tMenuHistory
   answer tMenuHistory
end menuPick
kind regards
Bernd
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Pull Down Menu button error?

Post by jacque »

The solution is to use tags in the menu. See the answer here: http://runtime-revolution.278305.n4.nab ... l#a4668086

Scroll down about half way to the reply by Support Toki.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Pull Down Menu button error?

Post by snm »

Thanks a lot Bernd AND Jacque for quick reply, but you answered and have working solution for my next question not asked yet.

The base question treated the bug which I can't find any roundaround:
If I set the kabel of button as "Pokaż:" then switch / case part of code doesn't work properly and it doesn't matter what content is in the menu list. If there is "default" in the switch statement then it's triggered always. If not, all the switch statement is jumped to end switch.

As I see in debugger, case statement is not triggered even if pItemName is the same as case parameter. The situation change to proper if you put break at switch LINE of code, click pItemName in debugger to edit it, then accept not changed value and click run.

If I change the label of button to English "Show:" (translation to Polish "Pokaż:") or any other label without accented letter, the same switch statement works correct. It's bug which is blocking use switch in program with any language UI containing accented characters.

Marek
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Pull Down Menu button error?

Post by bn »

Marek,

I see what you are observing: as soon as one choice contains unicode characters the switch does not work.

But if you follow Jacque's link and do the "/|" trick it works

The following works for me. In the field for choices:

Code: Select all

Październik/|ITEM1
-
Kwiecień/|ITEM2
Sierpień/|ITEM3
Pokaż/|ITEM4
code of the pull down menu button

Code: Select all

on menuPick pItemName
   switch pItemName
      case "ITEM1"
         answer "item1"
         break
      case "ITEM2"
         answer "item2"
         break
              
      case "ITEM3"
         answer "item3"
         break
      case "ITEM4"
         answer "Item4"
         break
      default 
         answer "default" 
      end switch
end menuPick
Kind regards
Bernd
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Pull Down Menu button error?

Post by bn »

Marek,

this "answers" the menu items as displayed, even with unicode
same choices as before

Code: Select all

on menuPick pItemName
   set the itemDelimiter to "/"
   set the unicodeText of the templateField to the unicodeText of me
   switch pItemName
      case "ITEM1"
         answer item 1 of line 1 the htmltext of the templateField
         break
      case "ITEM2"
         answer item 1 of line 3 the htmltext of the templateField
         break
      case "ITEM3"
         answer item 1 of line 4 of the htmlText of the templateField
         break
      case "ITEM4"
         answer item 1 of line 5 of the htmlText of the templateField
         break
      default 
         answer "default" 
      end switch
   reset the templateField
end menuPick
Kind regards
Bernd
snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Pull Down Menu button error?

Post by snm »

Bernd,

Both buttons in attached sample stack "Show" (btn "M1") and "Pokaż" (btn "M2") have the same script and the same menu text:
"Choice 1"
"Choice 2"
"Choice 3"

There is no accented letters in menu items to choose.

The only dirrerence is in their labels - btn "M2" has accented character "ż", which breaks menuPick handler, even if there is not used any label information there. If I remove accented character from the label of btn "M2" it starts to work as expected.

I can choose the item from menu with using tags (like
"Choose 1|item1") and it works if the content of menu is unicode, but the label must not be unicode.

The problem is to have the label of menu button with accented characters. In such case the handler "on menuPick pItemName" doesnt work correct. Whatever you choose from btn "M2" (with the label "Pokaż") the answer is "default".

The only possible roundaround is to use the menuHistory in switch of "on menuPick" handler in place of pItemName. You can check it with btn "M3" (with the label "Pokaż w/h menuHistory).

Marek
Attachments
UnicodeBug.livecode.zip
Sample stack
(1.73 KiB) Downloaded 345 times
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Pull Down Menu button error?

Post by Klaus »

Hi Marek,

this is definitively a BUG!

If I add a "put pItemName" ad the top of your script I get indeed the correct menuitem in the messagebox!?
But the following "switch pItemName" does NOT work? Too funky 8)


Best

Klaus
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Pull Down Menu button error?

Post by bn »

Marek,

I finally get what you describe, I was confused because in a option menu the label = the choice, anyway Klaus gave me an idea because pItemName looked ok but if you try to set a cursor after it in the message box the cursor won't move with arrowKeys.

This works

Code: Select all

on menuPick pItemName
   set the unicodeText of the templateField to pItemName
   put the text of the templateField into pItemName
   
   switch pItemName
      case "Choice 1" 
         answer "Choice 1"
         break
      case "Choice 2"
         answer "Choice 2"
         break
      case "Choice 3"
         answer "Choice 3"
         break
      default
         answer "default, not Choice n"
   end switch
end menuPick
There is a stray character from unicode or something lurking somewhere :) How is that for an explanation.
And please do report this as a bug and also mention the workaround with the templateField.

I hope all this will be nice memories from the past once Livecode uses unicode throughout

(forgot to add a 'reset the templateField' at the end. Probably would be a nice gesture.)

Kind regards
Bernd
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Pull Down Menu button error?

Post by Klaus »

Oh yeah, never would have thought of THAT! 8)
snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Pull Down Menu button error?

Post by snm »

Hi Bernd, Jacque and Klaus,

Thank all of you for help. I reported the bug 11605 (with all the solutions of workaround).

@ Bernd
It's foxy solution with the templateField - I should get this idea asap I saw that enter into the field with value of pItemName of debugger after breakpoint in "on menuPick" handler, apply edit and run the rest of script (without editing it) worked as expected. :oops:
Anyway I wonder how can such behaviour be caused by unicode text in button's label as script doesn't use it at all.

Marek
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Pull Down Menu button error?

Post by bn »

Marek,

here is a version of the menuPick handler that works for ASCII and Unicode Labels. But probably only as long as the bug is not fixed.

It is probably a good idea to mark all pull-down menus you modify to change them once the bug is fixed. (also the ones with the short work around)
By the way I higly recommend lcTaskList by Bill Vlahos $10 in the Livecode store for this kind of marking. You see all the marks , which you can also custom define, in all script at a glance. (disclaimer: no financial interest in lcTaskList)

Code: Select all

on menuPick pItemName

   -- -- if you want to see what is in pItemName
   --   put "" into msg
   --   repeat for each char aChar in pItemName
   --      put charToNum(aChar) & "-"  after msg
   --   end repeat
   
   if "unicodeLabel" is among the keys of the properties of me then
      set the unicodeText of the templateField to pItemName
      put the text of the templateField into pItemName
      reset the templateField
   end if
   
   switch pItemName
      case "Choice 1" 
         answer "Choice 1"
         break
      case "Choice 2"
         answer "Choice 2"
         break
      case "Choice 3"
         answer "Choice 3"
         break
      default
         answer "default, not Choice n"
   end switch
end menuPick
if you put pItemName for "Choice 1" in its unicode glory you see

Code: Select all

67-0-104-0-111-0-105-0-99-0-101-0-32-0-49-0-
As to why it is so: maybe an attempt to use unicode throughout once a unicode label is defined????

I think I stop now fooling around with unicode in Livecode, it is not good for my mental health. I admire you, Marek, and all the others that use Livecode in a non-ASCII language.

Kind regards
Bernd
snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Pull Down Menu button error?

Post by snm »

It's beyond belief!

Using Jacque's solution with the "/|" trick if there is no unicode in the list but the label of button is unicode - it works only with Bernd's "templateField" solution.

But if there is unicode label of button and also even one unicode item in pull down list - it works as expected with raw script code:
- button label: "Pokaż"
- menu list:

Code: Select all

Październik/|ITEM1
-
Kwiecień/|ITEM2
Sierpień/|ITEM3
- button script:

Code: Select all

on menuPick pItemName
   switch pItemName
      case "ITEM1"
         answer "ITEM1"
         break
      case "ITEM2"
         answer "ITEM2"
         break
      case "ITEM3"
         answer "ITEM3"
         break
      default
         answer "default" 
   end switch
end menuPick
And it works!
It's more and more difficult to understand it.

Marek
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Pull Down Menu button error?

Post by bn »

Marek,

I can not reproduce, maybe I do it wrong. Could you post a minimal stack with the different options which work and don't work? Each as a pull-Down menu.

It gets confusing.

Kind regards
Bernd
snm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 253
Joined: Fri Dec 09, 2011 11:17 am

Re: Pull Down Menu button error?

Post by snm »

Hi Bernd,

Updated stack attached. Please read EDIT2 in text fld.
There are two identical buttons M2 and M5 labeled as "Pokaż" and Pokaż2". The only difference is the content of pull down menu as below.
- "Pokaż":

Code: Select all

Choice 1
Choice 2
Choice 3
- "Pokaż2":

Code: Select all

wrzesień/|Choice 1
sierpień/|Choice 2
luty/|Choice 3
The both button scripts are the same. "Pokaż2" is working without problem.

Have fun,
Marek
Attachments
UnicodeBug2.livecode.zip
Second version
(2.25 KiB) Downloaded 348 times
Post Reply