Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, win32gui, win32ui, win32con, win32api
- from PIL import Image, ImageChops, ImageTk
- import Tkinter
- from threading import Timer
- class qqDiffCrack:
- widthWindow = 510
- heightWindow = 495
- leftImage0 = 577
- leftImage1 = 970
- topImage0 = topImage1 = 187
- widthImage0 = widthImage1 = 409
- heightImage0 = heightImage1 = 286
- interval = 3.0
- def __init__(self):
- self.root = root = Tkinter.Tk()
- self.photo = ImageTk.PhotoImage(self.qqDiffCrackCore())
- self.label = Tkinter.Label(root, image=self.photo)
- self.label.image = self.photo
- self.label.place(x=5,y=5)
- self.button = Tkinter.Button(root, text="Update", command=self.updateImage)
- self.button.place(x=5,y=460)
- self.button = Tkinter.Button(root, text="Start Auto Update", command=self.startAutoUpdate)
- self.button.place(x=120,y=460)
- #self.button = Tkinter.Button(root, text="Stop Auto Update", command=self.stopAutoUpdate)
- #self.button.place(x=240,y=460)
- self.removeTmpFiles()
- def MainLoop(self):
- self.root.minsize(self.widthWindow,self.heightWindow)
- self.root.maxsize(self.widthWindow,self.heightWindow)
- self.root.mainloop()
- def updateImage(self):
- self.photo = ImageTk.PhotoImage(self.qqDiffCrackCore())
- self.label = Tkinter.Label(self.root, image=self.photo)
- self.label.image = self.photo
- self.label.place(x=5,y=5)
- self.removeTmpFiles()
- def stopAutoUpdate(self):
- if self.__dict__.has_key("__timer"):
- self.__timer.cancel()
- del self.__timer
- def startAutoUpdate(self):
- self.stopAutoUpdate()
- self.__timer = Timer(self.interval, self.runAutoUpdate)
- self.__timer.start()
- def restartAutoUpdate(self):
- self.startAutoUpdate()
- def runAutoUpdate(self):
- self.updateImage()
- self.restartAutoUpdate()
- def removeTmpFiles(self):
- for rootdir, dirs, files in os.walk(".\\tmp\\", topdown=False):
- for name in files:
- os.remove(os.path.join(rootdir, name))
- def getImage(self, left, top, width, height):
- hwnd = 0
- dc = win32gui.GetWindowDC(hwnd)
- mfcDC=win32ui.CreateDCFromHandle(dc)
- saveDC=mfcDC.CreateCompatibleDC()
- saveBitMap = win32ui.CreateBitmap()
- saveBitMap.CreateCompatibleBitmap(mfcDC, width, height)
- saveDC.SelectObject(saveBitMap)
- saveDC.BitBlt((0,0), (width,height), mfcDC, (left,top), win32con.SRCCOPY)
- if not os.path.isdir('.\\tmp'):
- os.mkdir(".\\tmp")
- bmpname=win32api.GetTempFileName(".\\tmp\\","")[0]+'.bmp'
- saveBitMap.SaveBitmapFile(saveDC, bmpname)
- return bmpname
- def qqDiffCrackCore(self):
- img0 = Image.open(self.getImage(self.leftImage0,self.topImage0,self.widthImage0,self.heightImage0))
- img1 = Image.open(self.getImage(self.leftImage1,self.topImage1,self.widthImage1,self.heightImage1))
- diffImage = ImageChops.difference(img0,img1)
- for x in range(self.widthImage0):
- for y in range(self.heightImage0):
- if diffImage.getpixel((x,y)) == (0,0,0):
- diffImage.putpixel((x,y), (255,0,0))
- else:
- diffImage.putpixel((x,y), (0,255,0))
- return diffImage
- if __name__=="__main__":
- game = qqDiffCrack()
- game.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement