Skip to content

Commit

Permalink
Merge pull request #654 from joaorb64/feature/track-station
Browse files Browse the repository at this point in the history
Feature: Add station tracking support
  • Loading branch information
joaorb64 authored Nov 27, 2023
2 parents d37b341 + c51ca0f commit 3a478cf
Show file tree
Hide file tree
Showing 21 changed files with 1,023 additions and 419 deletions.
Binary file modified TSH.exe
Binary file not shown.
53 changes: 53 additions & 0 deletions assets/icons/station.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 43 additions & 52 deletions src/TSHScoreboardWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from src.TSHColorButton import TSHColorButton

from src.TSHSelectSetWindow import TSHSelectSetWindow
from src.TSHSelectStationWindow import TSHSelectStationWindow

from .TSHScoreboardPlayerWidget import TSHScoreboardPlayerWidget
from .SettingsManager import SettingsManager
Expand All @@ -26,6 +27,8 @@ class TSHScoreboardWidgetSignals(QObject):
NewSetSelected = Signal(object)
SetSelection = Signal()
StreamSetSelection = Signal()
StationSelection = Signal()
StationSelected = Signal(object)
UserSetSelection = Signal()
CommandScoreChange = Signal(int, int)
CommandTeamColor = Signal(int, str)
Expand All @@ -49,7 +52,8 @@ def __init__(self, scoreboardNumber=1, *args):
self.signals.UpdateSetData.connect(self.UpdateSetData)
self.signals.NewSetSelected.connect(self.NewSetSelected)
self.signals.SetSelection.connect(self.LoadSetClicked)
self.signals.StreamSetSelection.connect(self.LoadStreamSetClicked)
self.signals.StationSelected.connect(self.LoadStationSet)
self.signals.StationSelection.connect(self.LoadStationSetClicked)
self.signals.UserSetSelection.connect(self.LoadUserSetClicked)
self.signals.ChangeSetData.connect(self.ChangeSetData)

Expand Down Expand Up @@ -82,6 +86,8 @@ def __init__(self, scoreboardNumber=1, *args):

self.lastSetSelected = None

self.lastStationSelected = None

self.autoUpdateTimer: QTimer = None
self.timeLeftTimer: QTimer = None

Expand Down Expand Up @@ -203,31 +209,20 @@ def __init__(self, scoreboardNumber=1, *args):
hbox = QHBoxLayout()
bottomOptions.layout().addLayout(hbox)

self.btLoadStreamSet = QPushButton(
QApplication.translate("app", "Load current stream set"))
self.btLoadStreamSet.setIcon(QIcon("./assets/icons/twitch.svg"))
self.btLoadStreamSet.setEnabled(False)
hbox.addWidget(self.btLoadStreamSet)
self.btLoadStreamSet.clicked.connect(
self.signals.StreamSetSelection.emit)
TSHTournamentDataProvider.instance.signals.twitch_username_updated.connect(
self.UpdateStreamButton)

self.btLoadStreamSetOptions = QPushButton()
self.btLoadStreamSetOptions.setSizePolicy(
QSizePolicy.Maximum, QSizePolicy.Maximum)
self.btLoadStreamSetOptions.setIcon(
QIcon("./assets/icons/settings.svg"))
self.btLoadStreamSetOptions.clicked.connect(
self.LoadStreamSetOptionsClicked)
hbox.addWidget(self.btLoadStreamSetOptions)
self.btLoadStationSet = QPushButton(
QApplication.translate("app", "Track station sets"))
self.btLoadStationSet.setIcon(QIcon("./assets/icons/station.svg"))
hbox.addWidget(self.btLoadStationSet)
self.btLoadStationSet.clicked.connect(
self.signals.StationSelection.emit)

hbox = QHBoxLayout()
bottomOptions.layout().addLayout(hbox)

if self.scoreboardNumber <= 1:
self.btLoadPlayerSet = QPushButton("Load player set")
self.btLoadPlayerSet.setIcon(QIcon("./assets/icons/person_search.svg"))
self.btLoadPlayerSet.setIcon(
QIcon("./assets/icons/person_search.svg"))
self.btLoadPlayerSet.setEnabled(False)
self.btLoadPlayerSet.clicked.connect(
self.signals.UserSetSelection.emit)
Expand All @@ -251,6 +246,7 @@ def __init__(self, scoreboardNumber=1, *args):
TSHTournamentDataProvider.instance.signals.tournament_changed.emit()

self.selectSetWindow = TSHSelectSetWindow(self)
self.selectStationWindow = TSHSelectStationWindow(self)

self.timerLayout = QWidget()
self.timerLayout.setLayout(QHBoxLayout())
Expand Down Expand Up @@ -369,7 +365,8 @@ def __init__(self, scoreboardNumber=1, *args):

self.scoreColumn.findChild(QSpinBox, "best_of").valueChanged.connect(
lambda value: [
StateManager.Set(f"score.{self.scoreboardNumber}.best_of", value),
StateManager.Set(
f"score.{self.scoreboardNumber}.best_of", value),
StateManager.Set(f"score.{self.scoreboardNumber}.best_of_text", TSHLocaleHelper.matchNames.get(
"best_of").format(value) if value > 0 else ""),
]
Expand Down Expand Up @@ -443,24 +440,23 @@ def __init__(self, scoreboardNumber=1, *args):
if self.scoreColumn.findChild(QComboBox, "match").findText(matchString) < 0:
self.scoreColumn.findChild(
QComboBox, "match").addItem(matchString)

if self.scoreboardNumber > 1:
self.UpdateStreamButton()

def ExportTeamLogo(self, team, value):
if os.path.exists(f"./user_data/team_logo/{value.lower()}.png"):
StateManager.Set(f"score.{self.scoreboardNumber}.team.{team}.logo",
f"./user_data/team_logo/{value.lower()}.png")
else:
StateManager.Set(f"score.{self.scoreboardNumber}.team.{team}.logo", None)
StateManager.Set(
f"score.{self.scoreboardNumber}.team.{team}.logo", None)

def GenerateThumbnail(self):
msgBox = QMessageBox()
msgBox.setWindowIcon(QIcon('assets/icons/icon.png'))
msgBox.setWindowTitle(QApplication.translate(
"thumb_app", "TSH - Thumbnail"))
try:
thumbnailPath = thumbnail.generate(settingsManager=SettingsManager, scoreboardNumber=self.scoreboardNumber)
thumbnailPath = thumbnail.generate(
settingsManager=SettingsManager, scoreboardNumber=self.scoreboardNumber)
msgBox.setText(QApplication.translate(
"thumb_app", "The thumbnail has been generated here:") + " ")
msgBox.setIcon(QMessageBox.NoIcon)
Expand Down Expand Up @@ -496,7 +492,6 @@ def UpdateBottomButtons(self):
self.btSelectSet.setText(
QApplication.translate("app", "Load set from {0}").format(TSHTournamentDataProvider.instance.provider.url))
self.btSelectSet.setEnabled(True)
self.btLoadStreamSet.setEnabled(True)
if self.scoreboardNumber <= 1:
self.btLoadPlayerSet.setEnabled(True)
else:
Expand Down Expand Up @@ -545,7 +540,7 @@ def SetPlayersPerTeam(self, number):
path=f'score.{self.scoreboardNumber}.team.{2}.player.{len(self.team2playerWidgets)+1}',
scoreboardNumber=self.scoreboardNumber)
self.playerWidgets.append(p)

self.team2column.findChild(
QScrollArea).widget().layout().addWidget(p)
p.SetCharactersPerPlayer(self.charNumber.value())
Expand Down Expand Up @@ -587,7 +582,8 @@ def SetPlayersPerTeam(self, number):
if StateManager.Get(f'score.{self.scoreboardNumber}.team.{team}'):
for k in list(StateManager.Get(f'score.{self.scoreboardNumber}.team.{team}.player').keys()):
if int(k) > number:
StateManager.Unset(f'score.{self.scoreboardNumber}.team.{team}.player.{k}')
StateManager.Unset(
f'score.{self.scoreboardNumber}.team.{team}.player.{k}')

if number > 1:
self.team1column.findChild(QLineEdit, "teamName").setVisible(True)
Expand Down Expand Up @@ -648,7 +644,8 @@ def SwapTeams(self):
self.teamsSwapped = not self.teamsSwapped

finally:
StateManager.Set(f"score.{self.scoreboardNumber}.teamsSwapped", self.teamsSwapped)
StateManager.Set(
f"score.{self.scoreboardNumber}.teamsSwapped", self.teamsSwapped)

for p in self.playerWidgets:
p.dataLock.release()
Expand Down Expand Up @@ -677,7 +674,11 @@ def NewSetSelected(self, data):
if data.get("auto_update") == "set":
self.labelAutoUpdate.setText("Auto update (Set)")
elif data.get("auto_update") == "stream":
self.labelAutoUpdate.setText("Auto update (Stream)")
self.labelAutoUpdate.setText(
f"Auto update (Stream [{self.lastStationSelected.get('identifier')}])")
elif data.get("auto_update") == "station":
self.labelAutoUpdate.setText(
f"Auto update (Station [{self.lastStationSelected.get('identifier')}])")
elif data.get("auto_update") == "user":
self.labelAutoUpdate.setText("Auto update (User)")
else:
Expand All @@ -692,7 +693,8 @@ def NewSetSelected(self, data):
TSHTournamentDataProvider.instance.GetStreamQueue()

if data.get("id") != None and data.get("id") != self.lastSetSelected:
StateManager.Unset(f'score.{self.scoreboardNumber}.stage_strike')
StateManager.Unset(
f'score.{self.scoreboardNumber}.stage_strike')
self.lastSetSelected = data.get("id")
self.CommandClearAll()
self.ClearScore()
Expand All @@ -712,9 +714,9 @@ def NewSetSelected(self, data):
self.autoUpdateTimer.timeout.connect(
lambda setId=data: self.AutoUpdate(data))

if data.get("auto_update") == "stream":
if data.get("auto_update") in ("stream", "station"):
self.autoUpdateTimer.timeout.connect(
lambda setId=data: TSHTournamentDataProvider.instance.LoadStreamSet(self, SettingsManager.Get("twitch_username")))
lambda setId=data: TSHTournamentDataProvider.instance.LoadStationSet(self))

if data.get("auto_update") == "user":
self.autoUpdateTimer.timeout.connect(
Expand Down Expand Up @@ -743,25 +745,14 @@ def LoadSetClicked(self):
self.selectSetWindow.LoadSets()
self.selectSetWindow.show()

def LoadStreamSetClicked(self):
def LoadStationSet(self, station):
self.lastSetSelected = None
TSHTournamentDataProvider.instance.LoadStreamSet(
self, SettingsManager.Get("twitch_username"))

def LoadStreamSetOptionsClicked(self):
TSHTournamentDataProvider.instance.SetTwitchUsername(self)

def UpdateStreamButton(self):
if SettingsManager.Get("twitch_username"):
self.btLoadStreamSet.setText(
QApplication.translate("app", "Load current stream set") + " "+QApplication.translate("punctuation", "(")+SettingsManager.Get("twitch_username")+QApplication.translate("punctuation", ")"))
self.btLoadStreamSet.setEnabled(True)
StateManager.Set(f"currentStream",
SettingsManager.Get("twitch_username"))
else:
self.btLoadStreamSet.setText(
QApplication.translate("app", "Load current stream set"))
self.btLoadStreamSet.setEnabled(False)
self.lastStationSelected = station
TSHTournamentDataProvider.instance.LoadStationSet(self)

def LoadStationSetClicked(self):
self.selectStationWindow.LoadStations()
self.selectStationWindow.show()

def UpdateUserSetButton(self):
provider = None
Expand Down
20 changes: 12 additions & 8 deletions src/TSHSelectSetWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def filterList(text):
self.startggSetSelectionItemList.setEditTriggers(
QAbstractItemView.NoEditTriggers)
self.startggSetSelectionItemList.setModel(self.proxyModel)
self.startggSetSelectionItemList.setColumnHidden(5, True)
self.startggSetSelectionItemList.setColumnHidden(6, True)
self.startggSetSelectionItemList.horizontalHeader(
).setSectionResizeMode(QHeaderView.Stretch)
self.startggSetSelectionItemList.resizeColumnsToContents()
Expand Down Expand Up @@ -90,13 +90,15 @@ def LoadSets(self):
def SetSets(self, sets):
logger.info("Got sets" + str(len(sets)))
model = QStandardItemModel()
horizontal_labels = ["Stream", "Wave", "Title", "Player 1", "Player 2"]
horizontal_labels = ["Stream", "Station",
"Wave", "Title", "Player 1", "Player 2"]
horizontal_labels[0] = QApplication.translate("app", "Stream")
horizontal_labels[1] = QApplication.translate("app", "Phase")
horizontal_labels[2] = QApplication.translate("app", "Match")
horizontal_labels[3] = QApplication.translate(
"app", "Player {0}").format(1)
horizontal_labels[1] = QApplication.translate("app", "Station")
horizontal_labels[2] = QApplication.translate("app", "Phase")
horizontal_labels[3] = QApplication.translate("app", "Match")
horizontal_labels[4] = QApplication.translate(
"app", "Player {0}").format(1)
horizontal_labels[5] = QApplication.translate(
"app", "Player {0}").format(2)
model.setHorizontalHeaderLabels(horizontal_labels)

Expand Down Expand Up @@ -124,6 +126,8 @@ def SetSets(self, sets):

model.appendRow([
QStandardItem(s.get("stream", "")),
QStandardItem(str(s.get("station", "")) if s.get(
"station", "") != None else ""),
QStandardItem(s.get("tournament_phase", "")),
QStandardItem(s["round_name"]),
QStandardItem(player_names[0]),
Expand All @@ -132,7 +136,7 @@ def SetSets(self, sets):
])

self.proxyModel.setSourceModel(model)
self.startggSetSelectionItemList.setColumnHidden(5, True)
self.startggSetSelectionItemList.setColumnHidden(6, True)
self.startggSetSelectionItemList.resizeColumnsToContents()
self.startggSetSelectionItemList.horizontalHeader(
).setSectionResizeMode(QHeaderView.Stretch)
Expand All @@ -146,7 +150,7 @@ def LoadSelectedSet(self):
row = self.startggSetSelectionItemList.selectionModel().selectedRows()[
0].row()
setId = self.startggSetSelectionItemList.model().index(
row, 5).data(Qt.ItemDataRole.UserRole)
row, 6).data(Qt.ItemDataRole.UserRole)
self.close()

if setId:
Expand Down
Loading

0 comments on commit 3a478cf

Please sign in to comment.