Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- working code for a stackoverflow.com question
- http://stackoverflow.com/questions/12135211/problems-displaying-wxbitmaps-using-wxpython
- class viewWindow(wx.Frame):
- imgSizer = (480,360)
- def __init__(self, parent, title="View Window"):
- super(viewWindow,self).__init__(parent)
- ## create the menu and its sub trees
- menubar = wx.MenuBar()
- filemenu = wx.Menu()
- menubar.Append(filemenu, 'File')
- self.fitem = filemenu.Append(wx.ID_ANY, 'Open Connection Window')
- self.Bind(wx.EVT_MENU, self.openConnectionWindow, self.fitem)
- self.SetMenuBar(menubar)
- ## here is where the actual stuff inside the frame is set up.
- self.pnl = wx.Panel(self)
- self.vbox = wx.BoxSizer(wx.VERTICAL)
- ## create the wxImage for the web cam pic
- self.image = wx.EmptyImage(self.imgSizer[0],self.imgSizer[1])
- ## create the wxBitmap so that the wxImage can be displayed
- self.imageBit = wx.BitmapFromImage(self.image)
- self.staticBit = wx.StaticBitmap(self.pnl,wx.ID_ANY, self.imageBit)
- ## add the staticBit to the sizer so it is rendered properly on resizes and such
- ## note: not actually needed to get the image to display, but reccommended for ease
- ## of layout
- self.vbox.Add(self.staticBit)
- ## register the sizer with the panel so the panel knows to use it.
- self.pnl.SetSizer(self.vbox)
- ## create a timer that will update the window based on frame rate
- self.timex = wx.Timer(self, wx.ID_OK)
- self.timex.Start(1000/framerate)
- self.Bind(wx.EVT_TIMER, self.redraw, self.timex)
- ## set the size of the frame itself when it is first opened
- self.SetSize(self.imgSizer)
- self.Show()
- def openConnectionWindow(self, e):
- ## this will open a new connection window
- connect = connectionWindow(None)
- def redraw(self,e):
- ## this function updates the frame with the latest web cam image that has been
- ## retrieved by the client thread from the server.
- ## get the newest image in the queue
- if not imgQ.empty():
- picz = imgQ.get()
- ## convert the image from a string to something usable (wxImage)
- self.image.SetData(picz)
- ## from wxImage to wxBitmap
- self.imageBit = wx.BitmapFromImage(self.image)
- self.staticBit = wx.StaticBitmap(self.pnl,wx.ID_ANY, self.imageBit)
- ## refresh the frame
- self.Refresh()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement