def _SetupList(self): child_style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | win32con.WS_HSCROLL | win32con.WS_VSCROLL child_style |= commctrl.LVS_SINGLESEL | commctrl.LVS_SHOWSELALWAYS | commctrl.LVS_REPORT self.hwndList = win32gui.CreateWindow("SysListView32", None, child_style, 0, 0, 100, 100, self.hwnd, IDC_LISTBOX, self.hinst, None) child_ex_style = win32gui.SendMessage( self.hwndList, commctrl.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0) child_ex_style |= commctrl.LVS_EX_FULLROWSELECT win32gui.SendMessage(self.hwndList, commctrl.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, child_ex_style) # Add an image list - use the builtin shell folder icon - this # demonstrates the problem with alpha-blending of icons on XP if # winxpgui is not used in place of win32gui. il = win32gui.ImageList_Create( win32api.GetSystemMetrics(win32con.SM_CXSMICON), win32api.GetSystemMetrics(win32con.SM_CYSMICON), commctrl.ILC_COLOR32 | commctrl.ILC_MASK, 1, # initial size 0) # cGrow shell_dll = os.path.join(win32api.GetSystemDirectory(), "shell32.dll") large, small = win32gui.ExtractIconEx(shell_dll, 4, 1) win32gui.ImageList_ReplaceIcon(il, -1, small[0]) win32gui.DestroyIcon(small[0]) win32gui.DestroyIcon(large[0]) win32gui.SendMessage(self.hwndList, commctrl.LVM_SETIMAGELIST, commctrl.LVSIL_SMALL, il) # Setup the list control columns. lvc = LVCOLUMN(mask=commctrl.LVCF_FMT | commctrl.LVCF_WIDTH | commctrl.LVCF_TEXT | commctrl.LVCF_SUBITEM) lvc.fmt = commctrl.LVCFMT_LEFT lvc.iSubItem = 1 lvc.text = "Title" lvc.cx = 200 win32gui.SendMessage(self.hwndList, commctrl.LVM_INSERTCOLUMN, 0, lvc.toparam()) lvc.iSubItem = 0 lvc.text = "Order" lvc.cx = 50 win32gui.SendMessage(self.hwndList, commctrl.LVM_INSERTCOLUMN, 0, lvc.toparam()) win32gui.UpdateWindow(self.hwnd)
def __init__(self): grouppolicydir = os.path.join(win32api.GetSystemDirectory(), "GroupPolicy") if not os.path.exists(grouppolicydir): os.mkdir(grouppolicydir) inifile = os.path.join(grouppolicydir, "gpt.ini") self._inifile = inifile self.config = ConfigParser.SafeConfigParser() logger.debug("LGP: Opening %s" % inifile) try: self.config.read(self._inifile) except ConfigParser.Error: #file does not exist self.config.add_section('General') if not self.config.has_section('General'): self.config.add_section('General')
def RegisterWin32com(searchPaths): """Knows how to register win32com components """ import win32api # import ni,win32dbg;win32dbg.brk() corePath = FindRegisterPackage("win32com", "olectl.py", searchPaths) if corePath: FindRegisterHelpFile("PyWin32.chm", searchPaths + [corePath + "\\win32com"], "Python COM Reference") suffix = IsDebug() ver_str = hex(sys.hexversion)[2] + hex(sys.hexversion)[4] FindRegisterModule("pythoncom", "pythoncom%s%s.dll" % (ver_str, suffix), [win32api.GetSystemDirectory(), '.'])
def base(): hKey = None keyFound = True try: hKey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, BIND_SUBKEY) except: keyFound = False if keyFound: try: (namedBase, _) = win32api.RegQueryValueEx(hKey, "InstallDir") except: keyFound = False win32api.RegCloseKey(hKey) if keyFound: return namedBase return win32api.GetSystemDirectory()
def __init__(self, parent, name, commands=None, icon_path=None): self.parent = parent self.name = name self.WM_NOTIFY = win32con.WM_USER + 20 wndproc = { win32con.WM_DESTROY: self.on_destroy, win32con.WM_COMMAND: self.on_command, self.WM_NOTIFY: self.on_tray_notify, } wc = win32gui.WNDCLASS() wc.hInstance = hinst = win32api.GetModuleHandle(None) wc.lpszClassName = name.title() wc.lpfnWndProc = wndproc try: class_atom = win32gui.RegisterClass(wc) except: pass self.hwnd = win32gui.CreateWindow(wc.lpszClassName, "", win32con.WS_POPUP, 0, 0, 1, 1, 0, 0, hinst, None) win32gui.UpdateWindow(self.hwnd) if icon_path is not None and os.path.isfile(icon_path): icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE hicon = win32gui.LoadImage(None, icon_path, win32con.IMAGE_ICON, 0, 0, icon_flags) else: shell_dll = os.path.join(win32api.GetSystemDirectory(), "shell32.dll") large, small = win32gui.ExtractIconEx(shell_dll, 19, 1) #19 or 76 hicon = small[0] win32gui.DestroyIcon(large[0]) self.hicon = hicon flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP | win32gui.NIF_INFO nid = (self.hwnd, 0, flags, self.WM_NOTIFY, self.hicon, self.name) win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid) self.next_command_id = 1000 self.commands = {} self.register_command('Exit', lambda: win32gui.DestroyWindow(self.hwnd)) if commands is not None: for n, f in commands[::-1]: self.register_command(n, f)
def get_dll_search_path(): """Generate a list of all the places where the pythonNN.dll files might be stored. This roughly duplicates the standard win32 rules. There may be a lot of duplicates, but this routine attempts to be comprehensive.""" # searchlist contains full paths searchlist = [] # check with win32api, if present if HAVE_WIN32_API: # p will be e.g. c:\windows\system p = win32api.GetSystemDirectory() searchlist.append(p) # on NT, p will contain SYSTEM32, so add SYSTEM as well p = os.path.join(os.path.dirname(p), 'SYSTEM') searchlist.append(p) # add, e.g. c:\windows searchlist.append( win32api.GetWindowsDirectory() ) # generate some root paths, then add SYSTEM & SYSTEM32 to each rootlist = [] # check the registry path = get_winroot_from_registry() if path is not None: rootlist.append( path ) # add PATH directories rootlist.extend( string.split( os.environ['PATH'], os.pathsep )) # now, for each, add SYSTEM & SYSTEM32, in the hope # that one of the paths is, e.g. c:\windows for path in rootlist: searchlist.append( path ) searchlist.append( os.path.join(path,'SYSTEM') ) searchlist.append( os.path.join(path,'SYSTEM32') ) # add the .exe directory searchlist.append( os.path.dirname( os.path.abspath( sys.executable ))) # add the cwd searchlist.append( os.getcwd() ) return searchlist
def SetupCore(searchPaths): """Setup the core Python information in the registry. This function makes no assumptions about the current state of sys.path. After this function has completed, you should have access to the standard Python library, and the standard Win32 extensions """ import sys for path in searchPaths: sys.path.append(path) import string, os import regutil, _winreg, win32api installPath, corePaths = LocatePythonCore(searchPaths) # Register the core Pythonpath. print corePaths regutil.RegisterNamedPath(None, string.join(corePaths, ";")) # Register the install path. hKey = _winreg.CreateKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey()) try: # Core Paths. _winreg.SetValue(hKey, "InstallPath", _winreg.REG_SZ, installPath) finally: _winreg.CloseKey(hKey) # The core DLL. # regutil.RegisterCoreDLL() # Register the win32 extensions, as some of them are pretty much core! # Why doesnt win32con.__file__ give me a path? (ahh - because only the .pyc exists?) # Register the win32 core paths. win32paths = os.path.abspath( os.path.split(win32api.__file__)[0]) + ";" + \ os.path.abspath( os.path.split(LocateFileName("win32con.py;win32con.pyc", sys.path ) )[0] ) suffix = IsDebug() ver_str = hex(sys.hexversion)[2] + hex(sys.hexversion)[4] FindRegisterModule("pywintypes", "pywintypes%s%s.dll" % (ver_str, suffix), [".", win32api.GetSystemDirectory()]) regutil.RegisterNamedPath("win32", win32paths)
def WindowsCompletePath(): path = win32api.GetEnvironmentVariable('PATH') dirs = [ os.getcwd(), win32api.GetSystemDirectory(), win32api.GetWindowsDirectory() ] + path.split(';') dirs_norm = [] dirs_l = [] for aDir in dirs: aDirLower = aDir.lower() if aDirLower not in dirs_l: dirs_l.append(aDirLower) dirs_norm.append(aDir) return dirs_norm
def get_system_path(): """Return the path that Windows will search for dlls.""" _bpath = [] if is_win: try: import win32api except ImportError: logger.warn("Cannot determine your Windows or System directories") logger.warn("Please add them to your PATH if .dlls are not found") logger.warn("or install http://sourceforge.net/projects/pywin32/") else: sysdir = win32api.GetSystemDirectory() sysdir2 = os.path.normpath(os.path.join(sysdir, '..', 'SYSTEM')) windir = win32api.GetWindowsDirectory() _bpath = [sysdir, sysdir2, windir] _bpath.extend(os.environ.get('PATH', '').split(os.pathsep)) return _bpath
def WindowsCompletePath(): """Try paths as described in MSDN""" path = win32api.GetEnvironmentVariable('PATH') dirs = [ os.getcwd(), win32api.GetSystemDirectory(), win32api.GetWindowsDirectory() ] + path.split(';') dirs_norm = [] dirs_l = [] for a_dir in dirs: a_dir_lower = a_dir.lower() if a_dir_lower not in dirs_l: dirs_l.append(a_dir_lower) dirs_norm.append(a_dir) return dirs_norm
def get_system_path(): """ Return the path that Windows will search for dlls. """ _bpath = [] try: import win32api sys_dir = win32api.GetSystemDirectory() except ImportError: sys_dir = os.path.normpath(os.path.join(get_windows_dir(), 'system32')) # Ensure C:\Windows\system32 and C:\Windows directories are # always present in PATH variable. # C:\Windows\system32 is valid even for 64bit Windows. Access do DLLs are # transparently redirected to C:\Windows\syswow64 for 64bit applactions. # http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx _bpath = [sys_dir, get_windows_dir()] _bpath.extend(compat.getenv('PATH', '').split(os.pathsep)) return _bpath
def collecting_computer_information(): user = "******" + win_api.GetUserName() computer_name = "Имя компьютера: " + win_api.GetComputerName() windows_directory = "Путь к папке OS Windows: " + win_api.GetWindowsDirectory( ) system_directory = "Путь к папке с системными файлами: " + win_api.GetSystemDirectory( ) volume_label = "Метка Тома: " + str(win_api.GetVolumeInformation("E:\\")) memory = "Обьем Памяти:" + str(win_api.GetDiskFreeSpace()) screen_height = "Высота экрана: " + str(win_api.GetSystemMetrics(0)) keyboard_type = "Тип и подтип клавиатуры: " + str( win_api.GetKeyboardLayout()) all_info = " ".join([ user, computer_name, windows_directory, system_directory, volume_label, memory, screen_height, keyboard_type ]) all_info = sha512(all_info.encode()) return all_info.hexdigest()
def __init__(self, grph): self.grph = grph self.path = win32api.GetEnvironmentVariable('PATH') # try paths as described in MSDN self.dirs = [ os.getcwd(), win32api.GetSystemDirectory(), win32api.GetWindowsDirectory() ] + self.path.split(';') self.dirs_norm = [] dirs_l = [] for aDir in self.dirs: aDirLower = aDir.lower() if aDirLower not in dirs_l: dirs_l.append(aDirLower) self.dirs_norm.append(aDir)
def LocatePythonServiceExe(exeName=None): found = _LocatePythonServiceExe(exeName) where = os.path.dirname(found) under_d = "_d" if "_d.pyd" in importlib.machinery.EXTENSION_SUFFIXES else "" suffix = "%s%s%s.dll" % ( sys.version_info[0], sys.version_info[1], under_d, ) # If someone isn't using python.exe to register pythonservice.exe we assume they know what they # are doing. if found == sys.executable: return found py_dll = "python{}".format(suffix) pyw_dll = "pywintypes{}".format(suffix) system_dir = win32api.GetSystemDirectory() exec_prefix = sys.exec_prefix dirs = [system_dir, exec_prefix, where] fpaths = [os.path.join(p, dll) for dll in [py_dll, pyw_dll] for p in dirs] fpaths = [f for f in fpaths if os.path.exists(f)] fpaths = fpaths and fpaths or ["nothing"] ok = (os.path.exists(os.path.join(where, py_dll)) or os.path.exists(os.path.join(system_dir, py_dll))) and ( os.path.exists(os.path.join(where, pyw_dll)) or os.path.exists(os.path.join(system_dir, pyw_dll))) if not ok: print( noise.format( exe=found, good=os.path.dirname(pywintypes.__file__), py_dll=py_dll, pyw_dll=pyw_dll, dirs="\n ".join(dirs), fpaths="\n ".join(fpaths), exec_prefix=exec_prefix, ), file=sys.stderr, ) return found
def getWindowsPath(): """Return the path that Windows will search for dlls.""" global _bpath if _bpath is None: _bpath = [] if iswin: try: import win32api except ImportError: print "W: Cannot determine your Windows or System directories" print "W: Please add them to your PATH if .dlls are not found" print "W: or install starship.python.net/skippy/win32/Downloads.html" else: sysdir = win32api.GetSystemDirectory() sysdir2 = os.path.join(sysdir, '../SYSTEM') windir = win32api.GetWindowsDirectory() _bpath = [sysdir, sysdir2, windir] _bpath.extend(string.split(os.environ.get('PATH', ''), os.pathsep)) return _bpath
def prefix(bindir = ''): if os.name != 'nt': return os.path.join('/usr/local', bindir) bind_subkey = "Software\\ISC\\BIND" hKey = None keyFound = True try: hKey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, bind_subkey) except: keyFound = False if keyFound: try: (namedBase, _) = win32api.RegQueryValueEx(hKey, "InstallDir") except: keyFound = False win32api.RegCloseKey(hKey) if keyFound: return os.path.join(namedBase, bindir) return os.path.join(win32api.GetSystemDirectory(), bindir)
def getWindowsPath(): """Return the path that Windows will search for dlls.""" global _bpath if _bpath is None: _bpath = [] if sys.platform == 'win32': try: import win32api except ImportError: print "Warning: Cannot determine your Windows or System directories because pywin32 is not installed." print "Warning: Either install it from http://sourceforge.net/projects/pywin32/ or" print "Warning: add them to your PATH if .dlls are not found." else: sysdir = win32api.GetSystemDirectory() sysdir2 = os.path.join(sysdir, '../SYSTEM') windir = win32api.GetWindowsDirectory() _bpath = [sysdir, sysdir2, windir] _bpath.extend(os.environ.get('PATH', '').split(os.pathsep)) return _bpath
def getWindowsPath(): """Return the path that Windows will search for dlls.""" global _bpath if _bpath is None: _bpath = [] if iswin: try: import win32api except ImportError: print "W: Cannot determine your Windows or System directories" print "W: Please add them to your PATH if .dlls are not found" print "W: or install http://sourceforge.net/projects/pywin32/" else: sysdir = win32api.GetSystemDirectory() sysdir2 = os.path.normpath(os.path.join( sysdir, '..', 'SYSTEM')) windir = win32api.GetWindowsDirectory() _bpath = [sysdir, sysdir2, windir] _bpath.extend(string.split(os.environ.get('PATH', ''), os.pathsep)) return _bpath
def look_for(fname): """prints paths for fname where fname can be found""" files = [] path = win32api.GetEnvironmentVariable('PATH') # try paths as described in MSDN dirs = [os.getcwd(), win32api.GetSystemDirectory(), win32api.GetWindowsDirectory()] + path.split(';') for d in dirs: fname2 = os.path.join(d, fname) if os.path.exists(fname2): if not fname2 in files: files.append(fname2) if len(files) > 1: print '===== SHARED LIBRARY WARNING: There is more than one: ' + fname + ' on the search path!! =====' if files: #print '\n'.join([f for f in files]) #Return the first found path return files[0] else: return None
def prefix(bindir=''): if os.name != 'nt': return os.path.join('/usr', bindir) hklm = win32con.HKEY_LOCAL_MACHINE bind_subkey = "Software\\ISC\\BIND" sam = win32con.KEY_READ h_key = None key_found = True # can fail if the registry redirected for 32/64 bits try: h_key = win32api.RegOpenKeyEx(hklm, bind_subkey, 0, sam) except: key_found = False # retry for 32 bit python with 64 bit bind9 if not key_found: key_found = True sam64 = sam | win32con.KEY_WOW64_64KEY try: h_key = win32api.RegOpenKeyEx(hklm, bind_subkey, 0, sam64) except: key_found = False # retry 64 bit python with 32 bit bind9 if not key_found: key_found = True sam32 = sam | win32con.KEY_WOW64_32KEY try: h_key = win32api.RegOpenKeyEx(hklm, bind_subkey, 0, sam32) except: key_found = False if key_found: try: (named_base, _) = win32api.RegQueryValueEx(h_key, "InstallDir") except: key_found = False win32api.RegCloseKey(h_key) if key_found: return os.path.join(named_base, bindir) return os.path.join(win32api.GetSystemDirectory(), bindir)
def __init__(self, app): QtGui.QMainWindow.__init__(self) self.setupUi(self) self.app = app self.db = None self.show() self.connect(self.btnQuery, SIGNAL('clicked()'), self.onBtnQueryClick) self.connect(self.btnExport, SIGNAL('clicked()'), self.onBtnExportClick) self.connect(self.tvMain, SIGNAL('itemClicked(QTreeWidgetItem*,int)'), self.onTreeItemClick_Main) self.connect(self.tvGoods, SIGNAL('itemClicked(QTreeWidgetItem*,int)'), self.onTreeItemClick_Goods) self.connect(self.btnImportInvoice, SIGNAL('clicked()'), self.onBtnImportInvoiceClick) self.connect(self.btnSave, SIGNAL('clicked()'), self.onBtnSaveProfile) self.connect(self.btnUpload, SIGNAL('clicked()'), self.onBtnUploadServerClick) # self.initUi() self.mtxthis = threading.Lock() self.confile = 'local.profile' self.libfile = '%s/taxexp.dll' % (win32api.GetSystemDirectory()) self.libfile = 'taxexp.dll' self.props = {'corpname': '', 'taxcode': '', 'addres': '', 'bank': ''} self.clients = {} # self.invoices={} self.initData() self.setWindowTitle(u'发票认证输出 %s' % VER)
def setConfig(): Pyro.config.PYRO_TRACELEVEL = 3 Pyro.config.PYRO_STORAGE = os.path.splitdrive( win32api.GetSystemDirectory())[0] + os.sep Pyro.config.PYRO_LOGFILE = "Pyro_ES_svc.log"
# # o Updated for wx namespace # o Tested with updated demo # import wx try: import win32ui import pywin.mfc.activex import win32com.client except ImportError: import sys if hasattr(sys, "frozen"): import os, win32api dllpath = os.path.join(win32api.GetSystemDirectory(), 'MFC71.DLL') if sys.version[:3] >= '2.4' and not os.path.exists(dllpath): message = "%s not found" % dllpath else: raise # original error message else: message = "ActiveXWrapper requires PythonWin. Please install the PyWin32 package." raise ImportError(message) ##from win32con import WS_TABSTOP, WS_VISIBLE WS_TABSTOP = 0x00010000 WS_VISIBLE = 0x10000000 #----------------------------------------------------------------------
# This returns the full path name of a shared library file name. # This works in similar ways on Windows on Linux. # The difference is in the PATH. # This is done only once because it should not change in a process lifetime. if lib_util.isPlatformWindows: import win32api library_search_path = [] path = win32api.GetEnvironmentVariable('PATH') # try paths as described in MSDN dirs = [ os.getcwd(), win32api.GetSystemDirectory(), win32api.GetWindowsDirectory() ] + path.split(';') dirs_lower = set() for one_dir in dirs: a_dir_lower = one_dir.lower() if a_dir_lower not in dirs_lower: dirs_lower.add(a_dir_lower) library_search_path.append(one_dir) if lib_util.isPlatformLinux: library_search_path = os.environ["PATH"].split(':') def FindPathFromSharedLibraryName(dll_filename):
import sys import os vars = { 'version': 'UNKNOWN', 'pyver': '%d%d' % (sys.version_info[0], sys.version_info[1]), } ISSPath = 'iguanaIR.iss' try: import win32api except: pass else: vars['sys32'] = win32api.GetSystemDirectory() # read the version from the CMakeLists.txt with open('../CMakeLists.txt') as input: for line in input: line = ' '.join(line.strip().split()) if line.startswith('Set(FULLVER '): vars['version'] = line.split(None, 1)[1][:-1] out = open(ISSPath, 'w') out.write(""" [Setup] AppName=IguanaIR AppVerName=IguanaIR %(version)s DefaultDirName={pf}\IguanaIR DefaultGroupName=IguanaIR
# * Copyright (C) 2007, IguanaWorks Incorporated (http://iguanaworks.net) # * Author: Joseph Dunn <*****@*****.**> # * # * Distributed under the GPL version 2. # * See LICENSE for license details. # */ import sys import os import win32api vars = { 'version': 'UNKNOWN', 'pyver': '%d%d' % (sys.version_info[0], sys.version_info[1]), 'sys32': win32api.GetSystemDirectory() } ISSPath = 'iguanaIR.iss' # read the version from the release.h with open('../release.h') as input: for line in input: line = ' '.join(line.strip().split()) if line.startswith('#define IGUANAIR_RELEASE '): vars['version'] = line.split(None, 2)[2][1:-1] out = open(ISSPath, 'w') out.write(""" [Setup] AppName=IguanaIR AppVerName=IguanaIR %(version)s
SPLASH.message(u'Инициализация') import logging import logging.handlers import os import atexit from ZODB.FileStorage import FileStorage from ZODB.DB import DB as ZDB from Crypto.Hash import SHA import win32api import marshal from Crypto.Cipher import Blowfish import types hash = SHA.new() d, p = os.path.splitdrive(win32api.GetSystemDirectory()) hash.update(str(win32api.GetSystemInfo())) hash.update(APPNAME) hash.update(str(win32api.GetVolumeInformation(d + '/'))) HWINFO = hash.hexdigest() cipher = Blowfish.new(HWINFO) egg = os.path.expanduser('~/' + APPNAME) HOMEDIR = unicode(egg, encoding=sys.getfilesystemencoding()) if not os.path.isdir(HOMEDIR): os.mkdir(HOMEDIR) logger = logging.getLogger() logger.setLevel(logging.DEBUG) formatter = logging.Formatter( "%(asctime)s - %(levelname)s - %(module)s: %(message)s")
def InvokeCommand(self, ci): mask, hwnd, verb, params, dir, nShow, hotkey, hicon = ci handle = win32process.CreateProcess( os.path.join(win32api.GetSystemDirectory(), "cmd.exe"), '', None, None, 0, win32process.CREATE_NEW_CONSOLE, None, self.folder, win32process.STARTUPINFO())
while i < len(fnms): fnm = os.path.join(dir, fnms[i]) if os.path.isdir(fnm): if ispackage(fnm): pkgdirs.append(fnm) i = i + 1 else: del fnms[i] else: i = i + 1 if _bpath is None: try: import win32api except ImportError: print "Cannot determine your Windows or System directories" print "Please add them to your PATH if .dlls are not found" _bpath = [] else: sysdir = win32api.GetSystemDirectory() sysdir2 = os.path.join(sysdir, '../SYSTEM') windir = win32api.GetWindowsDirectory() _bpath = [sysdir, sysdir2, windir] _bpath.extend(string.split(os.environ.get('PATH', ''), ';')) if _ppath is None: _ppath = expand(sys.path) def getpath(): """Return the path that Windows will search for dlls.""" return _bpath
_cp = int(_cp[2:]) ctypes.windll.kernel32.SetConsoleCP(_cp) ctypes.windll.kernel32.SetConsoleOutputCP(_cp) except (ValueError, TypeError): # Code page number in locale is not valid pass except ImportError: pass # Workaround for IPython thread issues with win32 comdlg32 if os.environ.get('IPYTHON', False): try: import win32gui, win32api try: win32gui.GetOpenFileNameW( File=win32api.GetSystemDirectory()[:2]) except win32gui.error: # This error is triggered intentionally pass except ImportError: # Unfortunately, pywin32 is not installed... pass # Set standard outputs encoding: # (otherwise, for example, print u"é" will fail) encoding = None try: import locale except ImportError: pass else: