Class: ActiveWindow::Application
- Inherits:
-
Object
- Object
- ActiveWindow::Application
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/active_window/application.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#database ⇒ Object
Returns the value of attribute database.
-
#window ⇒ Object
Returns the value of attribute window.
Class Method Summary collapse
Instance Method Summary collapse
- #default_database ⇒ Object
-
#dispatch(handler) ⇒ Object
gets a handler like “config.reset_settings” returns the method (reset_settings) of the controller (ConfigController) to use as a callback.
-
#initialize(options = {}) ⇒ Application
constructor
A new instance of Application.
-
#post_setup ⇒ Object
calls post_setup on each controller.
- #run ⇒ Object
- #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
#initialize(options = {}) ⇒ Application
Returns a new instance of Application.
21 22 23 24 25 26 27 28 29 |
# File 'lib/active_window/application.rb', line 21 def initialize( = {}) @builder = Gtk::Builder.new @builder.add_from_file(find_view) @window = ([:main_window] || 'main_window') @window.signal_connect("destroy") { Gtk.main_quit } @dot_file_prefs = ActiveWindow::DotFile.read @database = [:database] run_callbacks :after_initialize end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
6 7 8 |
# File 'lib/active_window/application.rb', line 6 def builder @builder end |
#controller ⇒ Object
Returns the value of attribute controller.
5 6 7 |
# File 'lib/active_window/application.rb', line 5 def controller @controller end |
#database ⇒ Object
Returns the value of attribute database.
5 6 7 |
# File 'lib/active_window/application.rb', line 5 def database @database end |
#window ⇒ Object
Returns the value of attribute window.
5 6 7 |
# File 'lib/active_window/application.rb', line 5 def window @window end |
Class Method Details
.widget(*widgets) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/active_window/application.rb', line 8 def self.(*) .each do || name = .to_s.camelize define_method do builder[name] end end end |
Instance Method Details
#default_database ⇒ Object
41 42 43 |
# File 'lib/active_window/application.rb', line 41 def default_database @dot_file_prefs[:db] end |
#dispatch(handler) ⇒ Object
gets a handler like “config.reset_settings” returns the method (reset_settings) of the controller (ConfigController) to use as a callback
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/active_window/application.rb', line 80 def dispatch(handler) 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) end |
#post_setup ⇒ Object
calls post_setup on each controller
71 72 73 74 75 |
# File 'lib/active_window/application.rb', line 71 def post_setup controller.each do |name,ctrl| ctrl.post_setup end end |
#run ⇒ Object
37 38 39 |
# File 'lib/active_window/application.rb', line 37 def run Gtk.main end |
#save_default_database(hash) ⇒ Object
45 46 47 48 |
# File 'lib/active_window/application.rb', line 45 def save_default_database(hash) @dot_file_prefs[:db] = hash @dot_file_prefs.save end |
#setup ⇒ Object
creates the controllers, connects the signals calls ‘setup’ on each controller
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/active_window/application.rb', line 52 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 builder.connect_signals do |handler_name| dispatch(handler_name) end post_setup end |
#start ⇒ Object
31 32 33 34 35 |
# File 'lib/active_window/application.rb', line 31 def start setup window.show run end |
#widget(name) ⇒ Object
17 18 19 |
# File 'lib/active_window/application.rb', line 17 def (name) builder[name] end |