Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Showing message on status bar (See related posts)

There's an empty space below app.title that we can
use as a status bar. So, I modify this recipe and
make it into a module. (need fgimage.pyd from here)
# status.py
from graphics import *
import fgimage
__all__ = ["status_on", "status_off"]

bar = Image.new((119,13))
bgcolor = screenshot().getpixel((0,0))[0]
fg = fgimage.FGImage()

def status_on(message=None):
    if message is not None:
        bar.clear(bgcolor)
        bar.text((0,11), unicode(message), 0xffffff)
    fg.set(57,30, bar._bitmapapi())

def status_off():
    fg.unset()

You can use it easily this way
>>> from status import *
>>> status_on('Hello world')  # show it
>>> status_off()              # hide it
>>>

See a screenshot.

Comments on this post

cyke64 posts on Mar 09, 2006 at 12:40
Korakot ,

This code doesn't work because pixel(0,0) is the wrong pixel !
You must take the pixel of the frame ie where you begin to draw fg !
I also remarked that bar init with white color (0xFFFFFF) ! If you begin with status_on()
init bar with bgcolor first.
Thus bgcolor is white and you draw text in white also ! You display anything !

Here's new version with complete example:

keep on the good work !

# status.py
from e32 import *
from graphics import *
import fgimage
__all__ = ["status_on", "status_off"]

bar = Image.new((119,13))
ao_sleep(3)
screen= screenshot()
bgcolor = screen.getpixel((57,30))[0]
fg = fgimage.FGImage()
bar.clear(bgcolor)
    
def status_on(message=None):
    if message is not None:
        bar.clear(bgcolor)
        bar.text((0,11), unicode(message), 0xffffff)
    fg.set(57,30, bar._bitmapapi())

def status_off():
    fg.unset()

status_on() # display empty bar with bgcolor ( abc display is hidden !)
ao_sleep(3)
status_on('hello') 
ao_sleep(3)
status_on('Welcome to snippets')
ao_sleep(3)
status_on('') # clear bar but it is always there !
ao_sleep(3)
status_on('hey !') 
ao_sleep(3)
status_off()  # remove bar you see abc again !
ao_sleep(3)
status_on()   # show last bar display : you see "Hey !"
ao_sleep(3)
status_off()  # remove bar you see abc again !
ao_sleep(3)

You need to create an account or log in to post comments to this site.


Click here to browse all 5140 code snippets

Related Posts