Re: [MacRuby-devel] Problem with a window controller

2012-12-02 Thread david kramf
Thank you very much Andy and Jim
I followed your remarks , played  with the code and I am still surprised. It 
turns out that awakeFromNib is called before applicationDidFinishLaunching so 
there MyController is already initialized and has the correct window as the his 
instance variable. NSWindow has both a delegate protocol and a Controller class 
and so I called setDelegate and setController . Everything seems OK but the 
methods willLoad and didLoad are not called although clearly my class is both 
the delegate and the controller of my window . So I am still left asking what 
am I doing wrong (??).

Are there MacRuby code samples I can use. I read Lim,Chueng and McAnally book. 
I wonder where can I find more samples. I am also not sure I am doing 
everything correct with the IB . My blue box that represents MyController list 
"showWindow: " as a "Received Action"  , but I could not  connect it to any 
element of window draw in the XIB file.

David

class AppDelegate
attr_accessor :window
def applicationDidFinishLaunching(a_notification)
puts " Insert code here to initialize your application"
wCtrl = @window.delegate
puts "no delegate" if wCtrl == nil
win = wCtrl.window
puts "win is nil" if win == nil
puts "title of window is #{win.title}"
ctrl = @window.windowController
puts "no controller" if ctrl == nil
puts "class of delegate is #{wCtrl.class}"
puts "class of controller is #{ctrl.class}"
puts "both are equal " if wCtrl == ctrl
x = ctrl.showWindow
puts "x class is #{x.class} " unless x == nil

#puts "window nil " if win == nil
#wCtrl.close
end
end
class MyController < NSWindowController
attr_accessor :window

def initialize
puts "in initialize"
initWithWindowNibName("tow")
#puts "after initialization window is #{@window.title}"
end

def routine
puts "in routine"
end

#def initWithWindow(window)
#   puts "in initWithWindow"
#   super(@window)
#end

def awakeFromNib
@window.setDelegate(self)
@window.setWindowController(self)
puts " at end of awake from nib. title is #{@window.title}"
end

def windowWillLoad
puts "window  will be soon loaded"
end

def windowDidLoad
puts "window loaded"
end
def windowTitleForDocumentDisplayName(displayName)
"Hello World"
end

def showWindow
   puts "in showWindow"
   super(self)
end

def close
puts "in close window is #{@window.title}" 
super
end

end


at end of awake from nib. title is two
 Insert code here to initialize your application
title of window is two
class of delegate is MyController
class of controller is MyController
both are equal 
in showWindow
x class is MyController 
 



On Dec 1, 2012, at 3:00 AM, Andy Park wrote:

> Without being able to verify anything for accuracy at the moment, it looks 
> like your window's delegate is not set to the controller at the time the 
> events are occurring. 
> 
> Check if you need to set this - try tracing the window's delegate at 
> different points of the controller's lifecycle.
> 
> On 30 Nov 2012, at 00:50, david kramf  wrote:
> 
>> 
>> Hi, 
>> In the copied below code only the awakeFromNib is executed . Can someone 
>> explain me what do I do wrong ?  Window is displayed and I expected all 
>> other methods to be called.
>> Thanks, David
>> 
>> 
>> class MyController < NSWindowController
>> attr_accessor :window
>> 
>> def awakeFromNib
>> @window.delegate = self
>> puts " at end of awake from nib. title is #{@window.title}"
>> end
>> 
>> def windowWillLoad
>> puts "window  will be soon loaded"
>> end
>> 
>> def windowDidLoad
>> puts "window loaded"
>> end
>> def windowTitleForDocumentDisplayName(displayName)
>> "Hello World"
>> end
>> 
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo/macruby-devel

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo/macruby-devel


Re: [MacRuby-devel] Problem with a window controller

2012-12-02 Thread Andy Park
On Sunday, 2 December 2012, david kramf wrote:

> Thank you very much Andy and Jim
> I followed your remarks , played  with the code and I am still surprised.
> It turns out that awakeFromNib is called before applicationDidFinishLaunching
> so there MyController is already initialized and has the correct window
> as the his instance variable. NSWindow has both a delegate protocol and a
> Controller class and so I called setDelegate and setController . Everything
> seems OK but the methods willLoad and didLoad are not called although
> clearly my class is both the delegate and the controller of my window . So
> I am still left asking what am I doing wrong (??).
>
>
There are a few things about the code below that seems to be throwing you
down a rabbit hole, discussed here.
http://www.cocoabuilder.com/archive/cocoa/93361-awakefromnib-and-windowwillload-basic-question.html

When using xibs, the delegate of view objects such as windows are
conventionally set in the xib
by connecting the outlet. Try replacing the contents of your awakeFromNib
with traces
of the window's delegate and controller, set up your window's ibloutlet to
the controller in your
Xib, and see what happens.

As for the window delegate methods, the mailing list thread suggests you
should avoid
relying on them to signal view-level events.



> Are there MacRuby code samples I can use. I read Lim,Chueng and McAnally
> book. I wonder where can I find more samples. I am also not sure I am doing
> everything correct with the IB . My blue box that represents MyController
> list "showWindow: " as a "Received Action"  , but I could not  connect it
> to any element of window draw in the XIB file.
>

ShowWindow is probably not meant to be an IBAction that you're expected to
connect with a control.
This sounds like the macruby script that parses IBActions is taking the
method to be an IBAction due
to the signature being like so, when you just wanted to implement a
delegate method.

>
> David
>
> class AppDelegate
> attr_accessor :window
> def applicationDidFinishLaunching(a_notification)
> puts " Insert code here to initialize your application"
> wCtrl = @window.delegate
> puts "no delegate" if wCtrl == nil
> win = wCtrl.window
> puts "win is nil" if win == nil
> puts "title of window is #{win.title}"
> ctrl = @window.windowController
> puts "no controller" if ctrl == nil
> puts "class of delegate is #{wCtrl.class}"
> puts "class of controller is #{ctrl.class}"
> puts "both are equal " if wCtrl == ctrl
> x = ctrl.showWindow
> puts "x class is #{x.class} " unless x == nil
>
>
> #puts "window nil " if win == nil
> #wCtrl.close
> end
> end
> class MyController < NSWindowController
> attr_accessor :window
>
>
> def initialize
> puts "in initialize"
> initWithWindowNibName("tow")
> #puts "after initialization window is #{@window.title}"
> end
>
>
> def routine
> puts "in routine"
> end
>
>
> #def initWithWindow(window)
> #   puts "in initWithWindow"
> #   super(@window)
> #end
>
>
> def awakeFromNib
> @window.setDelegate(self)
> @window.setWindowController(self)
> puts " at end of awake from nib. title is #{@window.title}"
> end
>
>
> def windowWillLoad
> puts "window  will be soon loaded"
> end
>
>
> def windowDidLoad
> puts "window loaded"
> end
> def windowTitleForDocumentDisplayName(displayName)
> "Hello World"
> end
>
>
> def showWindow
>puts "in showWindow"
>super(self)
> end
>
>
> def close
> puts "in close window is #{@window.title}"
> super
> end
>
>
> end
>
>
> *at end of awake from nib. title is two*
> * Insert code here to initialize your application*
> *title of window is two*
> *class of delegate is MyController*
> *class of controller is MyController*
> *both are equal *
> *in showWindow*
> *x class is MyController *
>
>
>
>
> On Dec 1, 2012, at 3:00 AM, Andy Park wrote:
>
> Without being able to verify anything for accuracy at the moment, it looks
> like your window's delegate is not set to the controller at the time the
> events are occurring.
>
> Check if you need to set this - try tracing the window's delegate at
> different points of the controller's lifecycle.
>
> On 30 Nov 2012, at 00:50, david kramf  wrote:
>
>
> Hi,
> In the copied below code only the awakeFromNib is executed . Can someone
> explain me what do I do wrong ?  Window is displayed and I expected all
> other methods to be called.
> Thanks, David
>
>
> class MyController < NSWindowController
> attr_accessor :window
>
> def awakeFromNib
> @window.delegate = self
> puts " at end of awake from nib. title is #{@window.title}"
> end
>
> def windowWillLoad
>
>
___
MacRuby-devel maili

Re: [MacRuby-devel] Problem with a window controller

2012-12-02 Thread J Silver

Hi David,

Try NSLog instead of puts. Also you can override puts to #NSLog.

I have some production MacRuby code up at 
https://github.com/jsilverMDX/GlobalChat2/tree/master/globalchat%202%20OSX 
that's in the App Store.


Look here for an example of a working MacRuby app that uses IB and Sockets.

Try firing an action on seperate view controller and storing your 
information there. I don't use Window object for much except showing and 
hiding views.


Domo

jsilver

On 02/12/2012 05:30, david kramf wrote:

Thank you very much Andy and Jim
I followed your remarks , played  with the code and I am still 
surprised. It turns out that awakeFromNib is called before 
applicationDidFinishLaunching so there MyController is already 
initialized and has the correct window as the his instance variable. 
NSWindow has both a delegate protocol and a Controller class and so I 
called setDelegate and setController . Everything seems OK but the 
methods willLoad and didLoad are not called although clearly my class 
is both the delegate and the controller of my window . So I am still 
left asking what am I doing wrong (??).


Are there MacRuby code samples I can use. I read Lim,Chueng and 
McAnally book. I wonder where can I find more samples. I am also not 
sure I am doing everything correct with the IB . My blue box that 
represents MyController list "showWindow: " as a "Received Action"  , 
but I could not  connect it to any element of window draw in the XIB file.


David

class AppDelegate
attr_accessor :window
def applicationDidFinishLaunching(a_notification)
puts " Insert code here to initialize your application"
wCtrl = @window.delegate
puts "no delegate" if wCtrl == nil
win = wCtrl.window
puts "win is nil" if win == nil
puts "title of window is #{win.title}"
ctrl = @window.windowController
puts "no controller" if ctrl == nil
puts "class of delegate is #{wCtrl.class}"
puts "class of controller is #{ctrl.class}"
puts "both are equal " if wCtrl == ctrl
x = ctrl.showWindow
puts "x class is #{x.class} "unlessx == nil


#puts "window nil " if win == nil
#wCtrl.close
end
end
class MyController < NSWindowController
attr_accessor :window


def initialize
puts "in initialize"
initWithWindowNibName("tow")
#puts "after initialization window is #{@window.title}"
end


def routine
puts "in routine"
end


#def initWithWindow(window)
#   puts "in initWithWindow"
#   super(@window)
#end


def awakeFromNib
@window.setDelegate(self)
@window.setWindowController(self)
puts " at end of awake from nib. title is #{@window.title}"
end


def windowWillLoad
puts "window  will be soon loaded"
end


def windowDidLoad
puts "window loaded"
end
def windowTitleForDocumentDisplayName(displayName)
"Hello World"
end


def showWindow
   puts "in showWindow"
super(self)
end


def close
puts "in close window is #{@window.title}"
super
end


end


*at end of awake from nib. title is two*
* Insert code here to initialize your application*
*title of window is two*
*class of delegate is MyController*
*class of controller is MyController*
*both are equal *
*in showWindow*
*x class is MyController *



On Dec 1, 2012, at 3:00 AM, Andy Park wrote:

Without being able to verify anything for accuracy at the moment, it 
looks like your window's delegate is not set to the controller at the 
time the events are occurring.


Check if you need to set this - try tracing the window's delegate at 
different points of the controller's lifecycle.


On 30 Nov 2012, at 00:50, david kramf > wrote:




Hi,
In the copied below code only the awakeFromNib is executed . Can 
someone explain me what do I do wrong ?  Window is displayed and I 
expected all other methods to be called.

Thanks, David


class MyController < NSWindowController
attr_accessor :window

def awakeFromNib
@window.delegate = self
puts " at end of awake from nib. title is #{@window.title}"
end

def windowWillLoad
puts "window  will be soon loaded"
end

def windowDidLoad
puts "window loaded"
end
def windowTitleForDocumentDisplayName(displayName)
"Hello World"
end

___
MacRuby-devel mailing list
[email protected] 


http://lists.macosforge.org/mailman/listinfo/macruby-devel

___
MacRuby-devel mailing list
[email protected] 


http://lists.macosforge.org/mailman/listinfo/macruby-devel




___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo/macruby-devel


___
MacRuby-devel mailing list
[email protected]

Re: [MacRuby-devel] MacBacon problem

2012-12-02 Thread stephen horne
On a related note to some things touched upon in this thread, it seems that in 
macbacon test scripts you don't need to require rubygems or mac_bacon, as this 
is done for you in the macbacon executable.

Stephen

On 30/11/2012, at 18:26, J Silver  wrote:

> Wow, didn't even know 1.9 required "rubygems" by default! Thanks!
> 
> On 30/11/2012 10:22, Joshua Ballanco wrote:
>> Do you have a "require 'rubygems'" in your script? Unlike Ruby 1.9, MacRuby 
>> doesn't automatically load RubyGems by default.
>> On Friday, November 30, 2012 at 8:11 PM, stephen horne wrote:
>> 
>>> Thanks Daniel, you were right - I'd gem installed it. I've now gem 
>>> uninstalled it and tried with macgem, but whilst that claims to install it, 
>>> I get a Gem::LoadError when I try to use it:
>>> 
>>> $sudo macgem install mac_bacon
>>> Successfully installed mac_bacon-1.3
>>> 1 gem installed
>>> 
>>> and then try:
>>> 
>>> $macbacon my_class_test.rb
>>> 
>>> I get:
>>> 
>>> /usr/local/bin/macbacon:18:in `': Could not find mac_bacon (>= 0) 
>>> amongst [ParseTree-2.1.1, RubyInline-3.11.3, ZenTest-4.8.2, 
>>> addressable-2.2.8, autotest-4.4.6, bacon-1.1.0, 
>>> bouncy-castle-java-1.5.0146.1, bundle-0.0.1, bundler-1.0.22, cheat-1.3.0, 
>>> choice-0.1.6, dbi-0.4.5, debugger-1.2.2, debugger-linecache-1.1.2, 
>>> debugger-ruby_core_source-1.1.5, deprecated-2.0.1, diff-lcs-1.1.3, 
>>> fuzzy-string-match_pure-0.9.3, gem-man-0.3.0, git-1.2.5, hoe-3.2.0, 
>>> htty-1.4.0, jruby-openssl-0.7.7, launchy-2.1.0, lolcommits-0.1.5, 
>>> lucene-0.5.0.beta.1, mime-types-1.19, net-ftp-list-3.2.3, net-sftp-2.0.5, 
>>> net-ssh-2.5.2, plugin_manager-1.5, rack-1.4.1, rack-test-0.6.2, 
>>> rb-appscript-0.6.1, rb-fsevent-0.9.2, rbx-require-relative-0.0.9, 
>>> rdebug-0.1, rdiscount-1.6.8, redcar-0.13, redcar-bundles-0.3, 
>>> redcar-icons-0.3, redcar-javamateview-0.2, redcar-jruby-0.1, 
>>> redcar-svnkit-0.2, rmagick-2.13.1, rspec-2.12.0, rspec-core-2.12.0, 
>>> rspec-core-2.11.1, rspec-expectations-2.12.0, rspec-expectations-2.11.3, 
>>> rspec-mocks-2.12.0, rspec-mocks-2.11.3, ruby-blockcache-0.2, 
>>> ruby2ruby-1.1.8, sake-1.0.15, spoon-0.0.1, swt-0.13, yard-0.8.2.1] 
>>> (Gem::LoadError)
>>> 
>>> and indeed, when I run
>>> 
>>> macgem list
>>> 
>>> there is no mac_bacon listed there. Do you know what else I'm missing here?
>>> 
>>> Thanks,
>>> 
>>> Stephen
>>> 
>>> 
>>> 
>>> On 30/11/2012, at 17:52, Daniel Westendorf  wrote:
>>> 
 Stephen,
 
 It looks like MacBacon is using MRI Ruby, not MacRuby. Did you install the 
 gem using macgem? You might have to uninstall any other versions you've 
 installed.
 
 I never had much luck with RVM+MacRuby; I always installed MacRuby using 
 the installer from the website. This might have been fixed though.
 
 dw
 
 On Fri, Nov 30, 2012 at 10:46 AM, stephen horne  wrote:
> I'm trying to get started with tdd and MacRuby, but I've hit a stumbling 
> block immediately with macbacon. I suspect it's something to do with rvm, 
> but I'm not sure.
> 
> When I run macbacon like this:
> 
> 
>   $macbacon my_class_test.rb 
> 
> I get the following error backtrace:
> 
> /Users/fatboy/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
>  `require': 
> /Users/fatboy/.rvm/gems/ruby-1.9.3-p125/gems/mac_bacon-1.3/lib/mac_bacon.rb:212:
>  syntax error, unexpected tLABEL (SyntaxError)
> ...eForKeyPath(key_path, ofObject:object, change:_, context:__)
> ...   ^
> /Users/fatboy/.rvm/gems/ruby-1.9.3-p125/gems/mac_bacon-1.3/lib/mac_bacon.rb:337:
>  class definition in method body
> /Users/fatboy/.rvm/gems/ruby-1.9.3-p125/gems/mac_bacon-1.3/lib/mac_bacon.rb:429:
>  syntax error, unexpected keyword_end, expecting $end
>  
> from 
> /Users/fatboy/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
>  `require'
>  
> from 
> /Users/fatboy/.rvm/gems/ruby-1.9.3-p125/gems/mac_bacon-1.3/bin/macbacon:110:in
>  `'
>  
> from /Users/fatboy/.rvm/gems/ruby-1.9.3-p125/bin/macbacon:19:in `load'
>  
> from /Users/fatboy/.rvm/gems/ruby-1.9.3-p125/bin/macbacon:19:in `'
> 
> Can anyone see what's wrong with my setup?
> 
> Thanks.
> --
> Stephen Horne
> 
> 
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo/macruby-devel
> 
 
 ___
 MacRuby-devel mailing list
 [email protected]
 http://lists.macosforge.org/mailman/listinfo/macruby-devel
>>> 
>>> --
>>> Stephen Horne
>>> 
>>> ___
>>> MacRuby-devel mailing list
>>> [email protected]
>>> http://lists.macosforge.or

Re: [MacRuby-devel] Problem with a window controller

2012-12-02 Thread Robert Carl Rice
Hi David,

A couple of things I notice offhand in you code:

The NSWindowController class defines accessor methods for "window" so you 
shouldn't redefine it with the Ruby attr_accessor method. Note: similarly 
NSViewController defines accessor methods for "view".

You can configure IB to link the window delegate when the Nib is expanded so 
that you don't need to set it in awakeFromNib.

Bob Rice


On Nov 29, 2012, at 6:50 PM, david kramf  wrote:

> 
> Hi, 
> In the copied below code only the awakeFromNib is executed . Can someone 
> explain me what do I do wrong ?  Window is displayed and I expected all other 
> methods to be called.
> Thanks, David
> 

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo/macruby-devel


Re: [MacRuby-devel] Problem with a window controller

2012-12-02 Thread david kramf
Hi Bob
My code crashes if I omit the attr_accessor. 
Can you refer me to instructions of how to configure the IB to link to my 
controller as delegate (?) . In the examples I have in my book  and ,if I am 
not mistaken, lectures I viewed in iTunes U ( the Stanford series ), they all 
used the awakeFromNib as point of initialization .
Thanks, David 
On Dec 3, 2012, at 6:24 AM, Robert Carl Rice wrote:

> Hi David,
> 
> A couple of things I notice offhand in you code:
> 
> The NSWindowController class defines accessor methods for "window" so you 
> shouldn't redefine it with the Ruby attr_accessor method. Note: similarly 
> NSViewController defines accessor methods for "view".
> 
> You can configure IB to link the window delegate when the Nib is expanded so 
> that you don't need to set it in awakeFromNib.
> 
> Bob Rice
> 
> 
> On Nov 29, 2012, at 6:50 PM, david kramf  wrote:
> 
>> 
>> Hi, 
>> In the copied below code only the awakeFromNib is executed . Can someone 
>> explain me what do I do wrong ?  Window is displayed and I expected all 
>> other methods to be called.
>> Thanks, David
>> 
> 
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo/macruby-devel

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo/macruby-devel