Module: GtkApp::ViewHelpers
- Included in:
- View
- Defined in:
- lib/gtk_app/view_helpers.rb
Instance Method Summary collapse
-
#build_listview(widget_name, columns, options = {}) {|iter, header, column, renderer| ... } ⇒ Object
Simple way to setup a listview.
-
#desensitize(*widgets) ⇒ Object
Set widget(s) sensitivity property to false.
-
#sensitize(*widgets) ⇒ Object
Set widget(s) sensitivity property to true.
Instance Method Details
#build_listview(widget_name, columns, options = {}) {|iter, header, column, renderer| ... } ⇒ Object
Simple way to setup a listview.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gtk_app/view_helpers.rb', line 19 def build_listview(, columns, ={}, &block) list = self.send(:"#{}") list.model = Gtk::ListStore.new(*columns.values) columns.each_with_index do |keyval, index| header, data_type = keyval renderer, attrs = case "#{data_type}".to_sym when :String, :Integer [Gtk::CellRendererText.new, text: index] when :TrueClass toggle = Gtk::CellRendererToggle.new toggle.signal_connect('toggled') do |, path| iter = list.model.get_iter(path) iter[index] = !iter[index] end [toggle, active: index] when :'Gtk::ListStore' _renderer = Gtk::CellRendererCombo.new model = Gtk::ListStore.new(String) _renderer.signal_connect("edited") do |cell, path, text| model.get_iter(path)[index] = text end [_renderer, text_column: 0, model: model, text: index, editable: index] else raise("GtkApp::View##{__method__} does not know how to handle " + "'#{data_type}' data types.") end column = Gtk::TreeViewColumn.new("#{header}".titleize, renderer, attrs) column.visible = false if index == 0 yield(index, header, column, renderer) if block_given? if .key?(:formatter) && [:formatter].is_a?(Proc) column.set_cell_data_func(renderer, &[:formatter]) end list.append_column(column) end end |
#desensitize(: lblFoo, : lblBar) ⇒ Object #desensitize(: cmbBar) ⇒ Object
Set widget(s) sensitivity property to false
68 69 70 |
# File 'lib/gtk_app/view_helpers.rb', line 68 def desensitize(*) .each { |w| self["#{w}"].sensitive = false } end |
#sensitize(: lblFoo, : txtFoo) ⇒ Object #sensitize(: cmbBar) ⇒ Object
Set widget(s) sensitivity property to true
61 62 63 |
# File 'lib/gtk_app/view_helpers.rb', line 61 def sensitize(*) .each { |w| self["#{w}"].sensitive = true } end |