class CombinerIcon(ProjectItemIcon): _SHAKE_FACTOR = 0.05 def __init__(self, toolbox, x, y, project_item, icon): """View icon for the Design View. Args: toolbox (ToolBoxUI): QMainWindow instance x (float): Icon x coordinate y (float): Icon y coordinate project_item (ProjectItem): Item icon (str): icon resource path """ super().__init__(toolbox, x, y, project_item, icon, icon_color=QColor("#990000"), background_color=QColor("#ffcccc")) self.time_line = QTimeLine() self.time_line.setLoopCount(0) # loop forever self.time_line.setFrameRange(0, 10) self.time_line.setDirection(QTimeLine.Backward) self.time_line.valueChanged.connect( self._handle_time_line_value_changed) self.time_line.stateChanged.connect( self._handle_time_line_state_changed) self._svg_item_pos = self.svg_item.pos() @Slot(float) def _handle_time_line_value_changed(self, value): rect = self.svg_item.sceneBoundingRect() width = rect.width() height = rect.height() x = random.uniform(-self._SHAKE_FACTOR, self._SHAKE_FACTOR) * width y = random.uniform(-self._SHAKE_FACTOR, self._SHAKE_FACTOR) * height self.svg_item.setPos(self._svg_item_pos + QPointF(x, y)) @Slot("QTimeLine::State") def _handle_time_line_state_changed(self, new_state): if new_state == QTimeLine.NotRunning: self.svg_item.setPos(self._svg_item_pos) def start_animation(self): """Start the animation that plays when the Combiner associated to this GraphicsItem is running. """ if self.time_line.state() == QTimeLine.Running: return self.time_line.start() def stop_animation(self): """Stop animation""" if self.time_line.state() != QTimeLine.Running: return self.time_line.stop()
class ToolIcon(ProjectItemIcon): def __init__(self, toolbox, x, y, project_item, icon): """Tool icon for the Design View. Args: toolbox (ToolBoxUI): QMainWindow instance x (float): Icon x coordinate y (float): Icon y coordinate project_item (ProjectItem): Item icon (str): icon resource path """ super().__init__( toolbox, x, y, project_item, icon, icon_color=QColor("red"), background_color=QColor("#ffe6e6") ) self.time_line = QTimeLine() self.time_line.setLoopCount(0) # loop forever self.time_line.setFrameRange(0, 10) self.time_line.setDuration(1200) self.time_line.setDirection(QTimeLine.Backward) self.time_line.valueChanged.connect(self._handle_time_line_value_changed) self.time_line.stateChanged.connect(self._handle_time_line_state_changed) self._svg_item_pos = self.svg_item.pos() rect = self.svg_item.sceneBoundingRect() self._anim_transformation_origin_point_y = -0.75 * rect.height() self._anim_delta_x_factor = 0.5 * rect.width() @Slot(float) def _handle_time_line_value_changed(self, value): angle = value * 45.0 self.svg_item.setRotation(angle) delta_y = 0.5 * self.svg_item.sceneBoundingRect().height() delta = QPointF(self._anim_delta_x_factor * value, delta_y) self.svg_item.setPos(self._svg_item_pos + delta) @Slot("QTimeLine::State") def _handle_time_line_state_changed(self, new_state): if new_state == QTimeLine.Running: self.svg_item.setTransformOriginPoint(0, self._anim_transformation_origin_point_y) elif new_state == QTimeLine.NotRunning: self.svg_item.setTransformOriginPoint(0, 0) self.svg_item.setPos(self._svg_item_pos) self.svg_item.setRotation(0) def start_animation(self): """Starts the item execution animation. """ if self.time_line.state() == QTimeLine.Running: return self.time_line.start() def stop_animation(self): """Stop animation""" if self.time_line.state() != QTimeLine.Running: return self.time_line.stop()
class MainWindow(QMainWindow): def __init__(self): global pixmapDict, specialDescriptionDict super(MainWindow, self).__init__() self.ui = Ui_pipboy() self.ui.setupUi(self) self.ui.chartContainer.setContentsMargins(0, 0, 0, 0) self.anim = QTimeLine(20000, self) self.anim.setFrameRange(0, 500) self.anim.setLoopCount(0) self.anim.setUpdateInterval(16) self.anim.frameChanged[int].connect( self.ui.perks_description.verticalScrollBar().setValue) self.anim.frameChanged[int].connect( self.ui.aid_effect_label.verticalScrollBar().setValue) self.anim.frameChanged[int].connect( self.ui.data_description.verticalScrollBar().setValue) #self.anim2 = QPropertyAnimation(self.ui.main_tab, b"pos") #self.anim2.setEasingCurve(QEasingCurve.OutBounce) #self.anim2.setDuration(2000) #self.anim2.setStartValue(QPoint(10, -400)) #self.anim2.setEndValue(QPoint(10, 0)) #self.anim2.start() self.random = QRandomGenerator.global_() self.ui.stat_tab.setFocus() self.ui.stat_tab.currentChanged.connect(self.shift) self.ui.stat_tab.installEventFilter(self) self.ui.inv_tab.installEventFilter(self) self.ui.special_list.installEventFilter(self) self.ui.perks_list.installEventFilter(self) self.ui.test_list.installEventFilter(self) self.ui.apparel_list.installEventFilter(self) self.ui.aid_list.installEventFilter(self) self.ui.ammo_list.installEventFilter(self) self.ui.data_list.installEventFilter(self) self.ui.radio_list.installEventFilter(self) self.ui.main_img.setPixmap(description.main_img_pixmap) self.ui.special_image.setPixmap(description.pixmapDict.get(0)) self.ui.perks_image.setPixmap(description.pixmatPerksDict.get(0)) self.ui.weapon_image.setPixmap(description.pixmapWeaponDict.get(0)) self.ui.apparel_image.setPixmap(description.pixmapWeaponDict.get(0)) self.ui.aid_image.setPixmap(description.pixmapAidDict.get(0)) self.ui.ammo_image.setPixmap(description.pixmapAmmoDict.get(0)) lay = QVBoxLayout(self.ui.chartContainer) lay.setContentsMargins(0, 0, 0, 0) self.chartview = QtCharts.QChartView() self.chartview.setContentsMargins(0, 0, 0, 0) lay.addWidget(self.chartview) self.chart = QtCharts.QChart() self.chart.legend().hide() self.chart.setAnimationOptions(QtCharts.QChart.SeriesAnimations) self.series = QtCharts.QLineSeries() self.pen = QPen(QColor(119, 251, 81, 255)) self.pen.setWidth(3) self.pen.setJoinStyle(Qt.RoundJoin) self.series.setPen(self.pen) backgroundGradient = QLinearGradient(QPointF(100, 100), QPointF(200, 200)) backgroundGradient.setColorAt(0, QColor(0, 0, 0, 255)) backgroundGradient.setColorAt(1, QColor(0, 0, 0, 255)) self.chart.setBackgroundBrush(backgroundGradient) self.chart.setPlotAreaBackgroundBrush(backgroundGradient) self.chart.addSeries(self.series) self.chart.createDefaultAxes() self.chart.axisX(self.series).setVisible(False) self.chart.axisY(self.series).setVisible(False) self.chart.axisY(self.series).setRange(0, 100) self.chartview.setChart(self.chart) self.play = False self.player = QMediaPlayer() self.playlistFalloutNewVegas = QMediaPlaylist(self.player) self.playlistFalloutNewVegas.addMedia( QMediaContent(description.falooutNewVegas)) self.playlistFalloutNewVegas.setCurrentIndex(1) self.playListMohaveMusic = QMediaPlaylist(self.player) for url in description.mohaveMusic: self.playListMohaveMusic.addMedia(QMediaContent(url)) self.playListMohaveMusic.setCurrentIndex(1) self.playlisNewVegas = QMediaPlaylist(self.player) for url in description.newVegas: self.playlisNewVegas.addMedia(QMediaContent(url)) self.playlisNewVegas.setCurrentIndex(1) self.playlistDict = { 0: self.playlistFalloutNewVegas, 1: self.playListMohaveMusic, 2: self.playlisNewVegas } def append_data_and_plot(self, d): """Append and update the plot""" num, m = d ax1 = self.chart.axisX(self.series) xmin = xmax = num step = 100 for p in self.series.pointsVector()[-step:]: xmin = min(p.x(), xmin) xmax = max(p.x(), xmax) xmin = max(0, xmax - step) ax1.setMin(xmin) ax1.setMax(xmax) self.series.append(QPointF(num, m)) def eventFilter(self, obj, event): if event.type() == QEvent.KeyPress: #print(obj) if event.key() == 49: self.ui.main_tab.setCurrentIndex(1) self.ui.stat_tab.setFocus() #self.ui.hp_head.setValue(self.random.bounded(50, 100)) #self.ui.hp_left_arm.setValue(self.random.bounded(50, 100)) #self.ui.hp_right_arm.setValue(self.random.bounded(50, 100)) #self.ui.hp_left_leg.setValue(self.random.bounded(50, 100)) #self.ui.hp_right_leg.setValue(self.random.bounded(50, 100)) #self.ui.hp_body.setValue(self.random.bounded(50, 100)) return True elif event.key() == 50: self.ui.main_tab.setCurrentIndex(2) self.ui.inv_tab.setFocus() return True elif event.key() == 51: self.ui.main_tab.setCurrentIndex(3) self.ui.data_list.setFocus() self.ui.data_list.setCurrentRow(0) return True elif event.key() == 52: self.ui.main_tab.setCurrentIndex(4) return True elif event.key() == 53: self.ui.main_tab.setCurrentIndex(5) self.ui.radio_list.setFocus() self.ui.radio_list.setCurrentRow(0) return True elif event.key() == 54: print(QApplication.focusWidget()) return True #focus from stat_tab to special_list elif (obj == self.ui.stat_tab) and (self.ui.stat_tab.currentIndex() == 1) and (event.key() == 47): self.ui.special_list.setFocus() self.ui.special_list.setCurrentRow(0) self.ui.special_image.setPixmap(description.pixmapDict.get(0)) self.ui.special_description.setText( description.specialDescriptionDict.get(0)) return True # elif (obj == self.ui.special_list) and (event.key() == 16777236): self.ui.special_list.setCurrentRow( self.ui.special_list.currentRow() + 1) if (self.ui.special_list.currentRow() == -1): self.ui.special_list.setCurrentRow(0) self.ui.special_list.scrollToItem( self.ui.special_list.currentItem()) self.ui.special_image.setPixmap( description.pixmapDict.get( self.ui.special_list.currentRow())) self.ui.special_description.setText( description.specialDescriptionDict.get( self.ui.special_list.currentRow())) elif (obj == self.ui.special_list) and (event.key() == 16777234): self.ui.special_list.setCurrentRow( self.ui.special_list.currentRow() - 1) if (self.ui.special_list.currentRow() == -1): self.ui.special_list.setCurrentRow(0) self.ui.special_list.scrollToItem( self.ui.special_list.currentItem()) self.ui.special_image.setPixmap( description.pixmapDict.get( self.ui.special_list.currentRow())) self.ui.special_description.setText( description.specialDescriptionDict.get( self.ui.special_list.currentRow())) #focus from special_list to stat_tab elif (obj == self.ui.special_list) and (event.key() == 47): self.ui.special_list.setCurrentRow(-1) self.ui.stat_tab.setFocus() return True # focus from stat_tab to perks_list elif (obj == self.ui.stat_tab) and (self.ui.stat_tab.currentIndex() == 2) and (event.key() == 47): self.ui.perks_list.setFocus() self.ui.perks_list.setCurrentRow(0) self.anim.setCurrentTime(0) self.anim.start() elif (obj == self.ui.perks_list) and (event.key() == 16777236): self.ui.perks_list.setCurrentRow( self.ui.perks_list.currentRow() + 1) if (self.ui.perks_list.currentRow() == -1): self.ui.perks_list.setCurrentRow(0) self.ui.perks_list.scrollToItem( self.ui.perks_list.currentItem()) self.ui.perks_image.setPixmap( description.pixmatPerksDict.get( self.ui.perks_list.currentRow())) self.ui.perks_description.setText( description.perksDescriptionDict.get( self.ui.perks_list.currentRow())) self.anim.stop() self.anim.setCurrentTime(0) self.anim.start() elif (obj == self.ui.perks_list) and (event.key() == 16777234): self.ui.perks_list.setCurrentRow( self.ui.perks_list.currentRow() - 1) if (self.ui.perks_list.currentRow() == -1): self.ui.perks_list.setCurrentRow(0) self.ui.perks_list.scrollToItem( self.ui.perks_list.currentItem()) self.ui.perks_image.setPixmap( description.pixmatPerksDict.get( self.ui.perks_list.currentRow())) self.ui.perks_description.setText( description.perksDescriptionDict.get( self.ui.perks_list.currentRow())) self.anim.stop() self.anim.setCurrentTime(0) self.anim.start() #focus from perks_list to stat_tab elif (obj == self.ui.perks_list) and (event.key() == 47): self.ui.perks_list.setCurrentRow(-1) self.ui.stat_tab.setFocus() self.anim.stop() return True #/------------------------------------------------INV-WEAPON--------------------------------------------------/ elif (obj == self.ui.inv_tab) and (self.ui.inv_tab.currentIndex() == 0) and (event.key() == 47): self.ui.test_list.setFocus() self.ui.test_list.setCurrentRow(0) return True elif (obj == self.ui.test_list) and (event.key() == 47): self.ui.test_list.setCurrentRow(-1) self.ui.inv_tab.setFocus() return True elif (obj == self.ui.test_list) and (event.key() == 16777236): self.ui.test_list.setCurrentRow( self.ui.test_list.currentRow() + 1) if (self.ui.test_list.currentRow() == -1): self.ui.test_list.setCurrentRow(0) self.ui.test_list.scrollToItem(self.ui.test_list.currentItem()) self.ui.weapon_image.setPixmap( description.pixmapWeaponDict.get( self.ui.test_list.currentRow())) self.ui.w_damage_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[0]) self.ui.w_weight_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[1]) self.ui.w_cost_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[2]) self.ui.w_durability_PB.setValue(self.random.bounded(20, 100)) self.ui.w_ammo_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[3]) self.ui.w_effect_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[4]) elif (obj == self.ui.test_list) and (event.key() == 16777234): self.ui.test_list.setCurrentRow( self.ui.test_list.currentRow() - 1) if (self.ui.test_list.currentRow() == -1): self.ui.test_list.setCurrentRow(0) self.ui.test_list.scrollToItem(self.ui.test_list.currentItem()) self.ui.weapon_image.setPixmap( description.pixmapWeaponDict.get( self.ui.test_list.currentRow())) self.ui.w_damage_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[0]) self.ui.w_weight_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[1]) self.ui.w_cost_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[2]) self.ui.w_durability_PB.setValue(self.random.bounded(20, 100)) self.ui.w_ammo_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[3]) self.ui.w_effect_label.setText( description.weaponDescriptionDict.get( self.ui.test_list.currentRow())[4]) #/------------------------------------------------INV-APPAREL--------------------------------------------------/ elif (obj == self.ui.inv_tab) and (self.ui.inv_tab.currentIndex() == 1) and (event.key() == 47): self.ui.apparel_list.setFocus() self.ui.apparel_list.setCurrentRow(0) return True elif (obj == self.ui.apparel_list) and (event.key() == 47): self.ui.apparel_list.setCurrentRow(-1) self.ui.inv_tab.setFocus() return True elif (obj == self.ui.apparel_list) and (event.key() == 16777236): self.ui.apparel_list.setCurrentRow( self.ui.apparel_list.currentRow() + 1) if (self.ui.apparel_list.currentRow() == -1): self.ui.apparel_list.setCurrentRow(0) self.ui.apparel_list.scrollToItem( self.ui.apparel_list.currentItem()) self.ui.apparel_image.setPixmap( description.pixmapClothesDict.get( self.ui.apparel_list.currentRow())) self.ui.a_damage_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[0]) self.ui.a_weight_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[1]) self.ui.a_cost_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[2]) self.ui.a_durability_PB.setValue(self.random.bounded(0, 100)) self.ui.a_type_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[3]) self.ui.a_effect_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[4]) elif (obj == self.ui.apparel_list) and (event.key() == 16777234): self.ui.apparel_list.setCurrentRow( self.ui.apparel_list.currentRow() - 1) if (self.ui.apparel_list.currentRow() == -1): self.ui.apparel_list.setCurrentRow(0) self.ui.apparel_list.scrollToItem( self.ui.apparel_list.currentItem()) self.ui.apparel_image.setPixmap( description.pixmapClothesDict.get( self.ui.apparel_list.currentRow())) self.ui.a_damage_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[0]) self.ui.a_weight_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[1]) self.ui.a_cost_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[2]) self.ui.a_durability_PB.setValue(self.random.bounded(0, 100)) self.ui.a_type_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[3]) self.ui.a_effect_label.setText( description.clothesDescriptionDict.get( self.ui.apparel_list.currentRow())[4]) #/------------------------------------------------INV-AID--------------------------------------------------/ elif (obj == self.ui.inv_tab) and (self.ui.inv_tab.currentIndex() == 2) and (event.key() == 47): self.ui.aid_list.setFocus() self.ui.aid_list.setCurrentRow(0) return True elif (obj == self.ui.aid_list) and (event.key() == 47): self.ui.aid_list.setCurrentRow(-1) self.ui.inv_tab.setFocus() return True elif (obj == self.ui.aid_list) and (event.key() == 16777236): self.ui.aid_list.setCurrentRow(self.ui.aid_list.currentRow() + 1) if (self.ui.aid_list.currentRow() == -1): self.ui.aid_list.setCurrentRow(0) self.ui.aid_list.scrollToItem(self.ui.aid_list.currentItem()) self.ui.aid_image.setPixmap( description.pixmapAidDict.get( self.ui.aid_list.currentRow())) self.ui.aid_weight_label.setText( description.aidDescriptionDict.get( self.ui.aid_list.currentRow())[0]) self.ui.aid_cost_label.setText( description.aidDescriptionDict.get( self.ui.aid_list.currentRow())[1]) self.ui.aid_effect_label.setText( description.aidDescriptionDict.get( self.ui.aid_list.currentRow())[2]) self.anim.stop() self.anim.setCurrentTime(0) self.anim.start() elif (obj == self.ui.aid_list) and (event.key() == 16777234): self.ui.aid_list.setCurrentRow(self.ui.aid_list.currentRow() - 1) if (self.ui.aid_list.currentRow() == -1): self.ui.aid_list.setCurrentRow(0) self.ui.aid_list.scrollToItem(self.ui.aid_list.currentItem()) self.ui.aid_image.setPixmap( description.pixmapAidDict.get( self.ui.aid_list.currentRow())) self.ui.aid_weight_label.setText( description.aidDescriptionDict.get( self.ui.aid_list.currentRow())[0]) self.ui.aid_cost_label.setText( description.aidDescriptionDict.get( self.ui.aid_list.currentRow())[1]) self.ui.aid_effect_label.setText( description.aidDescriptionDict.get( self.ui.aid_list.currentRow())[2]) self.anim.stop() self.anim.setCurrentTime(0) self.anim.start() #/------------------------------------------------INV-AMMO--------------------------------------------------/ elif (obj == self.ui.inv_tab) and (self.ui.inv_tab.currentIndex() == 3) and (event.key() == 47): self.ui.ammo_list.setFocus() self.ui.ammo_list.setCurrentRow(0) return True elif (obj == self.ui.ammo_list) and (event.key() == 47): self.ui.ammo_list.setCurrentRow(-1) self.ui.inv_tab.setFocus() return True elif (obj == self.ui.ammo_list) and (event.key() == 16777236): self.ui.ammo_list.setCurrentRow( self.ui.ammo_list.currentRow() + 1) if (self.ui.ammo_list.currentRow() == -1): self.ui.ammo_list.setCurrentRow(0) self.ui.ammo_list.scrollToItem(self.ui.ammo_list.currentItem()) self.ui.ammo_image.setPixmap( description.pixmapAmmoDict.get( self.ui.ammo_list.currentRow())) self.ui.ammo_weight_label.setText( description.ammoDescriptionDict.get( self.ui.ammo_list.currentRow())[0]) self.ui.ammo_cost_label.setText( description.ammoDescriptionDict.get( self.ui.ammo_list.currentRow())[1]) elif (obj == self.ui.ammo_list) and (event.key() == 16777234): self.ui.ammo_list.setCurrentRow( self.ui.ammo_list.currentRow() - 1) if (self.ui.ammo_list.currentRow() == -1): self.ui.ammo_list.setCurrentRow(0) self.ui.ammo_list.scrollToItem(self.ui.ammo_list.currentItem()) self.ui.ammo_image.setPixmap( description.pixmapAmmoDict.get( self.ui.ammo_list.currentRow())) self.ui.ammo_weight_label.setText( description.ammoDescriptionDict.get( self.ui.ammo_list.currentRow())[0]) self.ui.ammo_cost_label.setText( description.ammoDescriptionDict.get( self.ui.ammo_list.currentRow())[1]) #/------------------------------------------------DATA--------------------------------------------------/ elif (obj == self.ui.data_list) and (event.key() == 16777236): self.ui.data_list.setCurrentRow( self.ui.data_list.currentRow() + 1) if (self.ui.data_list.currentRow() == -1): self.ui.data_list.setCurrentRow(0) self.ui.data_list.scrollToItem(self.ui.data_list.currentItem()) self.ui.data_description.setText( description.questDescriptionDict.get( self.ui.data_list.currentRow())) self.anim.stop() self.anim.setCurrentTime(0) self.anim.start() elif (obj == self.ui.data_list) and (event.key() == 16777234): self.ui.data_list.setCurrentRow( self.ui.data_list.currentRow() - 1) if (self.ui.data_list.currentRow() == -1): self.ui.data_list.setCurrentRow(0) self.ui.data_list.scrollToItem(self.ui.data_list.currentItem()) self.ui.data_description.setText( description.questDescriptionDict.get( self.ui.data_list.currentRow())) self.anim.stop() self.anim.setCurrentTime(0) self.anim.start() #/------------------------------------------------RADIO--------------------------------------------------/ elif (obj == self.ui.radio_list) and (event.key() == 16777236): self.ui.radio_list.setCurrentRow( self.ui.radio_list.currentRow() + 1) if (self.ui.radio_list.currentRow() == -1): self.ui.radio_list.setCurrentRow(0) elif (obj == self.ui.radio_list) and (event.key() == 16777234): self.ui.radio_list.setCurrentRow( self.ui.radio_list.currentRow() - 1) if (self.ui.radio_list.currentRow() == -1): self.ui.radio_list.setCurrentRow(0) #self.ui.data_description.setText(description.questDescriptionDict.get(self.ui.radio_list.currentRow())) elif (obj == self.ui.radio_list) and (event.key() == 47): if self.play: self.player.stop() self.play = False else: self.player.setPlaylist( self.playlistDict.get(self.ui.radio_list.currentRow())) self.playListMohaveMusic.setCurrentIndex( self.random.bounded(0, 9) + 1) self.playlisNewVegas.setCurrentIndex( self.random.bounded(0, 10) + 1) self.player.play() self.play = True return True else: #print(event.key()) return True return super(MainWindow, self).eventFilter(obj, event) @Slot() def shift(self): print(self.ui.stat_tab.currentIndex()) index = self.ui.stat_tab.currentIndex() if index == 0: self.ui.stat_tab.setGeometry(0, 0, 904, 380) elif index == 1: self.ui.stat_tab.setGeometry(-108, 0, 904, 380) elif index == 2: self.ui.stat_tab.setGeometry(-214, 0, 904, 380)
class ImporterExporterAnimation: def __init__(self, item, duration=2000, count=5, percentage_size=0.24, x_shift=0): """Initializes animation stuff. Args: item (QGraphicsItem): The item on top of which the animation should play. """ self._item = item self.cubes = [QGraphicsTextItem("\uf1b2", item) for i in range(count)] self.opacity_at_value_path = QPainterPath(QPointF(0.0, 0.0)) self.opacity_at_value_path.lineTo(QPointF(0.01, 1.0)) self.opacity_at_value_path.lineTo(QPointF(0.5, 1.0)) self.opacity_at_value_path.lineTo(QPointF(1.0, 0.0)) self.time_line = QTimeLine() self.time_line.setLoopCount(0) # loop forever self.time_line.setFrameRange(0, 10) self.time_line.setDuration(duration) self.time_line.setCurveShape(QTimeLine.LinearCurve) self.time_line.valueChanged.connect( self._handle_time_line_value_changed) self.time_line.stateChanged.connect( self._handle_time_line_state_changed) font = QFont('Font Awesome 5 Free Solid') item_rect = item.rect() cube_size = percentage_size * 0.875 * item_rect.height() font.setPixelSize(cube_size) rect = item_rect.translated(-0.5 * cube_size + x_shift, -cube_size) end = rect.center() ctrl = end - QPointF(0, 0.6 * rect.height()) lower, upper = 0.2, 0.8 starts = [lower + i * (upper - lower) / count for i in range(count)] starts = [ rect.topLeft() + QPointF(start * rect.width(), 0) for start in starts ] self.paths = [QPainterPath(start) for start in starts] for path in self.paths: path.quadTo(ctrl, end) self.offsets = [i / count for i in range(count)] for cube in self.cubes: cube.setFont(font) cube.setDefaultTextColor("#003333") cube.setTransformOriginPoint(cube.boundingRect().center()) cube.hide() cube.setOpacity(0) @Slot(float) def _handle_time_line_value_changed(self, value): for cube, offset, path in zip(self.cubes, self.offsets, self.paths): value = (offset + value) % 1.0 opacity = self.opacity_at_value_path.pointAtPercent(value).y() cube.setOpacity(opacity) percent = self.percent(value) point = path.pointAtPercent(percent) angle = percent * 360.0 cube.setPos(point) cube.setRotation(angle) @Slot("QTimeLine::State") def _handle_time_line_state_changed(self, new_state): if new_state == QTimeLine.Running: random.shuffle(self.offsets) for cube in self.cubes: cube.show() elif new_state == QTimeLine.NotRunning: for cube in self.cubes: cube.hide() def start(self): """Starts the animation.""" if self.time_line.state() == QTimeLine.Running: return self.time_line.start() @staticmethod def percent(value): raise NotImplementedError() def stop(self): """Stops the animation""" self.time_line.stop()
class ToolIcon(ProjectItemIcon): def __init__(self, toolbox, x, y, w, h, name): """Tool icon for the Design View. Args: toolbox (ToolBoxUI): QMainWindow instance x (float): Icon x coordinate y (float): Icon y coordinate w (float): Width of master icon h (float): Height of master icon name (str): Item name """ super().__init__( toolbox, x, y, w, h, name, ":/icons/project_item_icons/hammer.svg", icon_color=QColor("red"), background_color=QColor("#ffe6e6"), ) # animation stuff self.timer = QTimeLine() self.timer.setLoopCount(0) # loop forever self.timer.setFrameRange(0, 10) # self.timer.setCurveShape(QTimeLine.CosineCurve) self.timer.valueForTime = self._value_for_time self.tool_animation = QGraphicsItemAnimation() self.tool_animation.setItem(self.svg_item) self.tool_animation.setTimeLine(self.timer) self.delta = 0.25 * self.svg_item.sceneBoundingRect().height() @staticmethod def _value_for_time(msecs): rem = (msecs % 1000) / 1000 return 1.0 - rem def start_animation(self): """Start the animation that plays when the Tool associated to this GraphicsItem is running. """ if self.timer.state() == QTimeLine.Running: return self.svg_item.moveBy(0, -self.delta) offset = 0.75 * self.svg_item.sceneBoundingRect().height() for angle in range(1, 45): step = angle / 45.0 self.tool_animation.setTranslationAt(step, 0, offset) self.tool_animation.setRotationAt(step, angle) self.tool_animation.setTranslationAt(step, 0, -offset) self.tool_animation.setPosAt( step, QPointF(self.svg_item.pos().x(), self.svg_item.pos().y() + offset)) self.timer.start() def stop_animation(self): """Stop animation""" if self.timer.state() != QTimeLine.Running: return self.timer.stop() self.svg_item.moveBy(0, self.delta) self.timer.setCurrentTime(999)
class ImportExportAnimation: def __init__(self, parent_item, src_item, dst_item, duration=2000): """Initializes animation stuff. Args: parent_item (QGraphicsItem): The item on top of which the animation should play. src_item (QGraphicsItem): The source item. dst_item (QGraphicsItem): The destination item. duration (int. optional): The desired duration of each loop in milliseconds, defaults to 1000. """ self._parent_item = parent_item self.src_item = src_item self.dst_item = dst_item font = QFont('Font Awesome 5 Free Solid') size = 0.875 * round(parent_item.rect().height() / 2) font.setPixelSize(size) self.src_item.setFont(font) self.dst_item.setFont(font) self.src_opacity_effect = QGraphicsOpacityEffect() self.src_item.setGraphicsEffect(self.src_opacity_effect) self.dst_opacity_effect = QGraphicsOpacityEffect() self.dst_item.setGraphicsEffect(self.dst_opacity_effect) self.timer = QTimeLine() self.timer.setLoopCount(0) # loop forever self.timer.setFrameRange(0, 10) self.timer.valueChanged.connect(self._handle_timer_value_changed) self.timer.setDuration(duration) self.src_animation = QGraphicsItemAnimation() self.src_animation.setItem(self.src_item) self.src_animation.setTimeLine(self.timer) self.dst_animation = QGraphicsItemAnimation() self.dst_animation.setItem(self.dst_item) self.dst_animation.setTimeLine(self.timer) @Slot(float) def _handle_timer_value_changed(self, value): self.src_opacity_effect.setOpacity(1.0 - 2 * value) self.dst_opacity_effect.setOpacity(2 * value - 1.0) def start(self): """Starts the animation.""" rect = self._parent_item.rect() dx = self.src_item.boundingRect().width() dy = self.dst_item.boundingRect().height() rect.adjust(0, 0, -dx, -dy) src, dst = rect.topLeft(), rect.bottomRight() vec = dst - src self.src_item.setParentItem(self._parent_item) self.dst_item.setParentItem(self._parent_item) self.src_item.setPos(src) self.dst_item.setPos(src) self.src_opacity_effect.setOpacity(0.0) self.dst_opacity_effect.setOpacity(0.0) for i in range(100): step = i / 100.0 self.src_animation.setPosAt(step, src + vec * step) self.dst_animation.setPosAt(step, src + vec * step) self.timer.start() def stop(self): """Stops the animation""" self.timer.stop() self.src_item.setParentItem(None) self.dst_item.setParentItem(None) self.src_item.scene().removeItem(self.src_item) self.dst_item.scene().removeItem(self.dst_item) self.timer.setCurrentTime(999)