Elementary 下带有 Vala 应用程序的简单 AppIndicator OS
Simple AppIndicator with Vala application under Elementary OS
昨天我被困在一些困难的事情上。一开始看起来很简单但谁不推我:/
这是我想要的:一个应用程序指示器(statusicon?),带有我的应用程序的自定义图标。
不幸的是,除了 this,我在 valadoc 中找不到任何东西,但它已被弃用,它说我们应该使用通知,这实际上不是一回事
我听说过 .vapi Appindicator 文件,但这不是关于如何使用它的真正文档
如果有人可以post编写有关将 AppIndicator 集成到 vala 代码中的代码,我将不胜感激!
谢谢
您是否尝试过 libappindicator 中包含的 Vala 示例?
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Marco Trevisan (Treviño) <mail@3v1n0.net>
*/
using Gtk;
using AppIndicator;
public class IndicatorExample {
public static int main(string[] args) {
Gtk.init(ref args);
var win = new Window();
win.title = "Indicator Test";
win.resize(200, 200);
win.destroy.connect(Gtk.main_quit);
var label = new Label("Hello, world!");
win.add(label);
var indicator = new Indicator(win.title, "indicator-messages",
IndicatorCategory.APPLICATION_STATUS);
if (!(indicator is Indicator)) return -1;
indicator.set_status(IndicatorStatus.ACTIVE);
indicator.set_attention_icon("indicator-messages-new");
var menu = new Gtk.Menu();
var item = new Gtk.MenuItem.with_label("Foo");
item.activate.connect(() => {
indicator.set_status(IndicatorStatus.ATTENTION);
});
item.show();
menu.append(item);
var bar = item = new Gtk.MenuItem.with_label("Bar");
item.show();
item.activate.connect(() => {
indicator.set_status(IndicatorStatus.ACTIVE);
});
menu.append(item);
indicator.set_menu(menu);
indicator.set_secondary_activate_target(bar);
win.show_all();
Gtk.main();
return 0;
}
}
昨天我被困在一些困难的事情上。一开始看起来很简单但谁不推我:/
这是我想要的:一个应用程序指示器(statusicon?),带有我的应用程序的自定义图标。
不幸的是,除了 this,我在 valadoc 中找不到任何东西,但它已被弃用,它说我们应该使用通知,这实际上不是一回事 我听说过 .vapi Appindicator 文件,但这不是关于如何使用它的真正文档
如果有人可以post编写有关将 AppIndicator 集成到 vala 代码中的代码,我将不胜感激!
谢谢
您是否尝试过 libappindicator 中包含的 Vala 示例?
/*
* Copyright 2011 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Marco Trevisan (Treviño) <mail@3v1n0.net>
*/
using Gtk;
using AppIndicator;
public class IndicatorExample {
public static int main(string[] args) {
Gtk.init(ref args);
var win = new Window();
win.title = "Indicator Test";
win.resize(200, 200);
win.destroy.connect(Gtk.main_quit);
var label = new Label("Hello, world!");
win.add(label);
var indicator = new Indicator(win.title, "indicator-messages",
IndicatorCategory.APPLICATION_STATUS);
if (!(indicator is Indicator)) return -1;
indicator.set_status(IndicatorStatus.ACTIVE);
indicator.set_attention_icon("indicator-messages-new");
var menu = new Gtk.Menu();
var item = new Gtk.MenuItem.with_label("Foo");
item.activate.connect(() => {
indicator.set_status(IndicatorStatus.ATTENTION);
});
item.show();
menu.append(item);
var bar = item = new Gtk.MenuItem.with_label("Bar");
item.show();
item.activate.connect(() => {
indicator.set_status(IndicatorStatus.ACTIVE);
});
menu.append(item);
indicator.set_menu(menu);
indicator.set_secondary_activate_target(bar);
win.show_all();
Gtk.main();
return 0;
}
}