[fxruby-users] setCurrent switcher index out of bounds problem

Meinrad Recheis meinrad.recheis at gmail.com
Tue Jun 6 05:15:40 EDT 2006


On 6/6/06, Axel Etzold <AEtzold at gmx.de> wrote:
>
> I'm trying to develop a GUI that combines features of
> the foursplit.rb and shutter.rb examples.
> So there is a bar of ShutterButtons to the left,
> and a set of four FX4Splitter elements to the right
> of the screen.
> Thanks to expert help from Lyle, it's now possible to
> 'expand' any of these elements to full size of the
> right pane.
> Now, I need to add the possibility to switch between
> different layers of the right pane, just like in the
> shutter.rb application, where you press one of the
> ShutterButtons on the left to have that behaviour.
>
> In my code, I set a variable @shutter.current =0, etc..,
> like this
>
> ...
> big_splitter = FXSplitter.new(self, (LAYOUT_SIDE_TOP|LAYOUT_FILL_X|
>       LAYOUT_FILL_Y|SPLITTER_TRACKING))
> ...
> @shutter = FXShutter.new(big_splitter, nil, 0,
>       FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y,
>       0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
> ...
> @switcher = FXSwitcher.new(big_splitter,
>       FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0)
> splitter = FX4Splitter.new(@switcher,
>       LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y|FOURSPLITTER_TRACKING)
> shutterItem = ShutterItem.new(@shutter, "Files, data, and pictures", nil, LAYOUT_FILL_Y)
>     ShutterButton.new(shutterItem.content, "Expand dirlist", big_folder).connect(SEL_COMMAND){
>      @switcher.current=0
>      splitter.handle(self,FXSEL(SEL_COMMAND, FX4Splitter::ID_EXPAND_TOPLEFT), nil)}
>     ShutterButton.new(shutterItem.content, "Expand cell file editor", pens).connect(SEL_COMMAND){
>      @switcher.current=0
>      splitter.handle(self,FXSEL(SEL_COMMAND, FX4Splitter::ID_EXPAND_BOTTOMLEFT), nil)}
>     ShutterButton.new(shutterItem.content, "Expand tuning curve plot", messypaint).connect(SEL_COMMAND){
>      @switcher.current=1
>      splitter.handle(self,FXSEL(SEL_COMMAND, FX4Splitter::ID_EXPAND_TOPRIGHT), nil)}
>     ShutterButton.new(shutterItem.content, "Expand reconstruction plot", drawing).connect(SEL_COMMAND){
>      @switcher.current=2
>      splitter.handle(self,FXSEL(SEL_COMMAND, FX4Splitter::ID_EXPAND_BOTTOMRIGHT), nil)}
>     ShutterButton.new(shutterItem.content, "Show all four", monitor).connect(SEL_COMMAND){
>      @switcher.current=3
>      splitter.handle(self,FXSEL(SEL_COMMAND, FX4Splitter::ID_EXPAND_ALL), nil)}
>
> Then, I get the error below.
> What is the problem here ?
>
> Thank you very much in advance,
>
> Axel
>
>
> Error message:
>
> c:/ruby/lib/ruby/gems/1.8/gems/fxruby-1.4.6-mswin32/lib/fox14/aliases.rb:4067:in `setCurrent': switcher item index out of bounds (IndexError)
>         from c:/ruby/lib/ruby/gems/1.8/gems/fxruby-1.4.6-mswin32/lib/fox14/aliases.rb:4067:in `current='
>         from c:/axelhome/ngui/f17.rb:170:in `initialize'
>         from c:/ruby/lib/ruby/gems/1.8/gems/fxruby-1.4.6-mswin32/lib/fox14/responder2.rb:57:in `onHandleMsg'
>         from c:/axelhome/ngui/f17.rb:610:in `runme'
>         from c:/axelhome/ngui/f17.rb:619
>

it's normal to get some errors when writing a program. but a
programmer must know how to deal with them. i give you some help so
that you can help yourself in future:

have a look at the error msg: it tells you exactly where in your
source code the error happened. then add some lines that output the
values to see what's going on.

in your case you set the current item of the switcher to an index that
does not exist. so just output the index with puts to see what is the
error in your program.

try that first. if you have more questions i will answer them.
hope that helps,
-- henon


More information about the fxruby-users mailing list