示例#1
0
 def __init__(self, parent=None):
     QtGui.QWidget.__init__(self, parent)
     # Setting the model/view and linking the two.
     self.model = GuestsModel()
     self.tagModel = QtGui.QStringListModel()
     self.view = GuestsView()
     self.view.setModel(self.model)
     self.view.setSelectionMode(
             QtGui.QAbstractItemView.ExtendedSelection)
     # Creation of the stackbar, adding button to it.
     self.gStackBar = StackBar()
     self.gStackBar.addItem(35, 'Add guest', 'images/plus.png', False,
                            'Add a guest at the end of the list')
     self.gStackBar.addItem(35, 'Del guest', 'images/minus.png', False,
                            '''Delete a selected guest.
         If any are selected, delete the last row''')
     self.gStackBar.addItem(55, 'Import\nguests',
                            'images/import.png', False,
                            'Import a list of guest from file')
     self.gStackBar.addItem(55, 'Export\nguests',
                            'images/export.png', False,
                            'Export a list of guest to a file')
     self.gStackBar.addItem(55, 'Manage tags', 'images/iconTags', False,
                            'Manage tags')
     # Setting function ton the stackbar buttons
     self.gStackBar.setFunction(0, self.addGuest)
     self.gStackBar.setFunction(1, self.delGuest)
     self.gStackBar.setFunction(4, self.manageTags)
     # Creating the vertical layout
     layout = QtGui.QVBoxLayout()
     layout.addWidget(self.gStackBar)
     layout.addWidget(self.view)
     self.setLayout(layout)
     # Temporary dimension of the widget.
     self.setGeometry(300, 300, 500, 500)
示例#2
0
class Widget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        # Setting the model/view and linking the two.
        self.model = GuestsModel()
        self.tagModel = QtGui.QStringListModel()
        self.view = GuestsView()
        self.view.setModel(self.model)
        self.view.setSelectionMode(
                QtGui.QAbstractItemView.ExtendedSelection)
        # Creation of the stackbar, adding button to it.
        self.gStackBar = StackBar()
        self.gStackBar.addItem(35, 'Add guest', 'images/plus.png', False,
                               'Add a guest at the end of the list')
        self.gStackBar.addItem(35, 'Del guest', 'images/minus.png', False,
                               '''Delete a selected guest.
            If any are selected, delete the last row''')
        self.gStackBar.addItem(55, 'Import\nguests',
                               'images/import.png', False,
                               'Import a list of guest from file')
        self.gStackBar.addItem(55, 'Export\nguests',
                               'images/export.png', False,
                               'Export a list of guest to a file')
        self.gStackBar.addItem(55, 'Manage tags', 'images/iconTags', False,
                               'Manage tags')
        # Setting function ton the stackbar buttons
        self.gStackBar.setFunction(0, self.addGuest)
        self.gStackBar.setFunction(1, self.delGuest)
        self.gStackBar.setFunction(4, self.manageTags)
        # Creating the vertical layout
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.gStackBar)
        layout.addWidget(self.view)
        self.setLayout(layout)
        # Temporary dimension of the widget.
        self.setGeometry(300, 300, 500, 500)

    def addGuest(self):
        print "Creating a row..."
        self.model.insertRows(self.model.rowCount(), 1)
        self.view.openPersistentEditor(
                self.model.index(self.model.rowCount() - 1, 2))
        self.view.openPersistentEditor(
                self.model.index(self.model.rowCount() - 1, 3))

    def delGuest(self):
        print "Deleting a list of selected rows"
        selection = self.view.selectionModel()
        l = reversed(list(skip_duplicates([item.row()
                                           for item in selection.selectedIndexes()])))
        for row in l:
            self.model.removeRows(row, 1)

    def manageTags(self):
        tagWindow = TagWindow()
        self.connect(tagWindow, QtCore.SIGNAL("closingTagWindow(PyQt_PyObject)"))
        tagWindow.setWindowModality(QtCore.Qt.ApplicationModal)
        tagWindow.show()