Alex,
Nice work! I''ll have to play around with it some to see how it all
feels. Certainly there are a lot better ways we could these things.
Roy
Alex Fenton wrote:> Hi
>
> Do a search on ''wxruby'' and you''ll see that
people''s main gripes are
> 1) stability 2) development progress 3) documentation and 4) syntax.
>
> We''re making great progress on 1-3 so thought it seemed like a
good
> time to start looking at 4). So here''s announcing a first release
of
> WxSugar. It can be downloaded via gems (gem install wx_sugar) or from
> http://rubyforge.org/frs/?group_id=665 . If you install the gem it
> will automatically build docs for you.
>
> This package is a set of pure ruby extensions to wxRuby that are meant
> to make the syntax:
>
> - more expressive
> - more ''rubyish'' and less C++ish
> - shorter
>
> The main idea is to get a discussion going about how we want to
> develop the wxRuby syntax. The extensions are designed to be modular
> (you can use one and not the other) and to complement rather than
> replace the existing syntax (so you can run existing wxRuby code with
> them).
>
> You can require ''wx_sugar/all'' to load all the
behaviours, or select
> particular ones including
>
> * ''accessors'' : creates ruby-style accessors (foo instead
of get_foo,
> foo= instead of set_foo, foo? instead of is_foo). If there''s a
> consensus that we want to follow WxPython in doing this, I''ll
submit a
> patch that implements this at the C API level.
>
> * ''keyword_constructors'' : For example,
Wx::Button.new(:label =>
> ''press me''); this extension allows you to avoid typing
> Wx::DEFAULT_POSITION or having to remember what order arguments go in
> ever again. You can mix positional and keyword arguments (in case you
> hate the latter, Kevin ;) )
>
> * ''layout'' : simplifies using sizers, and combines
instantiating
> widgets with adding them to sizers (which has to be two steps in
> wxRuby). Especially useful for nested sizers. Still under development
>
> * ''menus'' : never deal with tedious menu ids again. Needs
documenting
> and integrating with core classes.
>
> * ''itemdata'' : simulates itemdata, but using any ruby
object. Not
> fully integrated yet.
>
> This is very much alpha - some of it is stuff that''s ripped from
> applications I''ve written, and not properly generalised yet. But
> hopefully it''s of interest. Please see the attached example of the
> kind of syntax it produces.
>
> Sweet!
> alex
>
> ------------------------------------------------------------------------
>
> require ''wx''
> require ''wx_sugar/all''
>
> class MyButton < Wx::Button
> def on_button()
> p "clicked my button"
> end
> end
>
> class SugaryFrame < Wx::Frame
> def initialize(*args)
> super
> # binds evt_close automatically to self#on_close
> listen(:close)
>
> arrange_vertically(:padding => 5)
> # This panel and contents should expand to fit
> add( Wx::Panel, :proportion => 1 ) do | panel |
> # a text control
> panel.background_colour = Wx::Colour.new(200, 150, 100)
> panel.add( Wx::TextCtrl[ :value => ''initial
value'',
> :style => Wx::TE_MULTILINE,
> :size => [200, 300] ] )
> end
>
> # use a nested grid sizer to arrange bottom area
> arrange_grid( :cols => 2, :rows => 2, :proportion => 0,
> :vgap => 2, :minsize => true, :padding => 1 ) do
> # a custom button subclass
> add( MyButton[ :label => ''baz'' ], :proportion
=> 1 ) do | button |
> listen(:button, button, :on_baz_button)
> end
>
> # a drop down
> choices = %w[ nasty nice ]
> add( Wx::Choice[ :choices => choices ], :padding => 4)
>
> # another button
> add( Wx::Button[ :label => ''foo'' ] ) do | button
|
> # handle using a method
> listen(:button, button, :on_foo_button)
> # handle using a block
> listen(:button, button) { | e | p "clicked in a block";
e.skip }
> end
> add( Wx::TextCtrl[ :value => ''foo'' ], :align
=> ''right'' )
> end
> end
>
> def on_close(event)
> puts "CLOSING"
> event.skip()
> end
>
> def on_button(event)
> p event
> end
>
> def on_foo_button(e)
> p "FOO"
> e.skip()
> end
>
> # you aren''t required to receive the event
> def on_baz_button()
> p "baZ"
> end
> end
>
> class SugaryApp < Wx::App
> def on_init
> frame = SugaryFrame.new( nil, :title => "Arranger
Application" )
> frame.show()
> end
> end
>
> SugaryApp.new.main_loop()
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> wxruby-users mailing list
> wxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wxruby-users