To me, the main app (an object) is separate from the app gui (object)... MVC''ish. How can I have the gui part communicate to the app that an event has taken place? Example code somewhere? Thank you. -- - Martin J. Brown, Jr. - - mjbjr@beaudesign.com - Public PGP Key ID: 0xB09AFEFE keyserver: http://pgpkeys.mit.edu:11371/ Key fingerprint = F3C4 503E 6239 E395 1D33 2FA6 CF11 6F34 B09A FEFE _______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users
mjbjr@beaudesign.com wrote:> To me, the main app (an object) is separate from the app gui (object)... > MVC''ish. > > How can I have the gui part communicate to the app that an event has > taken place? Example code somewhere?The short answer to your question as asked would be that you would simply invoke normal ruby methods in your app class. Something like this (written in email and never run through ruby): ##################################### class MyApp < Wx::App ... def something_happened puts("something happened!") end ... end class MyMainFrame < Wx::Frame ... def on_click Wx::get_app.something_happened end ... end ##################################### Hm. That call to get_app.something_happened probably won''t work in wxruby 0.6 because it doesn''t have great support for extending subclassed classes. Maybe, though. It might not even work in wxruby-swig, but I think it would. If not, the alternative to simply keep a global $app variable, and invoke $app.something_happened. In a perfect world, wxruby would support the Wx::Document class, which might be a better place for your non-GUI logic. Unfortunately, neither wxruby 0.6 nor wxruby-swig supports that yet. However, you could create your own document (aka model) class, and create it in your frame initializer. In that case, the sample above would end up more like: def on_click @model.something_happened end If you wanted to get fancier, you could use the wx event system to pass messages to a document or to your app. Your document would be a subclass of Wx::EventHandler, which would allow it to receive events. However, that''s very much uncharted territory, so if you experiment with it, you might be the first person on the planet ever to have done so. Hope that helps. Kevin
Hi What sort of GUI events are they, and, importantly, are they things that the GUI needs to update in response to the results? As Kevin suggested, it might be easiest for the GUI to call the app object''s methods - the app should expose a set of methods that correspond to the actions that can be performed through the GUI Weft QDA (http://www.pressure.to/qda/) follows this model for gui->app communication. app->gui communication - including presenting the results of user actions - is handled by a module similar to Observable (in the standard library). When an updateable UI element is created, it subscribes to global app events that it is interested in. class Widget include Subscriber def initialize(foo, bar) ... subscribe(:category_added, :category_changed) end def receive_category_added(category) update_myself_to_show_new_category end end hth alex mjbjr@beaudesign.com wrote:> To me, the main app (an object) is separate from the app gui (object)... > MVC''ish. > > How can I have the gui part communicate to the app that an event has > taken place? Example code somewhere? > > Thank you. > > > > ------------------------------------------------------------------------ > > _______________________________________________ > wxruby-users mailing list > wxruby-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users
Well, I was hoping to not have to sub-class Frame, but that''s what I''ve done. Now, the mainApp object passes ''self'' to the myFrame object on instantiation. -- - Martin J. Brown, Jr. - - mjbjr@beaudesign.com - Public PGP Key ID: 0xB09AFEFE keyserver: http://pgpkeys.mit.edu:11371/ Key fingerprint = F3C4 503E 6239 E395 1D33 2FA6 CF11 6F34 B09A FEFE -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-users/attachments/20050714/c3dca730/attachment.bin