home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / gui / alphaborder / alphawin.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  2.5 KB  |  67 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from ctypes import windll, Structure, c_byte, c_long, c_int, byref, WinError, GetLastError
  6. user32 = windll.user32
  7. kernel32 = windll.kernel32
  8. GetDC = user32.GetDC
  9. UpdateLayeredWindow = user32.UpdateLayeredWindow
  10. AC_SRC_OVER = 0
  11. AC_SRC_ALPHA = 1
  12. ULW_ALPHA = 2
  13. WS_EX_LAYERED = 524288
  14.  
  15. class CPoint(Structure):
  16.     _fields_ = (('x', c_long), ('y', c_long))
  17.  
  18.  
  19. class BLENDFUNCTION(Structure):
  20.     _fields_ = (('BlendOp', c_byte), ('BlendFlags', c_byte), ('SourceConstantAlpha', c_byte), ('AlphaFormat', c_byte))
  21.  
  22.  
  23. def setLayered(win, layered):
  24.     hwnd = win.Handle
  25.     style = user32.GetWindowLongA(hwnd, 0xFFFFFFECL)
  26.     oldlayered = bool(WS_EX_LAYERED & style)
  27.     if layered == oldlayered:
  28.         return None
  29.     
  30.     if layered:
  31.         style |= WS_EX_LAYERED
  32.     else:
  33.         style &= ~WS_EX_LAYERED
  34.     user32.SetWindowLongA(hwnd, 0xFFFFFFECL, style)
  35.  
  36.  
  37. def makeBlendFunction(alpha):
  38.     if not isinstance(alpha, int) and alpha < 0 or alpha > 255:
  39.         raise TypeError('alpha must be an integer from 0 to 255')
  40.     
  41.     f = BLENDFUNCTION()
  42.     f.BlendOp = AC_SRC_OVER
  43.     f.BlendFlags = 0
  44.     f.SourceConstantAlpha = alpha
  45.     f.AlphaFormat = AC_SRC_ALPHA
  46.     return f
  47.  
  48.  
  49. def ApplyAlpha(win, bitmap, sourceAlpha = 255):
  50.     setLayered(win, True)
  51.     r = win.Rect
  52.     pos = CPoint()
  53.     (pos.x, pos.y) = r[:2]
  54.     size = CPoint()
  55.     (size.x, size.y) = r[2:]
  56.     memdc = wx.MemoryDC(bitmap)
  57.     imgpos = CPoint()
  58.     imgpos.x = imgpos.y = 0
  59.     colorkey = c_int(0)
  60.     blendPixelFunction = makeBlendFunction(sourceAlpha)
  61.     res = UpdateLayeredWindow(win.Handle, GetDC(None), byref(pos), byref(size), memdc.GetHDC(), byref(imgpos), colorkey, byref(blendPixelFunction), ULW_ALPHA)
  62.     if not res:
  63.         raise WinError(GetLastError())
  64.     
  65.     memdc.SelectObject(wx.NullBitmap)
  66.  
  67.