示例#1
0
class ItemListWidget(QWidget):
    def __init__(self, parent, itemManager):
        QWidget.__init__(self, parent)
        self.setLayout(QVBoxLayout(self))
        self.im = itemManager
        self.updateUi()
        
    def updateUi(self):
        self.nbItems = 0
        self.itemList = ItemList(self, self.im)
        self.layout().addWidget(self.itemList)
        self._addButtons()
        
    def _addButtons(self):
        self._addButton = QPushButton("add", self)
        self._addButton.setIcon(KIcon("list-add"))
        self.connect(self._addButton, SIGNAL("clicked()"), self._createItem)
        
        self._editButton = QPushButton("edit", self)
        self._editButton.setIcon(KIcon("list-add"))
        self._editButton.setEnabled(False)
        self.connect(self._editButton, SIGNAL("clicked()"), self.itemList.showEdit)
        
        self._deleteButton = QPushButton("delete", self)
        self._deleteButton.setIcon(KIcon("edit-delete"))
        self._deleteButton.setEnabled(False)
        self.connect(self._deleteButton, SIGNAL("clicked()"), self.itemList.delete)
        
        hbox = QHBoxLayout()
        hbox.insertStretch(0)
        hbox.addWidget(self._addButton)
        hbox.addWidget(self._editButton)
        hbox.addWidget(self._deleteButton)
        self.layout().addLayout(hbox)
        
        self.connect(self.itemList, SIGNAL("itemSelectionChanged()"), self._enableButtons)
        
    def _enableButtons(self):
        if self.itemList.currentItem():
            self._editButton.setEnabled(True)
            self._deleteButton.setEnabled(True)
        else:
            self._editButton.setEnabled(False)
            self._deleteButton.setEnabled(False)
            
    def _createItem(self):
        theme = Plasma.Theme.defaultTheme()
        font = theme.font(Plasma.Theme.DefaultFont)
        color = theme.color(Plasma.Theme.TextColor)
        item = self.im.createItem(font, color)
        self.itemList.add(item)
        
    def _deleteItem(self):
        pass
示例#2
0
 def updateUi(self):
     self.nbItems = 0
     self.itemList = ItemList(self, self.im)
     self.layout().addWidget(self.itemList)
     self._addButtons()