from PyQt5 import QtWidgets
from ui.qt.dlg_tag_editor_ui import Ui_DlgTagEditor


class DlgTagEditor(QtWidgets.QDialog):
    def __init__(self, track=None, parent=None):
        super().__init__(parent)
        self.createWidgets(track)

    def createWidgets(self, track=None):
        self.ui = Ui_DlgTagEditor()
        self.ui.setupUi(self)
        self.ui.tagsTable.populate(track)

        self.ui.btnOk.clicked.connect(self.ok)
        self.ui.btnCancel.clicked.connect(self.cancel)

    @classmethod
    def select(cls, parent, track=None):
        dlg = cls(parent, track)
        r = dlg.exec_()
        if r:
            return dlg.selected_tags()
        else:
            return None

    def ok(self):
        self.done(1)

    def cancel(self):
        self.done(0)

    def selected_tags(self):
        return []
