Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit 938c3ac

Browse files
added support for changing mixer dev
Also switch all tabs to use grids for layout
1 parent 4923347 commit 938c3ac

File tree

5 files changed

+59
-17
lines changed

5 files changed

+59
-17
lines changed

CHANGELOG

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
0.1.0
22

3-
* Add support for basic configuration of sndiod, mainly with a focus
3+
* Added support for basic configuration of sndiod, mainly with a focus
44
on the ability to switch audio devices.
5+
6+
* Switched to using tkinter grids, rather than packed frames for layout,
7+
leading to a more visually appealing widget alignment.
8+
9+
* Added support for switching mixer devices via the "basic" tab by
10+
re-starting the application in-place.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ Contributions are more than welcome. If there is a feature you would like added
2525
to gmixerctl, please feel free to open a pull request. In particular, I would
2626
appreciate help implementing the following features:
2727

28-
* Changing the mixer device at run time (this may be a Tk limitation, but I'm
29-
not experienced enough with Tk at the moment)
28+
* ~~Changing the mixer device at run time (this may be a Tk limitation, but I'm
29+
not experienced enough with Tk at the moment)~~
30+
31+
* Support added in 0.1.0
3032

3133
* ~~Configuring `sndiod` flags (i.e. a menu for running `rcctl set sndiod flags
3234
-f rsnd/X ; rcctl restart sndiod`)~~

gmixerctl/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
log_level = logging.DEBUG
1010

11+
mixer_device = "/dev/mixer"
12+
1113
# control names to appear in the basic tab
1214
basic_controls = [
1315
"outputs.master",

gmixerctl/gui.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import tkinter.messagebox
55
import time
66
import subprocess
7+
import glob
78

89
from . import mixerctl
910
from . import util
@@ -82,7 +83,17 @@ def on_press (this):
8283
"\n\nerror was:\n\n{}".format(e)
8384
)
8485

86+
class SetMixerDevice:
87+
def __init__(this, parent):
88+
this.parent = parent
89+
90+
def __call__(this, val):
91+
# implement callback for setting mixer device
8592

93+
constants.mixer_device = val
94+
logging.debug("updated mixer device to {}".format(val))
95+
this.parent.destroy()
96+
main()
8697

8798
class MultiSelect(tkinter.Frame):
8899
# https://stackoverflow.com/a/34550169
@@ -126,7 +137,7 @@ def update(this):
126137
mixerctl.set_value(this.name, ",".join(
127138
[x for x in this.choices if this.choices[x].get() == 1]))
128139

129-
def render_control(parent, control, tabs, tkvars):
140+
def render_control(parent, control, tabs, tkvars, row):
130141
name = control["name"]
131142

132143

@@ -136,7 +147,7 @@ def render_control(parent, control, tabs, tkvars):
136147
parent,
137148
text = name,
138149
width = constants.label_width)
139-
text_widget.pack(side=tkinter.LEFT)
150+
text_widget.grid(row = row, column = 0)
140151

141152
# create a new callback object - we need to use the update_value
142153
# class so that mixerctl.set_value() knows what control we want
@@ -160,7 +171,7 @@ def render_control(parent, control, tabs, tkvars):
160171
command = callback,
161172
)
162173
# scale.config(width = constants.control_width)
163-
scale.pack(side=tkinter.RIGHT)
174+
scale.grid(row = row, column = 1)
164175

165176
elif control["type"] == "enum":
166177

@@ -178,7 +189,7 @@ def render_control(parent, control, tabs, tkvars):
178189
command = callback,
179190
)
180191
menu.config(width = constants.control_width)
181-
menu.pack(side=tkinter.RIGHT)
192+
menu.grid(row = row, column = 1)
182193

183194
elif control["type"] == "set":
184195

@@ -190,14 +201,14 @@ def render_control(parent, control, tabs, tkvars):
190201
control["possible"],
191202
tkvars[name].choices
192203
)
193-
menu.pack(side=tkinter.RIGHT)
204+
menu.grid(row = row, column = 1)
194205
else:
195206
menu = MultiSelect(
196207
parent,
197208
name,
198209
control["possible"],
199210
)
200-
menu.pack(side=tkinter.RIGHT)
211+
menu.grid(row = row, column = 1)
201212
tkvars[name] = menu
202213

203214

@@ -222,6 +233,7 @@ def main():
222233
tkvars = {}
223234

224235
# custom-build "basic" tab
236+
row_counter = 0
225237
for name in controls:
226238

227239
# only display the controls we have configured
@@ -237,9 +249,25 @@ def main():
237249
nb.add(tabs[tab_name], text=tab_name)
238250

239251
# create the frame for this control
240-
frame = ttk.Frame(tabs[tab_name])
241-
render_control(frame, control, tabs, tkvars)
242-
frame.pack()
252+
render_control(tabs[tab_name], control, tabs, tkvars, row_counter)
253+
row_counter += 1
254+
255+
# add mixer device selector to basic tab
256+
dev_selector_label = tkinter.Label(tabs[tab_name],
257+
text = "select mixer device")
258+
dev_selector_label.grid(row = row_counter, column = 0)
259+
260+
callback = SetMixerDevice(root)
261+
available_device = []
262+
dev_selector_var = tkinter.StringVar()
263+
dev_selector_var.set(constants.mixer_device)
264+
mixer_dev_selector = tkinter.OptionMenu(
265+
tabs[tab_name],
266+
dev_selector_var,
267+
*list(glob.glob("/dev/mixer*")),
268+
command = callback,
269+
)
270+
mixer_dev_selector.grid(row = row_counter, column = 1)
243271

244272

245273
# sndiod control tab
@@ -286,6 +314,7 @@ def main():
286314

287315

288316
# automatically generate the rest of the tabs
317+
row_counter = 0
289318
for name in controls:
290319
control = controls[name]
291320

@@ -296,9 +325,8 @@ def main():
296325
nb.add(tabs[tab_name], text=tab_name)
297326

298327
# create the frame for this control
299-
frame = ttk.Frame(tabs[tab_name])
300-
render_control(frame, control, tabs, tkvars)
301-
frame.pack()
328+
render_control(tabs[tab_name], control, tabs, tkvars, row_counter)
329+
row_counter += 1
302330

303331
# add about tab
304332
about = ttk.Frame(nb)

gmixerctl/mixerctl.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44

55
from . import util
6+
from . import constants
67

78
def parse_line(line):
89
"""parse_line
@@ -57,7 +58,8 @@ def get_state():
5758
Get the current mixer state.
5859
"""
5960

60-
raw = subprocess.check_output(["mixerctl", "-v"], stderr=subprocess.STDOUT)
61+
raw = subprocess.check_output(["mixerctl", "-f", constants.mixer_device,
62+
"-v"], stderr=subprocess.STDOUT)
6163
raw = raw.decode()
6264

6365
control = {}
@@ -79,6 +81,8 @@ def set_value(control, value):
7981
:param value:
8082
"""
8183
logging.debug("setting {} = {}".format(control, value))
82-
raw = subprocess.check_output(["mixerctl", "{}={}".format(control, value)],
84+
raw = subprocess.check_output(
85+
["mixerctl", "-f", constants.mixer_device,
86+
"{}={}".format(control, value)],
8387
stderr=subprocess.STDOUT)
8488
logging.debug("mixerctl says {}".format(raw))

0 commit comments

Comments
 (0)