init
This commit is contained in:
37
app/view/components/gb_information_card.py
Normal file
37
app/view/components/gb_information_card.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# coding: utf-8
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtWidgets import QVBoxLayout
|
||||
from qfluentwidgets import BodyLabel, ElevatedCardWidget, SubtitleLabel
|
||||
|
||||
|
||||
class GbInformationCard(ElevatedCardWidget):
|
||||
def __init__(self, amount,station,parent=None):
|
||||
super().__init__(parent=parent)
|
||||
|
||||
|
||||
self.currentAmountLabel = SubtitleLabel(self)
|
||||
self.currentAmountLabel.setText(self.formatSize(amount))
|
||||
self.currentAmountLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
self.stationLabel = BodyLabel(station,self)
|
||||
self.stationLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
self.vBoxLayout = QVBoxLayout(self)
|
||||
self.vBoxLayout.setContentsMargins(2,5,2,5)
|
||||
self.vBoxLayout.addWidget(self.currentAmountLabel,0,Qt.AlignmentFlag.AlignTop)
|
||||
self.vBoxLayout.addSpacing(0)
|
||||
self.vBoxLayout.addWidget(self.stationLabel,0,Qt.AlignmentFlag.AlignTop)
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def formatSize(size):
|
||||
"""格式化文件大小"""
|
||||
for unit in ["B", "KB", "MB", "GB", "TB"]:
|
||||
if size < 1024:
|
||||
return f"{size:.2f} {unit}"
|
||||
size /= 1024
|
||||
return f"{size:.2f} PB"
|
||||
|
||||
def updateValue(self,value):
|
||||
self.currentAmountLabel.setText(self.formatSize(value))
|
||||
Reference in New Issue
Block a user