class MainWidget(QWidget): def __init__(self): super(MainWidget, self).__init__() self._blur = QGraphicsBlurEffect() self._blur.setBlurRadius(0) self.image = ImageView() self.image.setGraphicsEffect(self._blur) self.video = QVideoWidget() self.label = QLabel() self.label.setMaximumHeight(25) self.label.setStyleSheet('color: rgb(200, 200, 200);') font = QFont() font.setPixelSize(20) font.setWeight(QFont.Bold) self.label.setFont(font) self.setLayout(QVBoxLayout()) self.layout().addWidget(self.image) self.layout().addWidget(self.video) self.layout().addWidget(self.label) self.mplayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.mplayer.setVideoOutput(self.video) self.mplayer.error.connect( lambda: print("Video:", self.mplayer.errorString())) self.mplayer.mediaStatusChanged.connect(self.state_changed) self.overlay = QLabel(self) self.overlay.setFrameStyle(Qt.FramelessWindowHint) self.overlay.setStyleSheet( 'background-color: rgba(0,0,0,0.7); color: rgba(200,200,200,1);') self.overlay.setFont(font) self.overlay.setVisible(False) self.overlay.setWordWrap(True) def resize(self): self.overlay.setGeometry(0, 3 * self.height() // 4 - 50, self.width(), 100) def resizeEvent(self, event): super().resizeEvent(event) self.resize() def state_changed(self, state): if state == QMediaPlayer.EndOfMedia: self.mplayer.setPosition(0) self.mplayer.play() @property def blur(self): return self._blur.blurRadius() @blur.setter def blur(self, value): self._blur.setBlurRadius(value) def load(self, pic, *args, **kwargs): if isinstance(pic, str): still = path.splitext(pic)[1].lower()[1:] not in ('webm', 'mp4') else: still = pic.is_still if pic else True if still: self.image.load(pic, *args, **kwargs) self.video.hide() self.image.show() self.mplayer.stop() else: url = pic if isinstance(pic, str) else pic.filename self.mplayer.setMedia(QMediaContent(QUrl.fromLocalFile(url))) self.mplayer.setMuted(True) self.mplayer.play() self.image.hide() self.video.show() self.overlay.setVisible(False) def message(self, msg): self.label.setText('<div align="center">{}</div>'.format(msg)) def flash(self, msg): self.overlay.setText('<div align="center">{}</div>'.format(msg)) self.overlay.setVisible(True) def halt(self): self.mplayer.stop()
class NumPadWidget(object): def __init__(self, nums, parent): super().__init__() self.nums = nums self.parent = parent self.tile_events = events.TileInterfaceEvent() # Init main widget for master-controlling NumPad self.widget = QWidget() self.widget.setObjectName('NumPad') # Create blur effect for widgets self.blur_top_lbl = QGraphicsBlurEffect() self.blur_top_lbl.setBlurRadius(0.0) self.blur_bottom_lbl = QGraphicsBlurEffect() self.blur_bottom_lbl.setBlurRadius(0.0) self.opacity_effect = QGraphicsOpacityEffect() self.opacity_effect.setOpacity(0.0) # Create animation classes self.blur_anim = QVariantAnimation() self.blur_anim.setEasingCurve(QEasingCurve.InOutQuad) self.blur_anim.valueChanged.connect(self.play_animation) self.opacity_anim = QPropertyAnimation(self.opacity_effect, b'opacity') self.opacity_anim.setEasingCurve(QEasingCurve.InOutQuad) elements_hbl = QVBoxLayout() # Top label of NumPad self.top_lbl = QLabel() self.top_lbl.setGraphicsEffect(self.blur_top_lbl) self.top_lbl.setText(str(nums)) self.top_lbl.setObjectName('NumPad') self.top_lbl.setAlignment(Qt.AlignCenter) # Bottom label of NumPad self.bottom_lbl = QLabel() self.bottom_lbl.setGraphicsEffect(self.blur_bottom_lbl) self.bottom_lbl.setObjectName('NumPad') self.bottom_lbl.setAlignment(Qt.AlignCenter) elements_hbl.addWidget(self.top_lbl, 50) elements_hbl.addWidget(self.bottom_lbl, 50) self.widget.setLayout(elements_hbl) self.create_master_numpad() # Events and signals widget self.widget.enterEvent = lambda event: self.enter_event() self.widget.leaveEvent = lambda event: self.leave_event() def create_master_numpad(self): self.overlay_widget = QWidget(self.widget) self.overlay_widget.setObjectName("OverlayNumPadWidget") sound_pbtn_widget = QWidget(self.overlay_widget) # sound_pbtn_widget.setAttribute(Qt.WA_TranslucentBackground) # NumPad widgets, layouts and items sound_name_lbl = QLabel(self.overlay_widget) sound_name_lbl.setObjectName('NumPadName') sound_name_lbl.setAlignment(Qt.AlignCenter) sound_name_lbl.setText('Name of Sound') numpad_spacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) settings_numpad_pbtn = QPushButton(self.overlay_widget) settings_numpad_pbtn.setObjectName('NumPad') settings_numpad_pbtn.setText('Settings') add_numpad_pbtn = QPushButton(self.overlay_widget) add_numpad_pbtn.setObjectName('NumPad') add_numpad_pbtn.setText('Add Sound') remove_numpad_pbtn = QPushButton(self.overlay_widget) remove_numpad_pbtn.setObjectName('NumPad') remove_numpad_pbtn.setText('Remove Sound') # Master sound buttons play_sound_pbtn = QPushButton() play_sound_pbtn.setObjectName('PlayBtns') play_sound_pbtn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) play_sound_pbtn.setIcon( QIcon('./interface-stylesheets/interface-element/play.gif')) play_sound_pbtn.setAccessibleName('NumPadPushButton_%d' % self.nums) begin_sound_pbtn = QPushButton() begin_sound_pbtn.setObjectName('PlayBtns') begin_sound_pbtn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) begin_sound_pbtn.setIcon( QIcon('./interface-stylesheets/interface-element/end.gif')) end_sound_pbtn = QPushButton() end_sound_pbtn.setObjectName('PlayBtns') end_sound_pbtn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) end_sound_pbtn.setIcon( QIcon('./interface-stylesheets/interface-element/begin.gif')) overlay_pbtn_hbl = QVBoxLayout() overlay_pbtn_hbl.setContentsMargins(0, 0, 0, 0) overlay_pbtn_hbl.setSpacing(0) # Create and set layouts and add widgets play_sound_hbl = QHBoxLayout() play_sound_hbl.setContentsMargins(0, 0, 0, 0) play_sound_hbl.addWidget(begin_sound_pbtn) play_sound_hbl.addWidget(play_sound_pbtn) play_sound_hbl.addWidget(end_sound_pbtn) overlay_pbtn_hbl.addWidget(sound_name_lbl) overlay_pbtn_hbl.addItem(numpad_spacer) overlay_pbtn_hbl.addWidget(sound_pbtn_widget) overlay_pbtn_hbl.addWidget(add_numpad_pbtn) overlay_pbtn_hbl.addWidget(remove_numpad_pbtn) overlay_pbtn_hbl.addWidget(settings_numpad_pbtn) sound_pbtn_widget.setLayout(play_sound_hbl) self.overlay_widget.setLayout(overlay_pbtn_hbl) # Custom parameters self.overlay_widget.setGraphicsEffect(self.opacity_effect) # Events and signals widget self.widget.resizeEvent = lambda event: self.resize_event() play_sound_pbtn.clicked.connect( lambda: self.tile_events.switch_play_pbtn(play_sound_pbtn)) settings_numpad_pbtn.mousePressEvent = lambda event: self.tile_events.press_settings_buttonEvent( self.parent) def set_text_lbl_icons(self, bottom_text_lbl): if type(bottom_text_lbl) is str: self.bottom_lbl.setText(bottom_text_lbl) elif bottom_text_lbl is not None: pixmap_lbl = QPixmap( './interface-stylesheets/interface-element/%d_numpad_night.png' % bottom_text_lbl) pixmap_lbl.scaled(32, 32, Qt.KeepAspectRatio, Qt.FastTransformation) self.bottom_lbl.setPixmap(pixmap_lbl) # If mouse pointer on the widget then play animate widget buttons and blur master widget def enter_event(self): self.blur_anim.setDirection(QPropertyAnimation.Forward) self.blur_anim.setDuration(500) self.blur_anim.setStartValue(self.blur_top_lbl.blurRadius()) self.blur_anim.setEndValue(8.0) self.blur_anim.start() self.opacity_anim.setDirection(QPropertyAnimation.Forward) self.opacity_anim.setDuration(500) self.opacity_anim.setStartValue(self.opacity_effect.opacity()) self.opacity_anim.setEndValue(0.6) self.opacity_anim.start() # If mouse pointer out the widget then play reverse animate widget buttons and unblur master widget def leave_event(self): self.blur_anim.setDirection(QPropertyAnimation.Backward) self.blur_anim.setDuration(500) self.blur_anim.setStartValue(0.0) self.blur_anim.setEndValue(self.blur_top_lbl.blurRadius()) self.blur_anim.start() self.opacity_anim.setDirection(QPropertyAnimation.Backward) self.opacity_anim.setDuration(500) self.opacity_anim.setStartValue(0.0) self.opacity_anim.setEndValue(self.opacity_effect.opacity()) self.opacity_anim.start() def play_animation(self): self.blur_top_lbl.setBlurRadius(self.blur_anim.currentValue()) self.blur_bottom_lbl.setBlurRadius(self.blur_anim.currentValue()) def resize_event(self): self.overlay_widget.setGeometry(0, 0, self.widget.geometry().width(), self.widget.geometry().height()) def return_top_lbl(self): return self.top_lbl def return_bottom_lbl(self): return self.bottom_lbl def return_widget(self): return self.widget