an Image

J

JDevine

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
 
P

Peter Hansen

JDevine said:
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
 
J

Jan Erik Breimo

JDevine said:
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
 
M

M.E.Farmer

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.GetHeight()))
app = wx.PySimpleApp()
frame.Show()
app.MainLoop()
except:frame.Destroy()

Hth,
M.E. Farmer
 
M

Mel Wilson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top