Skip to content

Commit

Permalink
Basic UI working
Browse files Browse the repository at this point in the history
  • Loading branch information
fergalmoran committed Aug 2, 2021
1 parent 5be5848 commit 04e9f8f
Show file tree
Hide file tree
Showing 22 changed files with 549 additions and 119 deletions.
Binary file removed data/test.mp3
Binary file not shown.
96 changes: 96 additions & 0 deletions desktop/main.py
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()
221 changes: 221 additions & 0 deletions desktop/ui/main.ui
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 &amp;Bridge</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>
Binary file added desktop/ui/resources/dancing-stu.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added desktop/ui/resources/icons/music.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added desktop/ui/resources/icons/refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added desktop/ui/resources/stu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 04e9f8f

Please sign in to comment.