2023-08-22 18:52:18 +08:00
|
|
|
#!/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):
|
2023-08-24 17:04:41 +08:00
|
|
|
|
|
|
|
app = None
|
|
|
|
on_top = False
|
|
|
|
|
2023-08-24 15:25:03 +08:00
|
|
|
def __init__(self, app):
|
2023-08-22 18:52:18 +08:00
|
|
|
Gtk.Menu.__init__(self)
|
2023-08-24 15:25:03 +08:00
|
|
|
self.app = app
|
2023-08-22 18:52:18 +08:00
|
|
|
|
|
|
|
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 '首选项':
|
2023-08-25 15:45:56 +08:00
|
|
|
self.app.preferences.show()
|
2023-08-24 17:04:41 +08:00
|
|
|
|
2023-08-22 18:52:18 +08:00
|
|
|
case '窗口置顶':
|
2023-08-24 17:04:41 +08:00
|
|
|
self.on_top = not self.on_top
|
|
|
|
self.app.window.set_keep_above(self.on_top)
|
|
|
|
if self.on_top:
|
|
|
|
item.select()
|
|
|
|
else:
|
|
|
|
item.deselect()
|
|
|
|
|
2023-08-22 18:52:18 +08:00
|
|
|
case '退出应用':
|
2023-08-24 17:04:41 +08:00
|
|
|
self.app.quit_all()
|
|
|
|
|
2023-08-22 18:52:18 +08:00
|
|
|
case '关于播放器':
|
2023-08-24 15:25:03 +08:00
|
|
|
self.app.about.present()
|
2023-08-22 18:52:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def show(self, widget):
|
|
|
|
# 在按钮下方显示菜单
|
|
|
|
self.popup_at_widget(widget, Gdk.Gravity.NORTH_WEST, Gdk.Gravity.NORTH_WEST, None)
|