@@ -1869,6 +1869,8 @@ def __init__(self, interactive = True, framerate = 60,
18691869
18701870 self .__last_mouse_move = None
18711871
1872+ self .connect ("realize" , self .__on_realize )
1873+
18721874 if interactive :
18731875 self .set_can_focus (True )
18741876 self .set_events (gdk .EventMask .POINTER_MOTION_MASK
@@ -1983,7 +1985,6 @@ def do_draw(self, context):
19831985 context .scale (aspect_x , aspect_y )
19841986
19851987 if self .fps is None :
1986- self ._window = self .get_window ()
19871988 self .emit ("on-first-frame" , context )
19881989
19891990 cursor , self .mouse_x , self .mouse_y , mods = self ._window .get_pointer ()
@@ -2241,6 +2242,10 @@ def __on_button_release(self, scene, event):
22412242 self .__check_mouse (event .x , event .y )
22422243 return True
22432244
2245+ def __on_realize (self , widget ):
2246+ # Store as soon as available. Maybe for performance reasons,
2247+ # to avoid get_window() calls in __on_mouse_move ?
2248+ self ._window = self .get_window ()
22442249
22452250 def __on_scroll (self , scene , event ):
22462251 target = self .get_sprite_at_position (event .x , event .y )
0 commit comments