コード例 #1
0
    def updateValues(self):
        try:

            counter_books = book_session.query(Book).count()

            genres = book_session.query(Genre).all()
            self.genre_series.clear()
            for genre in genres:
                genre_books = book_session.query(Book).filter_by(
                    genre_id=genre.id).count()
                self.genre_series.append(genre.name,
                                         genre_books / counter_books)

            for i in range(len(self.genre_series)):
                slice = QPieSlice()
                slice = self.genre_series.slices()[i]
                slice.setLabelVisible(True)

            authors = book_session.query(Author).all()
            self.author_series.clear()
            for author in authors:
                author_books = book_session.query(Book).filter_by(
                    author_id=author.id).count()
                self.author_series.append(author.name + " " + author.surname,
                                          author_books / counter_books)

            for i in range(len(self.author_series)):
                slice = QPieSlice()
                slice = self.author_series.slices()[i]
                slice.setLabelVisible(True)

            self.status_series.clear()
            all_status = book_session.query(BookStatus).all()
            counter_status = {}
            for status in all_status:
                book_status = book_session.query(Book).filter_by(
                    status_id=status.id).count()
                self.status_series.append(status.name,
                                          book_status / counter_books)

            for i in range(len(self.status_series)):
                slice = QPieSlice()
                slice = self.status_series.slices()[i]
                slice.setLabelVisible(True)
                if slice.label() == 'Not readed':
                    slice.setColor(QColor(255, 0, 0))
                elif slice.label() == 'In progress':
                    slice.setColor(QColor(0, 0, 255))
                elif slice.label() == 'Readed':
                    slice.setColor(QColor(0, 100, 0))

        except ZeroDivisionError:
            home_window = self.parent().findChild(QWidget, 'home_window')
            self.parent().setCurrentWidget(home_window)
            openDialog(QMessageBox.Critical, 'Insufficient data for chart',
                       'Error')
コード例 #2
0
    def updateValues(self):
        try:
            counter_movies = movie_session.query(Movie).count()

            genres = movie_session.query(Genre).all()
            self.genre_series.clear()
            for genre in genres:
                genre_movies = movie_session.query(Movie).filter_by(genre_id=genre.id).count()
                self.genre_series.append(genre.name, genre_movies/counter_movies)

            for i in range(len(self.genre_series)):
                slice = QPieSlice()
                slice = self.genre_series.slices()[i]
                slice.setLabelVisible(True)

            film_directors = movie_session.query(Film_director).all()
            self.filmDirector_series.clear()
            for film_director in film_directors:
                filmDirector_movie = movie_session.query(Movie).filter_by(film_director_id=film_director.id).count()
                self.filmDirector_series.append(film_director.name + " " + film_director.surname, filmDirector_movie/counter_movies)

            for i in range(len(self.filmDirector_series)):
                slice = QPieSlice()
                slice = self.filmDirector_series.slices()[i]
                slice.setLabelVisible(True)

            self.status_series.clear()
            all_status = movie_session.query(MovieStatus).all()
            counter_status = {}
            for status in all_status:
                movie_status = movie_session.query(Movie).filter_by(status_id = status.id).count()
                self.status_series.append(status.name, movie_status/counter_movies)

            for i in range(len(self.status_series)):
                slice = QPieSlice()
                slice = self.status_series.slices()[i]
                slice.setLabelVisible(True)
                if slice.label() == 'Not watched':
                    slice.setColor(QColor(255, 0, 0))
                elif slice.label() == 'Watched':
                    slice.setColor(QColor(0, 100, 0))
        
        except ZeroDivisionError:
            home_window = self.parent().findChild(QWidget, 'home_window')
            self.parent().setCurrentWidget(home_window)
            openDialog(QMessageBox.Critical, 'Insufficient data for chart', 'Error')

            
コード例 #3
0
ファイル: charts.py プロジェクト: bitxer/ICT1002-Py
    def create(self):
        '''
        Creates Chart Data and returns
        '''
        slices = QPieSlice()
        for x in range(0, len(self.chartseries.slices())):
            slices = self.chartseries.slices()[x]
            slices.setLabelVisible()
            slices.setLabel(str(slices.label()) + " : " + str(slices.value()))

        chart = QChart()
        chart.addSeries(self.chartseries)
        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.setTitle(self.title)
        # chart.setTheme(5)
        chart.legend().setVisible(False)
        chart.legend().attachToChart()
        return chart