Пишу программу на pygobject, и не понимаю, как мне реализовать это, вот исходники(AdwApplicationWindow):
import gi
import sys
gi.require_version("Gtk", "4.0")
gi.require_version('Adw', '1')
gi.require_version('Playerctl', '2.0')
from gi.repository import Playerctl, GLib, Gtk, Adw, Gdk
class MyApp(Adw.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
def on_activate(self, app):
self.player = Playerctl.Player()
self.player.connect('metadata', self.on_metadata)
self.player.connect('playback-status::paused', self.on_pause)
self.player.connect('playback-status::playing', self.on_play)
# Create a Builder
builder = Gtk.Builder()
builder.add_from_file("nasos-gnotify.ui")
# Obtain the button widget and connect it to a function
# button = builder.get_object("button1")
# button.connect("clicked", self.hello)
self.tracklabel = builder.get_object("Tracklabel")
self.setTitleText(self.player.get_title())
self.playbtn = builder.get_object("playbtn")
self.playbtn.connect("clicked", self.playcontol)
self.backbtn = builder.get_object("backbtn")
self.backbtn.connect("clicked", self.backbtnclick)
self.nextbtn = builder.get_object("nextbtn")
self.nextbtn.connect("clicked", self.nextbtnclick)
# Obtain and show the main window
self.win = builder.get_object("mainwindow")
self.win.set_application(self) # Application will close once it no longer has active windows attached to it
self.win.present()
def on_metadata(self, player, metadata):
if 'xesam:artist' in metadata.keys() and 'xesam:title' in metadata.keys():
self.setTitleText(metadata['xesam:title'])
# self.tracklabel.set_markup(f"<b>{metadata['xesam:title']}</b>")
# self.tracklabel.use_markup = True
print('Now playing:')
print('{artist} - {title}'.format(
artist=metadata['xesam:artist'][0], title=metadata['xesam:title']))
def on_pause(self, player, status):
self.playbtn.set_icon_name("media-playback-start-symbolic")
def on_play(self, player, status):
self.playbtn.set_icon_name("media-playback-pause-symbolic")
def nextbtnclick(self, player):
self.player.next()
def backbtnclick(self, player):
self.player.previous()
def playcontol(self, player):
self.player.play_pause()
def setTitleText(self, text):
if len(text) > 30:
self.tracklabel.set_markup(f"<b>{text[:30] + '...'}</b>")
else:
self.tracklabel.set_markup(f"<b>{text}</b>")
def on_focus_out(self, win, event):
self.win.close()
app = MyApp(application_id="com.example.GtkApplication")
app.run(sys.argv)