limelight release 0.6.14

34 views
Skip to first unread message

Chuck Remes

unread,
Jul 18, 2012, 11:18:38 AM7/18/12
to limelig...@googlegroups.com
Many thanks to Micah for doing a Ruby gem release yesterday afternoon that addresses some problems on Windows with text_box players.

I am updating some code to conform to the new API. The biggest change is that players are no longer Modules that take method definitions like "mouse_clicked" to add functionality to the player. Instead, the player is tagged with an :id => "some_player" and the override functionality for that player is loaded from "some_player.rb" where the methods use a DSL.

file some_player.rb (player is a button)

on_button_pushed do
# some work
end

So, my problem has to do with using a partial. I use a partial because my main window gets 4 rows loaded that all have the same characteristics; the partial is used to help keep things DRY. In my main prop.rb I have some code like so:

rows :id => 'rows' do
__install 'entry_window/row_partial.rb'
__install 'entry_window/row_partial.rb'
__install 'entry_window/row_partial.rb'
__install 'entry_window/row_partial.rb'
end

The row_partial.rb contains the following code:

row do
symbol_box :players => 'text_box', :id => "symbol_box"
action_box :players => 'text_box'
price_box :players => 'text_box'
example_price_box :text => ''
lots_box :players => 'text_box'
exits_box :players => 'text_box'
stop_ticks_box :players => 'text_box'
activation_date_box :players => 'text_box'
activation_time_box :players => 'text_box'
deactivation_date_box :players => 'text_box'
deactivation_time_box :players => 'text_box'
account_box :players => 'text_box'
end


I need "symbol_box" to do some work when the focus is lost, so I tag it with an :id to load up the code from "symbol_box.rb". I have an override in there that looks similar to this:

on_focus_lost do
if defaults.has_key?(symbol)
populate_defaults(defaults[symbol])
self.text = self.text.upcase
get_prop(self.parent, 'price_box').multiplier = @multiplier
else
self.text = 'WRONG'
end
end

However, loading the partial no longer works. When starting up the application it blows up when I try to __install the row_partial.rb file a second time. It complains about a duplicate ":id" for "symbol_box". This error is generated from some Java code at limelight.ui.model.ScenePanel.addToIndex(ScenePanel.java:223)

What's the recommended technique now for accomplishing this task? I see that I need to avoid giving each row's symbol_box the same :id, but I don't see how I can pass a variable (like "@counter") to increment the :id each time the file is installed/loaded.

Any hints?

cr

Micah Martin

unread,
Jul 18, 2012, 11:50:14 AM7/18/12
to limelig...@googlegroups.com
Chuck,

You can pass variable to partials.

rows :id => 'rows' do
__install 'entry_window/row_partial.rb', :id => 1
__install 'entry_window/row_partial.rb', :id => 2
__install 'entry_window/row_partial.rb', :id => 3
__install 'entry_window/row_partial.rb', :id => 4
end

row do
symbol_box :players => 'text_box', :id => "symbol_box_#{@id}"
...
end

However, it's not clean why you need an id on symbol_box. Players are automatically applied based on the name of the prop, not the id. Also, if you wanted other players, besides the one associated with the name of the prop, you can add the attribute to the prop.

my_prop :players => "other_player"
my_prop :players => ["other_player", "another_player"]

The "id" of a prop is usually just marker so it can be found later.

my_prop = scene.find("my_props_id")

Hope this helps.

Micah

Chuck Remes

unread,
Jul 18, 2012, 3:06:51 PM7/18/12
to limelig...@googlegroups.com

On Jul 18, 2012, at 10:50 AM, Micah Martin wrote:

> Chuck,
>
> You can pass variable to partials.
>
> rows :id => 'rows' do
> __install 'entry_window/row_partial.rb', :id => 1
> __install 'entry_window/row_partial.rb', :id => 2
> __install 'entry_window/row_partial.rb', :id => 3
> __install 'entry_window/row_partial.rb', :id => 4
> end
>
> row do
> symbol_box :players => 'text_box', :id => "symbol_box_#{@id}"
> ...
> end
>
> However, it's not clean why you need an id on symbol_box. Players are automatically applied based on the name of the prop, not the id. Also, if you wanted other players, besides the one associated with the name of the prop, you can add the attribute to the prop.
>
> my_prop :players => "other_player"
> my_prop :players => ["other_player", "another_player"]
>
> The "id" of a prop is usually just marker so it can be found later.
>
> my_prop = scene.find("my_props_id")
>
> Hope this helps.

That helped immensely. I now have most of that working.

My next issue is loading gems that are packaged as part of the production. I discovered a few things.

1. In production.rb, limelight no longer uses a Production module and calls #production_opening, #production_loaded, etc. It calls #on_production_created, #on_production_loaded, etc.

2. Gems should be stored in <project>/__resources/gems/gems

In my #on_production_created method I am trying to load up gems. I have this code:

on_production_created do
require 'rubygems'
Gem.path << File.expand_path(gems_directory)

require 'uuid'
require 'ffi-rzmq'
require 'time'
require 'json'
end

It dies on the require 'uuid' call with this backtrace:

https://gist.github.com/3138120

The sandbox example did not show how to use this new feature so I'm kind of stabbing in the dark. I tried the same code minus the modification to Gem.path and it fails the same way. What's the right way to do this now?

cr

Chuck Remes

unread,
Jul 18, 2012, 3:15:21 PM7/18/12
to limelig...@googlegroups.com

On Jul 18, 2012, at 2:06 PM, Chuck Remes wrote:

> My next issue is loading gems that are packaged as part of the production. I discovered a few things.
>
> 1. In production.rb, limelight no longer uses a Production module and calls #production_opening, #production_loaded, etc. It calls #on_production_created, #on_production_loaded, etc.
>
> 2. Gems should be stored in <project>/__resources/gems/gems
>
> In my #on_production_created method I am trying to load up gems. I have this code:
>
> on_production_created do
> require 'rubygems'
> Gem.path << File.expand_path(gems_directory)
>
> require 'uuid'
> require 'ffi-rzmq'
> require 'time'
> require 'json'
> end
>
> It dies on the require 'uuid' call with this backtrace:
>
> https://gist.github.com/3138120
>
> The sandbox example did not show how to use this new feature so I'm kind of stabbing in the dark. I tried the same code minus the modification to Gem.path and it fails the same way. What's the right way to do this now?

Never mind this one. If the gem is installed in the jruby gems directory then it finds the gems just fine. I can use it that way for now, so bundling the gem with the production isn't a necessity.

cr

Micah Martin

unread,
Jul 18, 2012, 4:03:52 PM7/18/12
to limelig...@googlegroups.com
Okay… but just so you know. The need for gem support in limelight when away with the arrival of Bundler.

bundle install --standalone

This will dump all the gems in a local 'bundle' dir. Make sure that goes inside the production. Then in production.rb add a hook (production_created should do) that includes:

require File.dirname(__FILE__) + "/bundle/bundler/setup"

This is an elegant solution that remove dependencies on bundler and rubygems at runtime.

Micah
Reply all
Reply to author
Forward
0 new messages