我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用gi.repository.Gtk.Popover()。
def __init__(self, parent): self.parent = parent self.language = 'Plain' self.curLinter = None self.lintersObj = { 'c': LinterClang(self.parent, self) } self.linterPopover = Gtk.Popover() self.errorsLbl = Gtk.Label('Errors: 0') self.statusLbl = Gtk.Label('Status: OK') self.linterPopoverBox = Gtk.VBox() self.linterPopoverBox.set_border_width(10) self.linterPopoverBox.pack_start(self.errorsLbl, False, False, 0) self.linterPopoverBox.pack_start(self.statusLbl, False, False, 0) self.linterPopover.add(self.linterPopoverBox) ##
def _emoji_event_box_selected(self, event_box): ''' Called when an event box containing an emoji was selected in the flowbox. The emoji is then copied to the clipboard and a popover pops up for a short time to notify the user that the emoji has been copied to the clipboard. :param event_box: The event box which contains the emoji :type event_box: Gtk.EventBox object ''' # Use .get_label() instead of .get_text() to fetch the text # from the label widget including any embedded underlines # indicating mnemonics and Pango markup. The emoji is in # first <span>...</span>, and we want fetch only the emoji # here: text = event_box.get_child().get_label() if _ARGS.debug: sys.stdout.write("_emoji_event_box_selected() text = %s\n" %text) (emoji, name) = self._parse_emoji_and_name_from_text(text) if not emoji: return Gdk.EVENT_PROPAGATE self._set_clipboards(emoji) self._add_to_recently_used(emoji) self._emoji_selected_popover = Gtk.Popover() self._emoji_selected_popover.set_relative_to(event_box) self._emoji_selected_popover.set_position(Gtk.PositionType.TOP) if name: rectangle = Gdk.Rectangle() rectangle.x = 0 rectangle.y = 0 rectangle.width = self._fontsize * 1.5 rectangle.height = self._fontsize * 1.5 self._emoji_selected_popover.set_pointing_to(rectangle) label = Gtk.Label(_('Copied to clipboard!')) self._emoji_selected_popover.add(label) if GTK_VERSION >= (3, 22, 0): self._emoji_selected_popover.popup() self._emoji_selected_popover.show_all() GLib.timeout_add(500, self._emoji_selected_popover_popdown)
def __init__(self, item): super().__init__() self.set_name('LinksButton') self.set_label('%i links' % len(item.links)) self.set_halign(Gtk.Align.START) self.set_valign(Gtk.Align.END) self.set_margin_left(5) self.set_margin_bottom(5) self.connect('activate-link', self._on_activate_link) style_context = self.get_style_context() style_context.remove_class('text-button') style_context.remove_class('button') self._weakref = weakref.ref(item) self._box = Gtk.Box() self._box.set_orientation(Gtk.Orientation.VERTICAL) height_request = 300 if len(self.item.links) <= 5: height_request = 150 scrolled_window = Gtk.ScrolledWindow() scrolled_window.set_policy( Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC ) scrolled_window.set_size_request(300, height_request) scrolled_window.add(self._box) scrolled_window.show_all() self._popover = Gtk.Popover() self._popover.set_relative_to(self) self._popover.add(scrolled_window) self.populate()
def __init__(self): super().__init__() self.set_name('HistoriesManagerBox') self.set_orientation(Gtk.Orientation.HORIZONTAL) self.set_halign(Gtk.Align.END) self.set_valign(Gtk.Align.CENTER) self.set_hexpand(True) self.set_vexpand(False) self.link = Gtk.LinkButton() self.link.connect('activate-link', self._on_activate_link) self.link.set_label('...') self.link.set_tooltip_text(_('Open histories manager')) self._entry = Gtk.Entry() self._entry.set_placeholder_text(_('New history')) self._entry.set_icon_from_icon_name( Gtk.EntryIconPosition.PRIMARY, 'list-add-symbolic' ) self._entry.connect('activate', self._on_entry_activate) self._box = Gtk.Box() self._box.set_orientation(Gtk.Orientation.VERTICAL) self._box.add(self._entry) self.popover = Gtk.Popover() self.popover.set_relative_to(self.link) self.popover.add(self._box) self.add(self.link) gpaste_client.connect('SwitchHistory', self.update) gpaste_client.connect('DeleteHistory', self.update) self.update()
def build_scrollable_popover(pos, width, height): popover = Gtk.Popover() popover.set_position(pos) scrolled_window = Gtk.ScrolledWindow() scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scrolled_window.set_size_request(width, height) popover.add(scrolled_window) return popover
def on_skin_tone_selected(self, dummy_flowbox, flowbox_child): ''' Signal handler for selecting a skin tone emoji :param dummy_flowbox: The flowbox displaying the skin tone emoji :type dummy_flowbox: Gtk.FlowBox object :param flowbox_child: The child object containing the selected emoji :type flowbox_child: Gtk.FlowBoxChild object ''' # Use .get_label() instead of .get_text() to fetch the text # from the label widget including any embedded underlines # indicating mnemonics and Pango markup. The emoji is in # first <span>...</span>, and we want fetch only the emoji # here: text = flowbox_child.get_child().get_label() if _ARGS.debug: sys.stdout.write('on_skin_tone_selected() text = %s\n' %text) (emoji, dummy_name) = self._parse_emoji_and_name_from_text(text) if not emoji: return self._set_clipboards(emoji) self._add_to_recently_used(emoji) self._skin_tone_selected_popover = Gtk.Popover() self._skin_tone_selected_popover.set_relative_to( flowbox_child.get_child()) self._skin_tone_selected_popover.set_position(Gtk.PositionType.TOP) label = Gtk.Label(_('Copied to clipboard!')) self._skin_tone_selected_popover.add(label) if GTK_VERSION >= (3, 22, 0): self._skin_tone_selected_popover.popup() self._skin_tone_selected_popover.show_all() # When an emoji with a different skin tone is selected in a # skin tone popover opened in a browse flowbox (not a search # results flowbox), replace the original emoji which was used # to open the popover immediately. label = self._skin_tone_popover.get_relative_to().get_child() text = label.get_label() (old_emoji, old_name) = self._parse_emoji_and_name_from_text(text) if old_emoji and not old_name: # If the old emoji has a name, this is a line # in a search results flowbox and we do *not* want # to replace the emoji. new_text = ( '<span font="%s %s" fallback="%s">' %(self._font, self._fontsize, str(self._fallback).lower()) + html.escape(emoji) + '</span>') label.set_text(new_text) label.set_use_markup(True) GLib.timeout_add(500, self._skin_tone_selected_popover_popdown)
def on_font_button_clicked(self, dummy_button): ''' The font button in the header bar has been clicked :param dummy_button: The font button :type dummy_button: Gtk.Button object ''' if _ARGS.debug: sys.stdout.write( 'on_font_button_clicked()\n') self._font_popover = Gtk.Popover() self._font_popover.set_relative_to(self._font_button) self._font_popover.set_position(Gtk.PositionType.BOTTOM) self._font_popover.set_vexpand(True) font_popover_vbox = Gtk.VBox() margin = 12 font_popover_vbox.set_margin_start(margin) font_popover_vbox.set_margin_end(margin) font_popover_vbox.set_margin_top(margin) font_popover_vbox.set_margin_bottom(margin) font_popover_vbox.set_spacing(margin) font_popover_label = Gtk.Label() font_popover_label.set_text(_('Set Font')) font_popover_label.set_visible(True) font_popover_label.set_halign(Gtk.Align.FILL) font_popover_vbox.pack_start( font_popover_label, False, False, 0) font_popover_search_entry = Gtk.SearchEntry() font_popover_search_entry.set_can_focus(True) font_popover_search_entry.set_visible(True) font_popover_search_entry.set_halign(Gtk.Align.FILL) font_popover_search_entry.set_hexpand(False) font_popover_search_entry.set_vexpand(False) font_popover_search_entry.connect( 'search_changed', self.on_font_search_entry_search_changed) font_popover_vbox.pack_start( font_popover_search_entry, False, False, 0) self._font_popover_scroll = Gtk.ScrolledWindow() self._fill_listbox_font('') font_popover_vbox.pack_start( self._font_popover_scroll, True, True, 0) self._font_popover.add(font_popover_vbox) if GTK_VERSION >= (3, 22, 0): self._font_popover.popup() self._font_popover.show_all()
def timelist(action, view, bflist, button, margin, xalign, yalign, hover, icns, defcon): if action == 0: timelist = bflist.get_back_list_with_limit(10) else: timelist = bflist.get_forward_list_with_limit(10) popover = Gtk.Popover() menu = Gtk.Box(orientation = Gtk.Orientation.VERTICAL) menu.set_property('margin', margin) popover.set_relative_to(button) popover.set_position(Gtk.PositionType.BOTTOM) popover.add(menu) for item in timelist: url = item.get_uri() title = item.get_title() if item.get_title(): title = minify(title, 50) else: title = minify(url, 50) link = Gtk.ModelButton() link.set_alignment(xalign, yalign) link.set_label(title) link.set_hexpand(True) link_icon = Gtk.Image() link_icon.set_from_file("{}text-x-generic.svg".format(icns)) if not defcon and icons_pop: favicon = get_favicon(view, url, (16, 16)) if favicon: link_icon.set_from_pixbuf(favicon) grid_timelist = Gtk.Grid() grid_timelist.set_column_spacing(10) grid_timelist.attach(link_icon, 0, 1, 1, 1) grid_timelist.attach(link, 1, 1, 1, 1) grid_timelist.set_column_homogeneous(False) link.connect("clicked", lambda throw_away=0, url=url: view.load_uri(url)) link.connect("enter", lambda throw_away=0, url=url: hover.set_text(minify(url, 100))) link.connect("leave", lambda x: hover.set_text("")) menu.pack_start(grid_timelist, False, False, 0) popover.show_all()