Dual Status in SysTray

Share your advanced PureBasic knowledge/code with the community.
jamirokwai
Enthusiast
Enthusiast
Posts: 798
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Dual Status in SysTray

Post by jamirokwai »

Hi there,

while developing my DropMeFTP further, I added the following ProgressBar to the SysTray...
Feel free to use. I think, this will only work on Mac OS X, as the SysTray-Icon is 54x22 Pixels.

edit: Thanks, guys. Seems to work on Windows and Linux, too.

Code: Select all

Global menuletimage
Global systray

Procedure Draw_On_Menulet(top.f,topsize.f,bottom.f,bottomsize.f)
  If StartDrawing(ImageOutput(menuletimage))
    DrawingMode(#PB_2DDrawing_AllChannels)
    Box(0, 0,ImageWidth(menuletimage),ImageHeight(menuletimage),RGBA(0,0,0,0))
    Box(2, 4,ImageWidth(menuletimage) - 4,6,RGBA(0,96,0,255))
    Box(2,13,ImageWidth(menuletimage) - 4,6,RGBA(0,0,96,255))
    Box(2, 4,top / topsize * (ImageWidth(menuletimage) - 4),6,RGBA(0,192,0,255))
    Box(2,13,bottom / bottomsize * (ImageWidth(menuletimage) - 4),6,RGBA(0,0,192,255))
    StopDrawing()
  EndIf
  ChangeSysTrayIcon(systray,ImageID(menuletimage))
  SysTrayIconToolTip(systray, "Current file: " + Str(top) + " of " + Str(topsize) + #CR$ + "All files: " + Str(bottom) + " of " + Str(bottomsize))
EndProcedure

Procedure Create_Menulet_Bar(win,width,height)
  menuletimage = CreateImage(#PB_Any, width + 4, height, 32)
  If StartDrawing(ImageOutput(menuletimage))
    DrawingMode(#PB_2DDrawing_AllChannels)
    Box(0,0,width + 4,height,RGBA(0,0,0,0))
    StopDrawing()
  EndIf
  If Not IsSysTrayIcon(Systray)
    Systray = AddSysTrayIcon(#PB_Any, WindowID(win), ImageID(menuletimage))
  EndIf
EndProcedure

OpenWindow(0,100,100,100,100,"test")
Create_Menulet_Bar(0,50,22)   ; create a Menulet for the Window 0 with Size width x height, e.g. 50,22
i = 0
j = 0
Repeat
  j + Random(5)
  If j >= 50
    i + 5
    j = 0
  EndIf  

  ; Draw and update the Menulet with j (top) and i (bottom), 50 is for setting the maximum width
  ; you may also insert 1234567 bytes of 987654 bytes. Try it
  Draw_On_Menulet(j,50,i,50)
  While WaitWindowEvent(10) : Wend
  Delay(10)
Until i = 50
Last edited by jamirokwai on Thu Nov 03, 2011 7:55 am, edited 1 time in total.
Regards,
JamiroKwai
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Dual Status in SysTray - Mac only?

Post by Polo »

Nice!

On MacOSX however, it would look better if you were actually displaying these progress bars directly on your dock icon.
Not sure how to do that, but some apps do it and it's quite good :)
jamirokwai
Enthusiast
Enthusiast
Posts: 798
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Dual Status in SysTray - Mac only?

Post by jamirokwai »

Polo wrote:Nice!

On MacOSX however, it would look better if you were actually displaying these progress bars directly on your dock icon.
Not sure how to do that, but some apps do it and it's quite good :)
Yeah,

but on my Air, the Dock is always hidden. Hence, I wouldn't see the tiny bar...
Maybe I will go, and try to add dock-bars in another release :-)
Regards,
JamiroKwai
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Dual Status in SysTray - Mac only?

Post by em_uk »

Works fine on Win7 x64.
----

R Tape loading error, 0:1
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Dual Status in SysTray - Mac only?

Post by Kwai chang caine »

Works fine on XP SP3
Thanks for sharing
ImageThe happiness is a road...
Not a destination
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Dual Status in SysTray - Mac only?

Post by idle »

works fine ubuntu nice :mrgreen:
Windows 11, Manjaro, Raspberry Pi OS
Image
Post Reply