添加 ProgressInfoBar 组件
This commit is contained in:
74
ui/components/infobar.py
Normal file
74
ui/components/infobar.py
Normal file
@@ -0,0 +1,74 @@
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtGui import QIcon
|
||||
from qfluentwidgets import InfoBar, InfoBarPosition, InfoBarIcon, FluentIconBase, ProgressBar, IndeterminateProgressBar, \
|
||||
InfoBarManager
|
||||
|
||||
|
||||
class ProgressInfoBar(InfoBar):
|
||||
def __init__(self, icon: InfoBarIcon | FluentIconBase | QIcon | str, title: str, content: str, orient=Qt.Horizontal,
|
||||
isClosable=True, duration=1000,
|
||||
position=InfoBarPosition.TOP_RIGHT, parent=None):
|
||||
super().__init__(icon, title, content, orient, isClosable, duration, position, parent)
|
||||
|
||||
self.pb = ProgressBar()
|
||||
self.ipb = IndeterminateProgressBar(start=True)
|
||||
|
||||
self.addWidget(self.pb)
|
||||
self.addWidget(self.ipb)
|
||||
|
||||
self.hide_progress()
|
||||
|
||||
self.show()
|
||||
|
||||
def set_progress(self, value: int):
|
||||
manager = InfoBarManager.make(self.position)
|
||||
|
||||
if value < 0 or value > 100:
|
||||
if not self.ipb.isVisible():
|
||||
manager.remove(self)
|
||||
self.ipb.setVisible(True)
|
||||
self.pb.setVisible(False)
|
||||
self.adjustSize()
|
||||
manager.add(self)
|
||||
else:
|
||||
return
|
||||
else:
|
||||
if not self.pb.isVisible():
|
||||
manager.remove(self)
|
||||
self.pb.setVisible(True)
|
||||
self.ipb.setVisible(False)
|
||||
self.adjustSize()
|
||||
manager.add(self)
|
||||
self.pb.setValue(value)
|
||||
|
||||
def hide_progress(self):
|
||||
self.pb.setVisible(False)
|
||||
self.ipb.setVisible(False)
|
||||
self.adjustSize()
|
||||
|
||||
def set_title(self, title: str):
|
||||
if title == self.title:
|
||||
return
|
||||
manager = InfoBarManager.make(self.position)
|
||||
manager.remove(self)
|
||||
|
||||
self.title = title
|
||||
self._adjustText()
|
||||
|
||||
manager.add(self)
|
||||
|
||||
def show_success(self, title: str = '成功!', content: str = "操作已完成", isCloseable: bool = True,
|
||||
duration: int = 5000):
|
||||
|
||||
self.setVisible(False)
|
||||
InfoBarManager.make(self.position).remove(self)
|
||||
|
||||
InfoBar.success(
|
||||
title=title,
|
||||
content=content,
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=isCloseable,
|
||||
position=InfoBarPosition.BOTTOM,
|
||||
duration=duration,
|
||||
parent=self.parent()
|
||||
)
|
||||
Reference in New Issue
Block a user