home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / gui / native / win / winhelpers.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  6.8 KB  |  205 lines

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