mirror of
https://github.com/LorenEteval/Furious.git
synced 2026-10-13 17:58:19 +03:00
Refactor package architecture
Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
# Copyright (C) 2024–present Loren Eteval & contributors <loren.eteval@proton.me>
|
||||
#
|
||||
# This file is part of Furious.
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
"""Provide widgets for GUI customize network test."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from Furious.Frozenlib import *
|
||||
from Furious.Qt import *
|
||||
from Furious.Qt import gettext as _
|
||||
|
||||
from PySide6 import QtCore
|
||||
from PySide6.QtWidgets import *
|
||||
|
||||
import logging
|
||||
import functools
|
||||
|
||||
__all__ = ['NetworkTestDialog']
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
registerAppSettings('CustomNetworkSpeedTestURL')
|
||||
registerAppSettings('CustomNetworkConnectivityTestURL')
|
||||
|
||||
|
||||
class NetworkTestDialog(AppQDialog):
|
||||
"""Present the GUI customize network test dialog."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Initialize the network test settings dialog."""
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.setWindowTitle(_('Customize Network Test URL'))
|
||||
self.setWindowModality(QtCore.Qt.WindowModality.WindowModal)
|
||||
|
||||
self.speedTestURLText = AppQLabel(_('Enter network speed test URL:'))
|
||||
self.speedTestURLEdit = QLineEdit()
|
||||
|
||||
speedTestURLSettings = AppSettings.get('CustomNetworkSpeedTestURL')
|
||||
|
||||
if isinstance(speedTestURLSettings, str):
|
||||
self.speedTestURLEdit.setText(speedTestURLSettings)
|
||||
else:
|
||||
self.speedTestURLEdit.setText(NETWORK_SPEED_TEST_URL)
|
||||
|
||||
self.connectivityText = AppQLabel(_('Enter network connectivity test URL:'))
|
||||
self.connectivityEdit = QLineEdit()
|
||||
|
||||
connectivitySettings = AppSettings.get('CustomNetworkConnectivityTestURL')
|
||||
|
||||
if isinstance(connectivitySettings, str):
|
||||
self.connectivityEdit.setText(connectivitySettings)
|
||||
else:
|
||||
self.connectivityEdit.setText(NETWORK_CONNECTIVITY_TEST_URL)
|
||||
|
||||
self.dialogBtns = AppQDialogButtonBox(QtCore.Qt.Orientation.Horizontal)
|
||||
self.dialogBtns.addButton(_('OK'), AppQDialogButtonBox.ButtonRole.AcceptRole)
|
||||
self.dialogBtns.addButton(
|
||||
_('Cancel'), AppQDialogButtonBox.ButtonRole.RejectRole
|
||||
)
|
||||
self.dialogBtns.accepted.connect(self.accept)
|
||||
self.dialogBtns.rejected.connect(self.reject)
|
||||
|
||||
self.speedTestURLResetBtn = AppQPushButton(_('Reset'))
|
||||
self.speedTestURLResetBtn.clicked.connect(
|
||||
lambda: self.speedTestURLEdit.setText(NETWORK_SPEED_TEST_URL)
|
||||
)
|
||||
self.connectivityResetBtn = AppQPushButton(_('Reset'))
|
||||
self.connectivityResetBtn.clicked.connect(
|
||||
lambda: self.connectivityEdit.setText(NETWORK_CONNECTIVITY_TEST_URL)
|
||||
)
|
||||
|
||||
self.speedTestURLHboxLayout = QHBoxLayout()
|
||||
self.speedTestURLHboxLayout.addWidget(self.speedTestURLEdit)
|
||||
self.speedTestURLHboxLayout.addWidget(self.speedTestURLResetBtn)
|
||||
|
||||
self.connectivityHboxLayout = QHBoxLayout()
|
||||
self.connectivityHboxLayout.addWidget(self.connectivityEdit)
|
||||
self.connectivityHboxLayout.addWidget(self.connectivityResetBtn)
|
||||
|
||||
layout = QFormLayout()
|
||||
layout.addRow(self.speedTestURLText)
|
||||
layout.addRow(self.speedTestURLHboxLayout)
|
||||
layout.addRow(self.connectivityText)
|
||||
layout.addRow(self.connectivityHboxLayout)
|
||||
layout.addRow(self.dialogBtns)
|
||||
layout.setFormAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
self.setLayout(layout)
|
||||
|
||||
self.finished.connect(functools.partial(self.handleResultCode))
|
||||
|
||||
def setWidthAndHeight(self):
|
||||
"""Apply the default size for the GUI customize network test dialog."""
|
||||
self.resize(656, 180)
|
||||
|
||||
def handleResultCode(self, code):
|
||||
"""Handle result code."""
|
||||
for widget, info, settingsName, reset in [
|
||||
(
|
||||
self.speedTestURLEdit,
|
||||
'speed test URL',
|
||||
'CustomNetworkSpeedTestURL',
|
||||
NETWORK_SPEED_TEST_URL,
|
||||
),
|
||||
(
|
||||
self.connectivityEdit,
|
||||
'connectivity test URL',
|
||||
'CustomNetworkConnectivityTestURL',
|
||||
NETWORK_CONNECTIVITY_TEST_URL,
|
||||
),
|
||||
]:
|
||||
if code == PySide6Legacy.enumValueWrapper(AppQDialog.DialogCode.Accepted):
|
||||
value = widget.text()
|
||||
|
||||
logger.info(f'setting {info} to \'{value}\'')
|
||||
|
||||
AppSettings.set(settingsName, value)
|
||||
else:
|
||||
try:
|
||||
settings = AppSettings.get(settingsName)
|
||||
|
||||
if isinstance(settings, str):
|
||||
widget.setText(settings)
|
||||
else:
|
||||
widget.setText(reset)
|
||||
except Exception as ex:
|
||||
# Any non-exit exceptions
|
||||
|
||||
logger.error(f'error restoring {info}: {ex}')
|
||||
Reference in New Issue
Block a user