×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    25

    Some questions about GUI and Time.sleep

    Hello everyone...!

    Code:
    Code:
    def handle_redraw(rect):
        global graph
        canvas.blit(graph)
    canvas=appuifw.Canvas(redraw_callback=handle_redraw)
    appuifw.app.body=canvas
    canvas.blit(graph)
    I'm currently working on a new application and I'm having some problems first this is how my application should look like:
    An Image at the center of the screen.
    A text under the image will appear.
    A black background color.

    I will try to arrange my questions:
    1. How can I set an image to be at the center of the screen? (I guess some math will be in the code?).
    2. How can I set some text right under the image?
    3. How can I set the background color to be black? should I declare a new image in some code and fill the image in black? and how can I do that?
    4. I use time.sleep(x) to set some delay, but I'm trying to use milliseconds (like 0.5 sec) but it doesn't really work, how can I make a delay with milliseconds?

    well basicly the GUI should look like this:
    http://img376.imageshack.us/img376/4813/appguimw9.jpg

  2. #2
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: Some questions about GUI and Time.sleep

    Hi shynet,

    First thing you should do is create a new image.

    Code:
    def handle_redraw(rect):
        canvas.blit(img)
    
    canvas=appuifw.Canvas(redraw_callback=handle_redraw)
    appuifw.app.body=canvas
    img = graphics.Image.new(canvas.size)
    For the background to be black, you should clear it:

    Code:
    img.clear((0,0,0)) # (0,0,0) is the color in RGB, which is black
    Centralizing the image will depend on it's size, so you'll have to test some points. Just keep changing the target for testing:

    Code:
    img2 = graphics.Image.open("E:\\Python\\image.png")
    
    canvas.blit(img2, target=(20,20))
    For the text, you will need to test the points too, so just change them as you need:

    Code:
    img.text((40,40), u"Hi, this works!", (255,255,255), 'normal')) # (40,40) is the point, (255,255,255) the RGB color and 'normal'is the font
    Finally, this is a script I tested and would work like you expected:

    Code:
    import e32
    import appuifw
    import graphics
    
    img = None
    
    def handle_redraw(rect):
        canvas.blit(img)
    
    canvas=appuifw.Canvas(redraw_callback=handle_redraw)
    appuifw.app.body=canvas
    img = graphics.Image.new(canvas.size)
    img.clear((0,0,0))
    img.text((70,160), u"This works!", (255,255,255), 'normal')
    handle_redraw(())
    img2 = graphics.Image.open("E:\\Python\\applicationicon.png")
    canvas.blit(img2, target=(70,70))
    
    app_lock = e32.Ao_lock()
    app_lock.wait()
    Just regarding that the points will depend on the size of the image, so you should change those according to your needs.


    About timers, you can use this:

    Code:
    import e32
    
    timer = e32.Ao_timer()
    
    timer.after(0.5)
    Hope it helps,

    Rafael.
    Last edited by Rafael T.; 2008-12-25 at 15:13.

  3. #3
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Some questions about GUI and Time.sleep

    Quote Originally Posted by Rafael T. View Post
    For the background to be black, you should clear it:

    Code:
    img.clear((0,0,0)) # (0,0,0) is the color in RGB, which is black
    Hi Rafael,

    Just completing, the color can also be specified in hexadecimal format
    Code:
    img.clear(0x000000)
    And there is no need for repeated testing when it comes to centering the image.
    Let's say you want to put img2 in the center of the screen:
    Code:
    appuifw.app.screen = 'full'
    
    #Find out the display size using the sysinfo module
    w = sysinfo.display_pixels()[0]
    h = sysinfo.display_pixels()[1]
    
    img2=graphics.Image.new((40,50))
    
    #Find out how much space should be between img2 and the margins of screen
    x1 = int((w-img2.size[0])/2)
    y1 = int((h-img2.size[1])/2)
    
    #Place img2 accordingly
    img.blit(img2, target=(x1,y1))
    Last edited by bogdan.galiceanu; 2008-12-25 at 17:49. Reason: Typos

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    25

    Re: Some questions about GUI and Time.sleep

    Thank you very much! it works...!

Similar Threads

  1. Bug in time.sleep?
    By jkirma in forum Symbian
    Replies: 2
    Last Post: 2005-08-22, 16:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×