Class: GtkApp::View
- Inherits:
-
Gtk::Builder
- Object
- Gtk::Builder
- GtkApp::View
- Includes:
- Helpers, ViewHelpers
- Defined in:
- lib/gtk_app/view.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(controller, builder_file, *args) ⇒ View
constructor
A new instance of View.
- #method_missing(id, *args, &block) ⇒ Object
Methods included from ViewHelpers
#build_listview, #desensitize, #sensitize
Methods included from Helpers
Constructor Details
#initialize(controller, builder_file, *args) ⇒ View
Returns a new instance of View.
8 9 10 11 12 13 14 15 |
# File 'lib/gtk_app/view.rb', line 8 def initialize(controller, builder_file, *args) super() # options = args.extract_options! self.add_from_file(builder_file) self.connect_signals { |handler| controller.method(handler) } # self.title = options[:title] if options.key?(:title) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &block) ⇒ Object
17 18 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gtk_app/view.rb', line 17 def method_missing(id, *args, &block) method_name = id.to_s = (method_name =~ /([!=]|<{2})$/ ? method_name.chop : method_name) = self["#{}"] super unless bang_proc, equal_proc, append_proc = case when Gtk::TextView then [ lambda { .buffer.text }, lambda { |*argv| .buffer.text = argv[0].to_s }, lambda { |text| .buffer.text << text.to_s } ] when Gtk::ComboBox then [ lambda { .active_text }, lambda do |*argv| if argv[0].is_a?(Fixnum) .active = argv[0] elsif .model result = nil .model.each do |m, p, i| result = iter if iter[0] =~ /\A#{argv[0]}/i end .active_iter = result if result end end, lambda { |text| .append_text(text.to_s) } ] when Gtk::ToggleButton, Gtk::CheckButton then [ lambda { .active? }, lambda { |*argv| .active = argv[0] }, nil ] when Gtk::TreeView then [ lambda { .selection.selected }, nil, lambda do |row| iter = .model.append if row.is_a?(Gtk::TreeIter) (0..model.n_columns).each { |i| iter[i] = row[i] } else row.each_with_index { |v,i| iter[i] = v } end iter end ] else if .respond_to?(:text) [ lambda { .text }, lambda { |*argv| .text = argv[0].to_s }, lambda { |text| .text = ("#{.text}" << text) } ] else [nil, nil, nil]; end end class_eval do define_method(:"#{}", lambda { }) define_method(:"#{}!", bang_proc) if bang_proc define_method(:"#{}=", equal_proc) if equal_proc end .class_eval do define_method("<<", append_proc) end if append_proc send(:"#{method_name}", *args, &block) end |