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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. import ctypes
  6. import sys
  7. import os
  8. from ctypes.wintypes import RECT
  9. from ctypes import byref, c_int, c_long, WinError
  10. from logging import getLogger
  11. log = getLogger('winhelpers')
  12. user32 = ctypes.windll.user32
  13. kernel32 = ctypes.windll.kernel32
  14. SetWindowLong = user32.SetWindowLongW
  15. CallWindowProc = user32.CallWindowProcW
  16. DefWindowProc = user32.DefWindowProcW
  17. WndProcType = ctypes.PYFUNCTYPE(c_int, c_long, c_int, c_int, c_int)
  18. GWL_WNDPROC = -4
  19. WM_SIZING = 532
  20. WM_MOVING = 534
  21. WM_ENTERSIZEMOVE = 561
  22. WM_EXITSIZEMOVE = 562
  23. WM_NCHITTEST = 132
  24. WM_WINDOWPOSCHANGING = 70
  25. GW_HWNDNEXT = 2
  26. import wx
  27.  
  28. def bindwin32(win, msg, callback):
  29.     if not hasattr(win, '_win32binder'):
  30.         PlatformMessageBinder = PlatformMessageBinder
  31.         import cgui
  32.         win._win32binder = PlatformMessageBinder.ForWindow(win)
  33.     
  34.     win._win32binder.Bind(msg, callback)
  35.  
  36.  
  37. def unbindwin32(win, msg, callback):
  38.     if not hasattr(win, '_win32binder'):
  39.         return None
  40.     
  41.     win._win32binder.Unbind(msg, callback)
  42.  
  43.  
  44. wx.Window.ShowNoFocus = lambda win: win.Show(show = True, activate = False)
  45. if getattr(wx, 'WXPY', False):
  46.     import new
  47.     meth = new.instancemethod
  48.     wx._Window.BindWin32 = meth(bindwin32, None, wx._Window)
  49.     wx._Window.UnbindWin32 = meth(unbindwin32, None, wx._Window)
  50. else:
  51.     wx.Window.BindWin32 = bindwin32
  52.     wx.Window.UnbindWin32 = unbindwin32
  53.  
  54. try:
  55.     AttachThreadInput = user32.AttachThreadInput
  56.     GetWindowThreadProcessId = user32.GetWindowThreadProcessId
  57.     GetCurrentThreadId = kernel32.GetCurrentThreadId
  58.     GetForegroundWindow = user32.GetForegroundWindow
  59.     GetDesktopWindow = user32.GetDesktopWindow
  60.     GetShellWindow = user32.GetShellWindow
  61.     SetForegroundWindow = user32.SetForegroundWindow
  62. except:
  63.     print >>sys.stderr, 'No ReallyRaise'
  64.     
  65.     wx.WindowClass.ReallyRaise = lambda win: win.Raise()
  66.  
  67.  
  68. def ReallyRaise(win):
  69.     AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(), 0), GetCurrentThreadId(), True)
  70.     SetForegroundWindow(win.Handle)
  71.     AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(), 0), GetCurrentThreadId(), False)
  72.  
  73. getattr(wx, '_Window', wx.Window).ReallyRaise = ReallyRaise
  74. GetLastInputInfo = user32.GetLastInputInfo
  75. GetTickCount = kernel32.GetTickCount
  76. GetLastError = kernel32.GetLastError
  77.  
  78. class LastInputInfo(ctypes.Structure):
  79.     _fields_ = [
  80.         ('cbSize', ctypes.wintypes.UINT),
  81.         ('dwTime', ctypes.wintypes.DWORD)]
  82.  
  83. input_info = LastInputInfo()
  84. input_info.cbSize = ctypes.sizeof(input_info)
  85. input_info_ref = ctypes.byref(input_info)
  86.  
  87. def GetUserIdleTime():
  88.     if GetLastInputInfo(input_info_ref):
  89.         return GetTickCount() - input_info.dwTime
  90.     else:
  91.         raise WinError()
  92.  
  93. GetTopWindow = user32.GetTopWindow
  94. GetWindow = user32.GetWindow
  95. GetWindowRect = user32.GetWindowRect
  96. IsWindowVisible = user32.IsWindowVisible
  97. GetWindowLong = user32.GetWindowLongA
  98. GWL_EXSTYLE = -20
  99. WS_EX_TOPMOST = 8
  100.  
  101. def win32ontop(hwnd):
  102.     return bool(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
  103.  
  104. from wx import FRAME_NO_TASKBAR
  105. from gui.native.win.winconstants import SWP_NOMOVE, SWP_NOSIZE, SWP_NOZORDER, SWP_FRAMECHANGED, WS_EX_APPWINDOW, GWL_EXSTYLE
  106. window_pos_flags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED
  107. from ctypes import windll
  108. user32 = windll.user32
  109. GA_ROOT = 2
  110.  
  111. def ctypes_import(src, **k):
  112.     G = globals()
  113.     for name, funcs in k.iteritems():
  114.         dll = getattr(src, name)
  115.         (G.update,)((lambda .0: for func in .0:
  116. (func, getattr(dll, func)))(funcs))
  117.     
  118.  
  119. SetWindowLongA = user32.SetWindowLongA
  120. GetWindowLongA = user32.GetWindowLongA
  121. SetWindowPos = user32.SetWindowPos
  122. GetParent = user32.GetParent
  123. SetParent = user32.SetParent
  124. FindWindowA = user32.FindWindowA
  125. ShowWindow = user32.ShowWindow
  126. GetAncestor = user32.GetAncestor
  127. SetLastError = kernel32.SetLastError
  128. GetLastError = kernel32.GetLastError
  129.  
  130. def SetOnTaskbar(f, val):
  131.     hwnd = f.Handle
  132.     needs_show = f.IsShown()
  133.     needs_focus = getattr(wx.Window.FindFocus(), 'Top', None) is f
  134.     f.Frozen().__enter__()
  135.     
  136.     try:
  137.         if needs_show:
  138.             f.Hide()
  139.         
  140.         SetLastError(0)
  141.         if val:
  142.             f.WindowStyle = f.WindowStyle & ~FRAME_NO_TASKBAR
  143.             res = SetWindowLongA(hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_APPWINDOW)
  144.         else:
  145.             f.WindowStyle = f.WindowStyle | FRAME_NO_TASKBAR
  146.             res = SetWindowLongA(hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_APPWINDOW)
  147.         if needs_show:
  148.             if not needs_focus:
  149.                 
  150.                 try:
  151.                     return f.Show(True, False)
  152.                 except Exception:
  153.                     pass
  154.                 except:
  155.                     None<EXCEPTION MATCH>Exception
  156.                 
  157.  
  158.             None<EXCEPTION MATCH>Exception
  159.             f.Show(True)
  160.     finally:
  161.         pass
  162.  
  163.  
  164.  
  165. def GetOnTaskbar(f):
  166.     return not (FRAME_NO_TASKBAR & f.WindowStyle)
  167.  
  168. wx.TopLevelWindow.OnTaskbar = property(GetOnTaskbar, SetOnTaskbar)
  169. import cgui
  170. wx.TopLevelWindow.Visible = property(cgui.WindowVisible)
  171.  
  172. def FullscreenApp():
  173.     
  174.     try:
  175.         winfullscreen = winfullscreen
  176.         import gui.native.win
  177.     except ImportError:
  178.         traceback.print_exc_once()
  179.  
  180.     if winfullscreen.enabled:
  181.         
  182.         try:
  183.             return not winfullscreen.get_accepts_notifications()
  184.         except Exception:
  185.             traceback.print_exc()
  186.             winfullscreen.enabled = False
  187.         except:
  188.             None<EXCEPTION MATCH>Exception
  189.         
  190.  
  191.     None<EXCEPTION MATCH>Exception
  192.     hwnd = GetForegroundWindow()
  193.     desktopHwnd = GetDesktopWindow()
  194.     shellHwnd = GetShellWindow()
  195.     winRECT = RECT()
  196.     RECT2wx = wxRectFromRECT
  197.     import gui.native.win.winextensions
  198.     Monitor = Monitor
  199.     import gui.toolbox
  200.     if hwnd and hwnd not in (desktopHwnd, shellHwnd):
  201.         GetWindowRect(hwnd, byref(winRECT))
  202.         winrect = RECT2wx(winRECT)
  203.         mrect = Monitor.GetFromHandle(hwnd).Geometry
  204.         if winrect.Size == mrect.Size:
  205.             return True
  206.         
  207.     
  208.     return False
  209.  
  210.  
  211. def createEmail(mailto):
  212.     return os.startfile(mailto)
  213.  
  214.  
  215. def GetProcessDefaultLayout():
  216.     windll = windll
  217.     byref = byref
  218.     import ctypes
  219.     DWORD = DWORD
  220.     import ctypes.wintypes
  221.     layout = DWORD()
  222.     windll.user32.GetProcessDefaultLayout(byref(layout))
  223.     return layout.value
  224.  
  225. WS_EX_LAYOUTRTL = 4194304
  226.  
  227. def mirror(win):
  228.     hwnd = win.Handle
  229.     new_style = GetWindowLong(hwnd, GWL_EXSTYLE) ^ WS_EX_LAYOUTRTL
  230.     return SetWindowLong(hwnd, GWL_EXSTYLE, new_style)
  231.  
  232.