From: Roger E. <ro...@er...> - 2005-09-13 20:12:48
|
Hi, I've got problems in trying to create a .exe file for the script below. Could anyone with 'PIL-experience' comment on the script eurocapture.pyw or setup.py script? I'm using py2exe 0.6.2 Python 2.4.1 wxPython 2.6.1.0 PIL 1.1.5 on a winXP box. The error (warning?) is: The following modules appear to be missing ['_grabscreen'] Thanks in advance, Roger ============================================================== eurocapture.pyw: import wx import win32ui import win32gui #from PIL import Image, ImageGrab import Image import ImageGrab import PngImagePlugin # as per the py2exe wiki regarding PIL import BmpImagePlugin # as per the py2exe wiki regarding PIL BLINK_STATE = 0 Image._initialized = 2 # as per the py2exe wiki regarding PIL class TaskBarApp(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, -1, title, size = (1, 1), style=wx.FRAME_NO_TASKBAR| wx.NO_FULL_REPAINT_ON_RESIZE) self.tbicon = wx.TaskBarIcon() icon = wx.Icon('euroned16x16.ico', wx.BITMAP_TYPE_ICO) self.tbicon.SetIcon(icon, 'Klik om een vensterafdruk te maken') self.tbicon.Bind(wx.EVT_TASKBAR_LEFT_UP, self.OnTaskBarLeftClick) self.tbicon.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarRightClick) self.Show(True) def OnTaskBarLeftClick(self, evt): self.FlashIcon(evt) def _MyCallback(hwnd, extra ): extra.append(hwnd) windows = [] win32gui.EnumWindows(_MyCallback, windows) j = 0 winDict = {} for i in windows: if win32gui.IsWindowVisible(i): winDict[j] = i j += 1 win32gui.SetForegroundWindow(winDict[1]) # found by trial and error I # needed this key try: fgwindow = win32ui.GetForegroundWindow() global img bbox = fgwindow.GetWindowRect() img = ImageGrab.grab( bbox) width = bbox[2] - bbox[0] if width > 640: coeff = width * 100. / 640 height = bbox[3] - bbox[1] newHeight = int( coeff * height) img = img.resize((640,480), Image.ANTIALIAS) img = img.convert("P", dither=Image.NONE, palette=Image.ADAPTIVE, colors=256) img.save("_eurocap.png", "PNG", optimize=1) #img.show() except: print "Geen venster op de voorgrond?!" self.FlashIcon(evt) def OnTaskBarRightClick(self, evt): self.tbicon.Destroy() self.Close(True) wx.GetApp().ProcessIdle() def FlashIcon(self, evt): global BLINK_STATE if BLINK_STATE == 0: icon = wx.Icon('euroned16x16flash.ico', wx.BITMAP_TYPE_ICO) self.tbicon.SetIcon(icon, 'Vensterafdruk wordt gemaakt...') BLINK_STATE = 1 return else: icon = wx.Icon('euroned16x16.ico', wx.BITMAP_TYPE_ICO) self.tbicon.SetIcon(icon, 'Klik om een vensterafdruk te maken') BLINK_STATE = 0 return class MyApp(wx.App): def OnInit(self): frame = TaskBarApp(None, -1, ' ') frame.Center(wx.BOTH) frame.Show(False) return True def main(): app = MyApp(0) app.MainLoop() if __name__ == '__main__': main() ==================================================== setup.py: from distutils.core import setup import py2exe import sys # If run without args, build executables, in quiet mode. if len(sys.argv) == 1: sys.argv.append("py2exe") sys.argv.append("-q") class Target: def __init__(self, **kw): self.__dict__.update(kw) # for the versioninfo resources self.version = "0.1.0" self.company_name = "Euroned Systems" self.copyright = "Euroned Systems 2005" self.name = "EuroNed Windows Tools" ################################################################ # A program using wxPython # The manifest will be inserted as resource into test_wx.exe. This # gives the controls the Windows XP appearance (if run on XP ;-) # # Another option would be to store it in a file named # test_wx.exe.manifest, and copy it with the data_files option into # the dist-dir. # manifest_template = ''' <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="5.0.0.0" processorArchitecture="x86" name="%(prog)s" type="win32" /> <description>%(prog)s Program</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly> ''' RT_MANIFEST = 24 eurocapture = Target( # used for the versioninfo resource description = "A screen capture tool", # what to build script = "eurocapture.pyw", other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="eurocapture"))], icon_resources = [(1, "euroned16x16.ico"), (2, "euroned16x16flash.ico")], dest_base = "eurocapture") ################################################################ setup( options = {"py2exe": {"compressed": 1, "optimize": 2, "ascii": 1, "bundle_files": 1}}, zipfile = None, windows = [eurocapture], ) |