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

Method __init__

lib/matplotlib/backends/_backend_gtk.py:137–186  ·  view source on GitHub ↗
(self, canvas, num)

Source from the content-addressed store, hash-verified

135 """
136
137 def __init__(self, canvas, num):
138 self._gtk_ver = gtk_ver = Gtk.get_major_version()
139
140 app = _create_application()
141 self.window = Gtk.Window()
142 app.add_window(self.window)
143 super().__init__(canvas, num)
144
145 if gtk_ver == 3:
146 icon_ext = "png" if sys.platform == "win32" else "svg"
147 self.window.set_icon_from_file(
148 str(cbook._get_data_path(f"images/matplotlib.{icon_ext}")))
149
150 self.vbox = Gtk.Box()
151 self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL)
152
153 if gtk_ver == 3:
154 self.window.add(self.vbox)
155 self.vbox.show()
156 self.canvas.show()
157 self.vbox.pack_start(self.canvas, True, True, 0)
158 elif gtk_ver == 4:
159 self.window.set_child(self.vbox)
160 self.vbox.prepend(self.canvas)
161
162 # calculate size for window
163 w, h = self.canvas.get_width_height()
164
165 if self.toolbar is not None:
166 if gtk_ver == 3:
167 self.toolbar.show()
168 self.vbox.pack_end(self.toolbar, False, False, 0)
169 elif gtk_ver == 4:
170 sw = Gtk.ScrolledWindow(vscrollbar_policy=Gtk.PolicyType.NEVER)
171 sw.set_child(self.toolbar)
172 self.vbox.append(sw)
173 min_size, nat_size = self.toolbar.get_preferred_size()
174 h += nat_size.height
175
176 self.window.set_default_size(w, h)
177
178 self._destroying = False
179 self.window.connect("destroy", lambda *args: Gcf.destroy(self))
180 self.window.connect({3: "delete_event", 4: "close-request"}[gtk_ver],
181 lambda *args: Gcf.destroy(self))
182 if mpl.is_interactive():
183 self.window.show()
184 self.canvas.draw_idle()
185
186 self.canvas.grab_focus()
187
188 def destroy(self, *args):
189 if self._destroying:

Callers

nothing calls this directly

Calls 9

_create_applicationFunction · 0.85
set_childMethod · 0.80
get_width_heightMethod · 0.80
__init__Method · 0.45
addMethod · 0.45
showMethod · 0.45
connectMethod · 0.45
destroyMethod · 0.45
draw_idleMethod · 0.45

Tested by

no test coverage detected