Class: ActiveWindow::Application
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/active_window/application.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#database ⇒ Object
Returns the value of attribute database.
-
#glade ⇒ Object
Returns the value of attribute glade.
-
#window ⇒ Object
Returns the value of attribute window.
Instance Method Summary collapse
- #default_database ⇒ Object
-
#dispatch(handler, event) ⇒ Object
dispatch a signal to the correct controller.
-
#initialize(options = {}) ⇒ Application
constructor
A new instance of Application.
-
#post_setup ⇒ Object
calls post_setup on each controller.
- #save_default_database(hash) ⇒ Object
-
#setup ⇒ Object
creates the controllers, connects the signals calls ‘setup’ on each controller.
- #start ⇒ Object
- #widget(name) ⇒ Object
Constructor Details
permalink #initialize(options = {}) ⇒ Application
Returns a new instance of Application.
11 12 13 14 15 16 17 18 19 |
# File 'lib/active_window/application.rb', line 11 def initialize( = {}) @glade = GladeXML.new(find_glade, nil, [:title] || 'application' ) @window = ([:main_window] || 'main_window') @window.signal_connect("destroy") { Gtk.main_quit } @dot_file_prefs = DotFile.read @database = [:database] run_callbacks :after_initialize end |
Instance Attribute Details
permalink #controller ⇒ Object
Returns the value of attribute controller.
5 6 7 |
# File 'lib/active_window/application.rb', line 5 def controller @controller end |
permalink #database ⇒ Object
Returns the value of attribute database.
5 6 7 |
# File 'lib/active_window/application.rb', line 5 def database @database end |
Instance Method Details
permalink #default_database ⇒ Object
[View source]
28 29 30 |
# File 'lib/active_window/application.rb', line 28 def default_database @dot_file_prefs[:db] end |
permalink #dispatch(handler, event) ⇒ Object
dispatch a signal to the correct controller
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/active_window/application.rb', line 73 def dispatch(handler, event) controller_name,action = handler.to_s.split('.') unless controller_name and action return(error "cannot parse handler '%s'" % handler) end name = controller_name.to_sym ctrl = controller[name] unless ctrl puts controller.inspect return(error "no controller '%s' defined" % controller_name.camelize) end unless ctrl.respond_to? action return(error "controller '%s' does not have a method '%s'" % [ctrl.class, action]) end method = ctrl.method(action) #puts "calling %s.%s" % [controller_name.camelize, action] if method.arity == 0 method.call else method.call(event) end end |
permalink #post_setup ⇒ Object
calls post_setup on each controller
64 65 66 67 68 |
# File 'lib/active_window/application.rb', line 64 def post_setup controller.each do |name,ctrl| ctrl.post_setup end end |
permalink #save_default_database(hash) ⇒ Object
[View source]
32 33 34 35 |
# File 'lib/active_window/application.rb', line 32 def save_default_database(hash) @dot_file_prefs[:db] = hash @dot_file_prefs.save end |
permalink #setup ⇒ Object
creates the controllers, connects the signals calls ‘setup’ on each controller
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_window/application.rb', line 39 def setup @controller = {} Module.constants.grep(/.Controller$/).each do |klass| ctrl = Kernel.const_get(klass).instance ctrl.application = self ctrl.setup name = klass.to_s.sub('Controller','').underscore.to_sym # eg MyFirstController -> :my_first controller[name] = ctrl end glade.signal_autoconnect_full do |source, target, signal, handler, data| # for example: # source : instance of Gtk::ImageMenuItem # target : nil # signal : activate, clicked, pressed, etc. # handler : window.close, which would call WindowController.close() # data : nil #puts [source, target, signal, handler, data].inspect source.signal_connect(signal) { |,event| self.dispatch(handler, :source => source, :target => target, :signal => signal, :handler => handler, :data => data, :widget => , :event => event) } #source.signal_connect(signal) { self.(handler, data) } end end |
permalink #start ⇒ Object
[View source]
21 22 23 24 25 26 |
# File 'lib/active_window/application.rb', line 21 def start setup post_setup window.show Gtk.main end |
permalink #widget(name) ⇒ Object
[View source]
7 8 9 |
# File 'lib/active_window/application.rb', line 7 def (name) glade[name] end |