Browse Source

Add activities window

Johann Schmitz 1 month ago
parent
commit
bc0e53c5d8
Signed by: Johann Schmitz <johann@j-schmitz.net> GPG Key ID: A084064277C501ED
2 changed files with 75 additions and 2 deletions
  1. 10
    1
      ptt/main.py
  2. 65
    1
      ptt/ui.py

+ 10
- 1
ptt/main.py View File

@@ -16,7 +16,7 @@ from tzlocal import get_localzone
16 16
 from ptt.remote import Remote
17 17
 from ptt.submit import SubmitWindow
18 18
 from ptt.timetracker import Timetracker
19
-from ptt.ui import DurationFormatDelegate, format_timedelta, ActivityEditItemDelegate
19
+from ptt.ui import DurationFormatDelegate, format_timedelta, ActivityEditItemDelegate, ActivitiesWindow
20 20
 
21 21
 logger = logging.getLogger(__name__)
22 22
 
@@ -273,11 +273,20 @@ class MainWindow(QWidget):
273 273
             btn._issue = issue
274 274
             fav_buttons.addWidget(btn)
275 275
 
276
+        fav_buttons.addStretch(1)
277
+        activities_button = QPushButton("Activities", self)
278
+        activities_button.clicked.connect(self.manage_activities)
279
+        fav_buttons.addWidget(activities_button)
280
+
276 281
         hbox = QHBoxLayout()
277 282
         hbox.addWidget(self.entry_table)
278 283
         hbox.addLayout(fav_buttons)
279 284
         return hbox
280 285
 
286
+    def manage_activities(self):
287
+        window = ActivitiesWindow(self)
288
+        window.show()
289
+
281 290
     def build_controls_layout(self):
282 291
         hbox = QHBoxLayout()
283 292
         

+ 65
- 1
ptt/ui.py View File

@@ -4,7 +4,8 @@ import datetime
4 4
 import logging
5 5
 
6 6
 from PyQt5.QtCore import Qt
7
-from PyQt5.QtWidgets import QStyledItemDelegate, QItemDelegate, QPlainTextEdit, QComboBox
7
+from PyQt5.QtSql import QSqlQueryModel
8
+from PyQt5.QtWidgets import QStyledItemDelegate, QItemDelegate, QPlainTextEdit, QComboBox, QDialog, QTableView, QVBoxLayout
8 9
 
9 10
 logger = logging.getLogger(__name__)
10 11
 
@@ -67,3 +68,66 @@ class MultilineEditDelegate(QItemDelegate):
67 68
     def createEditor(self, parent, option, index):
68 69
         logger.debug("createEditor: parent=%s, option=%s, index=%s", parent, option, index)
69 70
         return QPlainTextEdit(parent)
71
+
72
+
73
+class ActivitiesTableModel(QSqlQueryModel):
74
+    
75
+    query = """SELECT * FROM activities ORDER BY upstream_id DESC"""
76
+
77
+    def __init__(self, parent):
78
+        super(ActivitiesTableModel, self).__init__(parent)
79
+        self.setQuery(self.query)
80
+        self.setHeaderData(1, Qt.Horizontal, "Issue")
81
+        self.setHeaderData(2, Qt.Horizontal, "Description")
82
+    #
83
+    # def setData(self, index, value, role=Qt.EditRole):
84
+    #     if index.isValid() and 0 <= index.row() <= self.rowCount():
85
+    #         logger.info("UPDATE: index=%s, value=%s, role=%s", index, value, role)
86
+    #
87
+    #         q = QSqlQuery()
88
+    #         q.prepare("UPDATE submit_entries SET description=:desc WHERE id=:id")
89
+    #         q.bindValue(':desc', value)
90
+    #         q.bindValue(':id', self.record(index.row()).value('id'))
91
+    #         if q.exec_():
92
+    #             logger.debug("Updated entry")
93
+    #         else:
94
+    #             logger.error("Not updated: %s", q.lastError())
95
+    #
96
+    #         self.setQuery(self.query)
97
+    #
98
+    #         self.dataChanged.emit(index, index)
99
+    #
100
+    #         return True
101
+    #     return False
102
+
103
+class ActivitiesWindow(QDialog):
104
+    
105
+    def __init__(self, parent, *args, **kwargs):
106
+        super(ActivitiesWindow, self).__init__(parent=parent, *args, **kwargs)
107
+        
108
+        self.table = None
109
+        self.table_model = None
110
+        self.build_ui()
111
+    
112
+    def build_ui(self):
113
+        self.setMinimumSize(650, 350)
114
+        self.setWindowTitle("Activities")
115
+        self.setModal(True)
116
+        
117
+        self.table_model = ActivitiesTableModel(self)
118
+        
119
+        self.table = QTableView(self)
120
+        self.table.setModel(self.table_model)
121
+        self.table.verticalHeader().setVisible(False)
122
+        self.table.setColumnHidden(0, True)
123
+        self.table.setColumnWidth(1, 100)
124
+        self.table.setColumnWidth(2, 250)
125
+        self.table.setColumnWidth(3, 75)
126
+        self.table.horizontalHeader().setStretchLastSection(True)
127
+        self.table.setItemDelegateForColumn(3, DurationFormatDelegate(self))
128
+        self.table.setItemDelegateForColumn(4, MultilineEditDelegate(self))
129
+        
130
+        vbox = QVBoxLayout()
131
+        vbox.addWidget(self.table)
132
+        
133
+        self.setLayout(vbox)