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() FIXME: where could # this be needed? # 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 try: thumbFolder = os.listdir(os.path.join(os.path.split(str(desktopFiles))[0], "contents")) except OSError: thumbFolder = os.listdir(os.path.join(os.path.split(str(desktopFiles))[0], "content")) """ Appearantly the thumbnail names doesn't have a standard. 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, "utf8", "replace"), unicode(wallpaperDesc, "utf8", "replace"), 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.itemSelectionChanged.connect(self.setWallpaper) self.ui.checkBox.stateChanged.connect(self.disableWidgets) self.ui.buttonChooseWp.clicked.connect(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() FIXME: where could # this be needed? # 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 try: thumbFolder = os.listdir( os.path.join( os.path.split(str(desktopFiles))[0], "contents")) except OSError: thumbFolder = os.listdir( os.path.join( os.path.split(str(desktopFiles))[0], "content")) """ Appearantly the thumbnail names doesn't have a standard. 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, "utf8", "replace"), unicode(wallpaperDesc, "utf8", "replace"), 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.itemSelectionChanged.connect(self.setWallpaper) self.ui.checkBox.stateChanged.connect(self.disableWidgets) self.ui.buttonChooseWp.clicked.connect(self.selectWallpaper)
class Widget(QtGui.QWidget, Screen): screenSettings = {} screenSettings["hasChanged"] = False # title and description at the top of the dialog window title = i18n("Wallpaper") desc = i18n("Choose a Wallpaper") 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() FIXME: where could # this be needed? # 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 try: thumbFolder = os.listdir(os.path.join(os.path.split(str(desktopFiles))[0], "contents")) except OSError: thumbFolder = os.listdir(os.path.join(os.path.split(str(desktopFiles))[0], "content")) """ Appearantly the thumbnail names doesn't have a standard. 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, "utf8", "replace"), unicode(wallpaperDesc, "utf8", "replace"), 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.itemSelectionChanged.connect(self.setWallpaper) self.ui.checkBox.stateChanged.connect(self.disableWidgets) self.ui.buttonChooseWp.clicked.connect(self.selectWallpaper) def disableWidgets(self, state): if state: self.__class__.screenSettings["hasChanged"] = False self.ui.buttonChooseWp.setDisabled(True) self.ui.listWallpaper.setDisabled(True) else: self.__class__.screenSettings["hasChanged"] = True self.ui.buttonChooseWp.setDisabled(False) self.ui.listWallpaper.setDisabled(False) def setWallpaper(self): self.__class__.screenSettings["selectedWallpaper"] = self.ui.listWallpaper.currentItem().statusTip() self.__class__.screenSettings["hasChanged"] = True def selectWallpaper(self): selectedFile = QFileDialog.getOpenFileName(None, "Open Image", os.environ["HOME"], 'Image Files (*.png *.jpg *.bmp)') if selectedFile.isNull(): return else: item = QtGui.QListWidgetItem(self.ui.listWallpaper) wallpaperName = os.path.splitext(os.path.split(str(selectedFile))[1])[0] widget = WallpaperItemWidget(unicode(wallpaperName, "utf8", "replace"), unicode("Unknown"), selectedFile, self.ui.listWallpaper) item.setSizeHint(QSize(120, 170)) self.ui.listWallpaper.setItemWidget(item, widget) item.setStatusTip(selectedFile) self.ui.listWallpaper.setCurrentItem(item) self.resize(120, 170) def shown(self): pass def execute(self): return True
class Widget(QtGui.QWidget, Screen): screenSettings = {} screenSettings["hasChanged"] = False # title and description at the top of the dialog window title = i18n("Wallpaper") desc = i18n("Choose a Wallpaper") 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() FIXME: where could # this be needed? # 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 try: thumbFolder = os.listdir( os.path.join( os.path.split(str(desktopFiles))[0], "contents")) except OSError: thumbFolder = os.listdir( os.path.join( os.path.split(str(desktopFiles))[0], "content")) """ Appearantly the thumbnail names doesn't have a standard. 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, "utf8", "replace"), unicode(wallpaperDesc, "utf8", "replace"), 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.itemSelectionChanged.connect(self.setWallpaper) self.ui.checkBox.stateChanged.connect(self.disableWidgets) self.ui.buttonChooseWp.clicked.connect(self.selectWallpaper) def disableWidgets(self, state): if state: self.__class__.screenSettings["hasChanged"] = False self.ui.buttonChooseWp.setDisabled(True) self.ui.listWallpaper.setDisabled(True) else: self.__class__.screenSettings["hasChanged"] = True self.ui.buttonChooseWp.setDisabled(False) self.ui.listWallpaper.setDisabled(False) def setWallpaper(self): self.__class__.screenSettings[ "selectedWallpaper"] = self.ui.listWallpaper.currentItem( ).statusTip() self.__class__.screenSettings["hasChanged"] = True def selectWallpaper(self): selectedFile = QFileDialog.getOpenFileName( None, "Open Image", os.environ["HOME"], 'Image Files (*.png *.jpg *.bmp)') if selectedFile.isNull(): return else: item = QtGui.QListWidgetItem(self.ui.listWallpaper) wallpaperName = os.path.splitext( os.path.split(str(selectedFile))[1])[0] widget = WallpaperItemWidget( unicode(wallpaperName, "utf8", "replace"), unicode("Unknown"), selectedFile, self.ui.listWallpaper) item.setSizeHint(QSize(120, 170)) self.ui.listWallpaper.setItemWidget(item, widget) item.setStatusTip(selectedFile) self.ui.listWallpaper.setCurrentItem(item) self.resize(120, 170) def shown(self): pass def execute(self): return True