×

Discussion Board

Results 1 to 10 of 10

Thread: Image display

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    15

    Image display

    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.

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

    Re: Image display

    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:
    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.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    15

    Re: Image display

    Thanks It worked

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    24

    Red face Re: Image display

    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.

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Image display

    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

  6. #6
    Registered User
    Join Date
    Nov 2008
    Posts
    24

    Re: Image display

    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 13:46.

  7. #7
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: Image display

    Review your handle_redraw() function. Most likely it's not supporting your tabs views.

    Cheers,

    --jouni

  8. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    24

    Re: Image display

    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.

  9. #9
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: Image display

    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

  10. #10
    Registered User
    Join Date
    Nov 2008
    Posts
    24

    Red face Re: Image display

    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

Similar Threads

  1. How to display jpeg image on separate window
    By amol_benare604 in forum Symbian
    Replies: 2
    Last Post: 2009-03-21, 11:00
  2. Image display which is converted
    By kalgi in forum Symbian
    Replies: 4
    Last Post: 2009-02-09, 05:45
  3. Re: Image display and select
    By zed1 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2007-01-05, 16:04
  4. Display, modify and save image
    By mazi888 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-03-13, 20:14

Posting Permissions

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