469,610 Members | 1,620 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

an Image

I am going through the painfull process of learning wxPython. Sincer
there is nearly no documentation, I am learning from the demos.
Unfortunately, I have realized these demos do some specialized
importing and that all the imports are not applicable. Specifially,
All I want to do now is insert a bmp I have drawn into a windows
application. The image clases from the demos are completely
unexplanatory about how to do this. The "images" module that is
imported has custom functions for calling a specific set of images
such as GetTest2Bitmap, which does not help me at all. Please help me
understand this.

-Thanks

-Justin
Jul 18 '05 #1
4 1472
JDevine wrote:
I am going through the painfull process of learning wxPython. Sincer
there is nearly no documentation, I am learning from the demos.
Unfortunately, I have realized these demos do some specialized
importing and that all the imports are not applicable. Specifially,
All I want to do now is insert a bmp I have drawn into a windows
application. The image clases from the demos are completely
unexplanatory about how to do this. The "images" module that is
imported has custom functions for calling a specific set of images
such as GetTest2Bitmap, which does not help me at all. Please help me
understand this.


I don't know what part of the demo you are looking at, but the
one I have has some real simple code under "Using Images->Image"
that looks like this (irrelevant parts removed for simplicity):

import wx

def runTest(frame, nb, log):
bmp = wx.Image('bitmaps/image.bmp',
wx.BITMAP_TYPE_BMP).ConvertToBitmap()

panel = wx.Panel(nb, -1)

pos = 10
wx.StaticBitmap(panel, -1, bmp, (10, pos),
(bmp.GetWidth(), bmp.GetHeight()))
Can't get much simpler than that... are you remembering to
look under the "Demo Code" tab of the demo, where the source
code is shown? It almost sounds like you are digging through
the source files manually, rather than using the demo the way
it was intended.

-Peter
Jul 18 '05 #2
"JDevine" <ju************@hotmail.com> wrote in message
news:f9**************************@posting.google.c om...
I am going through the painfull process of learning wxPython. Sincer
there is nearly no documentation, I am learning from the demos.
Unfortunately, I have realized these demos do some specialized
importing and that all the imports are not applicable. Specifially,
I agree that the documentation and the examples leave much to be desired,
but check out http://wiki.wxpython.org/ if you haven't done so already.
Among the documents you'll find there is this one about StaticBitmap:
http://wiki.wxpython.org/index.cgi/wxStaticBitmap
All I want to do now is insert a bmp I have drawn into a windows
application. The image clases from the demos are completely
unexplanatory about how to do this. The "images" module that is
imported has custom functions for calling a specific set of images
such as GetTest2Bitmap, which does not help me at all. Please help me
understand this.

-Thanks

-Justin

Jul 18 '05 #3
ju************@hotmail.com (JDevine) wrote in message news:<f9**************************@posting.google. com>...
I am going through the painfull process of learning wxPython. Sincer
there is nearly no documentation, I am learning from the demos.
Unfortunately, I have realized these demos do some specialized
importing and that all the imports are not applicable. Specifially,
All I want to do now is insert a bmp I have drawn into a windows
application. The image clases from the demos are completely
unexplanatory about how to do this. The "images" module that is
imported has custom functions for calling a specific set of images
such as GetTest2Bitmap, which does not help me at all. Please help me
understand this.

-Thanks

-Justin

Maybe this will help you.

# SimpleImage ver 1.0
# by M.E.Farmer Jr. 2003
# Utilizes the new wx namespace
# usage: python SimpleImage.py image.jpg
import sys
import wx
try:
frame = wx.Frame(None, -1, "SimpleImage", size=(-1,-1),pos=(1,1))
wx.InitAllImageHandlers()
# Converts the image into a wx compatible bitmap
pix = wx.Image(sys.argv[1], wx.BITMAP_TYPE_ANY).ConvertToBitmap()
# Now wx.StaticBitmap() can be used to place that bitmap onto the parent
st = wx.StaticBitmap(frame, -1, pix, pos=(1,1),
size=wx.Size(pix.GetWidth(),pix.GetHeight()))
frame.SetClientSize(wx.Size(pix.GetWidth(),pix.Get Height()))
app = wx.PySimpleApp()
frame.Show()
app.MainLoop()
except:frame.Destroy()

Hth,
M.E. Farmer
Jul 18 '05 #4
In article <18**************************@posting.google.com >,
me*****@hotmail.com (M.E.Farmer) wrote:
ju************@hotmail.com (JDevine) wrote in message news:<f9**************************@posting.google. com>...
I am going through the painfull process of learning wxPython. Sincer
there is nearly no documentation, I am learning from the demos.
Unfortunately, I have realized these demos do some specialized
importing and that all the imports are not applicable. Specifially,
All I want to do now is insert a bmp I have drawn into a windows
application. The image clases from the demos are completely
unexplanatory about how to do this. The "images" module that is
imported has custom functions for calling a specific set of images
such as GetTest2Bitmap, which does not help me at all. Please help me
understand this.
Maybe this will help you.

# SimpleImage ver 1.0
# by M.E.Farmer Jr. 2003
# Utilizes the new wx namespace
# usage: python SimpleImage.py image.jpg
[ ... ]
pix = wx.Image(sys.argv[1], wx.BITMAP_TYPE_ANY).ConvertToBitmap()
[ ... ]
st = wx.StaticBitmap(frame, -1, pix, pos=(1,1),
size=wx.Size(pix.GetWidth(),pix.GetHeight()))


You can also with a little more difficulty write straight
to the window.. Below is a fragment from __init__ of a
wx.Frame descendant. (It's straight from working code but I
haven't tested it independently.)
w, h = self.GetClientSizeTuple()
bmp = wx.EmptyBitmap (w, h)
mdc = wx.MemoryDC()
if bmp.LoadFile ("sweeper.bmp", wx.BITMAP_TYPE_BMP):
mdc.SelectObject (bmp)
wx.ClientDC (self).Blit (0,0, w,h, mdc, 0,0)
The complication with such techniques is that you need to
coordinate a lot of different objects.. Frame, Bitmap, DC..
and look up the separate documentation on those guys.. to
get any work done. Also not shown is the paint routine that
replays that Blit operation after an EVT_PAINT. Just for
what it's worth because I was just working on this.

Regards. Mel.
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Pierre Tremblay | last post: by
3 posts views Thread by dave | last post: by
8 posts views Thread by Jef Driesen | last post: by
6 posts views Thread by QuasiChameleon | last post: by
15 posts views Thread by Anand Ganesh | last post: by
7 posts views Thread by lgbjr | last post: by
6 posts views Thread by comp.lang.php | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.