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 __init__(self): super(QChart, self).__init__() self.m_timer = QTimer() self.m_series = None self.m_titles = [] self.m_axis = QValueAxis() self.m_step = None self.m_x = 5 self.m_y = 1 random.seed(QTime.currentTime().msec()) self.m_timer.timeout.connect(self.handleTimeout) self.m_timer.setInterval(1000) self.m_series = QSplineSeries(self) green = QPen(Qt.green) green.setWidth(3) self.m_series.setPen(green) self.m_series.append(self.m_x, self.m_y) self.addSeries(self.m_series) self.createDefaultAxes() self.setAxisX(self.m_axis, self.m_series) self.m_axis.setTickCount(5) self.axisX().setRange(0, 10) self.axisY().setRange(-5, 10) self.m_timer.start()
def __init__(self, parent=None): super(QtChartCanvas, self).__init__(parent) self.plotChart = QChart() self.plotChart.legend().hide() self.verticalLayout = QtWidgets.QVBoxLayout(self) self.plotView = QChartView(self.plotChart) self.verticalLayout.addWidget(self.plotView) # self.setCentralWidget(self.plotView) self.plotCurve = QSplineSeries() self.plotCurve.setUseOpenGL(True) self.plotCurve.pen().setColor(Qt.red) self.plotChart.addSeries(self.plotCurve) self.plotChart.createDefaultAxes() # self.plotChart.axisX().setLabelFormat('%d') self.plotChart.axisX().hide() self.RecvData = [] # 存储接收到的传感器数据 self.RecvIndx = 0 self.setLockY = True self.isTop = False self.minY = 0 self.maxY = 100
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 __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 __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)
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 __init__(self, parent=None): super().__init__(QGraphicsScene(), parent) self.m_tooltip = None self.m_callouts = [] self.setDragMode(QGraphicsView.NoDrag) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # chart self.m_chart = QChart() self.m_chart.setMinimumSize(640, 480) self.m_chart.setTitle( "Hover the line to show callout. Click the line to make it stay" ) self.m_chart.legend().hide() series = QLineSeries() series.append(1, 3) series.append(4, 5) series.append(5, 4.5) series.append(7, 1) series.append(11, 2) self.m_chart.addSeries(series) series2 = QSplineSeries() series2.append(1.6, 1.4) series2.append(2.4, 3.5) series2.append(3.7, 2.5) series2.append(7, 4) series2.append(10, 2) self.m_chart.addSeries(series2) self.m_chart.createDefaultAxes() self.m_chart.setAcceptHoverEvents(True) self.setRenderHint(QPainter.Antialiasing) self.scene().addItem(self.m_chart) self.m_coordX = QGraphicsSimpleTextItem(self.m_chart) self.m_coordX.setPos( self.m_chart.size().width() / 2 - 50, self.m_chart.size().height() ) self.m_coordX.setText("X: ") self.m_coordY = QGraphicsSimpleTextItem(self.m_chart) self.m_coordY.setPos( self.m_chart.size().width() / 2 + 50, self.m_chart.size().height() ) self.m_coordY.setText("Y: ") series.clicked.connect(self.keepCallout) series.hovered.connect(self.tooltip) series2.clicked.connect(self.keepCallout) series2.hovered.connect(self.tooltip) self.setMouseTracking(True)
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 getSeries(self, chart): # 第一组 series = QSplineSeries(chart) series << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) \ << QPointF(12, 6) << QPointF(16, 7) << QPointF(18, 5) chart.addSeries(series) # 第二组 series = QSplineSeries(chart) series << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) \ << QPointF(12, 3) << QPointF(16, 4) << QPointF(18, 3) chart.addSeries(series)
def createSplineChart(self): chart = QChart() chart.setTitle("Spline chart") for i, data_list in enumerate(self.m_dataTable): series = QSplineSeries(chart) for value, _ in data_list: series.append(value) series.setName("Series " + str(i)) chart.addSeries(series) chart.createDefaultAxes() return chart
def appendData(self, key, data, msgTime): if key not in self.data: self.data[key] = QSplineSeries() self.data[key].setName(key) ser = self.data[key] ser.append(msgTime, data) if key in self.visibleData: r0 = False if msgTime < self.xRange[0]: self.xRange = (msgTime, self.xRange[1]) r0 = True elif msgTime > self.xRange[1]: self.xRange = (self.xRange[0], msgTime) r0 = True if r0: self.axisX.setRange(self.xRange[0], self.xRange[1]) r0 = False if data < self.yRange[0]: self.yRange = (data, self.yRange[1]) r0 = True elif data > self.yRange[1]: self.yRange = (self.yRange[0], data) r0 = True if r0: # add extra space for Y axis ext = self.extraYScale * (self.yRange[1] - self.yRange[0]) self.yRange = (int(self.yRange[0] - ext), int(self.yRange[1] + ext)) self.axisY.setRange(self.yRange[0], self.yRange[1])
def __init__(self, parent=None): super(QtChartCanvas, self).__init__(parent) self.setStyleSheet("border:0;background-color:#263848") self.plotChart = QChart() self.plotChart.legend().hide() self.verticalLayout = QtWidgets.QVBoxLayout(self) self.plotView = QChartView(self.plotChart) self.plotView.setStyleSheet("border:0;background-color:#263848;") self.plotView.setBackgroundBrush(QBrush(QColor("#263848"))) self.plotChart.setBackgroundBrush(QBrush(QColor("#263848"))) #self.plotChart.setStyle() self.verticalLayout.addWidget(self.plotView) self.plotCurve = QSplineSeries() self.plotCurve.setColor(QColor("#AABFFF")) self.plotCurve.setUseOpenGL(True) self.plotCurve.pen().setColor(QColor("#FAF0FF")) self.plotChart.addSeries(self.plotCurve) # self.scatter=QScatterSeries() # self.scatter.setMarkerSize(8) # self.plotChart.addSeries(self.scatter) self.plotChart.createDefaultAxes() self.plotChart.axisY().setGridLineColor(QColor("#5D5C72")) self.plotChart.axisY().setLinePenColor(QColor("#9D9CA2")) self.plotChart.axisY().setLabelsColor(QColor("#F8F6F6")) self.plotChart.axisY().setRange(0, 100) self.plotChart.axisX().hide() self.RecvData = [] # 存储接收到的传感器数据 self.RecvIndx = 0 self.setLockY = True self.isTop = False self.minY = 0 self.maxY = 100
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 QtChartCanvas(QWidget): def __init__(self, parent=None): super(QtChartCanvas, self).__init__(parent) self.plotChart = QChart() self.plotChart.legend().hide() self.verticalLayout = QtWidgets.QVBoxLayout(self) self.plotView = QChartView(self.plotChart) self.verticalLayout.addWidget(self.plotView) # self.setCentralWidget(self.plotView) self.plotCurve = QSplineSeries() self.plotCurve.setUseOpenGL(True) self.plotCurve.pen().setColor(Qt.red) self.plotChart.addSeries(self.plotCurve) self.plotChart.createDefaultAxes() # self.plotChart.axisX().setLabelFormat('%d') self.plotChart.axisX().hide() self.RecvData = [] # 存储接收到的传感器数据 self.RecvIndx = 0 self.setLockY = True self.isTop = False self.minY = 0 self.maxY = 100 def update_figure(self, payload): self.RecvData.append(payload["data"]) self.RecvData = self.RecvData[-20:] plotData = [] #print("call") if self.isTop: for i, val in enumerate(self.RecvData): plotData.append(QPoint(i, val)) self.plotCurve.replace(plotData) self.plotChart.axisX().setMax(len(plotData)) if not self.setLockY: self.plotChart.axisY().setRange(min(self.RecvData), max(self.RecvData)) else: self.plotChart.axisY().setRange(self.minY, self.maxY) def setYLimit(self, miny=0, maxy=100, lockY=True): self.setLockY = lockY if self.setLockY: self.maxY = maxy self.minY = miny # self.plotChart.axisY().setRange(miny,maxy) def changeTop(self, isTop): self.isTop = isTop
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 Chart(QChart): def __init__(self): super(QChart, self).__init__() self.m_timer = QTimer() self.m_series = None self.m_titles = [] self.m_axis = QValueAxis() self.m_step = None self.m_x = 5 self.m_y = 1 random.seed(QTime.currentTime().msec()) self.m_timer.timeout.connect(self.handleTimeout) self.m_timer.setInterval(1000) self.m_series = QSplineSeries(self) green = QPen(Qt.green) green.setWidth(3) self.m_series.setPen(green) self.m_series.append(self.m_x, self.m_y) self.addSeries(self.m_series) self.createDefaultAxes() self.setAxisX(self.m_axis, self.m_series) self.m_axis.setTickCount(5) self.axisX().setRange(0, 10) self.axisY().setRange(-5, 10) self.m_timer.start() @pyqtSlot() def handleTimeout(self): x = self.plotArea().width() / self.m_axis.tickCount() y = (self.m_axis.max() - self.m_axis.min()) / self.m_axis.tickCount() self.m_x += y self.m_y = random.randint(0, 5) - 2.5 self.m_series.append(self.m_x, self.m_y) self.scroll(x, 0) if self.m_x is 100: self.m_timer.stop()
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")
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 __init__(self, weight_path, out_file_path, real_time_show_predict_flag: bool, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) self.setWindowTitle("Image Segmentation System for Crack Detection " + 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, "real_time_checkBox": self.real_time_checkBox }) '''媒体流绑定输出''' 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) self.output_mask_player = QMediaPlayer() # 媒体输入的widget self.output_mask_player.setVideoOutput(self.output_mask_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(1000) # 播放时长, 以 input 的时长为准 self.video_length = 0 self.out_file_path = out_file_path # 推理使用另外一线程 self.predict_handler_thread = PredictHandlerThread( self.input_player, self.output_player, self.out_file_path, weight_path, self.predict_info_plainTextEdit, self.predict_progressBar, self.fps_label, self.button_dict, self.input_media_tabWidget, self.output_media_tabWidget, self.input_real_time_label, self.output_real_time_label, self.output_mask_player, self.output_mask_media_tabWidget, self.output_mask_real_time_label, real_time_show_predict_flag) self.weight_label.setText( f" Using weight : ****** {Path(weight_path).name} ******") # 界面美化 self.gen_better_gui() self.media_source = "" # 推理媒体的路径 self.predict_progressBar.setValue(0) # 进度条归零 '''check box 绑定''' self.real_time_checkBox.stateChanged.connect( self.real_time_checkbox_state_changed) self.real_time_checkBox.setChecked(real_time_show_predict_flag) self.real_time_check_state = self.real_time_checkBox.isChecked()
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)
def __createChart(self): ##创建图表 chart = QChart() #创建 Chart ## chart.setTitle("简单函数曲线") chart.legend().setVisible(True) self.chartView.setChart(chart) #Chart添加到chartView pen=QPen() pen.setWidth(2) ##========LineSeries折线 和 ScatterSeries散点 seriesLine = QLineSeries() seriesLine.setName("LineSeries折线") seriesLine.setPointsVisible(False) #数据点不可见 pen.setColor(Qt.red) seriesLine.setPen(pen) seriesLine.hovered.connect(self.do_series_hovered) #信号 hovered seriesLine.clicked.connect(self.do_series_clicked) #信号 clicked chart.addSeries(seriesLine) #添加到chart seriesLinePoint = QScatterSeries() #散点序列 seriesLinePoint.setName("ScatterSeries散点") shape=QScatterSeries.MarkerShapeCircle #MarkerShapeRectangle seriesLinePoint.setMarkerShape(shape) #散点形状,只有2种 seriesLinePoint.setBorderColor(Qt.yellow) seriesLinePoint.setBrush(QBrush(Qt.red)) seriesLinePoint.setMarkerSize(10) #散点大小 seriesLinePoint.hovered.connect(self.do_series_hovered) #信号 hovered seriesLinePoint.clicked.connect(self.do_series_clicked) #信号 clicked chart.addSeries(seriesLinePoint) #添加到chart ##======== SplineSeries 曲线和 QScatterSeries 散点 seriesSpLine = QSplineSeries() seriesSpLine.setName("SplineSeries曲线") seriesSpLine.setPointsVisible(False) #数据点不可见 pen.setColor(Qt.blue) seriesSpLine.setPen(pen) seriesSpLine.hovered.connect(self.do_series_hovered) #信号 hovered seriesSpLine.clicked.connect(self.do_series_clicked) #信号 clicked seriesSpPoint = QScatterSeries() #散点序列 seriesSpPoint.setName("QScatterSeries") shape=QScatterSeries.MarkerShapeRectangle #MarkerShapeCircle seriesSpPoint.setMarkerShape(shape) #散点形状,只有2种 seriesSpPoint.setBorderColor(Qt.green) seriesSpPoint.setBrush(QBrush(Qt.blue)) seriesSpPoint.setMarkerSize(10) #散点大小 seriesSpPoint.hovered.connect(self.do_series_hovered) #信号 hovered seriesSpPoint.clicked.connect(self.do_series_clicked) #信号 clicked chart.addSeries(seriesSpLine) chart.addSeries(seriesSpPoint) ## 创建缺省坐标轴 chart.createDefaultAxes() #创建缺省坐标轴并与序列关联 chart.axisX().setTitleText("time(secs)") chart.axisX().setRange(0,10) chart.axisX().applyNiceNumbers() chart.axisY().setTitleText("value") chart.axisY().setRange(-2,2) chart.axisY().applyNiceNumbers() for marker in chart.legend().markers(): #QLegendMarker类型列表 marker.clicked.connect(self.do_LegendMarkerClicked)
class QtChartCanvas(QWidget): def __init__(self, parent=None): super(QtChartCanvas, self).__init__(parent) self.setStyleSheet("border:0;background-color:#263848") self.plotChart = QChart() self.plotChart.legend().hide() self.verticalLayout = QtWidgets.QVBoxLayout(self) self.plotView = QChartView(self.plotChart) self.plotView.setStyleSheet("border:0;background-color:#263848;") self.plotView.setBackgroundBrush(QBrush(QColor("#263848"))) self.plotChart.setBackgroundBrush(QBrush(QColor("#263848"))) #self.plotChart.setStyle() self.verticalLayout.addWidget(self.plotView) self.plotCurve = QSplineSeries() self.plotCurve.setColor(QColor("#AABFFF")) self.plotCurve.setUseOpenGL(True) self.plotCurve.pen().setColor(QColor("#FAF0FF")) self.plotChart.addSeries(self.plotCurve) # self.scatter=QScatterSeries() # self.scatter.setMarkerSize(8) # self.plotChart.addSeries(self.scatter) self.plotChart.createDefaultAxes() self.plotChart.axisY().setGridLineColor(QColor("#5D5C72")) self.plotChart.axisY().setLinePenColor(QColor("#9D9CA2")) self.plotChart.axisY().setLabelsColor(QColor("#F8F6F6")) self.plotChart.axisY().setRange(0, 100) self.plotChart.axisX().hide() self.RecvData = [] # 存储接收到的传感器数据 self.RecvIndx = 0 self.setLockY = True self.isTop = False self.minY = 0 self.maxY = 100 def update_figure(self, payload): data = payload["data"] self.RecvData.append(data) self.RecvData = self.RecvData[-20:] plotData = [] if self.isTop: for i, val in enumerate(self.RecvData): plotData.append(QPoint(i, val)) self.plotCurve.replace(plotData) #self.scatter.replace(plotData) self.plotChart.axisX().setMax(len(plotData)) if not self.setLockY: self.plotChart.axisY().setRange( min(self.RecvData) * 0.5, max(self.RecvData) * 1.3) else: self.plotChart.axisY().setRange(self.minY, self.maxY) def setYLimit(self, miny=0, maxy=100, lockY=True): self.setLockY = lockY if self.setLockY: self.maxY = maxy self.minY = miny def changeTop(self, isTop): self.isTop = isTop
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()
app = QApplication(sys.argv) ANGULAR_MIN = -100 ANGULAR_MAX = 100 RADIAL_MIN = -100 RADIAL_MAX = 100 series1 = QScatterSeries() series1.setName("scatter") for i in range(ANGULAR_MIN, ANGULAR_MAX + 1, 10): series1.append(i, (float(i) / RADIAL_MAX) * RADIAL_MAX + 8.0) series2 = QSplineSeries() series2.setName("spline") for i in range(ANGULAR_MIN, ANGULAR_MAX + 1, 10): series2.append(i, (float(i) / RADIAL_MAX) * RADIAL_MAX) series3 = QLineSeries() series3.setName("star outer") ad = (ANGULAR_MAX - ANGULAR_MIN) / 8.0 rd = (RADIAL_MAX - RADIAL_MIN) / 3.0 * 1.3 series3.append(ANGULAR_MIN, RADIAL_MAX) series3.append(ANGULAR_MIN + ad * 1, RADIAL_MIN + rd) series3.append(ANGULAR_MIN + ad * 2, RADIAL_MAX) series3.append(ANGULAR_MIN + ad * 3, RADIAL_MIN + rd) series3.append(ANGULAR_MIN + ad * 4, RADIAL_MAX) series3.append(ANGULAR_MIN + ad * 5, RADIAL_MIN + rd) series3.append(ANGULAR_MIN + ad * 6, RADIAL_MAX)
def setData(self, timeData, valueData, chartTypes="Bar"): axisX = QDateTimeAxis() axisX.setFormat("yyyy-MM-dd") if self.chartTypes == "Bar": # Clear all series self.clearAll() self.zoomSeries = QLineSeries(self.chart()) barSeries = QBarSeries(self.chart()) barset = QBarSet("data") barSeries.setBarWidth(0.8) barSeries.append(barset) for td, vd in zip(timeData, valueData): self.zoomSeries.append(td.toMSecsSinceEpoch(), vd) barset.append(valueData) self.zoomSeries.hide() self.chart().addSeries(self.zoomSeries) self.chart().addSeries(barSeries) self.chart().setAxisY(QValueAxis(), self.zoomSeries) axisX.setRange(min(timeData), max(timeData)) self.chart().setAxisX(axisX, self.zoomSeries) elif self.chartTypes == "Scatter": # Clear all series self.clearAll() self.zoomSeries = QLineSeries(self.chart()) scattSeries = QScatterSeries(self.chart()) scattSeries.setMarkerSize(8) for td, vd in zip(timeData, valueData): self.zoomSeries.append(td.toMSecsSinceEpoch(), vd) scattSeries.append(td.toMSecsSinceEpoch(), vd) self.zoomSeries.hide() self.chart().addSeries(self.zoomSeries) self.chart().addSeries(scattSeries) self.chart().setAxisY(QValueAxis(), self.zoomSeries) axisX.setRange(min(timeData), max(timeData)) self.chart().setAxisX(axisX, self.zoomSeries) elif self.chartTypes in ["Line", "PLine"]: self.clearAll() if self.chartTypes == "Line": self.zoomSeries = QLineSeries(self.chart()) else: self.zoomSeries = QSplineSeries(self.chart()) for td, vd in zip(timeData, valueData): self.zoomSeries.append(td.toMSecsSinceEpoch(), vd) self.chart().addSeries(self.zoomSeries) self.chart().setAxisY(QValueAxis(), self.zoomSeries) axisX.setRange(min(timeData), max(timeData)) self.chart().setAxisX(axisX, self.zoomSeries) elif self.chartTypes == "Area": self.clearAll() self.zoomSeries = QLineSeries() self.zoomSeries.setColor(QColor("#666666")) for td, vd in zip(timeData, valueData): self.zoomSeries.append(td.toMSecsSinceEpoch(), vd) areaSeries = QAreaSeries(self.zoomSeries, None) self.chart().addSeries(self.zoomSeries) self.chart().addSeries(areaSeries) self.chart().setAxisY(QValueAxis(), areaSeries) axisX.setRange(min(timeData), max(timeData)) self.chart().setAxisX(axisX, areaSeries) self.zoomSeries.hide() self.mintimeData = min(timeData) self.maxtimeData = max(timeData) self.BtnsWidget.dateRangeEdit.setDateRange([ self.mintimeData.toString("yyyy-MM-dd"), self.maxtimeData.toString("yyyy-MM-dd"), ]) self.updateView()
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")
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()