Use accessor functions for data fields

The following data fields that were provided by PyGTK are not accessible
directly in GTK3+pygi and need to be replaced by accessor calls:

Adjustment.lower
Adjustment.page_size
Adjustment.upper
Adjustment.value
Bin.child
Widget.parent
Widget.style
Widget.window

Based on patches by Daniel Drake <dsd@laptop.org>.

Signed-off-by: Sascha Silbe <silbe@activitycentral.com>
This commit is contained in:
Sascha Silbe 2011-11-15 21:32:03 +01:00 committed by Simon Schampijer
parent 4aacaaf56e
commit c82a775267
9 changed files with 60 additions and 48 deletions

View File

@ -901,8 +901,8 @@ class Activity(Window, Gtk.Container):
self.reveal()
def __realize_cb(self, window):
wm.set_bundle_id(window.window, self.get_bundle_id())
wm.set_activity_id(window.window, str(self._activity_id))
wm.set_bundle_id(window.get_window(), self.get_bundle_id())
wm.set_activity_id(window.get_window(), str(self._activity_id))
def __delete_event_cb(self, widget, event):
self.close()

View File

@ -279,7 +279,7 @@ class NamingAlert(Gtk.Window):
def __realize_cb(self, widget):
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
self.window.set_accept_focus(True)
self.get_window().set_accept_focus(True)
def __keep_cb(self, widget):
if self._favorite_icon.get_active():

View File

@ -228,7 +228,7 @@ class _IconBuffer(object):
self.fill_color = None
def _get_insensitive_pixbuf(self, pixbuf, widget):
if not (widget and widget.style):
if not (widget and widget.get_style()):
return pixbuf
icon_source = Gtk.IconSource()
@ -239,9 +239,10 @@ class _IconBuffer(object):
icon_source.set_direction_wildcarded(False)
icon_source.set_size_wildcarded(False)
pixbuf = widget.style.render_icon(icon_source, widget.get_direction(),
Gtk.StateType.INSENSITIVE, -1, widget,
'sugar-icon')
style = widget.get_style()
pixbuf = style.render_icon(icon_source, widget.get_direction(),
Gtk.StateType.INSENSITIVE, -1, widget,
'sugar-icon')
return pixbuf

View File

@ -47,8 +47,9 @@ class ObjectChooser(object):
if parent is None:
parent_xid = 0
elif hasattr(parent, 'window') and hasattr(parent.window, 'xid'):
parent_xid = parent.window.xid
elif hasattr(parent, 'get_window') and hasattr(parent.get_window(),
'xid'):
parent_xid = parent.get_window().xid
else:
parent_xid = parent

View File

@ -350,8 +350,9 @@ class Palette(PaletteWindow):
def _update_accept_focus(self):
accept_focus = len(self._content.get_children())
if self.window:
self.window.set_accept_focus(accept_focus)
window = self.get_window()
if window:
window.set_accept_focus(accept_focus)
def __realize_cb(self, widget):
self._update_accept_focus()

View File

@ -386,7 +386,7 @@ class PaletteWindow(Gtk.Window):
self.emit('popdown')
def get_rect(self):
win_x, win_y = self.window.get_origin()
win_x, win_y = self.get_window().get_origin()
rectangle = self.get_allocation()
x = win_x + rectangle.x
@ -715,8 +715,9 @@ class WidgetInvoker(Invoker):
def get_rect(self):
allocation = self._widget.get_allocation()
if self._widget.window is not None:
x, y = self._widget.window.get_origin()
window = self._widget.get_window()
if window is not None:
x, y = window.get_origin()
else:
logging.warning(
"Trying to position palette with invoker that's not realized.")
@ -843,8 +844,9 @@ class CellRendererInvoker(Invoker):
def get_rect(self):
allocation = self._tree_view.get_allocation()
if self._tree_view.window is not None:
x, y = self._tree_view.window.get_origin()
window = self._tree_view.get_window()
if window is not None:
x, y = window.get_origin()
else:
logging.warning(
"Trying to position palette with invoker that's not realized.")

View File

@ -39,16 +39,18 @@ class ToolbarButton(ToolButton):
self.connect('hierarchy-changed', self.__hierarchy_changed_cb)
def __hierarchy_changed_cb(self, tool_button, previous_toplevel):
if hasattr(self.parent, 'owner'):
parent = self.get_parent()
if hasattr(parent, 'owner'):
if self.page_widget and previous_toplevel is None:
self._unparent()
self.parent.owner.pack_start(self.page_widget, True, True, 0)
parent.owner.pack_start(self.page_widget, True, True, 0)
self.set_expanded(False)
def get_toolbar_box(self):
if not hasattr(self.parent, 'owner'):
parent = self.get_parent()
if not hasattr(parent, 'owner'):
return None
return self.parent.owner
return parent.owner
toolbar_box = property(get_toolbar_box)
@ -72,7 +74,7 @@ class ToolbarButton(ToolButton):
def is_in_palette(self):
return self.page is not None and \
self.page_widget.parent == self.props.palette
self.page_widget.get_parent() == self.props.palette
def is_expanded(self):
return self.page is not None and \
@ -95,9 +97,10 @@ class ToolbarButton(ToolButton):
box = self.toolbar_box
if box.expanded_button is not None:
if box.expanded_button.window is not None:
button_window = box.expanded_button.get_window()
if button_window is not None:
# need to redraw it to erase arrow
box.expanded_button.window.invalidate_rect(None, True)
button_window.invalidate_rect(None, True)
box.expanded_button.set_expanded(False)
box.expanded_button = self
@ -117,9 +120,10 @@ class ToolbarButton(ToolButton):
self.props.palette.add(self.page_widget)
def _unparent(self):
if self.page_widget.parent is None:
page_parent = self.page_widget.get_parent()
if page_parent is None:
return
self.page_widget.parent.remove(self.page_widget)
page_parent.remove(self.page_widget)
def do_expose_event(self, event):
if not self.is_expanded() or self.props.palette is not None and \
@ -218,7 +222,7 @@ class _ToolbarPalette(PaletteWindow):
self.set_group_id('toolbarbox')
def get_expanded_button(self):
return self.invoker.parent
return self.invoker.get_parent()
expanded_button = property(get_expanded_button)
@ -272,9 +276,10 @@ class _Box(Gtk.EventBox):
self.set_app_paintable(True)
def do_expose_event(self, widget, event):
if self.parent.expanded_button is None:
expanded_button = self.get_parent().expanded_button
if expanded_button is None:
return
alloc = self.parent.expanded_button.allocation
alloc = expanded_button.allocation
self.get_style().paint_box(event.window,
Gtk.StateType.NORMAL, Gtk.ShadowType.IN, event.area, self,
'palette-invoker', -style.FOCUS_LINE_WIDTH, 0,
@ -318,7 +323,7 @@ def _embed_page(box_class, page):
def _get_embedded_page(page_widget):
return page_widget.get_child().child
return page_widget.get_child().get_child()
def _paint_arrow(widget, event, arrow_type):

View File

@ -85,32 +85,32 @@ class _TrayViewport(Gtk.Viewport):
start = item.allocation.y
stop = item.allocation.y + item.allocation.height
if start < adj.value:
adj.value = start
elif stop > adj.value + adj.page_size:
adj.value = stop - adj.page_size
if start < adj.get_value():
adj.set_value(start)
elif stop > adj.get_value() + adj.get_page_size():
adj.set_value(stop - adj.get_page_size())
def _scroll_next(self):
allocation = self.get_allocation()
if self.orientation == Gtk.Orientation.HORIZONTAL:
adj = self.get_hadjustment()
new_value = adj.value + allocation.width
adj.value = min(new_value, adj.upper - allocation.width)
new_value = adj.get_value() + allocation.width
adj.set_value(min(new_value, adj.get_upper() - allocation.width))
else:
adj = self.get_vadjustment()
new_value = adj.value + allocation.height
adj.value = min(new_value, adj.upper - allocation.height)
new_value = adj.get_value() + allocation.height
adj.set_value(min(new_value, adj.get_upper() - allocation.height))
def _scroll_previous(self):
allocation = self.get_allocation()
if self.orientation == Gtk.Orientation.HORIZONTAL:
adj = self.get_hadjustment()
new_value = adj.value - allocation.width
adj.value = max(adj.lower, new_value)
new_value = adj.get_value() - allocation.width
adj.set_value(max(adj.get_lower(), new_value))
else:
adj = self.get_vadjustment()
new_value = adj.value - allocation.height
adj.value = max(adj.lower, new_value)
new_value = adj.get_value() - allocation.height
adj.set_value(max(adj.get_lower(), new_value))
def do_size_request(self, requisition):
child_requisition = self.get_child().size_request()
@ -141,12 +141,13 @@ class _TrayViewport(Gtk.Viewport):
self.notify('scrollable')
def _adjustment_changed_cb(self, adjustment):
if adjustment.value <= adjustment.lower:
if adjustment.get_value() <= adjustment.get_lower():
can_scroll_prev = False
else:
can_scroll_prev = True
if adjustment.value + adjustment.page_size >= adjustment.upper:
if adjustment.get_value() + adjustment.get_page_size() >= \
adjustment.get_upper():
can_scroll_next = False
else:
can_scroll_next = True
@ -409,7 +410,7 @@ class _IconWidget(Gtk.EventBox):
self._icon.show()
def do_expose_event(self, event):
palette = self.parent.palette
palette = self.get_parent().palette
if palette and palette.is_up():
invoker = palette.props.invoker
invoker.draw_rectangle(event, palette)

View File

@ -125,13 +125,14 @@ class Window(Gtk.Window):
even after invoking on response on non-gtk events.
See #1423.
"""
if self.window is None:
window = self.get_window()
if window is None:
self.show()
return
timestamp = Gtk.get_current_event_time()
if not timestamp:
timestamp = GdkX11.get_server_time(self.window)
self.window.focus(timestamp)
timestamp = GdkX11.get_server_time(window)
window.focus(timestamp)
def fullscreen(self):
palettegroup.popdown_all()
@ -238,7 +239,7 @@ class Window(Gtk.Window):
def __window_realize_cb(self, window):
group = Gtk.Window()
group.realize()
window.window.set_group(group.window)
window.get_window().set_group(group.get_window())
def __key_press_cb(self, widget, event):
key = Gdk.keyval_name(event.keyval)