예제 #1
0
    def updateQuoteWidget(self, authorid):
        self.session_reinit()
        author = [author for author in
                  get_authors(self.session) if author.id == authorid][0]
        all_quotes = get_quotes(self.session)
        quotes = [quote for quote in all_quotes if quote.author == author.id]
        quoteids = [quote.id for quote in quotes]

        # check if there are quotes in db without a QListWidgetItem
        for quote in quotes:
            if self.checkIfQuoteNeedsNewItem(quote.id):
                self.quotesListWidget.addItem(QuoteItem(
                    quote.text,
                    quote.id,
                    self.quotesListWidget))

        # check if there are QListWidgetItems without an quote in db
        for quoteItem in [self.quotesListWidget.item(row) for row
                          in range(self.quotesListWidget.count())]:
            if quoteItem.quoteid not in quoteids:
                if self.quotesListWidget.currentItem() is not None:
                    if quoteItem.quoteid\
                            == self.quotesListWidget.currentItem().quoteid:
                        # the item that is currently selected is being deleted.
                        self.deleteQuotePushButton.setEnabled(False)
                row = self.quotesListWidget.row(quoteItem)
                self.quotesListWidget.takeItem(row)
                self.quotesListWidget.clearSelection()

        self.quotesListWidget.sortItems()
예제 #2
0
 def author_selected(self, authorItem):
     self.quotesListWidget.clear()
     self.deleteQuotePushButton.setEnabled(False)
     self.addQuotePushButton.setEnabled(True)
     self.deleteAuthorPushButton.setEnabled(True)
     self.session_reinit()
     for author in get_authors(self.session):
         if author.id == authorItem.authorid:
             for quote in author.quotes:
                 self.quotesListWidget.addItem(QuoteItem(
                     quote.text, quote.id, self.quotesListWidget))
예제 #3
0
    def updateAuthorWidget(self):
        self.session_reinit()
        authors = get_authors(self.session)
        authorids = [author.id for author in authors]
        needQuoteUpdate = True

        # check if there are authors in db without a QListWidgetItem
        for author in authors:
            if self.checkIfAuthorNeedsNewItem(author.id):
                self.authorsListWidget.addItem(AuthorItem(
                    author.firstname,
                    author.lastname,
                    author.id,
                    self.authorsListWidget))

        # check if there are QListWidgetItems without an author in db
        for authorItem in [self.authorsListWidget.item(row) for row
                           in range(self.authorsListWidget.count())]:
            if authorItem.authorid not in authorids:
                if self.authorsListWidget.currentItem() is not None:
                    if authorItem.authorid\
                            == self.authorsListWidget.currentItem().authorid:
                        # the item that is currently selected is being deleted.
                        self.quotesListWidget.clear()
                        needQuoteUpdate = False
                        self.addQuotePushButton.setEnabled(False)
                        self.deleteQuotePushButton.setEnabled(False)
                        self.deleteAuthorPushButton.setEnabled(False)
                row = self.authorsListWidget.row(authorItem)
                self.authorsListWidget.takeItem(row)
                self.authorsListWidget.clearSelection()

        self.authorsListWidget.sortItems()
        if self.authorsListWidget.currentItem() is not None:
            if needQuoteUpdate:
                self.updateQuoteWidget(
                    self.authorsListWidget.currentItem().authorid)