Author Topic: Ti-Nspire: Changing menu items dynamically?  (Read 3953 times)

0 Members and 1 Guest are viewing this topic.

Offline Goran

  • LV2 Member (Next: 40)
  • **
  • Posts: 32
  • Rating: +0/-0
    • View Profile
Ti-Nspire: Changing menu items dynamically?
« on: July 22, 2013, 08:40:07 am »
Hello,

Firstly, sorry if this question has been answered already (link please).

I want to change the menu content during lua script execution.
I found in "Lua Scripting API Reference Guide" the following sentence:

"Beginning with platform.apiLevel = '2.0', the names of the tool palette items
can be changed dynamically while the program is running."

but I am missing an example.

Any help would be appreciated.

Thanks,
Goran

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Ti-Nspire: Changing menu items dynamically?
« Reply #1 on: July 22, 2013, 10:06:18 am »
Just re-register the menu.

For example:
Code: [Select]
function swap()
    menu[1], menu[2] = menu[2], menu[1]
    toolpalette.register(menu)
end

menu = {
 
    {"Analysis",                 
       {"Decimal", print},         
       {"Hexadecimal", print},
       {"Octal", print},
       {"Binary", print},
       {"Signed", print},
       {"Unsigned", print},
    },
    {"Boolean",
       {"And", print},
       {"Or", print},
       {"XOr", print},
       {"Not", print},
    },
    {"Toggle",
       {"Swap menu", swap}     
    }
 
}

function on.construction()
    toolpalette.register(menu)
end

When clicking on swap, the first two menus will always be swapped. Silly example, but it shows that you dynamically can change the menu items.
« Last Edit: July 22, 2013, 10:08:45 am by Jim Bauwens »

Offline Goran

  • LV2 Member (Next: 40)
  • **
  • Posts: 32
  • Rating: +0/-0
    • View Profile
Re: Ti-Nspire: Changing menu items dynamically?
« Reply #2 on: July 22, 2013, 01:49:21 pm »
Thanks Jim,

great, that helped!

I have few other questions (different TI-Nspire/Lua topics), but I'll rather open new topics, I think it's better for the community.

Best regards,
Goran

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Ti-Nspire: Changing menu items dynamically?
« Reply #3 on: July 22, 2013, 03:20:04 pm »
Glad I could help you :)
Also, it would be indeed better to open new topics or you could also post in the Lua Q&A thread if it are small questions.