Make pygtk 2.14 failures more graceful

This commit is contained in:
Chris Jones 2010-01-05 14:24:37 +00:00
parent 0b3cb3df9b
commit 63a17a88b4

View File

@ -1661,17 +1661,21 @@ text/plain
# Center it over the current terminal (not perfect?!?) # Center it over the current terminal (not perfect?!?)
# This could be replaced by a less bothersome dialog, but then that would # This could be replaced by a less bothersome dialog, but then that would
# center over the window, not the terminal # center over the window, not the terminal
screen_w = gtk.gdk.screen_width() try:
screen_h = gtk.gdk.screen_height() screen_w = gtk.gdk.screen_width()
local_x, local_y = self.allocation.x, self.allocation.y screen_h = gtk.gdk.screen_height()
local_w, local_h = self.allocation.width, self.allocation.height local_x, local_y = self.allocation.x, self.allocation.y
window_x, window_y = self.get_window().get_origin() local_w, local_h = self.allocation.width, self.allocation.height
x = window_x + local_x window_x, window_y = self.get_window().get_origin()
y = window_y + local_y x = window_x + local_x
win.realize() y = window_y + local_y
new_x = min(max(0, x+(local_w/2)-(win.allocation.width/2)), screen_w-win.allocation.width) win.realize()
new_y = min(max(0, y+(local_h/2)-(win.allocation.height/2)), screen_h-win.allocation.height) new_x = min(max(0, x+(local_w/2)-(win.allocation.width/2)), screen_w-win.allocation.width)
win.move(new_x, new_y) new_y = min(max(0, y+(local_h/2)-(win.allocation.height/2)), screen_h-win.allocation.height)
win.move(new_x, new_y)
except AttributeError:
# Old pygtk has no gtk.Widget.get_window()
pass
win.show_all () win.show_all ()