-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
84 lines (74 loc) · 2.82 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from menu_options import opts_audio_devices, opts_audio_programs
from data import AudioDevice, AudioProgram
"""
Device Format
{
type: output/input
name: dev name
img: <>
default: T/F
volume: 0-100
mute: T/F
}
Program Format
{
name: program name
img: <>
volume: 0-100
mute: T/F
}
"""
def getAttributes(listName):
names = [i[0] for i in listName]
images = [i[1] for i in listName]
cmds = [i[2] for i in listName]
return [names, images, cmds]
# newDev structure = [device type, device name, device image path, default audio status, device volume, device mute status]
def updateDevices(newDevs: dict):
with open("out.txt", "a") as w:
w.write(f"Updating Device with {newDevs['name']}\n")
dev_set = False
# Check if the device is already in the current list
for opt_dev in opts_audio_devices:
# If it's already in the list, update the current item
if newDevs['name'] == opt_dev.m_name:
opt_dev.setImg(newDevs['img'])
opt_dev.setVolume(newDevs['volume'])
opt_dev.setMute(newDevs['mute'])
opt_dev.setDefault(newDevs['default'])
opt_dev.setOutput(newDevs['type'])
dev_set = True
with open("out.txt", "a") as w:
w.write(f"Item {newDevs['name']} already in list\n")
break
# Device not found in the list, create a new object & add it
if not dev_set:
with open("out.txt", "a") as w:
w.write(f"Item {newDevs['name']} not found in list\n")
aDev = AudioDevice(newDevs['name'], newDevs['img'], newDevs['volume'], newDevs['mute'])
# Check if it's input/output audio device
if newDevs['type'] == "in":
aDev.setOutput(False)
aDev.setDefault(newDevs['type'])
opts_audio_devices.append(aDev)
with open("out.txt", "a") as w:
w.write(f"\n")
# newProg structure = [program name, program image path, program volume, program mute state]
def updateprograms(newProg):
updated_programs = []
prog_set = False
# Check if the program is already in the current list
for opt_prog in opts_audio_programs:
# If it's already in the list, update the current item
if newProg['name'] == opt_prog.m_name:
opt_prog.setImg(newProg['img'])
opt_prog.setVolume(newProg['volume'])
opt_prog.setMute(newProg['mute'])
updated_programs.append(opt_prog)
prog_set = True
break
# Program not found in the list, create a new object & add it
if not prog_set:
aProg = AudioProgram(newProg['name'], newProg['img'], newProg['volume'], newProg['mute'])
opts_audio_programs.append(aProg)
updated_programs.append(aProg)