mirror of https://gitlab.com/pamhyr/pamhyr2
Pamhyr: Add waiting dialog at file loading.
parent
af779a1880
commit
4222503961
|
|
@ -49,6 +49,7 @@ from View.Tools.ListedSubWindow import ListedSubWindow
|
||||||
from View.DummyWindow import DummyWindow
|
from View.DummyWindow import DummyWindow
|
||||||
|
|
||||||
from View.Translate import MainTranslate
|
from View.Translate import MainTranslate
|
||||||
|
from View.WaitingDialog import WaitingDialog
|
||||||
|
|
||||||
from View.MainWindowTabInfo import WidgetInfo
|
from View.MainWindowTabInfo import WidgetInfo
|
||||||
from View.MainWindowTabChecker import WidgetChecker
|
from View.MainWindowTabChecker import WidgetChecker
|
||||||
|
|
@ -931,7 +932,19 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
|
|
||||||
if dialog.exec_():
|
if dialog.exec_():
|
||||||
file_name = dialog.selectedFiles()
|
file_name = dialog.selectedFiles()
|
||||||
self.open_study(file_name[0])
|
|
||||||
|
def fn():
|
||||||
|
self._tmp_study = Study.open(file_name[0])
|
||||||
|
|
||||||
|
dlg = WaitingDialog(
|
||||||
|
payload_fn=fn,
|
||||||
|
title="waiting_load",
|
||||||
|
parent=self
|
||||||
|
)
|
||||||
|
dlg.exec_()
|
||||||
|
|
||||||
|
self.set_model(self._tmp_study)
|
||||||
|
self.set_title()
|
||||||
|
|
||||||
def open_new_study(self):
|
def open_new_study(self):
|
||||||
"""Open dialog to set new study
|
"""Open dialog to set new study
|
||||||
|
|
@ -1260,7 +1273,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
name=name
|
name=name
|
||||||
)
|
)
|
||||||
|
|
||||||
dlg = ReadingResultsDialog(reading_fn=reading_fn, parent=self)
|
dlg = WaitingDialog(
|
||||||
|
payload_fn=reading_fn,
|
||||||
|
title="waiting_result",
|
||||||
|
parent=self
|
||||||
|
)
|
||||||
dlg.exec_()
|
dlg.exec_()
|
||||||
results = self._tmp_results
|
results = self._tmp_results
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,3 +92,10 @@ class MainTranslate(UnitTranslate):
|
||||||
self._dict["active_window"] = _translate(
|
self._dict["active_window"] = _translate(
|
||||||
"MainWindow", "Enable this window"
|
"MainWindow", "Enable this window"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._dict["waiting_load"] = _translate(
|
||||||
|
"MainWindow", "Loading file ..."
|
||||||
|
)
|
||||||
|
self._dict["waiting_result"] = _translate(
|
||||||
|
"MainWindow", "Reading results ..."
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,132 @@
|
||||||
|
# WaitingDialog.py -- Pamhyr
|
||||||
|
# Copyright (C) 2023-2024 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import random
|
||||||
|
|
||||||
|
from tools import logger_exception
|
||||||
|
|
||||||
|
from View.Tools.PamhyrWindow import PamhyrDialog
|
||||||
|
from View.Translate import MainTranslate
|
||||||
|
|
||||||
|
from PyQt5.QtGui import (
|
||||||
|
QKeySequence,
|
||||||
|
)
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
Qt, QVariant, QAbstractTableModel, QTimer,
|
||||||
|
QObject, pyqtSlot, pyqtSignal, QThread,
|
||||||
|
)
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import (
|
||||||
|
QLabel,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class Worker(QObject):
|
||||||
|
signalStatus = pyqtSignal(str)
|
||||||
|
|
||||||
|
def __init__(self, payload_fn, parent=None):
|
||||||
|
super(self.__class__, self).__init__(parent)
|
||||||
|
|
||||||
|
self._payload_fn = payload_fn
|
||||||
|
|
||||||
|
def process(self):
|
||||||
|
self._payload_fn()
|
||||||
|
self.signalStatus.emit('end')
|
||||||
|
|
||||||
|
|
||||||
|
class WaitingDialog(PamhyrDialog):
|
||||||
|
_pamhyr_ui = "WaitingDialog"
|
||||||
|
_pamhyr_name = "Waiting"
|
||||||
|
|
||||||
|
_spin_set = [
|
||||||
|
"-\\|/",
|
||||||
|
["", "", ".", ".", "..", "..", "...", "..."],
|
||||||
|
"▖▘▝▗",
|
||||||
|
"◢◣◤◥",
|
||||||
|
"◐◓◑◒",
|
||||||
|
"◰◳◲◱",
|
||||||
|
"◴◷◶◵",
|
||||||
|
"┤┘┴└├┌┬┐",
|
||||||
|
"⣷⣯⣟⡿⢿⣻⣽⣾",
|
||||||
|
"⡀⡁⡂⡃⡄⡅⡆⡇⡈⡉⡊⡋⡌⡍⡎⡏⡐⡑⡒⡓⡔⡕⡖⡗⡘⡙⡚⡛⡜⡝⡞⡟⡠⡡⡢⡣⡤⡥⡦⡧⡨⡩⡪⡫⡬⡭⡮⡯⡰⡱⡲⡳⡴⡵⡶⡷⡸⡹⡺⡻⡼⡽⡾⡿⢀⢁⢂⢃⢄⢅⢆⢇⢈⢉⢊⢋⢌⢍⢎⢏⢐⢑⢒⢓⢔⢕⢖⢗⢘⢙⢚⢛⢜⢝⢞⢟⢠⢡⢢⢣⢤⢥⢦⢧⢨⢩⢪⢫⢬⢭⢮⢯⢰⢱⢲⢳⢴⢵⢶⢷⢸⢹⢺⢻⢼⢽⢾⢿⣀⣁⣂⣃⣄⣅⣆⣇⣈⣉⣊⣋⣌⣍⣎⣏⣐⣑⣒⣓⣔⣕⣖⣗⣘⣙⣚⣛⣜⣝⣞⣟⣠⣡⣢⣣⣤⣥⣦⣧⣨⣩⣪⣫⣬⣭⣮⣯⣰⣱⣲⣳⣴⣵⣶⣷⣸⣹⣺⣻⣼⣽⣾⣿",
|
||||||
|
]
|
||||||
|
|
||||||
|
def __init__(self, payload_fn, title, parent=None):
|
||||||
|
trad = MainTranslate()
|
||||||
|
super(WaitingDialog, self).__init__(
|
||||||
|
title=trad[title],
|
||||||
|
trad=trad,
|
||||||
|
options=[],
|
||||||
|
parent=parent
|
||||||
|
)
|
||||||
|
|
||||||
|
self._payload_fn = payload_fn
|
||||||
|
|
||||||
|
self._init_default_values()
|
||||||
|
|
||||||
|
self.setup_timer()
|
||||||
|
self.setup_worker()
|
||||||
|
|
||||||
|
self._timer.start(300)
|
||||||
|
self._worker_thread.start()
|
||||||
|
|
||||||
|
def _init_default_values(self):
|
||||||
|
self._spinner_step = 0
|
||||||
|
self._spin = self._spin_set[
|
||||||
|
random.randrange(0, len(self._spin_set))
|
||||||
|
]
|
||||||
|
|
||||||
|
self.set_label_text("label_spinner", self._spin[0])
|
||||||
|
|
||||||
|
def setup_worker(self):
|
||||||
|
self._worker = Worker(self._payload_fn)
|
||||||
|
self._worker_thread = QThread(parent=self)
|
||||||
|
self._worker.moveToThread(self._worker_thread)
|
||||||
|
|
||||||
|
self._worker.signalStatus.connect(self.close)
|
||||||
|
self._worker_thread.started.connect(self._worker.process)
|
||||||
|
|
||||||
|
def setup_timer(self):
|
||||||
|
self._timer = QTimer(self)
|
||||||
|
self._timer.timeout.connect(self.update_spinner)
|
||||||
|
|
||||||
|
def update_spinner(self):
|
||||||
|
self._spinner_step += 1
|
||||||
|
self._spinner_step %= len(self._spin)
|
||||||
|
|
||||||
|
self.set_label_text(
|
||||||
|
"label_spinner",
|
||||||
|
self._spin[self._spinner_step]
|
||||||
|
)
|
||||||
|
|
||||||
|
def end_worker(self):
|
||||||
|
self._worker_thread.terminate()
|
||||||
|
self._worker_thread.wait()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
try:
|
||||||
|
self._timer.stop()
|
||||||
|
self.end_worker()
|
||||||
|
except Exception as e:
|
||||||
|
logger_exception(e)
|
||||||
|
|
||||||
|
super().close()
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>Dialog</class>
|
||||||
|
<widget class="QDialog" name="Dialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>205</width>
|
||||||
|
<height>42</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_spinner">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Monospace</family>
|
||||||
|
<pointsize>12</pointsize>
|
||||||
|
<weight>50</weight>
|
||||||
|
<bold>false</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Loading…
Reference in New Issue