Removed setProperty and findChild in dowloader.py for code uniformity

This commit is contained in:
Marco Dalla Tiezza
2024-06-10 21:51:53 +02:00
parent 19acf11b1a
commit 5b8670814b
3 changed files with 128 additions and 99 deletions

View File

@@ -6635,7 +6635,7 @@ G@\x11\x10HG\x93Hp\xec\x0au\xe3\xcd\x1e\xf4\
>k\xd0\xd3b\x1eG\xb5_d\xde\xb6{\x8f\x95\xc5\ >k\xd0\xd3b\x1eG\xb5_d\xde\xb6{\x8f\x95\xc5\
U\xaf\xbc\xfd\xe9\xb5\x9f\xe5\xe3}r\xba?\xbbI\x06\ U\xaf\xbc\xfd\xe9\xb5\x9f\xe5\xe3}r\xba?\xbbI\x06\
\xfe\xfc\x0f\xf4\xcd*2\ \xfe\xfc\x0f\xf4\xcd*2\
\x00\x00\x05\xab\ \x00\x00\x06\x95\
i\ i\
mport QtQuick\x0d\x0ai\ mport QtQuick\x0d\x0ai\
mport QtQuick.Wi\ mport QtQuick.Wi\
@@ -6644,90 +6644,105 @@ uick.Controls\x0d\x0ai\
mport QtQuick.Co\ mport QtQuick.Co\
ntrols.Material\x0d\ ntrols.Material\x0d\
\x0aimport QtQuick.\ \x0aimport QtQuick.\
Layouts\x0d\x0a\x0d\x0aWindo\ Layouts\x0d\x0a\x0d\x0a\x0d\x0aWin\
w {\x0d\x0a id: win\ dow {\x0d\x0a id: w\
dowDownloader\x0d\x0a\x0d\ indowDownloader\x0d\
\x0a width: 400\x0d\ \x0a\x0d\x0a width: 40\
\x0a height: 130\ 0\x0d\x0a height: 1\
\x0d\x0a\x0d\x0a maximumH\ 30\x0d\x0a\x0d\x0a maximu\
eight: height\x0d\x0a \ mHeight: height\x0d\
maximumWidth:\ \x0a maximumWidt\
width\x0d\x0a\x0d\x0a mi\ h: width\x0d\x0a\x0d\x0a \
nimumHeight: hei\ minimumHeight: h\
ght\x0d\x0a minimum\ eight\x0d\x0a minim\
Width: width\x0d\x0a\x0d\x0a\ umWidth: width\x0d\x0a\
modality: Qt\ \x0d\x0a modality: \
.ApplicationModa\ Qt.ApplicationMo\
l\x0d\x0a flags: Qt\ dal\x0d\x0a flags: \
.Dialog\x0d\x0a\x0d\x0a t\ Qt.Dialog\x0d\x0a\x0d\x0a \
itle: qsTr(\x22Arte\ title: qsTr(\x22Ar\
mis - Downloader\ temis - Download\
\x22)\x0d\x0a\x0d\x0a signal\ er\x22)\x0d\x0a\x0d\x0a sign\
onAbort()\x0d\x0a\x0d\x0a \ al onAbort()\x0d\x0a\x0d\x0a\
Page {\x0d\x0a \ function upd\
id: page\x0d\x0a \ ateProgressBar(b\
anchors.fill\ ytesReceived, by\
: parent\x0d\x0a\x0d\x0a \ tesTotal) {\x0d\x0a \
ColumnLayout\ progressBar\
{\x0d\x0a \ .value = bytesRe\
id: columnLayout\ ceived\x0d\x0a \
\x0d\x0a an\ progressBar.to =\
chors.fill: pare\ bytesTotal\x0d\x0a \
nt\x0d\x0a\x0d\x0a \ }\x0d\x0a\x0d\x0a functi\
on updateStatus(\
arg) {\x0d\x0a \
progressLabel.te\
xt = arg\x0d\x0a }\x0d\
\x0a\x0d\x0a Page {\x0d\x0a \
id: page\x0d\
\x0a anchors\
.fill: parent\x0d\x0a\x0d\
\x0a ColumnL\
ayout {\x0d\x0a \
id: columnL\
ayout\x0d\x0a \
anchors.fill:\
parent\x0d\x0a\x0d\x0a \
Label {\x0d\x0a\
\
text: qsTr(\x22Down\
loading in progr\
ess...\x22)\x0d\x0a \
Layout\
.alignment: Qt.A\
lignHCenter | Qt\
.AlignVCenter\x0d\x0a \
}\x0d\x0a\x0d\x0a\
Prog\
ressBar {\x0d\x0a \
id: p\
rogressBar\x0d\x0a \
Layo\
ut.rightMargin: \
20\x0d\x0a \
Layout.leftM\
argin: 20\x0d\x0a \
Layou\
t.fillWidth: tru\
e\x0d\x0a \
value: 0\x0d\x0a \
to:\
0\x0d\x0a \
}\x0d\x0a\x0d\x0a \
Label {\x0d\x0a \ Label {\x0d\x0a \
text:\ id: pr\
qsTr(\x22Downloadi\ ogressLabel\x0d\x0a \
ng in progress..\ Lay\
.\x22)\x0d\x0a \ out.alignment: Q\
Layout.alig\ t.AlignHCenter |\
nment: Qt.AlignH\ Qt.AlignVCenter\
Center | Qt.Alig\
nVCenter\x0d\x0a \
}\x0d\x0a\x0d\x0a \
ProgressB\
ar {\x0d\x0a \
objectName\
: \x22progressBar\x22\x0d\
\x0a \
Layout.rightMar\
gin: 20\x0d\x0a \
Layout.\
leftMargin: 20\x0d\x0a\
\
Layout.fillWidth\
: true\x0d\x0a \
value: 0\
\x0d\x0a }\x0d\ \x0d\x0a }\x0d\
\x0a\x0d\x0a L\ \x0a\x0d\x0a B\
abel {\x0d\x0a \ utton {\x0d\x0a \
objectNa\ text: q\
me: \x22labelProgre\ sTr(\x22Abort\x22)\x0d\x0a \
ss\x22\x0d\x0a \ ic\
Layout.alig\ on.source: \x22qrc:\
nment: Qt.AlignH\ /images/icons/ab\
Center | Qt.Alig\ ort.svg\x22\x0d\x0a \
nVCenter\x0d\x0a \ displa\
y: AbstractButto\
n.TextBesideIcon\
\x0d\x0a \
Layout.alignme\
nt: Qt.AlignHCen\
ter | Qt.AlignBo\
ttom\x0d\x0a \
onClicked:\
{ onAbort() }\x0d\x0a\
}\x0d\x0a \ }\x0d\x0a \
Button {\x0d\x0a \ }\x0d\x0a }\x0d\
t\ \x0a}\x0d\x0a\
ext: qsTr(\x22Abort\
\x22)\x0d\x0a \
icon.source:\
\x22qrc:/images/ic\
ons/abort.svg\x22\x0d\x0a\
\
display: Abstrac\
tButton.TextBesi\
deIcon\x0d\x0a \
Layout.a\
lignment: Qt.Ali\
gnHCenter | Qt.A\
lignBottom\x0d\x0a \
onCl\
icked: { onAbort\
() }\x0d\x0a \
}\x0d\x0a }\x0d\x0a\
}\x0d\x0a}\x0d\x0a\
\x00\x00\x05\xac\ \x00\x00\x05\xac\
i\ i\
mport QtQuick\x0d\x0ai\ mport QtQuick\x0d\x0ai\
@@ -7278,12 +7293,12 @@ qt_resource_struct = b"\
\x00\x00\x01\x8f\xff^8P\ \x00\x00\x01\x8f\xff^8P\
\x00\x00\x03<\x00\x01\x00\x00\x00\x01\x00\x01>\xe2\ \x00\x00\x03<\x00\x01\x00\x00\x00\x01\x00\x01>\xe2\
\x00\x00\x01\x8f\xff^8P\ \x00\x00\x01\x8f\xff^8P\
\x00\x00\x05\xa8\x00\x00\x00\x00\x00\x01\x00\x01\x9e\xf3\ \x00\x00\x05\xa8\x00\x00\x00\x00\x00\x01\x00\x01\x9f\xdd\
\x00\x00\x01\x8f\xff^8P\ \x00\x00\x01\x8f\xff^8P\
\x00\x00\x03r\x00\x01\x00\x00\x00\x01\x00\x01I\x0c\ \x00\x00\x03r\x00\x01\x00\x00\x00\x01\x00\x01I\x0c\
\x00\x00\x01\x8f\xff^8_\ \x00\x00\x01\x8f\xff^8_\
\x00\x00\x05\x86\x00\x00\x00\x00\x00\x01\x00\x01\x99D\ \x00\x00\x05\x86\x00\x00\x00\x00\x00\x01\x00\x01\x99D\
\x00\x00\x01\x8f\xff^8P\ \x00\x00\x01\x90\x03\xb0\x82B\
\x00\x00\x03X\x00\x02\x00\x00\x00\x04\x00\x00\x00+\ \x00\x00\x03X\x00\x02\x00\x00\x00\x04\x00\x00\x00+\
\x00\x00\x00\x00\x00\x00\x00\x00\ \x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x04\xc4\x00\x01\x00\x00\x00\x01\x00\x01v\x14\ \x00\x00\x04\xc4\x00\x01\x00\x00\x00\x01\x00\x01v\x14\
@@ -7302,13 +7317,13 @@ qt_resource_struct = b"\
\x00\x00\x01\x8f\xff^8P\ \x00\x00\x01\x8f\xff^8P\
\x00\x00\x05\x06\x00\x00\x00\x00\x00\x01\x00\x01\x85\xab\ \x00\x00\x05\x06\x00\x00\x00\x00\x00\x01\x00\x01\x85\xab\
\x00\x00\x01\x8f\xff^8P\ \x00\x00\x01\x8f\xff^8P\
\x00\x00\x05\xdc\x00\x01\x00\x00\x00\x01\x00\x01\xa7\xa6\ \x00\x00\x05\xdc\x00\x01\x00\x00\x00\x01\x00\x01\xa8\x90\
\x00\x00\x01\x8f\xff^8_\ \x00\x00\x01\x8f\xff^8_\
\x00\x00\x06$\x00\x01\x00\x00\x00\x01\x00\x01\xad\xeb\ \x00\x00\x06$\x00\x01\x00\x00\x00\x01\x00\x01\xae\xd5\
\x00\x00\x01\x8f\xff^8_\ \x00\x00\x01\x8f\xff^8_\
\x00\x00\x05\xc0\x00\x01\x00\x00\x00\x01\x00\x01\xa4\xa3\ \x00\x00\x05\xc0\x00\x01\x00\x00\x00\x01\x00\x01\xa5\x8d\
\x00\x00\x01\x8f\xff^8_\ \x00\x00\x01\x8f\xff^8_\
\x00\x00\x06\x00\x00\x01\x00\x00\x00\x01\x00\x01\xaai\ \x00\x00\x06\x00\x00\x01\x00\x00\x00\x01\x00\x01\xabS\
\x00\x00\x01\x8f\xff^8_\ \x00\x00\x01\x8f\xff^8_\
" "

View File

@@ -12,6 +12,9 @@ class UIDownloader(QObject):
# Python > QML Signals # Python > QML Signals
show_ui = Signal() show_ui = Signal()
close_ui = Signal() close_ui = Signal()
update_progress_bar = Signal(int, int)
update_status = Signal(str)
def __init__(self, parent): def __init__(self, parent):
super().__init__() super().__init__()
@@ -21,8 +24,6 @@ class UIDownloader(QObject):
self._engine = QQmlApplicationEngine() self._engine = QQmlApplicationEngine()
self._engine.load('qrc:/ui/Downloader.qml') self._engine.load('qrc:/ui/Downloader.qml')
self._window = self._engine.rootObjects()[0] self._window = self._engine.rootObjects()[0]
self._progress_bar = self._window.findChild(QObject, "progressBar")
self._label_progress = self._window.findChild(QObject, "labelProgress")
self._connect() self._connect()
@@ -34,6 +35,8 @@ class UIDownloader(QObject):
# Python > QML connections # Python > QML connections
self.show_ui.connect(self._window.show) self.show_ui.connect(self._window.show)
self.close_ui.connect(self._window.close) self.close_ui.connect(self._window.close)
self.update_progress_bar.connect(self._window.updateProgressBar)
self.update_status.connect(self._window.updateStatus)
@Slot() @Slot()
@@ -66,7 +69,7 @@ class UIDownloader(QObject):
""" Stop the download when user press abort button """ """ Stop the download when user press abort button """
if self.reply: if self.reply:
self.reply.abort() self.reply.abort()
self._progress_bar.setProperty("value", 0) self.update_progress_bar.emit(0, 0)
if self.file: if self.file:
self.file.cancelWriting() self.file.cancelWriting()
@@ -93,10 +96,10 @@ class UIDownloader(QObject):
if self.file: if self.file:
self.file.commit() self.file.commit()
self._label_progress.setProperty("text", "Checking DB integrity (SHA-256)") self.update_status.emit("Checking DB integrity (SHA-256)")
if match_hash(self.dest_file, self._parent.network_manager.remote_db_hash): if match_hash(self.dest_file, self._parent.network_manager.remote_db_hash):
self._label_progress.setProperty("text", "Unpacking archive...") self.update_status.emit("Unpacking archive...")
delete_dir(DATA_DIR / 'SigID') delete_dir(DATA_DIR / 'SigID')
unpack_tar(self.dest_file, DATA_DIR / 'SigID') unpack_tar(self.dest_file, DATA_DIR / 'SigID')
delete_file(self.dest_file) delete_file(self.dest_file)
@@ -109,9 +112,8 @@ class UIDownloader(QObject):
""" Update progress bar and label """ Update progress bar and label
""" """
total_bytes = self._parent.network_manager.remote_db_size total_bytes = self._parent.network_manager.remote_db_size
self._label_progress.setProperty("text", "{:.1f} Mb / {:.1f} Mb".format(bytesReceived/10**6, total_bytes/10**6)) self.update_status.emit("{:.1f} Mb / {:.1f} Mb".format(bytesReceived/10**6, total_bytes/10**6))
self._progress_bar.setProperty("to", total_bytes) self.update_progress_bar.emit(bytesReceived, total_bytes)
self._progress_bar.setProperty("value", bytesReceived)
@Slot(QNetworkReply.NetworkError) @Slot(QNetworkReply.NetworkError)

View File

@@ -4,6 +4,7 @@ import QtQuick.Controls
import QtQuick.Controls.Material import QtQuick.Controls.Material
import QtQuick.Layouts import QtQuick.Layouts
Window { Window {
id: windowDownloader id: windowDownloader
@@ -23,6 +24,15 @@ Window {
signal onAbort() signal onAbort()
function updateProgressBar(bytesReceived, bytesTotal) {
progressBar.value = bytesReceived
progressBar.to = bytesTotal
}
function updateStatus(arg) {
progressLabel.text = arg
}
Page { Page {
id: page id: page
anchors.fill: parent anchors.fill: parent
@@ -37,17 +47,19 @@ Window {
} }
ProgressBar { ProgressBar {
objectName: "progressBar" id: progressBar
Layout.rightMargin: 20 Layout.rightMargin: 20
Layout.leftMargin: 20 Layout.leftMargin: 20
Layout.fillWidth: true Layout.fillWidth: true
value: 0 value: 0
to: 0
} }
Label { Label {
objectName: "labelProgress" id: progressLabel
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
} }
Button { Button {
text: qsTr("Abort") text: qsTr("Abort")
icon.source: "qrc:/images/icons/abort.svg" icon.source: "qrc:/images/icons/abort.svg"