Hi,
I’m trying to display a list of JPEG files one after the
other on a single panel.
The essence of my code is something like (I’ve omitted the
pieces I thought were irrelevant):
JPGs = [‘f1.jpg’, ‘f2.jpg’, ‘f3.jpg’, ‘f4.jpg’, ‘f5.jpg’,
……
for file in JPGs:
img =
wx.Image(file, wx.BITMAP_TYPE_JPEG)
W =
Img.GetWidth()
H =
Img.GetHeight()
if W > H:
NewW = 640
NewH = 640 * H / W
else:
NewH = 480
NewW = 480 * W / H
Img =
Img.Scale(NewW,NewH)
convert it to a
wx.Bitmap, and put it on the wx.StaticBitmap
ImgObj.SetBitmap(wx.BitmapFromImage(Img))
self.Fit()
I see the first couple of images displayed on the panel but
then the screen goes white…and I don’t see the rest of my images.
Any ideas/suggestions?
Thank you,
Ilan
Maybe the enclosed test/demo code a wrote a while back will help.
Ilan Tiagai wrote:
I’m trying to display a list of JPEG files one after the other on a single panel.
all next to each-other, or one after another in time?
The essence of my code is something like (I’ve omitted the pieces I thought were irrelevant):
http://wiki.wxpython.org/MakingSampleApps
for file in JPGs:
img = wx.Image(file, wx.BITMAP_TYPE_JPEG)
W = Img.GetWidth()
H = Img.GetHeight()
if W > H:
NewW = 640
NewH = 640 * H / W
else:
NewH = 480
NewW = 480 * W / H
Img = Img.Scale(NewW,NewH)
# convert it to a wx.Bitmap, and put it on the wx.StaticBitmap
ImgObj.SetBitmap(wx.BitmapFromImage(Img))
self.Fit()
I see the first couple of images displayed on the panel but then the screen goes white…and I don’t see the rest of my images.
It looks like this loop is going to whip though your images, replacing them all on the same wxStaticBitmap, and leave you with the last.
If you want to see that process, do it in a wxTimer Callback.
-Chris
StaticBitmap.py (2.67 KB)
···
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (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
Thank you Chris. I've actually seen and run your program before and it
works fine with a button click.
It is only when I attempt to run through them in a loop without user
interaction (e.g. pressing a button) that I see the problem.
I've tried using a delay (wx.Sleep(1)) between the processing of each
file but it didn't help.
I'm going to try the timer now.
Does it make sense to use a ClientDC?
Thanks,
Ilan
···
-----Original Message-----
From: wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf Of
Christopher Barker
Sent: Monday, February 23, 2009 7:51 PM
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Sequencing through a list of JPEGs
Maybe the enclosed test/demo code a wrote a while back will help.
Ilan Tiagai wrote:
I'm trying to display a list of JPEG files one after the other on a
single panel.
all next to each-other, or one after another in time?
The essence of my code is something like (I've omitted the pieces I
thought were irrelevant):
http://wiki.wxpython.org/MakingSampleApps
for file in JPGs:
img = wx.Image(file, wx.BITMAP_TYPE_JPEG)
W = Img.GetWidth()
H = Img.GetHeight()
if W > H:
NewW = 640
NewH = 640 * H / W
else:
NewH = 480
NewW = 480 * W / H
Img = Img.Scale(NewW,NewH)
# convert it to a wx.Bitmap, and put it on the wx.StaticBitmap
ImgObj.SetBitmap(wx.BitmapFromImage(Img))
self.Fit()
I see the first couple of images displayed on the panel but then the
screen goes white...and I don't see the rest of my images.
It looks like this loop is going to whip though your images, replacing
them all on the same wxStaticBitmap, and leave you with the last.
If you want to see that process, do it in a wxTimer Callback.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (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
Ilan Tiagai wrote:
Thank you Chris. I've actually seen and run your program before and it
works fine with a button click.
It is only when I attempt to run through them in a loop without user
interaction (e.g. pressing a button) that I see the problem.
I've tried using a delay (wx.Sleep(1)) between the processing of each
file but it didn't help.
that's not expected to work -- in wx event handlers block -- so you can't have a bunch of stuff happening in one event -- the results may not get show 'till the whle thing is done, and the rest of the GUI will be locked up. You might get it to woek with a wx.Yield(), but it's not the "right" way in any case.
I'm going to try the timer now.
That's the way to go -- the timer will fire in individual event each time, so you can process just tone image with each event.
Does it make sense to use a ClientDC?
You could, but calling SetBitmap() is fine unless you want to do more fancy drawing.
-Chris
···
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (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