# Lazy WxRuby

**URL:** <https://www.ruby-forum.com/t/lazy-wxruby/169734>\
**Category:** wxRuby\
**Created:** [June 8, 2009, 4:16am UTC](https://www.ruby-forum.com/t/lazy-wxruby/169734 "2009-06-08T04:16:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 8, 2009, 4:16am UTC](https://www.ruby-forum.com/t/lazy-wxruby/169734/1 "2009-06-08T04:16:21Z")

</div>

If interested I posted an example of how I lazily build a WxRuby  
interface for an app. Here’s the link via DZone:

[http://www.dzone.com/links/wxruby\_for\_the\_lazy.html](http://www.dzone.com/links/wxruby_for_the_lazy.html)

T.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 8, 2009, 9:47pm UTC](https://www.ruby-forum.com/t/lazy-wxruby/169734/2 "2009-06-08T21:47:03Z")

</div>

Hi Trans,

On Mon, Jun 8, 2009 at 4:14 AM, trans[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If interested I posted an example of how I lazily build a WxRuby  
> interface for an app. Here’s the link via DZone:
> 
> [http://www.dzone.com/links/wxruby\_for\_the\_lazy.html](http://www.dzone.com/links/wxruby_for_the_lazy.html)

Interesting approach.

Just some comments on wxRuby usage or style :  
1/ You don’t need to supply -1 as the ID parameter for a Window (-1 or  
Wx::ID\_ANY is already the default value).  
For a window, the only mandatory parameter is the parent window (the  
first parameter).

=\>  
def notebook  
@notebook ||= (  
notebook = Wx::Notebook.new(frame\_panel)  
frame\_sizer.add(notebook, 1, Wx::GROW)  
notebook  
)  
end

2/ Wx::Bitmap is smart enough to guess the bitmap type based on the  
file extension (OK, it’s not well documented but I’ll fix that).  
Wx::Toolbar has also the add\_item method which support keyword  
arguments (and it’s well documented) :

@search\_start\_tool = toolbar.add\_tool(-1, ‘Start’ ,  
Wx::Bitmap.new(DIR + ‘/images/search.gif’,  
Wx::BITMAP\_TYPE\_GIF), ‘Start’)

=\>

@search\_start\_tool = toolbar.add\_item(Wx::Bitmap.new(DIR +  
‘/images/search.gif’), :label =\> ‘Start’, :short\_help =\> ‘Start’)

Cheers.

Chauk-Mean.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 8, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/lazy-wxruby/169734/3 "2009-06-08T22:30:34Z")

</div>

On Jun 8, 3:20 pm, Chauk-Mean P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Interesting approach.

Thanks. The approach really helped me wrap my head around WxRuby  
better.

> ```
> frame_sizer.add(notebook, 1, Wx::GROW)
> Wx::Bitmap.new(DIR + '/images/search.gif',
> 
> ```
> 
> Wx::BITMAP\_TYPE\_GIF), ‘Start’)
> 
> =\>
> 
> @search\_start\_tool = toolbar.add\_item(Wx::Bitmap.new(DIR +  
> ‘/images/search.gif’), :label =\> ‘Start’, :short\_help =\> ‘Start’)

Nice tips. I’ll apply those.

Thanks for taking at look at this.

T.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 9, 2009, 5:11am UTC](https://www.ruby-forum.com/t/lazy-wxruby/169734/4 "2009-06-09T05:11:58Z")

</div>

On Tue, Jun 9, 2009 at 3:27 AM, trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 1/ You don’t need to supply -1 as the ID parameter for a Window (-1 or  
> > )
> > 
> > =\>
> > 
> > @search\_start\_tool = toolbar.add\_item(Wx::Bitmap.new(DIR +  
> > ‘/images/search.gif’), :label =\> ‘Start’, :short\_help =\> ‘Start’)
> 
> Nice tips. I’ll apply those.
> 
> Thanks for taking at look at this.

Perhaps I’m still too lazy for this 🙂  
But your approaching is cool

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 17, 2009, 1:58pm UTC](https://www.ruby-forum.com/t/lazy-wxruby/169734/5 "2009-06-17T13:58:27Z")

</div>

trans wrote:

> If interested I posted an example of how I lazily build a WxRuby  
> interface for an app. Here’s the link via DZone:
> 
> [http://www.dzone.com/links/wxruby\_for\_the\_lazy.html](http://www.dzone.com/links/wxruby_for_the_lazy.html)

Late to the link, but thanks for posting this. I think the approach is  
interesting and instructive so I added it to the tutorials page on the  
wiki.

Another shortcut you can use:

Wx::VBoxSizer.new

instead of

Wx::BoxSizer.new(Wx::VERTICAL)

alex

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [June 17, 2009, 4:16pm UTC](https://www.ruby-forum.com/t/lazy-wxruby/169734/6 "2009-06-17T16:16:55Z")

</div>

On Jun 17, 7:56 am, Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> trans wrote:
> 
> > If interested I posted an example of how I lazily build a WxRuby  
> > interface for an app. Here’s the link via DZone:
> 
> > [http://www.dzone.com/links/wxruby\_for\_the\_lazy.html](http://www.dzone.com/links/wxruby_for_the_lazy.html)
> 
> Late to the link, but thanks for posting this. I think the approach is  
> interesting and instructive so I added it to the tutorials page on the wiki.

Nice 🙂

> Another shortcut you can use:
> 
> Wx::VBoxSizer.new
> 
> instead of
> 
> Wx::BoxSizer.new(Wx::VERTICAL)

Thanks, I updated the post to use this.

Btw, just for completeness sake, the Controller class should also have  
this method:

def sites ; service.sites ; end

trans
