Class: Freightrain::Toolkit::InterfaceBuilder
- Inherits:
-
Object
- Object
- Freightrain::Toolkit::InterfaceBuilder
- Defined in:
- lib/extensions/qt/interface_builder.rb,
lib/extensions/wx/interface_builder.rb,
lib/extensions/gtk/interface_builder.rb
Instance Attribute Summary collapse
-
#toplevel ⇒ Object
readonly
Returns the value of attribute toplevel.
Instance Method Summary collapse
- #connect_to_callback(widget, event_name, method) ⇒ Object
- #control ⇒ Object
- #create_object_accessors(widgets, view) ⇒ Object
- #create_objects_from_file(file_name) ⇒ Object
- #file_found?(file_name) ⇒ Boolean
- #get_glade_file(file_name) ⇒ Object
- #get_ui_files(file_name) ⇒ Object
- #get_xrc_files(file_name) ⇒ Object
-
#initialize ⇒ InterfaceBuilder
constructor
A new instance of InterfaceBuilder.
- #replace_faulty_containers(xml, abstract_class, hclass, vclass) ⇒ Object
Constructor Details
#initialize ⇒ InterfaceBuilder
Returns a new instance of InterfaceBuilder.
9 10 11 |
# File 'lib/extensions/gtk/interface_builder.rb', line 9 def initialize @builder = Gtk::Builder.new end |
Instance Attribute Details
#toplevel ⇒ Object (readonly)
Returns the value of attribute toplevel.
8 9 10 |
# File 'lib/extensions/qt/interface_builder.rb', line 8 def toplevel @toplevel end |
Instance Method Details
#connect_to_callback(widget, event_name, method) ⇒ Object
33 34 35 36 37 |
# File 'lib/extensions/qt/interface_builder.rb', line 33 def connect_to_callback(, event_name, callback) .connect(SIGNAL(.get_event_signature(event_name))) do |*args| callback.call(*args) end end |
#control ⇒ Object
49 50 51 |
# File 'lib/extensions/qt/interface_builder.rb', line 49 def control return @toplevel end |
#create_object_accessors(widgets, view) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/extensions/qt/interface_builder.rb', line 26 def create_object_accessors(, view) .each do || name = .objectName view.instance_eval "def #{name}; @widgets.select { |w| w.objectName == '#{name}' }.first ;end;" end end |
#create_objects_from_file(file_name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/extensions/qt/interface_builder.rb', line 14 def create_objects_from_file(file_name) file = Qt::File.new(get_ui_files(file_name)) file.open(Qt::File::ReadOnly) builder = Qt::UiLoader.new @toplevel = builder.load(file) builder.dispose file.close return get_all_objects(@toplevel).select do || .objectName && .objectName != "" end end |
#file_found?(file_name) ⇒ Boolean
10 11 12 |
# File 'lib/extensions/qt/interface_builder.rb', line 10 def file_found?(file_name) return get_ui_files(file_name) end |
#get_glade_file(file_name) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/extensions/gtk/interface_builder.rb', line 53 def get_glade_file(file_name) search_path = File.join( Freightrain.app_path, "views", "**", file_name.to_convention + ".glade") results = Dir.glob(search_path) return results.first end |
#get_ui_files(file_name) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/extensions/qt/interface_builder.rb', line 39 def get_ui_files(file_name) search_path = File.join( Freightrain.app_path, "views", "**", file_name.to_convention + ".ui") results = Dir.glob(search_path) return results.first end |
#get_xrc_files(file_name) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/extensions/wx/interface_builder.rb', line 14 def get_xrc_files(file_name) search_path = File.join( Freightrain.app_path, "views", "**", file_name.to_convention + ".xrc") results = Dir.glob(search_path) return results.first end |
#replace_faulty_containers(xml, abstract_class, hclass, vclass) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/extensions/gtk/interface_builder.rb', line 63 def replace_faulty_containers(xml, abstract_class, hclass, vclass) document = REXML::Document.new(xml) document.elements.each("//object[@class='#{abstract_class}']") do |box| substitute_class = hclass box.elements.each("property[@name='orientation']") do |orientation| substitute_class = orientation == "vertical" ? vclass : hclass end box.attributes["class"] = substitute_class end return document.to_s end |