python - Non-flicker interactive Image sequence display with wxpython -
i've created interactive image sequence viewer. viewer work if there no flickering. read bit double buffering , find bit confusing. need straight on explanation/code should remove flickering in program. in of examples there explanation resizing. in other hand not need that, window size-fixed. approach should take fix flickering?
code:
import wx class main_frame(wx.frame): def __init__(self): wx.frame.__init__(self, none, wx.id_any, 'main window', size=(1300, 750)) self.panel = wx.panel(self, -1) self.centre() #------------------------------------------------------------------------------ self.frames = [] l=1 while l < 365: self.frames.append(wx.image('images/{0}.png'.format(l), wx.bitmap_type_any)) print l l+=1 self.slider = wx.slider(self.panel, wx.id_any, size = (500,-1)) self.slider.setmax(356) l = self.slider.getvalue() self.image = wx.staticbitmap(self.panel,-1,wx.bitmapfromimage(self.frames[l])) #------------------------------------------------------------------------------ self.sizer = wx.boxsizer(wx.horizontal) self.sizer_v = wx.boxsizer(wx.vertical) self.sizer_v.add(self.image, 0, wx.centre | wx.all, 5) self.sizer_v.add(self.slider, 0, wx.centre | wx.all, 5) self.sizer.add(self.sizer_v, 1, wx.expand | wx.all | wx.center, 5) self.panel.setsizer(self.sizer) self.bind(wx.evt_slider, self.onslider, self.slider) def onslider(self,e): l = self.slider.getvalue() self.image.setbitmap(wx.bitmapfromimage(self.frames[l])) if __name__ == '__main__': app = wx.app() frame = main_frame().show() app.mainloop()
wx.staticbitmap works best when static, in unchanging. think instead of using wx.staticbitmap use panel binds handler evt_paint
event. when want image change self.panel.currentbitmap = self.frames[i]
followed self.panel.refresh()
. (or better move functionality panel class better encapsulation.) in evt_paint
handler wx.paintdc
, drawbitmap
of current bitmap. also, keep bitmaps in list instead of images save conversion time when moving slider.
Comments
Post a Comment