sonist-gtk/ui/ctrl_box.py

89 lines
2.4 KiB
Python
Raw Normal View History

2023-08-18 19:04:51 +08:00
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
from .image_button import ImageButton
2023-08-21 19:06:22 +08:00
from .toggle_button import ToggleButton
2023-08-18 19:04:51 +08:00
class CtrlBox(Gtk.Box):
__gsignals__ = {
2023-08-21 19:06:22 +08:00
'clicked': (GObject.SignalFlags.RUN_FIRST, None, (str,))
2023-08-18 19:04:51 +08:00
}
def __init__(self, spacing = 6):
Gtk.Box.__init__(self, spacing = spacing)
2023-08-23 20:36:52 +08:00
self.disabled = True
2023-08-21 19:06:22 +08:00
2023-08-18 19:04:51 +08:00
self.modes = ['./usr/share/sonist/all.png','./usr/share/sonist/rand.png','./usr/share/sonist/single.png']
self.curr_mode = 0
2023-08-21 19:06:22 +08:00
self.mode_btn = ImageButton(self.modes[0])
2023-08-18 19:04:51 +08:00
self.prev_btn = ImageButton('./usr/share/sonist/prev.png')
2023-08-21 19:06:22 +08:00
self.play_btn = ToggleButton(['./usr/share/sonist/pause.png', './usr/share/sonist/play.png', './usr/share/sonist/play_a.png'], 48, 48)
2023-08-18 19:04:51 +08:00
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)
2023-08-21 19:06:22 +08:00
# self.play_btn.connect('toggled', self.on_btn_clicked)
2023-08-18 19:04:51 +08:00
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)
def on_btn_clicked(self, btn):
2023-08-21 19:06:22 +08:00
if self.disabled:
return
2023-08-18 19:04:51 +08:00
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')
2023-08-21 19:06:22 +08:00
2023-08-18 19:04:51 +08:00
elif btn == self.vol_btn:
2023-08-24 17:04:41 +08:00
self.emit('clicked', 'vol_btn')
2023-08-18 19:04:51 +08:00
def toggle_play_btn(self, on = True):
2023-08-21 19:06:22 +08:00
if self.disabled:
return
self.play_btn.toggle(on)
2023-08-18 19:04:51 +08:00
def toggle_mode_btn(self, mode = 'single'):
2023-08-21 19:06:22 +08:00
if self.disabled:
return
2023-08-18 19:04:51 +08:00
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])