Help understanding EVERYTHING


#1

Team,

I am trying to learn a GUI for Ruby and I picked wxRuby.
The problem is that I am kind of slow learning this and I now feel
frustrated after trying for about at least 7 hours.
I am trying to design a simple Sudoku 9x9 grid to display numbers, 1 -
9,
using buttons.
I posted a question on Ruby forum ruby-talk and a gentleman, Alex
Fenton,
answered my questions.
Alex gave me what appear to be great hints. However, as I said earlier,
I am
kind of slow and learn by example.
I tried reading the bigdemo that comes with wxruby and looked on RDOC
and
google, but can’t find any help.
Alex suggested to use this forum to get help.

I don’t want you to provide me with a solution but I need some solid
hints,
if you have the time and will not mind helping me.

I am including a code that I am using to play and learn wxruby. Please
take
a look at it and see if you can tell me why I can’t display all the
buttons
a defined. Only the first button, 1, is displayed.
Once I get those working I will be able to add the rest. The total for a
“normal” Sudoku puzzle is 81 for the 9x9 grid.

Thank you very much for your help.

PS: Is there a wxruby book that I can purchase?


#2

Your message does not have any code attached. Might want to repost
with the attachment.

Sean


#3

Your problem was adding a sizer to the panel and then adding the
GridSizer to that sizer.

I automated your button generation for kicks.

Try this

Sean

begin
require ‘rubygems’
rescue LoadError
end

require ‘wx’
include Wx

class MyFrame < Frame
def initialize()
# One can use the following, commented version or the next 2
#Frame.new(nil, -1, “Sudoku Puzzle”).show()
super(nil, -1, ‘Sudoku Puzzle’, Point.new(220,100),
Size.new(600,480))
@mp = Panel.new(self)

# GridSizer.new(Integer rows,  Integer cols,  Integer vgap, Integer 

hgap)
gs = GridSizer.new(9, 9, 2, 2) # My goal is to define a sudoku grid
9x9

@buttons = Array.new(9)
@buttons.each_index do |i|
  @buttons[i] = Array.new(9)
end

id = 0
(0..8).to_a.each do |x|
  (0..8).to_a.each do |y|
    b = Button.new(@mp,id,:label=>id.to_s)
    @buttons[x][y] = b
    gs.add(b)
    evt_button(id) {|event| button_click(event)}
    id += 1
  end
end

main_sizer = Wx::BoxSizer.new(Wx::VERTICAL)
main_sizer.add(gs,1,Wx::ALL|Wx::GROW,5)
@mp.set_sizer(main_sizer)

show()

end # initialize

def button_click(event)
# code here
end

end # MyFrame Class

class MyApp3 < App
def on_init
MyFrame.new
end # on_init
end # MyApp3

MyApp3.new.main_loop


#4

On Thu, Jan 29, 2009 at 3:32 PM, Sean L. removed_email_address@domain.invalid
wrote:

The problem is that I am kind of slow learning this and I now feel
Alex suggested to use this forum to get help.
Once I get those working I will be able to add the rest. The total for a
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/wxruby-users


wxruby-users mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/wxruby-users

Sorry about that. Here it is:

begin
require ‘rubygems’
rescue LoadError
end

require ‘wx’
include Wx

class MyFrame < Frame
def initialize()
# One can use the following, commented version or the next 2
#Frame.new(nil, -1, “Sudoku Puzzle”).show()
super(nil, -1, ‘Sudoku Puzzle’, Point.new(220,100),
Size.new(600,480))
@mp = Panel.new(self)

# GridSizer.new(Integer rows,  Integer cols,  Integer vgap, Integer

hgap)
gs = GridSizer.new(9, 9, 2, 2) # My goal is to define a sudoku grid
9x9

=begin
Button.new(Window parent, Integer id, String label = ‘’,
Point pos = DEFAULT_POSITION,
Size size = DEFAULT_SIZE,
Integer style = 0,
Validator validator = DEFAULT_VALIDATOR,
String name = “button”)
=end

@b1 = Button.new(@mp, 1, :label=> ‘1’)
gs.add(@b1)
evt_button(@b1.get_id()) { |event| button_click(event)}

@b2 = Button.new(@mp, 2, :label=>‘2’)
gs.add(@b2)
evt_button(@b2.get_id()) { |event| button_click(event)}

@b3 = Button.new(@mp, 3, :label=> ‘3’)
gs.add(@b3)
evt_button(@b3.get_id()) { |event| button_click(event)}

@b4 = Button.new(@mp, 4, :label=>‘4’)
gs.add(@b4)
evt_button(@b4.get_id()) { |event| button_click(event)}

Etc, Etc …until placing button located on cell [9][9]
show()

end # initialize

  def button_click(event)
  # code here
  end

end # MyFrame Class

class MyApp3 < App
def on_init
MyFrame.new
end # on_init
end # MyApp3

MyApp3.new.main_loop


#5

On Fri, Jan 30, 2009 at 4:36 PM, Sean L. removed_email_address@domain.invalid
wrote:

require ‘rubygems’
super(nil, -1, ‘Sudoku Puzzle’, Point.new(220,100), Size.new(600,480))

MyApp3.new.main_loop

The problem is that I am kind of slow learning this and I now feel
kind of slow and learn by example.
take

http://rubyforge.org/mailman/listinfo/wxruby-users

gs = GridSizer.new(9, 9, 2, 2) # My goal is to define a sudoku grid

gs.add(@b1)
@b4 = Button.new(@mp, 4, :label=>‘4’)
end
MyApp3.new.main_loop
wxruby-users mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/wxruby-users

Sean,
Thank you for your help. Perhaps one day I’ll be able to help someone
else.