remove python-dateutil dependency in favor of QDateTime
This commit is contained in:
@@ -1,20 +1,13 @@
|
||||
import datetime
|
||||
from dateutil.parser import isoparse
|
||||
import logging
|
||||
|
||||
import requests
|
||||
|
||||
from PyQt6 import QtCore
|
||||
|
||||
|
||||
logger = logging.getLogger("gotify-tray")
|
||||
|
||||
|
||||
try:
|
||||
local_timezone = datetime.datetime.utcnow().astimezone().tzinfo
|
||||
except Exception as e:
|
||||
logger.error(f"gotify.models.local_timezone error: {e}")
|
||||
local_timezone = None
|
||||
|
||||
|
||||
class AttributeDict(dict):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(AttributeDict, self).__init__(*args, **kwargs)
|
||||
@@ -39,7 +32,7 @@ class GotifyPagingModel(AttributeDict):
|
||||
|
||||
class GotifyMessageModel(AttributeDict):
|
||||
appid: int
|
||||
date: datetime.datetime
|
||||
date: QtCore.QDateTime
|
||||
extras: dict | None = None
|
||||
id: int
|
||||
message: str
|
||||
@@ -48,7 +41,7 @@ class GotifyMessageModel(AttributeDict):
|
||||
|
||||
def __init__(self, d: dict, *args, **kwargs):
|
||||
d.update(
|
||||
{"date": isoparse(d["date"]).astimezone(local_timezone)}
|
||||
{"date": QtCore.QDateTime.fromString(d["date"], format=QtCore.Qt.DateFormat.ISODate).toLocalTime()}
|
||||
)
|
||||
super(GotifyMessageModel, self).__init__(d, *args, **kwargs)
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import getpass
|
||||
import locale
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
@@ -407,8 +406,6 @@ def start_gui():
|
||||
|
||||
init_logger(logger)
|
||||
|
||||
locale.setlocale(locale.LC_TIME, "")
|
||||
|
||||
# prevent multiple instances
|
||||
if (app.acquire_lock() or "--no-lock" in sys.argv) and verify_server():
|
||||
app.init_ui()
|
||||
|
||||
@@ -38,7 +38,12 @@ class MessageWidget(QtWidgets.QWidget, Ui_Form):
|
||||
|
||||
# Display message contents
|
||||
self.label_title.setText(message.title)
|
||||
self.label_date.setText(message.date.strftime("%x, %X" if settings.value("locale", type=bool) else "%Y-%m-%d, %H:%M"))
|
||||
|
||||
if settings.value("locale", type=bool):
|
||||
date_str = QtCore.QLocale.system().toString(message.date, QtCore.QLocale.FormatType.ShortFormat)
|
||||
else:
|
||||
date_str = message.date.toString("yyyy-MM-dd, hh:mm")
|
||||
self.label_date.setText(date_str)
|
||||
|
||||
if message.get("extras", {}).get("client::display", {}).get("contentType") == "text/markdown":
|
||||
self.label_message.setTextFormat(QtCore.Qt.TextFormat.MarkdownText)
|
||||
|
||||
Reference in New Issue
Block a user