display server version in ServerinfoDialog
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
from gotify_tray.gotify.models import GotifyVersionModel
|
||||||
|
from gotify_tray.tasks import VerifyServerInfoTask
|
||||||
from PyQt6 import QtWidgets
|
from PyQt6 import QtWidgets
|
||||||
|
|
||||||
from gotify_tray.tasks import VerifyServerInfoTask
|
|
||||||
from .designs.widget_server import Ui_Dialog
|
from .designs.widget_server import Ui_Dialog
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +12,9 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
self.setWindowTitle("Server info")
|
self.setWindowTitle("Server info")
|
||||||
self.line_url.setText(url)
|
self.line_url.setText(url)
|
||||||
self.line_token.setText(token)
|
self.line_token.setText(token)
|
||||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True)
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(
|
||||||
|
True
|
||||||
|
)
|
||||||
self.link_callbacks()
|
self.link_callbacks()
|
||||||
|
|
||||||
def test_server_info(self):
|
def test_server_info(self):
|
||||||
@@ -25,7 +28,9 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.pb_test.setDisabled(True)
|
self.pb_test.setDisabled(True)
|
||||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True)
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(
|
||||||
|
True
|
||||||
|
)
|
||||||
|
|
||||||
self.task = VerifyServerInfoTask(url, client_token)
|
self.task = VerifyServerInfoTask(url, client_token)
|
||||||
self.task.success.connect(self.server_info_success)
|
self.task.success.connect(self.server_info_success)
|
||||||
@@ -33,22 +38,35 @@ class ServerInfoDialog(QtWidgets.QDialog, Ui_Dialog):
|
|||||||
self.task.incorrect_url.connect(self.incorrect_url_callback)
|
self.task.incorrect_url.connect(self.incorrect_url_callback)
|
||||||
self.task.start()
|
self.task.start()
|
||||||
|
|
||||||
def server_info_success(self):
|
def server_info_success(self, version: GotifyVersionModel):
|
||||||
self.pb_test.setEnabled(True)
|
self.pb_test.setEnabled(True)
|
||||||
|
self.label_server_info.setText(f"Version: {version.version}")
|
||||||
self.pb_test.setStyleSheet("background-color: rgba(0, 255, 0, 100);")
|
self.pb_test.setStyleSheet("background-color: rgba(0, 255, 0, 100);")
|
||||||
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(True)
|
self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setEnabled(
|
||||||
|
True
|
||||||
|
)
|
||||||
|
|
||||||
def incorrect_token_callback(self):
|
def incorrect_token_callback(self, version: GotifyVersionModel):
|
||||||
self.pb_test.setEnabled(True)
|
self.pb_test.setEnabled(True)
|
||||||
|
self.label_server_info.setText(f"Version: {version.version}")
|
||||||
self.pb_test.setStyleSheet("background-color: rgba(255, 0, 0, 100);")
|
self.pb_test.setStyleSheet("background-color: rgba(255, 0, 0, 100);")
|
||||||
self.line_token.setStyleSheet("border: 1px solid red;")
|
self.line_token.setStyleSheet("border: 1px solid red;")
|
||||||
|
|
||||||
def incorrect_url_callback(self):
|
def incorrect_url_callback(self):
|
||||||
self.pb_test.setEnabled(True)
|
self.pb_test.setEnabled(True)
|
||||||
|
self.label_server_info.clear()
|
||||||
self.pb_test.setStyleSheet("background-color: rgba(255, 0, 0, 100);")
|
self.pb_test.setStyleSheet("background-color: rgba(255, 0, 0, 100);")
|
||||||
self.line_url.setStyleSheet("border: 1px solid red;")
|
self.line_url.setStyleSheet("border: 1px solid red;")
|
||||||
|
|
||||||
def link_callbacks(self):
|
def link_callbacks(self):
|
||||||
self.pb_test.clicked.connect(self.test_server_info)
|
self.pb_test.clicked.connect(self.test_server_info)
|
||||||
self.line_url.textChanged.connect(lambda: self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True))
|
self.line_url.textChanged.connect(
|
||||||
self.line_token.textChanged.connect(lambda: self.buttonBox.button(QtWidgets.QDialogButtonBox.StandardButton.Ok).setDisabled(True))
|
lambda: self.buttonBox.button(
|
||||||
|
QtWidgets.QDialogButtonBox.StandardButton.Ok
|
||||||
|
).setDisabled(True)
|
||||||
|
)
|
||||||
|
self.line_token.textChanged.connect(
|
||||||
|
lambda: self.buttonBox.button(
|
||||||
|
QtWidgets.QDialogButtonBox.StandardButton.Ok
|
||||||
|
).setDisabled(True)
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Form implementation generated from reading ui file 'gotify_tray/gui/designs\widget_server.ui'
|
# Form implementation generated from reading ui file 'gotify_tray/gui/designs\widget_server.ui'
|
||||||
#
|
#
|
||||||
# Created by: PyQt6 UI code generator 6.1.1
|
# Created by: PyQt6 UI code generator 6.2.1
|
||||||
#
|
#
|
||||||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||||
# run again. Do not edit this file unless you know what you are doing.
|
# run again. Do not edit this file unless you know what you are doing.
|
||||||
@@ -12,9 +12,16 @@ from PyQt6 import QtCore, QtGui, QtWidgets
|
|||||||
class Ui_Dialog(object):
|
class Ui_Dialog(object):
|
||||||
def setupUi(self, Dialog):
|
def setupUi(self, Dialog):
|
||||||
Dialog.setObjectName("Dialog")
|
Dialog.setObjectName("Dialog")
|
||||||
Dialog.resize(300, 124)
|
Dialog.resize(300, 130)
|
||||||
self.gridLayout = QtWidgets.QGridLayout(Dialog)
|
self.gridLayout = QtWidgets.QGridLayout(Dialog)
|
||||||
self.gridLayout.setObjectName("gridLayout")
|
self.gridLayout.setObjectName("gridLayout")
|
||||||
|
self.label_server_info = QtWidgets.QLabel(Dialog)
|
||||||
|
self.label_server_info.setText("")
|
||||||
|
self.label_server_info.setObjectName("label_server_info")
|
||||||
|
self.gridLayout.addWidget(self.label_server_info, 1, 2, 1, 1)
|
||||||
|
self.pb_test = QtWidgets.QPushButton(Dialog)
|
||||||
|
self.pb_test.setObjectName("pb_test")
|
||||||
|
self.gridLayout.addWidget(self.pb_test, 1, 4, 1, 1)
|
||||||
self.formLayout = QtWidgets.QFormLayout()
|
self.formLayout = QtWidgets.QFormLayout()
|
||||||
self.formLayout.setObjectName("formLayout")
|
self.formLayout.setObjectName("formLayout")
|
||||||
self.label = QtWidgets.QLabel(Dialog)
|
self.label = QtWidgets.QLabel(Dialog)
|
||||||
@@ -29,29 +36,26 @@ class Ui_Dialog(object):
|
|||||||
self.line_token = QtWidgets.QLineEdit(Dialog)
|
self.line_token = QtWidgets.QLineEdit(Dialog)
|
||||||
self.line_token.setObjectName("line_token")
|
self.line_token.setObjectName("line_token")
|
||||||
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.line_token)
|
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.line_token)
|
||||||
self.gridLayout.addLayout(self.formLayout, 0, 0, 1, 2)
|
self.gridLayout.addLayout(self.formLayout, 0, 1, 1, 4)
|
||||||
self.pb_test = QtWidgets.QPushButton(Dialog)
|
|
||||||
self.pb_test.setObjectName("pb_test")
|
|
||||||
self.gridLayout.addWidget(self.pb_test, 1, 1, 1, 1)
|
|
||||||
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
|
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
|
||||||
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
|
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
|
||||||
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
|
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
|
||||||
self.buttonBox.setObjectName("buttonBox")
|
self.buttonBox.setObjectName("buttonBox")
|
||||||
self.gridLayout.addWidget(self.buttonBox, 2, 1, 1, 1)
|
self.gridLayout.addWidget(self.buttonBox, 2, 4, 1, 1)
|
||||||
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
|
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
|
||||||
self.gridLayout.addItem(spacerItem, 1, 0, 1, 1)
|
self.gridLayout.addItem(spacerItem, 1, 3, 1, 1)
|
||||||
|
|
||||||
self.retranslateUi(Dialog)
|
self.retranslateUi(Dialog)
|
||||||
self.buttonBox.accepted.connect(Dialog.accept)
|
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
|
||||||
self.buttonBox.rejected.connect(Dialog.reject)
|
self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
|
||||||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||||
|
|
||||||
def retranslateUi(self, Dialog):
|
def retranslateUi(self, Dialog):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
|
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
|
||||||
|
self.pb_test.setText(_translate("Dialog", "Test"))
|
||||||
self.label.setText(_translate("Dialog", "Server url:"))
|
self.label.setText(_translate("Dialog", "Server url:"))
|
||||||
self.label_2.setText(_translate("Dialog", "Client token:"))
|
self.label_2.setText(_translate("Dialog", "Client token:"))
|
||||||
self.pb_test.setText(_translate("Dialog", "Test"))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -7,14 +7,21 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>300</width>
|
<width>300</width>
|
||||||
<height>124</height>
|
<height>130</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="1" column="4">
|
||||||
|
<widget class="QPushButton" name="pb_test">
|
||||||
|
<property name="text">
|
||||||
|
<string>Test</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" colspan="4">
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
@@ -38,14 +45,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="2" column="4">
|
||||||
<widget class="QPushButton" name="pb_test">
|
|
||||||
<property name="text">
|
|
||||||
<string>Test</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="3">
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
@@ -68,6 +68,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="1" colspan="2">
|
||||||
|
<widget class="QLabel" name="label_server_info">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import logging
|
|||||||
from PyQt6 import QtCore
|
from PyQt6 import QtCore
|
||||||
from PyQt6.QtCore import pyqtSignal
|
from PyQt6.QtCore import pyqtSignal
|
||||||
|
|
||||||
|
from gotify_tray.gotify.models import GotifyVersionModel
|
||||||
|
|
||||||
from . import gotify
|
from . import gotify
|
||||||
|
|
||||||
|
|
||||||
@@ -120,8 +122,8 @@ class GetMessagesTask(BaseTask):
|
|||||||
|
|
||||||
|
|
||||||
class VerifyServerInfoTask(BaseTask):
|
class VerifyServerInfoTask(BaseTask):
|
||||||
success = pyqtSignal()
|
success = pyqtSignal(GotifyVersionModel)
|
||||||
incorrect_token = pyqtSignal()
|
incorrect_token = pyqtSignal(GotifyVersionModel)
|
||||||
incorrect_url = pyqtSignal()
|
incorrect_url = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, url: str, client_token: str):
|
def __init__(self, url: str, client_token: str):
|
||||||
@@ -132,16 +134,22 @@ class VerifyServerInfoTask(BaseTask):
|
|||||||
def task(self):
|
def task(self):
|
||||||
try:
|
try:
|
||||||
gotify_client = gotify.GotifyClient(self.url, self.client_token)
|
gotify_client = gotify.GotifyClient(self.url, self.client_token)
|
||||||
|
|
||||||
|
version = gotify_client.version()
|
||||||
|
if isinstance(version, gotify.GotifyErrorModel):
|
||||||
|
self.incorrect_url.emit()
|
||||||
|
return
|
||||||
|
|
||||||
result = gotify_client.get_messages(limit=1)
|
result = gotify_client.get_messages(limit=1)
|
||||||
|
|
||||||
if isinstance(result, gotify.GotifyPagedMessagesModel):
|
if isinstance(result, gotify.GotifyPagedMessagesModel):
|
||||||
self.success.emit()
|
self.success.emit(version)
|
||||||
return
|
return
|
||||||
elif (
|
elif (
|
||||||
isinstance(result, gotify.GotifyErrorModel)
|
isinstance(result, gotify.GotifyErrorModel)
|
||||||
and result["error"] == "Unauthorized"
|
and result["error"] == "Unauthorized"
|
||||||
):
|
):
|
||||||
self.incorrect_token.emit()
|
self.incorrect_token.emit(version)
|
||||||
return
|
return
|
||||||
self.incorrect_url.emit()
|
self.incorrect_url.emit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user