thomthom / SKUI

Ruby wrapper of classes that maps to GUI controls in SketchUp's UI::WebDialogs
MIT License
26 stars 14 forks source link

Error: #<NoMethodError: undefined method `bridge' for nil:NilClass> #90

Closed jimfoltz closed 10 years ago

jimfoltz commented 10 years ago

Here's the code which causes the error.. https://github.com/jimfoltz/layer-behavior/blob/dev/src/jf_layer_behavior/main.rb#L75

I can get the properties of the RadioButton, but when I ask if it is checked?, I get the error.

I tagged the commit as iss90

Full Error:

Error: #<NoMethodError: undefined method `bridge' for nil:NilClass>
C:/Users/Jim/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/jf_layer_behavior/SKUI/checkbox.rb:40:in `checked?'
C:/Users/Jim/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/jf_layer_behavior/main.rb:76:in `block in main'
C:/Users/Jim/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/jf_layer_behavior/SKUI/events.rb:82:in `call'
C:/Users/Jim/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/jf_layer_behavior/SKUI/events.rb:82:in `block in trigger_event'
C:/Users/Jim/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/jf_layer_behavior/SKUI/events.rb:78:in `each'
C:/Users/Jim/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/jf_layer_behavior/SKUI/events.rb:78:in `trigger_event'
C:/Users/Jim/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/jf_layer_behavior/SKUI/window.rb:355:in `event_control_callback'
C:/Users/Jim/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/jf_layer_behavior/SKUI/window.rb:309:in `callback_handler'
C:/Users/Jim/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/jf_layer_behavior/SKUI/window.rb:267:in `block in add_callback'
-e:1:in `call'
noelwarr commented 10 years ago

Took me a few minutes to find. I seem to remember having a similar issue when I first started out. I guess it's technically a bug, but it can be easily avoided.

You are creating groups and attaching controls to them before you've attached the group to the window. Moving line 42 to 33 will fix the first error. You'll then get a second error which is exactly the same issue but for group 2.

Enjoy! :)

On 9 March 2014 21:23, Jim Foltz notifications@github.com wrote:

Here's the code which causes the error..

https://github.com/jimfoltz/layer-behavior/blob/dev/src/jf_layer_behavior/main.rb#L75

I can get the properties of the RadioButton, but when I ask if it is checked?, I get the error.

Reply to this email directly or view it on GitHubhttps://github.com/thomthom/SKUI/issues/90 .

thomthom commented 10 years ago

Control.name was added to let you refer to control's by symbols. They are safer than holding on to references.

thomthom commented 10 years ago

Ah! rdo_Visible is never assigned the window because grp_Default wasn't added to the window - meaning it never had a reference to pass on.

noelwarr commented 10 years ago

It was... Check out line 42. The problem is order.

On 9 March 2014 23:48, Thomas Thomassen notifications@github.com wrote:

Ah! rdo_Visible is never assigned the window because grp_Default wasn't added to the window - meaning it never had a reference to pass on.

Reply to this email directly or view it on GitHubhttps://github.com/thomthom/SKUI/issues/90#issuecomment-37142619 .

jimfoltz commented 10 years ago

Control.name was added to let you refer to control's by symbols. They are safer than holding on to references.

So Control.name... must turn multi-word strings into symbols? Does "Add Layer" become :add_layer?

The problem is order.

Yes, I think so too. However, when I added an OPTIONS hash the need to reference those controls in another block went away...

thomthom commented 10 years ago

@jimfoltz a control by default has no name. Check example.rb for how it's used: https://github.com/thomthom/SKUI/blob/master/examples/example.rb#L28

jimfoltz commented 10 years ago

AH! It's like a "handle"! :thumbsup: No need to make variables for controls, then.