#------------------------------------------------------------------------------# # Filename: importer.py # # Created: 06/20/2015 # # Author: BoĊĦtjan Mejak # # E-mail: bostjan.xperia@gmail.com # # License: GPLv3 # #------------------------------------------------------------------------------# """ The importer module exposes a function named tryToImport() which takes one keyword argument named module, i.e. it takes a module that the user tries to import. If the import fails, an error message box is shown. """ import importlib def tryToImport(module): """ Show a message box if a user-given module can't be imported. """ try: moduleObject = importlib.import_module(module) globals()[module] = moduleObject except ImportError as module: import ctypes import sys PARENT = None MESSAGE = u"{importedModule} is missing.".format(importedModule=module.name) CAPTION = u"Application Error" STYLE = 0 | 16 # An error message box with an OK button ctypes.windll.user32.MessageBoxW(PARENT, MESSAGE, CAPTION, STYLE) sys.exit("Not all library dependencies were met.")