Why does wxStaticBitmap display multiple ima ges instead of one [Newbie alert]

Chris:
   I, too, have been fighting with this for about two weeks. (Two newbies
with the same problem.) The documentation of wx.StaticBitmap is too sketchy
for me to tell what magic each incantation (method) is supposed to perform.
How does one get the new bitmap for .SetBitmap(bitmap)???
   Would you be so kind as to provide a version of Steve's showJpg function
which will do what he (and I) wish to accomplish? It HAS to be more simple
than I am making it!

···

------------
Vernon Cole

-----Original Message-----
From: Chris Barker [mailto:Chris.Barker@noaa.gov]
Sent: Tuesday, December 30, 2003 11:26 PM
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] Why does wxStaticBitmap display multiple
images instead of one [Newbie alert]

----- Original Message -----
From: Steve Cronje <scronje@sasktel.net>

The image then is displayed using a call:

       self.showJpg(curFile)

to the function showJpg:

   def showJpg(self, fName):
   #Display jpg to app
       img = wxImage(fName, wxBITMAP_TYPE_JPEG)
       imgSmall = img.Scale(200,200)
       wxStaticBitmap(self, -1, wxBitmapFromImage(imgSmall), pos =
(245, 60),
   size= (100,100))

All works as planned, except that the image displayed, being correct,
first shows, in rapid succession, each of the prior showed images
beforeit halts at the appropriate curFile.

THis is exacty what you have asked it to do..each call to showJpg
creates a new wxStaticBitmap on top of all the old ones. What you want
to do is create a single wxStaticBitmap, and then change the bitmap on
it with:

wxStaticBitmap.SetBitmap(bitmap)

-Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Vernon Cole wrote:

Chris:
   I, too, have been fighting with this for about two weeks. (Two newbies
with the same problem.) The documentation of wx.StaticBitmap is too sketchy
for me to tell what magic each incantation (method) is supposed to perform.

You'll get the hang of the docs soon enough. They really are reference docs, not tutorials. Have you searched both the demo and Wiki for wxStaticBitmap? I alwyas look for examples to modify when I'm trying to get the hang of a new class.

How does one get the new bitmap for .SetBitmap(bitmap)???

The same why you get the bitmap for the constructor call.

   Would you be so kind as to provide a version of Steve's showJpg function
which will do what he (and I) wish to accomplish? It HAS to be more simple
than I am making it!

I don't know what you're doing, but it's pretty simple. I've enclosed a sample app that displays a set of jpgs in an "Image directory".

There have been enough questions about this, I just may put this in the Wiki.

-Chris

wxStaticBitmap.py (1.6 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Vernon Cole wrote:

Chris:
   I, too, have been fighting with this for about two weeks. (Two newbies
with the same problem.) The documentation of wx.StaticBitmap is too sketchy
for me to tell what magic each incantation (method) is supposed to perform.
How does one get the new bitmap for .SetBitmap(bitmap)???
   Would you be so kind as to provide a version of Steve's showJpg function
which will do what he (and I) wish to accomplish? It HAS to be more simple
than I am making it!

It is very simple. Save a reference to the wxStaticBitmap when it is created, and then use that reference to call SetBitmap when needed.

         # in __init__ or somewhere
         self.stbmp = wxStaticBitmap(self, -1, aBitmap, pospos=(245, 60),
                                 size=(100,100))
...

     def showJpg(self, fName):
        #Display jpg to app
        img = wxImage(fName, wxBITMAP_TYPE_JPEG)
        imgSmall = img.Scale(200,200)
        self.stbmp.SetBitmap(wxBitmapFromImage(imgSmall)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks Chris

That was very helpful. I agree that it may be helpful in the Wiki.

Steve

···

On Wed, 2003-12-31 at 13:58, Chris Barker wrote:

I don't know what you're doing, but it's pretty simple. I've enclosed a
sample app that displays a set of jpgs in an "Image directory".

There have been enough questions about this, I just may put this in the
Wiki.

I agree, about how simple Python is. I am a raw beginner, but find
myself guessing, when I cannot find the appropriate docs, and am
(already) sometimes right!

I found this on the comp.lang.python list:

.....
About a year ago, I felt the same way about the lack of elementary
wxPython docs as you do. It seems that everyone who has had that
complaint either goes away or sticks with it for a week or two and
figures it out and then there is no problem. Not to make light of
your frustration, but this question is some ways similar to "Why
aren't there any good books for beginners on how to ride a bicycle?"
.....

It reminds me about my (much) earlier days with dBIII (remember that?).
Although the documentation was easier to get at, the main thing about
the learning curve was learning to think in the dBIII paradigm, and
suddenly, everything seemed intuitive.

Seems to me Python is even more so.

Steve

···

On Wed, 2003-12-31 at 14:08, Robin Dunn wrote:

It is very simple. Save a reference to the wxStaticBitmap when it is
created, and then use that reference to call SetBitmap when needed.