You Are Here:

Community: Developer Discussion Boards

#1 Old Image display - 2009-04-25, 13:28

Join Date: Aug 2008
Posts: 15
nitroxxx123
Offline
Registered User
In my program i am loading an image on the screen using canvas.blit(image) where image is already opened. The image gets displayed correctly the first time but when running the program if options menu is opened or a note is displayed then the image is erased.
How can I refresh the image in such events?
Also I would like to change the image when one of the options menu is selected. How can I achieve this? I tried using image.load(). But it did'nt work.
Reply With Quote

#2 Old Re: Image display - 2009-04-25, 14:25

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Quote:
Originally Posted by nitroxxx123 View Post
In my program i am loading an image on the screen using canvas.blit(image) where image is already opened. The image gets displayed correctly the first time but when running the program if options menu is opened or a note is displayed then the image is erased.
How can I refresh the image in such events?
The Canvas constructor can take a "redraw_callback" as a parameter. From the PyS60 Library Reference:
Quote:
class Canvas([redraw_callback=None, event_callback=None, resize_callback=None])

redraw_callback is called whenever a part of the Canvas has been obscured by something, is then revealed, and needs to be redrawn. This can typically happen, for example, when the user switches away from the Python application and back again, or after displaying a pop-up menu. The callback takes as its argument a four-element tuple that contains the top-left and the bottom-right corner of the area that needs to be redrawn. In many cases redrawing the whole Canvas is a reasonable option.
Does your canvas have such a callback? If not, make it something like this:
Code:
def handle_redraw(rect):
      canvas.blit(image)

canvas = appuifw.Canvas(redraw_callback=handle_redraw)
If this doesn't help please post the code you are using.

Quote:
Originally Posted by nitroxxx123 View Post
Also I would like to change the image when one of the options menu is selected. How can I achieve this? I tried using image.load(). But it did'nt work.
Well you can clear the canvas using canvas.clear() and then blit the new image. Or just blit the new image without clearing the canvas it covers the old one.
Reply With Quote

#3 Old Re: Image display - 2009-04-25, 15:38

Join Date: Aug 2008
Posts: 15
nitroxxx123
Offline
Registered User
Thanks It worked
Reply With Quote

#4 Old Red face Re: Image display - 2009-04-27, 13:27

Join Date: Nov 2008
Posts: 24
didacgil9
Offline
Registered User
I'm having a problem also with the canvas.

In my application, I have a presentation at the begining in full screen mode, using Canvas.
After that, I have two tabs, one of them with a list, and the second one with an image, using a new canvas2, and a new image2.
I don't know why, but after drawing the proper canvas in the tab, is covered by a white canvas.
I know that's not that easy to solve without the code posted, but does anyone have an idea why can that be?

Here some lines:

def print_feedback(self):
global img2, canvas2
self.setRow(20)
img2=Image.new((screenSize[0],screenSize[1]))
img2.clear((0,0,0))
self.setRow(40)
img2=self.prepare_text(img2, self.tab_prev_message)

# define your redraw function (still belonging to app 3)
def handle_redraw(rect):
global img2, canvas2
canvas2.blit(img2)

# define the canvas, include the redraw callback function
canvas2 =appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
appuifw.app.body = canvas2
e32.ao_sleep(2)

def exit_handler2():
global app_lock2
app_lock2.signal()

print_activity_description = appuifw.Listbox([u"Stefan", u"Holger", u"Emil", u"Ludger"], exit_handler2)

def handle_tab(self, index):
if index == 0:
appuifw.app.body = self.print_feedback()
if index == 1:
appuifw.app.body = self.print_description

def createTabs(self, titles,tabs_menu):
global app_lock2
appuifw.app.screen='normal'
appuifw.app.set_tabs(titles,self.handle_tab)
appuifw.app.body = self.print_feedback()
app_lock2.wait()
audio.say('exiting createTabs')

By using the e32.ao_sleep(2) in print_feedback, I saw that my image was printed, but overlaped after 2 seconds with the white one.

I know that the application has not left the tab section, as the audios are not played.

And, my previous images were not white, so I don't know where this white canvas covering my feedback is coming from.

Any clues? I have tryied a lot of things, so any comment will be more than welcome.
Reply With Quote

#5 Old Re: Image display - 2009-04-27, 13:37

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 didacgil99

it will be great if you edit your post and provide code tags in your post so that you can always get a good help.

Enjoy Pythoning
Gaba88


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

Forum Nokia Python Wiki


Learn Python at http://mobapps.org/PyS60
Reply With Quote

#6 Old Re: Image display - 2009-04-27, 14:30

Join Date: Nov 2008
Posts: 24
didacgil9
Offline
Registered User
I'm having a problem also with the canvas.

In my application, I have a presentation at the begining in full screen mode, using Canvas.
After that, I have two tabs, one of them with a list, and the second one with an image, using a new canvas2, and a new image2.
I don't know why, but after drawing the proper canvas in the tab, is covered by a white canvas.
I know that's not that easy to solve without the code posted, but does anyone have an idea why can that be?

Here some lines:
Code:
class GUI:
   def __init__(self):
      global app_lock2
      self.wall=Image.open('e:\\GeM\\images\\wall.jpg')
      self.tab_prev_message = u''
      self.tab_description = u''
      app_lock2 = e32.Ao_lock()

   #this function gets an string, and prepares an image cutting the string in pieces to fit on the screen
   def prepare_text(self, img, text, col=10, chars=40, colour=(255,255,255), space=20):
      while len(text) > chars:
         #I look for the furthest space in the first 40 characters
         position2 = 0
         position = 0
         while (position2 < chars):
            if position2 == -1:
               break
            position = position2
            position2 = text.find(' ',position+1)
         img.text((col,self.row), u"%s" %text[0:position],colour)
         self.row += space
                
         #I update the text to print with the rest of the string. We skip the space " " (position+1)
         text = text[position+1:len(text)]
    
      if len(text) > 0: #the last line needs to be printed directly
         img.text((col,self.row), u"%s" %text,colour)
         self.row += space
      #The text has been splitet already
      return img

   def print_feedback(self):
      global img2, canvas2
      self.setRow(20)
      img2=Image.new((screenSize[0],screenSize[1]))
      img2.clear((0,0,0))
      self.setRow(40)
      img2=self.prepare_text(img2, self.tab_prev_message)

      # define your redraw function (still belonging to app 3)
      def handle_redraw(rect):
         global img2, canvas2
         canvas2.blit(img2)

      # define the canvas, include the redraw callback function
      canvas2 =appuifw.Canvas(event_callback=None, redraw_callback=handle_redraw)
      appuifw.app.body = canvas2
      e32.ao_sleep(2)

   def exit_handler2():
      global app_lock2
      app_lock2.signal()

   print_activity_description = appuifw.Listbox([u"Stefan", u"Holger", u"Emil", u"Ludger"], exit_handler2)

   def handle_tab(self, index):
      if index == 0:
         appuifw.app.body = self.print_feedback()
      if index == 1:
         appuifw.app.body = self.print_description

   def createTabs(self, titles,tabs_menu):
      global app_lock2
      appuifw.app.screen='normal'
      appuifw.app.set_tabs(titles,self.handle_tab)
      appuifw.app.body = self.print_feedback()
      app_lock2.wait()
      audio.say('exiting createTabs')


And, somewhere in the application I have:

Code:
gui = GUI()
gui.presentation() #even the code is now show, it uses a global Canvas "canvas" and a global Image "img"
                   # and does a full screen presentation
[...]
gui.createTabs([u"Feedback", u"Description"], gui.handle_tab)


By using the e32.ao_sleep(2) in print_feedback, I saw that my image was printed, but overlaped after 2 seconds with the white one.

I know that the application has not left the tab section, as the audios are not played.

And, my previous images were not white, so I don't know where this white canvas covering my feedback is coming from.

Any clues? I have tryied a lot of things, so any comment will be more than welcome.
Last edited by didacgil9 : 2009-04-27 at 14:46.
Reply With Quote

#7 Old Re: Image display - 2009-04-28, 10:28

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Review your handle_redraw() function. Most likely it's not supporting your tabs views.

Cheers,

--jouni
Reply With Quote

#8 Old Re: Image display - 2009-04-28, 13:50

Join Date: Nov 2008
Posts: 24
didacgil9
Offline
Registered User
Quote:
Originally Posted by JOM View Post
Review your handle_redraw() function. Most likely it's not supporting your tabs views.

Cheers,

--jouni
Actually, it is redrawing the image each time I go back to the tab, but after the 2 seconds sleep (I put that intensiously to check that the redraw was done) I get the white page hiding my canvas.

Should does someone have an example of tab creation with canvas, having canvas previously printed on the screen before?

I need to say that I have not declared any other event_handler in any other section, that could be also called when I change the tab in focus.

I'm still looking for a reasonable answer to my question. I don't really understand why that happens, but I'm quite new to Python.
Reply With Quote

#9 Old Re: Image display - 2009-04-28, 14:51

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Well, if you're really sure that handle_redraw is correct, then I propose tracing your app. Then you know for sure where and why the "false" redraw happens. No need to read code, just read log file

Debug tips here: http://wiki.forum.nokia.com/index.ph...ing_techniques

Btw your code is pretty cryptic. I'm guessing you copy & pasted some lines? Would have been most helpful to see where the breaks are, but it's your question. General suggestion: use only one canvas.

Also cannot imagine what this line is supposed to do "appuifw.app.body = self.print_feedback()", when that func doesn't return anything at all. Guess: print_feedback creates new canvas, populates and activates it, but at return (after 2 sec timer) the body is reset with empty value, which gets redrawn as empty screen.

Cheers,

--jouni
Reply With Quote

#10 Old Red face Re: Image display - 2009-04-28, 20:56

Join Date: Nov 2008
Posts: 24
didacgil9
Offline
Registered User
Quote:
Originally Posted by JOM View Post
Well, if you're really sure that handle_redraw is correct, then I propose tracing your app. Then you know for sure where and why the "false" redraw happens. No need to read code, just read log file

Debug tips here: http://wiki.forum.nokia.com/index.ph...ing_techniques
Ok, I will try to write the output. Actually I did the "funny" debugging with the audio.say('number of the line'). As I though that it was a canvas.blit() changing my screen, I wrote the audio.say before all the blits, but no sound happend in that misterious case. It did on the ones I control.

Quote:
Originally Posted by JOM View Post
Btw your code is pretty cryptic. I'm guessing you copy & pasted some lines? Would have been most helpful to see where the breaks are, but it's your question. General suggestion: use only one canvas.
You are right. My code is quite long, so I just copied the lines I found to be relevand. Of course, there are some parts missing, but I though they can be guessed, like the
Code:
img2=self.prepare_text(img2, self.tab_prev_message)
Quote:
Originally Posted by JOM View Post
Also cannot imagine what this line is supposed to do "appuifw.app.body = self.print_feedback()", when that func doesn't return anything at all. Guess: print_feedback creates new canvas, populates and activates it, but at return (after 2 sec timer) the body is reset with empty value, which gets redrawn as empty screen.
Actually, I got this tab idea from an example (http://mobilenin.com/pys60/info_tabs_forms.htm), but I see your point, and very probably, that's the problem.
I will check that appuifw.app.body should get (img, canvas, etc) and I will prepare the return in that sense.

Thank you very much for your answers. I really appreciate them
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
How to display jpeg image on separate window amol_benare604 General Symbian C++ 2 2009-03-21 12:00
Image display which is converted kalgi General Symbian C++ 4 2009-02-09 06:45
Re: Image display and select zed1 Mobile Java Media (Graphics & Sounds) 1 2007-01-05 17:04
Display, modify and save image mazi888 Symbian Media (Graphics & Sounds) 1 2006-03-13 21:14

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