コード例 #1
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()

        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)
コード例 #2
0
ファイル: ScrStyle.py プロジェクト: pars-linux/uludag
    def __init__(self, *args):
        QtGui.QWidget.__init__(self, None)
        self.ui = Ui_styleWidget()
        self.ui.setupUi(self)

        self.styleDetails = {}
        self.catLang = KGlobal.locale().language()

        config = KConfig("kwinrc")
        group = config.group("Desktops")
        defaultDesktopNumber = int(group.readEntry('Number'))

        self.ui.spinBoxDesktopNumbers.setValue(defaultDesktopNumber)
        lst2 = glob.glob1("/usr/kde/4/share/apps/kaptan/gui/styles", "*.style")

        for desktopFiles in lst2:
            parser = DesktopParser()
            parser.read("/usr/kde/4/share/apps/kaptan/gui/styles/" +
                        str(desktopFiles))
            try:
                styleName = unicode(
                    parser.get_locale('Style', 'name[%s]' % self.catLang, ''))
            except:
                styleName = unicode(parser.get_locale('Style', 'name', ''))
            try:
                styleDesc = unicode(
                    parser.get_locale('Style',
                                      'description[%s]' % self.catLang, ''))
            except:
                styleDesc = unicode(
                    parser.get_locale('Style', 'description', ''))
            try:
                # TODO find a fallback values for these & handle exceptions seperately.
                #styleApplet = parser.get_locale('Style', 'applets', '')
                panelPosition = parser.get_locale('Style', 'panelPosition', '')
                #styleColorScheme = parser.get_locale('Style', 'colorScheme', '')
                widgetStyle = unicode(
                    parser.get_locale('Style', 'widgetStyle', ''))
                desktopTheme = unicode(
                    parser.get_locale('Style', 'desktopTheme', ''))
                colorScheme = unicode(
                    parser.get_locale('Style', 'colorScheme', ''))
                iconTheme = unicode(parser.get_locale('Style', 'iconTheme',
                                                      ''))
                windowDecoration = unicode(
                    parser.get_locale('Style', 'windowDecoration', ''))
                styleThumb = unicode(
                    os.path.join("/usr/kde/4/share/apps/kaptan/gui/styles/",
                                 parser.get_locale('Style', 'thumbnail', '')))

                colorDict = {}
                colorDir = "/usr/kde/4/share/apps/color-schemes/"
                self.Config = ConfigParser()
                self.Config.optionxform = str
                color = colorDir + colorScheme + ".colors"
                if not os.path.exists(color):
                    color = colorDir + "Oxygen.colors"

                self.Config.read(color)
                #colorConfig= KConfig("kdeglobals")
                for i in self.Config.sections():
                    #colorGroup = colorConfig.group(str(i))
                    colorDict[i] = {}
                    for key, value in self.ConfigSectionMap(i).items():
                        colorDict[i][key] = value
                        #colorGroup.writeEntry(str(key), str(value))

                self.styleDetails[styleName] = {
                    "description": styleDesc,
                    "widgetStyle": widgetStyle,
                    "colorScheme": colorDict,
                    "desktopTheme": desktopTheme,
                    "iconTheme": iconTheme,
                    "windowDecoration": windowDecoration,
                    "panelPosition": panelPosition
                }

                item = QtGui.QListWidgetItem(self.ui.listStyles)
                widget = StyleItemWidget(unicode(styleName),
                                         unicode(styleDesc), styleThumb,
                                         self.ui.listStyles)
                self.ui.listStyles.setItemWidget(item, widget)
                item.setSizeHint(QSize(120, 170))
                item.setStatusTip(styleName)
            except:
                print "Warning! Invalid syntax in ", desktopFiles

        self.ui.listStyles.connect(self.ui.listStyles,
                                   SIGNAL("itemSelectionChanged()"),
                                   self.setStyle)
        self.ui.comboBoxDesktopType.connect(
            self.ui.comboBoxDesktopType, SIGNAL("activated(const QString &)"),
            self.setDesktopType)
        self.ui.spinBoxDesktopNumbers.connect(
            self.ui.spinBoxDesktopNumbers,
            SIGNAL("valueChanged(const QString &)"), self.addDesktop)
コード例 #3
0
ファイル: ScrWallpaper.py プロジェクト: pars-linux/uludag
    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)