root/trunk/RBSkinning/RBSkinning/wxTools/AlphaBlend.py

Revision 501, 3.0 kB (checked in by sholloway, 6 years ago)

Removed dependencies on calldll/npstruct/dynwin in favor of the more generally and better architected ctypes module

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ License
4 ##~
5 ##- The RuneBlade Foundation library is intended to ease some
6 ##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.)
7 ##- applications, while providing the flexibility to modularly change the
8 ##- architecture. Enjoy.
9 ##~
10 ##~ Copyright (C) 2002  TechGame Networks, LLC.
11 ##~
12 ##~ This library is free software; you can redistribute it and/or
13 ##~ modify it under the terms of the BSD style License as found in the
14 ##~ LICENSE file included with this distribution.
15 ##~
16 ##~ TechGame Networks, LLC can be reached at:
17 ##~ 3578 E. Hartsel Drive #211
18 ##~ Colorado Springs, Colorado, USA, 80920
19 ##~
20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
22 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #~ Imports
24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 import ctypes
27
28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #~ Definitions
30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
32 """
33 hWndNext = self.user32.WindowFromPoint(*pos)
34 while hWndNext:
35     hWnd = hWndNext
36     hWndNext = self.user32.GetParent(hWnd)
37 style = self.user32.GetWindowLongA(hWnd,GWL_EXSTYLE)
38 self.user32.SetWindowLongA(hWnd, GWL_EXSTYLE, style^WS_EX_LAYERED)
39 if 0.0 < alpha < 1.0:
40     alpha = int(alpha*255.0)
41 else: alpha = int(alpha)
42 LastSettings = (hWnd, colorkey, alpha, LWA_ALPHA)
43 self.user32.SetLayeredWindowAttributes(*LastSettings)
44 return LastSettings
45 """
46
47 class winAlphaBlend(object):
48     GWL_EXSTYLE           = 0xffffffec
49     WS_EX_LAYERED         = 0x00080000
50     LWA_COLORKEY          = 0x00000001
51     LWA_ALPHA             = 0x00000002
52
53     alpha = 1.0
54     colorkey = None
55     user32 = ctypes.WinDLL('user32.dll')
56
57     def __init__(self, hWnd):
58         self.hWnd = hWnd
59         style = self.user32.GetWindowLongA(self.hWnd, self.GWL_EXSTYLE)
60         self.user32.SetWindowLongA(self.hWnd, self.GWL_EXSTYLE, style|self.WS_EX_LAYERED)
61
62     def Blend(self, alpha=None, colorkey=None, usedefaults=1):
63         flag = 0
64         if alpha is not None:
65             self.alpha = alpha
66             alpha = int(255 * alpha)
67             flag |= self.LWA_ALPHA
68         elif usedefaults:
69             alpha = int(255 * self.alpha)
70             if alpha < 255: flag |= self.LWA_ALPHA
71         else:
72             self.alpha = 1.0
73             alpha = 255
74
75         if colorkey is not None:
76             flag |= self.LWA_COLORKEY
77             self.colorkey = colorkey
78         elif usedefaults:
79             if self.colorkey is None: colorkey = 0
80             else:
81                 colorkey = self.colorkey
82                 if colorkey is not None:
83                     flag |= self.LWA_COLORKEY
84         else:
85             colorkey = 0
86             self.colorkey = None
87
88         self.user32.SetLayeredWindowAttributes(self.hWnd, colorkey, alpha, flag)
89
90 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91
92 class wxAlphaBlend(winAlphaBlend):
93     def __init__(self, window, *args, **kw):
94         super(wxAlphaBlend, self).__init__(window.GetHandle(), *args, **kw)
Note: See TracBrowser for help on using the browser.