MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _setup_gtk

Function _setup_gtk

galleries/examples/user_interfaces/mplcvd.py:117–179  ·  view source on GitHub ↗
(tb)

Source from the content-addressed store, hash-verified

115
116
117def _setup_gtk(tb):
118 from gi.repository import Gio, GLib, Gtk
119
120 for idx in range(tb.get_n_items()):
121 children = tb.get_nth_item(idx).get_children()
122 if children and isinstance(children[0], Gtk.Label):
123 break
124
125 toolitem = Gtk.SeparatorToolItem()
126 tb.insert(toolitem, idx)
127
128 image = Gtk.Image.new_from_gicon(
129 Gio.Icon.new_for_string(
130 str(Path(__file__).parent / "images/eye-symbolic.svg")),
131 Gtk.IconSize.LARGE_TOOLBAR)
132
133 # The type of menu is progressively downgraded depending on GTK version.
134 if Gtk.check_version(3, 6, 0) is None:
135
136 group = Gio.SimpleActionGroup.new()
137 action = Gio.SimpleAction.new_stateful("cvdsim",
138 GLib.VariantType("s"),
139 GLib.Variant("s", "none"))
140 group.add_action(action)
141
142 @functools.partial(action.connect, "activate")
143 def set_filter(action, parameter):
144 _set_menu_entry(tb, parameter.get_string())
145 action.set_state(parameter)
146
147 menu = Gio.Menu()
148 for name in _MENU_ENTRIES:
149 menu.append(name, f"local.cvdsim::{name}")
150
151 button = Gtk.MenuButton.new()
152 button.remove(button.get_children()[0])
153 button.add(image)
154 button.insert_action_group("local", group)
155 button.set_menu_model(menu)
156 button.get_style_context().add_class("flat")
157
158 item = Gtk.ToolItem()
159 item.add(button)
160 tb.insert(item, idx + 1)
161
162 else:
163
164 menu = Gtk.Menu()
165 group = []
166 for name in _MENU_ENTRIES:
167 item = Gtk.RadioMenuItem.new_with_label(group, name)
168 item.set_active(name == "None")
169 item.connect(
170 "activate", lambda item: _set_menu_entry(tb, item.get_label()))
171 group.append(item)
172 menu.append(item)
173 menu.show_all()
174

Callers 1

setupFunction · 0.85

Calls 8

PathClass · 0.85
_set_menu_entryFunction · 0.85
get_childrenMethod · 0.45
removeMethod · 0.45
addMethod · 0.45
set_activeMethod · 0.45
connectMethod · 0.45
get_labelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…