fime/task_edit.py

67 lines
2.1 KiB
Python
Raw Normal View History

2020-02-19 22:12:56 +00:00
from PySide2 import QtCore, QtGui, QtWidgets
class TaskEdit(QtWidgets.QDialog):
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.setWindowTitle("Edit Tasks")
self.list = QtCore.QStringListModel()
self.tableView = QtWidgets.QTableView()
self.tableView.setModel(self.list)
2021-11-17 02:48:39 +00:00
self.tableView.horizontalHeader().setStretchLastSection(True)
2020-02-19 22:12:56 +00:00
self.tableView.horizontalHeader().hide()
self.tableView.verticalHeader().hide()
new_button = QtWidgets.QPushButton()
new_button.setText("New item")
new_button.setIcon(QtGui.QIcon.fromTheme("list-add"))
new_button.pressed.connect(self.new_task)
2021-11-16 22:55:58 +00:00
new_button.setAutoDefault(False)
2020-02-19 22:12:56 +00:00
del_button = QtWidgets.QPushButton()
del_button.setText("Delete item")
del_button.setIcon(QtGui.QIcon.fromTheme("list-remove"))
del_button.pressed.connect(self.del_task)
2021-11-16 22:55:58 +00:00
del_button.setAutoDefault(False)
2020-02-19 22:12:56 +00:00
ok_button = QtWidgets.QPushButton()
ok_button.setText("OK")
2021-11-17 02:12:22 +00:00
ok_button.setIcon(QtGui.QIcon.fromTheme("dialog-ok"))
2020-02-19 22:12:56 +00:00
ok_button.pressed.connect(self.accept)
2021-11-16 22:55:58 +00:00
ok_button.setAutoDefault(True)
2020-02-19 22:12:56 +00:00
blayout = QtWidgets.QHBoxLayout()
blayout.addWidget(new_button)
blayout.addWidget(del_button)
blayout.addWidget(ok_button)
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.tableView)
layout.addLayout(blayout)
self.setLayout(layout)
@QtCore.Slot()
def new_task(self):
l = self.list.stringList()
l.append("")
self.list.setStringList(l)
i = self.list.index(len(l)-1)
self.tableView.setCurrentIndex(i)
self.tableView.edit(i)
@QtCore.Slot()
def del_task(self):
l = self.list.stringList()
del l[self.tableView.currentIndex().row()]
self.list.setStringList(l)
@property
def tasks(self):
ret = self.list.stringList()
return list(filter(None, ret)) # filter empty strings
@tasks.setter
def tasks(self, tasks):
self.list.setStringList(tasks)