Re: [Siop-development] wxRython
Status: Pre-Alpha
Brought to you by:
slobberchops
From: Rapheal K. <ra...@ma...> - 2006-06-14 07:56:28
|
Ok folks, as an example, I would like to introduce the first Python classes written in Ruby. They look funny now, but once we get up to level 2, implement static arrays and maps, this will look a lot cleaner. I'm thinking that it might even make sense for SIOP to have a level that deals with class definition. I will put this in an example directory. Kevin, the code below actually works... when you resize the window the new size is printed to the console. It's a fully Ruby based wx callback. The trick turned out to be to use this weird "instancemethod" function. Anyway, see if you can figure out what it means... ------------------------------- #!/usr/bin/env ruby require 'siop/pipe' Siop::Pipe.connect '../../scripts/siop-standard-server.py' do |bridge| bridge.fetch_namespace nil, 'wx' bridge.fetch_namespace nil, 'types' bridge.fetch_namespace nil, 'new' rc = bridge.remote_context wx = rc.wx instancemethod = rc.new.instancemethod $types = rc.types def tuple( *stuff ) list = $types.ListType.call for thing in stuff list.append( thing ) end $types.TupleType( list ) end def pyclass( name, parents, &definition ) instance_eval do klass = $types.ClassType( name.to_s, tuple( *parents ), $types.DictType.call ) klass.instance_eval &definition unless definition.nil? klass end end MyApp = pyclass :MyApp, [wx.App] do self.OnInit = proc do | pyself | pyself.frame = MyFrame.call(nil, -1, "This is a test") MyFrame.Show( pyself.frame, true ) pyself.SetTopWindow( pyself.frame ) true end self.OnInit = instancemethod.call( self.OnInit, nil, self ) end MyFrame = pyclass :MyFrame, [wx.Frame] do self.__init__ = proc do | pyself, parent, wid, title| wx.Frame.__init__( pyself, parent, wid, title ) pyself.Bind( wx.EVT_SIZE, pyself.OnSize ) end self.__init__ = instancemethod.call( self.__init__, nil, self ) self.OnSize = proc do |pyself, event| p "Coordinates (#{event.GetSize.call.x}, #{event.GetSize.call.y})" end self.OnSize = instancemethod.call( self.__init__, nil, self ) end app = MyApp.call app.MainLoop.call end |