sonist-gtk/usr/lib/sonist/ui/option_menu.py

72 lines
1.6 KiB
Python
Raw Permalink Normal View History

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
2023-08-25 16:50:16 +08:00
from assets import image_dict
2023-08-22 18:52:18 +08:00
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 = [
2023-08-25 16:50:16 +08:00
image_dict['setting'],
image_dict['pin'],
image_dict['switch'],
image_dict['info']
2023-08-22 18:52:18 +08:00
]
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):
if item.name == '首选项':
self.app.preferences.show()
elif item.name == '窗口置顶':
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()
elif item.name == '退出应用':
self.app.quit_all()
elif item.name == '关于播放器':
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)