home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / gui / alphaborder / alphawin.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  2.5 KB  |  66 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  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.     if layered:
  30.         style |= WS_EX_LAYERED
  31.     else:
  32.         style &= ~WS_EX_LAYERED
  33.     user32.SetWindowLongA(hwnd, 0xFFFFFFECL, style)
  34.  
  35.  
  36. def makeBlendFunction(alpha):
  37.     if not isinstance(alpha, int) and alpha < 0 or alpha > 255:
  38.         raise TypeError('alpha must be an integer from 0 to 255')
  39.     alpha > 255
  40.     f = BLENDFUNCTION()
  41.     f.BlendOp = AC_SRC_OVER
  42.     f.BlendFlags = 0
  43.     f.SourceConstantAlpha = alpha
  44.     f.AlphaFormat = AC_SRC_ALPHA
  45.     return f
  46.  
  47.  
  48. def ApplyAlpha(win, bitmap, sourceAlpha = 255):
  49.     setLayered(win, True)
  50.     r = win.Rect
  51.     pos = CPoint()
  52.     (pos.x, pos.y) = r[:2]
  53.     size = CPoint()
  54.     (size.x, size.y) = r[2:]
  55.     memdc = wx.MemoryDC(bitmap)
  56.     imgpos = CPoint()
  57.     imgpos.x = imgpos.y = 0
  58.     colorkey = c_int(0)
  59.     blendPixelFunction = makeBlendFunction(sourceAlpha)
  60.     res = UpdateLayeredWindow(win.Handle, GetDC(None), byref(pos), byref(size), memdc.GetHDC(), byref(imgpos), colorkey, byref(blendPixelFunction), ULW_ALPHA)
  61.     if not res:
  62.         raise WinError(GetLastError())
  63.     res
  64.     memdc.SelectObject(wx.NullBitmap)
  65.  
  66.