diff --git a/about_app.py b/about_app.py new file mode 100644 index 0000000..649ed5a --- /dev/null +++ b/about_app.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import gi, sys, os, mutagen +from pprint import pprint as print + +gi.require_version('Gtk', '3.0') + +from gi.repository import Gtk, Gdk, GLib, GdkPixbuf + + +class AboutWindow(Gtk.AboutDialog): + def __init__(self): + super().__init__(self) + + self.set_program_name('Sonist Gtk') + # self.set_logo('youtube') + self.set_logo_icon_name('google-chrome') + self.set_license_type(Gtk.License.MIT_X11) + self.set_version('0.1.0') + self.set_website('https://github.com/app-cat/sonist-gtk') + self.set_website_label('官网') + self.set_copyright('© 2023 Yutent') + self.set_comments('Sonist-Gtk 是一个界面美观, 基于MPD后端的音乐播放器, 使用python + gtk3开发。') \ No newline at end of file diff --git a/main.py b/main.py index 3916cdd..3f580e4 100755 --- a/main.py +++ b/main.py @@ -11,6 +11,7 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk, GLib, GdkPixbuf, GObject from window import SonistWindow +from about_app import AboutWindow from mpd.base import MPDClient @@ -93,8 +94,10 @@ class Application(Gtk.Application): self.mpd_is_online = self.mpd_connect() self.window = SonistWindow(self) + self.about = AboutWindow() self.add_window(self.window) self.window.show_all() + self.about.show_all() self.ping() diff --git a/ui/option_menu.py b/ui/option_menu.py new file mode 100644 index 0000000..bee995d --- /dev/null +++ b/ui/option_menu.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk, Gdk, GObject + +from .image import ScaleImage + +class OptionMenu(Gtk.Menu): + def __init__(self): + Gtk.Menu.__init__(self) + + btn_icos = [ + './usr/share/sonist/setting.png', + './usr/share/sonist/pin.png', + './usr/share/sonist/switch.png', + './usr/share/sonist/info.png' + ] + btn_txts = [ + '首选项', + '窗口置顶', + '退出应用', + '关于播放器' + ] + + + for i in range(4): + item = Gtk.MenuItem() + box = Gtk.Box(spacing = 0) + label = Gtk.Label(label = btn_txts[i]) + img = ScaleImage(btn_icos[i]).resize(16, 16) + + box.set_size_request(92, 32) + box.pack_start(img, False, False, 0) + box.pack_start(label, False, False, 6) + item.name = btn_txts[i] + item.add(box) + item.connect('activate', self.on_menu_select) + self.append(item) + + self.show_all() + + + def on_menu_select(self, item): + match(item.name): + case '首选项': + pass + case '窗口置顶': + pass + case '退出应用': + pass + case '关于播放器': + pass + + + + def show(self, widget): + # 在按钮下方显示菜单 + self.popup_at_widget(widget, Gdk.Gravity.NORTH_WEST, Gdk.Gravity.NORTH_WEST, None) \ No newline at end of file diff --git a/window.py b/window.py index ee526f0..742db05 100644 --- a/window.py +++ b/window.py @@ -2,7 +2,6 @@ import gi, sys, os, mutagen from pprint import pprint as print -from mutagen.flac import FLAC gi.require_version('Gtk', '3.0') @@ -16,6 +15,7 @@ from ui.image_button import ImageButton from ui.text import TextBox from ui.ctrl_box import CtrlBox from ui.timebar import Timebar +from ui.option_menu import OptionMenu @@ -51,8 +51,10 @@ class SonistWindow(Gtk.Window): layout = Gtk.Layout() # 菜单按钮 - menu = ImageButton('./usr/share/sonist/menu.png') - layout.put(menu, 276, 6) + menu_btn = ImageButton('./usr/share/sonist/menu.png') + popup_menu = OptionMenu() + menu_btn.connect('clicked', lambda w: popup_menu.show(w)) + layout.put(menu_btn, 276, 6) # 唱片 disk = ScaleImage('./usr/share/sonist/disk.png')