wxwidgets - How to judge bmp pictures from clipboard whether they are same using wxpython? -


function want realize: when bmp picture clipboard changed, refresh window. if not, nothing done.

question meet: every time program goes function updatemsgshownarea(), self.oldbmp diff self.bmp, have let self.oldbmp = self.bmp if different, , prints "111111". while next time program goes updatemsgshownarea(), self.oldbmp diff self.bmp again. confuses me.

my print message image

code follows:

#!/usr/bin/env python  import wx import os, sys  #----------------------------------------------------------------------------  # main window class myframe(wx.frame):     def __init__(self, parent, title):         wx.frame.__init__(self, parent, title=title, size=(600,480))         self.panel = mypanel(self)         self.createstatusbar() # statusbar in bottom of window          # setting menu.         filemenu= wx.menu()          # wx.id_about , wx.id_exit standard ids provided wxwidgets.         menuabout = filemenu.append(wx.id_about, "&about"," information program")         menuexit = filemenu.append(wx.id_exit,"e&xit"," terminate program")          # creating menubar.         menubar = wx.menubar()         menubar.append(filemenu,"&file") # adding "filemenu" menubar         self.setmenubar(menubar)  # adding menubar frame content.          # set events.         self.bind(wx.evt_menu, self.onabout, menuabout)         self.bind(wx.evt_menu, self.onexit, menuexit)          self.show(true)      def onabout(self,e):         # message dialog box ok button. wx.ok standard id in wxwidgets.         dlg = wx.messagedialog( self, "a small text editor", "about sample editor", wx.ok)         dlg.showmodal() # show         dlg.destroy() # destroy when finished.      def onexit(self,e):         self.close(true)  # close frame.  #----------------------------------------------------------------------------  # main panel class mypanel(wx.panel):     def __init__(self, parent):         wx.panel.__init__(self, parent, -1)          # shared path boxsizer, dirpickerctrl alternative , better realization textctrl + btn         sharedpathstatictext = wx.statictext(self, -1, 'shared dir:')         self.sharedpathtextctrl = wx.textctrl(self, -1, 'please choose dir', style = wx.te_readonly|wx.te_rich)         sharedpathbtn = wx.button(self, -1, 'browse', name = 'shared dir button')           box1 = wx.boxsizer(wx.horizontal)         box1.add(sharedpathstatictext, 0, wx.align_center)         box1.add(self.sharedpathtextctrl, 1, wx.align_center|wx.left|wx.right, 5) # proportion = 1, border = 5         box1.add(sharedpathbtn, 0)          self.bind(wx.evt_button, self.onopen, sharedpathbtn)          # local path boxsizer         localpathstatictext = wx.statictext(self, -1, 'local dir:   ')         self.localpathtextctrl = wx.textctrl(self, -1, 'please choose dir', style = wx.te_readonly|wx.te_rich)         localpathbtn = wx.button(self, -1, 'browse', name = 'local dir button')          box2 = wx.boxsizer(wx.horizontal)         box2.add(localpathstatictext, 0, wx.align_center)         box2.add(self.localpathtextctrl, 1, wx.align_center|wx.left|wx.right, 5) # proportion = 1, border = 5         box2.add(localpathbtn, 0)          self.bind(wx.evt_button, self.onopen, localpathbtn)          # message show area         messageshowstatictext = wx.statictext(self, -1, 'sync info shown area:   ')          box5 = wx.boxsizer(wx.horizontal)         box5.add(messageshowstatictext, 0, wx.align_left)          # size (200,200) don't take effect         #msgshowareaid = wx.newid()         #print msgshowareaid         self.msgshowarea = wx.scrolledwindow(self, -1, size = (200,200), style = wx.simple_border)          box3 = wx.boxsizer(wx.horizontal)         box3.add(self.msgshowarea, 1, wx.align_center, 10)          # sync ctrl buttons         stopsyncbtn = wx.button(self, -1, 'stop sync', name = 'stop sync button')         resumesyncbtn = wx.button(self, -1, 'resume sync', name = 'resume sync button')          box4 = wx.boxsizer(wx.horizontal)         box4.add(stopsyncbtn, 0, wx.align_center|wx.right, 20)         box4.add(resumesyncbtn, 0, wx.align_center|wx.left, 20)          # sizer         sizer = wx.boxsizer(wx.vertical)         sizer.add(box1, 0, wx.expand|wx.all, 10)         sizer.add(box2, 0, wx.expand|wx.all, 10)         sizer.add(box5, 0, wx.expand|wx.all, 10)         sizer.add(box3, 0, wx.expand|wx.all, 10)         sizer.add(box4, 0, wx.align_center, 10)          self.setsizer(sizer)         self.setautolayout(true)          # clipboard         self.clip = wx.clipboard()         self.x = wx.bitmapdataobject()         self.bmp = none         self.oldbmp = none          self.msgshowarea.bind(wx.evt_idle, self.updatemsgshownarea)         self.msgshowarea.bind(wx.evt_paint, self.onpaint)      def onopen(self, e):         """ open file"""         button = e.geteventobject()         dlg = wx.dirdialog(self, "choose dir", "", wx.dd_default_style | wx.dd_dir_must_exist)         if dlg.showmodal() == wx.id_ok:             path = dlg.getpath()              if button.getname() == 'shared dir button':                 self.sharedpathtextctrl.setvalue(path)             if  button.getname() == 'local dir button':                 self.localpathtextctrl.setvalue(path)         dlg.destroy()      def updatemsgshownarea(self, e):         print "updatemsgshownarea"         self.clip.open()         self.clip.getdata(self.x)         self.clip.close()         self.bmp = self.x.getbitmap()         if self.oldbmp == self.bmp:             print "same pic"             return         else:             print "diff pic"             self.oldbmp = self.bmp             if  self.oldbmp == self.bmp:                 print "111111"             else:                 print "222222"          print "abcd"         #self.refresh()         #self.msgshowarea.refresh()      def onpaint(self, evt):         if self.bmp:             dc = wx.paintdc(self.msgshowarea)             dc.drawbitmap(self.bmp, 20, 20, true)   #----------------------------------------------------------------------------  if __name__ == '__main__':     app = wx.app(false)     frame = myframe(none, "easysync")     app.mainloop() 

there no support clipboard change notifications in wxwidgets, unfortunately. under msw relatively simple add it, i'm less sure other platforms.

in case, right choice poll clipboard changes, i.e. set timer , check clipboard contents every time fires. ugly , inefficient, should work.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -