dlg_tag.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from PyQt5.QtWidgets import QDialog
  2. from core.models import Tag
  3. from core.repositories import TagRepository
  4. from ui.qt.dlg_tag_ui import Ui_dlgTag
  5. class DlgTag(QDialog):
  6. def __init__(self, tag, parent=None):
  7. super().__init__(parent)
  8. self.tag = tag
  9. self.createWidgets()
  10. def createWidgets(self):
  11. self.ui = Ui_dlgTag()
  12. self.ui.setupUi(self)
  13. if self.tag.label:
  14. self.ui.lineTagLabel.setText(self.tag.label)
  15. self.ui.btnSave.clicked.connect(self.save)
  16. self.ui.btnCancel.clicked.connect(self.cancel)
  17. @classmethod
  18. def edit(cls, tag=None, parent=None):
  19. if tag is None:
  20. tag = Tag()
  21. dlg = cls(tag, parent)
  22. r = dlg.exec_()
  23. return r
  24. def ok(self):
  25. new_label = self.ui.lineTagLabel.text()
  26. if not new_label:
  27. return
  28. tag_repo = TagRepository()
  29. self.tag = new_label
  30. tag_repo.commit()
  31. self.done(1)
  32. def cancel(self):
  33. self.done(0)