<s> import win32gui <EOL> import win32con <EOL> import win32api <EOL> import time <EOL> import math <EOL> import os <EOL> import sys <EOL> import re <EOL> if sys . version_info . major == <NUM_LIT:2> : <EOL> from urllib import pathname2url as urllib_pathname2url <EOL> else : <EOL> from urllib . request import pathname2url as urllib_pathname2url <EOL> g_debug = False <EOL> g_windows = { } <EOL> g_registeredClasses = { } <EOL> def Debug ( msg ) : <EOL> if not g_debug : <EOL> return <EOL> msg = "<STR_LIT>" + str ( msg ) <EOL> print ( msg ) <EOL> with open ( GetRealPath ( "<STR_LIT>" ) , "<STR_LIT:a>" ) as file : <EOL> file . write ( msg + "<STR_LIT:\n>" ) <EOL> def GetRealPath ( file = None , encodeURL = False ) : <EOL> if file is None : file = "<STR_LIT>" <EOL> if file . find ( "<STR_LIT:/>" ) != <NUM_LIT:0> and file . find ( "<STR_LIT:\\>" ) != <NUM_LIT:0> and not re . search ( r"<STR_LIT>" , file ) : <EOL> if hasattr ( sys , "<STR_LIT>" ) : path = os . path . dirname ( sys . executable ) <EOL> elif "<STR_LIT>" in globals ( ) : path = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> else : path = os . getcwd ( ) <EOL> path = path + os . sep + file <EOL> path = re . sub ( r"<STR_LIT>" , re . escape ( os . sep ) , path ) <EOL> path = re . sub ( r"<STR_LIT>" , "<STR_LIT>" , path ) <EOL> if encodeURL : <EOL> return urllib_pathname2url ( path ) <EOL> else : <EOL> return path <EOL> return file <EOL> def CreateWindow ( title , className , width , height , xpos = None , ypos = None , icon = None , windowProc = None ) : <EOL> """<STR_LIT>""" <EOL> if not windowProc : <EOL> windowProc = { win32con . WM_CLOSE : WM_CLOSE } <EOL> bigIcon = "<STR_LIT>" <EOL> smallIcon = "<STR_LIT>" <EOL> if icon : <EOL> icon = GetRealPath ( icon ) <EOL> bigX = win32api . GetSystemMetrics ( win32con . SM_CXICON ) <EOL> bigY = win32api . GetSystemMetrics ( win32con . SM_CYICON ) <EOL> bigIcon = win32gui . LoadImage ( <NUM_LIT:0> , icon , win32con . IMAGE_ICON , bigX , bigY , win32con . LR_LOADFROMFILE ) <EOL> smallX = win32api . GetSystemMetrics ( win32con . SM_CXSMICON ) <EOL> smallY = win32api . GetSystemMetrics ( win32con . SM_CYSMICON ) <EOL> smallIcon = win32gui . LoadImage ( <NUM_LIT:0> , icon , win32con . IMAGE_ICON , smallX , smallY , win32con . LR_LOADFROMFILE ) <EOL> wndclass = win32gui . WNDCLASS ( ) <EOL> wndclass . hInstance = win32api . GetModuleHandle ( None ) <EOL> wndclass . lpszClassName = className <EOL> wndclass . style = win32con . CS_VREDRAW | win32con . CS_HREDRAW <EOL> wndclass . hbrBackground = win32con . COLOR_WINDOW <EOL> wndclass . hCursor = win32gui . LoadCursor ( <NUM_LIT:0> , win32con . IDC_ARROW ) <EOL> wndclass . lpfnWndProc = windowProc <EOL> global g_registeredClasses <EOL> if not className in g_registeredClasses : <EOL> g_registeredClasses [ className ] = True <EOL> atomclass = win32gui . RegisterClass ( wndclass ) <EOL> Debug ( "<STR_LIT>" % className ) <EOL> if xpos is None or ypos is None : <EOL> Debug ( "<STR_LIT>" ) <EOL> screenx = win32api . GetSystemMetrics ( win32con . SM_CXSCREEN ) <EOL> screeny = win32api . GetSystemMetrics ( win32con . SM_CYSCREEN ) <EOL> xpos = int ( math . floor ( ( screenx - width ) / <NUM_LIT:2> ) ) <EOL> ypos = int ( math . floor ( ( screeny - height ) / <NUM_LIT:2> ) ) <EOL> if xpos < <NUM_LIT:0> : xpos = <NUM_LIT:0> <EOL> if ypos < <NUM_LIT:0> : ypos = <NUM_LIT:0> <EOL> windowID = win32gui . CreateWindow ( className , title , <EOL> win32con . WS_OVERLAPPEDWINDOW | win32con . WS_CLIPCHILDREN | win32con . WS_VISIBLE , <EOL> xpos , ypos , width , height , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , wndclass . hInstance , None ) <EOL> g_windows [ windowID ] = className <EOL> if icon : <EOL> if bigIcon : <EOL> win32api . SendMessage ( windowID , win32con . WM_SETICON , win32con . ICON_BIG , bigIcon ) <EOL> if smallIcon : <EOL> win32api . SendMessage ( windowID , win32con . WM_SETICON , win32con . ICON_SMALL , smallIcon ) <EOL> Debug ( "<STR_LIT>" % windowID ) <EOL> return windowID <EOL> def DestroyWindow ( windowID ) : <EOL> win32gui . DestroyWindow ( windowID ) <EOL> def GetWindowClassName ( windowID ) : <EOL> for key in g_windows : <EOL> if key == windowID : <EOL> return g_windows [ key ] <EOL> def MoveWindow ( windowID , xpos = None , ypos = None , width = None , height = None , center = None ) : <EOL> ( left , top , right , bottom ) = win32gui . GetWindowRect ( windowID ) <EOL> if xpos is None and ypos is None : <EOL> xpos = left <EOL> ypos = top <EOL> if width is None and height is None : <EOL> width = right - left <EOL> height = bottom - top <EOL> if xpos is None and ypos is not None : <EOL> xpos = left <EOL> if ypos is None and xpos is not None : <EOL> ypos = top <EOL> if not width : <EOL> width = right - left <EOL> if not height : <EOL> height = bottom - top <EOL> if center : <EOL> screenx = win32api . GetSystemMetrics ( win32con . SM_CXSCREEN ) <EOL> screeny = win32api . GetSystemMetrics ( win32con . SM_CYSCREEN ) <EOL> xpos = int ( math . floor ( ( screenx - width ) / <NUM_LIT:2> ) ) <EOL> ypos = int ( math . floor ( ( screeny - height ) / <NUM_LIT:2> ) ) <EOL> if xpos < <NUM_LIT:0> : xpos = <NUM_LIT:0> <EOL> if ypos < <NUM_LIT:0> : ypos = <NUM_LIT:0> <EOL> win32gui . MoveWindow ( windowID , xpos , ypos , width , height , <NUM_LIT:1> ) <EOL> def WM_CLOSE ( windowID , msg , wparam , lparam ) : <EOL> DestroyWindow ( windowID ) <EOL> win32gui . PostQuitMessage ( <NUM_LIT:0> ) <EOL> def GetLastError ( ) : <EOL> code = win32api . GetLastError ( ) <EOL> return "<STR_LIT>" % ( code , win32api . FormatMessage ( code ) ) <EOL> def MessageLoop ( className ) : <EOL> while not win32gui . PumpWaitingMessages ( ) : <EOL> time . sleep ( <NUM_LIT> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> g_debug = True <EOL> hwnd = CreateWindow ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT> ) <EOL> MessageLoop ( "<STR_LIT>" ) </s>
