I am new to visualruby. I am looking for a way to display and alter the contents of a Hash. I have code that uses VRuby from ruby 1.8.7 that would take a hash and dynamically display a dialog with drop-downs, tree-lists, edit boxes, check boxes, buttons, etc. depending of the type of the hash key,value entry. I have been experimenting with VR::ListView, but is seems that I can only have one display type per column. Is there perhaps a way to dynamically add items(widgets?) to a Glade form? For example how could I display and gather values from a window similar to this post form?
on 2013-12-06 19:12
on 2013-12-06 20:11
Hi: One way to add widgets to a glade form is to place empty vbox and hbox widgets to your form using the glade interface designer, then fill them in later with your code. For example, add a vbox to your form with 1 empty row. You can keep the name "vbox1". Later, in your code, you can do this: @dropdown = VR::SimpleComboBoxEntry("choice", "choice2") @builder["vbox1"].add(@dropdown) Then the vbox1 widget will be filled with the dropdown entry widget. Currently, the way you'd update your hash is by putting a submit button on the form, and making a method to handle the click event. You make the method name with the naming convention with two underscores. If you had a submit button called "submitButton" the method would be: def submitButton__clicked(*args) @hash["name"] = @builder["nameWidget"] etc.. end If you wanted to dynamically change each field when the widget changed value, It would be something like this: def nameWidget__changed(*args) @hash["name"] = @builder["nameWidget"] end Does this help? Eric
on 2013-12-06 20:51
Thanks for the reply. I would like to be able to build the form with a variable number of entries. The first example (adapted from one of the samples) was a ListView with rows for each hash entry. When I click on the value column of each row the appropriate widget is displayed (editbox, dropdown, etc.) where I can alter the value. This works, but I would like to find a way to do it all (or at least most of it) on one form. I think that I understand using vbox1 and adding a widget to it. I think that it is directly covered in one of the examples. Can I add vbox's to an existing glade form at run time? Or can I add multiple widgets via @builder["vbox1"].add(@xxx) @builder["vbox1"].add(@yyy)? Or can I have a max number of vbox place holders in the form and hide them if I don't need them? Assuming they would take no space in the form if they aren't used. Thanks for the help!
on 2013-12-06 23:24
Hi Hans: I beleive that you can do all the things that you described in your last post. Gtk is made so you can add widgets to containers (see pack_start etc.) However, this is a Gtk issue not a visualruby issue. Remember that visualruby is just working with Gtk objects in the same way that you do in your code. You will need to get a reference to the gtk object: @contain = @builder["myBox"] @container.add(....) You will need to consult the ruby-gnome docs. My goal is to simplify all of this. I think you're headed in the right direction. I'm trying to map data types directly to widgets, so when you write code, you don't even have to worry about how they are displayed. For example, a string in your code would map to a label or a textbox etc. Eric