File indexing completed on 2024-04-28 07:51:05

0001 """
0002 Copyright (C) 2008-2016 Wolfgang Rohdewald <wolfgang@rohdewald.de>
0003 
0004 partially based on C++ code from:
0005 Copyright (C) 2006 Mauricio Piacentini <mauricio@tabuleiro.com>
0006 
0007 SPDX-License-Identifier: GPL-2.0
0008 
0009 """
0010 
0011 from qt import QWidget, QLineEdit
0012 from background import Background
0013 from common import Internal
0014 from guiutil import loadUi
0015 
0016 
0017 class BackgroundSelector(QWidget):
0018 
0019     """presents all available backgrounds with previews"""
0020 
0021     def __init__(self, parent):
0022         super().__init__(parent)
0023         loadUi(self)
0024         self.kcfg_backgroundName = QLineEdit(self)
0025         self.kcfg_backgroundName.setVisible(False)
0026         self.kcfg_backgroundName.setObjectName('kcfg_backgroundName')
0027         self.setUp()
0028 
0029     def setUp(self):
0030         """fill the selector"""
0031 
0032         # The lineEdit widget holds our background path, but the user does
0033         # not manipulate it directly
0034         self.kcfg_backgroundName.hide()
0035 
0036         self.backgroundNameList.currentRowChanged.connect(
0037             self.backgroundRowChanged)
0038         self.kcfg_backgroundName.textChanged.connect(
0039             self.backgroundNameChanged)
0040         self.backgroundList = Background.available()
0041         for aset in self.backgroundList:
0042             self.backgroundNameList.addItem(aset.name)
0043         self.kcfg_backgroundName.setText(Internal.Preferences.backgroundName)
0044 
0045     def backgroundNameChanged(self, name):
0046         """the name changed: update the current row"""
0047         igrindex = 0
0048         for idx, aset in enumerate(self.backgroundList):
0049             if aset.desktopFileName == name:
0050                 igrindex = idx
0051                 break
0052         self.backgroundNameList.setCurrentRow(igrindex)
0053 
0054     def backgroundRowChanged(self):
0055         """user selected a new background, update our information about it and paint preview"""
0056         selBackground = self.backgroundList[
0057             self.backgroundNameList.currentRow()]
0058         self.kcfg_backgroundName.setText(selBackground.desktopFileName)
0059         self.backgroundAuthor.setText(selBackground.author)
0060         self.backgroundContact.setText(selBackground.authorEmail)
0061         self.backgroundDescription.setText(selBackground.description)
0062         selBackground.setPalette(self.backgroundPreview)
0063         self.backgroundPreview.setAutoFillBackground(True)