Forum: wxRuby Creating a ... table/matrix/grid ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aldric G. (Guest)
on 2009-04-05 22:13
(Received via mailing list)
Hey guys. First post, and I have a project which is ambitious (to me
anyway, since this is my first foray ever in GUI).
I want to dynamically create (from 2 arrays for instance) a table with
rows and columns, and each 'cell' would behave like a checkbox, sending
a query to a database tailored after the row/column in which it is (a
very simple query).

I've successfully done the same purpose with nested loops in a text-only
Ruby environment. The same purpose could be obtained from, say, two
drop-down menus selecting the options and pressing a button - but I want
a quick, graphical way of doing it all (maybe check all the boxes then
use a submit button, that'd work too)..

Now that I've explained all that.. I am a complete newbie at wxruby. I
followed the first three or so tutorials but I don't really know where
to go from there. Does anyone have a theoretical explanation of how to
accomplish what I want to do.. And maybe intermediary projects I can
accomplish to get there?

Sorry if I'm rambling a little.. Thanks in advance :)
--Aldric
Alex F. (Guest)
on 2009-04-06 01:11
(Received via mailing list)
Hi Aldric

Aldric G. wrote:
> Hey guys. First post, and I have a project which is ambitious (to me
> anyway, since this is my first foray ever in GUI).
> I want to dynamically create (from 2 arrays for instance) a table with
> rows and columns, and each 'cell' would behave like a checkbox, sending
> a query to a database tailored after the row/column in which it is (a
> very simple query).

Welcome to wxRuby which, happily, has a widget that I think will be very
well suited to your project. It's called Wx::Grid, and the documentation
is here:

http://wxruby.rubyforge.org/doc/grid.html

Note that there is one missing section we recently noticed in this doc,
which describes some of the events generated by grid. Have a look also
at:

http://docs.wxwidgets.org/stable/wx_wxgrid.html

There are two quite comprehensive grid samples that came with your
wxruby installation, in <libdir>/samples/grid/. You could study these as
an intermediary project.

Briefly, on some of the things you want to do:

- to display cells with check-box like appearance, use
Wx::GridCellBoolRenderer and Wx::GridCellBoolEditor classes. If you find
you don't like the default way these work, you can also completely
customise how cells are displayed using your own subclass of
Wx::GridCellRenderer.

- to handle an action when a cell is checked or unchecked, set up an
event handler on evt_grid_cell_change.

- if you already have the code that interacts with the database, an
efficient way to link this to the GUI display can be to use
GridTableBase. I won't go into detail, but have a look at the sample -
if you're used to model/view separation this works nicely.

hth
alex
This topic is locked and can not be replied to.