home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / gui / native / win / wineffects.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  7.2 KB  |  177 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import sys
  5. import wx
  6. import ctypes
  7. from ctypes.wintypes import RECT, byref
  8. from wx import Rect
  9. from platform import platform
  10. from util import Storage
  11. user32 = ctypes.windll.user32
  12. gdi32 = ctypes.windll.gdi32
  13. controls = Storage(captionclose = (1, 0), captionmin = (1, 1), captionmax = (1, 2), captionrestore = (1, 3), captionhelp = (1, 4), menuarrow = (2, 0), menucheck = (2, 1), menubullet = (2, 2), menuarrowright = (2, 4), scrollup = (3, 0), scrolldown = (3, 1), scrollleft = (3, 2), scrollright = (3, 3), scrollcombobox = (3, 5), scrollsizegrip = (3, 8), scrollsizegripright = (3, 16), buttoncheck = (1, 0), buttonradioimage = (4, 1), buttonradiomask = (4, 2), buttonradio = (4, 4), button3state = (4, 8), buttonpush = (4, 16))
  14. states = Storage(inactive = 256, pushed = 512, checked = 1024, transparent = 2048, hot = 4096, adjustrect = 8192, flat = 16384, mono = 32768)
  15.  
  16. def rect2wx(winRECT):
  17.     return Rect(winRECT.left, winRECT.top, winRECT.right - winRECT.left, winRECT.bottom - winRECT.top)
  18.  
  19. _smokeFrame = None
  20.  
  21. try:
  22.     from cgui import ApplySmokeAndMirrors
  23. except ImportError:
  24.     print >>sys.stderr, 'WARNING: using slow ApplySmokeAndMirrors'
  25.     
  26.     def ApplySmokeAndMirrors(win, shape = None, ox = 0, oy = 0):
  27.         global _smokeFrame
  28.         if _smokeFrame is None:
  29.             _smokeFrame = wx.Frame(wx.FindWindowByName('Buddy List'), -1, '', style = wx.FRAME_SHAPED)
  30.             
  31.             def on_destroy(e):
  32.                 e.Skip()
  33.                 if e.EventObject is _smokeFrame:
  34.                     
  35.                     globals()['ApplySmokeAndMirrors'] = lambda win, shape = None, ox = 0, oy = 0: pass
  36.                 
  37.  
  38.             _smokeFrame.Bind(wx.EVT_WINDOW_DESTROY, on_destroy)
  39.         
  40.         if isinstance(shape, (int, type(None))):
  41.             return user32.SetWindowRgn(win.Handle, shape, True)
  42.         
  43.         rgn = gdi32.CreateRectRgn(0, 0, *win.Size)
  44.         if shape:
  45.             if isinstance(shape, wx.Region):
  46.                 region = shape
  47.             elif not shape.GetMask():
  48.                 image = wx.ImageFromBitmap(shape)
  49.                 image.ConvertAlphaToMask(200)
  50.                 bitmap = wx.BitmapFromImage(image)
  51.             else:
  52.                 bitmap = shape
  53.             region = wx.RegionFromBitmap(bitmap)
  54.             _smokeFrame.SetShape(region)
  55.             user32.GetWindowRgn(_smokeFrame.Handle, rgn)
  56.             gdi32.OffsetRgn(rgn, -1 + ox, -1 + oy)
  57.         
  58.         user32.SetWindowRgn(win.Handle, rgn, True)
  59.         gdi32.DeleteObject(rgn)
  60.  
  61.  
  62.  
  63. def GetRgn(win):
  64.     rgn = gdi32.CreateRectRgn(0, 0, *win.Size)
  65.     type = user32.GetWindowRgn(win.Handle, rgn)
  66.     if not type:
  67.         rgn = gdi32.CreateRectRgn(0, 0, win.Rect.Right, win.Rect.Bottom)
  68.     
  69.     return rgn
  70.  
  71.  
  72. def SmokeAndMirrorsBomb(win, windows):
  73.     rgn = gdi32.CreateRectRgn(0, 0, 0, 0)
  74.     shown = _[1]
  75.     rgns = [ GetRgn(window) for window in shown ]
  76.     for i in xrange(len(shown)):
  77.         gdi32.OffsetRgn(rgns[i], *shown[i].Position)
  78.         gdi32.CombineRgn(rgn, rgn, rgns[i], 2)
  79.         gdi32.DeleteObject(rgns[i])
  80.     
  81.     user32.SetWindowRgn(win.Handle, rgn, True)
  82.     gdi32.DeleteObject(rgn)
  83.  
  84. SB_HORZ = 0
  85. SB_VERT = 1
  86. SB_BOTH = 3
  87. WS_EX_LAYERED = 524288
  88. _user32 = ctypes.windll.user32
  89. GetWindowLongA = _user32.GetWindowLongA
  90. SetWindowLongA = _user32.SetWindowLongA
  91.  
  92. try:
  93.     GetLayeredWindowAttributes = _user32.GetLayeredWindowAttributes
  94.     SetLayeredWindowAttributes = _user32.SetLayeredWindowAttributes
  95. except AttributeError:
  96.     pass
  97.  
  98. from ctypes import c_byte
  99.  
  100. def ShowScrollbar(window, show):
  101.     hwnd = window.GetHandle()
  102.     scrollbar = SB_VERT
  103.     _user32.ShowScrollBar(hwnd, scrollbar, show)
  104.  
  105.  
  106. def _setalpha_wxMSW_ctypes(window, alpha):
  107.     hwnd = window.GetHandle()
  108.     oldStyle = style = GetWindowLongA(hwnd, 0xFFFFFFECL)
  109.     if alpha == 255:
  110.         style &= ~WS_EX_LAYERED
  111.     else:
  112.         style |= WS_EX_LAYERED
  113.     if oldStyle != style:
  114.         SetWindowLongA(hwnd, 0xFFFFFFECL, style)
  115.     
  116.     SetLayeredWindowAttributes(hwnd, 0, alpha, 2)
  117.     window._alpha = alpha
  118.  
  119.  
  120. def _donealpha_wxMSW_ctypes(window):
  121.     if not window:
  122.         return None
  123.     
  124.     hwnd = window.GetHandle()
  125.     oldStyle = style = GetWindowLongA(hwnd, 0xFFFFFFECL)
  126.     style &= ~WS_EX_LAYERED
  127.     if getattr(window, '_alpha', 255) == 0:
  128.         window.Hide()
  129.     
  130.     if oldStyle != style:
  131.         SetWindowLongA(hwnd, 0xFFFFFFECL, style)
  132.     
  133.     window._alpha = 255
  134.  
  135.  
  136. def _getalpha_wxMSW_ctypes(window):
  137.     return getattr(window, '_alpha', 255)
  138.     hwnd = window.GetHandle()
  139.     alpha = c_byte()
  140.     
  141.     try:
  142.         GetLayeredWindowAttributes(hwnd, 0, alpha, 2)
  143.         return alpha.value
  144.     except AttributeError:
  145.         return getattr(window, '_alpha', 255)
  146.  
  147.  
  148.  
  149. def _drawnativecontrol_wxMSW(handle, rect, control, state = 0):
  150.     _user32.DrawFrameControl(handle, rect, control[0], control[1] | state)
  151.  
  152. setalpha = _setalpha_wxMSW_ctypes
  153. getalpha = _getalpha_wxMSW_ctypes
  154. donealpha = _donealpha_wxMSW_ctypes
  155.  
  156. def DrawSubMenuArrow(dc, rect):
  157.     wxRectToRECT = wxRectToRECT
  158.     import gui.native.win.winextensions
  159.     rect = wxRectToRECT(rect)
  160.     _drawnativecontrol_wxMSW(dc.GetHDC(), byref(rect), controls.menuarrow, 0)
  161.  
  162. if platform().startswith('Windows-2000'):
  163.     
  164.     setalpha = lambda *a: pass
  165.     
  166.     getalpha = lambda *a: 255
  167.     
  168.     fadein = lambda win, *a, **k: win.Show(True)
  169.     
  170.     def fadeout(win, speed = 'normal', on_done = None, from_ = None):
  171.         win.Show(False)
  172.         if on_done is not None:
  173.             on_done()
  174.         
  175.  
  176.  
  177.