You Are Here:

Community: Developer Discussion Boards

#1 Old Setting image as background - Need help debugging my code - 2009-03-08, 07:32

Join Date: Jan 2009
Posts: 33
soontobeared
Offline
Registered User
Hi,
I need help debugging the following code.The background isn't being set to the image specified.
Code:
from window import Application
from appuifw import *
from graphics import *
import graphics
import appuifw

image_path='e:\\logozjp8.jpg'

class MyApp(Application):
    def __init__(self):

        menu = [ (u"Menu A", self.option_a),
                 (u"Menu B", self.option_b),
                 (u"Menu C", self.option_c) ]

        img=Image.new((240,320))
        bgimage=Image.open(image_path)
        canvas=Canvas(event_callback=None, redraw_callback=self.handle_redraw)
        body=canvas
        Application.__init__(self,
                             u"MyApp title",
                             body,
                             menu)
        
    def handle_redraw(self,rect):
	canvas.blit(bgimage)

    def option_a(self): note(u"A","info")
    def option_b(self): note(u"B","info")
    def option_c(self): note(u"C","info")
 
    def close_app(self):
        ny = popup_menu( [u"No", u"Yes"], u"Exit ?")
        if ny is not None:
            if ny == 1:
                Application.close_app(self)
 
if __name__ == "__main__":
 
    app = MyApp()
    app.run()
I also need help with resizing the image. Where exactly do I need to put in
Code:
bgimge.resize((canvas.size))
Regards
Last edited by soontobeared : 2009-03-08 at 07:35. Reason: Forgot Something
Reply With Quote

#2 Old Re: Setting image as background - Need help debugging my code - 2009-03-08, 08:35

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
hello soontobeared

there are lots or mistakes in your code. so i am giving you a small function set a background image.
Code:
    appuifw.app.title = u"Secret Messages"
    appuifw.app.screen='large'
        
    img = graphics.Image.open(u"your path goes here")
    
    def handle_redraw(rect):        
        canvas.blit(img)
        
    canvas=appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
    appuifw.app.body=canvas
    img = img.resize(canvas.size)
    canvas.blit(img)
this is a hint please mold this according to your needs.

Enjoy Pythoning
Gaba88


Gargi Das- http://gargidas.blogsot.com

Forum Nokia Python Wiki


Learn Python at http://mobapps.org/PyS60
Last edited by gaba88 : 2009-03-08 at 08:43.
Reply With Quote

#3 Old Re: Setting image as background - Need help debugging my code - 2009-03-09, 01:14

Join Date: Jan 2009
Posts: 33
soontobeared
Offline
Registered User
Hi Gaba,
I am still having problems merging your code with mine.Here's what I am doing
Code:
from window import Application
from appuifw import *
from graphics import *
import graphics
import appuifw

image_path='e:\\logozjp8.jpg'

class MyApp(Application):
    def __init__(self):

        menu = [ (u"Menu A", self.option_a),
                 (u"Menu B", self.option_b),
                 (u"Menu C", self.option_c) ]

##        img=Image.new((240,320))
        bgimage=Image.open(image_path)
        canvas=Canvas(event_callback=None, redraw_callback=self.handle_redraw)
        body=canvas
        bgimage.resize(canvas.size)
        canvas.blit(bgimage)
        Application.__init__(self,
                             u"MyApp title",
                             body,
                             menu)
        
    def handle_redraw(self,rect):
	canvas.blit(bgimage)

    def option_a(self): note(u"A","info")
    def option_b(self): note(u"B","info")
    def option_c(self): note(u"C","info")
 
    def close_app(self):
        ny = popup_menu( [u"No", u"Yes"], u"Exit ?")
        if ny is not None:
            if ny == 1:
                Application.close_app(self)
 
if __name__ == "__main__":
 
    app = MyApp()
    app.run()
The problems I am facing are
1.The image is being displayed on the background, but not resized to fit in the mobile screen.
2.The notes that comeup upon clicking the buttons on the menu aren't disappearing after a while ie. the canvas is not being redrawn

Please help me debug the code.

Thanks&Regards
Last edited by soontobeared : 2009-03-09 at 02:44.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Background image loading in listbox RJ_Develop General Symbian C++ 3 2008-08-08 08:32
view based app backgound - how to set standart theme background image ? donDonald Symbian User Interface 6 2007-06-28 12:22
How to drow image on another image (background) afka Mobile Java General 1 2006-08-23 14:14
Help~ Grid's background image ... jpottojp Symbian 4 2005-06-17 11:56
Debugging a C++ code in VC6++ IDE mainul_2001 Bluetooth Technology 1 2002-10-02 13:34

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia