Как создать индикаторы Unity?

Если Xorg.1.log ближе к концу имеет следующие строки:

[     3.404] (II) UnloadModule: "intel"    
[     3.404] (II) Unloading intel
[     3.404] (EE) Screen(s) found, but none have a usable configuration.
[     3.404] 
Fatal server error:
[     3.404] no screens found

Это сработало для меня. Кажется, Lightdm слишком светлый. Вы должны замедлить этого ребенка, добавив к нему шаг сна.

1
задан 22 February 2018 в 19:20

2 ответа

Вот пример примера приложения в C. Это версия «только для индикаторов» (без окна) примера, представленного в Ubuntu Wiki:

#include <libappindicator/app-indicator.h>

static void activate_action (GtkAction *action);

static GtkActionEntry entries[] = {
    {"New",  "document-new",     "_New",  "<control>N",
        "Create a new file",    G_CALLBACK(activate_action)},
    {"Open", "document-open",    "_Open", "<control>O",
        "Open a file",          G_CALLBACK(activate_action)},
    {"Save", "document-save",    "_Save", "<control>S",
        "Save file",            G_CALLBACK(activate_action)},
    {"Quit", "application-exit", "_Quit", "<control>Q",
        "Exit the application", G_CALLBACK(gtk_main_quit)},
};
static guint n_entries = G_N_ELEMENTS(entries);

static const gchar *ui_info =
"<ui>"
"  <popup name='IndicatorPopup'>"
"    <menuitem action='New' />"
"    <menuitem action='Open' />"
"    <menuitem action='Save' />"
"    <menuitem action='Quit' />"
"  </popup>"
"</ui>";

static void activate_action(GtkAction *action)
{
    const gchar *name = gtk_action_get_name (action);
    GtkWidget *dialog;

    dialog = gtk_message_dialog_new(NULL,
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_INFO,
                                    GTK_BUTTONS_CLOSE,
                                    "You activated action: \"%s\"",
                                    name);

    g_signal_connect(dialog, "response", 
                     G_CALLBACK(gtk_widget_destroy), NULL);

    gtk_widget_show(dialog);
}

int main(int argc, char **argv)
{
    GtkWidget*      indicator_menu;
    GtkActionGroup* action_group;
    GtkUIManager*   uim;
    AppIndicator* indicator;
    GError* error = NULL;

    gtk_init(&argc, &argv);

    /* Menus */
    action_group = gtk_action_group_new("AppActions");
    gtk_action_group_add_actions(action_group, entries, n_entries,
                                 NULL);

    uim = gtk_ui_manager_new();
    gtk_ui_manager_insert_action_group(uim, action_group, 0);

    if (!gtk_ui_manager_add_ui_from_string(uim, ui_info, -1, &error)) {
        g_message("Failed to build menus: %s\n", error->message);
        g_error_free(error);
        error = NULL;
    }

    /* Indicator */
    indicator = app_indicator_new("example-simple-client",
                                  "go-jump",
                                  APP_INDICATOR_CATEGORY_APPLICATION_STATUS);

    indicator_menu = gtk_ui_manager_get_widget(uim, "/ui/IndicatorPopup");

    app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
    app_indicator_set_attention_icon(indicator, "indicator-messages-new");

    app_indicator_set_menu(indicator, GTK_MENU(indicator_menu));

    gtk_main();

    return 0;
}
4
ответ дан 25 May 2018 в 21:06
  • 1
    Ссылка дает 404 – Ring Ø 20 February 2017 в 10:12
  • 2
    @ ringø Отредактированный ответ sergej, добавил рабочую ссылку. Фактически, это та же связь, что и в ответе Хорхе. – Sergiy Kolodyazhnyy 21 February 2017 в 20:34
  • 3
    @Serg Хорошо, спасибо! – Ring Ø 22 February 2017 в 03:55

Я сделал короткий учебник для создания индикатора приложения секундомера в python: http://www.steshadoku.com/blog/2017/elapses-creating-a-unity-stopwatch-indicator-w-python/ [ ! d0]

import gobject
import gtk
import appindicator
import os, sys
import time
from datetime import timedelta

if __name__ == "__main__":

    saveseconds = 0 #global variable to save how many seconds the clock has run
    dir_path = os.path.dirname(os.path.realpath(__file__))
    source_id = ""

    def on_timer(args=None):
      savetime = int(time.time() - timestart) + saveseconds
      ind.set_label(str(timedelta(seconds=savetime)))
      return True

    def finish(args=None):
        sys.exit()
        return True

    def stoptime(args=None):
        #print(source_id)
        global saveseconds
        saveseconds += int(time.time() - timestart)
        gtk.timeout_remove(source_id)
        return True

    def starttime(args=None):
        global timestart
        timestart = time.time()
        global source_id
        source_id = gtk.timeout_add(1000, on_timer)
            #sets timer to run every 1s
        return True

    def cleartime(args=None):
        global saveseconds
        saveseconds = 0
        ind.set_label(str(timedelta(seconds=0)))
        gtk.timeout_remove(source_id)
        return True

    #format below is category name, icon
    ind = appindicator.Indicator ("simple-clock-client", "hourglass", appindicator.CATEGORY_APPLICATION_STATUS, dir_path)
    ind.set_status (appindicator.STATUS_ACTIVE)
    ind.set_label("Elapses"); #name of program and initial display

    ##Setup Menu Items
    menu = gtk.Menu()

    stop = gtk.MenuItem("Stop")
    stop.connect("activate", stoptime)
    stop.show()
    menu.append(stop)

    start = gtk.MenuItem("Start")
    start.connect("activate", starttime)
    start.show()
    menu.append(start)

    clear = gtk.MenuItem("Clear")
    clear.connect("activate", cleartime)
    clear.show()
    menu.append(clear)

    exit = gtk.MenuItem("Exit")
    exit.connect("activate", finish)
    exit.show()
    menu.append(exit)

    ind.set_menu(menu) #set the menu with added items
    gtk.main()
0
ответ дан 25 May 2018 в 21:06
  • 1
    Я не рассматривал фактический код, но с одной стороны: у вас есть ошибки отступов. И здесь, и в связанном учебнике. – Jacob Vlijm 21 February 2017 в 19:27
  • 2
    Нет, есть одно место для отступов. , , только один, что делает его абсолютно болезненным для чтения кода и не соответствует стандарту PEP8 Python – Sergiy Kolodyazhnyy 21 February 2017 в 20:26

Другие вопросы по тегам:

Похожие вопросы: