Commit b99cfb70 authored by Tom Pillot's avatar Tom Pillot
Browse files

Check if the team name and tag are valid

parent 50e3f103
......@@ -11,7 +11,7 @@ class AlignDelegate(qtw.QStyledItemDelegate):
option.displayAlignment = qtc.Qt.AlignCenter
class MainWindow(qtw.QWidget):
class MainWindow(qtw.QMainWindow):
NAME, TAG = range(2)
def __init__(self, *args, **kargs):
......@@ -21,6 +21,10 @@ class MainWindow(qtw.QWidget):
self.tag_ids = {}
self.setWindowTitle("Liste des équipes")
widget = qtw.QWidget(self)
self.setCentralWidget(widget)
self.status_bar = qtw.QStatusBar()
self.setStatusBar(self.status_bar)
self.table_view = qtw.QTableView()
self.table_view.setEditTriggers(qtw.QAbstractItemView.NoEditTriggers)
......@@ -65,7 +69,7 @@ class MainWindow(qtw.QWidget):
vlayout.addLayout(hlayout1)
vlayout.addLayout(hlayout3)
vlayout.addLayout(hlayout4)
self.setLayout(vlayout)
widget.setLayout(vlayout)
self.scan_button.clicked.connect(self.detect_tag)
self.add_button.clicked.connect(self.add_team)
......@@ -80,15 +84,16 @@ class MainWindow(qtw.QWidget):
self.tag_label.setText(str(tag_id))
def add_team(self):
if self.tag_label.text() and self.name_input.text():
if self.tag_label.text():
tag_id = int(self.tag_label.text())
name = self.name_input.text()
self.tree_model.insertRow(0)
self.tree_model.setData(self.tree_model.index(0, self.NAME), name)
self.tree_model.setData(self.tree_model.index(0, self.TAG), tag_id)
self.tag_label.setText("")
self.name_input.setText("")
self.tag_ids[name] = tag_id
if self.is_valid(name, tag_id):
self.tree_model.insertRow(0)
self.tree_model.setData(self.tree_model.index(0, self.NAME), name)
self.tree_model.setData(self.tree_model.index(0, self.TAG), tag_id)
self.tag_label.setText("")
self.name_input.setText("")
self.tag_ids[name] = tag_id
def edit_team(self):
selected = self.table_view.selectedIndexes()
......@@ -99,12 +104,26 @@ class MainWindow(qtw.QWidget):
self.tag_label.setText(str(tag_id))
self.name_input.setText(name)
self.tree_model.takeRow(item.row())
del self.tag_ids[name]
def delete_team(self):
selected = self.table_view.selectedIndexes()
if selected:
item = selected[0]
name = self.tree_model.data(self.tree_model.index(item.row(), self.NAME))
self.tree_model.takeRow(item.row())
del self.tag_ids[name]
def is_valid(self, new_name, new_tag_id):
"""Check that the name and the id are valid and not already used"""
for name, tag_id in self.tag_ids.items():
if name == new_name:
self.status_bar.showMessage("Une équipe avec ce nom existe déjà.", 5000)
return False
elif tag_id == new_tag_id:
self.status_bar.showMessage("Une équipe avec ce tag existe déjà.", 5000)
return False
return True
if __name__ == '__main__':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment