#!/usr/bin/env python3 import gi, sys, os, threading # import dbus # import dbus.service, dbus.mainloop.glib from pprint import pprint as print import musicbrainzngs as mus gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk, GLib, GdkPixbuf from window import SonistWindow # from mpd.asyncio import MPDClient from mpd.base import MPDClient app_id = 'fun.wkit.sonist' def run_async(func): def wrapper(*args, **kwargs): thread = threading.Thread(target=func, args=args, kwargs=kwargs) thread.daemon = True thread.start() return thread return wrapper class Application(Gtk.Application): def __init__(self): Gtk.Application.__init__(self, application_id = app_id) self.mpd = MPDClient() self.mpd.timeout = 10 self.mpd.connect("localhost", 6600) self.mpd.ping() self.connect('window-removed', self.on_window_removed) mus.set_useragent('Sonist Gtk', '0.0.1', 'https://github.com/app-cat/sonist-gtk') @run_async def get_cover(self, song, filepath, callback): try: data = mus.search_releases(song["artist"], song["title"], 1) release_id = data["release-list"][0]["release-group"]["id"] print(release_id) buff = mus.get_release_group_image_front(release_id, size = 128) with open(filepath, 'wb') as file: output = file.write(buff) callback(filepath) except: pass def do_activate(self): print('hello mpc') self.set_app_menu(None) self.set_menubar(None) self.window = SonistWindow(self) self.add_window(self.window) self.window.show_all() def on_window_removed(self, app, win): if len(self.get_windows()) == 0: print('朕要休息了~~~') """ class ApplicationService(dbus.service.Object): def __init__(self, app): self.app = app bus_name = dbus.service.BusName(app_id, bus = dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, '/') @dbus.service.method(app_id) def call_app(self): self.app.present() """ if __name__ == "__main__": # dbus.mainloop.glib.DBusGMainLoop(set_as_default = True) # bus = dbus.SessionBus() # try: # obj = bus.get_object(app_id, '/') # obj.call_app() # sys.exit(0) # except dbus.DBusException: # pass app = Application() # ApplicationService(app) app.run(sys.argv)