提交 34219ea1 编写于 作者: 之一Yo's avatar 之一Yo

菜单添加显示快捷键的功能

上级 3f0301d4
......@@ -42,7 +42,7 @@ class Demo1(QWidget):
# add hidden actions
self.commandBar.addHiddenAction(Action(FluentIcon.SCROLL, 'Sort', triggered=lambda: print('排序')))
self.commandBar.addHiddenAction(Action(FluentIcon.SETTING, 'Settings'))
self.commandBar.addHiddenAction(Action(FluentIcon.SETTING, 'Settings', shortcut='Ctrl+S'))
self.resize(240, 40)
self.setWindowTitle('Drag window')
......@@ -86,7 +86,7 @@ class Demo2(FramelessWindow):
self.vBoxLayout.setContentsMargins(0, 80, 0, 0)
self.setStyleSheet('Demo2{background: white}')
self.setWindowTitle('Click image 🥵')
self.setWindowTitle('Click Image 👇️🥵')
self.setWindowIcon(QIcon(":/qfluentwidgets/images/logo.png"))
def showCommandBar(self):
......@@ -96,7 +96,8 @@ class Demo2(FramelessWindow):
view.addAction(Action(FluentIcon.SAVE, 'Save'))
view.addAction(Action(FluentIcon.DELETE, 'Delete'))
view.addHiddenAction(Action(FluentIcon.SETTING, 'Settings'))
view.addHiddenAction(Action(FluentIcon.APPLICATION, 'App', shortcut='Ctrl+A'))
view.addHiddenAction(Action(FluentIcon.SETTING, 'Settings', shortcut='Ctrl+S'))
view.resizeToSuitableWidth()
Flyout.make(view, self.imageLabel, self, FlyoutAnimationType.FADE_IN)
......
......@@ -8,7 +8,7 @@ class Translator(QObject):
super().__init__(parent=parent)
self.text = self.tr('Text')
self.view = self.tr('View')
self.menus = self.tr('Menus')
self.menus = self.tr('Menus & toolbars')
self.icons = self.tr('Icons')
self.layout = self.tr('Layout')
self.dialogs = self.tr('Dialogs & flyouts')
......
......@@ -696,70 +696,175 @@ In that case, I would accept it no matter which side the ball falls on.</source>
<context>
<name>MenuInterface</name>
<message>
<location filename="../../view/menu_interface.py" line="27"/>
<location filename="../../view/menu_interface.py" line="29"/>
<source>Rounded corners menu</source>
<translation>圆角菜单</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="23"/>
<location filename="../../view/menu_interface.py" line="25"/>
<source>Show menu</source>
<translation>显示菜单</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="37"/>
<location filename="../../view/menu_interface.py" line="69"/>
<source>Copy</source>
<translation>复制</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="38"/>
<location filename="../../view/menu_interface.py" line="70"/>
<source>Cut</source>
<translation>剪切</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="43"/>
<location filename="../../view/menu_interface.py" line="75"/>
<source>Video</source>
<translation>视频</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="43"/>
<location filename="../../view/menu_interface.py" line="75"/>
<source>Music</source>
<translation>音乐</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="50"/>
<location filename="../../view/menu_interface.py" line="82"/>
<source>Paste</source>
<translation>粘贴</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="50"/>
<location filename="../../view/menu_interface.py" line="82"/>
<source>Undo</source>
<translation>撤回</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="57"/>
<location filename="../../view/menu_interface.py" line="89"/>
<source>Select all</source>
<translation>全选</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="60"/>
<location filename="../../view/menu_interface.py" line="154"/>
<source>Settings</source>
<translation>设置</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="62"/>
<location filename="../../view/menu_interface.py" line="94"/>
<source>Help</source>
<translation>帮助</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="62"/>
<location filename="../../view/menu_interface.py" line="94"/>
<source>Feedback</source>
<translation>反馈</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="41"/>
<location filename="../../view/menu_interface.py" line="73"/>
<source>Add to</source>
<translation>添加到</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="36"/>
<source>Command bar</source>
<translation>命令栏</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="49"/>
<source>Click the image to open a command bar flyout 👇️🥵</source>
<translation>点击图片来弹出命令栏 👇️🥵</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="58"/>
<source>Command bar flyout</source>
<translation>浮出命令栏</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="107"/>
<source>Add</source>
<translation>添加</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="107"/>
<source>Rotate</source>
<translation>旋转</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="107"/>
<source>Zoom in</source>
<translation>放大</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="107"/>
<source>Zoom out</source>
<translation>缩小</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="114"/>
<source>Edit</source>
<translation>编辑</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="114"/>
<source>Info</source>
<translation>信息</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="151"/>
<source>Delete</source>
<translation>删除</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="148"/>
<source>Share</source>
<translation>分享</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="126"/>
<source>Create Date</source>
<translation>创建日期</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="126"/>
<source>Shooting Date</source>
<translation>拍摄日期</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="126"/>
<source>Name</source>
<translation>名称</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="132"/>
<source>Ascending</source>
<translation>升序</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="132"/>
<source>Descending</source>
<translation>降序</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="149"/>
<source>Save</source>
<translation>保存</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="150"/>
<source>Add to favorate</source>
<translation>添加到收藏夹</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="153"/>
<source>Print</source>
<translation>打印</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="162"/>
<source>Save image</source>
<translation>保存图像</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="121"/>
<source>Sort</source>
<translation>排序</translation>
</message>
</context>
<context>
<name>NavigationViewInterface</name>
......@@ -1340,11 +1445,6 @@ In that case, I would accept it no matter which side the ball falls on.</source>
<source>Basic input</source>
<translation>基本输入</translation>
</message>
<message>
<location filename="../../common/translator.py" line="11"/>
<source>Menus</source>
<translation>菜单</translation>
</message>
<message>
<location filename="../../common/translator.py" line="16"/>
<source>Material</source>
......@@ -1395,6 +1495,11 @@ In that case, I would accept it no matter which side the ball falls on.</source>
<source>Dialogs &amp; flyouts</source>
<translation>对话框和弹出窗口</translation>
</message>
<message>
<location filename="../../common/translator.py" line="11"/>
<source>Menus &amp; toolbars</source>
<translation>菜单和工具栏</translation>
</message>
</context>
<context>
<name>TreeFrame</name>
......
......@@ -696,70 +696,175 @@ In that case, I would accept it no matter which side the ball falls on.</source>
<context>
<name>MenuInterface</name>
<message>
<location filename="../../view/menu_interface.py" line="27"/>
<location filename="../../view/menu_interface.py" line="29"/>
<source>Rounded corners menu</source>
<translation>圓角菜單</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="23"/>
<location filename="../../view/menu_interface.py" line="25"/>
<source>Show menu</source>
<translation>顯示菜單</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="37"/>
<location filename="../../view/menu_interface.py" line="69"/>
<source>Copy</source>
<translation>複製</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="38"/>
<location filename="../../view/menu_interface.py" line="70"/>
<source>Cut</source>
<translation>剪切</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="43"/>
<location filename="../../view/menu_interface.py" line="75"/>
<source>Video</source>
<translation>視頻</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="43"/>
<location filename="../../view/menu_interface.py" line="75"/>
<source>Music</source>
<translation>音樂</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="50"/>
<location filename="../../view/menu_interface.py" line="82"/>
<source>Paste</source>
<translation>粘貼</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="50"/>
<location filename="../../view/menu_interface.py" line="82"/>
<source>Undo</source>
<translation>撤回</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="57"/>
<location filename="../../view/menu_interface.py" line="89"/>
<source>Select all</source>
<translation>全選</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="60"/>
<location filename="../../view/menu_interface.py" line="154"/>
<source>Settings</source>
<translation>設置</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="62"/>
<location filename="../../view/menu_interface.py" line="94"/>
<source>Help</source>
<translation>幫助</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="62"/>
<location filename="../../view/menu_interface.py" line="94"/>
<source>Feedback</source>
<translation>反饋</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="41"/>
<location filename="../../view/menu_interface.py" line="73"/>
<source>Add to</source>
<translation>添加到</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="36"/>
<source>Command bar</source>
<translation>命令欄</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="49"/>
<source>Click the image to open a command bar flyout 👇️🥵</source>
<translation>點擊圖片來彈出命令欄 👇️🥵</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="58"/>
<source>Command bar flyout</source>
<translation>浮出命令欄</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="107"/>
<source>Add</source>
<translation>添加</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="107"/>
<source>Rotate</source>
<translation>旋轉</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="107"/>
<source>Zoom in</source>
<translation>放大</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="107"/>
<source>Zoom out</source>
<translation>縮小</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="114"/>
<source>Edit</source>
<translation>編輯</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="114"/>
<source>Info</source>
<translation>信息</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="151"/>
<source>Delete</source>
<translation>刪除</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="148"/>
<source>Share</source>
<translation>分享</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="126"/>
<source>Create Date</source>
<translation>創建日期</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="126"/>
<source>Shooting Date</source>
<translation>拍攝日期</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="126"/>
<source>Name</source>
<translation>名稱</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="132"/>
<source>Ascending</source>
<translation>昇序</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="132"/>
<source>Descending</source>
<translation>降序</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="149"/>
<source>Save</source>
<translation>保存</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="150"/>
<source>Add to favorate</source>
<translation>添加到收藏夾</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="153"/>
<source>Print</source>
<translation>打印</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="162"/>
<source>Save image</source>
<translation>保存圖像</translation>
</message>
<message>
<location filename="../../view/menu_interface.py" line="121"/>
<source>Sort</source>
<translation>排序</translation>
</message>
</context>
<context>
<name>NavigationViewInterface</name>
......@@ -1340,11 +1445,6 @@ In that case, I would accept it no matter which side the ball falls on.</source>
<source>Basic input</source>
<translation>基本輸入</translation>
</message>
<message>
<location filename="../../common/translator.py" line="11"/>
<source>Menus</source>
<translation>菜單</translation>
</message>
<message>
<location filename="../../common/translator.py" line="16"/>
<source>Material</source>
......@@ -1395,6 +1495,11 @@ In that case, I would accept it no matter which side the ball falls on.</source>
<source>Dialogs &amp; flyouts</source>
<translation>對話框和彈出窗口</translation>
</message>
<message>
<location filename="../../common/translator.py" line="11"/>
<source>Menus &amp; toolbars</source>
<translation>菜單和工具欄</translation>
</message>
</context>
<context>
<name>TreeFrame</name>
......
......@@ -110,6 +110,7 @@
<file>images/chidanta2.jpg</file>
<file>images/chidanta3.jpg</file>
<file>images/chidanta4.jpg</file>
<file>images/chidanta5.jpg</file>
<file>images/header.png</file>
<file>images/header1.png</file>
<file>images/kunkun.png</file>
......
......@@ -292,7 +292,7 @@ class HomeInterface(ScrollArea):
self.vBoxLayout.addWidget(materialView)
# menu samples
menuView = SampleCardView(self.tr('Menu samples'), self.view)
menuView = SampleCardView(self.tr('Menu & toolbars samples'), self.view)
menuView.addSampleCard(
icon=":/gallery/images/controls/MenuFlyout.png",
title="RoundMenu",
......@@ -301,6 +301,22 @@ class HomeInterface(ScrollArea):
routeKey="menuInterface",
index=0
)
menuView.addSampleCard(
icon=":/gallery/images/controls/CommandBar.png",
title="CommandBar",
content=self.tr(
"Shows a contextual list of simple commands or options."),
routeKey="menuInterface",
index=1
)
menuView.addSampleCard(
icon=":/gallery/images/controls/CommandBar.png",
title="CommandBar",
content=self.tr(
"Shows a contextual list of simple commands or options."),
routeKey="menuInterface",
index=2
)
self.vBoxLayout.addWidget(menuView)
# navigation
......
......@@ -16,7 +16,7 @@ class LayoutInterface(GalleryInterface):
subtitle="qfluentwidgets.components.layout",
parent=parent
)
self.setObjectName('iconInterface')
self.setObjectName('layoutInterface')
self.addExampleCard(
self.tr('Flow layout without animation'),
......
# coding:utf-8
from PyQt5.QtCore import QPoint
from PyQt5.QtWidgets import QAction
from qfluentwidgets import RoundMenu, PushButton, Action
from PyQt5.QtCore import QPoint, Qt, QStandardPaths
from PyQt5.QtWidgets import QAction, QWidget, QLabel, QVBoxLayout, QFileDialog
from qfluentwidgets import (RoundMenu, PushButton, Action, CommandBar, Action, TransparentDropDownPushButton,
setFont, CommandBarView, Flyout, ImageLabel, FlyoutAnimationType)
from qfluentwidgets import FluentIcon as FIF
from .gallery_interface import GalleryInterface
......@@ -20,6 +21,7 @@ class MenuInterface(GalleryInterface):
)
self.setObjectName('menuInterface')
# context menu
button = PushButton(self.tr('Show menu'))
button.clicked.connect(lambda: self.createMenu(
button.mapToGlobal(QPoint()) + QPoint(button.width()+5, -100)))
......@@ -30,6 +32,36 @@ class MenuInterface(GalleryInterface):
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/menu/demo.py'
)
# command bar
self.addExampleCard(
self.tr('Command bar'),
self.createCommandBar(),
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/menu/demo.py',
stretch=1
)
# command bar flyout
widget = QWidget(self)
widget.setLayout(QVBoxLayout())
widget.layout().setContentsMargins(0, 0, 0, 0)
widget.layout().setSpacing(10)
label = QLabel(self.tr('Click the image to open a command bar flyout 👇️🥵'))
self.imageLabel = ImageLabel(':/gallery/images/chidanta5.jpg')
self.imageLabel.scaledToWidth(350)
self.imageLabel.setBorderRadius(8, 8, 8, 8)
self.imageLabel.clicked.connect(self.createCommandBarFlyout)
widget.layout().addWidget(label)
widget.layout().addWidget(self.imageLabel)
self.addExampleCard(
self.tr('Command bar flyout'),
widget,
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/menu/demo.py',
stretch=1
)
def createMenu(self, pos):
menu = RoundMenu(parent=self)
......@@ -68,3 +100,72 @@ class MenuInterface(GalleryInterface):
)
menu.exec(pos, ani=True)
def createCommandBar(self):
bar = CommandBar(self)
bar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
bar.addActions([
Action(FIF.ADD, self.tr('Add')),
Action(FIF.ROTATE, self.tr('Rotate')),
Action(FIF.ZOOM_IN, self.tr('Zoom in')),
Action(FIF.ZOOM_OUT, self.tr('Zoom out')),
])
bar.addSeparator()
bar.addActions([
Action(FIF.EDIT, self.tr('Edit'), checkable=True),
Action(FIF.INFO, self.tr('Info')),
Action(FIF.DELETE, self.tr('Delete')),
Action(FIF.SHARE, self.tr('Share'))
])
button = TransparentDropDownPushButton(self.tr('Sort'), self, FIF.SCROLL)
button.setFixedHeight(34)
setFont(button, 12)
menu = RoundMenu(parent=self)
menu.addActions([
Action(FIF.CALENDAR, self.tr('Create Date')),
Action(FIF.CAMERA, self.tr('Shooting Date')),
Action(FIF.FONT, self.tr('Name')),
])
menu.addSeparator()
menu.addActions([
Action(FIF.UP, self.tr('Ascending')),
Action(FIF.DOWN, self.tr('Descending')),
])
button.setMenu(menu)
bar.addWidget(button)
bar.addHiddenActions([
Action(FIF.SETTING, self.tr('Settings'), shortcut='Ctrl+I'),
])
return bar
def createCommandBarFlyout(self):
view = CommandBarView(self)
view.addAction(Action(FIF.SHARE, self.tr('Share')))
view.addAction(Action(FIF.SAVE, self.tr('Save'), triggered=self.saveImage))
view.addAction(Action(FIF.HEART, self.tr('Add to favorate')))
view.addAction(Action(FIF.DELETE, self.tr('Delete')))
view.addHiddenAction(Action(FIF.PRINT, self.tr('Print'), shortcut='Ctrl+P'))
view.addHiddenAction(Action(FIF.SETTING, self.tr('Settings'), shortcut='Ctrl+S'))
view.resizeToSuitableWidth()
x = self.imageLabel.width()
pos = self.imageLabel.mapToGlobal(QPoint(x, 0))
Flyout.make(view, pos, self, FlyoutAnimationType.FADE_IN)
def saveImage(self):
path, ok = QFileDialog.getSaveFileName(
parent=self,
caption=self.tr('Save image'),
directory=QStandardPaths.writableLocation(QStandardPaths.DesktopLocation),
filter='PNG (*.png)'
)
if not ok:
return
self.imageLabel.image.save(path)
\ No newline at end of file
......@@ -44,14 +44,15 @@ class Demo(QWidget):
# add separator
menu.addSeparator()
menu.addAction(QAction(f'Select all'))
menu.addAction(QAction(f'Select all', shortcut='Ctrl+A'))
# insert actions
menu.insertAction(
menu.menuActions()[-1], Action(FIF.SETTING, 'Settings'))
menu.menuActions()[-1], Action(FIF.SETTING, 'Settings', shortcut='Ctrl+S'))
menu.insertActions(
menu.menuActions()[-1],
[Action(FIF.HELP, 'Help'), Action(FIF.FEEDBACK, 'Feedback')]
[Action(FIF.HELP, 'Help', shortcut='Ctrl+H'),
Action(FIF.FEEDBACK, 'Feedback', shortcut='Ctrl+F')]
)
# show menu
......
<?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" d="M1984 1088 q0 26 -19 45 l-893 893 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-893 -893 q-19 -19 -19 -45 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 l787 786 l0 -1765 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 q19 19 19 45 l0 1765 l787 -786 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" d="M1984 1088 q0 26 -19 45 l-893 893 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-893 -893 q-19 -19 -19 -45 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 l787 786 l0 -1765 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 q19 19 19 45 l0 1765 l787 -786 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="#000000" transform="translate(0, 50)" d="M0 192 q0 -40 15 -75 q15 -35 41 -61 q26 -26 61 -41 q35 -15 75 -15 l1664 0 q40 0 75 15 q35 15 61 41 q26 26 41 61 q15 35 15 75 q0 82 -60 139 l-648 618 q-14 14 -25 30 q-11 16 -19 33 q-16 35 -16 76 l0 768 q0 26 -19 45 q-19 19 -45 19 q-19 0 -35 -11 l-384 -256 q-29 -19 -29 -53 l0 -512 q0 -40 -15 -76 q-8 -18 -19.5 -33.5 q-11.5 -15.5 -25.5 -29.5 l-648 -618 q-60 -57 -60 -139 ZM1920 191 q0 -26 -19 -44.5 q-19 -18.5 -45 -18.5 l-1664 0 q-26 0 -45 18.5 q-19 18.5 -19 44.5 q0 29 20 47 l649 618 q47 45 73 106 q26 61 26 126 l0 478 l256 170 l0 -648 q0 -65 26 -126 q26 -61 73 -106 l649 -618 q20 -18 20 -47 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, 50)" d="M0 192 q0 -40 15 -75 q15 -35 41 -61 q26 -26 61 -41 q35 -15 75 -15 l1664 0 q40 0 75 15 q35 15 61 41 q26 26 41 61 q15 35 15 75 q0 82 -60 139 l-648 618 q-14 14 -25 30 q-11 16 -19 33 q-16 35 -16 76 l0 768 q0 26 -19 45 q-19 19 -45 19 q-19 0 -35 -11 l-384 -256 q-29 -19 -29 -53 l0 -512 q0 -40 -15 -76 q-8 -18 -19.5 -33.5 q-11.5 -15.5 -25.5 -29.5 l-648 -618 q-60 -57 -60 -139 ZM1920 191 q0 -26 -19 -44.5 q-19 -18.5 -45 -18.5 l-1664 0 q-26 0 -45 18.5 q-19 18.5 -19 44.5 q0 29 20 47 l649 618 q47 45 73 106 q26 61 26 126 l0 478 l256 170 l0 -648 q0 -65 26 -126 q26 -61 73 -106 l649 -618 q20 -18 20 -47 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="#000000" d="M1344 2048 q-26 0 -45 -19 q-19 -19 -19 -45 l0 -512 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 q19 19 19 45 l0 357 q128 -54 224 -135 q96 -81 160 -184.5 q64 -103.5 96 -226 q32 -122.5 32 -259.5 q0 -195 -67 -359 q-67 -164 -186.5 -283.5 q-119.5 -119.5 -283.5 -186.5 q-164 -67 -359 -67 q-123 0 -238 28 q-115 28 -215.5 83 q-100.5 55 -184 137 q-83.5 82 -144.5 191 q-60 106 -87 221 q-27 115 -27 236 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 q0 -147 35 -280.5 q35 -133.5 99.5 -247 q64.5 -113.5 156.5 -205.5 q92 -92 205.5 -156.5 q113.5 -64.5 247 -99.5 q133.5 -35 280.5 -35 q147 0 280.5 35 q133.5 35 247 99.5 q113.5 64.5 205.5 156.5 q92 92 156.5 205.5 q64.5 113.5 99.5 247 q35 133.5 35 280.5 q0 145 -33 278.5 q-33 133.5 -99.5 249 q-66.5 115.5 -166 209.5 q-99.5 94 -232.5 159 l339 0 q26 0 45 19 q19 19 19 45 q0 26 -19 45 q-19 19 -45 19 l-512 0 ZM768 1019 q0 -52 21 -97.5 q21 -45.5 56 -79.5 q35 -34 81.5 -54 q46.5 -20 97.5 -20 q52 0 99 20.5 q47 20.5 81.5 55 q34.5 34.5 55 81.5 q20.5 47 20.5 99 q0 53 -20.5 99.5 q-20.5 46.5 -55 81 q-34.5 34.5 -81.5 55 q-47 20.5 -99 20.5 q-54 0 -101 -20.5 q-47 -20.5 -81.5 -56 q-34.5 -35.5 -54 -83 q-19.5 -47.5 -19.5 -101.5 ZM1152 1024 q0 -26 -10 -49.5 q-10 -23.5 -27.5 -41 q-17.5 -17.5 -41 -27.5 q-23.5 -10 -49.5 -10 q-27 0 -50 10 q-23 10 -40.5 27.5 q-17.5 17.5 -27.5 40.5 q-10 23 -10 50 q0 27 10 50.5 q10 23.5 27 40.5 q17 17 40.5 27 q23.5 10 50.5 10 q27 0 50 -10 q23 -10 40.5 -27.5 q17.5 -17.5 27.5 -40.5 q10 -23 10 -50 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" d="M1344 2048 q-26 0 -45 -19 q-19 -19 -19 -45 l0 -512 q0 -26 19 -45 q19 -19 45 -19 q26 0 45 19 q19 19 19 45 l0 357 q128 -54 224 -135 q96 -81 160 -184.5 q64 -103.5 96 -226 q32 -122.5 32 -259.5 q0 -195 -67 -359 q-67 -164 -186.5 -283.5 q-119.5 -119.5 -283.5 -186.5 q-164 -67 -359 -67 q-123 0 -238 28 q-115 28 -215.5 83 q-100.5 55 -184 137 q-83.5 82 -144.5 191 q-60 106 -87 221 q-27 115 -27 236 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 q0 -147 35 -280.5 q35 -133.5 99.5 -247 q64.5 -113.5 156.5 -205.5 q92 -92 205.5 -156.5 q113.5 -64.5 247 -99.5 q133.5 -35 280.5 -35 q147 0 280.5 35 q133.5 35 247 99.5 q113.5 64.5 205.5 156.5 q92 92 156.5 205.5 q64.5 113.5 99.5 247 q35 133.5 35 280.5 q0 145 -33 278.5 q-33 133.5 -99.5 249 q-66.5 115.5 -166 209.5 q-99.5 94 -232.5 159 l339 0 q26 0 45 19 q19 19 19 45 q0 26 -19 45 q-19 19 -45 19 l-512 0 ZM768 1019 q0 -52 21 -97.5 q21 -45.5 56 -79.5 q35 -34 81.5 -54 q46.5 -20 97.5 -20 q52 0 99 20.5 q47 20.5 81.5 55 q34.5 34.5 55 81.5 q20.5 47 20.5 99 q0 53 -20.5 99.5 q-20.5 46.5 -55 81 q-34.5 34.5 -81.5 55 q-47 20.5 -99 20.5 q-54 0 -101 -20.5 q-47 -20.5 -81.5 -56 q-34.5 -35.5 -54 -83 q-19.5 -47.5 -19.5 -101.5 ZM1152 1024 q0 -26 -10 -49.5 q-10 -23.5 -27.5 -41 q-17.5 -17.5 -41 -27.5 q-23.5 -10 -49.5 -10 q-27 0 -50 10 q-23 10 -40.5 27.5 q-17.5 17.5 -27.5 40.5 q-10 23 -10 50 q0 27 10 50.5 q10 23.5 27 40.5 q17 17 40.5 27 q23.5 10 50.5 10 q27 0 50 -10 q23 -10 40.5 -27.5 q17.5 -17.5 27.5 -40.5 q10 -23 10 -50 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="#000000" d="M1984 960 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 l-787 -786 l0 1765 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 l0 -1765 l-787 786 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 q0 -26 19 -45 l893 -893 q11 -11 21.5 -16.5 q10.5 -5.5 26.5 -5.5 q16 0 26.5 5.5 q10.5 5.5 21.5 16.5 l893 893 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" d="M1984 960 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 l-787 -786 l0 1765 q0 26 -19 45 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 l0 -1765 l-787 786 q-19 19 -45 19 q-26 0 -45 -19 q-19 -19 -19 -45 q0 -26 19 -45 l893 -893 q11 -11 21.5 -16.5 q10.5 -5.5 26.5 -5.5 q16 0 26.5 5.5 q10.5 5.5 21.5 16.5 l893 893 q19 19 19 45 Z"/></svg>
\ No newline at end of file
......@@ -73,6 +73,10 @@ MenuActionListWidget::item:selected:active {
color: rgba(0, 0, 0, 0.7);
}
#commandListWidget{
border-color: rgb(233, 233, 233);
}
#completerListWidget[dropDown=true],
#commandListWidget[dropDown=true][long=false] {
border-top-left-radius: 0px;
......
此差异已折叠。
......@@ -186,6 +186,14 @@
<file>images/icons/HomeFill_white.svg</file>
<file>images/icons/LibraryFill_black.svg</file>
<file>images/icons/LibraryFill_white.svg</file>
<file>images/icons/Down_black.svg</file>
<file>images/icons/Down_white.svg</file>
<file>images/icons/Up_black.svg</file>
<file>images/icons/Up_white.svg</file>
<file>images/icons/Rotate_white.svg</file>
<file>images/icons/Rotate_black.svg</file>
<file>images/icons/Filter_white.svg</file>
<file>images/icons/Filter_black.svg</file>
<file>images/acrylic/noise.png</file>
<file>images/folder_list_dialog/Close_white.png</file>
......
import contextlib
import functools
import inspect
import itertools
import re
import sys
import warnings
class FluentDeprecationWarning(UserWarning):
"""
A class for issuing deprecation warnings for PyQt-Fluent-Widgets users.
In light of the fact that Python builtin DeprecationWarnings are ignored
by default as of Python 2.7 (see link below), this class was put in to
allow for the signaling of deprecation, but via UserWarnings which are not
ignored by default.
https://docs.python.org/dev/whatsnew/2.7.html#the-future-for-python-2-x
"""
def _generate_deprecation_warning(
since, message='', name='', alternative='', pending=False, obj_type='',
addendum='', removal=''):
if pending:
if removal:
raise ValueError(
"A pending deprecation cannot have a scheduled removal")
else:
if removal:
removal = "in {}".format(removal)
else:
removal = {"2.2": "in 3.1", "3.0": "in 3.2", "3.1": "in 3.3"}.get(
since, "two minor releases later")
if not message:
message = (
"\nThe `%(name)s` %(obj_type)s"
+ (" will be deprecated in a future version"
if pending else
(" was deprecated in PyQt-Fluent-Widgets %(since)s"
+ (" and will be removed %(removal)s"
if removal else
"")))
+ "."
+ (" Use `%(alternative)s` instead." if alternative else "")
+ (" %(addendum)s" if addendum else ""))
warning_cls = (PendingDeprecationWarning if pending
else FluentDeprecationWarning)
return warning_cls(message % dict(
func=name, name=name, obj_type=obj_type, since=since, removal=removal,
alternative=alternative, addendum=addendum))
def _warn_external(message, category=None):
"""
`warnings.warn` wrapper that sets *stacklevel* to "outside PyQt-Fluent-Widgets".
The original emitter of the warning can be obtained by patching this
function back to `warnings.warn`, i.e. ``_warn_external =
warnings.warn`` (or ``functools.partial(warnings.warn, stacklevel=2)``,
etc.).
"""
frame = sys._getframe()
for stacklevel in itertools.count(1): # lgtm[py/unused-loop-variable]
if frame is None:
# when called in embedded context may hit frame is None
break
if not re.match(r"\A(qfluentwidgets)(\Z|\.(?!tests\.))",
# Work around sphinx-gallery not setting __name__.
frame.f_globals.get("__name__", "")):
break
frame = frame.f_back
warnings.warn(message, category, stacklevel)
def warn_deprecated(since, message='', name='', alternative='', pending=False, obj_type='', addendum='', removal=''):
"""
Display a standardized deprecation.
Parameters
----------
since : str
The release at which this API became deprecated.
message : str, optional
Override the default deprecation message. The ``%(since)s``,
``%(name)s``, ``%(alternative)s``, ``%(obj_type)s``, ``%(addendum)s``,
and ``%(removal)s`` format specifiers will be replaced by the values
of the respective arguments passed to this function.
name : str, optional
The name of the deprecated object.
alternative : str, optional
An alternative API that the user may use in place of the deprecated
API. The deprecation warning will tell the user about this alternative
if provided.
pending : bool, optional
If True, uses a PendingDeprecationWarning instead of a
DeprecationWarning. Cannot be used together with *removal*.
obj_type : str, optional
The object type being deprecated.
addendum : str, optional
Additional text appended directly to the final message.
removal : str, optional
The expected removal version. With the default (an empty string), a
removal version is automatically computed from *since*. Set to other
Falsy values to not schedule a removal date. Cannot be used together
with *pending*.
Examples
--------
Basic example::
# To warn of the deprecation of "qfluentwidgets.name_of_module"
warn_deprecated('1.4.0', name='qfluentwidgets.name_of_module',
obj_type='module')
"""
warning = _generate_deprecation_warning(
since, message, name, alternative, pending, obj_type, addendum,
removal=removal)
_warn_external(warning, category=FluentDeprecationWarning)
def deprecated(since, message='', name='', alternative='', pending=False,
obj_type=None, addendum='', removal=''):
"""
Decorator to mark a function, a class, or a property as deprecated.
When deprecating a classmethod, a staticmethod, or a property, the
``@deprecated`` decorator should go *under* ``@classmethod`` and
``@staticmethod`` (i.e., `deprecated` should directly decorate the
underlying callable), but *over* ``@property``.
Parameters
----------
since : str
The release at which this API became deprecated.
message : str, optional
Override the default deprecation message. The ``%(since)s``,
``%(name)s``, ``%(alternative)s``, ``%(obj_type)s``, ``%(addendum)s``,
and ``%(removal)s`` format specifiers will be replaced by the values
of the respective arguments passed to this function.
name : str, optional
The name used in the deprecation message; if not provided, the name
is automatically determined from the deprecated object.
alternative : str, optional
An alternative API that the user may use in place of the deprecated
API. The deprecation warning will tell the user about this alternative
if provided.
pending : bool, optional
If True, uses a PendingDeprecationWarning instead of a
DeprecationWarning. Cannot be used together with *removal*.
obj_type : str, optional
The object type being deprecated; by default, 'class' if decorating
a class, 'attribute' if decorating a property, 'function' otherwise.
addendum : str, optional
Additional text appended directly to the final message.
removal : str, optional
The expected removal version. With the default (an empty string), a
removal version is automatically computed from *since*. Set to other
Falsy values to not schedule a removal date. Cannot be used together
with *pending*.
Examples
--------
Basic example::
@deprecated('1.4.0')
def the_function_to_deprecate():
pass
"""
def deprecate(obj, message=message, name=name, alternative=alternative,
pending=pending, obj_type=obj_type, addendum=addendum):
if isinstance(obj, type):
if obj_type is None:
obj_type = "class"
func = obj.__init__
name = name or obj.__name__
old_doc = obj.__doc__
def finalize(wrapper, new_doc):
try:
obj.__doc__ = new_doc
except AttributeError: # Can't set on some extension objects.
pass
obj.__init__ = functools.wraps(obj.__init__)(wrapper)
return obj
elif isinstance(obj, property):
obj_type = "attribute"
func = None
name = name or obj.fget.__name__
old_doc = obj.__doc__
class _deprecated_property(property):
def __get__(self, instance, owner):
if instance is not None:
_warn_external(warning)
return super().__get__(instance, owner)
def __set__(self, instance, value):
if instance is not None:
_warn_external(warning)
return super().__set__(instance, value)
def __delete__(self, instance):
if instance is not None:
_warn_external(warning)
return super().__delete__(instance)
def finalize(_, new_doc):
return _deprecated_property(
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc)
else:
if obj_type is None:
obj_type = "function"
func = obj
name = name or obj.__name__
old_doc = func.__doc__
def finalize(wrapper, new_doc):
wrapper = functools.wraps(func)(wrapper)
wrapper.__doc__ = new_doc
return wrapper
warning = _generate_deprecation_warning(
since, message, name, alternative, pending, obj_type, addendum,
removal=removal)
def wrapper(*args, **kwargs):
_warn_external(warning)
return func(*args, **kwargs)
old_doc = inspect.cleandoc(old_doc or '').strip('\n')
notes_header = '\nNotes\n-----'
new_doc = (f"[*Deprecated*] {old_doc}\n"
f"{notes_header if notes_header not in old_doc else ''}\n"
f".. deprecated:: {since}\n"
f" {message.strip()}")
if not old_doc:
# This is to prevent a spurious 'unexpected unindent' warning from
# docutils when the original docstring was blank.
new_doc += r'\ '
return finalize(wrapper, new_doc)
return deprecate
class _deprecate_privatize_attribute:
"""
Helper to deprecate public access to an attribute.
This helper should only be used at class scope, as follows::
class Foo:
attr = _deprecate_privatize_attribute(*args, **kwargs)
where *all* parameters are forwarded to `deprecated`. This form makes
``attr`` a property which forwards access to ``self._attr`` (same name but
with a leading underscore), with a deprecation warning. Note that the
attribute name is derived from *the name this helper is assigned to*.
"""
def __init__(self, *args, **kwargs):
self.deprecator = deprecated(*args, **kwargs)
def __set_name__(self, owner, name):
setattr(owner, name, self.deprecator(
property(lambda self: getattr(self, f"_{name}")), name=name))
def _rename_parameter(since, old, new, func=None):
"""
Decorator indicating that parameter *old* of *func* is renamed to *new*.
The actual implementation of *func* should use *new*, not *old*. If *old*
is passed to *func*, a DeprecationWarning is emitted, and its value is
used, even if *new* is also passed by keyword (this is to simplify pyplot
wrapper functions, which always pass *new* explicitly to the Axes method).
If *new* is also passed but positionally, a TypeError will be raised by the
underlying function during argument binding.
Examples
--------
::
@_rename_parameter("3.1", "bad_name", "good_name")
def func(good_name): ...
"""
if func is None:
return functools.partial(_rename_parameter, since, old, new)
signature = inspect.signature(func)
assert old not in signature.parameters, (
f"PyQt-Fluent-Widgets internal error: {old!r} cannot be a parameter for "
f"{func.__name__}()")
assert new in signature.parameters, (
f"PyQt-Fluent-Widgets internal error: {new!r} must be a parameter for "
f"{func.__name__}()")
@functools.wraps(func)
def wrapper(*args, **kwargs):
if old in kwargs:
warn_deprecated(
since, message=f"The {old!r} parameter of {func.__name__}() "
f"has been renamed {new!r} since PyQt-Fluent-Widgets {since}; support "
f"for the old name will be dropped %(removal)s.")
kwargs[new] = kwargs.pop(old)
return func(*args, **kwargs)
# wrapper() must keep the same documented signature as func(): if we
# instead made both *old* and *new* appear in wrapper()'s signature, they
# would both show up in the pyplot function for an Axes method as well and
# pyplot would explicitly pass both arguments to the Axes method.
return wrapper
class _deprecated_parameter_class:
def __repr__(self):
return "<deprecated parameter>"
_deprecated_parameter = _deprecated_parameter_class()
def _delete_parameter(since, name, func=None, **kwargs):
"""
Decorator indicating that parameter *name* of *func* is being deprecated.
The actual implementation of *func* should keep the *name* parameter in its
signature, or accept a ``**kwargs`` argument (through which *name* would be
passed).
Parameters that come after the deprecated parameter effectively become
keyword-only (as they cannot be passed positionally without triggering the
DeprecationWarning on the deprecated parameter), and should be marked as
such after the deprecation period has passed and the deprecated parameter
is removed.
Parameters other than *since*, *name*, and *func* are keyword-only and
forwarded to `.warn_deprecated`.
Examples
--------
::
@_delete_parameter("3.1", "unused")
def func(used_arg, other_arg, unused, more_args): ...
"""
if func is None:
return functools.partial(_delete_parameter, since, name, **kwargs)
signature = inspect.signature(func)
# Name of `**kwargs` parameter of the decorated function, typically
# "kwargs" if such a parameter exists, or None if the decorated function
# doesn't accept `**kwargs`.
kwargs_name = next((param.name for param in signature.parameters.values()
if param.kind == inspect.Parameter.VAR_KEYWORD), None)
if name in signature.parameters:
kind = signature.parameters[name].kind
is_varargs = kind is inspect.Parameter.VAR_POSITIONAL
is_varkwargs = kind is inspect.Parameter.VAR_KEYWORD
if not is_varargs and not is_varkwargs:
func.__signature__ = signature = signature.replace(parameters=[
param.replace(default=_deprecated_parameter)
if param.name == name else param
for param in signature.parameters.values()])
else:
is_varargs = is_varkwargs = False
assert kwargs_name, (
f"PyQt-Fluent-Widgets internal error: {name!r} must be a parameter for "
f"{func.__name__}()")
addendum = kwargs.pop('addendum', None)
@functools.wraps(func)
def wrapper(*inner_args, **inner_kwargs):
arguments = signature.bind(*inner_args, **inner_kwargs).arguments
if is_varargs and arguments.get(name):
warn_deprecated(
since, message=f"Additional positional arguments to "
f"{func.__name__}() are deprecated since %(since)s and "
f"support for them will be removed %(removal)s.")
elif is_varkwargs and arguments.get(name):
warn_deprecated(
since, message=f"Additional keyword arguments to "
f"{func.__name__}() are deprecated since %(since)s and "
f"support for them will be removed %(removal)s.")
# We cannot just check `name not in arguments` because the pyplot
# wrappers always pass all arguments explicitly.
elif any(name in d and d[name] != _deprecated_parameter
for d in [arguments, arguments.get(kwargs_name, {})]):
deprecation_addendum = (
f"If any parameter follows {name!r}, they should be passed as "
f"keyword, not positionally.")
warn_deprecated(
since,
name=repr(name),
obj_type=f"parameter of {func.__name__}()",
addendum=(addendum + " " + deprecation_addendum) if addendum
else deprecation_addendum,
**kwargs)
return func(*inner_args, **inner_kwargs)
return wrapper
def _make_keyword_only(since, name, func=None):
"""
Decorator indicating that passing parameter *name* (or any of the following
ones) positionally to *func* is being deprecated.
"""
if func is None:
return functools.partial(_make_keyword_only, since, name)
signature = inspect.signature(func)
POK = inspect.Parameter.POSITIONAL_OR_KEYWORD
KWO = inspect.Parameter.KEYWORD_ONLY
assert (name in signature.parameters
and signature.parameters[name].kind == POK), (
f"PyQt-Fluent-Widgets internal error: {name!r} must be a positional-or-keyword "
f"parameter for {func.__name__}()")
names = [*signature.parameters]
kwonly = [name for name in names[names.index(name):]
if signature.parameters[name].kind == POK]
func.__signature__ = signature.replace(parameters=[
param.replace(kind=KWO) if param.name in kwonly else param
for param in signature.parameters.values()])
@functools.wraps(func)
def wrapper(*args, **kwargs):
# Don't use signature.bind here, as it would fail when stacked with
# _rename_parameter and an "old" argument name is passed in
# (signature.bind would fail, but the actual call would succeed).
idx = [*func.__signature__.parameters].index(name)
if len(args) > idx:
warn_deprecated(
since, message="Passing the %(name)s %(obj_type)s "
"positionally is deprecated since PyQt-Fluent-Widgets %(since)s; the "
"parameter will become keyword-only %(removal)s.",
name=name, obj_type=f"parameter of {func.__name__}()")
return func(*args, **kwargs)
return wrapper
......@@ -242,6 +242,7 @@ class FluentIconBase:
class FluentIcon(FluentIconBase, Enum):
""" Fluent icon """
UP = "Up"
ADD = "Add"
CUT = "Cut"
PIN = "Pin"
......@@ -249,6 +250,7 @@ class FluentIcon(FluentIconBase, Enum):
CHAT = "Chat"
COPY = "Copy"
CODE = "Code"
DOWN = "Down"
EDIT = "Edit"
FONT = "Font"
HELP = "Help"
......@@ -285,12 +287,14 @@ class FluentIcon(FluentIconBase, Enum):
CANCEL = "Cancel"
DELETE = "Delete"
FOLDER = "Folder"
FILTER = "Filter"
SCROLL = "Scroll"
LAYOUT = "Layout"
GITHUB = "GitHub"
UPDATE = "Update"
RETURN = "Return"
RINGER = "Ringer"
ROTATE = "Rotate"
SEARCH = "Search"
SAVE_AS = "SaveAs"
ZOOM_IN = "ZoomIn"
......
......@@ -11,7 +11,6 @@ from .navigation_widget import (NavigationTreeWidgetBase, NavigationToolButton,
from ..widgets.scroll_area import SingleDirectionScrollArea
from ..widgets.tool_tip import ToolTipFilter
from ...common.router import qrouter
from ...common.deprecation import deprecated
from ...common.style_sheet import FluentStyleSheet
from ...common.icon import FluentIconBase
from ...common.icon import FluentIcon as FIF
......
......@@ -489,7 +489,7 @@ class CommandViewBar(CommandBar):
# adjust the shape of menu
menu.closedSignal.connect(lambda: view.setMenuVisible(False))
menu.setDropDown(self.isMenuDropDown(), menu.view.width() > view.width())
menu.setDropDown(self.isMenuDropDown(), menu.view.width() > view.width()+5)
# adjust menu size
if menu.view.width() < view.width():
......@@ -619,5 +619,5 @@ class CommandBarView(FlyoutViewBase):
painter.setBrush(
QColor(40, 40, 40) if isDarkTheme() else QColor(248, 248, 248))
painter.setPen(
QColor(23, 23, 23) if isDarkTheme() else QColor(233, 233, 233))
QColor(56, 56, 56) if isDarkTheme() else QColor(233, 233, 233))
painter.drawPath(path.simplified())
......@@ -191,6 +191,9 @@ class ImageLabel(QLabel):
super().mouseReleaseEvent(e)
self.clicked.emit()
def pixmap(self) -> QPixmap:
return QPixmap.fromImage(self.image)
def paintEvent(self, e):
if self.isNull():
return
......
......@@ -3,9 +3,10 @@ from enum import Enum
from typing import List, Union
from qframelesswindow import WindowEffect
from PyQt5.QtCore import (QEasingCurve, QEvent, QPropertyAnimation, QObject,
from PyQt5.QtCore import (QEasingCurve, QEvent, QPropertyAnimation, QObject, QModelIndex,
Qt, QSize, QRectF, pyqtSignal, QPoint, QTimer, QParallelAnimationGroup)
from PyQt5.QtGui import QIcon, QColor, QPainter, QPen, QPixmap, QRegion, QCursor, QTextCursor, QHoverEvent
from PyQt5.QtGui import (QIcon, QColor, QPainter, QPen, QPixmap, QRegion, QCursor, QTextCursor, QHoverEvent,
QFontMetrics)
from PyQt5.QtWidgets import (QAction, QApplication, QMenu, QProxyStyle, QStyle,
QGraphicsDropShadowEffect, QListWidget, QWidget, QHBoxLayout,
QListWidgetItem, QLineEdit, QTextEdit, QStyledItemDelegate, QStyleOptionViewItem)
......@@ -13,6 +14,7 @@ from PyQt5.QtWidgets import (QAction, QApplication, QMenu, QProxyStyle, QStyle,
from ...common.icon import FluentIcon as FIF
from ...common.icon import FluentIconEngine, Action, FluentIconBase, Icon
from ...common.style_sheet import FluentStyleSheet, themeColor
from ...common.font import getFont
from ...common.config import isDarkTheme
from .scroll_bar import SmoothScrollDelegate
......@@ -104,8 +106,11 @@ class SubMenuItemWidget(QWidget):
class MenuItemDelegate(QStyledItemDelegate):
""" Menu item delegate """
def _isSeparator(self, index: QModelIndex):
return index.model().data(index, Qt.DecorationRole) == "seperator"
def paint(self, painter, option, index):
if index.model().data(index, Qt.DecorationRole) != "seperator":
if not self._isSeparator(index):
return super().paint(painter, option, index)
# draw seperator
......@@ -121,6 +126,37 @@ class MenuItemDelegate(QStyledItemDelegate):
painter.restore()
class ShortcutMenuItemDelegate(MenuItemDelegate):
""" Shortcut key menu item delegate """
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex):
super().paint(painter, option, index)
if self._isSeparator(index):
return
# draw shortcut key
action = index.data(Qt.UserRole) # type: QAction
if not isinstance(action, QAction) or action.shortcut().isEmpty():
return
painter.save()
font = getFont(12)
painter.setFont(font)
painter.setPen(QColor(255, 255, 255, 200) if isDarkTheme() else QColor(0, 0, 0, 153))
fm = QFontMetrics(font)
shortcut = action.shortcut().toString()
sw = fm.width(shortcut)
painter.translate(option.rect.width()-sw-20, 0)
rect = QRectF(0, option.rect.y(), sw, option.rect.height())
painter.drawText(rect, Qt.AlignLeft | Qt.AlignVCenter, shortcut)
painter.restore()
class MenuActionListWidget(QListWidget):
""" Menu action list widget """
......@@ -131,7 +167,7 @@ class MenuActionListWidget(QListWidget):
self.setDragEnabled(False)
self.setMouseTracking(True)
self.setIconSize(QSize(14, 14))
self.setItemDelegate(MenuItemDelegate(self))
self.setItemDelegate(ShortcutMenuItemDelegate(self))
self.scrollDelegate = SmoothScrollDelegate(self)
self.setStyleSheet(
......@@ -303,12 +339,18 @@ class RoundMenu(QWidget):
raise ValueError('`before` is not in the action list')
item = QListWidgetItem(self._createItemIcon(action), action.text())
sw = self._longestShortcutWidth()
if sw:
sw += 22
# adjust the width of item
if not self._hasItemIcon():
w = 40 + self.view.fontMetrics().width(action.text())
w = 40 + self.view.fontMetrics().width(action.text()) + sw
else:
# add a blank character to increase space between icon and text
item.setText(" " + item.text())
w = 60 + self.view.fontMetrics().width(item.text())
w = 60 + self.view.fontMetrics().width(item.text()) + sw
item.setSizeHint(QSize(w, self.itemHeight))
item.setData(Qt.UserRole, action)
......@@ -319,6 +361,11 @@ class RoundMenu(QWidget):
def _hasItemIcon(self):
return any(not i.icon().isNull() for i in self._actions+self._subMenus)
def _longestShortcutWidth(self):
""" longest shortcut key """
fm = QFontMetrics(getFont(12))
return max(fm.width(a.shortcut().toString()) for a in self.menuActions())
def _createItemIcon(self, w):
""" create the icon of menu item """
hasIcon = self._hasItemIcon()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册