#PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 4124
Joined: Thu Apr 18, 2019 8:17 am

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by BarryG »

DannyWeijermans wrote: Sat Dec 28, 2024 12:02 am Barry? Explain! ;)
I've seen your name online, outside of these forums. One example -> https://www.imdb.com/name/nm0917916/
User avatar
DannyWeijermans
User
User
Posts: 26
Joined: Thu Aug 25, 2022 10:10 pm
Contact:

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by DannyWeijermans »

Aha, that's great BarryG!
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by Shardik »

DannyWeijermans wrote: Sun Dec 29, 2024 12:57 am Hi Shardik!
1 more question about it:
how to set it in Determinate mode again?
I have extended my previous MacOS example with a toggle button. You are now able to switch between Indeterminate and Determinate state. You are also able to control the length of the not moving determinated bar by setting the new variable ProgressBarValue (0.0: tiny small bar at the beginning, 50.0: bar with half length, 100.0: bar with full length).

Code: Select all

EnableExplicit

Define i.I
Define ProgressBarField.I
Define ProgressBarValue.D = 0.0 ; 100.0 for full bar
Define StatusBarField.I
Define SubViewArray.I
Define SubViewCount.I

OpenWindow(0, 270, 100, 300, 70, "StatusBarField with ProgressBar")
ButtonGadget(0, 50, 15, 200, 25, "Disable indeterminate state")

; ----- Create StatusBar and StatusBarFields

CreateStatusBar(0, WindowID(0))
AddStatusBarField(188)
StatusBarText(0, 0, "  StatusBar with ProgressBar:")
AddStatusBarField(WindowWidth(0) - 200)
StatusBarProgress(0, 1, 50)

; ----- Get StatusBarField containing ProgressBar

SubViewArray = CocoaMessage(0, StatusBarID(0), "subviews")

If SubViewArray
  SubViewCount = CocoaMessage(0, SubViewArray, "count")
  
  If SubViewCount
    For i = 0 To SubViewCount - 1
      StatusBarField = CocoaMessage(0, SubViewArray, "objectAtIndex:", i)

      If PeekS(CocoaMessage(0, CocoaMessage(0, StatusBarField, "className"),
        "UTF8String"), -1, #PB_UTF8) = "NSProgressIndicator"
        ProgressBarField = StatusBarField
 
        ; ----- Set ProgressBarField to indeterminate

        CocoaMessage(0, ProgressBarField, "setIndeterminate:", #YES)
        CocoaMessage(0, ProgressBarField, "startAnimation:", 0)
        Break
      EndIf
    Next i
  EndIf
EndIf

If ProgressBarField = #False
  MessageRequester("Error",
    "No StatusBarField with ProgressBar found!")
  End
EndIf 

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If CocoaMessage(0, ProgressBarField, "isIndeterminate") = #YES
        ; ----- Set ProgressBarField status to determinate

        CocoaMessage(0, ProgressBarField, "setIndeterminate:", #NO)
        CocoaMessage(0, ProgressBarField, "setDoubleValue:@", @ProgressBarValue)
        SetGadgetText(0, "Enable indeterminate state")
      Else
        ; ----- Set ProgressBarField status to indeterminate

        CocoaMessage(0, ProgressBarField, "setIndeterminate:", #YES)
        CocoaMessage(0, ProgressBarField, "startAnimation:", #NO)
        SetGadgetText(0, "Disable indeterminate state")
      EndIf
  EndSelect
ForEver
Last edited by Shardik on Fri Jan 03, 2025 6:32 pm, edited 2 times in total.
User avatar
DannyWeijermans
User
User
Posts: 26
Joined: Thu Aug 25, 2022 10:10 pm
Contact:

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by DannyWeijermans »

Wow again!
Working great here on OSX Sequoia 15.2 using PureBasic 6.20 Beta 2 !
Thanks so much again, Shardik!
I love how it works now..
Regards!
Danny
User avatar
DannyWeijermans
User
User
Posts: 26
Joined: Thu Aug 25, 2022 10:10 pm
Contact:

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by DannyWeijermans »

Happy NewYear!
Still something strange in this, Shardik!
After the ProgressBarValue was set to a new number
and after the ProgressBarField was set to Determinate (setIndeterminate : #NO)
then when setting the ProgressBarField to Indeterminate again,
it shows a different animation (not a 'block' moving from left to right and back,
but the same 'block' it was only changing in brightness - growing lighter and darker and back again)
Any thoughts on this?
Sorry to disturb you again with it ;)
User avatar
DannyWeijermans
User
User
Posts: 26
Joined: Thu Aug 25, 2022 10:10 pm
Contact:

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by DannyWeijermans »

PS, I thought: maybe the StatusBarProgress PureBasic code is interfering then??
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by Shardik »

Danny,

do you have a small code example to reproduce the switching from a moving block to a block changing in brightness when switching back to indeterminate mode again? Does this problem also show in my last example?

In your code

Code: Select all

CocoaMessage(0, ProgressBarField, "setIndeterminate:", #NO) ; ----- UnSet ProgressBarField to indeterminate
    CocoaMessage(0, ProgressBarField, "stopAnimation:", 0)
your described problem also occurred. Try to don't use
"stopAnimation:", #No
but instead
"startAnimation:", #No
when switching back to indeterminate mode. That solved the problem with the brightness change for me when testing your code above!
User avatar
DannyWeijermans
User
User
Posts: 26
Joined: Thu Aug 25, 2022 10:10 pm
Contact:

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by DannyWeijermans »

Hi Shardik!
The problem doesn't occur in your code.

The 'blinking' instead of moving sideways
occurs even when I only change the ProgressBarValue

(only added the 'ProgressBarValue + 10' line in your code:)

Code: Select all

Case #PB_Event_Gadget
      If CocoaMessage(0, ProgressBarField, "isIndeterminate") = #YES
        ; ----- Set ProgressBarField status to determinate

        CocoaMessage(0, ProgressBarField, "setIndeterminate:", #NO)
        ProgressBarValue + 10
        CocoaMessage(0, ProgressBarField, "setDoubleValue:@", @ProgressBarValue)
        SetGadgetText(0, "Enable indeterminate state")
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by Shardik »

Danny,

thank you for your code snippet. I was able to reproduce the problem and found a solution. In my last example after

Code: Select all

        ProgressBarField = StatusBarField
you should add the following line

Code: Select all

        CocoaMessage(0, ProgressBarField, "setUsesThreadedAnimation:", #NO)

After the addition of this new line your described problem should be fixed although the indeterminate animation seems to be about twice as fast now. I have found out that the property "usesThreadedAnimation:" is #Yes by default and because we don't define a threaded procedure this seems to cause your described problem.
User avatar
DannyWeijermans
User
User
Posts: 26
Joined: Thu Aug 25, 2022 10:10 pm
Contact:

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by DannyWeijermans »

Great Shardik!
That's THE trick! ;)
Thanks for all!
Makes sense..
No problem about the speed:
I even like it more ;)
Regards & a big THUMBS UP!!
Danny Weijermans - The Netherlands

PS, great that it's still compatible with the 'regular' StatusBarProgress 'setter' :

Code: Select all

StatusBarProgress(0, 1, MyProgress)
Post Reply