From 3ad57d995b8a4088c5b7788fbb44a1ced81c33b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20Mu=C3=B1oz=20Fernandez?= Date: Thu, 26 Nov 2020 22:55:53 +0100 Subject: [PATCH] feat: added timestamp to information widget log items --- game/infos/information.py | 10 ++++++++-- qt_ui/windows/infos/QInfoItem.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/game/infos/information.py b/game/infos/information.py index 4fd12d2f..35e94f92 100644 --- a/game/infos/information.py +++ b/game/infos/information.py @@ -1,3 +1,4 @@ +import datetime class Information(): @@ -5,7 +6,12 @@ class Information(): self.title = title self.text = text self.turn = turn + self.timestamp = datetime.datetime.now() def __str__(self): - s = "[" + str(self.turn) + "] " + self.title + "\n" + self.text - return s \ No newline at end of file + return '[{}][{}] {} {}'.format( + self.timestamp.strftime("%Y-%m-%d %H:%M:%S") if self.timestamp is not None else '', + self.turn, + self.title, + self.text + ) \ No newline at end of file diff --git a/qt_ui/windows/infos/QInfoItem.py b/qt_ui/windows/infos/QInfoItem.py index be5cf333..f8d63bf2 100644 --- a/qt_ui/windows/infos/QInfoItem.py +++ b/qt_ui/windows/infos/QInfoItem.py @@ -8,5 +8,5 @@ class QInfoItem(QStandardItem): def __init__(self, info: Information): super(QInfoItem, self).__init__() self.info = info - self.setText("[%02d]" % self.info.turn + " " + self.info.title + ' : {:<16}'.format(info.text)) + self.setText(str(info)) self.setEditable(False)