Browse Source

Add activities window

master
Johann Schmitz 1 year ago
parent
commit
bc0e53c5d8
Signed by: ercpe <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
from ptt.remote import Remote
from ptt.submit import SubmitWindow
from ptt.timetracker import Timetracker
from ptt.ui import DurationFormatDelegate, format_timedelta, ActivityEditItemDelegate
from ptt.ui import DurationFormatDelegate, format_timedelta, ActivityEditItemDelegate, ActivitiesWindow

logger = logging.getLogger(__name__)

@@ -273,11 +273,20 @@ class MainWindow(QWidget):
btn._issue = issue
fav_buttons.addWidget(btn)

fav_buttons.addStretch(1)
activities_button = QPushButton("Activities", self)
activities_button.clicked.connect(self.manage_activities)
fav_buttons.addWidget(activities_button)

hbox = QHBoxLayout()
hbox.addWidget(self.entry_table)
hbox.addLayout(fav_buttons)
return hbox

def manage_activities(self):
window = ActivitiesWindow(self)
window.show()

def build_controls_layout(self):
hbox = QHBoxLayout()


+ 65
- 1
ptt/ui.py View File

@@ -4,7 +4,8 @@ import datetime
import logging

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QStyledItemDelegate, QItemDelegate, QPlainTextEdit, QComboBox
from PyQt5.QtSql import QSqlQueryModel
from PyQt5.QtWidgets import QStyledItemDelegate, QItemDelegate, QPlainTextEdit, QComboBox, QDialog, QTableView, QVBoxLayout

logger = logging.getLogger(__name__)

@@ -67,3 +68,66 @@ class MultilineEditDelegate(QItemDelegate):
def createEditor(self, parent, option, index):
logger.debug("createEditor: parent=%s, option=%s, index=%s", parent, option, index)
return QPlainTextEdit(parent)


class ActivitiesTableModel(QSqlQueryModel):
query = """SELECT * FROM activities ORDER BY upstream_id DESC"""

def __init__(self, parent):
super(ActivitiesTableModel, self).__init__(parent)
self.setQuery(self.query)
self.setHeaderData(1, Qt.Horizontal, "Issue")
self.setHeaderData(2, Qt.Horizontal, "Description")
#
# def setData(self, index, value, role=Qt.EditRole):
# if index.isValid() and 0 <= index.row() <= self.rowCount():
# logger.info("UPDATE: index=%s, value=%s, role=%s", index, value, role)
#
# q = QSqlQuery()
# q.prepare("UPDATE submit_entries SET description=:desc WHERE id=:id")
# q.bindValue(':desc', value)
# q.bindValue(':id', self.record(index.row()).value('id'))
# if q.exec_():
# logger.debug("Updated entry")
# else:
# logger.error("Not updated: %s", q.lastError())
#
# self.setQuery(self.query)
#
# self.dataChanged.emit(index, index)
#
# return True
# return False

class ActivitiesWindow(QDialog):
def __init__(self, parent, *args, **kwargs):
super(ActivitiesWindow, self).__init__(parent=parent, *args, **kwargs)
self.table = None
self.table_model = None
self.build_ui()
def build_ui(self):
self.setMinimumSize(650, 350)
self.setWindowTitle("Activities")
self.setModal(True)
self.table_model = ActivitiesTableModel(self)
self.table = QTableView(self)
self.table.setModel(self.table_model)
self.table.verticalHeader().setVisible(False)
self.table.setColumnHidden(0, True)
self.table.setColumnWidth(1, 100)
self.table.setColumnWidth(2, 250)
self.table.setColumnWidth(3, 75)
self.table.horizontalHeader().setStretchLastSection(True)
self.table.setItemDelegateForColumn(3, DurationFormatDelegate(self))
self.table.setItemDelegateForColumn(4, MultilineEditDelegate(self))
vbox = QVBoxLayout()
vbox.addWidget(self.table)
self.setLayout(vbox)

Loading…
Cancel
Save