Re: [MacRuby-devel] NSPoint and CGPoint issue

2012-12-10 Thread Min Soo Kim
Hi David,

I ran the following

framework 'cocoa'
def  initLabel(h)
   @label = NSTextField.alloc.initWithFrame(CGRectMake(0,0,250, 45))
   @label.setStringValue(h)
   @label.drawsBackground = false
   @label.bezeled = false
   @label.font = NSFont.fontWithName("Arial", size:45.0)
   @label.editable = false
   puts "class of label is #{@label.class}"
   # width = 
(@window.contentView.frameSize.width/2.0)-(@label.frameSize.width/2.0)
   # height = 
(@window.contentView.frameSize.height/2.0)-(@label.frameSize.height/2.0)
   width=100.0
   height=200.0
   puts "width is #{width} heght is #{height}"
   origin = NSMakePoint(width,height)
   puts "class of origin is #{origin.class}"
   @label.setFrameOrigin(origin)
   puts @label.frame.origin
end

initLabel("Hello")


I got the following output. 

class of label is NSTextField
width is 100.0 heght is 200.0
class of origin is CGPoint
#class of origin is CGPoint
#

It seem be to working for me. I think NSPoint and CGPoint can be mix used. 
(Free ride)
I think the problem is in the `￯﾿ᄐ￯﾿ᄐ' whatever that is

Min Soo Kim

On Dec 10, 2012, at 3:37 PM, david kramf wrote:

> Hi Min,
> This error message was produced by run environment and not by my code. I 
> don't do (knowingly ) anything with encoded text. Usually I get 
> comprehendible error messages when my code crashes.
> Thanks, David
> 
> On Dec 10, 2012, at 2:10 AM, Min Soo Kim wrote:
> 
>> Hello David,
>> 
>> In your error message it says
>>> undefined method `￯﾿ᄐ￯﾿ᄐ'
>> 
>> Why are you getting `￯﾿ᄐ￯﾿ᄐ' instead of 'setFrameOrigin'?
>> Do you have some foreign encoded text somewhere?
>> 
>> Min Soo Kim
>> 
>> 
>> On Dec 10, 2012, at 1:41 AM, david kramf wrote:
>> 
>>> Hello,
>>> I am trying to create an NSPoint object so I can call setFrameOrigin but I 
>>> get in response a CGPoint object . When I pass the CGPoint to 
>>> setFrameOrigin , it crashes. How do I make NSMakePoint making an NSPoint 
>>> object and not a CGPoint object.
>>> Thank you for  your help, 
>>> David Kramf
>>> 
>>>  def  initLabel(h)
>>> @label = NSTextField.alloc.initWithFrame(CGRectMake(0,0,250, 45))
>>> @label.setStringValue(h)
>>> @label.drawsBackground = false
>>> @label.bezeled = false
>>> @label.font = NSFont.fontWithName("Arial", size:45.0)
>>> @label.editable = false
>>> puts "class of label is #{@label.class}"
>>> width = 
>>> (@window.contentView.frameSize.width/2.0)-(@label.frameSize.width/2.0)
>>> height = 
>>> (@window.contentView.frameSize.height/2.0)-(@label.frameSize.height/2.0)
>>> puts "width is #{width} heght is #{height}"
>>> origin = NSMakePoint(width,height)
>>> puts "class of origin is #{origin.class}"
>>> @label.setFrameOrigin(origin)
>>> end
>>> 
>>> class of label is NSTextField
>>> width is 75.0 heght is 77.5
>>> class of origin is CGPoint
>>> 2012-12-09 18:33:13.525 two[3836:503] 
>>> /Users/davidkramf/Library/Developer/Xcode/DerivedData/two-gdovgltwrnzjfbfpizcbgrudvizf/Build/Products/Debug/two.app/Contents/Resources/MyController.rb:34:in
>>>  `initLabel': undefined method `￯﾿ᄐ￯﾿ᄐ' for 
>>> # (NoMethodError)
>>> from 
>>> /Users/davidkramf/Library/Developer/Xcode/DerivedData/two-gdovgltwrnzjfbfpizcbgrudvizf/Build/Products/Debug/two.app/Contents/Resources/MyController.rb:15:in
>>>  `initialize'
>>> from /Users/davidkramf/Library/Developer
>>> ___
>>> 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]
http://lists.macosforge.org/mailman/listinfo/macruby-devel


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

2012-12-10 Thread Jean-Denis MUYS

On 7 déc. 2012, at 19:48:39, david kramf 
 wrote:
> 
> Message: 1
> Date: Fri, 7 Dec 2012 19:48:39 +0200
> From: david kramf 
> To: "MacRuby development discussions."
>   
> Subject: Re: [MacRuby-devel] Problem with a window controller
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset="us-ascii"
> 
> Hi Bob,
> "As you become more familiar with IB, you will probably do more 
> initialization of objects in IB and less in MacRuby. Nib file expansion 
> instantiates objects and then makes calls to initialize the objects using the 
> same methods that you are using to initialize objects in MacRuby. Actually, 
> in a large application, it would difficult to hook up all of the outlets 
> without using IB."
> 
> From my modest acquaintance with MacRuby that is not exactly the case since 
> when the NIB instantiates  an NSWindowController object , it does not call 
> "initialize"

Cocoa, whether accessed from Ruby, Python, Objective-C or any language, uses 
the Cocoa initialization patterns. It's unrealistic to assume the framework 
patterns to change when you change the client language.

> ,as defined in Ruby , but calls "awakeFromNib".

It does, but caveat: awakeFromNib is *not* an initialization method, even 
though it is often used as such. I was bitten before. The correct 
initialization method to use for Nib files is initWithCoder:. What's the 
difference, says you (and me)? Behold:  awakeFromNib can be called several 
times in the lifetime of an object. This is no big deals for most 
initializations, but becomes a major issue in others. In my case, I was 
registering for notifications in awakeFromNib. Since I was registered several 
times, I got the notifications multiple times, and since I only unsubscribed 
once in dealloc, my app would crash.

Many cases when awakeFromNib is called more than once are programming errors, 
but not all. And since there *is* a real initializer, I recommend using it.

So in that case why is there an awakeFromNib method at all? It is because at 
initWithCoder: time, IB outlets are not yet loaded and are all nil. So 
awakeFromNib is meant to for initialization code that configures outlet.

So here is a recipe:

1- Does you initialization code requires IB outlets to be alive? If not, 
override initWithCoder:
2- If so, put it in awakeFromNib
3- Does that awakeFromNib initialization code need to be called once only? if 
so, make it conditional on it having been already be called.
4- Optional: assert that awakeFromNib was not called before, and if that assert 
fires, investigate whether the case is legitimate or due to a bug in your code.

> Only when you instantiate your controller from the code itself , you get your 
> "initialize"method called.  

That is a bonus you just can be happy to have due to the deep integration of 
MacRuby in the Objective-C runtime system. There is no reason to assume that 
bonus to expand to objects created by the framework.

> I know I still have a lot of practicing on IB. What I find disturbing ,is 
> that when I do something  with IB I cannot see the code created to 
> accommodate my actions ( maybe because I only work in MacRuby and not 
> Objective-C?).

No. This is simply because there **no code created**. At all. IB does't 
generate code. And lest I forget: Interface Builder is not a code generation 
tool. IB instantiates and populates objects, and then serializes them to disk. 
Those objects are then simply deserialized from disk in your app. At no point 
ever is any code generated. Therefore, there is no "code created to accommodate 
your actions" for you to see. Even in Objective-C.

Best regards,

Jean-Denis

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


Re: [MacRuby-devel] NSPoint and CGPoint issue

2012-12-10 Thread Braxton Sherouse
I can't speak to the encoding issues, but I can attest to crashing
issues with incorrectly assuming the compatibility of NSPoint and
CGPoint.

It depends what version of Mac OS you're on whether NSPoint can safely
be cast as a CGPoint. In older versions of Mac OS, NSPoint used float
for its members (32-bit) -- later, it switched to CGFloat (64-bit).


There are functions in the Foundation framework that you can use, if
you want to be safe: NSPointFromCGPoint and NSPointToCGPoint:

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSPointFromCGPoint


Also, check out the documentation here, on NSPoint, which gives the
version history:

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/uid/TP40003794

Best,
-braxton

On Mon, Dec 10, 2012 at 9:11 AM, Min Soo Kim  wrote:
> Hi David,
>
> I ran the following
>
> framework 'cocoa'
> def  initLabel(h)
>@label = NSTextField.alloc.initWithFrame(CGRectMake(0,0,250, 45))
>@label.setStringValue(h)
>@label.drawsBackground = false
>@label.bezeled = false
>@label.font = NSFont.fontWithName("Arial", size:45.0)
>@label.editable = false
>puts "class of label is #{@label.class}"
># width =
> (@window.contentView.frameSize.width/2.0)-(@label.frameSize.width/2.0)
># height =
> (@window.contentView.frameSize.height/2.0)-(@label.frameSize.height/2.0)
>width=100.0
>height=200.0
>puts "width is #{width} heght is #{height}"
>origin = NSMakePoint(width,height)
>puts "class of origin is #{origin.class}"
>@label.setFrameOrigin(origin)
>puts @label.frame.origin
> end
>
> initLabel("Hello")
>
>
> I got the following output.
>
> class of label is NSTextField
> width is 100.0 heght is 200.0
> class of origin is CGPoint
> #class of origin is CGPoint
> #
>
> It seem be to working for me. I think NSPoint and CGPoint can be mix used.
> (Free ride)
> I think the problem is in the `￯﾿ᄐ￯﾿ᄐ' whatever that is
>
> Min Soo Kim
>
> On Dec 10, 2012, at 3:37 PM, david kramf wrote:
>
> Hi Min,
> This error message was produced by run environment and not by my code. I
> don't do (knowingly ) anything with encoded text. Usually I get
> comprehendible error messages when my code crashes.
> Thanks, David
>
> On Dec 10, 2012, at 2:10 AM, Min Soo Kim wrote:
>
> Hello David,
>
> In your error message it says
>
> undefined method `￯﾿ᄐ￯﾿ᄐ'
>
>
> Why are you getting `￯﾿ᄐ￯﾿ᄐ' instead of 'setFrameOrigin'?
> Do you have some foreign encoded text somewhere?
>
> Min Soo Kim
>
>
> On Dec 10, 2012, at 1:41 AM, david kramf wrote:
>
> Hello,
> I am trying to create an NSPoint object so I can call setFrameOrigin but I
> get in response a CGPoint object . When I pass the CGPoint to setFrameOrigin
> , it crashes. How do I make NSMakePoint making an NSPoint object and not a
> CGPoint object.
> Thank you for  your help,
> David Kramf
>
>  def  initLabel(h)
> @label = NSTextField.alloc.initWithFrame(CGRectMake(0,0,250, 45))
> @label.setStringValue(h)
> @label.drawsBackground = false
> @label.bezeled = false
> @label.font = NSFont.fontWithName("Arial", size:45.0)
> @label.editable = false
> puts "class of label is #{@label.class}"
> width =
> (@window.contentView.frameSize.width/2.0)-(@label.frameSize.width/2.0)
> height =
> (@window.contentView.frameSize.height/2.0)-(@label.frameSize.height/2.0)
> puts "width is #{width} heght is #{height}"
> origin = NSMakePoint(width,height)
> puts "class of origin is #{origin.class}"
> @label.setFrameOrigin(origin)
> end
>
> class of label is NSTextField
> width is 75.0 heght is 77.5
> class of origin is CGPoint
> 2012-12-09 18:33:13.525 two[3836:503]
> /Users/davidkramf/Library/Developer/Xcode/DerivedData/two-gdovgltwrnzjfbfpizcbgrudvizf/Build/Products/Debug/two.app/Contents/Resources/MyController.rb:34:in
> `initLabel': undefined method `￯﾿ᄐ￯﾿ᄐ' for
> # (NoMethodError)
> from
> /Users/davidkramf/Library/Developer/Xcode/DerivedData/two-gdovgltwrnzjfbfpizcbgrudvizf/Build/Products/Debug/two.app/Contents/Resources/MyController.rb:15:in
> `initialize'
> from /Users/davidkramf/Library/Developer
> ___
> 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/li

Re: [MacRuby-devel] NSPoint and CGPoint issue

2012-12-10 Thread david kramf
Braxton,
Many Thanks for your advice . I will try to cast from CGPoint to NSPoint .
Nim,
I will try your code . In addition to the fact that we probably run on a 
different OS or MacRuby version , the other difference is that you set the 
width and height to full constants . The division operations that you commented 
out produced fractions.
Thank You All,David
 
On Dec 10, 2012, at 11:35 AM, Braxton Sherouse wrote:

> I can't speak to the encoding issues, but I can attest to crashing
> issues with incorrectly assuming the compatibility of NSPoint and
> CGPoint.
> 
> It depends what version of Mac OS you're on whether NSPoint can safely
> be cast as a CGPoint. In older versions of Mac OS, NSPoint used float
> for its members (32-bit) -- later, it switched to CGFloat (64-bit).
> 
> 
> There are functions in the Foundation framework that you can use, if
> you want to be safe: NSPointFromCGPoint and NSPointToCGPoint:
> 
> https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSPointFromCGPoint
> 
> 
> Also, check out the documentation here, on NSPoint, which gives the
> version history:
> 
> https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html#//apple_ref/doc/uid/TP40003794
> 
> Best,
> -braxton
> 
> On Mon, Dec 10, 2012 at 9:11 AM, Min Soo Kim  wrote:
>> Hi David,
>> 
>> I ran the following
>> 
>> framework 'cocoa'
>> def  initLabel(h)
>>   @label = NSTextField.alloc.initWithFrame(CGRectMake(0,0,250, 45))
>>   @label.setStringValue(h)
>>   @label.drawsBackground = false
>>   @label.bezeled = false
>>   @label.font = NSFont.fontWithName("Arial", size:45.0)
>>   @label.editable = false
>>   puts "class of label is #{@label.class}"
>>   # width =
>> (@window.contentView.frameSize.width/2.0)-(@label.frameSize.width/2.0)
>>   # height =
>> (@window.contentView.frameSize.height/2.0)-(@label.frameSize.height/2.0)
>>   width=100.0
>>   height=200.0
>>   puts "width is #{width} heght is #{height}"
>>   origin = NSMakePoint(width,height)
>>   puts "class of origin is #{origin.class}"
>>   @label.setFrameOrigin(origin)
>>   puts @label.frame.origin
>> end
>> 
>> initLabel("Hello")
>> 
>> 
>> I got the following output.
>> 
>> class of label is NSTextField
>> width is 100.0 heght is 200.0
>> class of origin is CGPoint
>> #class of origin is CGPoint
>> #
>> 
>> It seem be to working for me. I think NSPoint and CGPoint can be mix used.
>> (Free ride)
>> I think the problem is in the `￯﾿ᄐ￯﾿ᄐ' whatever that is
>> 
>> Min Soo Kim
>> 
>> On Dec 10, 2012, at 3:37 PM, david kramf wrote:
>> 
>> Hi Min,
>> This error message was produced by run environment and not by my code. I
>> don't do (knowingly ) anything with encoded text. Usually I get
>> comprehendible error messages when my code crashes.
>> Thanks, David
>> 
>> On Dec 10, 2012, at 2:10 AM, Min Soo Kim wrote:
>> 
>> Hello David,
>> 
>> In your error message it says
>> 
>> undefined method `￯﾿ᄐ￯﾿ᄐ'
>> 
>> 
>> Why are you getting `￯﾿ᄐ￯﾿ᄐ' instead of 'setFrameOrigin'?
>> Do you have some foreign encoded text somewhere?
>> 
>> Min Soo Kim
>> 
>> 
>> On Dec 10, 2012, at 1:41 AM, david kramf wrote:
>> 
>> Hello,
>> I am trying to create an NSPoint object so I can call setFrameOrigin but I
>> get in response a CGPoint object . When I pass the CGPoint to setFrameOrigin
>> , it crashes. How do I make NSMakePoint making an NSPoint object and not a
>> CGPoint object.
>> Thank you for  your help,
>> David Kramf
>> 
>> def  initLabel(h)
>>@label = NSTextField.alloc.initWithFrame(CGRectMake(0,0,250, 45))
>>@label.setStringValue(h)
>>@label.drawsBackground = false
>>@label.bezeled = false
>>@label.font = NSFont.fontWithName("Arial", size:45.0)
>>@label.editable = false
>>puts "class of label is #{@label.class}"
>>width =
>> (@window.contentView.frameSize.width/2.0)-(@label.frameSize.width/2.0)
>>height =
>> (@window.contentView.frameSize.height/2.0)-(@label.frameSize.height/2.0)
>>puts "width is #{width} heght is #{height}"
>>origin = NSMakePoint(width,height)
>>puts "class of origin is #{origin.class}"
>>@label.setFrameOrigin(origin)
>>end
>> 
>> class of label is NSTextField
>> width is 75.0 heght is 77.5
>> class of origin is CGPoint
>> 2012-12-09 18:33:13.525 two[3836:503]
>> /Users/davidkramf/Library/Developer/Xcode/DerivedData/two-gdovgltwrnzjfbfpizcbgrudvizf/Build/Products/Debug/two.app/Contents/Resources/MyController.rb:34:in
>> `initLabel': undefined method `￯﾿ᄐ￯﾿ᄐ' for
>> # (NoMethodError)
>> from
>> /Users/davidkramf/Library/Developer/Xcode/DerivedData/two-gdovgltwrnzjfbfpizcbgrudvizf/Build/Products/Debug/two.app/Contents/Resources/MyController.rb:15:in
>> `initializ

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

2012-12-10 Thread david kramf
Hi Jean-Denis
1. Thank you for your advice about awakeFromNib and InitWithCoder.
2. "That is a bonus you ..". This is not a bonus. This is Ruby. If you define a 
Ruby class you expect that any object will get instantiated through 
"initialize". I have a feeling that all who responded to me on the forum 
started their programming track from Objective-C and proceeded to Ruby. I am 
coming from the opposite direction. I come from Ruby and wants to deal with 
Objective-C as little as possible. So I expect MacRuby to be as much "Ruby" as 
it is possible.
Many Thanks, David
On Dec 10, 2012, at 11:27 AM, Jean-Denis MUYS wrote:

> 
> On 7 déc. 2012, at 19:48:39, david kramf 
> wrote:
>> 
>> Message: 1
>> Date: Fri, 7 Dec 2012 19:48:39 +0200
>> From: david kramf 
>> To: "MacRuby development discussions."
>>  
>> Subject: Re: [MacRuby-devel] Problem with a window controller
>> Message-ID: <[email protected]>
>> Content-Type: text/plain; charset="us-ascii"
>> 
>> Hi Bob,
>> "As you become more familiar with IB, you will probably do more 
>> initialization of objects in IB and less in MacRuby. Nib file expansion 
>> instantiates objects and then makes calls to initialize the objects using 
>> the same methods that you are using to initialize objects in MacRuby. 
>> Actually, in a large application, it would difficult to hook up all of the 
>> outlets without using IB."
>> 
>> From my modest acquaintance with MacRuby that is not exactly the case since 
>> when the NIB instantiates  an NSWindowController object , it does not call 
>> "initialize"
> 
> Cocoa, whether accessed from Ruby, Python, Objective-C or any language, uses 
> the Cocoa initialization patterns. It's unrealistic to assume the framework 
> patterns to change when you change the client language.
> 
>> ,as defined in Ruby , but calls "awakeFromNib".
> 
> It does, but caveat: awakeFromNib is *not* an initialization method, even 
> though it is often used as such. I was bitten before. The correct 
> initialization method to use for Nib files is initWithCoder:. What's the 
> difference, says you (and me)? Behold:  awakeFromNib can be called several 
> times in the lifetime of an object. This is no big deals for most 
> initializations, but becomes a major issue in others. In my case, I was 
> registering for notifications in awakeFromNib. Since I was registered several 
> times, I got the notifications multiple times, and since I only unsubscribed 
> once in dealloc, my app would crash.
> 
> Many cases when awakeFromNib is called more than once are programming errors, 
> but not all. And since there *is* a real initializer, I recommend using it.
> 
> So in that case why is there an awakeFromNib method at all? It is because at 
> initWithCoder: time, IB outlets are not yet loaded and are all nil. So 
> awakeFromNib is meant to for initialization code that configures outlet.
> 
> So here is a recipe:
> 
> 1- Does you initialization code requires IB outlets to be alive? If not, 
> override initWithCoder:
> 2- If so, put it in awakeFromNib
> 3- Does that awakeFromNib initialization code need to be called once only? if 
> so, make it conditional on it having been already be called.
> 4- Optional: assert that awakeFromNib was not called before, and if that 
> assert fires, investigate whether the case is legitimate or due to a bug in 
> your code.
> 
>> Only when you instantiate your controller from the code itself , you get 
>> your "initialize"method called.  
> 
> That is a bonus you just can be happy to have due to the deep integration of 
> MacRuby in the Objective-C runtime system. There is no reason to assume that 
> bonus to expand to objects created by the framework.
> 
>> I know I still have a lot of practicing on IB. What I find disturbing ,is 
>> that when I do something  with IB I cannot see the code created to 
>> accommodate my actions ( maybe because I only work in MacRuby and not 
>> Objective-C?).
> 
> No. This is simply because there **no code created**. At all. IB does't 
> generate code. And lest I forget: Interface Builder is not a code generation 
> tool. IB instantiates and populates objects, and then serializes them to 
> disk. Those objects are then simply deserialized from disk in your app. At no 
> point ever is any code generated. Therefore, there is no "code created to 
> accommodate your actions" for you to see. Even in Objective-C.
> 
> Best regards,
> 
> Jean-Denis
> 
> ___
> 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