From 15946211cfa8c884281928b90953d7b3d081695e Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Thu, 15 Dec 2011 01:23:18 +0000 Subject: [PATCH] Trivial GTK3 porting fixes Fix some trivial issues missed earlier: various missing imports, some minor API changes to adapt to, do_size_request simple porting, etc. Signed-off-by: Daniel Drake Acked-by: Simon Schampijer --- src/sugar3/activity/activity.py | 1 + src/sugar3/activity/namingalert.py | 9 +++++---- src/sugar3/datastore/datastore.py | 2 +- src/sugar3/graphics/alert.py | 11 +++++++---- src/sugar3/graphics/colorbutton.py | 4 +++- src/sugar3/graphics/combobox.py | 1 + src/sugar3/graphics/icon.py | 2 ++ src/sugar3/graphics/iconentry.py | 3 +++ src/sugar3/graphics/objectchooser.py | 1 + src/sugar3/graphics/panel.py | 1 + src/sugar3/graphics/toolbox.py | 7 ++++--- src/sugar3/graphics/tray.py | 26 +++++++++++++++----------- src/sugar3/graphics/window.py | 26 +++++++++++++------------- src/sugar3/wm.py | 4 ++-- 14 files changed, 59 insertions(+), 39 deletions(-) diff --git a/src/sugar3/activity/activity.py b/src/sugar3/activity/activity.py index 6e23b141..5e9986d0 100644 --- a/src/sugar3/activity/activity.py +++ b/src/sugar3/activity/activity.py @@ -58,6 +58,7 @@ from functools import partial from gi.repository import GConf from gi.repository import Gtk from gi.repository import Gdk +from gi.repository import GdkPixbuf from gi.repository import GObject import dbus import dbus.service diff --git a/src/sugar3/activity/namingalert.py b/src/sugar3/activity/namingalert.py index b697d042..09c0cb4f 100644 --- a/src/sugar3/activity/namingalert.py +++ b/src/sugar3/activity/namingalert.py @@ -20,6 +20,7 @@ import os from gi.repository import Gio from gi.repository import Gtk +from gi.repository import Gdk from gi.repository import GObject from gi.repository import GConf @@ -194,18 +195,18 @@ class NamingAlert(Gtk.Window): header = self._create_header() body.pack_start(header, False, False, style.DEFAULT_PADDING) - body.pack_start(self._create_separator(style.DEFAULT_SPACING, True, True, 0), False, False, 0) + body.pack_start(self._create_separator(style.DEFAULT_SPACING), False, False, 0) - body.pack_start(self._create_label(_('Description:', True, True, 0)), False, False, 0) + body.pack_start(self._create_label(_('Description:')), False, False, 0) description = self._activity.metadata.get('description', '') description_box, self._description = self._create_text_view(description) body.pack_start(description_box, True, True, 0) - body.pack_start(self._create_separator(style.DEFAULT_PADDING, True, True, 0), False, False, 0) + body.pack_start(self._create_separator(style.DEFAULT_PADDING), False, False, 0) - body.pack_start(self._create_label(_('Tags:', True, True, 0)), False, False, 0) + body.pack_start(self._create_label(_('Tags:')), False, False, 0) tags = self._activity.metadata.get('tags', '') tags_box, self._tags = self._create_text_view(tags) diff --git a/src/sugar3/datastore/datastore.py b/src/sugar3/datastore/datastore.py index 2ada4744..c7a741ed 100644 --- a/src/sugar3/datastore/datastore.py +++ b/src/sugar3/datastore/datastore.py @@ -231,7 +231,7 @@ class RawObject(object): 'uid': file_path, 'title': os.path.basename(file_path), 'timestamp': stat.st_mtime, - 'mime_type': Gio.content_type_guess(filename=file_path), + 'mime_type': Gio.content_type_guess(file_path, None)[0], 'activity': '', 'activity_id': '', 'icon-color': client.get_string('/desktop/sugar/user/color'), diff --git a/src/sugar3/graphics/alert.py b/src/sugar3/graphics/alert.py index e85598a3..16392cd0 100644 --- a/src/sugar3/graphics/alert.py +++ b/src/sugar3/graphics/alert.py @@ -354,10 +354,13 @@ class _TimeoutIcon(Gtk.Alignment): self._draw(context) return False - def do_size_request(self, requisition): - requisition.height, requisition.width = \ - Gtk.icon_size_lookup(Gtk.IconSize.BUTTON) - self._text.size_request() + def do_get_preferred_width(self): + width = Gtk.icon_size_lookup(Gtk.IconSize.BUTTON)[1] + return width, width + + def do_get_preferred_height(self): + height = Gtk.icon_size_lookup(Gtk.IconSize.BUTTON)[2] + return height, height def _draw(self, context): w = self.get_allocated_width() diff --git a/src/sugar3/graphics/colorbutton.py b/src/sugar3/graphics/colorbutton.py index fbda30da..9f490bb3 100644 --- a/src/sugar3/graphics/colorbutton.py +++ b/src/sugar3/graphics/colorbutton.py @@ -17,6 +17,8 @@ # Boston, MA 02111-1307, USA. import gettext +from gi.repository import Gdk +from gi.repository import GdkPixbuf from gi.repository import Gtk from gi.repository import GObject import struct @@ -261,7 +263,7 @@ class _ColorPalette(Palette): self._swatch_tray = Gtk.Table() self._picker_hbox.pack_start(self._swatch_tray, True, True, 0) - self._picker_hbox.pack_start(Gtk.VSeparator(, True, True, 0), + self._picker_hbox.pack_start(Gtk.VSeparator(), True, True, padding=style.DEFAULT_SPACING) self._chooser_table = Gtk.Table(3, 2) diff --git a/src/sugar3/graphics/combobox.py b/src/sugar3/graphics/combobox.py index 3b70f119..170c5281 100644 --- a/src/sugar3/graphics/combobox.py +++ b/src/sugar3/graphics/combobox.py @@ -21,6 +21,7 @@ STABLE. from gi.repository import GObject from gi.repository import Gtk +from gi.repository import GdkPixbuf class ComboBox(Gtk.ComboBox): diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py index 2d98f8a8..a1800c7e 100644 --- a/src/sugar3/graphics/icon.py +++ b/src/sugar3/graphics/icon.py @@ -27,6 +27,8 @@ import logging from gi.repository import GObject from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GdkPixbuf import cairo from sugar3.graphics import style diff --git a/src/sugar3/graphics/iconentry.py b/src/sugar3/graphics/iconentry.py index 6e1d3413..154dfd0d 100644 --- a/src/sugar3/graphics/iconentry.py +++ b/src/sugar3/graphics/iconentry.py @@ -15,7 +15,10 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. +from gi.repository import GObject from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GdkPixbuf from sugar3.graphics import style from sugar3.graphics.icon import _SVGLoader diff --git a/src/sugar3/graphics/objectchooser.py b/src/sugar3/graphics/objectchooser.py index ed59a942..a904f258 100644 --- a/src/sugar3/graphics/objectchooser.py +++ b/src/sugar3/graphics/objectchooser.py @@ -23,6 +23,7 @@ import logging from gi.repository import GObject from gi.repository import Gtk +from gi.repository import Gdk import dbus from sugar3.datastore import datastore diff --git a/src/sugar3/graphics/panel.py b/src/sugar3/graphics/panel.py index 0e3d76aa..c254c21c 100644 --- a/src/sugar3/graphics/panel.py +++ b/src/sugar3/graphics/panel.py @@ -20,6 +20,7 @@ STABLE. """ from gi.repository import Gtk +from gi.repository import GObject class Panel(Gtk.VBox): diff --git a/src/sugar3/graphics/toolbox.py b/src/sugar3/graphics/toolbox.py index e4e4c324..fedca0b0 100644 --- a/src/sugar3/graphics/toolbox.py +++ b/src/sugar3/graphics/toolbox.py @@ -50,7 +50,7 @@ class Toolbox(Gtk.VBox): self._separator.modify_bg(Gtk.StateType.NORMAL, style.COLOR_PANEL_GREY.get_gdk_color()) self._separator.set_size_request(1, style.TOOLBOX_SEPARATOR_HEIGHT) - self.pack_start(self._separator, False) + self.pack_start(self._separator, False, False, 0) self._notebook.connect('notify::page', self._notify_page_cb) @@ -59,8 +59,9 @@ class Toolbox(Gtk.VBox): def add_toolbar(self, name, toolbar): label = Gtk.Label(label=name) - width, height_ = label.size_request() - label.set_size_request(max(width, style.TOOLBOX_TAB_LABEL_WIDTH), -1) + req = label.size_request() + label.set_size_request(max(req.width, style.TOOLBOX_TAB_LABEL_WIDTH), + -1) label.set_alignment(0.0, 0.5) event_box = Gtk.EventBox() diff --git a/src/sugar3/graphics/tray.py b/src/sugar3/graphics/tray.py index 07bf3e2d..f4bfb831 100644 --- a/src/sugar3/graphics/tray.py +++ b/src/sugar3/graphics/tray.py @@ -76,14 +76,15 @@ class _TrayViewport(Gtk.Viewport): assert item in self.traybar.get_children() # Get the allocation, and make sure that it is visible + allocation = item.get_allocation() if self.orientation == Gtk.Orientation.HORIZONTAL: adj = self.get_hadjustment() - start = item.allocation.x - stop = item.allocation.x + item.allocation.width + start = allocation.x + stop = allocation.x + allocation.width else: adj = self.get_vadjustment() - start = item.allocation.y - stop = item.allocation.y + item.allocation.height + start = allocation.y + stop = allocation.y + allocation.height if start < adj.get_value(): adj.set_value(start) @@ -112,14 +113,17 @@ class _TrayViewport(Gtk.Viewport): 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() + def do_get_preferred_width(self): if self.orientation == Gtk.Orientation.HORIZONTAL: - requisition[0] = 0 - requisition[1] = child_requisition[1] - else: - requisition[0] = child_requisition[0] - requisition[1] = 0 + return Gtk.Viewport.do_get_preferred_width(self) + child_minimum, child_natural = self.get_child().get_preferred_size() + return child_minimum.width, child_natural.width + + def do_get_preferred_height(self): + if self.orientation != Gtk.Orientation.HORIZONTAL: + return Gtk.Viewport.do_get_preferred_width(self) + child_minimum, child_natural = self.get_child().get_preferred_size() + return child_minimum.height, child_natural.height def do_get_property(self, pspec): if pspec.name == 'scrollable': diff --git a/src/sugar3/graphics/window.py b/src/sugar3/graphics/window.py index 253b74c0..965aecd7 100644 --- a/src/sugar3/graphics/window.py +++ b/src/sugar3/graphics/window.py @@ -22,6 +22,7 @@ STABLE. from gi.repository import GObject from gi.repository import Gdk +from gi.repository import GdkX11 from gi.repository import Gtk import warnings @@ -35,7 +36,7 @@ _UNFULLSCREEN_BUTTON_VISIBILITY_TIMEOUT = 2 class UnfullscreenButton(Gtk.Window): def __init__(self): - GObject.GObject.__init__(self) + Gtk.Window.__init__(self) self.set_decorated(False) self.set_resizable(False) @@ -46,12 +47,10 @@ class UnfullscreenButton(Gtk.Window): self.props.accept_focus = False #Setup estimate of width, height - w, h = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) + valid_, w, h = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR) self._width = w self._height = h - self.connect('size-request', self._size_request_cb) - screen = self.get_screen() screen.connect('size-changed', self._screen_size_changed_cb) @@ -73,10 +72,11 @@ class UnfullscreenButton(Gtk.Window): x = Gdk.Screen.width() - self._width self.move(x, 0) - def _size_request_cb(self, widget, req): - self._width = req.width - self._height = req.height + def do_get_preferred_width(self): + minimum, natural = Gtk.Window.do_get_preferred_width(self) + self._width = minimum self._reposition() + return minimum, natural def _screen_size_changed_cb(self, screen): self._reposition() @@ -193,7 +193,7 @@ class Window(Gtk.Window): self.__vbox.remove(self._toolbar_box) if toolbar_box: - self.__vbox.pack_start(toolbar_box, False) + self.__vbox.pack_start(toolbar_box, False, False, 0) self.__vbox.reorder_child(toolbar_box, 0) self._toolbar_box = toolbar_box @@ -206,18 +206,18 @@ class Window(Gtk.Window): box.remove(self.tray) if position == Gtk.PositionType.LEFT: - self.__hbox.pack_start(tray, False) + self.__hbox.pack_start(tray, False, False, 0) elif position == Gtk.PositionType.RIGHT: - self.__hbox.pack_end(tray, False) + self.__hbox.pack_end(tray, False, False, 0) elif position == Gtk.PositionType.BOTTOM: - self.__vbox.pack_end(tray, False) + self.__vbox.pack_end(tray, False, False, 0) self.tray = tray def add_alert(self, alert): self._alerts.append(alert) if len(self._alerts) == 1: - self.__vbox.pack_start(alert, False) + self.__vbox.pack_start(alert, False, False, 0) if self._toolbar_box is not None: self.__vbox.reorder_child(alert, 1) else: @@ -230,7 +230,7 @@ class Window(Gtk.Window): if alert.get_parent() is not None: self.__vbox.remove(alert) if len(self._alerts) >= 1: - self.__vbox.pack_start(self._alerts[0], False) + self.__vbox.pack_start(self._alerts[0], False, False, 0) if self._toolbar_box is not None: self.__vbox.reorder_child(self._alerts[0], 1) else: diff --git a/src/sugar3/wm.py b/src/sugar3/wm.py index 66db65e1..f7bda6a8 100644 --- a/src/sugar3/wm.py +++ b/src/sugar3/wm.py @@ -82,9 +82,9 @@ def get_sugar_window_type(wnck_window): def set_activity_id(window, activity_id): _property_change_trapped(window, '_SUGAR_ACTIVITY_ID', 'STRING', 8, - Gdk.PROP_MODE_REPLACE, activity_id) + Gdk.PropMode.REPLACE, activity_id) def set_bundle_id(window, bundle_id): _property_change_trapped(window, '_SUGAR_BUNDLE_ID', 'STRING', 8, - Gdk.PROP_MODE_REPLACE, bundle_id) + Gdk.PropMode.REPLACE, bundle_id)