#!/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 class CtrlBox(Gtk.Box): __gsignals__ = { 'clicked': (GObject.SignalFlags.RUN_FIRST, None, (str,)) } def __init__(self, spacing = 6): Gtk.Box.__init__(self, spacing = spacing) self.disabled = False 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', './usr/share/sonist/play_a.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('toggled', 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) 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.emit('clicked','vol_btn') 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])