|
From: Yvon T. <tho...@fr...> - 2006-02-21 18:12:04
|
in my gui i've a lot of NSButtons i've arranged theme into an Array :
@buttons = [@nonVideButtonGauche, @uniqueButtonGauche,
@fusionButtonGauche, @loadButtonGauche, @nonVideButtonDroite,
@uniqueButtonDroite, @fusionButtonDroite, @loadButtonDroite]
if i do (by the end of awakeFromNib) :
def enableAllButtons
@buttons.each { |b| p b.class.to_s}
end
i get "NilClass" for each NSButton
however doing :
def enableAllButtons
p "@nonVideButtonGauche " + @nonVideButtonGauche.class.to_s
p "@uniqueButtonGauche " + @uniqueButtonGauche.class.to_s
p "@fusionButtonGauche " + @fusionButtonGauche.class.to_s
p "@loadButtonGauche " + @loadButtonGauche.class.to_s
p "@nonVideButtonDroite " + @nonVideButtonDroite.class.to_s
p "@uniqueButtonDroite " + @uniqueButtonDroite.class.to_s
p "@fusionButtonDroite " + @fusionButtonDroite.class.to_s
p "@loadButtonDroite " + @loadButtonDroite.class.to_s
end
i get the right "OSX::NSButton" for all the buttons :
"@nonVideButtonGauche OSX::NSButton"
"@uniqueButtonGauche OSX::NSButton"
"@fusionButtonGauche OSX::NSButton"
"@loadButtonGauche OSX::NSButton"
"@nonVideButtonDroite OSX::NSButton"
"@uniqueButtonDroite OSX::NSButton"
"@fusionButtonDroite OSX::NSButton"
"@loadButtonDroite OSX::NSButton"
does that means we have also to use a proxy class ?
Yvon |
|
From: Jonathan P. <jp...@dc...> - 2006-02-21 23:49:56
|
On 21 Feb 2006, at 18:10, Yvon Thoraval wrote: > @buttons = [@nonVideButtonGauche, @uniqueButtonGauche, > @fusionButtonGauche, @loadButtonGauche, @nonVideButtonDroite, > @uniqueButtonDroite, @fusionButtonDroite, @loadButtonDroite] When do you execute this line? You should do it inside awakeFromNib, since before that method is called the buttons will not be set from Interface Builder. i.e., you must make the array assignment in awakeFromNib |
|
From: Yvon T. <tho...@fr...> - 2006-02-22 06:44:52
|
Le 22 f=E9vr. 06 =E0 00:49, Jonathan Paisley a =E9crit :
> i.e., you must make the array assignment in awakeFromNib
that's ok now, however when i do ;
@buttons.each { |b| b.setEnabled false}
the appearance of the buttons doesn't change, i've seen an appearance =20=
change only in awakeFromNib (in Interface Buider i did set all the =20
the buttons to enabled false)
because i want to disable the buttons when a long time action.
best,
Yvon=
|
|
From: Jonathan P. <jp...@dc...> - 2006-02-22 10:37:53
|
On 22 Feb 2006, at 6:43, Yvon Thoraval wrote:
> Le 22 f=E9vr. 06 =E0 00:49, Jonathan Paisley a =E9crit :
>
>> i.e., you must make the array assignment in awakeFromNib
>
> that's ok now, however when i do ;
>
> @buttons.each { |b| b.setEnabled false}
>
> the appearance of the buttons doesn't change, i've seen an =20
> appearance change only in awakeFromNib (in Interface Buider i did =20
> set all the the buttons to enabled false)
>
> because i want to disable the buttons when a long time action.
I'm afraid I'm not sure what's going on here. More complete code =20
would be helpful to understand how things are put together.
Cheers,
Jonathan
|
|
From: Yvon T. <tho...@fr...> - 2006-02-22 10:59:51
|
Le 22 f=E9vr. 06 =E0 11:37, Jonathan Paisley a =E9crit :
>
> I'm afraid I'm not sure what's going on here. More complete code =20
> would be helpful to understand how things are put together.
>
ok, in Interface Builder all the NSButtons enabled ckeckboxes are set =20=
to false.
then in Controller.rb i do :
def awakeFromNib
loadXmlGauche("safari.xml", "BookmarksBar")
loadXmlDroite("firefox.xml", "Barre personnelle")
@xmlGauche=3D"safari.xml"
@xmlDroite=3D"firefox.xml"
@labelGauche.setStringValue "Safari"
@labelDroite.setStringValue "Firefox"
@buttons =3D [@nonVideButtonGauche, @uniqueButtonGauche, =20
@fusionButtonGauche, @loadButtonGauche, @nonVideButtonDroite, =20
@uniqueButtonDroite, @fusionButtonDroite, @loadButtonDroite]
enableAllButtons ####### here i enable all =20
buttons
end
=09
def windowDidBecomeMain(sender)
p "windowDidBecomeMain(sender)"
end
def enableAllButtons
#@nonVideButtonGauche.setHidden true
#@nonVideButtonGauche.setNeedsDisplay true
@buttons.each { |b| b.setEnabled(true)}
end
def disableAllButtons
#@nonVideButtonGauche.setNeedsDisplay true
@buttons.each { |b| b.setEnabled(false)}
end
after awakeFromNib all the NSButtons are enabled, that' right.
when someone press one of the buttons, saying =20
"Load" (@loadButtonDroite) i do :
def loadDroite(sender)
disableAllButtons ####### here i disable all =20=
buttons
loadXmlDroite("firefox.xml", "Barre personnelle")
@xmlDroite=3D"firefox.xml"
@labelDroite.setStringValue "Firefox"
enableAllButtons ####### here i re-enable =20
all buttons
end
i do the "same" (isableAllButtons [...] enableAllButtons) for all the =20=
actions corresponding to all the buttons.
the appearance of the buttons doesn't change and also if, when an =20
action isn't terminated (that's to say between disableAllButtons and =20
enableAllButtons) the click is memorized and, when the action is =20
finished the process enters a new action corresponding to the new =20
button pressed.
if, in between disableAllButtons and enableAllButtons, i press two =20
times a button and another one afterwards, all the click on all the =20
different buttons and the corresponding actions are undertaken each =20
after each...
i'd like to avoid that : no memorization when an action is undertaken.
best,
Yvon=
|
|
From: Jonathan P. <jp...@dc...> - 2006-02-22 11:17:37
|
On 22 Feb 2006, at 10:58, Yvon Thoraval wrote: > the appearance of the buttons doesn't change and also if, when an > action isn't terminated (that's to say between disableAllButtons > and enableAllButtons) the click is memorized and, when the action > is finished the process enters a new action corresponding to the > new button pressed. > > if, in between disableAllButtons and enableAllButtons, i press two > times a button and another one afterwards, all the click on all the > different buttons and the corresponding actions are undertaken each > after each... > > i'd like to avoid that : no memorization when an action is undertaken. > I think the problem is that the visible 'disabled' state only updates when the event loop runs again. During your long-running method, the Cocoa event loop never gets a chance to run. Therefore, any clicks are queued and get processed later -- by which point the buttons have been enabled again. You could try disabling the buttons, explicitly redrawing them by calling 'display'. You could clear any button clicks from the event queue with 'discardEventsMatchingMask:beforeEvent:'. |
|
From: Yvon T. <tho...@fr...> - 2006-02-22 12:20:16
|
Le 22 f=E9vr. 06 =E0 12:17, Jonathan Paisley a =E9crit :
> I think the problem is that the visible 'disabled' state only =20
> updates when the event loop runs again. During your long-running =20
> method, the Cocoa event loop never gets a chance to run. Therefore, =20=
> any clicks are queued and get processed later -- by which point the =20=
> buttons have been enabled again.
>
ok, i understand.
> You could try disabling the buttons, explicitly redrawing them by =20
> calling 'display'. You could clear any button clicks from the event =20=
> queue with 'discardEventsMatchingMask:beforeEvent:'.
>
display (eventually after a "setNeedsDisplay true" ) doesn't change =20
anything :
def disableAllButtons
@buttons.each { |b|
b.setEnabled(false)
#b.setNeedsDisplay true
b.display
}
sleep 1
end
sleep 1 doesn't help too
with #display i get only that in the XCode's Run log :
[Session started at 2006-02-22 13:13:49 +0100.]
<NSButton: 0x69d0f0><NSButton: 0x4b3210><NSButton: =20
0x4bba30><NSButton: 0x6dfc70><NSButton: 0x689400><NSButton: =20
0x4b47a0><NSButton: 0x6899e0><NSButton: 0x6e5080>
BookmarksMerge has exited with status 0.
may be one drastic solution coud be using #setHidden true gaves no =20
change too...
then i went to "discardEventsMatchingMask:beforeEvent:" and applied =20
to a NSWindow as a receiver :
@mainWindow.discardEventsMatchingMask_beforeEvent=20
(OSX::NSAnyEventMask, OSX::NSKeyUpMask)
here i got this error in the XCode's Run log :
[Session started at 2006-02-22 13:13:18 +0100.]
2006-02-22 13:13:24.417 BookmarksMerge[22686] *** -[NSDecimalNumber =20
_cgsEventTime]: selector not recognized [self =3D 0x4bb0af0]
/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/=20=
objc/oc_wrapper.rb:17:in `NSApplicationMain': NSApplicationMain - =20
NSInvalidArgumentException - *** -[NSDecimalNumber _cgsEventTime]: =20
selector not recognized [self =3D 0x4bb0af0] (OSX::OCException)
from =
/Users/yvon/work/RubyCocoa/BookmarksMerge/build/Development/=20
BookmarksMerge.app/Contents/Resources/rb_main.rb:46
BookmarksMerge has exited with status 1.
i've followed what's written in the Cocoa browser...
?
Yvon
|
|
From: Jonathan P. <jp...@dc...> - 2006-02-22 12:52:36
|
> with #display i get only that in the XCode's Run log : > > [Session started at 2006-02-22 13:13:49 +0100.] > <NSButton: 0x69d0f0><NSButton: 0x4b3210><NSButton: > 0x4bba30><NSButton: 0x6dfc70><NSButton: 0x689400><NSButton: > 0x4b47a0><NSButton: 0x6899e0><NSButton: 0x6e5080> > BookmarksMerge has exited with status 0. Hehe - it's calling the ruby method 'display'. Try 'oc_display' instead. This bypasses any ruby methods defined. > then i went to "discardEventsMatchingMask:beforeEvent:" and applied > to a NSWindow as a receiver : > > @mainWindow.discardEventsMatchingMask_beforeEvent > (OSX::NSAnyEventMask, OSX::NSKeyUpMask) Ah, I realise now that discartEvents... won't work here. Instead look at "- (NSEvent *)nextEventMatchingMask:(unsigned int) mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue: (BOOL)flag" and call it repeatedly with dequeue:YES and try different values for untilDate: NSDate.date, NSDate.distantFuture or NSData.distantPast. Stop calling it when it returns no events. |
|
From: Yvon T. <tho...@fr...> - 2006-02-22 13:16:45
|
Le 22 f=E9vr. 06 =E0 13:52, Jonathan Paisley a =E9crit : > > Hehe - it's calling the ruby method 'display'. Try 'oc_display' =20 > instead. This bypasses any ruby methods defined. #oc_display works fine. however, something surprising to me is when a button is disabled, it =20 still memorizes click on it, only the view is changing. that's Cocoa design :[ (i never had such behaviour with Java-Swing...) > >> then i went to "discardEventsMatchingMask:beforeEvent:" and =20 >> applied to a NSWindow as a receiver : >> >> @mainWindow.discardEventsMatchingMask_beforeEvent=20 >> (OSX::NSAnyEventMask, OSX::NSKeyUpMask) > > Ah, I realise now that discartEvents... won't work here. > > Instead look at "- (NSEvent *)nextEventMatchingMask:(unsigned int)=20 > mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:=20= > (BOOL)flag" and call it repeatedly with dequeue:YES and try =20 > different values for untilDate: NSDate.date, NSDate.distantFuture =20 > or NSData.distantPast. Stop calling it when it returns no events. > ok, i need to investigate further on that point. Yvon |
|
From: kimura wataru<ki...@us...> - 2006-02-22 13:02:55
|
Hi,
I think it is an easy way to use thread. But we have a bug report
ruby's thread on RubyCocoa sometimes crashes.
def loadDroite(sender)
disableAllButtons ####### here i disable all buttons
Thread.new {
loadXmlDroite("firefox.xml", "Barre personnelle")
@xmlDroite="firefox.xml"
@labelDroite.setStringValue "Firefox"
enableAllButtons ####### here i re-enable all buttons
}
end
Wed, Feb 22, 2006 11:58:41 AM, Yvon Thoraval wrote:
> def loadDroite(sender)
> disableAllButtons ####### here i disable all
>buttons
> loadXmlDroite("firefox.xml", "Barre personnelle")
> @xmlDroite="firefox.xml"
> @labelDroite.setStringValue "Firefox"
> enableAllButtons ####### here i re-enable
>all buttons
> end
>
>i do the "same" (isableAllButtons [...] enableAllButtons) for all the
>actions corresponding to all the buttons.
>
--
kimura wataru
|
|
From: Yvon T. <tho...@fr...> - 2006-02-22 15:16:31
|
Le 22 f=E9vr. 06 =E0 14:02, kimura wataru a =E9crit : > I think it is an easy way to use thread. i've tried that, however this doesn't correspond to my needs, =20 because, with thread, we might launch asynchronously any action from =20 each other, which is not what i want. best, Yvon= |