def __iniChart(self): #图表初始化 self.chart = QPolarChart() ##极坐标图 self.chart.legend().setVisible(False) self.ui.chartView.setChart(self.chart) self.ui.chartView.setRenderHint(QPainter.Antialiasing) self.ui.chartView.setCursor(Qt.CrossCursor) self.__axisAngle = QValueAxis() #角度坐标轴 self.__axisAngle.setRange(0, 360) #角度范围 self.__axisAngle.setLabelFormat("NE %.0f") self.__axisAngle.setTickCount(9) self.chart.addAxis(self.__axisAngle, QPolarChart.PolarOrientationAngular) self.__axisRadial = QValueAxis() #径向坐标轴 self.__axisRadial.setTickCount(6) self.__axisRadial.setLabelFormat("%.1f") #标签格式 self.chart.addAxis(self.__axisRadial, QPolarChart.PolarOrientationRadial) pen = QPen(Qt.blue) pen.setWidth(2) seriesSpLine = QSplineSeries() seriesSpLine.setPen(pen) seriesSpLine.setPointsVisible(True) #数据点可见 seriesSpLine.hovered.connect(self.do_series_hovered) self.chart.addSeries(seriesSpLine) seriesSpLine.attachAxis(self.__axisAngle) seriesSpLine.attachAxis(self.__axisRadial)
class DynamicSpline(QChart): def __init__(self): super().__init__() self.m_step = 0 self.m_x = 2 self.m_y = 1 # Инициализировать изображение self.series = QSplineSeries(self) red_pen = QPen(Qt.red) red_pen.setWidth(2) self.series.setPen(red_pen) self.axisX = QValueAxis() self.axisY = QValueAxis() self.series.append(self.m_x, self.m_y) self.addSeries(self.series) self.addAxis(self.axisX, Qt.AlignBottom) self.addAxis(self.axisY, Qt.AlignLeft) self.series.attachAxis(self.axisX) self.series.attachAxis(self.axisY) self.axisX.setTickCount(5) self.axisX.setRange(0, 10) self.axisY.setRange(0, 100) self.timer = QTimer(self) self.timer.setInterval(1000) self.timer.timeout.connect(self.handleTimeout) self.timer.start() def handleTimeout(self): x = self.plotArea().width() / self.axisX.tickCount() y = (self.axisX.max() - self.axisX.min()) / self.axisX.tickCount() self.m_x += y # В PyQt 5.11.3 и выше, QRandomGenerator.global() был переименован в global_() try: self.m_y=db_wrk() except : self.m_y = QRandomGenerator.global_().bounded(50) self.series.append(self.m_x, self.m_y) self.scroll(x, 0) if self.m_x >= 10: self.timer.stop() def db_wrk(): return m_y
class CpuLineChart(QChart): def __init__(self, *args, **kwargs): super(CpuLineChart, self).__init__(*args, **kwargs) self.m_count = 10 # 隐藏图例 self.legend().hide() self.m_series = QSplineSeries(self) # 设置画笔 self.m_series.setPen(QPen(QColor('#3B8CFF'), 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) self.addSeries(self.m_series) # x轴 self.m_axisX = QDateTimeAxis(self) self.m_axisX.setTickCount(self.m_count + 1) # 设置刻度数量 self.m_axisX.setFormat('hh:mm:ss') # 设置时间显示格式 now = QDateTime.currentDateTime() # 前10秒到现在 self.m_axisX.setRange(now.addSecs(-self.m_count), now) self.addAxis(self.m_axisX, Qt.AlignBottom) self.m_series.attachAxis(self.m_axisX) # y轴 self.m_axisY = QValueAxis(self) self.m_axisY.setLabelFormat('%d') # 设置文本格式 self.m_axisY.setMinorTickCount(4) # 设置小刻度线的数目 self.m_axisY.setTickCount(self.m_count + 1) self.m_axisY.setRange(0, 100) self.addAxis(self.m_axisY, Qt.AlignLeft) self.m_series.attachAxis(self.m_axisY) # 填充11个初始点,注意x轴 需要转为秒的时间戳 self.m_series.append( [QPointF(now.addSecs(-i).toMSecsSinceEpoch(), 0) for i in range(self.m_count, -1, -1)]) # 定时器获取数据 self.m_timer = QTimer() self.m_timer.timeout.connect(self.update_data) self.m_timer.start(1000) def update_data(self): value = cpu_percent() now = QDateTime.currentDateTime() self.m_axisX.setRange(now.addSecs(-self.m_count), now) # 重新调整x轴的时间范围 # 获取原来的所有点,去掉第一个并追加新的一个 points = self.m_series.pointsVector() points.pop(0) points.append(QPointF(now.toMSecsSinceEpoch(), value)) # 替换法速度更快 self.m_series.replace(points)
class DynamicSpline(QChart): def __init__(self): super().__init__() self.m_step = 0 self.m_x = 5 self.m_y = 1 # 初始化图像 self.series = QSplineSeries(self) green_pen = QPen(Qt.red) green_pen.setWidth(3) self.series.setPen(green_pen) self.axisX = QValueAxis() self.axisY = QValueAxis() self.series.append(self.m_x, self.m_y) self.addSeries(self.series) self.addAxis(self.axisX, Qt.AlignBottom) self.addAxis(self.axisY, Qt.AlignLeft) self.series.attachAxis(self.axisX) self.series.attachAxis(self.axisY) self.axisX.setTickCount(5) self.axisX.setRange(0, 10) self.axisY.setRange(-5, 10) self.timer = QTimer(self) self.timer.setInterval(1000) self.timer.timeout.connect(self.handleTimeout) self.timer.start() def handleTimeout(self): x = self.plotArea().width() / self.axisX.tickCount() y = (self.axisX.max() - self.axisX.min()) / self.axisX.tickCount() self.m_x += y # 在PyQt5.11.3及以上版本中,QRandomGenerator.global()被重命名为global_() self.m_y = QRandomGenerator.global_().bounded(5) - 2.5 self.series.append(self.m_x, self.m_y) self.scroll(x, 0) if self.m_x >= 100: self.timer.stop()
class BalanceHistoryChartView(QChartView): """ Chart that displays the balance between several dates from an account, token or whole portfolio """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.chart = QChart() self.FIAT_CURRENCY = confighandler.get_fiat_currency() def setupChartWithData(self, selectiontype, name=None): """ Chart gets updated displaying new data. The data gets extracted from cbalancehistory, according to the selection Parameters: - selectiontype : in ('account','token','all') - name: str, corresponds to account/token on cbalancehistory """ self.chart = QChart() self.chart.setTheme(QChart.ChartThemeDark) self.chart.setAnimationOptions(QChart.SeriesAnimations) self.chart.setBackgroundBrush(QBrush(QColor('#19232d'))) # self.chart.setTitle("") # self.chart.setTitleBrush(QBrush(QColor('white'))) # Data # Get data if selectiontype == 'token': assert(name is not None) data = chistoricalbalances.get_balances_with_token_tuple(name) elif selectiontype == 'account': assert(name is not None) data = chistoricalbalances.get_balances_with_account_tuple(name) elif selectiontype == 'all': data = chistoricalbalances.get_balances_by_day_tuple() # Separate balance_btc from balance_fiat dates, balances_btc, balances_fiat = [], [], [] for date in data: dates.append(int(date)) balances_btc.append(data[date][0]) balances_fiat.append(data[date][1]) # Series self.btcseries = QSplineSeries() self.fiatseries = QSplineSeries() for date, balance_btc, balance_fiat in zip(dates, balances_btc, balances_fiat): date = datetime.fromtimestamp(date) date = datetime(date.year, date.month, date.day) dateQ = QDateTime(date).toMSecsSinceEpoch() self.btcseries.append(dateQ, balance_btc) self.fiatseries.append(dateQ, balance_fiat) # Append current point currentdate = QDateTime(datetime.today()).toMSecsSinceEpoch() if selectiontype == "all": # Append current balances self.btcseries.append(currentdate, cbalances.get_total_balance_all_accounts()) self.fiatseries.append(currentdate, cbalances.get_total_balance_all_accounts_fiat()) elif name != '': if selectiontype == "account": # Append current balances self.btcseries.append( currentdate, cbalances.get_total_account_balance(name)) self.fiatseries.append( currentdate, cbalances.get_total_account_balance_fiat(name)) elif selectiontype == "token": pass # Axis X (Dates) self.x_axis = QDateTimeAxis() self.x_axis.setTickCount(11) self.x_axis.setLabelsAngle(70) self.x_axis.setFormat("dd-MM-yy") self.x_axis.setTitleText(self.tr('Date')) # Axis Y (Balances) # BTC self.y_axis_btc = QValueAxis() if len(balances_btc) > 0: self.y_axis_btc.setMax(max(balances_btc)*1.1) self.y_axis_btc.setMin(min(balances_btc)*0.9) # Fiat self.y_axis_fiat = QValueAxis() if len(balances_fiat) > 0: self.y_axis_fiat.setMax(max(balances_fiat)*1.1) self.y_axis_fiat.setMin(min(balances_fiat)*0.9) self.chart.addAxis(self.y_axis_btc, Qt.AlignLeft) self.chart.addAxis(self.y_axis_fiat, Qt.AlignRight) self.chart.addAxis(self.x_axis, Qt.AlignBottom) # Add series to chart # BTC self.btcseries.setName("BTC") self.chart.addSeries(self.btcseries) self.btcseries.attachAxis(self.x_axis) self.btcseries.attachAxis(self.y_axis_btc) # Fiat self.fiatseries.setName(self.FIAT_CURRENCY.upper()) self.chart.addSeries(self.fiatseries) self.fiatseries.attachAxis(self.x_axis) self.fiatseries.attachAxis(self.y_axis_fiat) self.setChart(self.chart) self.setRenderHint(QPainter.Antialiasing) self.setStyleSheet("border: 0px")
class ChartView(QChartView, QChart): def __init__(self, *args, **kwargs): super(ChartView, self).__init__(*args, **kwargs) self.resize(800, 600) self.setRenderHint(QPainter.Antialiasing) # 抗锯齿 self.chart_init() self.timer_init() def timer_init(self): #使用QTimer,2秒触发一次,更新数据 self.timer = QTimer(self) self.timer.timeout.connect(self.drawLine) self.timer.start(200) def chart_init(self): self.chart = QChart() self.series = QSplineSeries() #设置曲线名称 self.series.setName("实时数据") #把曲线添加到QChart的实例中 self.chart.addSeries(self.series) #声明并初始化X轴,Y轴 self.dtaxisX = QDateTimeAxis() self.vlaxisY = QValueAxis() #设置坐标轴显示范围 self.dtaxisX.setMin(QDateTime.currentDateTime().addSecs(-300 * 1)) self.dtaxisX.setMax(QDateTime.currentDateTime().addSecs(0)) self.vlaxisY.setMin(0) self.vlaxisY.setMax(1500) #设置X轴时间样式 self.dtaxisX.setFormat("MM月dd hh:mm:ss") #设置坐标轴上的格点 self.dtaxisX.setTickCount(6) self.vlaxisY.setTickCount(11) #设置坐标轴名称 self.dtaxisX.setTitleText("时间") self.vlaxisY.setTitleText("量程") #设置网格不显示 self.vlaxisY.setGridLineVisible(False) #把坐标轴添加到chart中 self.chart.addAxis(self.dtaxisX, Qt.AlignBottom) self.chart.addAxis(self.vlaxisY, Qt.AlignLeft) #把曲线关联到坐标轴 self.series.attachAxis(self.dtaxisX) self.series.attachAxis(self.vlaxisY) self.setChart(self.chart) def drawLine(self): #获取当前时间 bjtime = QDateTime.currentDateTime() #更新X轴坐标 self.dtaxisX.setMin(QDateTime.currentDateTime().addSecs(-300 * 1)) self.dtaxisX.setMax(QDateTime.currentDateTime().addSecs(0)) #当曲线上的点超出X轴的范围时,移除最早的点 if (self.series.count() > 149): self.series.removePoints(0, self.series.count() - 149) #产生随即数 yint = random.randint(0, 1500) #添加数据到曲线末端 self.series.append(bjtime.toMSecsSinceEpoch(), yint)
class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, weight_path, out_file_path, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) self.setWindowTitle("VAT ROLL COMPARE LABEL TOOL" + " " + CODE_VER) self.showMaximized() '''按键绑定''' # 输入媒体 self.import_media_pushButton.clicked.connect(self.import_media) # 导入 self.start_predict_pushButton.clicked.connect( self.predict_button_click) # 开始推理 # 输出媒体 self.open_predict_file_pushButton.clicked.connect( self.open_file_in_browser) # 文件中显示推理视频 # 下方 self.play_pushButton.clicked.connect( self.play_pause_button_click) # 播放 self.pause_pushButton.clicked.connect( self.play_pause_button_click) # 暂停 self.button_dict = dict() self.button_dict.update({ "import_media_pushButton": self.import_media_pushButton, "start_predict_pushButton": self.start_predict_pushButton, "open_predict_file_pushButton": self.open_predict_file_pushButton, "play_pushButton": self.play_pushButton, "pause_pushButton": self.pause_pushButton, }) '''媒体流绑定输出''' self.input_player = QMediaPlayer() # 媒体输入的widget self.input_player.setVideoOutput(self.input_video_widget) self.input_player.positionChanged.connect( self.change_slide_bar) # 播放进度条 self.output_player = QMediaPlayer() # 媒体输出的widget self.output_player.setVideoOutput(self.output_video_widget) '''初始化GPU chart''' self.series = QSplineSeries() self.chart_init() '''初始化GPU定时查询定时器''' # 使用QTimer,0.5秒触发一次,更新数据 self.timer = QTimer(self) self.timer.timeout.connect(self.draw_gpu_info_chart) self.timer.start(500) # 播放时长, 以 input 的时长为准 self.video_length = 0 self.out_file_path = out_file_path # 推理使用另外一线程 self.predict_handler_thread = PredictHandlerThread( self.output_player, self.out_file_path, weight_path, self.predict_info_plainTextEdit, self.predict_progressBar, self.fps_label, self.button_dict) # 界面美化 self.gen_better_gui() def gen_better_gui(self): """ 美化界面 :return: """ # Play 按钮 play_icon = QIcon() play_icon.addPixmap(QPixmap("./UI/icon/play.png"), QIcon.Normal, QIcon.Off) self.play_pushButton.setIcon(play_icon) # Pause 按钮 play_icon = QIcon() play_icon.addPixmap(QPixmap("./UI/icon/pause.png"), QIcon.Normal, QIcon.Off) self.pause_pushButton.setIcon(play_icon) def chart_init(self): """ 初始化 GPU 折线图 :return: """ # self.gpu_info_chart._chart = QChart(title="折线图堆叠") # 创建折线视图 self.gpu_info_chart._chart = QChart() # 创建折线视图 # chart._chart.setBackgroundVisible(visible=False) # 背景色透明 self.gpu_info_chart._chart.setBackgroundBrush(QBrush( QColor("#FFFFFF"))) # 改变图背景色 # 设置曲线名称 self.series.setName("GPU Utilization") # 把曲线添加到QChart的实例中 self.gpu_info_chart._chart.addSeries(self.series) # 声明并初始化X轴,Y轴 self.dtaxisX = QDateTimeAxis() self.vlaxisY = QValueAxis() # 设置坐标轴显示范围 self.dtaxisX.setMin(QDateTime.currentDateTime().addSecs(-300 * 1)) self.dtaxisX.setMax(QDateTime.currentDateTime().addSecs(0)) self.vlaxisY.setMin(0) self.vlaxisY.setMax(100) # 设置X轴时间样式 self.dtaxisX.setFormat("hh:mm:ss") # 设置坐标轴上的格点 self.dtaxisX.setTickCount(5) self.vlaxisY.setTickCount(10) # 设置坐标轴名称 self.dtaxisX.setTitleText("Time") self.vlaxisY.setTitleText("Percent") # 设置网格不显示 self.vlaxisY.setGridLineVisible(False) # 把坐标轴添加到chart中 self.gpu_info_chart._chart.addAxis(self.dtaxisX, Qt.AlignBottom) self.gpu_info_chart._chart.addAxis(self.vlaxisY, Qt.AlignLeft) # 把曲线关联到坐标轴 self.series.attachAxis(self.dtaxisX) self.series.attachAxis(self.vlaxisY) # 生成 折线图 self.gpu_info_chart.setChart(self.gpu_info_chart._chart) def draw_gpu_info_chart(self): """ 绘制 GPU 折线图 :return: """ # 获取当前时间 time_current = QDateTime.currentDateTime() # 更新X轴坐标 self.dtaxisX.setMin(QDateTime.currentDateTime().addSecs(-300 * 1)) self.dtaxisX.setMax(QDateTime.currentDateTime().addSecs(0)) # 当曲线上的点超出X轴的范围时,移除最早的点 remove_count = 600 if self.series.count() > remove_count: self.series.removePoints(0, self.series.count() - remove_count) # 对 y 赋值 # yint = random.randint(0, 100) gpu_info = get_gpu_info() yint = gpu_info[0].get("gpu_load") # 添加数据到曲线末端 self.series.append(time_current.toMSecsSinceEpoch(), yint) def import_media(self): """ 导入媒体文件 :return: """ self.parameter_source = QFileDialog.getOpenFileUrl()[0] self.input_player.setMedia(QMediaContent( self.parameter_source)) # 选取视频文件 # 设置 output 为一张图片,防止资源被占用 path_current = str(Path.cwd().joinpath("area_dangerous\1.jpg")) self.output_player.setMedia( QMediaContent(QUrl.fromLocalFile(path_current))) # 将 QUrl 路径转为 本地路径str self.predict_handler_thread.parameter_source = self.parameter_source.toLocalFile( ) self.input_player.pause() # 显示媒体 image_flag = os.path.splitext( self.predict_handler_thread.parameter_source)[-1].lower( ) in img_formats for item, button in self.button_dict.items(): if image_flag and item in ['play_pushButton', 'pause_pushButton']: button.setEnabled(False) else: button.setEnabled(True) # self.output_player.setMedia(QMediaContent(QFileDialog.getOpenFileUrl()[0])) # 选取视频文件 def predict_button_click(self): """ 推理按钮 :return: """ # 启动线程去调用 self.predict_handler_thread.start() def change_slide_bar(self, position): """ 进度条移动 :param position: :return: """ self.video_length = self.input_player.duration() + 0.1 self.video_horizontalSlider.setValue( round((position / self.video_length) * 100)) self.video_percent_label.setText( str(round((position / self.video_length) * 100, 2)) + '%') @pyqtSlot() def play_pause_button_click(self): """ 播放、暂停按钮回调事件 :return: """ name = self.sender().objectName() if self.parameter_source == "": return if name == "play_pushButton": print("play") self.input_player.play() self.output_player.play() elif name == "pause_pushButton": self.input_player.pause() self.output_player.pause() @pyqtSlot() def open_file_in_browser(self): os.system(f"start explorer {self.out_file_path}") @pyqtSlot() def closeEvent(self, *args, **kwargs): """ 重写关闭事件 :param args: :param kwargs: :return: """ print("Close")
angularAxis = QValueAxis() angularAxis.setTickCount(9) angularAxis.setLabelFormat('%.1f') angularAxis.setShadesVisible(True) angularAxis.setShadesBrush(QBrush(QColor(249, 249, 255))) chart.addAxis(angularAxis, QPolarChart.PolarOrientationAngular) radialAxis = QValueAxis() radialAxis.setTickCount(9) radialAxis.setLabelFormat('%d') chart.addAxis(radialAxis, QPolarChart.PolarOrientationRadial) series1.attachAxis(radialAxis) series1.attachAxis(angularAxis) series2.attachAxis(radialAxis) series2.attachAxis(angularAxis) series3.attachAxis(radialAxis) series3.attachAxis(angularAxis) series4.attachAxis(radialAxis) series4.attachAxis(angularAxis) series5.attachAxis(radialAxis) series5.attachAxis(angularAxis) radialAxis.setRange(RADIAL_MIN, RADIAL_MAX) angularAxis.setRange(ANGULAR_MIN, ANGULAR_MAX) chartView = ChartView() chartView.setChart(chart) chartView.setRenderHint(QPainter.Antialiasing)
class TotalEquityChartView(QChartView): """ Chart that displays the balance between several dates from an account, token or whole portfolio """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.chart = QChart() def setupChartWithData(self, data, linecolor='#422F8A'): """ Chart gets updated displaying the new data. Data has to be expressed on a dictionary form: - keys are timestamps - values are total balance for that timestamp """ self.chart = QChart() self.chart.setTheme(QChart.ChartThemeDark) self.chart.setAnimationOptions(QChart.SeriesAnimations) self.chart.setBackgroundBrush(QBrush(QColor("transparent"))) # self.chart.setTitle("") # self.chart.setTitleBrush(QBrush(QColor('white'))) # Axis X (Dates) self.x_axis = QDateTimeAxis() self.x_axis.setTickCount(11) self.x_axis.setLabelsAngle(70) font = QFont() font.setFamily('Roboto') font.setLetterSpacing(QFont.PercentageSpacing, 110) font.setPointSize(8) self.x_axis.setLabelsFont(font) self.x_axis.setFormat("dd-MM-yy") self.x_axis.setTitleText(self.tr('Date')) self.x_axis.setTitleVisible(False) self.x_axis.setLineVisible(False) self.x_axis.setGridLineVisible(False) # Axis Y (Balances) self.y_axis = QValueAxis() if data != {}: self.y_axis.setMax(max(data.values()) * 1.05) self.y_axis.setMin(min(data.values()) * 0.95) # self.y_axis.setMinorGridLineVisible(False) self.y_axis.setLineVisible(False) self.y_axis.setGridLineColor(QColor("#ECE9F1")) self.chart.addAxis(self.y_axis, Qt.AlignLeft) self.chart.addAxis(self.x_axis, Qt.AlignBottom) # Series self.btcseries = QSplineSeries() for date in data: balance = data[date] date = QDateTime(datetime.fromtimestamp(int(float(date)))) self.btcseries.append(date.toMSecsSinceEpoch(), balance) self.btcseries.setName("BTC") pen = QPen(QColor(linecolor)) pen.setWidth(3) self.btcseries.setPen(pen) # Series functionality self.btcseries.hovered.connect(self.selectPoint) self.chart.addSeries(self.btcseries) self.btcseries.attachAxis(self.x_axis) self.btcseries.attachAxis(self.y_axis) self.setChart(self.chart) self.setRenderHint(QPainter.Antialiasing) self.setStyleSheet("border: 0px; background-color: rgba(0,0,0,0); ") self.chart.legend().hide() def selectPoint(self, point, state): """ Shows point where mouse is hovered """ self.chart.setTitle( f"{int(point.y())} {confighandler.get_fiat_currency().upper()}")
class Example(QMainWindow): def __init__(self, ): super().__init__() self.bijiao = [0, 0, 0] self.res = "" self.queue = [] self.k = -1 self.flag = -1 try: self.initUI() self.chart_init(10) except: traceback.print_exc() def initUI(self): icon = QtGui.QIcon() icon.addPixmap( QtGui.QPixmap("D:\\Sysytem\\Desktop\\zhong\\data\\ico.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.setWindowIcon(icon) self.resize(1000, 700) self.setWindowTitle('Icon') self.setObjectName("清华大学得不到的学生") self.setWindowTitle("一枚小乖乖~") self.label = QLabel(self) self.label.setWindowTitle("清华大学得不到的学生") self.setWindowFlags(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) self.label.setGeometry(QtCore.QRect(15, 15, 970, self.height() - 30)) self.label.setText("") palette = QtGui.QPalette() self.label.setStyleSheet("background-color: #fff;border-radius: 15px;") self.labelshadow = QGraphicsDropShadowEffect(self) self.labelshadow.setBlurRadius(15) self.labelshadow.setOffset(1, 1) self.label.setGraphicsEffect(self.labelshadow) self.label.setScaledContents(True) self.label.setObjectName("label") self.pushButton_12 = QtWidgets.QPushButton(self) self.pushButton_12.setGeometry( QtCore.QRect(self.width() - 55, 29, 20, 20)) self.pushButton_12.setStyleSheet( "QPushButton{\n" " background:#fc625d;\n" " color:white;\n" " box-shadow: 1px 1px 3px rgba(0,0,0,0.3);font-size:20px;border-radius: 10px;font-family: 微软雅黑;\n" "}\n" "QPushButton:hover{ \n" " background:#FF2D2D;\n" "}\n" "QPushButton:pressed{\n" " border: 1px solid #3C3C3C!important;\n" " background:#AE0000;\n" "}") self.pushButton_12.clicked.connect(self.close) self.pushButton_14 = QtWidgets.QPushButton(self) self.pushButton_14.setGeometry( QtCore.QRect(self.width() - 55 - 35, 29, 20, 20)) self.pushButton_14.setStyleSheet( "QPushButton{\n" " background:#35cd4b;\n" " color:white;\n" " box-shadow: 1px 1px 3px rgba(0,0,0,0.3);font-size:20px;border-radius: 10px;font-family: 微软雅黑;\n" "}\n" "QPushButton:hover{ \n" " background:#00CC00;\n" "}\n" "QPushButton:pressed{\n" " border: 1px solid #3C3C3C!important;\n" " background:#009900;\n" "}") self.pushButton_14.clicked.connect(self.showMinimized) self.color = ["#e89291", "#c4b98b", "#81a8e1", "#8cc9c4", "#83bde2"] # -----------------------------------------------------------------测试数量------------------------ error = QtWidgets.QLineEdit(self) error.setGeometry(QtCore.QRect(70, 70, 150, 50)) error.setStyleSheet( "text-align: center;background-color: " + self.color[0] + ";border-radius: 7px;border: 0px solid #000;color:#ffffff;font-size:20px;font-family: 微软雅黑;" ) errorshadow = QGraphicsDropShadowEffect(self) error.setPlaceholderText("测试数量") errorshadow.setBlurRadius(30) cl = QColor("#cacaca") errorshadow.setColor(cl) error.setAlignment(Qt.AlignCenter) errorshadow.setOffset(0, 0) error.textChanged.connect(self.set_suliang) # error.setGraphicsEffect(errorshadow) # -----------------------------------------------------------------随机范围------------------------ fan = QtWidgets.QLineEdit(self) fan.setGeometry(QtCore.QRect(240, 70, 150, 50)) fan.setStyleSheet( "text-align: center;background-color: " + self.color[2] + ";border-radius: 7px;border: 0px solid #000;color:#ffffff;font-size:20px;font-family: 微软雅黑;" ) fanshadow = QGraphicsDropShadowEffect(self) fanshadow.setBlurRadius(30) fancl = QColor("#cacaca") fan.setPlaceholderText("随机范围") fanshadow.setColor(fancl) fan.setAlignment(Qt.AlignCenter) fanshadow.setOffset(0, 0) fan.textChanged.connect(self.set_fanwei) # fan.setGraphicsEffect(fanshadow) # -----------------------------------------------------------------内存块数----------------------- kuai = QtWidgets.QLineEdit(self) kuai.setGeometry(QtCore.QRect(410, 70, 150, 50)) kuai.setStyleSheet( "text-align: center;background-color: " + self.color[3] + ";border-radius: 7px;border: 0px solid #000;color:#ffffff;font-size:20px;font-family: 微软雅黑;" ) kuaishadow = QGraphicsDropShadowEffect(self) kuaishadow.setBlurRadius(30) kuaicl = QColor("#cacaca") kuai.setPlaceholderText("内存块数") kuaishadow.setColor(kuaicl) kuai.setAlignment(Qt.AlignCenter) kuaishadow.setOffset(0, 0) kuai.textChanged.connect(self.set_kuai) # kuai.setGraphicsEffect(kuaishadow) self.Button = QtWidgets.QPushButton(self) self.Button.setGeometry(QtCore.QRect(580, 70, 150, 50)) self.Button.setStyleSheet( "QPushButton{text-align: center;background-color: #83bde2;" "border-radius: 7px;border: 0px solid #000;color:#ffffff;" "font-size:20px;font-family: 微软雅黑;}" + "QPushButton:hover{ " + " background-color: #9ad0d0;color: white;" + "}") Buttonshadow = QGraphicsDropShadowEffect(self) Buttonshadow.setBlurRadius(30) Buttoncl = QColor("#cacaca") self.Button.setText("执行") Buttonshadow.setColor(Buttoncl) Buttonshadow.setOffset(0, 0) # Button.setGraphicsEffect(Buttonshadow) self.Button.clicked.connect(self.on_click_start) self.avgflag = 0 self.qq = QtWidgets.QPushButton(self) self.qq.setGeometry(QtCore.QRect(750, 70, 180, 50)) self.qq.setStyleSheet( "color: #000;text-align: center;background-color: #f0f0f0;border-radius: 7px;border: 0px solid #000;font-size:14px;font-family: 微软雅黑;" ) self.qq.clicked.connect(self.on_avg) self.show() def on_avg(self): if self.avgflag == 0: self.series.hide() self.serieslru.hide() self.seriesopt.hide() self.seriesfifoavg.show() self.serieslruavg.show() self.seriesoptavg.show() self.avgflag = 1 else: self.series.show() self.serieslru.show() self.seriesopt.show() self.seriesfifoavg.hide() self.serieslruavg.hide() self.seriesoptavg.hide() self.avgflag = 0 def set_kuai(self, text): self.kuai = text def set_fanwei(self, text): self.fan = text def set_suliang(self, text): self.su = text def hideerror(self): self.error.hide() def set_kuaishu(self, text): self.kuaishu = text def set_yemian(self, text): self.yemian = text def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate def mousePressEvent(self, e): if e.button() == Qt.LeftButton: self.m_drag = True self.m_DragPosition = e.globalPos() - self.pos() e.accept() def mouseReleaseEvent(self, e): if e.button() == Qt.LeftButton: self.m_drag = False def mouseMoveEvent(self, e): try: if Qt.LeftButton and self.m_drag: self.move(e.globalPos() - self.m_DragPosition) e.accept() except: print("错误代码:000x0") def on_click_start(self): try: self.jishu = 0 self.thread = MyThread() self.thread.set_su(self.su) self.thread.set_kuai(self.kuai) self.thread.set_x(self.dtaxisX) self.thread.set_fan(self.fan) self.thread.det_bijiao(self.bijiao) self.dailist = [] self.avg = [] self.avg1 = [] self.avg2 = [] self.dailistlru = [] self.dailistopt = [] self.thread.sinOut.connect(self.change) self.thread.start() # self.qq.setText("FIFO:%0.2f LRU:%0.2f \n OPT:%0.2f" % (self.bijiao[0], self.bijiao[1], self.bijiao[2])) except: traceback.print_exc() # self.sinOut.emit(self.dailist) # self.sinOut2.emit(self.dailistlru) # self.sinOut3.emit(self.dailistopt) def change(self, dailist): try: # print(dailist) # arr = str.split(dailist) # print(arr) flag = 0 start = 0 flag = dailist.find(" ", flag) flag = dailist.find(" ", flag + 1) end = flag arr = str.split(dailist[start:end]) start = flag flag = dailist.find(" ", flag + 1) flag = dailist.find(" ", flag + 1) end = flag arr1 = str.split(dailist[start:end]) start = flag flag = dailist.find(" ", flag + 1) flag = dailist.find(" ", flag + 1) end = flag arr2 = str.split(dailist[start:end]) self.dailist.append(QPointF(float(arr[0]), float(arr[1]))) self.dailistlru.append(QPointF(float(arr1[0]), float(arr1[1]))) self.dailistopt.append(QPointF(float(arr2[0]), float(arr2[1]))) # self.series.replace(self.dailist) self.serieslru.replace(self.dailistlru) self.seriesopt.replace(self.dailistopt) if self.jishu == 0: self.bijiao[0] = float(arr[1]) self.bijiao[1] = float(arr1[1]) self.bijiao[2] = float(arr2[1]) self.jishu = 1 else: self.bijiao[0] = (float(arr[1]) + self.bijiao[0]) / 2.0 self.bijiao[1] = (float(arr1[1]) + self.bijiao[1]) / 2.0 self.bijiao[2] = (float(arr2[1]) + self.bijiao[2]) / 2.0 self.jishu = self.jishu + 1 self.avg.append(QPointF(float(arr[0]), self.bijiao[0])) self.avg1.append(QPointF(float(arr[0]), self.bijiao[1])) self.avg2.append(QPointF(float(arr[0]), self.bijiao[2])) # print(self.avg) self.seriesfifoavg.replace(self.avg) self.serieslruavg.replace(self.avg1) self.seriesoptavg.replace(self.avg2) self.qq.setText("FIFO:%0.2f LRU:%0.2f \n OPT:%0.2f" % (self.bijiao[0], self.bijiao[1], self.bijiao[2])) except: traceback.print_exc() def drawLine(self): self.series.replace(self.dailist) # print("uiy") def chart_init(self, su): self.start_num = 0 self.chart = QChartView(self) self.chart.setGeometry(50, 150, self.width() - 100, self.height() - 150 - 50) # 设置charView位置、大小 self.series = QSplineSeries() self.series.setName("FIFO") self.chart.chart().addSeries(self.series) pen = QPen(Qt.gray) pen.setWidth(2) self.serieslru = QSplineSeries() self.serieslru.setPen(pen) self.serieslru.setName("LRU") self.serieslru.setColor(QColor("#e89291")) self.chart.chart().addSeries(self.serieslru) pen2 = QPen(Qt.gray) pen2.setWidth(2) self.seriesopt = QSplineSeries() self.seriesopt.setPen(pen2) self.seriesopt.setColor(QColor("#3ea54f")) self.seriesopt.setName("OPT") self.chart.chart().addSeries(self.seriesopt) penfifo = QPen(Qt.gray) penfifo.setWidth(2) self.seriesfifoavg = QSplineSeries() self.seriesfifoavg.setPen(penfifo) self.seriesfifoavg.setName("FIFO-avg") self.seriesfifoavg.setColor(QColor("#209fdf")) self.chart.chart().addSeries(self.seriesfifoavg) self.seriesfifoavg.hide() penavg = QPen(Qt.gray) penavg.setWidth(2) self.serieslruavg = QSplineSeries() self.serieslruavg.setPen(penavg) self.serieslruavg.setName("LRU-avg") self.serieslruavg.setColor(QColor("#e89291")) self.chart.chart().addSeries(self.serieslruavg) self.serieslruavg.hide() pen2avg = QPen(Qt.gray) pen2avg.setWidth(2) self.seriesoptavg = QSplineSeries() self.seriesoptavg.setPen(pen2avg) self.seriesoptavg.setColor(QColor("#3ea54f")) self.seriesoptavg.setName("OPT-avg") self.chart.chart().addSeries(self.seriesoptavg) self.seriesoptavg.hide() self.dtaxisX = QValueAxis() self.vlaxisY = QValueAxis() self.dtaxisX.setMin(10) self.dtaxisX.setMax(100) self.vlaxisY.setMin(0) self.vlaxisY.setMax(100) self.dtaxisX.setTickCount(6) self.vlaxisY.setTickCount(11) self.dtaxisX.setTitleText("页数") self.vlaxisY.setTitleText("缺页率") self.vlaxisY.setGridLineVisible(False) self.chart.chart().addAxis(self.dtaxisX, Qt.AlignBottom) self.chart.chart().addAxis(self.vlaxisY, Qt.AlignLeft) self.series.attachAxis(self.dtaxisX) self.series.attachAxis(self.vlaxisY) self.serieslru.attachAxis(self.dtaxisX) self.serieslru.attachAxis(self.vlaxisY) self.seriesopt.attachAxis(self.dtaxisX) self.seriesopt.attachAxis(self.vlaxisY) self.seriesoptavg.attachAxis(self.dtaxisX) self.seriesoptavg.attachAxis(self.vlaxisY) self.serieslruavg.attachAxis(self.dtaxisX) self.serieslruavg.attachAxis(self.vlaxisY) self.seriesfifoavg.attachAxis(self.dtaxisX) self.seriesfifoavg.attachAxis(self.vlaxisY) self.chart.chart().setTitleBrush(QBrush(Qt.cyan)) cc = QColor("#f0f0f0") self.chart.setBackgroundBrush(cc) self.chart.setStyleSheet( "QChartView{ background-color: #83bde2;border-radius: 20px;}") self.chart.show()