我正在尝试向AppIndicator添加一个类似于Sound Menu的滑块.
我查看了声音菜单的代码,发现我应该使用libido-0.1.
这是我到目前为止所拥有的:
indicator_menu = gtk_menu_new();
ido_slider_widget = ido_scale_menu_item_new_with_range("BRIGHTNESS", IDO_RANGE_STYLE_DEFAULT, 0, 0, 100, 1);
ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(ido_slider_widget), "BRIGHTNESS");
ido_scale_menu_item_set_style(IDO_SCALE_MENU_ITEM(ido_slider_widget), IDO_SCALE_MENU_ITEM_STYLE_LABEL);
ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(ido_slider_widget), " - ");
ido_scale_menu_item_set_secondary_label(IDO_SCALE_MENU_ITEM(ido_slider_widget), " + ");
GtkMenuItem *menu_slider_item = GTK_MENU_ITEM(ido_slider_widget);
gtk_menu_append(indicator_menu, GTK_WIDGET(menu_slider_item));
gtk_menu_append(indicator_menu, gtk_menu_item_new_with_label("dfdsfds"));
gtk_widget_show_all(indicator_menu);
gtk_widget_show_all(ido_slider_widget);
app_indicator_set_menu(indicator, GTK_MENU(indicator_menu));
Run Code Online (Sandbox Code Playgroud)
我看到的只是菜单中的' - '符号,我该如何解决这个问题?
以下是AppIndicator的最小示例:
#!/usr/bin/python
import gobject
import gtk
import appindicator
if __name__ == "__main__":
ind = appindicator.Indicator("example-simple-client", "gtk-execute", appindicator.CATEGORY_APPLICATION_STATUS)
ind.set_status (appindicator.STATUS_ACTIVE)
menu = gtk.Menu()
menu_items = gtk.MenuItem('Quit')
menu.append(menu_items)
menu_items.connect("activate", gtk.main_quit)
menu_items.show()
ind.set_menu(menu)
gtk.main()
Run Code Online (Sandbox Code Playgroud)
不幸的是,关于此的文档非常不完整.我正在寻找的是一种检查AppIndicator菜单是否由用户打开的方法(例如,点击了指示器图标).那么当菜单打开时会发出一个信号吗?
我是QT的新手,需要使用app-indicator构建应用程序.由于QT似乎比GTK +更容易,我在QT中制作它.
我会提到我已经安装了sni-qt,并且vlc和skype的app指示符在面板上显示正常.我在Ubuntu 13.04 64位上使用QT5.
我一步一步地遵循了本教程:http://qt-project.org/doc/qt-4.8/desktop-systray.html
但是当我运行它时,它出现的方式(十字架是我正在使用的图标):

我该如何解决?
我希望能够在我的gtk.Menu中放置一个gtk.ProgressBar,但由于菜单只需要gtk.MenuItems及其子类,我所做的就是采用一个普通的gtk.MenuItem并尝试添加我的进度条作为一个孩子.由于gtk.MenuItem是gtk.Bin的子类,因此它应该能够容纳任何小部件.
例:
menu = gtk.Menu()
item = gtk.MenuItem()
button = gtk.ProgressBar()
button.pulse()
button.show()
item.add(button)
item.show()
menu.append(item)
Run Code Online (Sandbox Code Playgroud)
没有pygtk抱怨,这运行得很好.但是,我的进度条根本没有显示:

如果我用gtk.Label替换进度条,它就显示得很好.
现在问我的问题:
Ubuntu 13.10上没有Appindicator?
jason@jz:~$ python
Python 2.7.5+ (default, Sep 19 2013, 13:48:49)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import appindicator
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named appindicator
>>>
Run Code Online (Sandbox Code Playgroud)
有替代品吗?或者我可以自己安装吗?
提前致谢.
我在python中写openweathermap网站appindicator,但我只需要指针中没有图标的文字标签.但是当我离开""然后给我看空图标.为什么,我只需要文字.在Ubuntu 12.04中,python-appindicator不需要图标如果离开""然后不加载空图标,但在ubuntu 14.04中留下空图标.如何禁用图标?有任何想法吗?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import urllib2
import json
import time
import datetime
from gi.repository import Gtk, Gdk, GLib, GObject
from gi.repository import AppIndicator3 as appindicator
class programa:
def __init__(self):
# Create Indicator with icon and label
# If leave empty "" then load empty icon
self.ind = appindicator.Indicator.new("Weather","",appindicator.IndicatorCategory.APPLICATION_STATUS)
self.ind.set_status(appindicator.IndicatorStatus.ACTIVE) #
self.menu_structure()
# Menu structure
def menu_structure(self):
refresh = 720 # Refresh interval in seconds
url = urllib2.Request('http://api.openweathermap.org/data/2.5/weather?q=siauliai&units=metric')
openup = urllib2.urlopen(url) …Run Code Online (Sandbox Code Playgroud) 我刚刚发现了tomate:https://gitorious.org/tomate 一个非常简单的程序,可以帮助您在计算机上完成工作.
但是tomate使用gtk.status_icon而不是appindicator所以我想解决这个问题.
但是,我想与appindicator保持相同的行为.它很容易像这样使用,我不想创建菜单并使其使用复杂化.
简单的行为是当您单击图标时启动时间计数器,再次单击时停止它.
所以你不需要菜单.
是否可以在没有菜单的情况下使用appindicator,或者只接收点击并且没有任何项目的基本菜单?
谢谢你的帮助.
我正在尝试将 appindicator 与 gtk 菜单集成。我想要一些菜单项有这样的快捷方式:
不幸的是,在将加速器添加到第二个菜单项后,我仍然得到没有图标和快捷方式的项目。
我希望看到的是“item2”右侧的快捷方式。
int main (int argc, char **argv) {
gtk_init(&argc, &argv);
// main window
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "menu-with-shortcuts-window");
gtk_window_set_icon_name(GTK_WINDOW(window), "menu-with-shortcuts-icon");
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
// indicator
AppIndicator* indicator = app_indicator_new("menu-with-shortcuts-appindicator", "transmission-tray-icon", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
// menu
GtkWidget* indicator_menu = gtk_menu_new();
GtkWidget* item1 = gtk_menu_item_new_with_label("item1");
gtk_menu_shell_append(GTK_MENU_SHELL(indicator_menu), item1);
g_signal_connect(item1, "activate", G_CALLBACK(Item1Clicked), NULL);
gtk_widget_show(item1);
GtkAccelGroup* accel_group = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
GtkWidget* item2 = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, accel_group);
gtk_widget_add_accelerator(item2, "activate", accel_group, GDK_q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_menu_shell_append(GTK_MENU_SHELL(indicator_menu), item2);
g_signal_connect(item2, "activate", G_CALLBACK(Item2Clicked), NULL); …Run Code Online (Sandbox Code Playgroud) GTK2GtkStatusIcon中的 .GTK3 已弃用,大多数应用程序appindicator使用GtkStatusIcon. 但听起来这appindicator在 MacOS 中不可用,是否有任何库可以像GtkStatusIconMacOS 和 Linux 一样工作?谢谢。
我有一个简单的 Python 代码,它使用GI的AppIndicator3创建一个 Linux 托盘指示器。效果很好。但我想检测并处理简单的用户单击或双击此托盘图标。
据我所知,例如,Telegram使用Qt 类QSystemTrayIcon,它支持此功能,因为当用户双击托盘图标时,Telegram 窗口会自动显示。
scroll_event当用户在托盘图标上滚动鼠标滚轮时触发的信号。当
AyatanaAppIndicator3.Indicator接收到滚动事件时发出信号。
set_secondary_activate_target(menuitem)方法指示以某种方式处理中键单击事件。设置
menuitem为在图标/标签上发出辅助激活事件(即中键单击)时激活AyatanaAppIndicator3.Indicator。
有人了解它是如何工作的吗?前面的两个例子让我想知道为什么没有简单的鼠标单击信号/事件。我在想是否可以更深入,也许继承AyatanaAppIndicator3.Indicator类并重写一些事件处理?或者可能更深入地研究StatusNotifierItem和Activate方法(如果这是 AppIndicator 实现的)?
或者有什么棘手的解决方法吗?因为这似乎是一个十多年来没有答案的问题,我不满足于仅仅“不可能”的答案。
我也知道我不是第一个问这个问题的人。我做了一些小研究,发现了多个相关线程:
Python AppIndicator 绑定 -> 如何检查菜单是否打开?
如何在单击应用程序指示器时运行操作
如何对一键指示器进行编程(添加中键单击功能)?
当菜单显示/隐藏时,指示器应用程序不发送信号处理
单击事件和修饰符