This repository has been archived on 2023-09-06. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
py-gtk-notes
Archived
1
0
Fork 0
py-gtk-notes/notes/tray.py

66 lines
1.6 KiB
Python

import gi, platform
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
# 需要安装这个包 gir1.2-gdkpixbuf-2.0
from gi.repository.GdkPixbuf import Pixbuf
# 优先尝试使用指示器, 没有再使用 Gtk.StatusIcon
try:
gi.require_version('AyatanaAppIndicator3', '0.1')
# 需要安装这个包 gir1.2-ayatanaappindicator3-0.1
from gi.repository import AyatanaAppIndicator3 as AppIndicator3
except (ValueError, ImportError):
AppIndicator3 = None
# 是否 widnows
def is_windows():
return platform.system() in ('Windows', 'Microsoft')
# 文件要绝对路径
def get_pixbuf(filename: str, size: int = 0) -> Pixbuf:
if size:
pixbuf = Pixbuf.new_from_file_at_size(filename, size, size)
else:
pixbuf = Pixbuf.new_from_file(filename)
return pixbuf
# 获取logo图标
def get_logo(size):
filename = 'youtube.svg'
# windows要用png格式
if is_windows():
filename = 'youtube.png'
return get_pixbuf(filename, size)
def create_tray():
if AppIndicator3 :
indicator = AppIndicator3.Indicator.new(
"youtube",
"youtube",
AppIndicator3.IndicatorCategory.APPLICATION_STATUS
)
# 加上这句, 图标才会显示
indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
else:
# windows 和 macos 必须传二进制图标, linux可传图标名称(自会去主题中找)
indicator = Gtk.StatusIcon.new_from_pixbuf(get_logo(32))
# linux
indicator = Gtk.StatusIcon.new_from_icon_name('youtube')
# 图标的点击事件
indicator.connect('activate', toggle_visible)
return indicator
def toggle_visible():
pass
python + gtk3 + webkit2 学习笔记
Python 60.1%
JavaScript 37.6%
HTML 2.3%