class TokenPieChart(QChartView): """ Chart that displays certaing tokens with their respective balance on a Pie Chart. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.series = QPieSeries() self.chart = QChart() # self.chart.setTheme(QChart.ChartThemeBrownSand) self.chart.setTheme(QChart.ChartThemeQt) self.chart.legend().hide() self.chart.addSeries(self.series) self.chart.createDefaultAxes() self.chart.setAnimationOptions(QChart.SeriesAnimations) self.chart.setBackgroundBrush(QBrush(QColor('#19232d'))) self.chart.setTitle("") self.chart.setTitleBrush(QBrush(QColor('white'))) self.chart.legend().setAlignment(Qt.AlignBottom) self.setChart(self.chart) self.setRenderHint(QPainter.Antialiasing) self.setStyleSheet('border: 0px') # self.setMinimumWidth(300) def updateWithAccount(self, account): """Changes the series so that only tokens from a certain account are shown""" entries_with_account = cbalances.get_entries_with_account(account) self.series.clear() for entry in entries_with_account: token = entry[1].upper() amount = entry[2] amount_btc = prices.to_btc(token, amount) self.series.append(token, amount_btc) self.showSliceLabels() def allMode(self): """Changes the series to show all tokens""" self.series.clear() data = cbalances.get_all_tokens_with_amount() for d in data: token = d[0].upper() amount = d[1] total_in_btc = prices.to_btc(token, amount) self.series.append(token, total_in_btc) self.showSliceLabels() self.hideLittleSlices() def showSliceLabels(self): """ Formats the Slices so that they show the percentage """ for slce in self.series.slices(): slce.setLabel("{} {}% ({})".format( slce.label(), int(100*slce.percentage()), str(round(slce.value(), 4)) + " BTC")) slce.setLabelPosition(QPieSlice.LabelInsideNormal) # slce.setLabelPosition(QPieSlice.LabelOutside) slce.setLabelVisible(True) self.hideLittleSlices() def selectSlice(self, account): """ Explodes a certaing slice that corresponds to an account """ for slce in self.series.slices(): if slce.label().split(' ')[0] == account: # Explode slice slce.setExploded(True) font = QFont() font.setBold(True) font.setWeight(QFont.ExtraBold) font.setUnderline(True) slce.setLabelFont(font) slce.setLabelColor(QColor("white")) slce.setLabelPosition(QPieSlice.LabelOutside) else: slce.setExploded(False) slce.setLabelFont(QFont()) # # slce.setLabelPosition(QPieSlice.LabelInsideTangential) font = QFont() slce.setLabelColor(QColor("#3f3f39")) slce.setLabelFont(font) slce.setLabelPosition(QPieSlice.LabelInsideNormal) self.hideLittleSlices(selected=account) def hideLittleSlices(self, selected=''): """ If a slice is not big enough for the label to be properly seen, the label gets hidden """ for slce in self.series.slices(): if slce.angleSpan() < 5 and slce.label().split(' ')[0] != selected: # Slice too little to show, and it's not selected slce.setLabelVisible(False) else: slce.setLabelVisible(True)
class AccountPieChart(QChartView): """ Chart that displays certaing accounts with their respective balance on a Pie Chart. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.series = QPieSeries() self.chart = QChart() self.chart.setTheme(QChart.ChartThemeDark) self.chart.legend().hide() self.chart.addSeries(self.series) self.chart.createDefaultAxes() self.chart.setAnimationOptions(QChart.SeriesAnimations) self.chart.setBackgroundBrush(QBrush(QColor('#19232d'))) self.chart.setTitle("") self.chart.setTitleBrush(QBrush(QColor('white'))) self.chart.legend().setAlignment(Qt.AlignBottom) self.chart.legend().setLabelColor(QColor('white')) self.setChart(self.chart) self.setRenderHint(QPainter.Antialiasing) self.setStyleSheet("border: 0px") # self.setMinimumWidth(300) def updateWithToken(self, token): """ Updates series with all accounts that have a certain token """ entries_with_token = cbalances.get_entries_with_token(token) self.series.clear() for entry in entries_with_token: account = entry[0] amount = entry[2] self.series.append(account, amount) self.showSliceLabels(token) def allMode(self): """Updates series with all accounts""" self.series.clear() data = cbalances.get_all_accounts_with_amount() for d in data: account = d[0] balance = d[1] self.series.append(account, balance) self.showSliceLabels("btc") self.hideLittleSlices() def showSliceLabels(self, token): """ Formats the Slices so that they show the percentage """ for slce in self.series.slices(): slce.setLabel("{} {}% ({})".format( slce.label(), int(100*slce.percentage()), str(prices.to_btc(token, slce.value())) + " BTC")) slce.setLabelPosition(QPieSlice.LabelInsideNormal) # slce.setLabelPosition(QPieSlice.LabelOutside) slce.setLabelColor(QColor('white')) slce.setLabelVisible(True) self.hideLittleSlices() def selectSlice(self, account): """ Explodes a certaing slice that corresponds to an account """ for slce in self.series.slices(): if account in slce.label(): # Explode slice slce.setExploded(True) font = QFont() font.setBold(True) font.setUnderline(True) slce.setLabelFont(font) slce.setLabelPosition(QPieSlice.LabelOutside) else: slce.setExploded(False) slce.setLabelFont(QFont()) # slce.setLabelPosition(QPieSlice.LabelInsideTangential) slce.setLabelPosition(QPieSlice.LabelInsideNormal) self.hideLittleSlices(selected=account) def hideLittleSlices(self, selected=''): """ If a slice is not big enough for the label to be properly seen, the label gets hidden """ for slce in self.series.slices(): if slce.angleSpan() < 5 and slce.label().split(' ')[0] != selected: # Slice too little to show, and it's not selected slce.setLabelVisible(False) else: slce.setLabelVisible(True)
class Pencere(QtWidgets.QWidget): def __init__(self): super().__init__() self.timer = QTimer() # timer nesnesi oluşturduk self.init_ui() self.w = Pencere2() def init_ui(self): # window(ekranın özellikleri oluyor burada) timerDegeri = 1000 self.ozellikler = getSystemInfo() self.timer.start(timerDegeri) # timer çalıştırdık # boş pasta grafiklerimizi oluşturduk self.PastaGrafik_islemci = QPieSeries() self.PastaGrafik_ram = QPieSeries() self.PastaGrafik_hdd = QPieSeries() self.timer.timeout.connect( self.Loop) # her saniye click adlı metodu çağırır # Chartları oluşturduk chart = QChart() chart.legend().hide() chart.addSeries(self.PastaGrafik_islemci) chart.createDefaultAxes() chart.setTitle("CPU Kullanımı") # Chart isimleri verdik chartview = QChartView(chart) chart.setOpacity(0.7) chart.setTheme(QChart.ChartThemeDark) chart2 = QChart() chart2.legend().hide() chart2.addSeries(self.PastaGrafik_ram) chart2.createDefaultAxes() chart2.setTitle("RAM Kullanımı") chartview2 = QChartView(chart2) chart2.setOpacity(0.7) chart2.setTheme(QChart.ChartThemeDark) chart3 = QChart() chart3.legend().hide() chart3.addSeries(self.PastaGrafik_hdd) chart3.createDefaultAxes() chart3.setTitle("Hard Disk Kullanımı") chartview3 = QChartView(chart3) chart3.setOpacity(0.7) chart3.setTheme(QChart.ChartThemeDark) # Düzenli bir görünüm için v_box oluşturduk. Grafikleri Vbox'a koyduk # Bu sayede grafikler alt alta göründü. v_box = QtWidgets.QVBoxLayout() v_box.addWidget(chartview) v_box.addWidget(chartview2) v_box.addWidget(chartview3) h_box = QtWidgets.QHBoxLayout( ) # h box oluşturup grafiklerin bulunduğu v boxı oluşturduğumuz h boxa koyduk h_box.addLayout(v_box) v_box2 = QtWidgets.QVBoxLayout( ) # Sistem bilgilerinin yazılacağı labeller için ikinci bir vbox oluşturduk h_box.addLayout(v_box2) # 2. vbox'ımızı hbox'ımıza koyduk # Pencereye Hbox layoutumuzu atadık self.setLayout(h_box) self.setStyleSheet("background-color: black;") # Pencere boyut ayarlaması ve gösterilmesi self.setGeometry(800, 100, 500, 500) # this will hide the title bar self.setWindowFlag(Qt.FramelessWindowHint) # creating a label widget # show all the widgets self.show() def Loop(self): # Grafiklerimizi temizledik self.PastaGrafik_ram.clear() self.PastaGrafik_islemci.clear() self.PastaGrafik_hdd.clear() # İşlemci kullanımı ve ram kullanımını bulduk self.islemci_kullanimi = psutil.cpu_percent(0) self.ram_kullanimi = psutil.virtual_memory()[2] # İşlemci kullanımını 1. grafiğimize ekledik self.PastaGrafik_islemci.append("işlemci Kullanımı", self.islemci_kullanimi * 3.6) self.PastaGrafik_islemci.append("Boşta", (100 - self.islemci_kullanimi) * 3.6) # Ram kullanımını 2. grafiğimize ekledik self.PastaGrafik_ram.append("Ram Kullanımı", self.ram_kullanimi * 3.6) self.PastaGrafik_ram.append("Boşta", (100 - self.ram_kullanimi) * 3.6) # Hard disk kullanımını 3. grafiğimize ekledik self.kullanilan = self.ozellikler['hard-drive used'] self.bosta = self.ozellikler['hard-drive free'] self.PastaGrafik_hdd.append("Kullanılan", float(self.kullanilan)) self.PastaGrafik_hdd.append("Boşta", float(self.bosta))
class StatisticsView(QWidget): def __init__(self, parent): super().__init__(parent) self.ui = Ui_statistics_window() self.ui.setupUi(self) self.genre_series = QPieSeries() self.filmDirector_series = QPieSeries() self.status_series = QPieSeries() self.createChart('Movie percentages genre', self.genre_series) self.createChart('Movie percentages film director', self.filmDirector_series) self.createChart('Movie percentages status', self.status_series) self.show() def getValues(self): movies = movie_session.query(Movie).count() filmDirectors = movie_session.query(Film_director).count() genres = movie_session.query(Genre).count() self.ui.moviesCounter_label.setText(str(movies)) self.ui.filmDirectorsCounter_label.setText(str(filmDirectors)) self.ui.genresCounter_label.setText(str(genres)) def createChart(self, title, series): chart = QChart() chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle(title) #sslice.setLabel("{:.1f}%".format(100 * slice.percentage())) chartview = QChartView(chart) chartview.setRenderHint(QPainter.Antialiasing) #setChart(chartview) self.ui.pieChart_container.addWidget(chartview) 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')
class StatisticsView(QWidget): def __init__(self, parent): super().__init__(parent) self.ui = Ui_statistics_window() self.ui.setupUi(self) self.genre_series = QPieSeries() self.author_series = QPieSeries() self.status_series = QPieSeries() self.createChart('Book percentages genre', self.genre_series) self.createChart('Book percentages author', self.author_series) self.createChart('Book percentages status', self.status_series) self.show() def getValues(self): books = book_session.query(Book).count() authors = book_session.query(Author).count() genres = book_session.query(Genre).count() self.ui.booksCounter_label.setText(str(books)) self.ui.authorsCounter_label.setText(str(authors)) self.ui.genresCounter_label.setText(str(genres)) def createChart(self, title, series): chart = QChart() chart.addSeries(series) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle(title) #sslice.setLabel("{:.1f}%".format(100 * slice.percentage())) chartview = QChartView(chart) chartview.setRenderHint(QPainter.Antialiasing) #setChart(chartview) self.ui.horizontalLayout.addWidget(chartview) 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')