Exemplo n.º 1
0
 def readFromLnk(self, path):
   if not os.path.exists(path):
     path = self.slot.winPathToUnix(path)
   if not os.path.exists(path):
     raise Exception(self.tr("File does not exist"))
   try:
     lnk = shortcutlib.readLnk(path)
   except:
     print >>sys.stderr, "Failed to read %s" % path
     raise
   name = os.path.splitext(os.path.basename(path))[0]
   self.setProgram(lnk.target)
   self.setArguments(str(lnk.commandLineArgs) if lnk.commandLineArgs else "")
   self.setWorkingDirectory(str(lnk.workingDirectory) if lnk.workingDirectory else "")
   if lnk.description:
     self["description"] = lnk.description
   if lnk.customIcon:
     iconPath = self.slot.winPathToUnix(str(lnk.customIcon), "c:\windows")
   else:
     iconPath = self.slot.winPathToUnix(lnk.target)
   if os.path.splitext(iconPath)[1].lower() == '.exe':
     icons = icolib.readExeIcons(iconPath, lnk.iconIndex)
     if not icons:
       icons = icolib.readExeIcons(iconPath)
   else:
     icons = icolib.readIcoIcons(iconPath)
   bestIco = icolib.bestIcon(icons)
   if bestIco:
     self.setIcon(bestIco.data)
Exemplo n.º 2
0
 def _loadIcons(self, path):
   self.filename.setText(path)
   if not os.path.exists(path):
     return
   icons = []
   if path.lower().endswith(".exe"):
     icons = icolib.readExeIcons(path)
   elif path.lower().endswith(".ico"):
     icons = icolib.readIcoIcons(path)
   else:
     with open(path) as fp:
       data = fp.read()
     image = loadIconFromData(data, scale=(32, 32))
     if image:
       IconListItem(self.iconView, os.path.basename(path), image, iconData=data)
   for icon in icons:
     image = loadIconFromData(icon.data, scale=(32, 32))
     if image:
       IconListItem(self.iconView, "%dx%d %d-bit" % (icon.width, icon.height, icon.bits), image, iconData=icon.data)