Speedtest with gui using pyside6 , python and lib speedtest

preview_player
Показать описание
Speedtest with gui using pyside6 , python , the lib speedtest and with help from chatgpt for the thread ( I am new to Pyside6/PyQT) . It is different from threading with tkinter :)
Рекомендации по теме
Комментарии
Автор

gui part 2 : = QBrush(QColor(44, 44, 44, 89))

#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
QPalette.PlaceholderText, brush10)
#endif
= QBrush(QColor(63, 63, 63, 179))

QPalette.Accent, brush11)

= QIcon()
QSize(), QIcon.Mode.Normal, QIcon.State.Off)

= QWidget(MainWindow)

=


284, 201, 46))
= QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)




= QFont()




{\n"
" color: #333;\n"
" border: 2px solid #555;\n"
" border-radius: 20px; /* Ajustez cette valeur pour arrondir davantage */\n"
" background: qradialgradient(\n"
" cx: 0.3, cy: -0.4, fx: 0.3, fy: -0.4, \n"
" radius: 1.5, stop: 0 stop: 1
" );\n"
" padding: 10px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background: qradialgradient(\n"
" cx: 0.3, cy: -0.4, fx: 0.3, fy: -0.4, \n"
" radius: 1.5, stop: 0 stop: 1
" );\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" border-style: inset;\n"
" background: qradialgradient(\n"
" cx: 0.4, cy: -0.1, fx: 0.4, fy: -0.1, \n"
" radius: 1.5, stop: 0 stop: 1
" );\n"
"}\n"
"")



= QWidget(self.centralwidget)

1, 781, 281))
= QVBoxLayout(self.widget)

0, 0, 0)
= QLabel(self.widget)

= QFont()







= QTextEdit(self.widget)

= QFont()










~~~~# setupUi
~~~~def retranslateUi(self, MainWindow):
u" Internet SpeedTest ( Fabrice Fontaine )", None))
u" Speed Test", None))
u"Result :", None))
~~~~# retranslateUi

pajfab
Автор

gui part 1: # -*- coding: utf-8 -*-

## Form generated from reading UI file
##
## Created by: Qt User Interface Compiler version 6.8.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
~~~~QMetaObject, QObject, QPoint, QRect,
~~~~QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
~~~~QFont, QFontDatabase, QGradient, QIcon,
~~~~QImage, QKeySequence, QLinearGradient, QPainter,
~~~~QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QLabel, QMainWindow, QPushButton,
~~~~QSizePolicy, QTextEdit, QVBoxLayout, QWidget)
class Ui_MainWindow(object):
~~~~def setupUi(self, MainWindow):
not MainWindow.objectName():

336)
= QSizePolicy(QSizePolicy.Policy.Preferred,




336))
336))
= QPalette()
= QBrush(QColor(255, 255, 255, 255))

QPalette.WindowText, brush)
= QBrush(QColor(89, 89, 89, 179))

QPalette.Button, brush1)
= QBrush(QColor(133, 133, 133, 179))

QPalette.Light, brush2)
= QBrush(QColor(111, 111, 111, 179))

QPalette.Midlight, brush3)
= QBrush(QColor(44, 44, 44, 179))

QPalette.Dark, brush4)
= QBrush(QColor(59, 59, 59, 179))

QPalette.Mid, brush5)
QPalette.Text, brush)
QPalette.BrightText, brush)
QPalette.ButtonText, brush)
= QBrush(QColor(0, 0, 0, 255))

QPalette.Base, brush6)
QPalette.Window, brush1)
QPalette.Shadow, brush6)
= QBrush(QColor(44, 44, 44, 217))

QPalette.AlternateBase, brush7)
= QBrush(QColor(255, 255, 220, 255))

QPalette.ToolTipBase, brush8)
QPalette.ToolTipText, brush6)
= QBrush(QColor(255, 255, 255, 127))

#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
QPalette.PlaceholderText, brush9)
#endif
QPalette.Accent, brush6)
QPalette.WindowText, brush)
QPalette.Button, brush1)
QPalette.Light, brush2)
QPalette.Midlight, brush3)
QPalette.Dark, brush4)
QPalette.Mid, brush5)
QPalette.Text, brush)
QPalette.BrightText, brush)
QPalette.ButtonText, brush)
QPalette.Base, brush6)
QPalette.Window, brush1)
QPalette.Shadow, brush6)
QPalette.AlternateBase, brush7)
QPalette.ToolTipBase, brush8)
QPalette.ToolTipText, brush6)
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
QPalette.PlaceholderText, brush9)
#endif
QPalette.Accent, brush6)
QPalette.WindowText, brush4)
QPalette.Button, brush1)
QPalette.Light, brush2)
QPalette.Midlight, brush3)
QPalette.Dark, brush4)
QPalette.Mid, brush5)
QPalette.Text, brush4)
QPalette.BrightText, brush)
QPalette.ButtonText, brush4)
QPalette.Base, brush1)
QPalette.Window, brush1)
QPalette.Shadow, brush6)
QPalette.AlternateBase, brush1)
QPalette.ToolTipBase, brush8)
QPalette.ToolTipText, brush6)

pajfab
Автор

logic : import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtCore import QThread, Signal, Slot
from internet_speedtest_GUI import Ui_MainWindow
import speedtest as st


class SpeedTestWorker(QThread):
~~~~# Déclarez des signaux pour renvoyer les résultats
~~~~results_ready = Signal(str, str, str)

~~~~def run(self):

= st.Speedtest()
= test.download()
= round(down_speed / 10**6, 2)
= f" Download Speed in Mbps: {down_speed}"

= test.upload()
= round(up_speed / 10**6, 2)
= f" Upload Speed in Mbps: {up_speed}"

= test.results.ping
= f" Ping in ms: {ping}"

Emettez les résultats
line_up, line_ping)
Exception as e:
En cas d'erreur, émettez les messages d'erreur
during speed test", "", str(e))


class MainApp(QMainWindow):
~~~~def __init__(self):

= Ui_MainWindow()


Connecter le bouton "speedtest" à une méthode


Préparer les attributs
= None

~~~~def fn_speedtest(self):
Désactivez le bouton pour éviter d'autres clics


Effacez l'UI et affichez un message de progression

")
Working, please wait...")

Créez et configurez le thread pour SpeedTest
= SpeedTestWorker()


Démarrez le thread


~~~~def handle_speedtest_results(self, line_down, line_up, line_ping):
Réactivez le bouton après la fin du test


Affichez les résultats dans l'interface utilisateur

")
line_down:

line_up:

line_ping:



if __name__ == "__main__":
~~~~app = QApplication(sys.argv)
~~~~main_window = MainApp()
~~~~main_window.show()
~~~~sys.exit(app.exec())

pajfab
welcome to shbcf.ru