Sco*_*nce 5 indicator icons python
我正在编写一个小型 Python 3应用程序,它用于AppIndicator3在顶部栏中放置一个图标,然后根据用户操作更改该图标。很简单吧?由于该应用程序很小,因此需要从其源目录运行,无需任何安装。
问题是AppIndicator3.set_icon()需要str带有图标名称的 ,而不是所述图标的路径。
我怎样才能说服 AppIndicator3 让我给它一个文件名或一个Pixbuf? 或者,如何将我的图标目录添加到图标名称搜索路径?(我试过AppIndicator3.set_icon_theme_path(),但我的图标名称仍然无法识别。
使用图标的路径最好用一个例子来说明。在下面的示例中,我将图标保存在与脚本(指示器)相同的目录中,这在您的情况下似乎是一个方便的解决方案。
最重要的是,一旦您启动了指标:
class Indicator():
def __init__(self):
self.app = "<indicator_name>"
iconpath = "/path/to/initial/icon/"
-------------------------------
self.testindicator = AppIndicator3.Indicator.new(
self.app, iconpath,
AppIndicator3.IndicatorCategory.OTHER)
-------------------------------
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方法更改图标:
self.testindicator.set_icon("/path/to/new/icon/")
Run Code Online (Sandbox Code Playgroud)
在下面的例子中,所有图标,nocolor.png,purple.png并green.png与脚本存储在一起,但路径图标集
currpath = os.path.dirname(os.path.realpath(__file__))
Run Code Online (Sandbox Code Playgroud)
可以在任何地方。
class Indicator():
def __init__(self):
self.app = "<indicator_name>"
iconpath = "/path/to/initial/icon/"
-------------------------------
self.testindicator = AppIndicator3.Indicator.new(
self.app, iconpath,
AppIndicator3.IndicatorCategory.OTHER)
-------------------------------
Run Code Online (Sandbox Code Playgroud)
...如果您需要从第二个线程更新图标,则需要使用
GObject.threads_init()
Run Code Online (Sandbox Code Playgroud)
前
Gtk.main()
Run Code Online (Sandbox Code Playgroud)
并且您需要使用以下方法更新界面(图标或指示器文本):
GObject.idle_add()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2353 次 |
| 最近记录: |