Re: that's enough
Christopher Barker <[email protected]>
| Newsgroups | gmane.comp.python.image |
|---|---|
| Message-ID | <[email protected]> |
Jack Uretsky wrote:
> Thanks. Do you have a recommendation for which veersion of wxpython I
> should download for Mac OS X Snow Leopard (10.6)?
> Regards,
> Jack
Use the OS-X installer for the latest version found at the wxpython site.
I *think* it will work with either the Apple-supplied python or the
python.org one, but it's possible that that is broken on 10.6 -- I heard
a lot of issues on 10.6 (I'm running 10.5, so no no details).
I'd install python 2.6 from python.org, and use the wxpython installer
for that. That combination is the safest.
This might be useful, too:
http://wiki.wxpython.org/RecipesImagesAndGraphics
Note that wxPython has some basic image stuff built in, so depending on
what you need to do, you may not even need PIL. (but you may -- PIL is
far more full featured)
Oh, and I've enclosed a slightly more complex example.
-Chris
> "Trust me. I have a lot of experience at this."
> General Custer's unremembered message to his men,
> just before leading them into the Little Big Horn Valley
>
>
>
>
> On Mon, 12 Jul 2010, Alec Bennett wrote:
>
>> My understanding is that show() is mainly for debugging and tests, and
>> that
>> it doesn't offer very much control or efficiency. That's not to say that
>> what you're after can't be done, maybe someone else can help you with
>> that,
>> I just don't know.
>>
>> Personally I'd suggest using WXPython, which can do what you're after
>> fairly
>> easily.
>>
>> Here's one very simple way to display an image in WX:
>>
>> import wx
>>
>> class PictureWindow(wx.Frame):
>> ..def __init__(self, parent, id):
>>
>> ....wx.Frame.__init__(self, parent, id, "Window Title", size=(200,
>> 200), pos
>> = (50, 50), style = wx.DEFAULT_FRAME_STYLE)
>> ....panel = wx.Panel(self, -1)
>> ....bmp = wx.Image("page1.jpg", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
>> ....self.mainPic = wx.StaticBitmap(panel, -1, bmp)
>> ....self.Show()
>>
>> app = wx.App(redirect=0)
>> PictureWindow(None, -1)
>> app.MainLoop()
>>
>>
>>
>>
>>
>> On Sun, Jul 11, 2010 at 4:16 PM, Jack Uretsky <[email protected]> wrote:
>>
>>> Hi-
>>> The following worked very well:
>>>
>>>> import Image
>>>>>> d = Image.open("a_1.jpg")
>>>>>> d.show()
>>>>>>
>>>>>>
>>> Now, how do I turn
>>> it off before showing another image
>>> I'm on an Intel Mac, OS X Snow Leopard.
>>> Regards,
>>> Jack U.
>>> "Trust me. I have a lot of experience at this."
>>> General Custer's unremembered message to his men,
>>> just before leading them into the Little Big Horn Valley
>>>
>>>
>>>
>>> _______________________________________________
>>> Image-SIG maillist - [email protected]
>>> http://mail.python.org/mailman/listinfo/image-sig
>>>
>>
> _______________________________________________
> Image-SIG maillist - [email protected]
> http://mail.python.org/mailman/listinfo/image-sig
--
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
[email protected]
_______________________________________________
Image-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/image-sig
StaticBitmap.py
(application/x-python, 2.7 KB)
#!/usr/bin/env python2.5
import wx, os
class TestFrame(wx.Frame):
def __init__(self, *args, **kwargs):#parent, id,title,position,size):
wx.Frame.__init__(self, *args, **kwargs)#parent, id,title,position, size)
# there needs to be an "Images" directory with one or more jpegs in it in the
# current working directory for this to work
self.jpgs = GetJpgList("./Images") # get all the jpegs in the Images directory
self.CurrentJpg = 0
self.MaxImageSize = 200
b = wx.Button(self, -1, "Display next")
b.Bind(wx.EVT_BUTTON, self.DisplayNext)
#wx.EVT_BUTTON(self, b.GetId(), self.DisplayNext)
# starting with an EmptyBitmap, the real one will get put there
# by the call to .DisplayNext()
self.Image = wx.StaticBitmap(self, bitmap=wx.EmptyBitmap(self.MaxImageSize, self.MaxImageSize))
self.DisplayNext()
# Using a Sizer to handle the layout: I never like to use absolute postioning
box = wx.BoxSizer(wx.VERTICAL)
box.Add(b, 0, wx.CENTER | wx.ALL,10)
# adding stretchable space before and after centers the image.
box.Add((1,1),1)
box.Add(self.Image, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL | wx.ADJUST_MINSIZE, 10)
box.Add((1,1),1)
self.SetSizerAndFit(box)
wx.EVT_CLOSE(self, self.OnCloseWindow)
def DisplayNext(self, event=None):
# load the image
Img = wx.Image(self.jpgs[self.CurrentJpg], wx.BITMAP_TYPE_JPEG)
# scale the image, preserving the aspect ratio
W = Img.GetWidth()
H = Img.GetHeight()
if W > H:
NewW = self.MaxImageSize
NewH = self.MaxImageSize * H / W
else:
NewH = self.MaxImageSize
NewW = self.MaxImageSize * W / H
Img = Img.Scale(NewW,NewH)
# convert it to a wx.Bitmap, and put it on the wx.StaticBitmap
self.Image.SetBitmap(wx.BitmapFromImage(Img))
# You can fit the frame to the image, if you want.
#self.Fit()
#self.Layout()
self.Refresh()
self.CurrentJpg += 1
if self.CurrentJpg > len(self.jpgs) -1:
self.CurrentJpg = 0
def OnCloseWindow(self, event):
self.Destroy()
def GetJpgList(dir):
jpgs = [f for f in os.listdir(dir) if f[-4:] == ".jpg"]
print "JPGS are:", jpgs
return [os.path.join(dir, f) for f in jpgs]
class App(wx.App):
def OnInit(self):
frame = TestFrame(None, -1, "wxBitmap Test", wx.DefaultPosition,(550,200))
self.SetTopWindow(frame)
frame.Show(True)
return True
if __name__ == "__main__":
app = App(0)
app.MainLoop()