Exemplo n.º 1
0
    def __init__(self, *args):
        QtGui.QWidget.__init__(self, None)
        self.ui = Ui_wallpaperWidget()
        self.ui.setupUi(self)

        # Get system locale
        self.catLang = Desktop.common.getLanguage()

        # Get screen resolution
        self.rect = QtGui.QDesktopWidget().screenGeometry()

        # Get metadata.desktop files from shared wallpaper directory
        lst = Desktop.wallpaper.getWallpaperSettings()

        self.lst = lst
        for wallpaper in lst:
            # 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(wallpaper["wallpaperTitle"]),
                                         unicode(wallpaper["wallpaperDesc"]),
                                         wallpaper["wallpaperThumb"],
                                         self.ui.listWallpaper)
            if ctx.Pds.session.Name == "KDE":
                item.setSizeHint(QSize(120, 170))
            else:
                item.setSizeHint(QSize(130, 160))
            self.ui.listWallpaper.setItemWidget(item, widget)
            # Add a hidden value to each item for detecting selected wallpaper's path.
            item.setStatusTip(wallpaper["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)
Exemplo n.º 2
0
    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)