-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5be5848
commit 04e9f8f
Showing
22 changed files
with
549 additions
and
119 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import subprocess | ||
import sys | ||
import threading | ||
|
||
from PyQt6 import uic | ||
from PyQt6.QtWidgets import QApplication, QMainWindow, QMessageBox, QFileDialog | ||
|
||
from main_window import Ui_MainWindow | ||
from services.disco_ball import DiscoBall | ||
|
||
|
||
class BridgeNotRegisteredException(Exception): | ||
pass | ||
|
||
|
||
class BridgeNotFoundException(Exception): | ||
pass | ||
|
||
|
||
class App(QMainWindow, Ui_MainWindow): | ||
def __init__(self, parent=None): | ||
super().__init__() | ||
uic.loadUi('./ui/main.ui', self) | ||
self._manager = None | ||
self._bootstrap_ui() | ||
|
||
def _bootstrap_ui(self): | ||
print('Scanning for Hue Bridges') | ||
bridges = DiscoBall.get_bridge_list() | ||
|
||
if len(bridges) != 0: | ||
for bridge in bridges: | ||
self.bridgeList.addItem(bridge['value']) | ||
self._select_bridge(0) | ||
|
||
self.bridgeList.currentIndexChanged.connect(self._select_bridge) | ||
self.refreshBridges.clicked.connect(lambda: self._select_bridge(self.bridgeList.currentIndex())) | ||
self.chooseFile.clicked.connect(self._choose_input_file) | ||
self.startButton.clicked.connect(self._play_audio_file) | ||
|
||
def _select_bridge(self, index): | ||
ip = self.bridgeList.itemText(index) | ||
self._manager = DiscoBall(ip) | ||
try: | ||
lights = self._manager.get_light_list() | ||
print(lights) | ||
|
||
for light in lights: | ||
self.lightsList.addItem(light['value']) | ||
except BridgeNotRegisteredException as e: | ||
msg = QMessageBox() | ||
msg.setIcon(QMessageBox.Icon.Warning) | ||
msg.setText("This application is not registered with this Hue Bridge") | ||
msg.setInformativeText("Please press the register button on top of the bridge and click the retry button") | ||
msg.setWindowTitle("Error") | ||
msg.show() | ||
|
||
def _choose_input_file(self): | ||
fname = QFileDialog.getOpenFileName( | ||
win, | ||
'Open file', | ||
'~', | ||
'Audio Files (*.mp3 *.wav *.ogg)') | ||
self.inputFileName.setText(fname[0]) | ||
|
||
def _play_audio_file(self): | ||
audio_thread = threading.Thread(target=self._play_audio_file_internal, name="player") | ||
audio_thread.start() | ||
|
||
def _play_audio_file_internal(self): | ||
command = [ | ||
'../disco-hue.py', | ||
'--action', 'flash', | ||
'--file', self.inputFileName.text(), | ||
'--light-id', '1', | ||
'--bridge-ip', self.bridgeList.currentText() | ||
] | ||
subprocess.run(command, stdout=subprocess.PIPE) | ||
|
||
def closeEvent(self, event): | ||
if self._manager is not None: | ||
self._manager.stop() | ||
event.accept() | ||
|
||
|
||
app = QApplication(sys.argv) | ||
win = App() | ||
|
||
|
||
def bootstrap_app(): | ||
win.show() | ||
sys.exit(app.exec()) | ||
|
||
|
||
if __name__ == "__main__": | ||
bootstrap_app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MainWindow</class> | ||
<widget class="QMainWindow" name="MainWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>521</width> | ||
<height>261</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>MainWindow</string> | ||
</property> | ||
<property name="toolTip"> | ||
<string>Refresh Bridge Status</string> | ||
</property> | ||
<widget class="QWidget" name="centralwidget"> | ||
<widget class="QLabel" name="label"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>50</y> | ||
<width>101</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>Light</string> | ||
</property> | ||
</widget> | ||
<widget class="QComboBox" name="lightsList"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>130</x> | ||
<y>50</y> | ||
<width>301</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
</widget> | ||
<widget class="QComboBox" name="bridgeList"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>130</x> | ||
<y>10</y> | ||
<width>301</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>10</y> | ||
<width>101</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>Bridge</string> | ||
</property> | ||
</widget> | ||
<widget class="QToolButton" name="refreshBridges"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>440</x> | ||
<y>10</y> | ||
<width>71</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>()</string> | ||
</property> | ||
<property name="icon"> | ||
<iconset> | ||
<normaloff>resources/icons/refresh.png</normaloff>resources/icons/refresh.png | ||
</iconset> | ||
</property> | ||
<property name="iconSize"> | ||
<size> | ||
<width>64</width> | ||
<height>64</height> | ||
</size> | ||
</property> | ||
</widget> | ||
<widget class="QLabel" name="label_3"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>90</y> | ||
<width>101</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>Input File</string> | ||
</property> | ||
</widget> | ||
<widget class="QLineEdit" name="inputFileName"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>130</x> | ||
<y>90</y> | ||
<width>301</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
</widget> | ||
<widget class="QToolButton" name="chooseFile"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>440</x> | ||
<y>90</y> | ||
<width>71</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>16</pointsize> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>...</string> | ||
</property> | ||
<property name="iconSize"> | ||
<size> | ||
<width>64</width> | ||
<height>64</height> | ||
</size> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="startButton"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>130</y> | ||
<width>501</width> | ||
<height>81</height> | ||
</rect> | ||
</property> | ||
<property name="font"> | ||
<font> | ||
<pointsize>18</pointsize> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string>Let's Dance!</string> | ||
</property> | ||
<property name="icon"> | ||
<iconset> | ||
<normaloff>resources/icons/music.png</normaloff>resources/icons/music.png | ||
</iconset> | ||
</property> | ||
<property name="iconSize"> | ||
<size> | ||
<width>32</width> | ||
<height>32</height> | ||
</size> | ||
</property> | ||
</widget> | ||
</widget> | ||
<widget class="QMenuBar" name="menubar"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>521</width> | ||
<height>19</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QStatusBar" name="statusbar"/> | ||
<action name="actionChange_Bridge"> | ||
<property name="text"> | ||
<string>Change &Bridge</string> | ||
</property> | ||
</action> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.