Browse Source

Show localized time in tooltip

Johann Schmitz 6 months ago
parent
commit
602219834b
Signed by: Johann Schmitz <johann@j-schmitz.net> GPG Key ID: A084064277C501ED
4 changed files with 12 additions and 2 deletions
  1. 7
    1
      ptt/main.py
  2. 1
    1
      ptt/timetracker.py
  3. 3
    0
      ptt/ui.py
  4. 1
    0
      requirements.txt

+ 7
- 1
ptt/main.py View File

@@ -4,12 +4,14 @@ import logging
4 4
 import os
5 5
 from configparser import ConfigParser
6 6
 
7
+import pytz
7 8
 from PyQt5 import QtSql
8 9
 from PyQt5.QtCore import Qt, QEvent, QBasicTimer, QVariant
9 10
 from PyQt5.QtGui import QColor
10 11
 from PyQt5.QtSql import QSqlDatabase, QSqlTableModel, QSqlQuery
11 12
 from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QLineEdit, QVBoxLayout, QPushButton, \
12 13
     QTableView, QCompleter, QMessageBox, QApplication, QSystemTrayIcon, QStyle
14
+from tzlocal import get_localzone
13 15
 
14 16
 from ptt.remote import Remote
15 17
 from ptt.submit import SubmitWindow
@@ -297,8 +299,12 @@ class MainWindow(QWidget):
297 299
                 self.current_entry.setEnabled(False)
298 300
                 self.timer_label.setText('0:00:00')
299 301
                 self.duration_timer.start(1000, self)
302
+
303
+                start = self.timetracker.start_time.replace(tzinfo=pytz.utc)
304
+                start = start.astimezone(get_localzone())
305
+                
300 306
                 self.tray_icon.setToolTip("%s since %s" % (self.current_entry.text(),
301
-                                                           self.timetracker.start_time.strftime("%X")))
307
+                                                           start.strftime("%X")))
302 308
                 self.tray_icon.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
303 309
 
304 310
         self.tte_model.refresh()

+ 1
- 1
ptt/timetracker.py View File

@@ -18,7 +18,7 @@ class Timetracker(object):
18 18
     @property
19 19
     def start_time(self):
20 20
         return self._current_activity_start
21
-
21
+    
22 22
     def start(self, activity):
23 23
         logger.debug("Start tracking: %s", activity)
24 24
 

+ 3
- 0
ptt/ui.py View File

@@ -22,6 +22,9 @@ class DurationFormatDelegate(QStyledItemDelegate):
22 22
 
23 23
     def displayText(self, value, locale):
24 24
 
25
+        if not value:
26
+            return ''
27
+        
25 28
         if isinstance(value, int):
26 29
             seconds = value
27 30
         else:

+ 1
- 0
requirements.txt View File

@@ -4,3 +4,4 @@ sqlalchemy[sqlite]
4 4
 jira
5 5
 keyring
6 6
 pytz
7
+tzlocal