class PlayerControlPanel(FFrame): def __init__(self, app, parent=None): super().__init__(parent) self._app = app self._layout = QHBoxLayout(self) self.previous_btn = PlayerControlButton(self._app, '上一首', self) self.pp_btn = PlayerControlButton(self._app, '播放', self) self.next_btn = PlayerControlButton(self._app, '下一首', self) self.progress_slider = ProgressSlider(self._app, self) self.volume_slider = VolumeSlider(self._app, self) self.progress_label = ProgressLabel(self._app, '00:00/00:00', self) self._btn_container = FFrame(self) self._slider_container = FFrame(self) self._bc_layout = QHBoxLayout(self._btn_container) self._sc_layout = QHBoxLayout(self._slider_container) self.setObjectName('pc_panel') self.set_theme_style() self.setup_ui() def set_theme_style(self): theme = self._app.theme_manager.current_theme style_str = ''' #{0} {{ background: transparent; color: {1}; }} '''.format(self.objectName(), theme.foreground.name(), theme.color0.name()) self.setStyleSheet(style_str) def setup_ui(self): self._btn_container.setFixedWidth(140) self._slider_container.setMinimumWidth(700) self.progress_label.setFixedWidth(90) self._layout.setSpacing(0) self._layout.setContentsMargins(0, 0, 0, 0) self._bc_layout.setSpacing(0) self._bc_layout.setContentsMargins(0, 0, 0, 0) self._bc_layout.addWidget(self.previous_btn) self._bc_layout.addStretch(1) self._bc_layout.addWidget(self.pp_btn) self._bc_layout.addStretch(1) self._bc_layout.addWidget(self.next_btn) self._sc_layout.addWidget(self.progress_slider) self._sc_layout.addSpacing(2) self._sc_layout.addWidget(self.progress_label) self._sc_layout.addSpacing(5) self._sc_layout.addWidget(self.volume_slider) self._layout.addWidget(self._btn_container) self._layout.addSpacing(10) self._layout.addWidget(self._slider_container)
class DescriptionPreviewDialog(FDialog): def __init__(self, app, parent=None): super().__init__(parent) self._app = app self.setObjectName('n_desc_preview_dialog') self.desc_container = DescriptionContainer(self._app, self) self._container = FFrame(self) self._container.setObjectName('n_desc_preview_dialog_container') self.setWindowFlags(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) self.set_theme_style() self._container_layout = QVBoxLayout(self._container) self._layout = QVBoxLayout(self) self.setup_ui() def set_theme_style(self): theme = self._app.theme_manager.current_theme style_str = ''' #{0} {{ color: {3}; }} #{1} {{ background: {2}; border: 5px solid {4}; border-radius: 5px; padding: 3px; }} '''.format(self.objectName(), self._container.objectName(), theme.background.name(), theme.foreground.name(), theme.random_color().name()) self.setStyleSheet(style_str) def setup_ui(self): self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self._container_layout.setContentsMargins(0, 0, 0, 0) self._container_layout.setSpacing(0) self._layout.addWidget(self._container) self._container_layout.addWidget(self.desc_container) def set_copy(self, desc_container): self.desc_container.set_html(desc_container.html) def keyPressEvent(self, event): key_code = event.key() if key_code == Qt.Key_Space: self.close() else: super().keyPressEvent(event)
def __init__(self, app, parent=None): super().__init__(parent) self._app = app self.songs_table = None self.img_label = CoverImgLabel(self._app) self.desc_container = DescriptionContainer(self._app) self.info_container = FFrame(parent=self) self.table_control = TableControl(self._app) self._layout = QVBoxLayout(self) self._info_layout = QHBoxLayout(self.info_container) self.setup_ui()
def __init__(self, app, parent=None): super().__init__(parent) self._app = app self.setObjectName('n_desc_preview_dialog') self.desc_container = DescriptionContainer(self._app, self) self._container = FFrame(self) self._container.setObjectName('n_desc_preview_dialog_container') self.setWindowFlags(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) self.set_theme_style() self._container_layout = QVBoxLayout(self._container) self._layout = QVBoxLayout(self) self.setup_ui()
def __init__(self, app, parent=None): super().__init__(parent) self._app = app self._layout = QHBoxLayout(self) self.previous_btn = PlayerControlButton(self._app, '上一首', self) self.pp_btn = PlayerControlButton(self._app, '播放', self) self.next_btn = PlayerControlButton(self._app, '下一首', self) self.progress_slider = ProgressSlider(self._app, self) self.volume_slider = VolumeSlider(self._app, self) self.progress_label = ProgressLabel(self._app, '00:00/00:00', self) self._btn_container = FFrame(self) self._slider_container = FFrame(self) self._bc_layout = QHBoxLayout(self._btn_container) self._sc_layout = QHBoxLayout(self._slider_container) self.setObjectName('pc_panel') self.set_theme_style() self.setup_ui()
def __init__(self, app): super().__init__() self._app = app self.login_dialog = LoginDialog(self._app, self._app) self.login_btn = LoginButton(self._app) self._lb_container = FFrame() self.songs_table_container = SongsTable_Container(self._app) self.fm_item = LP_GroupItem(self._app, '私人FM') self.fm_item.set_img_text('Ω') self.recommend_item = LP_GroupItem(self._app, '每日推荐') self.recommend_item.set_img_text('✦') self.simi_item = LP_GroupItem(self._app, '相似歌曲') self.simi_item.set_img_text('∾') self._lbc_layout = QHBoxLayout(self._lb_container) self.setup()
class SongsTable_Container(FFrame): def __init__(self, app, parent=None): super().__init__(parent) self._app = app self.songs_table = None self.img_label = CoverImgLabel(self._app) self.desc_container = DescriptionContainer(self._app) self.info_container = FFrame(parent=self) self.table_control = TableControl(self._app) self._layout = QVBoxLayout(self) self._info_layout = QHBoxLayout(self.info_container) self.setup_ui() def setup_ui(self): self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) self._info_layout.setContentsMargins(0, 0, 0, 0) self._info_layout.setSpacing(0) self._info_layout.addWidget(self.img_label) self._info_layout.addSpacing(20) self._info_layout.addWidget(self.desc_container) self._layout.addSpacing(10) self._layout.addWidget(self.info_container) self._layout.addSpacing(10) self._layout.addWidget(self.table_control) def set_table(self, songs_table): if self.songs_table: self._layout.replaceWidget(self.songs_table, songs_table) self.songs_table.deleteLater() else: self._layout.addWidget(songs_table) self._layout.addSpacing(10) self.songs_table = songs_table def load_img(self, img_url, img_name): self.info_container.show() event_loop = asyncio.get_event_loop() future = event_loop.create_task( self._app.img_ctl.get(img_url, img_name)) future.add_done_callback(self.set_img) def set_img(self, future): content = future.result() img = QImage() img.loadFromData(content) pixmap = QPixmap(img) if pixmap.isNull(): return None self.img_label.setPixmap( pixmap.scaledToWidth(self.img_label.width(), mode=Qt.SmoothTransformation)) def set_desc(self, desc): self.desc_container.set_html(desc) def hide_info_container(self): self.info_container.hide()