提交 1874a838 编写于 作者: 之一Yo's avatar 之一Yo

添加更多 gallery 界面

上级 e431d69b
......@@ -9,6 +9,7 @@ class Icon(FluentIconBase, Enum):
HOME = "Home"
CHAT = "Chat"
MENU = "Menu"
SCROLL = "Scroll"
LAYOUT = "Layout"
GITHUB = "Github"
MESSAGE = "Message"
......
......@@ -11,4 +11,5 @@ class Translator(QObject):
self.dialogs = self.tr('Dialogs')
self.material = self.tr('Material')
self.statusInfo = self.tr('Status & info')
self.scroll = self.tr('Scrolling')
self.layout = self.tr('Layout')
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#000000" transform="translate(0, 250)" d="M640 218 l0 1254 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 l0 -1254 l-403 403 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 q0 -26 19 -45 l509 -509 q11 -11 22 -16.5 q11 -5.5 26 -5.5 q15 0 26 5.5 q11 5.5 22 16.5 l509 509 q19 19 19 45 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 l-403 -403 ZM2048 960 q0 26 -19 45 l-509 509 q-11 11 -21.5 16.5 q-10.5 5.5 -26.5 5.5 q-16 0 -26.5 -5.5 q-10.5 -5.5 -21.5 -16.5 l-509 -509 q-19 -19 -19 -45 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 l403 402 l0 -1253 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 q19 19 19 45 l0 1253 l403 -402 q19 -19 45 -19 q26 0 45 19 q19 19 19 45 Z"/></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<svg id="" width="16" height="16" style="width:16px;height:16px;" version="1.1"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048" enable-background="new 0 0 2048 2048"
xml:space="preserve"><path fill="#ffffff" transform="translate(0, 250)" d="M640 218 l0 1254 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 l0 -1254 l-403 403 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 q0 -26 19 -45 l509 -509 q11 -11 22 -16.5 q11 -5.5 26 -5.5 q15 0 26 5.5 q11 5.5 22 16.5 l509 509 q19 19 19 45 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 l-403 -403 ZM2048 960 q0 26 -19 45 l-509 509 q-11 11 -21.5 16.5 q-10.5 5.5 -26.5 5.5 q-16 0 -26.5 -5.5 q-10.5 -5.5 -21.5 -16.5 l-509 -509 q-19 -19 -19 -45 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 l403 402 l0 -1253 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 q19 19 19 45 l0 1253 l403 -402 q19 -19 45 -19 q26 0 45 19 q19 19 19 45 Z"/></svg>
\ No newline at end of file
......@@ -52,11 +52,15 @@ ExampleCard>#titleLabel {
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
margin-top: 132px;
margin-bottom: 0;
padding-right: 2px;
}
#imageViewer QScrollBar {
margin-top: 0px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
......
......@@ -49,11 +49,16 @@ ExampleCard > #titleLabel {
QScrollBar {
background: transparent;
width: 4px;
margin-top: 32px;
margin-top: 132px;
margin-bottom: 0;
padding-right: 2px;
}
#imageViewer QScrollBar {
margin-top: 0px;
}
/*隐藏上箭头*/
QScrollBar::sub-line {
background: transparent;
......
......@@ -3,7 +3,7 @@ from PyQt5.QtCore import Qt, QSize
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QButtonGroup
from PyQt5.QtMultimedia import QSound
from qfluentwidgets import (PushButton, ToolButton, PrimaryPushButton, HyperlinkButton,
ComboBox, RadioButton, CheckBox, Slider)
ComboBox, RadioButton, CheckBox, Slider, SwitchButton, IndicatorPosition)
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
......@@ -103,3 +103,11 @@ class BasicInputInterface(GalleryInterface):
slider,
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/slider/demo.py'
)
self.addExampleCard(
self.tr('A simple switch button'),
SwitchButton(self.tr('Off'), self),
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/switch_button/demo.py'
)
# coding:utf-8
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import Qt
from qfluentwidgets import PushButton, Dialog, MessageBox, ColorDialog
from ..common.translator import Translator
......
......@@ -67,9 +67,11 @@ class ToolBar(QWidget):
class ExampleCard(QWidget):
""" Example card """
def __init__(self, title, widget: QWidget, sourcePath, parent=None):
def __init__(self, title, widget: QWidget, sourcePath, stretch=0, parent=None):
super().__init__(parent=parent)
self.widget = widget
self.stretch = stretch
self.titleLabel = QLabel(title, self)
self.card = QFrame(self)
......@@ -119,7 +121,9 @@ class ExampleCard(QWidget):
self.widget.setParent(self.card)
self.topLayout.addWidget(self.widget)
self.topLayout.addStretch(1)
if self.stretch == 0:
self.topLayout.addStretch(1)
self.widget.show()
self.bottomLayout.addWidget(self.sourcePathLabel, 0, Qt.AlignLeft)
......@@ -139,6 +143,18 @@ class GalleryInterface(ScrollArea):
""" Gallery interface """
def __init__(self, title: str, subtitle: str, parent=None):
"""
Parameters
----------
title: str
The title of gallery
subtitle: str
The subtitle of gallery
parent: QWidget
parent widget
"""
super().__init__(parent=parent)
self.view = QWidget(self)
self.toolBar = ToolBar(title, subtitle, self)
......@@ -156,9 +172,10 @@ class GalleryInterface(ScrollArea):
self.__setQss()
cfg.themeChanged.connect(self.__setQss)
def addExampleCard(self, title, widget, sourcePath: str):
card = ExampleCard(title, widget, sourcePath, self.view)
def addExampleCard(self, title, widget, sourcePath: str, stretch=0):
card = ExampleCard(title, widget, sourcePath, stretch, self.view)
self.vBoxLayout.addWidget(card, 0, Qt.AlignTop)
return card
def resizeEvent(self, e):
super().resizeEvent(e)
......
# coding:utf-8
from PyQt5.QtWidgets import QWidget
from qfluentwidgets import FlowLayout, PushButton
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
class LayoutInterface(GalleryInterface):
""" Layout interface """
def __init__(self, parent=None):
t = Translator()
super().__init__(
title=t.layout,
subtitle="qfluentwidgets.components.layout",
parent=parent
)
self.addExampleCard(
self.tr('Flow layout without animation'),
self.createWidget(),
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/flow_layout/demo.py',
stretch=1
)
self.addExampleCard(
self.tr('Flow layout with animation'),
self.createWidget(True),
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/flow_layout/demo.py',
stretch=1
)
def createWidget(self, animation=False):
texts = [
self.tr('Star Platinum'), self.tr('Hierophant Green'),
self.tr('Silver Chariot'), self.tr('Crazy diamond'),
self.tr("Heaven's Door"), self.tr('Killer Queen'),
self.tr("Gold Experience"), self.tr('Sticky Fingers'),
self.tr("Sex Pistols"), self.tr('Dirty Deeds Done Dirt Cheap'),
]
widget = QWidget()
layout = FlowLayout(widget, animation)
layout.setContentsMargins(0, 0, 0, 0)
layout.setVerticalSpacing(20)
layout.setHorizontalSpacing(10)
for text in texts:
layout.addWidget(PushButton(text))
return widget
......@@ -9,9 +9,14 @@ from qfluentwidgets import FluentIcon as FIF
from qframelesswindow import FramelessWindow
from .title_bar import CustomTitleBar
from .setting_interface import SettingInterface, cfg
from .basic_input_interface import BasicInputInterface
from .dialog_interface import DialogInterface
from .layout_interface import LayoutInterface
from .material_interface import MaterialInterface
from .menu_interface import MenuInterface
from .scroll_interface import ScrollInterface
from .status_info_interface import StatusInfoInterface
from .setting_interface import SettingInterface, cfg
from ..components.avatar_widget import AvatarWidget
from ..common.icon import Icon
......@@ -57,10 +62,20 @@ class MainWindow(FramelessWindow):
# create sub interface
self.basicInputInterface = BasicInputInterface(self)
self.dialogInterface = DialogInterface(self)
self.layoutInterface = LayoutInterface(self)
self.menuInterface = MenuInterface(self)
self.materialInterface = MaterialInterface(self)
self.scrollInterface= ScrollInterface(self)
self.statusInfoInterface = StatusInfoInterface(self)
self.settingInterface = SettingInterface(self)
self.stackWidget.addWidget(self.basicInputInterface)
self.stackWidget.addWidget(self.dialogInterface)
self.stackWidget.addWidget(self.layoutInterface)
self.stackWidget.addWidget(self.menuInterface)
self.stackWidget.addWidget(self.materialInterface)
self.stackWidget.addWidget(self.scrollInterface)
self.stackWidget.addWidget(self.statusInfoInterface)
self.stackWidget.addWidget(self.settingInterface)
# initialize layout
......@@ -88,6 +103,11 @@ class MainWindow(FramelessWindow):
def initNavigation(self):
self.basicInputInterface.setObjectName('basicInterface')
self.dialogInterface.setObjectName('dialogInterface')
self.layoutInterface.setObjectName('layoutInterface')
self.menuInterface.setObjectName('menuInterface')
self.materialInterface.setObjectName('materialInterface')
self.statusInfoInterface.setObjectName('statusInfoInterface')
self.scrollInterface.setObjectName('scrollInterface')
self.settingInterface.setObjectName('settingsInterface')
self.navigationInterface.addItem(
......@@ -113,31 +133,38 @@ class MainWindow(FramelessWindow):
position=NavigationItemPostion.SCROLL
)
self.navigationInterface.addItem(
routeKey='Status&info',
routeKey=self.layoutInterface.objectName(),
icon=Icon.LAYOUT,
text=self.tr('Layout'),
onClick=print,
onClick=lambda: self.switchTo(self.layoutInterface),
position=NavigationItemPostion.SCROLL
)
self.navigationInterface.addItem(
routeKey='Menus',
routeKey=self.menuInterface.objectName(),
icon=Icon.MENU,
text=self.tr('Menus'),
onClick=print,
onClick=lambda: self.switchTo(self.menuInterface),
position=NavigationItemPostion.SCROLL
)
self.navigationInterface.addItem(
routeKey='Material',
routeKey=self.materialInterface.objectName(),
icon=FIF.PALETTE,
text=self.tr('Material'),
onClick=print,
onClick=lambda: self.switchTo(self.materialInterface),
position=NavigationItemPostion.SCROLL
)
self.navigationInterface.addItem(
routeKey=self.scrollInterface.objectName(),
icon=Icon.SCROLL,
text=self.tr('Scrolling'),
onClick=lambda: self.switchTo(self.scrollInterface),
position=NavigationItemPostion.SCROLL
)
self.navigationInterface.addItem(
routeKey='Layout',
routeKey=self.statusInfoInterface.objectName(),
icon=Icon.CHAT,
text=self.tr('Status & info'),
onClick=print,
onClick=lambda: self.switchTo(self.statusInfoInterface),
position=NavigationItemPostion.SCROLL
)
......@@ -163,11 +190,13 @@ class MainWindow(FramelessWindow):
self.stackWidget.currentWidgetChanged.connect(
lambda w: self.navigationInterface.setCurrentItem(w.objectName()))
self.navigationInterface.setCurrentItem(self.basicInputInterface.objectName())
self.navigationInterface.setCurrentItem(
self.basicInputInterface.objectName())
self.stackWidget.setCurrentIndex(0)
def initWindow(self):
self.resize(900, 700)
self.resize(1000, 780)
self.setMinimumWidth(580)
self.setWindowIcon(QIcon('app/resource/images/logo.png'))
self.setWindowTitle('PyQt-Fluent-Widgets')
self.titleBar.setAttribute(Qt.WA_StyledBackground)
......
# coding:utf-8
from PyQt5.QtGui import QColor
from qfluentwidgets.components.widgets.label import AcrylicLabel
from qfluentwidgets import FluentIcon as FIF
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
class MaterialInterface(GalleryInterface):
""" Material interface """
def __init__(self, parent=None):
t = Translator()
super().__init__(
title=t.menus,
subtitle='qfluentwidgets.components.widgets',
parent=parent
)
label = AcrylicLabel(15, QColor(105, 114, 168, 102))
label.setImage('app/resource/images/chidanta.jpg')
label.setMaximumSize(787, 579)
label.setMinimumSize(197, 145)
self.addExampleCard(
self.tr('Acrylic label'),
label,
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/acrylic_label/demo.py',
stretch=1
)
# coding:utf-8
from PyQt5.QtCore import QPoint
from PyQt5.QtWidgets import QAction
from qfluentwidgets import RoundMenu, PushButton
from qfluentwidgets import FluentIcon as FIF
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
class MenuInterface(GalleryInterface):
""" Menu interface """
def __init__(self, parent=None):
t = Translator()
super().__init__(
title=t.menus,
subtitle='qfluentwidgets.components.widgets',
parent=parent
)
button = PushButton('Show menu')
button.clicked.connect(lambda: self.createMenu(
button.mapToGlobal(QPoint()) + QPoint(button.width()+5, -100)))
self.addExampleCard(
self.tr('Rounded corners menu'),
button,
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/menu/demo.py'
)
def createMenu(self, pos):
menu = RoundMenu(parent=self)
# add actions
menu.addAction(QAction(FIF.COPY.icon(), 'Copy'))
menu.addAction(QAction(FIF.CUT.icon(), 'Cut'))
# add sub menu
submenu = RoundMenu("Add to", self)
submenu.setIcon(FIF.ADD.icon())
submenu.addActions([
QAction(FIF.VIDEO.icon(), 'Video'),
QAction(FIF.MUSIC.icon(), 'Music'),
])
menu.addMenu(submenu)
# add actions
menu.addActions([
QAction(FIF.PASTE.icon(), 'Paste'),
QAction(FIF.CANCEL.icon(), 'Undo')
])
# add separator
menu.addSeparator()
menu.addAction(QAction(f'Select all'))
# insert actions
menu.insertAction(
menu.menuActions()[-1], QAction(FIF.SETTING.icon(), 'Settings'))
menu.insertActions(
menu.menuActions()[-1],
[QAction(FIF.HELP.icon(), 'Help'), QAction(
FIF.FEEDBACK.icon(), 'Feedback')]
)
# show menu
menu.exec(pos, ani=True)
# coding:utf-8
from PyQt5.QtCore import Qt, QEasingCurve
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QLabel
from qfluentwidgets import ScrollArea, SmoothScrollArea
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
class ScrollInterface(GalleryInterface):
""" Scroll interface """
def __init__(self, parent=None):
t = Translator()
super().__init__(
title=t.scroll,
subtitle="qfluentwidgets.components.widgets",
parent=parent
)
w = ScrollArea()
label = QLabel(self)
label.setPixmap(QPixmap("app/resource/images/chidanta2.jpg").scaled(
775, 1229, Qt.KeepAspectRatio, Qt.SmoothTransformation
))
w.horizontalScrollBar().setValue(0)
w.setWidget(label)
w.setFixedHeight(400)
w.setObjectName('imageViewer')
self.addExampleCard(
self.tr('Smooth scroll area'),
w,
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/scroll_area/demo.py',
)
# coding:utf-8
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QLabel
from qfluentwidgets import StateToolTip, ToolTipFilter, PushButton
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
class StatusInfoInterface(GalleryInterface):
""" Status info interface """
def __init__(self, parent=None):
t = Translator()
super().__init__(
title=t.statusInfo,
subtitle="qfluentwidgets.components.widgets",
parent=parent
)
self.stateTooltip = None
button = PushButton('Show StateToolTip')
button.clicked.connect(self.onStateButtonClicked)
self.addExampleCard(
self.tr('State tool tip'),
button,
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/status_tool_tip/demo.py'
)
button = PushButton('Button with a simple ToolTip')
button.installEventFilter(ToolTipFilter(button))
button.setToolTip('Simple ToolTip')
self.addExampleCard(
self.tr('State tool tip'),
button,
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/tool_tip/demo.py'
)
label = QLabel()
label.setPixmap(QPixmap('app/resource/images/kunkun.png').scaled(
200, 200, Qt.KeepAspectRatio, Qt.SmoothTransformation))
label.installEventFilter(ToolTipFilter(label, showDelay=500))
label.setToolTip(self.tr('Label with a ToolTip'))
label.setToolTipDuration(2000)
label.setFixedSize(200, 200)
self.addExampleCard(
self.tr('A label with a ToolTip'),
label,
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/tool_tip/demo.py'
)
def onStateButtonClicked(self):
if self.stateTooltip:
self.stateTooltip.setContent('The model training is complete! 😆')
self.stateTooltip.setState(True)
self.stateTooltip = None
else:
self.stateTooltip = StateToolTip(
'Training model', 'Please wait patiently', self.window())
self.sender().setText(self.tr('Hide state tool tip'))
self.stateTooltip.move(self.stateTooltip.getSuitablePos())
self.stateTooltip.show()
......@@ -36,6 +36,9 @@ class NavigationPanel(QFrame):
def __init__(self, parent=None, isMinimalEnabled=False):
super().__init__(parent=parent)
self._parent = parent # type: QWidget
self._isMenuButtonVisible = True
self._isReturnButtonVisible = False
self.scrollArea = ScrollArea(self)
self.scrollWidget = QWidget()
......@@ -192,10 +195,12 @@ class NavigationPanel(QFrame):
def setMenuButtonVisible(self, isVisible: bool):
""" set whether the menu button is visible """
self._isMenuButtonVisible = isVisible
self.menuButton.setVisible(isVisible)
def setReturnButtonVisible(self, isVisible: bool):
""" set whether the menu button is visible """
self._isReturnButtonVisible = isVisible
self.returnButton.setVisible(isVisible)
def setExpandWidth(self, width: int):
......@@ -298,7 +303,7 @@ class NavigationPanel(QFrame):
if w < 1008 and self.displayMode == NavigationDisplayMode.EXPAND:
self.collapse()
elif w >= 1008 and self.displayMode == NavigationDisplayMode.COMPACT and \
not self.menuButton.isVisible():
not self._isMenuButtonVisible:
self.expand()
return super().eventFilter(obj, e)
......
......@@ -10,6 +10,8 @@ try:
except ImportError as e:
warnings.warn('`AcrylicLabel` is not supported in current qfluentwidgets, use `pip install PyQt-Fluent-Widgets[full]` to enable it.')
def gaussianBlur(imagePath, blurRadius=18, brightFactor=1, blurPicSize=None):
return QPixmap(imagePath)
class BlurCoverThread(QThread):
......@@ -21,7 +23,7 @@ class BlurCoverThread(QThread):
super().__init__(parent)
self.imagePath = ""
self.blurRadius = 7
self.maxSize = (450, 450)
self.maxSize = None
def run(self):
if not self.imagePath:
......@@ -141,6 +143,6 @@ class AcrylicLabel(QLabel):
super().resizeEvent(e)
self.acrylicTextureLabel.resize(self.size())
if not self.blurPixmap.isNull():
if not self.blurPixmap.isNull() and self.blurPixmap.size() != self.size():
self.setPixmap(self.blurPixmap.scaled(
self.size(), Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation))
......@@ -129,6 +129,19 @@ class StateToolTip(QWidget):
self.rotateAngle = (self.rotateAngle + self.deltaAngle) % 360
self.update()
def getSuitablePos(self):
""" get suitable position in main window """
for i in range(10):
dy = i*(self.height() + 16)
pos = QPoint(self.window().width() - self.width() - 24, 50+dy)
widget = self.window().childAt(pos + QPoint(2, 2))
if isinstance(widget, (StateToolTip, ToastToolTip)):
pos += QPoint(0, self.height() + 16)
else:
break
return pos
def paintEvent(self, e):
""" paint state tooltip """
super().paintEvent(e)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册