Changes between Version 4 and Version 5 of GtkSimpleWidgets

11/02/11 20:52:26 (6 years ago)

added combo and radio buttons to GtkSimpleWidgets


  • GtkSimpleWidgets

    v4 v5  
    110110== Radio Buttons == 
     112Radio buttons present a set of choices to the user; only one choice can be selected at any time.   
     114There are two things to think about when using radio buttons: 
     116 1. putting the radio buttons into a group, so as one is selected the others become unselected. 
     117 1. retrieving the selected value. 
     119A straightforward way to retrieve the selected value is to listen for the 'toggle' events on each radio button.  When a radio button is toggled, it is selected, and a method can be called to store the relevant value.  Placing radio buttons into the same group is done by passing the first radio button as an argument to the constructor for the second and subsequent radio buttons. 
     123        var _state as String # stores the current selected item in the list of radio buttons  
     125        def selected1(obj, e) # update state as first radio button has been selected 
     126                _state = "Cobra" 
     128        def createWidgets 
     129                # ... create first radio button 
     130                radio1 = RadioButton("Cobra") 
     131                listen radio1.toggled, ref .selected1 
     132                # the second radio button uses the first, to put them in the same group 
     133                radio2 = RadioButton(radio1, "Java") 
     134                listen radio2.toggled, ref .selected2 
    113141== Combo Boxes == 
     143The combo box allows the user to select from a predefined list of items.  The current selection is always shown to the user.  Different variations of the combo box exist, such as allowing the user to enter some text to make a selection.  Combo boxes can display different kinds of information. Before display, a 'cell renderer' must be created to control how the items in the list are displayed.  And the list of items must be added to a suitable data store. 
     145The example here simply displays a list of strings. The renderer is an instance of '!CellRendererText', and the store is a simple '!ListStore'.  The currently selected item ''index'' can be found as {{{}}}  
     152                _combobox = ComboBox() 
     153                _combobox.clear 
     154                # create and add the text renderer to the combox box 
     155                cell = CellRendererText() 
     156                _combobox.packStart(cell, false) 
     157                _combobox.addAttribute(cell, "text", 0) 
     158                # create and set the backing store of items to display 
     159                store = ListStore(String) 
     160                _combobox.model = store 
     161                # add string values to list store 
     162                for planet in ["Mercury", "Venus", "Earth", "Mars",      _ 
     163                               "Jupiter", "Saturn", "Uranus", "Neptune"] 
     164                        store.appendValues(planet) 
     165                # set the index of the item to display 
     166       = 5  
    116169== Spin Buttons ==