Skip to content

Commit

Permalink
Merge pull request #28 from locaal-ai/roy.fix_vmix_updates
Browse files Browse the repository at this point in the history
fix vmix updates
  • Loading branch information
royshil authored Aug 13, 2024
2 parents 39bb661 + d65d026 commit 472d006
Show file tree
Hide file tree
Showing 5 changed files with 536 additions and 819 deletions.
42 changes: 30 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
QInputDialog,
QTableWidgetItem,
)
from PySide6.QtUiTools import QUiLoader
from PySide6.QtGui import QIcon, QStandardItemModel, QStandardItem
from PySide6.QtGui import QIcon, QStandardItemModel, QStandardItem, QDesktopServices
from PySide6.QtCore import (
Qt,
Signal,
Expand All @@ -25,9 +24,11 @@
QCoreApplication,
QEvent,
QMetaMethod,
QUrl,
)
from dotenv import load_dotenv
from os import path
from platformdirs import user_data_dir

from camera_info import CameraInfo
from get_camera_info import get_camera_info
Expand Down Expand Up @@ -116,6 +117,7 @@ def __init__(self, translator: QTranslator, parent: QObject):
file_menu.addAction("View Current Log", self.openLogsDialog)
file_menu.addAction("Import Configuration", self.importConfiguration)
file_menu.addAction("Export Configuration", self.exportConfiguration)
file_menu.addAction("Open Configuration Folder", self.openConfigurationFolder)

# Add "Language" menu
languageMenu = file_menu.addMenu("Language")
Expand Down Expand Up @@ -352,6 +354,12 @@ def __init__(self, translator: QTranslator, parent: QObject):
self.ui.checkBox_updateOnchange.setChecked(
fetch_data("scoresight.json", "update_on_change", True)
)
self.ui.checkBox_vmix_send_same.setChecked(
fetch_data("scoresight.json", "vmix_send_same", False)
)
self.ui.checkBox_vmix_send_same.toggled.connect(
partial(self.globalSettingsChanged, "vmix_send_same")
)

self.update_sources.connect(self.updateSources)
self.get_sources.connect(self.getSources)
Expand Down Expand Up @@ -441,6 +449,14 @@ def exportConfiguration(self):
# save the configuration to the file
self.detectionTargetsStorage.saveBoxesToFile(file)

def openConfigurationFolder(self):
# open the configuration folder in the file explorer
QDesktopServices.openUrl(
QUrl(
"file:///" + user_data_dir("scoresight"), QUrl.ParsingMode.TolerantMode
)
)

def toggleOSD(self, value):
if self.image_viewer:
self.image_viewer.toggleOSD(value)
Expand Down Expand Up @@ -599,6 +615,8 @@ def vmixMappingChanged(self, _):
mapping[item.text()] = value.text()
self.globalSettingsChanged("vmix_mapping", mapping)
self.vmixUpdater.set_field_mapping(mapping)
else:
logger.error("vmixMappingChanged: model is not a QStandardItemModel")

def vmixUiSetup(self):
# populate the vmix connection from storage
Expand Down Expand Up @@ -646,7 +664,7 @@ def togglevMix(self, value):
self.vmixUpdater.running = False

def updatevMixTable(self, detectionTargets):
mapping_storage = fetch_data("scoresight.json", f"vmix_mapping")
mapping_storage = fetch_data("scoresight.json", "vmix_mapping")
model = QStandardItemModel()
model.blockSignals(True)

Expand All @@ -661,19 +679,16 @@ def updatevMixTable(self, detectionTargets):
model.setItem(row, 0, QStandardItem(box.name))
# the first item shouldn't be editable
model.item(row, 0).setFlags(Qt.ItemFlag.NoItemFlags)
if mapping_storage and box.name in mapping_storage:
model.setItem(row, 1, QStandardItem(mapping_storage[box.name]))
else:
model.setItem(row, 1, QStandardItem(box.name))
else:
# update the item in the list
item = items[0]
row = item.row()
# get value from storage
if mapping_storage and box.name in mapping_storage:
model.setItem(row, 1, QStandardItem(mapping_storage[box.name]))
else:
model.setItem(row, 1, QStandardItem(box.name))

# get value from storage or use the box name
if mapping_storage and box.name in mapping_storage:
model.setItem(row, 1, QStandardItem(mapping_storage[box.name]))
else:
model.setItem(row, 1, QStandardItem(box.name))
# remove the items that are not in the detectionTargets
for i in range(model.rowCount()):
item = model.item(i, 0)
Expand All @@ -682,6 +697,9 @@ def updatevMixTable(self, detectionTargets):

model.blockSignals(False)
self.ui.tableView_vmixMapping.setModel(model)
self.ui.tableView_vmixMapping.model().dataChanged.connect(
self.vmixMappingChanged
)

def detectionTargetsChanged(self, detectionTargets):
for box in detectionTargets:
Expand Down
100 changes: 55 additions & 45 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@
<property name="verticalSpacing">
<number>2</number>
</property>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QTableView" name="tableView_vmixMapping">
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
Expand All @@ -1256,32 +1256,8 @@
</attribute>
</widget>
</item>
<item row="1" column="0">
<widget class="QWidget" name="widget_16" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_19">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item row="0" column="0">
<layout class="QFormLayout" name="formLayout_3">
<property name="horizontalSpacing">
<number>3</number>
</property>
<property name="verticalSpacing">
<number>3</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="leftMargin">
<number>0</number>
</property>
Expand All @@ -1294,14 +1270,7 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="connectionLabel">
<property name="text">
<string>Connection</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item>
<widget class="QWidget" name="connectionWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_18">
<property name="spacing">
Expand All @@ -1319,6 +1288,13 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="connectionLabel">
<property name="text">
<string>Connection</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_vmixHost">
<property name="text">
Expand Down Expand Up @@ -1374,18 +1350,52 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="vmixinputLabel">
<property name="text">
<string>Input</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="inputLineEdit_vmix">
<property name="text">
<string>1</string>
<item>
<widget class="QWidget" name="widget_16" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_19">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="vmixinputLabel">
<property name="text">
<string>Input</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="inputLineEdit_vmix">
<property name="text">
<string>1</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_vmix_send_same">
<property name="toolTip">
<string>Send only new detections or also existing?</string>
</property>
<property name="text">
<string>Send Same?</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
Expand Down
Loading

0 comments on commit 472d006

Please sign in to comment.