def __init__(self, bus):
        self.bus = bus
        self.action_group = Gio.SimpleActionGroup()
        self.menu = Gio.Menu()
        self.sub_menu = Gio.Menu()

        self.current_switch_icon = self.DISABLED_ICON
Exemplo n.º 2
0
    def init_menu(self):
        menu_items = {
            'sect_0': [
                ('重置', 'reset', Handler.on_reset, ['<Ctrl>R']),
                ('存档', 'save', Handler.on_save, ['<Ctrl>S']),
                ('读档', 'load', Handler.on_load, ['<Ctrl>L']),
            ],
            'sect_1': [('快捷键', 'keyshot', Handler.on_keyshot, ['<Ctrl>K']),
                       ('关于', 'about', Handler.on_about, [])]
        }

        main_menu = Gio.Menu()

        for sect in menu_items.keys():
            menu_sect = Gio.Menu()
            main_menu.append_section(None, menu_sect)
            for item in menu_items[sect]:
                action_label = item[0]
                action_name = item[1].lower()
                action_dname = 'app.' + action_name
                action_callback = item[2]
                action_accels = item[3]

                action = Gio.SimpleAction.new(action_name, None)
                action.connect('activate', action_callback, self)
                self.add_action(action)

                self.set_accels_for_action(action_dname, action_accels)
                menu_sect.append(action_label, action_dname)

        self.set_app_menu(main_menu)
Exemplo n.º 3
0
    def create_blank_hamburger_menu(self):
        self.blank_menu_button = Gtk.MenuButton()
        image = Gtk.Image.new_from_icon_name('open-menu-symbolic',
                                             Gtk.IconSize.BUTTON)
        self.blank_menu_button.set_image(image)
        self.blank_menu_button.set_focus_on_click(False)
        self.blank_options_menu = Gio.Menu()

        view_section = Gio.Menu()
        view_menu = Gio.Menu()
        view_menu.append_item(
            Gio.MenuItem.new('Show Sidebar', 'win.toggle_sidebar'))
        view_section.append_submenu('View', view_menu)
        self.blank_options_menu.append_section(None, view_section)
        preferences_section = Gio.Menu()
        item = Gio.MenuItem.new('Preferences', 'win.show_preferences_dialog')
        preferences_section.append_item(item)
        self.blank_options_menu.append_section(None, preferences_section)
        meta_section = Gio.Menu()
        item = Gio.MenuItem.new('Keyboard Shortcuts',
                                'win.show_shortcuts_window')
        meta_section.append_item(item)
        item = Gio.MenuItem.new('About', 'win.show_about_dialog')
        meta_section.append_item(item)
        item = Gio.MenuItem.new('Quit', 'win.quit')
        meta_section.append_item(item)
        self.blank_options_menu.append_section(None, meta_section)

        self.blank_menu_button.set_menu_model(self.blank_options_menu)
Exemplo n.º 4
0
    def do_activate(self):
        self._library = ToolLibrary()
        self._library.set_locations(
            os.path.join(self.plugin_info.get_data_dir(), 'tools'))

        action = Gio.SimpleAction(name="manage-tools")
        action.connect("activate",
                       lambda action, parameter: self._open_dialog())
        self.app.add_action(action)

        self.css = Gtk.CssProvider()
        self.css.load_from_data("""
.gedit-tool-manager-paned {
  border-style: solid;
  border-color: @borders;
}

.gedit-tool-manager-paned:dir(ltr) {
  border-width: 0 1px 0 0;
}

.gedit-tool-manager-paned:dir(rtl) {
  border-width: 0 0 0 1px;
}

.gedit-tool-manager-view {
  border-width: 0 0 1px 0;
}

.gedit-tool-manager-treeview {
  border-top-width: 0;
}

.gedit-tool-manager-treeview:dir(ltr) {
  border-left-width: 0;
}

.gedit-tool-manager-treeview:dir(rtl) {
  border-right-width: 0;
}
""".encode('utf-8'))

        Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
                                                 self.css, 600)

        self.menu_ext = self.extend_menu("preferences-section")
        item = Gio.MenuItem.new(_("Manage _External Tools..."),
                                "app.manage-tools")
        self.menu_ext.append_menu_item(item)

        self.submenu_ext = self.extend_menu("tools-section-1")
        external_tools_submenu = Gio.Menu()
        item = Gio.MenuItem.new_submenu(_("External _Tools"),
                                        external_tools_submenu)
        self.submenu_ext.append_menu_item(item)
        external_tools_submenu_section = Gio.Menu()
        external_tools_submenu.append_section(None,
                                              external_tools_submenu_section)

        self.menu = ToolMenu(self._library, external_tools_submenu_section)
Exemplo n.º 5
0
def bus_acquired(bus, name):
    menu = Gio.Menu()
    foo = Gio.MenuItem.new('foo', 'app.foo')
    foo.set_attribute_value('x-additionaltext',
                            GLib.Variant.new_string('lorem ipsum'))
    foo.set_attribute_value('x-enabled', GLib.Variant.new_boolean(True))
    menu.append_item(foo)
    bar = Gio.MenuItem.new('bar', 'bar')
    bar.set_attribute_value('x-defaultvalue',
                            GLib.Variant.new_string('Hello World!'))
    bar.set_attribute_value('x-canonical-currentvalue',
                            GLib.Variant.new_string('awesome'))
    bar.set_attribute_value('x-velocity', GLib.Variant.new_uint64(83374))
    menu.append_item(bar)
    menu.append('bleh', 'app.bleh')
    submenu = Gio.Menu()
    submenu.append('submenu A', 'app.suba')
    submenu2 = Gio.Menu()
    submenu2.append('submenu2 A', 'app.sub2a')
    submenu2.append('submenu2 B', 'app.sub2b')
    submenu2.append('submenu2 C', 'app.sub2c')
    submenu.append_submenu('submenu submenu', submenu2)
    submenu.append('submenu C', 'app.subc')
    menu.append_submenu('submenu', submenu)
    menu.append('baz', 'app.baz')
    bus.export_menu_model(BUS_OBJECT_PATH, menu)

    actions = Gio.SimpleActionGroup.new()
    actions.add_action(Gio.SimpleAction.new("bar", None))
    bus.export_action_group(BUS_OBJECT_PATH, actions)
Exemplo n.º 6
0
    def _create_menu(self):
        # for the standard menu control button add the button
        # to all supported view types
        app = Gio.Application.get_default()
        self.app_id = 'coverart-browser'

        action_name = 'coverart-browser-views'
        self.action = Gio.SimpleAction.new_stateful(
            action_name, GLib.VariantType.new('s'),
            self._views.get_action_name(ListView.name))
        self.action.connect("activate", self.view_change_cb)
        app.add_action(self.action)

        menu_item = Gio.MenuItem()
        section = Gio.Menu()
        menu = Gio.Menu()
        toolbar_item = Gio.MenuItem()

        for view_name in self._views.get_view_names():
            menu_item.set_label(self._views.get_menu_name(view_name))
            menu_item.set_action_and_target_value(
                'app.' + action_name, self._views.get_action_name(view_name))
            section.append_item(menu_item)

        menu.append_section(None, section)

        cl = CoverLocale()
        cl.switch_locale(cl.Locale.LOCALE_DOMAIN)
        toolbar_item.set_label('…')
        cl.switch_locale(cl.Locale.RB)

        toolbar_item.set_submenu(menu)
        for location in self.locations:
            app.add_plugin_menu_item(location, self.app_id, toolbar_item)
Exemplo n.º 7
0
    def __init__(self, app):
        Gtk.Window.__init__(self, title="Menubutton Example", application=app)
        self.set_default_size(600, 400)

        grid = Gtk.Grid()

        # a menubutton
        menubutton = Gtk.MenuButton()
        menubutton.set_size_request(80, 35)

        grid.attach(menubutton, 0, 0, 1, 1)

        # a menu with two actions
        menumodel = Gio.Menu()
        menumodel.append("New", "app.new")
        menumodel.append("About", "win.about")

        # a submenu with one action for the menu
        submenu = Gio.Menu()
        submenu.append("Quit", "app.quit")
        menumodel.append_submenu("Other", submenu)

        # the menu is set as the menu of the menubutton
        menubutton.set_menu_model(menumodel)

        # the action related to the window (about)
        about_action = Gio.SimpleAction.new("about", None)
        about_action.connect("activate", self.about_callback)
        self.add_action(about_action)

        self.add(grid)
    def __init__(self, bus):
        self.bus = bus
        self.action_group = Gio.SimpleActionGroup()
        self.menu = Gio.Menu()
        self.sub_menu = Gio.Menu()

        self.current_switch_icon = "torch-off"
Exemplo n.º 9
0
 def _build_menu_gio(self):
     menu = gio.Menu()
     section = gio.Menu()
     section.append_item(
         gio.MenuItem.new(
             _('Armadito: version %s') % (self._antivirus_version, ), None))
     menu.append_section("foobar", section)
     return menu
Exemplo n.º 10
0
    def create_full_hamburger_menu(self):
        self.menu_button = Gtk.MenuButton()
        image = Gtk.Image.new_from_icon_name('open-menu-symbolic',
                                             Gtk.IconSize.BUTTON)
        self.menu_button.set_image(image)
        self.menu_button.set_focus_on_click(False)
        self.options_menu = Gio.Menu()

        kernel_section = Gio.Menu()
        item = Gio.MenuItem.new('Restart Language Kernel',
                                'win.restart_kernel')
        kernel_section.append_item(item)
        self.change_kernel_menu = Gio.Menu()
        kernel_section.append_submenu('Change Language',
                                      self.change_kernel_menu)

        save_section = Gio.Menu()
        item = Gio.MenuItem.new('Save As ...', 'win.save_as')
        save_section.append_item(item)
        item = Gio.MenuItem.new('Save All', 'win.save_all')
        save_section.append_item(item)

        notebook_section = Gio.Menu()
        item = Gio.MenuItem.new('Delete Notebook ...', 'win.delete')
        notebook_section.append_item(item)

        close_section = Gio.Menu()
        item = Gio.MenuItem.new('Close', 'win.close')
        close_section.append_item(item)
        item = Gio.MenuItem.new('Close All', 'win.close_all')
        close_section.append_item(item)

        self.options_menu.append_section(None, kernel_section)
        self.options_menu.append_section(None, save_section)
        self.options_menu.append_section(None, notebook_section)
        self.options_menu.append_section(None, close_section)

        view_section = Gio.Menu()
        view_menu = Gio.Menu()
        view_menu.append_item(
            Gio.MenuItem.new('Show Sidebar', 'win.toggle_sidebar'))
        view_section.append_submenu('View', view_menu)
        self.options_menu.append_section(None, view_section)
        preferences_section = Gio.Menu()
        item = Gio.MenuItem.new('Preferences', 'win.show_preferences_dialog')
        preferences_section.append_item(item)
        self.options_menu.append_section(None, preferences_section)
        meta_section = Gio.Menu()
        item = Gio.MenuItem.new('Keyboard Shortcuts',
                                'win.show_shortcuts_window')
        meta_section.append_item(item)
        item = Gio.MenuItem.new('About', 'win.show_about_dialog')
        meta_section.append_item(item)
        item = Gio.MenuItem.new('Quit', 'win.quit')
        meta_section.append_item(item)
        self.options_menu.append_section(None, meta_section)

        self.menu_button.set_menu_model(self.options_menu)
Exemplo n.º 11
0
    def _export(self, window, gtk_group):
        actions = [
            ["Preferences", "Plugins"],
            ["RefreshLibrary"],
            ["OnlineHelp", "About", "Quit"],
        ]

        # build the new menu
        menu = Gio.Menu()
        action_names = []
        for group in actions:
            section = Gio.Menu()
            for name in group:
                action = gtk_group.get_action(name)
                assert action
                label = action.get_label()
                section.append(label, "app." + name)
                action_names.append(name)
            menu.append_section(None, section)
        menu.freeze()

        # proxy activate to the old group
        def callback(action, data):
            name = action.get_name()
            gtk_action = gtk_group.get_action(name)
            gtk_action.activate()

        action_group = Gio.SimpleActionGroup()
        for name in action_names:
            action = Gio.SimpleAction.new(name, None)
            action_group.insert(action)
            action.connect("activate", callback)

        # export on the bus
        ag_object_path = "/net/sacredchao/QuodLibet"
        am_object_path = "/net/sacredchao/QuodLibet/menus/appmenu"
        app_id = "net.sacredchao.QuodLibet"

        try:
            bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
            self._ag_id = bus.export_action_group(ag_object_path, action_group)
            self._am_id = bus.export_menu_model(am_object_path, menu)
        except GLib.GError as e:
            print_d("Registering appmenu failed: %r" % e)
            return

        self._bus = bus

        win = window.get_window()
        if not hasattr(win, "set_utf8_property"):
            # not a GdkX11.X11Window
            print_d("Registering appmenu failed: X11 only")
            return

        win.set_utf8_property("_GTK_UNIQUE_BUS_NAME", bus.get_unique_name())
        win.set_utf8_property("_GTK_APPLICATION_ID", app_id)
        win.set_utf8_property("_GTK_APPLICATION_OBJECT_PATH", ag_object_path)
        win.set_utf8_property("_GTK_APP_MENU_OBJECT_PATH", am_object_path)
Exemplo n.º 12
0
 def __init__(self, artist_ids):
     """
         Init menu
         @param artist_ids as [int]
     """
     Gio.Menu.__init__(self)
     section = Gio.Menu()
     radio_action = Gio.SimpleAction(name="radio_action_collection")
     App().add_action(radio_action)
     radio_action.connect("activate", self.__on_radio_action_activate,
                          artist_ids)
     menu_item = Gio.MenuItem.new(_("Related tracks"),
                                  "app.radio_action_collection")
     menu_item.set_attribute_value("close", GLib.Variant("b", True))
     section.append_item(menu_item)
     radio_action = Gio.SimpleAction(name="radio_action_loved")
     App().add_action(radio_action)
     radio_action.connect("activate", self.__on_radio_action_activate,
                          artist_ids)
     menu_item = Gio.MenuItem.new(_("Loved tracks"),
                                  "app.radio_action_loved")
     menu_item.set_attribute_value("close", GLib.Variant("b", True))
     section.append_item(menu_item)
     radio_action = Gio.SimpleAction(name="radio_action_populars")
     App().add_action(radio_action)
     radio_action.connect("activate", self.__on_radio_action_activate,
                          artist_ids)
     menu_item = Gio.MenuItem.new(_("Popular tracks"),
                                  "app.radio_action_populars")
     menu_item.set_attribute_value("close", GLib.Variant("b", True))
     section.append_item(menu_item)
     self.append_section(_("From collection"), section)
     section = Gio.Menu()
     radio_action = Gio.SimpleAction(name="radio_action_deezer")
     App().add_action(radio_action)
     radio_action.connect("activate", self.__on_radio_action_activate,
                          artist_ids)
     radio_action.set_enabled(get_network_available("DEEZER"))
     menu_item = Gio.MenuItem.new(_("Deezer"), "app.radio_action_deezer")
     menu_item.set_attribute_value("close", GLib.Variant("b", True))
     section.append_item(menu_item)
     radio_action = Gio.SimpleAction(name="radio_action_lastfm")
     App().add_action(radio_action)
     radio_action.connect("activate", self.__on_radio_action_activate,
                          artist_ids)
     radio_action.set_enabled(get_network_available("LASTFM"))
     menu_item = Gio.MenuItem.new(_("Last.fm"), "app.radio_action_lastfm")
     menu_item.set_attribute_value("close", GLib.Variant("b", True))
     section.append_item(menu_item)
     radio_action = Gio.SimpleAction(name="radio_action_spotify")
     App().add_action(radio_action)
     radio_action.connect("activate", self.__on_radio_action_activate,
                          artist_ids)
     radio_action.set_enabled(get_network_available("SPOTIFY"))
     menu_item = Gio.MenuItem.new(_("Spotify"), "app.radio_action_spotify")
     menu_item.set_attribute_value("close", GLib.Variant("b", True))
     section.append_item(menu_item)
     self.append_section(_("From the Web"), section)
Exemplo n.º 13
0
    def __init__(self, spotify_playback, **kwargs):
        super().__init__(**kwargs)
        self.progressbar = self.SimpleProgressBar(spotify_playback)
        self.progressbar_box.pack_start(self.progressbar, False, True, 0)
        self.progressbar_box.reorder_child(self.progressbar, 0)

        self.cover_art = Gtk.Image()
        self.mainbox.pack_start(self.cover_art, False, True, 0)

        self.song_label = Gtk.Label()
        self.song_label.set_line_wrap(False)
        self.mainbox.pack_start(self.song_label, False, True, 0)

        spotify_playback.connect("track_changed", self.on_track_changed)

        def reveal_child(_, reveal):
            self.set_reveal_child(reveal)
        spotify_playback.connect("has_playback", reveal_child)

        self.devices_menu = Gio.Menu()
        self.devices_list_menu = Gio.Menu()
        self.devices_list_menu.append("Device1", None)
        self.devices_list_menu.append("Device2", None)
        spotify_playback.connect("devices_changed", self.update_devices_list)
        self.update_devices_list(spotify_playback)
        self.devices_menu.append_section("Devices", self.devices_list_menu)

        devices_button = Gtk.MenuButton()
        self.devices_popover = Gtk.Popover.new_from_model(
            devices_button, self.devices_menu)
        self.devices_popover.set_relative_to(devices_button)
        devices_button.set_popover(self.devices_popover)
        devices_button.set_direction(Gtk.ArrowType.UP)
        devices_button.set_image(
            Gtk.Image.new_from_icon_name(
                "multimedia-player-symbolic.symbolic",
                Gtk.IconSize.LARGE_TOOLBAR))
        heart_button = self.SaveTrackButton(spotify_playback)
        play_button = self.PlaybackButton(spotify_playback)
        self.buttons = Gtk.ButtonBox(Gtk.Orientation.HORIZONTAL)

        devices_button.set_relief(Gtk.ReliefStyle.NONE)
        heart_button.set_relief(Gtk.ReliefStyle.NONE)
        play_button.set_relief(Gtk.ReliefStyle.NONE)

        self.buttons.pack_start(devices_button, False, True, 0)
        self.buttons.pack_start(heart_button, False, True, 0)
        self.buttons.pack_start(play_button, False, True, 0)
        self.buttons.set_homogeneous(True)
        self.buttons.set_halign(Gtk.Align.CENTER)
        self.buttons.set_valign(Gtk.Align.CENTER)
        self.buttons.set_layout(Gtk.ButtonBoxStyle.EXPAND)
        self.mainbox.pack_end(self.buttons, False, True, 10)

        spotify_playback.bind_property(
            "progress_fraction", self.progressbar, "fraction")
        self.show_all()
Exemplo n.º 14
0
    def _create_headerbar(self):
        # User/help menu
        user = api.get_current_user(self.store)
        xml = MENU_XML.format(username=stoq_api.escape(user.get_description()),
                              preferences=_('Preferences...'), password=_('Change password...'),
                              signout=_('Sign out...'), help=_('Help'),
                              contents=_('Contents'), translate=_('Translate Stoq...'),
                              get_support=_('Get support online...'), chat=_('Online chat...'),
                              about=_('About'), quit=_('Quit'))
        builder = Gtk.Builder.new_from_string(xml, -1)

        # Header bar
        self.header_bar = Gtk.HeaderBar()
        self.toplevel.set_titlebar(self.header_bar)

        # Right side
        self.close_btn = self.create_button('fa-power-off-symbolic', action='stoq.quit')
        self.close_btn.set_relief(Gtk.ReliefStyle.NONE)
        self.min_btn = self.create_button('fa-window-minimize-symbolic')
        self.min_btn.set_relief(Gtk.ReliefStyle.NONE)
        #self.header_bar.pack_end(self.close_btn)
        #self.header_bar.pack_end(self.min_btn)
        box = Gtk.Box.new(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
        box.pack_start(self.min_btn, False, False, 0)
        box.pack_start(self.close_btn, False, False, 0)
        self.header_bar.pack_end(box)

        self.user_menu = builder.get_object('app-menu')
        self.help_section = builder.get_object('help-section')
        self.user_button = self.create_button('fa-cog-symbolic',
                                              menu_model=self.user_menu)
        self.search_menu = Gio.Menu()
        self.search_button = self.create_button('fa-search-symbolic', _('Searches'),
                                                menu_model=self.search_menu)
        self.main_menu = Gio.Menu()
        self.menu_button = self.create_button('fa-bars-symbolic', _('Actions'),
                                              menu_model=self.main_menu)

        self.header_bar.pack_end(
            ButtonGroup([self.menu_button, self.search_button, self.user_button]))

        self.sign_button = self.create_button('', _('Sign now'), style_class='suggested-action')
        #self.header_bar.pack_end(self.sign_button)

        # Left side
        self.home_button = self.create_button(STOQ_LAUNCHER, style_class='suggested-action')
        self.new_menu = Gio.Menu()
        self.new_button = self.create_button('fa-plus-symbolic', _('New'),
                                             menu_model=self.new_menu)

        self.header_bar.pack_start(
            ButtonGroup([self.home_button, self.new_button, ]))

        self.domain_header = None
        self.header_bar.show_all()

        self.notifications = NotificationCounter(self.home_button, blink=True)
Exemplo n.º 15
0
    def __init__(self, bus):
        self.bus = bus
        self.action_group = Gio.SimpleActionGroup()
        self.menu = Gio.Menu()
        self.sub_menu = Gio.Menu()

        self.current_switch_icon = 'phone-smartphone-symbolic'

        self.settings = Gio.Settings.new(self.BASE_KEY)
Exemplo n.º 16
0
    def build_menu(self):
        filemenu = Gio.Menu()
        filemenu.append("Open", "win.open")
        filemenu.append("Save", "win.save")
        filemenu.append("Save As", "win.saveas")
        filemenu.append("Quit", "app.quit")

        menu = Gio.Menu()
        menu.append_submenu("File", filemenu)

        return menu
Exemplo n.º 17
0
    def __init__(self, widget, mask, header=False):
        """
            Init menu
            @param widget as Gtk.Widget
            @param mask as SelectionListMask
            @param header as bool
        """
        Gio.Menu.__init__(self)
        self.__widget = widget
        self.__mask = mask

        if header:
            from lollypop.menu_header import MenuHeader
            if mask & SelectionListMask.PLAYLISTS:
                label = _("Playlists")
                icon_name = "emblem-documents-symbolic"
            else:
                label = _("Sidebar")
                icon_name = "org.gnome.Lollypop-sidebar-symbolic"
            self.append_item(MenuHeader(label, icon_name))

        # Options
        if not App().window.folded and\
                not mask & SelectionListMask.PLAYLISTS:
            options_menu = Gio.Menu()
            action = Gio.SimpleAction.new_stateful(
                "show_label", None,
                App().settings.get_value("show-sidebar-labels"))
            action.connect("change-state", self.__on_show_label_change_state)
            App().add_action(action)
            options_menu.append(_("Show text"), "app.show_label")
            self.append_section(_("Options"), options_menu)
        # Shown menu
        shown_menu = Gio.Menu()
        if mask & SelectionListMask.PLAYLISTS:
            lists = ShownPlaylists.get(True)
            wanted = App().settings.get_value("shown-playlists")
        else:
            mask |= SelectionListMask.COMPILATIONS
            lists = ShownLists.get(mask, True)
            wanted = App().settings.get_value("shown-album-lists")
        for item in lists:
            if item[0] == Type.SEPARATOR:
                continue
            exists = item[0] in wanted
            encoded = sha256(item[1].encode("utf-8")).hexdigest()
            action = Gio.SimpleAction.new_stateful(
                encoded, None, GLib.Variant.new_boolean(exists))
            action.connect("change-state", self.__on_shown_change_state,
                           item[0])
            App().add_action(action)
            shown_menu.append(item[1], "app.%s" % encoded)
        # Translators: shown => items
        self.append_section(_("Sections"), shown_menu)
Exemplo n.º 18
0
    def create_main_menu(self):
        menumodel = Gio.Menu()
        menumodel.append("Open image", "win.open-image")
        menumodel.append("About", "win.about")
        menumodel.append("Quit", "app.quit")

        submenu = Gio.Menu()
        submenu.append("Cut", "win.add-cut")
        menumodel.append_submenu("Operations", submenu)

        return menumodel
Exemplo n.º 19
0
 def setup_context_menu(self) -> None:
     menu = Gio.Menu()
     action_menu = Gio.Menu()
     action_menu.append('Remove', 'win.page_remove')
     menu.append_section(None, action_menu)
     prop_menu = Gio.Menu()
     prop_menu.append('Properties', 'win.page_properties')
     menu.append_section(None, prop_menu)
     self.context_menu.bind_model(menu, None, True)
     self.context_menu.attach_to_widget(self)
     self.context_menu.show_all()
    def __init__(self, bus):
        self.get_config()

        self.bus = bus
        self.action_group = Gio.SimpleActionGroup()
        self.menu = Gio.Menu()
        self.sub_menu = Gio.Menu()

        self.current_condition_icon = self.CLEAR
        self.current_condition_text = 'Clear'
        self.current_temperature = 75
        self.error = 'No weather data yet'
Exemplo n.º 21
0
 def __init__(self, widget, rowid, mask):
     """
         Init menu
         @param widget as Gtk.Widget
         @param rowid as int
         @param mask as SelectionListMask
     """
     Popover.__init__(self)
     self.__widget = widget
     self.__rowid = rowid
     self.__mask = mask
     menu = Gio.Menu()
     self.bind_model(menu, None)
     # Startup menu
     if rowid in [Type.POPULARS, Type.RADIOS, Type.LOVED,
                  Type.ALL, Type.RECENTS, Type.YEARS,
                  Type.RANDOMS, Type.NEVER,
                  Type.PLAYLISTS, Type.ARTISTS] and\
             not App().settings.get_value("save-state"):
         startup_menu = Gio.Menu()
         if self.__mask & SelectionListMask.LIST_TWO:
             exists = rowid in App().settings.get_value("startup-two-ids")
         else:
             exists = rowid in App().settings.get_value("startup-one-ids")
         action = Gio.SimpleAction.new_stateful(
             "default_selection_id", None, GLib.Variant.new_boolean(exists))
         App().add_action(action)
         action.connect("change-state", self.__on_default_change_state,
                        rowid)
         item = Gio.MenuItem.new(_("Default on startup"),
                                 "app.default_selection_id")
         startup_menu.append_item(item)
         menu.insert_section(0, _("Startup"), startup_menu)
     # Shown menu
     shown_menu = Gio.Menu()
     if mask & SelectionListMask.PLAYLISTS:
         lists = ShownPlaylists.get(True)
         wanted = App().settings.get_value("shown-playlists")
     else:
         lists = ShownLists.get(mask, True)
         wanted = App().settings.get_value("shown-album-lists")
     for item in lists:
         exists = item[0] in wanted
         encoded = sha256(item[1].encode("utf-8")).hexdigest()
         action = Gio.SimpleAction.new_stateful(
             encoded, None, GLib.Variant.new_boolean(exists))
         action.connect("change-state", self.__on_shown_change_state,
                        item[0])
         App().add_action(action)
         shown_menu.append(item[1], "app.%s" % encoded)
     # Translators: shown => items
     menu.insert_section(1, _("Shown"), shown_menu)
Exemplo n.º 22
0
    def _build_app_menu(self):
        menu = Gio.Menu()
        menu.append(_("Edit CSV file"), "app.edit_csv")
        menu.append(_("Open Data Analyzer"), "app.show_data")

        menu_settings = Gio.Menu()
        menu_settings.append(_("Settings"), "app.settings")
        menu.append_section(None, menu_settings)

        menu_close = Gio.Menu()
        menu_close.append(_("About"), "app.about")
        menu_close.append(_("Quit"), "app.quit")
        menu.append_section(None, menu_close)
        return menu
Exemplo n.º 23
0
	def create_app_menu(self):

		self.app_menu = Gio.Menu()

		self.theme_submenu = Gio.Menu()
		self.theme_submenu.append("Default", "app.theme_default")
		self.theme_submenu.append("Solarized light", "app.theme_solarized_light")
		self.theme_submenu.append("Solarized dark", "app.theme_solarized_dark")

		self.app_menu.append("Fullscreen", "app.fullscreen")
		self.app_menu.append_submenu("Theme", self.theme_submenu)
		self.app_menu.append("Preferences", "app.on_preferences_activated")

		self.set_app_menu(self.app_menu)
Exemplo n.º 24
0
 def __init__(self, win):
     super(MainMenu, self).__init__()
     self.win = win
     self._button = self.win.get_ui('mainmenu_button')
     self._button.connect('clicked', self._on_button)
     self._popover = Gtk.Popover.new_from_model(self._button, self)
     help_menu = Gio.Menu()
     self._add_menu(help_menu, _("About"), 'about')
     self._add_menu(help_menu, _("Documentation"), 'docs')
     self.append_section(_("Help"), help_menu)
     gen_menu = Gio.Menu()
     self._add_menu(gen_menu, _("Preferences"), 'pref')
     self._add_menu(gen_menu, _("Refresh Metadata"), 'reload')
     self._add_menu(gen_menu, _("Quit"), 'quit')
     self.append_section(None, gen_menu)
Exemplo n.º 25
0
def bus_acquired(bus, name):
    # menu
    menu = Gio.Menu()

    password_item = Gio.MenuItem.new("Password:"******"notifications.password")
    password_item.set_attribute_value(
        "x-canonical-type",
        GLib.Variant.new_string("com.canonical.snapdecision.textfield"))
    password_item.set_attribute_value('x-echo-mode-password',
                                      GLib.Variant.new_boolean(True))
    menu.append_item(password_item)

    # actions
    actions = Gio.SimpleActionGroup.new()
    password_action = Gio.SimpleAction.new_stateful(
        "password", GLib.VariantType.new("s"), GLib.Variant.new_string(""))
    password_action.connect("change-state", password_changed)
    actions.insert(password_action)

    global connection
    connection = bus

    global exported_action_group_id
    exported_action_group_id = connection.export_action_group(
        PASSWORD_ACTION_PATH, actions)

    global exported_menu_model_id
    exported_menu_model_id = connection.export_menu_model(
        PASSWORD_MENU_PATH, menu)
Exemplo n.º 26
0
    def __init__(self, win):
        super(HeaderBar, self).__init__()
        self.win = win

        self.set_show_close_button(True)
        self.set_title('RunSQLRun')
        self.set_subtitle('Database query tool')

        self.pack_start(self._btn_from_command('app', 'neweditor'))
        self.pack_start(self._btn_from_command('editor', 'run'))

        # gears button
        menu = Gio.Menu()

        action = Gio.SimpleAction.new('manage_connections', None)
        action.connect('activate', self.on_manage_connections)
        self.win.app.add_action(action)
        menu.append('Manage connections', 'app.manage_connections')

        action = Gio.SimpleAction.new('about', None)
        action.connect('activate', self.on_show_about)
        self.win.app.add_action(action)
        menu.append('About RunSQLRun', 'app.about')

        btn = Gtk.MenuButton()
        icon = Gio.ThemedIcon(name="preferences-system-symbolic")
        image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
        btn.add(image)
        btn.set_popover(Gtk.Popover.new_from_model(btn, menu))
        self.pack_end(btn)
Exemplo n.º 27
0
 def build_menu(preset):
     menu = Gio.Menu()
     for item in preset:
         if isinstance(item[1], str):
             action_name, label = item
             if action_name == 'app.browse-history':
                 menuitem = Gio.MenuItem.new(label, action_name)
                 dict_ = {'account': GLib.Variant('s', account),
                          'jid': GLib.Variant('s', jid)}
                 variant_dict = GLib.Variant('a{sv}', dict_)
                 menuitem.set_action_and_target_value(action_name,
                                                      variant_dict)
                 menu.append_item(menuitem)
             else:
                 menu.append(label, action_name + control_id)
         else:
             label, sub_menu = item
             if 'sync' in sub_menu:
                 # Sync threshold menu
                 submenu = build_sync_menu()
             elif 'chatstate' in sub_menu:
                 submenu = build_chatstate_menu()
             else:
                 # This is a submenu
                 submenu = build_menu(sub_menu)
             menu.append_submenu(label, submenu)
     return menu
Exemplo n.º 28
0
    def __createMenuModel(self):
        action_group = Gio.SimpleActionGroup()
        menu_model = Gio.Menu()

        self.__move_layer_top_action = Gio.SimpleAction.new("move-layer-to-top", None)
        action = self.__move_layer_top_action
        action.connect("activate", self.__move_layer_cb, -2)
        action_group.add_action(action)
        menu_model.append(_("Move layer to top"), "layer.%s" % action.get_name().replace(" ", "."))

        self.__move_layer_up_action = Gio.SimpleAction.new("move-layer-up", None)
        action = self.__move_layer_up_action
        action.connect("activate", self.__move_layer_cb, -1)
        action_group.add_action(action)
        menu_model.append(_("Move layer up"), "layer.%s" % action.get_name().replace(" ", "."))

        self.__move_layer_down_action = Gio.SimpleAction.new("move-layer-down", None)
        action = self.__move_layer_down_action
        action.connect("activate", self.__move_layer_cb, 1)
        action_group.add_action(action)
        menu_model.append(_("Move layer down"), "layer.%s" % action.get_name().replace(" ", "."))

        self.__move_layer_bottom_action = Gio.SimpleAction.new("move-layer-to-bottom", None)
        action = self.__move_layer_bottom_action
        action.connect("activate", self.__move_layer_cb, 2)
        action_group.add_action(action)
        menu_model.append(_("Move layer to bottom"), "layer.%s" % action.get_name().replace(" ", "."))

        self.delete_layer_action = Gio.SimpleAction.new("delete-layer", None)
        action = self.delete_layer_action
        action.connect("activate", self.__delete_layer_cb)
        action_group.add_action(action)
        menu_model.append(_("Delete layer"), "layer.%s" % action.get_name())

        return menu_model, action_group
Exemplo n.º 29
0
    def __init__(self):
        Gtk.Application.__init__(self,
                                 application_id="org.gnome.TwoFactorAuth",
                                 flags=Gio.ApplicationFlags.FLAGS_NONE)
        GLib.set_application_name(_("TwoFactorAuth"))
        GLib.set_prgname("Gnome-TwoFactorAuth")

        self.menu = Gio.Menu()
        self.db = Database()
        self.cfg = SettingsReader()
        self.locked = self.cfg.read("state", "login")

        result = GK.unlock_sync("Gnome-TwoFactorAuth", None)
        if result == GK.Result.CANCELLED:
            self.quit()

        if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 20:
            cssFileName = "gnome-twofactorauth-post3.20.css"
        else:
            cssFileName = "gnome-twofactorauth-pre3.20.css"
        cssProviderFile = Gio.File.new_for_uri('resource:///org/gnome/TwoFactorAuth/%s' % cssFileName)
        cssProvider = Gtk.CssProvider()
        screen = Gdk.Screen.get_default()
        styleContext = Gtk.StyleContext()
        try:
            cssProvider.load_from_file(cssProviderFile)
            styleContext.add_provider_for_screen(screen, cssProvider,
                                             Gtk.STYLE_PROVIDER_PRIORITY_USER)
            logging.debug("Loading css file ")
        except Exception as e:
            logging.error("Error message %s" % str(e))
Exemplo n.º 30
0
    def do_activate(self):
        if not self.window:
            self.window = Gtk.ApplicationWindow(application=self)

            action = Gio.SimpleAction.new("quit", None)
            action.connect("activate", self.on_quit)
            self.add_action(action)

            action = Gio.SimpleAction.new("about", None)
            action.connect("activate", self.on_about)
            self.add_action(action)

            menu = Gio.Menu()
            menu.append('About', 'app.about')
            menu.append("Exit", "app.quit")
            self.set_app_menu(menu)

            icon_theme = Gtk.IconTheme.get_default()
            self.logo = icon_theme.load_icon("applications-other", 128, 0)
            self.window.set_icon(self.logo)

            hb = Gtk.HeaderBar()
            hb.set_show_close_button(True)
            hb.props.title = self.title
            self.window.set_titlebar(hb)

            self.window.set_default_size(640, 480)

            sw = Gtk.ScrolledWindow()
            self.window.add(sw)
            self.window.show_all()

        self.window.present()