Como fazer popover.set_modal (True) funcionar corretamente em python / um applet Budgie?

0

Em um applet para desktop budgie há um objeto Budgie.Popover.new (). Ele abre e fecha através de um botão no painel. Eu defino Budgie.Popover.set_modal (True), mas isso não funciona. para clicar no botão para fechar o popover.Quando clico fora do popover nada acontece.A seguir está um trecho do applet mostrando a criação do popover e outro o botão de operação.

#create a simple button for the applet
    self.button = Gtk.Button()
    self.button.set_relief(Gtk.ReliefStyle.NONE)
    self.button.set_tooltip_text("User Name")
    self.img = Gtk.Image.new_from_icon_name("preferences-desktop-personal", Gtk.IconSize.BUTTON)
    self.img1 = Gtk.Image.new_from_pixbuf(pixbuf)
    self.button.add(self.img)
    self.add(self.button)
    self.show_all()

    # create a popover
    self.popover = Budgie.Popover.new(self.button)
    self.popover.set_modal(True)
    self.popover.set_size_request(50, 130)

O botão:

#applet button signal
    self.button.connect("clicked", self.on_button_clicked)

    def on_button_clicked(self, button):

    if self.popover.get_visible():

        self.popover.hide()

    else:

        self.popover.show_all()

Isto é:

#!/usr/bin/env python3

import pickle
import subprocess
import os
import pwd
import gi.repository
gi.require_version('Budgie', '1.0')
gi.require_version('AccountsService', '1.0')
from gi.repository import Budgie, GObject, Gtk, AccountsService, GLib, 
Gio, GdkPixbuf


file = os.path.expanduser('~/states.p')
class UserName(GObject.GObject, Budgie.Plugin):

        __gtype_name__ = "UserName"

    def __int__(self):
        GObject.Object.__init__(self)

    def do_get_panel_widget(self, uuid):

        return UserNameApplet(uuid)

class UserNameApplet(Budgie.Applet):

    def __init__(self, uuid):

        Budgie.Applet.__init__(self)

    # get avatar
        current_user = GLib.get_user_name()
        bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
        result = bus.call_sync('org.freedesktop.Accounts',
                           '/org/freedesktop/Accounts',
                           'org.freedesktop.Accounts',
                           'FindUserByName',
                           GLib.Variant('(s)', (current_user,)),
                           GLib.VariantType.new('(o)'),
                           Gio.DBusCallFlags.NONE,
                           -1,
                           None)
        (path,) = result.unpack()

        result = bus.call_sync('org.freedesktop.Accounts',
                           path,
                           'org.freedesktop.DBus.Properties',
                           'GetAll',
                           GLib.Variant('(s)', 
                           ('org.freedesktop.Accounts.User',)),
                           GLib.VariantType.new('(a{sv})'),
                           Gio.DBusCallFlags.NONE,
                           -1,
                           None)
    (props,) = result.unpack()
    #print(props['IconFile'])

    pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(props['IconFile'], 22, 22, False)

    username = Gtk.Label(pwd.getpwuid(os.getuid())[4])

    #create a simple button for the applet
    self.button = Gtk.Button()
    self.button.set_relief(Gtk.ReliefStyle.NONE)
    self.button.set_tooltip_text("User Name")
    self.img = Gtk.Image.new_from_icon_name("preferences-desktop-personal", Gtk.IconSize.BUTTON)
    self.img1 = Gtk.Image.new_from_pixbuf(pixbuf)
    self.button.add(self.img)
    self.add(self.button)
    self.show_all()

    # create a popover
    self.popover = Budgie.Popover.new(self.button)
    self.popover.set_modal(True)
    self.popover.set_size_request(50, 130)

    # create a box
    self.box1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
    self.box1.set_spacing(10)

    self.popover.add(self.box1)

    #create the user box with avatar
    self.boxy = Gtk.Box()
    self.box1.pack_start(self.boxy, True, True, 0)
    self.boxy.pack_start(username, True, True, 5)
    self.boxy.add(self.img1)

    # create a separator
    separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
    self.box1.add(separator)

    #create a box with label and a switch
    box2 = Gtk.Box()
    self.box1.add(box2)
    self.switch = Gtk.Switch()
    self.switch.connect("notify::active", self.on_switch_toggled)
    label = Gtk.Label("\tDisplay Full Name\t")
    label.set_justify(Gtk.Justification.LEFT)
    box2.pack_start(label, False, False, 5)
    box2.pack_start(self.switch, False, False, 0)

    #create a separator
    separator1 = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
    self.box1.add(separator1)

    # create a eventbox and a label
    box3 = Gtk.EventBox()
    label1 = Gtk.Label("User Settings")
    label1.set_justify(Gtk.Justification.LEFT)
    box3.add(label1)
    self.box1.pack_start(box3, False, False, 0)
    box3.connect("button-press-event", self.event_press1)

    # create a separator
    separator2 = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
    self.box1.add(separator2)

    # create a eventbox and a label
    box4 = Gtk.EventBox()
    label2 = Gtk.Label("Log Out")
    label2.set_justify(Gtk.Justification.LEFT)
    box4.add(label2)
    self.box1.pack_start(box4, False, False, 0)
    box4.connect("button-press-event", self.event_press2)

O arquivo .plugin:

[Plugin]
Loader=python3
Module=UserName
Name=username
Description=username
Authors=chris
Copyright=Copyright © 2018
Website=some_website
Icon=preferences-desktop-personal

O que estou fazendo errado? Como fazer isso funcionar?

Obrigado antecipadamente.

    
por cgiannakisis 24.03.2018 / 10:34

0 respostas