audio: Create custom PreviousButton and NextButton buttons
Along with a shared base class for these buttons, and soon the PlayPause button Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
e4f6018195
commit
ec9ed14474
|
@ -2,6 +2,31 @@
|
|||
from . import menu
|
||||
from gi.repository import Gtk, Gst
|
||||
|
||||
|
||||
class ControlButton(Gtk.Button):
|
||||
def __init__(self, player, icon):
|
||||
Gtk.Button.__init__(self)
|
||||
self.add_css_class("large-icons")
|
||||
self.set_icon_name(icon)
|
||||
self.player = player
|
||||
|
||||
|
||||
class PreviousButton(ControlButton):
|
||||
def __init__(self, player):
|
||||
ControlButton.__init__(self, player, "media-skip-backward")
|
||||
|
||||
def do_clicked(self):
|
||||
self.player.previous()
|
||||
|
||||
|
||||
class NextButton(ControlButton):
|
||||
def __init__(self, player):
|
||||
ControlButton.__init__(self, player, "media-skip-forward")
|
||||
|
||||
def do_clicked(self):
|
||||
self.player.next()
|
||||
|
||||
|
||||
class Controls(Gtk.Box):
|
||||
def __init__(self):
|
||||
Gtk.Box.__init__(self)
|
||||
|
|
|
@ -1,10 +1,51 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import controls
|
||||
from lib import settings
|
||||
from gi.repository import Gtk, Gst, GLib
|
||||
import unittest
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gst
|
||||
from . import controls
|
||||
|
||||
class FakePlayer(GObject.GObject):
|
||||
def __init__(self):
|
||||
GObject.GObject.__init__(self)
|
||||
self.prev = False
|
||||
self.nxt = False
|
||||
|
||||
def previous(self): self.prev = True
|
||||
def next(self): self.nxt = True
|
||||
|
||||
|
||||
class TestControlButton(unittest.TestCase):
|
||||
def test_control_button(self):
|
||||
fake = FakePlayer()
|
||||
ctrl = controls.ControlButton(fake, "missing-icon")
|
||||
self.assertIsInstance(ctrl, Gtk.Button)
|
||||
self.assertTrue(ctrl.has_css_class("large-icons"))
|
||||
self.assertEqual(ctrl.get_icon_name(), "missing-icon")
|
||||
self.assertEqual(ctrl.player, fake)
|
||||
|
||||
|
||||
class TestPreviousButton(unittest.TestCase):
|
||||
def test_previous_button(self):
|
||||
fake = FakePlayer()
|
||||
prev = controls.PreviousButton(fake)
|
||||
|
||||
self.assertIsInstance(prev, controls.ControlButton)
|
||||
self.assertEqual(prev.get_icon_name(), "media-skip-backward")
|
||||
prev.emit("clicked")
|
||||
self.assertTrue(fake.prev)
|
||||
|
||||
|
||||
class TestNextButton(unittest.TestCase):
|
||||
def test_next_button(self):
|
||||
fake = FakePlayer()
|
||||
next = controls.NextButton(fake)
|
||||
|
||||
self.assertIsInstance(next, controls.ControlButton)
|
||||
self.assertEqual(next.get_icon_name(), "media-skip-forward")
|
||||
next.emit("clicked")
|
||||
self.assertTrue(fake.nxt)
|
||||
|
||||
main_context = GLib.main_context_default()
|
||||
|
||||
class TestControls(unittest.TestCase):
|
||||
def test_controls_init(self):
|
||||
|
|
Loading…
Reference in New Issue