home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2511 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.9 KB  |  134 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32gui
  5. import win32con
  6. import win32api
  7. import time
  8. import math
  9. import random
  10.  
  11. def _MyCallback(hwnd, extra):
  12.     (hwnds, classes) = extra
  13.     hwnds.append(hwnd)
  14.     classes[win32gui.GetClassName(hwnd)] = 1
  15.  
  16.  
  17. def TestEnumWindows():
  18.     windows = []
  19.     classes = { }
  20.     win32gui.EnumWindows(_MyCallback, (windows, classes))
  21.     print 'Enumerated a total of %d windows with %d classes' % (len(windows), len(classes))
  22.     if not classes.has_key('tooltips_class32'):
  23.         print "Hrmmmm - I'm very surprised to not find a 'tooltips_class32' class."
  24.     
  25.  
  26.  
  27. def OnPaint_1(hwnd, msg, wp, lp):
  28.     (dc, ps) = win32gui.BeginPaint(hwnd)
  29.     win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED)
  30.     br = win32gui.CreateSolidBrush(win32api.RGB(255, 0, 0))
  31.     win32gui.SelectObject(dc, br)
  32.     angle = win32gui.GetWindowLong(hwnd, win32con.GWL_USERDATA)
  33.     win32gui.SetWindowLong(hwnd, win32con.GWL_USERDATA, angle + 2)
  34.     r_angle = angle * (math.pi / 180)
  35.     win32gui.SetWorldTransform(dc, {
  36.         'M11': math.cos(r_angle),
  37.         'M12': math.sin(r_angle),
  38.         'M21': math.sin(r_angle) * -1,
  39.         'M22': math.cos(r_angle),
  40.         'Dx': 250,
  41.         'Dy': 250 })
  42.     win32gui.MoveToEx(dc, 250, 250)
  43.     win32gui.BeginPath(dc)
  44.     win32gui.Pie(dc, 10, 70, 200, 200, 350, 350, 75, 10)
  45.     win32gui.Chord(dc, 200, 200, 850, 0, 350, 350, 75, 10)
  46.     win32gui.LineTo(dc, 300, 300)
  47.     win32gui.LineTo(dc, 100, 20)
  48.     win32gui.LineTo(dc, 20, 100)
  49.     win32gui.LineTo(dc, 400, 0)
  50.     win32gui.LineTo(dc, 0, 400)
  51.     win32gui.EndPath(dc)
  52.     win32gui.StrokeAndFillPath(dc)
  53.     win32gui.EndPaint(hwnd, ps)
  54.     return 0
  55.  
  56. wndproc_1 = {
  57.     win32con.WM_PAINT: OnPaint_1 }
  58.  
  59. def OnPaint_2(hwnd, msg, wp, lp):
  60.     (dc, ps) = win32gui.BeginPaint(hwnd)
  61.     win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED)
  62.     (l, t, r, b) = win32gui.GetClientRect(hwnd)
  63.     for x in xrange(25):
  64.         vertices = ({
  65.             'x': int(random.random() * r),
  66.             'y': int(random.random() * b),
  67.             'Red': int(random.random() * 65280),
  68.             'Green': 0,
  69.             'Blue': 0,
  70.             'Alpha': 0 }, {
  71.             'x': int(random.random() * r),
  72.             'y': int(random.random() * b),
  73.             'Red': 0,
  74.             'Green': int(random.random() * 65280),
  75.             'Blue': 0,
  76.             'Alpha': 0 }, {
  77.             'x': int(random.random() * r),
  78.             'y': int(random.random() * b),
  79.             'Red': 0,
  80.             'Green': 0,
  81.             'Blue': int(random.random() * 65280),
  82.             'Alpha': 0 })
  83.         mesh = ((0, 1, 2),)
  84.         win32gui.GradientFill(dc, vertices, mesh, win32con.GRADIENT_FILL_TRIANGLE)
  85.     
  86.     win32gui.EndPaint(hwnd, ps)
  87.     return 0
  88.  
  89. wndproc_2 = {
  90.     win32con.WM_PAINT: OnPaint_2 }
  91.  
  92. def TestSetWorldTransform():
  93.     wc = win32gui.WNDCLASS()
  94.     wc.lpszClassName = 'test_win32gui_1'
  95.     wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW
  96.     wc.hbrBackground = win32con.COLOR_WINDOW + 1
  97.     wc.lpfnWndProc = wndproc_1
  98.     class_atom = win32gui.RegisterClass(wc)
  99.     hwnd = win32gui.CreateWindow(wc.lpszClassName, 'Spin the Lobster!', win32con.WS_CAPTION | win32con.WS_VISIBLE, 100, 100, 900, 900, 0, 0, 0, None)
  100.     for x in xrange(500):
  101.         win32gui.InvalidateRect(hwnd, None, True)
  102.         win32gui.PumpWaitingMessages()
  103.         time.sleep(0.01)
  104.     
  105.     win32gui.DestroyWindow(hwnd)
  106.     win32gui.UnregisterClass(wc.lpszClassName, None)
  107.  
  108.  
  109. def TestGradientFill():
  110.     wc = win32gui.WNDCLASS()
  111.     wc.lpszClassName = 'test_win32gui_2'
  112.     wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW
  113.     wc.hbrBackground = win32con.COLOR_WINDOW + 1
  114.     wc.lpfnWndProc = wndproc_2
  115.     class_atom = win32gui.RegisterClass(wc)
  116.     hwnd = win32gui.CreateWindowEx(0, class_atom, 'Kaleidoscope', win32con.WS_CAPTION | win32con.WS_VISIBLE | win32con.WS_THICKFRAME | win32con.WS_SYSMENU, 100, 100, 900, 900, 0, 0, 0, None)
  117.     s = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
  118.     win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, s | win32con.WS_EX_LAYERED)
  119.     win32gui.SetLayeredWindowAttributes(hwnd, 0, 175, win32con.LWA_ALPHA)
  120.     for x in xrange(30):
  121.         win32gui.InvalidateRect(hwnd, None, True)
  122.         win32gui.PumpWaitingMessages()
  123.         time.sleep(0.3)
  124.     
  125.     win32gui.DestroyWindow(hwnd)
  126.     win32gui.UnregisterClass(class_atom, None)
  127.  
  128. print 'Enumerating all windows...'
  129. TestEnumWindows()
  130. print 'Testing drawing functions ...'
  131. TestSetWorldTransform()
  132. TestGradientFill()
  133. print 'All tests done!'
  134.