problem with selectColor

  1. last year

    Hello,

    64-bit, Xojo 18r4, Mojave 10.14.2

    I notice that after executing the code below, and dismissing the Color window either clicking Cancel or OK, next time I run the debugger the Color window keeps popping up.

    //action event of a pushButton
    dim c as color = color.red
    if selectColor(c,"") then
    end if

    I cleared Xojo cache, trashed the preferences file of the app, restarted Xojo. Yet, when I run that app in the debugger, the Color window is there to greet me.
    To be precise: the Color window shows without its Cancel and OK buttons.
    I recall this happened also when launching the built apps (yep, I have a couple of projects showing this behavior).

    Unfortunately I cannot reproduce this behavior in a fresh project.
    Suggestions appreciated. Thanks.

  2. Thomas O

    is not verified 22 Feb 2019 Germany, not far from Cologne

    Is this solved?

  3. 2 months ago

    Daniel T

    Jan 22 Pre-Release Testers, Xojo Pro
    Edited 2 months ago

    Searched the forums and found this. I've got the exact same problem now in a project I need to build soon. Adding one call to SelectColor in one location has resulted in the color picker appearing at launch in both the debugger and in compiled macOS apps. This happens even if I remove the line of code that calls SelectColor. I've also found that the color picker opens before the App.Open event fires.

    I've tried changing the properties of the window which calls it (implicit; not implicit; visible/invisible; etc) to no effect. I'm at a loss as to what to try next or why this would ever happen.

  4. Norman P

    Jan 22 Pre-Release Testers, Xojo Pro outside enjoying the fresh air
    Edited 2 months ago

    Thank Apple
    There was another thread about this - let me see if I can find it

    edit : https://forum.xojo.com/56285-catalina-color-panel

  5. Daniel T

    Jan 22 Pre-Release Testers, Xojo Pro

    Would love to read the other thread if you find it. After 20m of frustration I make my post...try toggling Visible again...and the problem disappears (for now?).

    Is it a state problem on a particular machine? In other words if I had copied the binary to another Mac, or restarted my Mac, and launched the binary would it have been fine?

  6. Norman P

    Jan 22 Pre-Release Testers, Xojo Pro outside enjoying the fresh air

    there is / was some decalre you could call to close the system async color selector window
    basically thats what is hanging around and apple records that it is / was open in your app's plist when it quits and the plist is finally synced
    then when you open there it is

    or you can switch to using the MBS one and it doesnt do this

  7. Daniel T

    Jan 22 Pre-Release Testers, Xojo Pro

    Thank you!

  8. Edited 2 months ago

    In the closeCancel event handler of each window calling selectcolor I call the following code (thanks to Sam!):
    BTW: I use NSColorWell (macOSLib 64bit) to show the selectcolor pane.

    Public Sub closeNSColorPanel()
      #if TargetMacOS then
        declare function NSClassFromString lib "AppKit" ( className as CFStringRef ) as ptr
        declare function sharedColorPanel lib "AppKit" selector "sharedColorPanel" ( classRef as Ptr ) as Ptr
        declare sub close lib "AppKit" selector "close" ( panel as Ptr )
        close( sharedColorPanel( NSClassFromString( "NSColorPanel" ) ) ) 
      #endif
    End Sub
  9. Daniel T

    Jan 23 Pre-Release Testers, Xojo Pro

    Thank you Carlo!

  10. @Daniel Taylor, @Carlo Rubini — I think you should use sharedColorPanelExists, which checks whether the color panel exists without creating one. Calling sharedColorPanel creates one if it doesn't already exist.

    Public Sub closeNSColorPanel()
      #if TargetMacOS then
        declare function NSClassFromString lib "AppKit" ( className as CFStringRef ) as ptr
        declare function sharedColorPanel lib "AppKit" selector "sharedColorPanel" ( classRef as Ptr ) as Ptr
        declare sub close lib "AppKit" selector "close" ( panel as Ptr )
        declare function sharedColorPanelExists lib "AppKit" ( classRef as Ptr ) as Boolean
    
        if sharedColorPanelExists then
            close( sharedColorPanel( NSClassFromString( "NSColorPanel" ) ) )
        end if
      #endif
    End Sub
  11. @Daniel Taylor

    Thank you Carlo!

    That is, thank you @Sam R for the original snippet and thank you @Stéphane ;Mons for the update.

  12. @Stéphane Mons: running your suggested code, I get a "Not enough arguments: missing Ptr value for parameter "Class Ref" warning/error at:

    if sharedColorPanelExists then//<<<< here

    Any suggestion how to fix it?

    Thanks

  13. 8 weeks ago

    Daniel T

    Feb 3 Pre-Release Testers, Xojo Pro

    @Carlo R @Stéphane Mons: running your suggested code, I get a "Not enough arguments: missing Ptr value for parameter "Class Ref" warning/error at:

    if sharedColorPanelExists then//<<<< here

    Any suggestion how to fix it?

    I would assume NSClassFromString( "NSColorPanel" ) would return the proper pointer value for sharedColorPanelExists. But when I try it I actually get a linker error and compilation cannot complete.

    Carlo's original code seems to be working for me even if it unnecessarily creates and then closes a color panel.

or Sign Up to reply!