Example #1
0
 def doLoadImage(self, iconPathName):
     mingw_prefix = os.environ.get("MINGW_PREFIX")
     if mingw_prefix and iconPathName.find(mingw_prefix) >= 0:
         #python can deal with mixed win32 and unix paths,
         #but the native win32 LoadImage function cannot,
         #this happens when running from a mingw environment
         iconPathName = iconPathName.replace("/", "\\")
     icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
     try:
         assert os.path.exists(
             iconPathName), "icon '%s' not found" % iconPathName
         img_type = win32con.IMAGE_ICON
         if iconPathName.lower().split(".")[-1] in ("png", "bmp"):
             img_type = win32con.IMAGE_BITMAP
             icon_flags |= win32con.LR_CREATEDIBSECTION | win32con.LR_LOADTRANSPARENT
         log("LoadImage(%s) using image type=%s", iconPathName, {
             win32con.IMAGE_ICON: "ICON",
             win32con.IMAGE_BITMAP: "BITMAP",
         }.get(img_type))
         niwc = get_notifyicon_wnd_class()
         v = LoadImageW(niwc.hInstance, iconPathName, img_type, 0, 0,
                        icon_flags)
         assert v is not None
     except Exception:
         log.error("Error: failed to load icon '%s'",
                   iconPathName,
                   exc_info=True)
         return None
     else:
         log("LoadImage(%s)=%#x", iconPathName, v)
         return v
Example #2
0
 def doLoadImage(self, iconPathName):
     v = None
     if iconPathName:
         icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
         try:
             img_type = win32con.IMAGE_ICON
             if iconPathName.lower().split(".")[-1] in ("png", "bmp"):
                 img_type = win32con.IMAGE_BITMAP
                 icon_flags |= win32con.LR_CREATEDIBSECTION | win32con.LR_LOADTRANSPARENT
             log("LoadImage(%s) using image type=%s", iconPathName, {
                 win32con.IMAGE_ICON: "ICON",
                 win32con.IMAGE_BITMAP: "BITMAP",
             }.get(img_type))
             v = LoadImageW(NIwc.hInstance, iconPathName, img_type, 0, 0,
                            icon_flags)
         except:
             log.error("Failed to load icon at %s",
                       iconPathName,
                       exc_info=True)
     log("LoadImage(%s)=%s", iconPathName, v)
     return v