#PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Just starting out? Need help? Post your questions and find answers here.
User avatar
DannyWeijermans
User
User
Posts: 26
Joined: Thu Aug 25, 2022 10:10 pm
Contact:

#PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by DannyWeijermans »

Dear all,
I'd like to use the PB_ProgressBar_Unknown feature
in the StatusBarProgress.
Anyone knows if or how this would be possible?
I'm in OSX..
Thanks for any thoughts!
Merry belated xmas!!
Peace in 2025!
Danny
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by infratec »

As written in the help:

Code: Select all

SetGadgetState(YourProgressbarGadget, #PB_ProgressBar_Unknown)
But I don't know hat happens then. :wink:
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by infratec »

Hi, hi, in windows a small bar 'rotates'.
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by Wolfram »

You should see an animated gradient.

Code: Select all

Global Window_0, pgBar


Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 80)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  pgBar = ProgressBarGadget(#PB_Any, 50, 20, width -100, 15, 0, 99)
  SetGadgetState(pgBar, #PB_ProgressBar_Unknown)
  
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
      
    Case #PB_Event_Menu
      Select EventMenu()
        Case #PB_Menu_Quit
          ProcedureReturn #False
          
      EndSelect
      
    Case #PB_Event_Gadget
      
      
  EndSelect

ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False
macOS Catalina 10.15.7
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!
Thanks for all answers!

Yes, but it's different (it seems) for the ProgressBar in the Status Gadget
when I test it on this.
(StatusBarProgress(\MyStatusBar, #StatusBarProgress, #PB_ProgressBar_Unknown)
it doesn't work..

Any thoughts on this?
Regards!
Danny
BarryG
Addict
Addict
Posts: 4127
Joined: Thu Apr 18, 2019 8:17 am

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by BarryG »

Wait a minute... I knew I recognized your name, Danny! :) Great to see you're a PureBasic user!
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: #PB_ProgressBar_Unknown SetGadgetState() in StatusBarProgress

Post by infratec »

In this case is nowhere written in the help that you can use #PB_ProgressBar_Unknown.
So in general you can't use 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 »

true intratec,
but would be really nice ;)
and I guess it should be possible..
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: Sat Dec 28, 2024 12:15 am and I guess it should be possible..
Yes, it's possible. But it's a feature request for "Feature Requests and Wishlists". The following example demonstrates how to display an indeterminated ProgressBar (like a ProgressBarGadget with the flag #PB_ProgressBar_Unknown) in the StatusBar (tested successfully on MacOS 13.7.2 'Ventura' with PB 6.20 Beta 2):

Code: Select all

EnableExplicit

Define Frame.NSRect
Define ProgressBar.I
Define StatusBar.I

OpenWindow(0, 100, 270, 280, 60, "StatusBar with ProgressBar")
TextGadget(0, 10, 10, WindowWidth(0) - 20, 20,
  "StatusBar with indeterminated ProgressBar")

; ----- Create horizontal ProgressBar

Frame\origin\x = 10
Frame\origin\y = 5
Frame\size\width = WindowWidth(0) - 20
Frame\size\height = 20
ProgressBar = CocoaMessage(0,
  CocoaMessage(0, 0, "NSProgressIndicator alloc"), "initWithFrame:@", @Frame)
CocoaMessage(0, ProgressBar, "setIndeterminate:", #YES)
CocoaMessage(0, ProgressBar, "startAnimation:", 0)

; ----- Create StatusBar

CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
StatusBar = StatusBarID(0)

; ----- Add ProgressBar to StatusBar

CocoaMessage(0, StatusBar, "addSubview:", ProgressBar)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
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 »

The following example demonstrates how to display an indeterminated StatusBarProgress field (tested successfully on MacOS 15.2 'Sequoia' with PB 6.12 and 6.20 Beta 2):

Code: Select all

EnableExplicit

Define i.I
Define ProgressBarField.I
Define StatusBarField.I
Define SubViewArray.I
Define SubViewCount.I

OpenWindow(0, 270, 100, 300, 70, "StatusBarField with ProgressBar")

; ----- 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
Until WaitWindowEvent() = #PB_Event_CloseWindow
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 »

W O W !
That's SO awesome, Shardik!!!
Thanks so much (again!!)
Works like a charm,
and good that it's in the wish list:
would be good to have as a 'standard' option ;)

Regards,
and I wish you and all fellow PureBasic coders
a GOOD 2025
with GOOD HEALTH & PEACE !
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 »

The following example is cross-platform. I have tested it succussfully with PB 6.12 on these operating systems:
  • Linux Mint 21.3 'Virginia' with Cinnamon and Gtk3
  • MacOS 13.7.2 'Ventura'
  • Windows 10 23H2

Code: Select all

EnableExplicit

#StatusBarText = "  StatusBar with ProgressBar:"

Define ProgressBarField.I

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    ImportC ""
      g_object_set_double(*Object, Property.P-ASCII, Value.D,
        Null) As "g_object_set"
    EndImport

    Procedure GetStatusBarProgressField(StatusBarID.I)
      Shared ProgressBarField.I

      Protected ChildCount.I
      Protected *ChildListGtkFrame.GList
      Protected *ChildListGtkBox.GList
      Protected *GtkBox.GtkWidget
      Protected *GtkFrame.GtkWidget
      Protected i.I
      Protected *Widget.GtkWidget
      Protected *WidgetName

      *GtkBox = StatusBarID(StatusBarID)
      *ChildListGtkBox = gtk_container_get_children_(*GtkBox)
      *WidgetName = gtk_widget_get_name_(*GtkBox)
      ChildCount = g_list_length_(*ChildListGtkBox)

      For i = 0 To ChildCount - 1
        *GtkFrame = g_list_nth_data_(*ChildListGtkBox, i)
        *ChildListGtkFrame = gtk_container_get_children_(*GtkFrame)
        *Widget = g_list_nth_data_(*ChildListGtkFrame, 0)
        *WidgetName = gtk_widget_get_name_(*Widget)
        g_list_free_(*ChildListGtkFrame)

        If PeekS(*WidgetName, -1, #PB_UTF8) = "GtkProgressBar"
          ProgressBarField = *Widget
          g_object_set_double(ProgressBarField, "pulse-step", 0.2, 0)
          AddWindowTimer(0, 0, 400)
          Break
        EndIf
      Next i

      g_list_free_(*ChildListGtkBox)
    EndProcedure
  CompilerCase #PB_OS_MacOS
    Procedure GetStatusBarProgressField(StatusBarID.I)
      Shared ProgressBarField.I

      Protected i.I
      Protected StatusBarField.I
      Protected SubViewArray.I
      Protected SubViewCount.I
      
      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
              CocoaMessage(0, ProgressBarField, "setIndeterminate:", #YES)
              CocoaMessage(0, ProgressBarField, "startAnimation:", 0)
              Break
            EndIf
          Next i
        EndIf
      EndIf
    EndProcedure
  CompilerCase #PB_OS_Windows
    #PBM_SETMARQUEE = #WM_USER + 10

    Procedure EnumChildWindowCallback(WindowHandle.I, LParam.I)
      Shared ProgressBarField.I
      
      Protected ClassName.S = Space(#MAX_PATH)
      
      GetClassName_(WindowHandle, @ClassName, #MAX_PATH - 1)
      
      If ClassName = "msctls_progress32"
        ProgressBarField = WindowHandle
        ProcedureReturn #False
      Else
        ProcedureReturn #True
      EndIf
    EndProcedure
    
    Procedure GetStatusBarProgressField(StatusBarID.I)
      Shared ProgressBarField.I

      EnumChildWindows_(StatusBarID(StatusBarID), @EnumChildWindowCallback(),
        0)

      If ProgressBarField
        SetWindowLongPtr_(ProgressBarField, #GWL_STYLE,
          GetWindowLongPtr_(ProgressBarField, #GWL_STYLE) ! #PBS_MARQUEE)
        SendMessage_(ProgressBarField, #PBM_SETMARQUEE, 1, 50)
      EndIf
    EndProcedure
CompilerEndSelect

OpenWindow(0, 270, 100, 360, 70,
  "StatusBar with #PB_ProgressBar_Unknown")

; ----- Create StatusBar and StatusBarFields

CreateStatusBar(0, WindowID(0))
AddStatusBarField(180)
StatusBarText(0, 0, #StatusBarText)
AddStatusBarField(WindowWidth(0) - 190)
StatusBarProgress(0, 1, 20, 0, 0, 100)

; ----- Get StatusBarField containing ProgressBar

GetStatusBarProgressField(0)

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

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    CompilerIf #PB_Compiler_OS = #PB_OS_Linux
      Case #PB_Event_Timer
        gtk_progress_bar_pulse_(ProgressBarField)
    CompilerEndIf
  EndSelect
ForEver
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: Sat Dec 28, 2024 10:34 pm W O W !
That's SO awesome, Shardik!!!
Thanks so much (again!!)
Works like a charm
I am glad that it works for you like a charm!
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!
1 more question about it:
how to set it in Determinate mode again?
I tried it with

Code: Select all

CocoaMessage(0, ProgressBarField, "setIndeterminate:", #NO) ; ----- UnSet ProgressBarField to indeterminate
    CocoaMessage(0, ProgressBarField, "stopAnimation:", 0)
but the ProgressBarfield then takes a while before showing the determinate position.
And how to set it in Indeterminate mode again after that?
(when I do that the ProgressBarField stays greyed out)
Thanks for any more help!
Regards,
Danny
Post Reply