101 lines
2.7 KiB
Python
101 lines
2.7 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import gi
|
||
|
gi.require_version('Gtk', '3.0')
|
||
|
from gi.repository import Gtk, GObject
|
||
|
|
||
|
from .image_button import ImageButton
|
||
|
from .toggle_button import ToggleButton
|
||
|
from .volume import Volume
|
||
|
|
||
|
class CtrlBox(Gtk.Box):
|
||
|
|
||
|
__gsignals__ = {
|
||
|
'clicked': (GObject.SignalFlags.RUN_FIRST, None, (str,)),
|
||
|
'volume_changed': (GObject.SignalFlags.RUN_FIRST, None, (int,))
|
||
|
}
|
||
|
|
||
|
def __init__(self, spacing = 6):
|
||
|
Gtk.Box.__init__(self, spacing = spacing)
|
||
|
|
||
|
self.disabled = True
|
||
|
|
||
|
self.modes = [
|
||
|
'./usr/share/sonist/all.png',
|
||
|
'./usr/share/sonist/rand.png',
|
||
|
'./usr/share/sonist/single.png'
|
||
|
]
|
||
|
self.curr_mode = 0
|
||
|
|
||
|
self.mode_btn = ImageButton(self.modes[0])
|
||
|
self.prev_btn = ImageButton('./usr/share/sonist/prev.png')
|
||
|
self.play_btn = ToggleButton(['./usr/share/sonist/pause.png', './usr/share/sonist/play.png'], 48, 48)
|
||
|
self.next_btn = ImageButton('./usr/share/sonist/next.png')
|
||
|
self.vol_btn = ImageButton('./usr/share/sonist/volume.png')
|
||
|
|
||
|
self.pack_start(self.mode_btn, False, False, 0)
|
||
|
self.pack_start(self.prev_btn, False, False, 0)
|
||
|
self.pack_start(self.play_btn, False, False, 0)
|
||
|
self.pack_start(self.next_btn, False, False, 0)
|
||
|
self.pack_start(self.vol_btn, False, False, 0)
|
||
|
|
||
|
|
||
|
self.mode_btn.connect('clicked', self.on_btn_clicked)
|
||
|
self.prev_btn.connect('clicked', self.on_btn_clicked)
|
||
|
self.play_btn.connect('clicked', self.on_btn_clicked)
|
||
|
self.next_btn.connect('clicked', self.on_btn_clicked)
|
||
|
self.vol_btn.connect('clicked', self.on_btn_clicked)
|
||
|
|
||
|
self.volume_bar = Volume(self.vol_btn)
|
||
|
self.volume_bar.connect('volume_changed', lambda bar, vol: self.emit('volume_changed', vol))
|
||
|
|
||
|
|
||
|
def on_btn_clicked(self, btn):
|
||
|
|
||
|
if self.disabled:
|
||
|
return
|
||
|
|
||
|
if btn == self.play_btn:
|
||
|
self.emit('clicked', 'play_btn')
|
||
|
|
||
|
elif btn == self.mode_btn:
|
||
|
self.curr_mode += 1
|
||
|
if self.curr_mode > 2:
|
||
|
self.curr_mode = 0
|
||
|
self.mode_btn.set_image(self.modes[self.curr_mode])
|
||
|
self.emit('clicked', 'mode_btn')
|
||
|
|
||
|
elif btn == self.prev_btn:
|
||
|
self.emit('clicked', 'prev_btn')
|
||
|
|
||
|
elif btn == self.next_btn:
|
||
|
self.emit('clicked', 'next_btn')
|
||
|
|
||
|
elif btn == self.vol_btn:
|
||
|
self.volume_bar.show_all()
|
||
|
|
||
|
|
||
|
def set_volume(self, vol):
|
||
|
self.volume_bar.set_volume(vol)
|
||
|
|
||
|
|
||
|
def toggle_play_btn(self, on = True):
|
||
|
if self.disabled:
|
||
|
return
|
||
|
|
||
|
self.play_btn.toggle(on)
|
||
|
|
||
|
|
||
|
def toggle_mode_btn(self, mode = 'single'):
|
||
|
if self.disabled:
|
||
|
return
|
||
|
|
||
|
if mode == 'single':
|
||
|
self.curr_mode = 2
|
||
|
elif mode == 'random':
|
||
|
self.curr_mode = 1
|
||
|
else:
|
||
|
self.curr_mode = 0
|
||
|
|
||
|
self.mode_btn.set_image(self.modes[self.curr_mode])
|