def __init__(self, *args): QtGui.QWidget.__init__(self, None) self.ui = Ui_wallpaperWidget() self.ui.setupUi(self) # Get system locale self.catLang = KGlobal.locale().language() isWide = lambda x: float(x[0]) / float(x[1]) >= 1.6 isSquare = lambda x: float(x[0]) / float(x[1]) < 1.6 # Get screen resolution rect = QtGui.QDesktopWidget().screenGeometry() # Get metadata.desktop files from shared wallpaper directory lst = KStandardDirs().findAllResources("wallpaper", "*metadata.desktop", KStandardDirs.Recursive) for desktopFiles in lst: parser = DesktopParser() parser.read(str(desktopFiles)) try: wallpaperTitle = parser.get_locale('Desktop Entry', 'Name[%s]' % self.catLang, '') except: wallpaperTitle = parser.get_locale('Desktop Entry', 'Name', '') try: wallpaperDesc = parser.get_locale('Desktop Entry', 'X-KDE-PluginInfo-Author', '') except: wallpaperDesc = "Unknown" # Get all files in the wallpaper's directory l = os.listdir( os.path.join( os.path.split(str(desktopFiles))[0], "contents/images")) wallpaperFile = os.path.split(str(desktopFiles))[0] wallpaperThumb = os.path.join( os.path.split(str(desktopFiles))[0], "contents/screenshot.png") # Insert wallpapers to listWidget. item = QtGui.QListWidgetItem(self.ui.listWallpaper) # Each wallpaper item is a widget. Look at widgets.py for more information. widget = WallpaperItemWidget(unicode(wallpaperTitle), unicode(wallpaperDesc), wallpaperThumb, self.ui.listWallpaper) item.setSizeHint(QSize(38, 110)) self.ui.listWallpaper.setItemWidget(item, widget) # Add a hidden value to each item for detecting selected wallpaper's path. item.setStatusTip(wallpaperFile) self.ui.listWallpaper.connect(self.ui.listWallpaper, SIGNAL("itemSelectionChanged()"), self.setWallpaper) self.ui.checkBox.connect(self.ui.checkBox, SIGNAL("stateChanged(int)"), self.disableWidgets) self.ui.buttonChooseWp.connect(self.ui.buttonChooseWp, SIGNAL("clicked()"), self.selectWallpaper)
def __init__(self, *args): QtGui.QWidget.__init__(self, None) self.ui = Ui_wallpaperWidget() self.ui.setupUi(self) # Get system locale self.catLang = KGlobal.locale().language() # Get screen resolution rect = QtGui.QDesktopWidget().screenGeometry() # Get metadata.desktop files from shared wallpaper directory lst = KStandardDirs().findAllResources("wallpaper", "*metadata.desktop", KStandardDirs.Recursive) for desktopFiles in lst: parser = DesktopParser() parser.read(str(desktopFiles)) try: wallpaperTitle = parser.get_locale('Desktop Entry', 'Name[%s]' % self.catLang, '') except: wallpaperTitle = parser.get_locale('Desktop Entry', 'Name', '') try: wallpaperDesc = parser.get_locale('Desktop Entry', 'X-KDE-PluginInfo-Author', '') except: wallpaperDesc = "Unknown" # Get all files in the wallpaper's directory thumbFolder = os.listdir( os.path.join(os.path.split(str(desktopFiles))[0], "contents")) """ Appearantly the thumbnail names doesn't have a standart. So we get the file list from the contents folder and choose the file which has a name that starts with "scre". File names I've seen so far; screenshot.jpg, screnshot.jpg, screenshot.png, screnshot.png """ wallpaperThumb = "" for thumb in thumbFolder: if thumb.startswith('scre'): wallpaperThumb = os.path.join( os.path.split(str(desktopFiles))[0], "contents/" + thumb) wallpaperFile = os.path.split(str(desktopFiles))[0] # Insert wallpapers to listWidget. item = QtGui.QListWidgetItem(self.ui.listWallpaper) # Each wallpaper item is a widget. Look at widgets.py for more information. widget = WallpaperItemWidget(unicode(wallpaperTitle), unicode(wallpaperDesc), wallpaperThumb, self.ui.listWallpaper) item.setSizeHint(QSize(120, 170)) self.ui.listWallpaper.setItemWidget(item, widget) # Add a hidden value to each item for detecting selected wallpaper's path. item.setStatusTip(wallpaperFile) self.ui.listWallpaper.connect(self.ui.listWallpaper, SIGNAL("itemSelectionChanged()"), self.setWallpaper) self.ui.checkBox.connect(self.ui.checkBox, SIGNAL("stateChanged(int)"), self.disableWidgets) self.ui.buttonChooseWp.connect(self.ui.buttonChooseWp, SIGNAL("clicked()"), self.selectWallpaper)