# Dynamic Task Bar Menu Items

**URL:** <https://www.ruby-forum.com/t/dynamic-task-bar-menu-items/123480>\
**Category:** wxRuby\
**Created:** [December 18, 2007, 4:47am UTC](https://www.ruby-forum.com/t/dynamic-task-bar-menu-items/123480 "2007-12-18T04:47:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![EchoB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@EchoB](https://www.ruby-forum.com/u/EchoB)\
**Post date:** [December 18, 2007, 4:47am UTC](https://www.ruby-forum.com/t/dynamic-task-bar-menu-items/123480/1 "2007-12-18T04:47:51Z")

</div>

# Am looking for a way to dynamically add menu items to a task bar icon menu. And then once selected - I would like to get the title of the menu item. The general idea is to read a text file: Project1 Project2 Project3

Add those to the task bar menu, and when i select (for example)  
Project2, I want to pass the string “Project2” to the code.

Also - Am wondering about how to get the menu to respond to the left  
mouse button click - as opposed to the right one by default.

---

<div class="post-metadata">

**Author:** ![EchoB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@EchoB](https://www.ruby-forum.com/u/EchoB)\
**Post date:** [December 18, 2007, 10:26am UTC](https://www.ruby-forum.com/t/dynamic-task-bar-menu-items/123480/2 "2007-12-18T10:26:02Z")

</div>

Hi

Firstly, take a look at the sample “bigdemo/bigdemo.rb” and look for the  
class DemoTaskBarIcon. I think it demonstrates most of what you want to  
do.

EchoB wrote:

> Am looking for a way to dynamically add menu items to a task bar icon  
> menu.  
> Define a method “create\_popup\_menu” in your TaskBarIcon subclass. This  
> will be called on each occasion that the menu is shown, so simply create  
> the menu with the appropriate items at any given time.  
> And then once selected - I would like to get the title of the menu  
> item.  
> Use evt\_menu to get the menu item selected, then use Wx::Menu#get\_label  
> to get the text string for that item. Imagine that in create\_popup\_menu  
> you store the menu as an instance variable @menu, you could do the  
> following in your TaskBarIcon initialize method to capture all menu  
> events and show the text label.

evt\_menu(Wx::ID\_ANY) do | event |  
puts @menu.label(event.id)  
end

> Also - Am wondering about how to get the menu to respond to the left  
> mouse button click - as opposed to the right one by default.  
> use evt\_taskbar\_left\_down or evt\_taskbar\_left\_up. Take a look at the  
> TaskBarIcon and Menu documentation - I think this should all be covered,  
> but please get in touch if anything’s not clear.

[http://wxruby.rubyforge.org/doc/taskbaricon.html](http://wxruby.rubyforge.org/doc/taskbaricon.html)  
[http://wxruby.rubyforge.org/doc/menu.html](http://wxruby.rubyforge.org/doc/menu.html)

cheers  
alex
