90 lines
2.8 KiB
Python
90 lines
2.8 KiB
Python
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 = InfoBarIcon.INFORMATION, title: str = "1",
|
|
content: str = "", orient=Qt.Horizontal,
|
|
isClosable=True, duration=1000,
|
|
position=InfoBarPosition.BOTTOM, 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:
|
|
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()
|
|
)
|
|
|
|
def show_error(self, title: str = '错误!', content: str = "操作失败", isCloseable: bool = True,
|
|
duration: int = 5000):
|
|
self.setVisible(False)
|
|
InfoBarManager.make(self.position).remove(self)
|
|
|
|
InfoBar.error(
|
|
title=title,
|
|
content=content,
|
|
orient=Qt.Horizontal,
|
|
isClosable=isCloseable,
|
|
position=InfoBarPosition.BOTTOM,
|
|
duration=duration,
|
|
parent=self.parent()
|
|
)
|