Run pygi-convert.sh for automatic conversion from GTK2 to GTK3 + pygi.

This is only on a best-effort basis; the code will be in a broken state after
this patch and need to be fixed manually.

The purpose of committing the intermediate, non-working output is to make it
reproducible. It's impractical to manually review the changes.

The exact version used was 4f637212f13b197a95c824967a58496b9e3b877c from the
main pygobject repository [1] plus a custom patch [2] that hasn't been sent
upstream yet.

[1] git://git.gnome.org/pygobject
[2] https://sascha.silbe.org/patches/pygobject-convert-sugar-20111122.patch

Signed-off-by: Sascha Silbe <silbe@activitycentral.com>
This commit is contained in:
Sascha Silbe 2011-11-15 19:29:07 +01:00 committed by Simon Schampijer
parent aed295ec4e
commit 820efa56b9
47 changed files with 818 additions and 818 deletions

View File

@ -1,4 +1,4 @@
import gtk from gi.repository import Gtk
from sugar3.graphics.radiopalette import RadioPalette, RadioMenuButton, \ from sugar3.graphics.radiopalette import RadioPalette, RadioMenuButton, \
RadioToolsButton RadioToolsButton
@ -6,16 +6,16 @@ from sugar3.graphics.radiotoolbutton import RadioToolButton
from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics import style from sugar3.graphics import style
window = gtk.Window() window = Gtk.Window()
box = gtk.VBox() box = Gtk.VBox()
window.add(box) window.add(box)
toolbar = gtk.Toolbar() toolbar = Gtk.Toolbar()
box.pack_start(toolbar, False) box.pack_start(toolbar, False)
text_view = gtk.TextView() text_view = Gtk.TextView()
box.pack_start(text_view) box.pack_start(text_view, True, True, 0)
def echo(button, label): def echo(button, label):
@ -72,4 +72,4 @@ button = RadioToolsButton(palette=palette)
toolbar.insert(button, -1) toolbar.insert(button, -1)
window.show_all() window.show_all()
gtk.main() Gtk.main()

View File

@ -1,41 +1,41 @@
import gtk from gi.repository import Gtk
from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton
from sugar3.graphics import style from sugar3.graphics import style
window = gtk.Window() window = Gtk.Window()
box = gtk.VBox() box = Gtk.VBox()
window.add(box) window.add(box)
toolbar = ToolbarBox() toolbar = ToolbarBox()
box.pack_start(toolbar, False) box.pack_start(toolbar, False)
tollbarbutton_1 = ToolbarButton( tollbarbutton_1 = ToolbarButton(
page=gtk.Button('sub-widget #1'), page=Gtk.Button('sub-widget #1'),
icon_name='computer-xo') icon_name='computer-xo')
toolbar.toolbar.insert(tollbarbutton_1, -1) toolbar.toolbar.insert(tollbarbutton_1, -1)
tollbarbutton_2 = ToolbarButton( tollbarbutton_2 = ToolbarButton(
page=gtk.Button('sub-widget #2'), page=Gtk.Button('sub-widget #2'),
icon_name='button_cancel', icon_name='button_cancel',
tooltip='with custom palette instead of sub-widget') tooltip='with custom palette instead of sub-widget')
toolbar.toolbar.insert(tollbarbutton_2, -1) toolbar.toolbar.insert(tollbarbutton_2, -1)
toolbar.toolbar.insert(gtk.SeparatorToolItem(), -1) toolbar.toolbar.insert(Gtk.SeparatorToolItem(), -1)
def del_cb(widget): def del_cb(widget):
toolbar.toolbar.remove(tollbarbutton_3) toolbar.toolbar.remove(tollbarbutton_3)
del_b = gtk.Button('delete sub-widget #3') del_b = Gtk.Button('delete sub-widget #3')
del_b.connect('clicked', del_cb) del_b.connect('clicked', del_cb)
tollbarbutton_3 = ToolbarButton( tollbarbutton_3 = ToolbarButton(
page=del_b, page=del_b,
icon_name='activity-journal') icon_name='activity-journal')
toolbar.toolbar.insert(tollbarbutton_3, -1) toolbar.toolbar.insert(tollbarbutton_3, -1)
subbar = gtk.Toolbar() subbar = Gtk.Toolbar()
subbutton = ToolButton( subbutton = ToolButton(
icon_name='document-send', icon_name='document-send',
tooltip='document-send') tooltip='document-send')
@ -48,4 +48,4 @@ tollbarbutton_4 = ToolbarButton(
toolbar.toolbar.insert(tollbarbutton_4, -1) toolbar.toolbar.insert(tollbarbutton_4, -1)
window.show_all() window.show_all()
gtk.main() Gtk.main()

View File

@ -55,9 +55,9 @@ import time
from hashlib import sha1 from hashlib import sha1
from functools import partial from functools import partial
import gconf from gi.repository import GConf
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
import dbus import dbus
import dbus.service import dbus.service
from dbus import PROPERTIES_IFACE from dbus import PROPERTIES_IFACE
@ -100,15 +100,15 @@ J_DBUS_INTERFACE = 'org.laptop.Journal'
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties' CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
class _ActivitySession(gobject.GObject): class _ActivitySession(GObject.GObject):
__gsignals__ = { __gsignals__ = {
'quit-requested': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'quit-requested': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'quit': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'quit': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
def __init__(self): def __init__(self):
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._xsmp_client = XSMPClient() self._xsmp_client = XSMPClient()
self._xsmp_client.connect('quit-requested', self._xsmp_client.connect('quit-requested',
@ -127,7 +127,7 @@ class _ActivitySession(gobject.GObject):
if len(self._activities) == 0: if len(self._activities) == 0:
logging.debug('Quitting the activity process.') logging.debug('Quitting the activity process.')
gtk.main_quit() Gtk.main_quit()
def will_quit(self, activity, will_quit): def will_quit(self, activity, will_quit):
if will_quit: if will_quit:
@ -150,7 +150,7 @@ class _ActivitySession(gobject.GObject):
self.emit('quit') self.emit('quit')
class Activity(Window, gtk.Container): class Activity(Window, Gtk.Container):
"""This is the base Activity class that all other Activities derive from. """This is the base Activity class that all other Activities derive from.
This is where your activity starts. This is where your activity starts.
@ -204,8 +204,8 @@ class Activity(Window, gtk.Container):
Finaly, your Activity will very likely need some activity specific Finaly, your Activity will very likely need some activity specific
buttons and options you can create your own toolbars by deriving a buttons and options you can create your own toolbars by deriving a
class from gtk.Toolbar: class from Gtk.Toolbar:
class MySpecialToolbar(gtk.Toolbar): class MySpecialToolbar(Gtk.Toolbar):
... ...
4. Use your creativity. Make your Activity something special and share 4. Use your creativity. Make your Activity something special and share
@ -221,11 +221,11 @@ class Activity(Window, gtk.Container):
__gtype_name__ = 'SugarActivity' __gtype_name__ = 'SugarActivity'
__gsignals__ = { __gsignals__ = {
'shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'shared': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'joined': (GObject.SignalFlags.RUN_FIRST, None, ([])),
# For internal use only, use can_close() if you want to perform extra # For internal use only, use can_close() if you want to perform extra
# checks before actually closing # checks before actually closing
'_closing': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), '_closing': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
def __init__(self, handle, create_jobject=True): def __init__(self, handle, create_jobject=True):
@ -248,7 +248,7 @@ class Activity(Window, gtk.Container):
Connects our "destroy" message to our _destroy_cb Connects our "destroy" message to our _destroy_cb
method. method.
Creates a base gtk.Window within this window. Creates a base Gtk.Window within this window.
Creates an ActivityService (self._bus) servicing Creates an ActivityService (self._bus) servicing
this application. this application.
@ -265,7 +265,7 @@ class Activity(Window, gtk.Container):
# screen. Would be better if it was the shell to do this, but we # screen. Would be better if it was the shell to do this, but we
# haven't found yet a good way to do it there. See #1263. # haven't found yet a good way to do it there. See #1263.
self.connect('window-state-event', self.__window_state_event_cb) self.connect('window-state-event', self.__window_state_event_cb)
screen = gtk.gdk.screen_get_default() screen = Gdk.Screen.get_default()
screen.connect('size-changed', self.__screen_size_changed_cb) screen.connect('size-changed', self.__screen_size_changed_cb)
self._adapt_window_to_screen() self._adapt_window_to_screen()
@ -298,7 +298,7 @@ class Activity(Window, gtk.Container):
self.__session_quit_requested_cb) self.__session_quit_requested_cb)
self._session.connect('quit', self.__session_quit_cb) self._session.connect('quit', self.__session_quit_cb)
accel_group = gtk.AccelGroup() accel_group = Gtk.AccelGroup()
self.set_data('sugar-accel-group', accel_group) self.set_data('sugar-accel-group', accel_group)
self.add_accel_group(accel_group) self.add_accel_group(accel_group)
@ -321,7 +321,7 @@ class Activity(Window, gtk.Container):
self._jobject = self._initialize_journal_object() self._jobject = self._initialize_journal_object()
if handle.invited: if handle.invited:
wait_loop = gobject.MainLoop() wait_loop = GObject.MainLoop()
self._client_handler = _ClientHandler( self._client_handler = _ClientHandler(
self.get_bundle_id(), self.get_bundle_id(),
partial(self.__got_channel_cb, wait_loop)) partial(self.__got_channel_cb, wait_loop))
@ -350,7 +350,7 @@ class Activity(Window, gtk.Container):
def _initialize_journal_object(self): def _initialize_journal_object(self):
title = _('%s Activity') % get_bundle_name() title = _('%s Activity') % get_bundle_name()
client = gconf.client_get_default() client = GConf.Client.get_default()
icon_color = client.get_string('/desktop/sugar/user/color') icon_color = client.get_string('/desktop/sugar/user/color')
jobject = datastore.create() jobject = datastore.create()
@ -433,7 +433,7 @@ class Activity(Window, gtk.Container):
if not self._active and self._jobject: if not self._active and self._jobject:
self.save() self.save()
active = gobject.property( active = GObject.property(
type=bool, default=False, getter=get_active, setter=set_active) type=bool, default=False, getter=get_active, setter=set_active)
def get_max_participants(self): def get_max_participants(self):
@ -442,7 +442,7 @@ class Activity(Window, gtk.Container):
def set_max_participants(self, participants): def set_max_participants(self, participants):
self._max_participants = participants self._max_participants = participants
max_participants = gobject.property( max_participants = GObject.property(
type=int, default=0, getter=get_max_participants, type=int, default=0, getter=get_max_participants,
setter=set_max_participants) setter=set_max_participants)
@ -468,7 +468,7 @@ class Activity(Window, gtk.Container):
"""Sets the 'work area' of your activity with the canvas of your """Sets the 'work area' of your activity with the canvas of your
choice. choice.
One commonly used canvas is gtk.ScrolledWindow One commonly used canvas is Gtk.ScrolledWindow
""" """
Window.set_canvas(self, canvas) Window.set_canvas(self, canvas)
if not self._read_file_called: if not self._read_file_called:
@ -483,7 +483,7 @@ class Activity(Window, gtk.Container):
self.move(0, 0) self.move(0, 0)
def _adapt_window_to_screen(self): def _adapt_window_to_screen(self):
screen = gtk.gdk.screen_get_default() screen = Gdk.Screen.get_default()
self.set_geometry_hints(None, self.set_geometry_hints(None,
screen.get_width(), screen.get_height(), screen.get_width(), screen.get_height(),
screen.get_width(), screen.get_height(), screen.get_width(), screen.get_height(),
@ -615,11 +615,11 @@ class Activity(Window, gtk.Container):
pixmap = self.canvas.get_snapshot((-1, -1, 0, 0)) pixmap = self.canvas.get_snapshot((-1, -1, 0, 0))
width, height = pixmap.get_size() width, height = pixmap.get_size()
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8, width, height) pixbuf = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, 0, 8, width, height)
pixbuf = pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), pixbuf = pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(),
0, 0, 0, 0, width, height) 0, 0, 0, 0, width, height)
pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225), pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225),
gtk.gdk.INTERP_BILINEAR) GdkPixbuf.InterpType.BILINEAR)
preview_data = [] preview_data = []
@ -814,10 +814,10 @@ class Activity(Window, gtk.Container):
alert.props.msg = _('Keep error: all changes will be lost') alert.props.msg = _('Keep error: all changes will be lost')
cancel_icon = Icon(icon_name='dialog-cancel') cancel_icon = Icon(icon_name='dialog-cancel')
alert.add_button(gtk.RESPONSE_CANCEL, _('Don\'t stop'), cancel_icon) alert.add_button(Gtk.ResponseType.CANCEL, _('Don\'t stop'), cancel_icon)
stop_icon = Icon(icon_name='dialog-ok') stop_icon = Icon(icon_name='dialog-ok')
alert.add_button(gtk.RESPONSE_OK, _('Stop anyway'), stop_icon) alert.add_button(Gtk.ResponseType.OK, _('Stop anyway'), stop_icon)
self.add_alert(alert) self.add_alert(alert)
alert.connect('response', self._keep_failed_dialog_response_cb) alert.connect('response', self._keep_failed_dialog_response_cb)
@ -826,7 +826,7 @@ class Activity(Window, gtk.Container):
def _keep_failed_dialog_response_cb(self, alert, response_id): def _keep_failed_dialog_response_cb(self, alert, response_id):
self.remove_alert(alert) self.remove_alert(alert)
if response_id == gtk.RESPONSE_OK: if response_id == Gtk.ResponseType.OK:
self.close(skip_save=True) self.close(skip_save=True)
if self._quit_requested: if self._quit_requested:
self._session.will_quit(self, True) self._session.will_quit(self, True)

View File

@ -26,7 +26,7 @@ import logging
import uuid import uuid
import dbus import dbus
import gobject from gi.repository import GObject
from sugar3.activity.activityhandle import ActivityHandle from sugar3.activity.activityhandle import ActivityHandle
from sugar3 import util from sugar3 import util
@ -148,7 +148,7 @@ def open_log_file(activity):
raise e raise e
class ActivityCreationHandler(gobject.GObject): class ActivityCreationHandler(GObject.GObject):
"""Sugar-side activity creation interface """Sugar-side activity creation interface
This object uses a dbus method on the ActivityFactory This object uses a dbus method on the ActivityFactory
@ -182,7 +182,7 @@ class ActivityCreationHandler(gobject.GObject):
If the file '/etc/olpc-security' exists, then activity launching If the file '/etc/olpc-security' exists, then activity launching
will be delegated to the prototype 'Rainbow' security service. will be delegated to the prototype 'Rainbow' security service.
""" """
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._bundle = bundle self._bundle = bundle
self._service_name = bundle.get_bundle_id() self._service_name = bundle.get_bundle_id()
@ -258,7 +258,7 @@ class ActivityCreationHandler(gobject.GObject):
stdout=log_file.fileno(), stdout=log_file.fileno(),
stderr=log_file.fileno()) stderr=log_file.fileno())
gobject.child_watch_add(child.pid, GObject.child_watch_add(child.pid,
_child_watch_cb, _child_watch_cb,
(environment_dir, log_file, (environment_dir, log_file,
self._handle.activity_id)) self._handle.activity_id))

View File

@ -17,7 +17,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import gconf from gi.repository import GConf
from gettext import gettext from gettext import gettext
import locale import locale
@ -135,7 +135,7 @@ def get_locale_path(bundle_id):
if 'SUGAR_LOCALEDIR' in os.environ: if 'SUGAR_LOCALEDIR' in os.environ:
candidate_dirs[os.environ['SUGAR_LOCALEDIR']] = 2 candidate_dirs[os.environ['SUGAR_LOCALEDIR']] = 2
gconf_client = gconf.client_get_default() gconf_client = GConf.Client.get_default()
package_dir = gconf_client.get_string('/desktop/sugar/i18n/langpackdir') package_dir = gconf_client.get_string('/desktop/sugar/i18n/langpackdir')
if package_dir is not None and package_dir is not '': if package_dir is not None and package_dir is not '':
candidate_dirs[package_dir] = 1 candidate_dirs[package_dir] = 1

View File

@ -18,10 +18,10 @@
import gettext import gettext
import os import os
import gio from gi.repository import Gio
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
import gconf from gi.repository import GConf
from sugar3.graphics import style from sugar3.graphics import style
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
@ -40,7 +40,7 @@ def _get_icon_name(metadata):
mime_type = metadata.get('mime_type', '') mime_type = metadata.get('mime_type', '')
if not file_name and mime_type: if not file_name and mime_type:
icons = gio.content_type_get_icon(mime_type) icons = Gio.content_type_get_icon(mime_type)
for icon_name in icons.props.names: for icon_name in icons.props.names:
file_name = get_icon_file_name(icon_name) file_name = get_icon_file_name(icon_name)
if file_name is not None: if file_name is not None:
@ -52,30 +52,30 @@ def _get_icon_name(metadata):
return file_name return file_name
class NamingToolbar(gtk.Toolbar): class NamingToolbar(Gtk.Toolbar):
""" Toolbar of the naming alert """ Toolbar of the naming alert
""" """
__gtype_name__ = 'SugarNamingToolbar' __gtype_name__ = 'SugarNamingToolbar'
__gsignals__ = { __gsignals__ = {
'keep-clicked': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'keep-clicked': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
def __init__(self): def __init__(self):
gtk.Toolbar.__init__(self) Gtk.Toolbar.__init__(self)
client = gconf.client_get_default() client = GConf.Client.get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color')) color = XoColor(client.get_string('/desktop/sugar/user/color'))
icon = Icon() icon = Icon()
icon.set_from_icon_name('activity-journal', icon.set_from_icon_name('activity-journal',
gtk.ICON_SIZE_LARGE_TOOLBAR) Gtk.IconSize.LARGE_TOOLBAR)
icon.props.xo_color = color icon.props.xo_color = color
self._add_widget(icon) self._add_widget(icon)
self._add_separator() self._add_separator()
self._title = gtk.Label(_('Name this entry')) self._title = Gtk.Label(label=_('Name this entry'))
self._add_widget(self._title) self._add_widget(self._title)
self._add_separator(True) self._add_separator(True)
@ -87,7 +87,7 @@ class NamingToolbar(gtk.Toolbar):
self._keep_button.show() self._keep_button.show()
def _add_separator(self, expand=False): def _add_separator(self, expand=False):
separator = gtk.SeparatorToolItem() separator = Gtk.SeparatorToolItem()
separator.props.draw = False separator.props.draw = False
if expand: if expand:
separator.set_expand(True) separator.set_expand(True)
@ -97,7 +97,7 @@ class NamingToolbar(gtk.Toolbar):
separator.show() separator.show()
def _add_widget(self, widget, expand=False): def _add_widget(self, widget, expand=False):
tool_item = gtk.ToolItem() tool_item = Gtk.ToolItem()
tool_item.set_expand(expand) tool_item.set_expand(expand)
tool_item.add(widget) tool_item.add(widget)
@ -110,11 +110,11 @@ class NamingToolbar(gtk.Toolbar):
self.emit('keep-clicked') self.emit('keep-clicked')
class FavoriteIcon(gtk.ToggleButton): class FavoriteIcon(Gtk.ToggleButton):
def __init__(self): def __init__(self):
gtk.ToggleButton.__init__(self) GObject.GObject.__init__(self)
self.set_relief(gtk.RELIEF_NONE) self.set_relief(Gtk.ReliefStyle.NONE)
self.set_focus_on_click(False) self.set_focus_on_click(False)
self._icon = Icon(icon_name='emblem-favorite', self._icon = Icon(icon_name='emblem-favorite',
@ -127,7 +127,7 @@ class FavoriteIcon(gtk.ToggleButton):
def __toggled_cb(self, widget): def __toggled_cb(self, widget):
if self.get_active(): if self.get_active():
client = gconf.client_get_default() client = GConf.Client.get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color')) color = XoColor(client.get_string('/desktop/sugar/user/color'))
self._icon.props.xo_color = color self._icon.props.xo_color = color
else: else:
@ -143,12 +143,12 @@ class FavoriteIcon(gtk.ToggleButton):
self._icon.props.fill_color = style.COLOR_TRANSPARENT.get_svg() self._icon.props.fill_color = style.COLOR_TRANSPARENT.get_svg()
class NamingAlert(gtk.Window): class NamingAlert(Gtk.Window):
__gtype_name__ = 'SugarNamingAlert' __gtype_name__ = 'SugarNamingAlert'
def __init__(self, activity, bundle_path): def __init__(self, activity, bundle_path):
gtk.Window.__init__(self) GObject.GObject.__init__(self)
self._bundle_path = bundle_path self._bundle_path = bundle_path
self._favorite_icon = None self._favorite_icon = None
@ -156,16 +156,16 @@ class NamingAlert(gtk.Window):
self._description = None self._description = None
self._tags = None self._tags = None
accel_group = gtk.AccelGroup() accel_group = Gtk.AccelGroup()
self.set_data('sugar-accel-group', accel_group) self.set_data('sugar-accel-group', accel_group)
self.add_accel_group(accel_group) self.add_accel_group(accel_group)
self.set_border_width(style.LINE_WIDTH) self.set_border_width(style.LINE_WIDTH)
offset = style.GRID_CELL_SIZE offset = style.GRID_CELL_SIZE
width = gtk.gdk.screen_width() - offset * 2 width = Gdk.Screen.width() - offset * 2
height = gtk.gdk.screen_height() - offset * 2 height = Gdk.Screen.height() - offset * 2
self.set_size_request(width, height) self.set_size_request(width, height)
self.set_position(gtk.WIN_POS_CENTER_ALWAYS) self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_decorated(False) self.set_decorated(False)
self.set_resizable(False) self.set_resizable(False)
self.set_modal(True) self.set_modal(True)
@ -173,7 +173,7 @@ class NamingAlert(gtk.Window):
self._activity = activity self._activity = activity
vbox = gtk.VBox() vbox = Gtk.VBox()
self.add(vbox) self.add(vbox)
vbox.show() vbox.show()
@ -189,23 +189,23 @@ class NamingAlert(gtk.Window):
self._title.grab_focus() self._title.grab_focus()
def _create_body(self): def _create_body(self):
body = gtk.VBox(spacing=style.DEFAULT_SPACING) body = Gtk.VBox(spacing=style.DEFAULT_SPACING)
body.set_border_width(style.DEFAULT_SPACING * 3) body.set_border_width(style.DEFAULT_SPACING * 3)
header = self._create_header() header = self._create_header()
body.pack_start(header, False, False, style.DEFAULT_PADDING) body.pack_start(header, False, False, style.DEFAULT_PADDING)
body.pack_start(self._create_separator(style.DEFAULT_SPACING), False, False, 0) body.pack_start(self._create_separator(style.DEFAULT_SPACING, True, True, 0), False, False, 0)
body.pack_start(self._create_label(_('Description:')), False, False, 0) body.pack_start(self._create_label(_('Description:', True, True, 0)), False, False, 0)
description = self._activity.metadata.get('description', '') description = self._activity.metadata.get('description', '')
description_box, self._description = self._create_text_view(description) description_box, self._description = self._create_text_view(description)
body.pack_start(description_box, True, True, 0) body.pack_start(description_box, True, True, 0)
body.pack_start(self._create_separator(style.DEFAULT_PADDING), False, False, 0) body.pack_start(self._create_separator(style.DEFAULT_PADDING, True, True, 0), False, False, 0)
body.pack_start(self._create_label(_('Tags:')), False, False, 0) body.pack_start(self._create_label(_('Tags:', True, True, 0)), False, False, 0)
tags = self._activity.metadata.get('tags', '') tags = self._activity.metadata.get('tags', '')
tags_box, self._tags = self._create_text_view(tags) tags_box, self._tags = self._create_text_view(tags)
@ -215,29 +215,29 @@ class NamingAlert(gtk.Window):
return body return body
def _create_label(self, text): def _create_label(self, text):
text = gtk.Label(text) text = Gtk.Label(label=text)
text.set_alignment(0, 0.5) text.set_alignment(0, 0.5)
text.modify_fg(gtk.STATE_NORMAL, text.modify_fg(Gtk.StateType.NORMAL,
style.COLOR_BUTTON_GREY.get_gdk_color()) style.COLOR_BUTTON_GREY.get_gdk_color())
return text return text
def _create_separator(self, height): def _create_separator(self, height):
separator = gtk.HSeparator() separator = Gtk.HSeparator()
separator.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color()) separator.modify_bg(Gtk.StateType.NORMAL, style.COLOR_WHITE.get_gdk_color())
separator.set_size_request(-1, height) separator.set_size_request(-1, height)
return separator return separator
def _create_header(self): def _create_header(self):
header = gtk.HBox(spacing=style.DEFAULT_SPACING) header = Gtk.HBox(spacing=style.DEFAULT_SPACING)
self._favorite_icon = FavoriteIcon() self._favorite_icon = FavoriteIcon()
header.pack_start(self._favorite_icon, expand=False) header.pack_start(self._favorite_icon, False, True, 0)
entry_icon = self._create_entry_icon() entry_icon = self._create_entry_icon()
header.pack_start(entry_icon, expand=False) header.pack_start(entry_icon, False, True, 0)
self._title = self._create_title() self._title = self._create_title()
header.pack_start(self._title, expand=True) header.pack_start(self._title, True, True, 0)
return header return header
@ -251,26 +251,26 @@ class NamingAlert(gtk.Window):
else: else:
activity_bundle = ActivityBundle(self._bundle_path) activity_bundle = ActivityBundle(self._bundle_path)
file_name = activity_bundle.get_icon() file_name = activity_bundle.get_icon()
entry_icon = Icon(file=file_name, icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) entry_icon = Icon(file=file_name, icon_size=Gtk.IconSize.LARGE_TOOLBAR)
if self._activity.metadata.get('icon-color'): if self._activity.metadata.get('icon-color'):
entry_icon.props.xo_color = XoColor( \ entry_icon.props.xo_color = XoColor( \
self._activity.metadata['icon-color']) self._activity.metadata['icon-color'])
return entry_icon return entry_icon
def _create_title(self): def _create_title(self):
title = gtk.Entry() title = Gtk.Entry()
title.set_text(self._activity.metadata.get('title', _('Untitled'))) title.set_text(self._activity.metadata.get('title', _('Untitled')))
return title return title
def _create_text_view(self, text): def _create_text_view(self, text):
scrolled_window = gtk.ScrolledWindow() scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scrolled_window.set_border_width(style.LINE_WIDTH) scrolled_window.set_border_width(style.LINE_WIDTH)
scrolled_window.set_shadow_type(gtk.SHADOW_IN) scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
text_view = gtk.TextView() text_view = Gtk.TextView()
text_view.set_left_margin(style.DEFAULT_PADDING) text_view.set_left_margin(style.DEFAULT_PADDING)
text_view.set_wrap_mode(gtk.WRAP_WORD_CHAR) text_view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
text_view.set_accepts_tab(False) text_view.set_accepts_tab(False)
text_view.get_buffer().set_text(text) text_view.get_buffer().set_text(text)
scrolled_window.add(text_view) scrolled_window.add(text_view)
@ -278,7 +278,7 @@ class NamingAlert(gtk.Window):
return scrolled_window, text_view return scrolled_window, text_view
def __realize_cb(self, widget): def __realize_cb(self, widget):
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
self.window.set_accept_focus(True) self.window.set_accept_focus(True)
def __keep_cb(self, widget): def __keep_cb(self, widget):

View File

@ -15,10 +15,10 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
from gtk import gdk from gi.repository import Gdk
import gtk from gi.repository import Gtk
import gettext import gettext
import gconf from gi.repository import GConf
import logging import logging
from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.toolbutton import ToolButton
@ -38,7 +38,7 @@ def _create_activity_icon(metadata):
if metadata is not None and metadata.get('icon-color'): if metadata is not None and metadata.get('icon-color'):
color = XoColor(metadata['icon-color']) color = XoColor(metadata['icon-color'])
else: else:
client = gconf.client_get_default() client = GConf.Client.get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color')) color = XoColor(client.get_string('/desktop/sugar/user/color'))
from sugar3.activity.activity import get_bundle_path from sugar3.activity.activity import get_bundle_path
@ -173,7 +173,7 @@ class KeepButton(ToolButton):
self.props.tooltip = _('Keep') self.props.tooltip = _('Keep')
self.props.accelerator = '<Ctrl>S' self.props.accelerator = '<Ctrl>S'
client = gconf.client_get_default() client = GConf.Client.get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color')) color = XoColor(client.get_string('/desktop/sugar/user/color'))
keep_icon = Icon(icon_name='document-save', xo_color=color) keep_icon = Icon(icon_name='document-save', xo_color=color)
keep_icon.show() keep_icon.show()
@ -185,14 +185,14 @@ class KeepButton(ToolButton):
activity.copy() activity.copy()
class TitleEntry(gtk.ToolItem): class TitleEntry(Gtk.ToolItem):
def __init__(self, activity, **kwargs): def __init__(self, activity, **kwargs):
gtk.ToolItem.__init__(self) Gtk.ToolItem.__init__(self)
self.set_expand(False) self.set_expand(False)
self.entry = gtk.Entry(**kwargs) self.entry = Gtk.Entry(**kwargs)
self.entry.set_size_request(int(gtk.gdk.screen_width() / 3), -1) self.entry.set_size_request(int(Gdk.Screen.width() / 3), -1)
self.entry.set_text(activity.metadata['title']) self.entry.set_text(activity.metadata['title'])
self.entry.connect('focus-out-event', self.__title_changed_cb, activity) self.entry.connect('focus-out-event', self.__title_changed_cb, activity)
self.entry.show() self.entry.show()
@ -202,11 +202,11 @@ class TitleEntry(gtk.ToolItem):
activity.connect('_closing', self.__closing_cb) activity.connect('_closing', self.__closing_cb)
def modify_bg(self, state, color): def modify_bg(self, state, color):
gtk.ToolItem.modify_bg(self, state, color) Gtk.ToolItem.modify_bg(self, state, color)
self.entry.modify_bg(state, color) self.entry.modify_bg(state, color)
def __jobject_updated_cb(self, jobject): def __jobject_updated_cb(self, jobject):
if self.entry.flags() & gtk.HAS_FOCUS: if self.entry.has_focus():
return return
if self.entry.get_text() == jobject['title']: if self.entry.get_text() == jobject['title']:
return return
@ -236,7 +236,7 @@ class TitleEntry(gtk.ToolItem):
shared_activity.props.name = title shared_activity.props.name = title
class ActivityToolbar(gtk.Toolbar): class ActivityToolbar(Gtk.Toolbar):
"""The Activity toolbar with the Journal entry title, sharing """The Activity toolbar with the Journal entry title, sharing
and Stop buttons and Stop buttons
@ -245,7 +245,7 @@ class ActivityToolbar(gtk.Toolbar):
""" """
def __init__(self, activity, orientation_left=False): def __init__(self, activity, orientation_left=False):
gtk.Toolbar.__init__(self) Gtk.Toolbar.__init__(self)
self._activity = activity self._activity = activity
@ -256,7 +256,7 @@ class ActivityToolbar(gtk.Toolbar):
self.title = title_button.entry self.title = title_button.entry
if orientation_left == False: if orientation_left == False:
separator = gtk.SeparatorToolItem() separator = Gtk.SeparatorToolItem()
separator.props.draw = False separator.props.draw = False
separator.set_expand(True) separator.set_expand(True)
self.insert(separator, -1) self.insert(separator, -1)
@ -274,7 +274,7 @@ class ActivityToolbar(gtk.Toolbar):
self.stop.show() self.stop.show()
class EditToolbar(gtk.Toolbar): class EditToolbar(Gtk.Toolbar):
"""Provides the standard edit toolbar for Activities. """Provides the standard edit toolbar for Activities.
Members: Members:
@ -309,7 +309,7 @@ class EditToolbar(gtk.Toolbar):
""" """
def __init__(self): def __init__(self):
gtk.Toolbar.__init__(self) Gtk.Toolbar.__init__(self)
self.undo = UndoButton() self.undo = UndoButton()
self.insert(self.undo, -1) self.insert(self.undo, -1)
@ -319,7 +319,7 @@ class EditToolbar(gtk.Toolbar):
self.insert(self.redo, -1) self.insert(self.redo, -1)
self.redo.show() self.redo.show()
self.separator = gtk.SeparatorToolItem() self.separator = Gtk.SeparatorToolItem()
self.separator.set_draw(True) self.separator.set_draw(True)
self.insert(self.separator, -1) self.insert(self.separator, -1)
self.separator.show() self.separator.show()

View File

@ -25,9 +25,9 @@ import time
from datetime import datetime from datetime import datetime
import os import os
import tempfile import tempfile
import gobject from gi.repository import GObject
import gconf from gi.repository import GConf
import gio from gi.repository import Gio
import dbus import dbus
import dbus.glib import dbus.glib
@ -77,14 +77,14 @@ updated = dispatch.Signal()
_get_data_store() _get_data_store()
class DSMetadata(gobject.GObject): class DSMetadata(GObject.GObject):
"""A representation of the metadata associated with a DS entry.""" """A representation of the metadata associated with a DS entry."""
__gsignals__ = { __gsignals__ = {
'updated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'updated': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
def __init__(self, properties=None): def __init__(self, properties=None):
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
if not properties: if not properties:
self._properties = {} self._properties = {}
else: else:
@ -226,12 +226,12 @@ class RawObject(object):
def __init__(self, file_path): def __init__(self, file_path):
stat = os.stat(file_path) stat = os.stat(file_path)
client = gconf.client_get_default() client = GConf.Client.get_default()
metadata = { metadata = {
'uid': file_path, 'uid': file_path,
'title': os.path.basename(file_path), 'title': os.path.basename(file_path),
'timestamp': stat.st_mtime, 'timestamp': stat.st_mtime,
'mime_type': gio.content_type_guess(filename=file_path), 'mime_type': Gio.content_type_guess(filename=file_path),
'activity': '', 'activity': '',
'activity_id': '', 'activity_id': '',
'icon-color': client.get_string('/desktop/sugar/user/color'), 'icon-color': client.get_string('/desktop/sugar/user/color'),

View File

@ -47,9 +47,9 @@ STABLE.
import gettext import gettext
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
import pango from gi.repository import Pango
import math import math
from sugar3.graphics import style from sugar3.graphics import style
@ -59,7 +59,7 @@ from sugar3.graphics.icon import Icon
_ = lambda msg: gettext.dgettext('sugar-toolkit', msg) _ = lambda msg: gettext.dgettext('sugar-toolkit', msg)
class Alert(gtk.EventBox): class Alert(Gtk.EventBox):
""" """
UI interface for Alerts UI interface for Alerts
@ -81,13 +81,13 @@ class Alert(gtk.EventBox):
__gtype_name__ = 'SugarAlert' __gtype_name__ = 'SugarAlert'
__gsignals__ = { __gsignals__ = {
'response': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object])), 'response': (GObject.SignalFlags.RUN_FIRST, None, ([object])),
} }
__gproperties__ = { __gproperties__ = {
'title': (str, None, None, None, gobject.PARAM_READWRITE), 'title': (str, None, None, None, GObject.PARAM_READWRITE),
'msg': (str, None, None, None, gobject.PARAM_READWRITE), 'msg': (str, None, None, None, GObject.PARAM_READWRITE),
'icon': (object, None, None, gobject.PARAM_WRITABLE), 'icon': (object, None, None, GObject.PARAM_WRITABLE),
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -97,26 +97,26 @@ class Alert(gtk.EventBox):
self._icon = None self._icon = None
self._buttons = {} self._buttons = {}
self._hbox = gtk.HBox() self._hbox = Gtk.HBox()
self._hbox.set_border_width(style.DEFAULT_SPACING) self._hbox.set_border_width(style.DEFAULT_SPACING)
self._hbox.set_spacing(style.DEFAULT_SPACING) self._hbox.set_spacing(style.DEFAULT_SPACING)
self._msg_box = gtk.VBox() self._msg_box = Gtk.VBox()
self._title_label = gtk.Label() self._title_label = Gtk.Label()
self._title_label.set_alignment(0, 0.5) self._title_label.set_alignment(0, 0.5)
self._msg_box.pack_start(self._title_label, False, False, 0) self._msg_box.pack_start(self._title_label, False, False, 0)
self._msg_label = gtk.Label() self._msg_label = Gtk.Label()
self._msg_label.set_alignment(0, 0.5) self._msg_label.set_alignment(0, 0.5)
self._msg_box.pack_start(self._msg_label, False, False, 0) self._msg_box.pack_start(self._msg_label, False, False, 0)
self._hbox.pack_start(self._msg_box, False, False, 0) self._hbox.pack_start(self._msg_box, False, False, 0)
self._buttons_box = gtk.HButtonBox() self._buttons_box = Gtk.HButtonBox()
self._buttons_box.set_layout(gtk.BUTTONBOX_END) self._buttons_box.set_layout(Gtk.ButtonBoxStyle.END)
self._buttons_box.set_spacing(style.DEFAULT_SPACING) self._buttons_box.set_spacing(style.DEFAULT_SPACING)
self._hbox.pack_start(self._buttons_box) self._hbox.pack_start(self._buttons_box, True, True, 0)
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
self.set_visible_window(True) self.set_visible_window(True)
self.add(self._hbox) self.add(self._hbox)
@ -189,22 +189,22 @@ class Alert(gtk.EventBox):
that will occure right to the buttom that will occure right to the buttom
icon : icon :
this can be a SugarIcon or a gtk.Image this can be a SugarIcon or a Gtk.Image
postion : postion :
the position of the button in the box (optional) the position of the button in the box (optional)
Returns Returns
------- -------
button :gtk.Button button :Gtk.Button
""" """
button = gtk.Button() button = Gtk.Button()
self._buttons[response_id] = button self._buttons[response_id] = button
if icon is not None: if icon is not None:
button.set_image(icon) button.set_image(icon)
button.set_label(label) button.set_label(label)
self._buttons_box.pack_start(button) self._buttons_box.pack_start(button, True, True, 0)
button.show() button.show()
button.connect('clicked', self.__button_clicked_cb, response_id) button.connect('clicked', self.__button_clicked_cb, response_id)
if position != -1: if position != -1:
@ -245,8 +245,8 @@ class ConfirmationAlert(Alert):
A confirmation alert is a nice shortcut from a standard Alert because it A confirmation alert is a nice shortcut from a standard Alert because it
comes with 'OK' and 'Cancel' buttons already built-in. When clicked, the comes with 'OK' and 'Cancel' buttons already built-in. When clicked, the
'OK' button will emit a response with a response_id of gtk.RESPONSE_OK, 'OK' button will emit a response with a response_id of Gtk.ResponseType.OK,
while the 'Cancel' button will emit gtk.RESPONSE_CANCEL. while the 'Cancel' button will emit Gtk.ResponseType.CANCEL.
Examples Examples
-------- --------
@ -273,9 +273,9 @@ class ConfirmationAlert(Alert):
self.remove_alert(alert) self.remove_alert(alert)
#Do any work that is specific to the type of button clicked. #Do any work that is specific to the type of button clicked.
if response_id is gtk.RESPONSE_OK: if response_id is Gtk.ResponseType.OK:
print 'Ok Button was clicked. Do any work upon ok here ...' print 'Ok Button was clicked. Do any work upon ok here ...'
elif response_id is gtk.RESPONSE_CANCEL: elif response_id is Gtk.ResponseType.CANCEL:
print 'Cancel Button was clicked.' print 'Cancel Button was clicked.'
""" """
@ -284,11 +284,11 @@ class ConfirmationAlert(Alert):
Alert.__init__(self, **kwargs) Alert.__init__(self, **kwargs)
icon = Icon(icon_name='dialog-cancel') icon = Icon(icon_name='dialog-cancel')
self.add_button(gtk.RESPONSE_CANCEL, _('Cancel'), icon) self.add_button(Gtk.ResponseType.CANCEL, _('Cancel'), icon)
icon.show() icon.show()
icon = Icon(icon_name='dialog-ok') icon = Icon(icon_name='dialog-ok')
self.add_button(gtk.RESPONSE_OK, _('Ok'), icon) self.add_button(Gtk.ResponseType.OK, _('Ok'), icon)
icon.show() icon.show()
@ -298,7 +298,7 @@ class ErrorAlert(Alert):
An error alert is a nice shortcut from a standard Alert because it An error alert is a nice shortcut from a standard Alert because it
comes with the 'OK' button already built-in. When clicked, the comes with the 'OK' button already built-in. When clicked, the
'OK' button will emit a response with a response_id of gtk.RESPONSE_OK. 'OK' button will emit a response with a response_id of Gtk.ResponseType.OK.
Examples Examples
-------- --------
@ -325,7 +325,7 @@ class ErrorAlert(Alert):
self.remove_alert(alert) self.remove_alert(alert)
#Do any work that is specific to the response_id. #Do any work that is specific to the response_id.
if response_id is gtk.RESPONSE_OK: if response_id is Gtk.ResponseType.OK:
print 'Ok Button was clicked. Do any work upon ok here ...' print 'Ok Button was clicked. Do any work upon ok here ...'
""" """
@ -334,33 +334,33 @@ class ErrorAlert(Alert):
Alert.__init__(self, **kwargs) Alert.__init__(self, **kwargs)
icon = Icon(icon_name='dialog-ok') icon = Icon(icon_name='dialog-ok')
self.add_button(gtk.RESPONSE_OK, _('Ok'), icon) self.add_button(Gtk.ResponseType.OK, _('Ok'), icon)
icon.show() icon.show()
class _TimeoutIcon(gtk.Alignment): class _TimeoutIcon(Gtk.Alignment):
__gtype_name__ = 'SugarTimeoutIcon' __gtype_name__ = 'SugarTimeoutIcon'
def __init__(self): def __init__(self):
gtk.Alignment.__init__(self, 0, 0, 1, 1) GObject.GObject.__init__(self, 0, 0, 1, 1)
self.set_app_paintable(True) self.set_app_paintable(True)
self._text = gtk.Label() self._text = Gtk.Label()
self._text.set_alignment(0.5, 0.5) self._text.set_alignment(0.5, 0.5)
attrlist = pango.AttrList() attrlist = Pango.AttrList()
attrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD)) attrlist.insert(Pango.AttrWeight(Pango.Weight.BOLD))
self._text.set_attributes(attrlist) self._text.set_attributes(attrlist)
self.add(self._text) self.add(self._text)
self._text.show() self._text.show()
self.connect("expose_event", self.__expose_cb) self.connect("expose_event", self.__expose_cb)
def __expose_cb(self, widget, event): def __expose_cb(self, widget, event):
context = widget.window.cairo_create() context = widget.get_window().cairo_create()
self._draw(context) self._draw(context)
return False return False
def do_size_request(self, requisition): def do_size_request(self, requisition):
requisition.height, requisition.width = \ requisition.height, requisition.width = \
gtk.icon_size_lookup(gtk.ICON_SIZE_BUTTON) Gtk.icon_size_lookup(Gtk.IconSize.BUTTON)
self._text.size_request() self._text.size_request()
def _draw(self, context): def _draw(self, context):
@ -410,9 +410,9 @@ class TimeoutAlert(Alert):
self.remove_alert(alert) self.remove_alert(alert)
#Do any work that is specific to the type of button clicked. #Do any work that is specific to the type of button clicked.
if response_id is gtk.RESPONSE_OK: if response_id is Gtk.ResponseType.OK:
print 'Ok Button was clicked. Do any work upon ok here ...' print 'Ok Button was clicked. Do any work upon ok here ...'
elif response_id is gtk.RESPONSE_CANCEL: elif response_id is Gtk.ResponseType.CANCEL:
print 'Cancel Button was clicked.' print 'Cancel Button was clicked.'
elif response_id == -1: elif response_id == -1:
print 'Timout occurred' print 'Timout occurred'
@ -425,21 +425,21 @@ class TimeoutAlert(Alert):
self._timeout = timeout self._timeout = timeout
icon = Icon(icon_name='dialog-cancel') icon = Icon(icon_name='dialog-cancel')
self.add_button(gtk.RESPONSE_CANCEL, _('Cancel'), icon) self.add_button(Gtk.ResponseType.CANCEL, _('Cancel'), icon)
icon.show() icon.show()
self._timeout_text = _TimeoutIcon() self._timeout_text = _TimeoutIcon()
self._timeout_text.set_text(self._timeout) self._timeout_text.set_text(self._timeout)
self.add_button(gtk.RESPONSE_OK, _('Continue'), self._timeout_text) self.add_button(Gtk.ResponseType.OK, _('Continue'), self._timeout_text)
self._timeout_text.show() self._timeout_text.show()
gobject.timeout_add_seconds(1, self.__timeout) GObject.timeout_add_seconds(1, self.__timeout)
def __timeout(self): def __timeout(self):
self._timeout -= 1 self._timeout -= 1
self._timeout_text.set_text(self._timeout) self._timeout_text.set_text(self._timeout)
if self._timeout == 0: if self._timeout == 0:
self._response(gtk.RESPONSE_OK) self._response(Gtk.ResponseType.OK)
return False return False
return True return True
@ -475,15 +475,15 @@ class NotifyAlert(Alert):
self._timeout_text = _TimeoutIcon() self._timeout_text = _TimeoutIcon()
self._timeout_text.set_text(self._timeout) self._timeout_text.set_text(self._timeout)
self.add_button(gtk.RESPONSE_OK, _('Ok'), self._timeout_text) self.add_button(Gtk.ResponseType.OK, _('Ok'), self._timeout_text)
self._timeout_text.show() self._timeout_text.show()
gobject.timeout_add(1000, self.__timeout) GObject.timeout_add(1000, self.__timeout)
def __timeout(self): def __timeout(self):
self._timeout -= 1 self._timeout -= 1
self._timeout_text.set_text(self._timeout) self._timeout_text.set_text(self._timeout)
if self._timeout == 0: if self._timeout == 0:
self._response(gtk.RESPONSE_OK) self._response(Gtk.ResponseType.OK)
return False return False
return True return True

View File

@ -21,20 +21,20 @@ STABLE.
import time import time
import gobject from gi.repository import GObject
EASE_OUT_EXPO = 0 EASE_OUT_EXPO = 0
EASE_IN_EXPO = 1 EASE_IN_EXPO = 1
class Animator(gobject.GObject): class Animator(GObject.GObject):
__gsignals__ = { __gsignals__ = {
'completed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'completed': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
def __init__(self, duration, fps=20, easing=EASE_OUT_EXPO): def __init__(self, duration, fps=20, easing=EASE_OUT_EXPO):
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._animations = [] self._animations = []
self._duration = duration self._duration = duration
self._interval = 1.0 / fps self._interval = 1.0 / fps
@ -80,7 +80,7 @@ class Animator(gobject.GObject):
self.stop() self.stop()
self._start_time = time.time() self._start_time = time.time()
self._timeout_sid = gobject.timeout_add( self._timeout_sid = GObject.timeout_add(
int(self._interval * 1000), self._next_frame_cb) int(self._interval * 1000), self._next_frame_cb)
def stop(self): def stop(self):
@ -95,7 +95,7 @@ class Animator(gobject.GObject):
""" """
if self._timeout_sid: if self._timeout_sid:
gobject.source_remove(self._timeout_sid) GObject.source_remove(self._timeout_sid)
self._timeout_sid = 0 self._timeout_sid = 0
self.emit('completed') self.emit('completed')

View File

@ -17,8 +17,8 @@
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import gettext import gettext
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
import struct import struct
import logging import logging
@ -35,8 +35,8 @@ def get_svg_color_string(color):
color.blue / 257) color.blue / 257)
class _ColorButton(gtk.Button): class _ColorButton(Gtk.Button):
"""This is a ColorButton for Sugar. It is similar to the gtk.ColorButton, """This is a ColorButton for Sugar. It is similar to the Gtk.ColorButton,
but does not have any alpha support. but does not have any alpha support.
Instead of a color selector dialog it will pop up a Sugar palette. Instead of a color selector dialog it will pop up a Sugar palette.
@ -45,37 +45,37 @@ class _ColorButton(gtk.Button):
""" """
__gtype_name__ = 'SugarColorButton' __gtype_name__ = 'SugarColorButton'
__gsignals__ = {'color-set': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, __gsignals__ = {'color-set': (GObject.SignalFlags.RUN_FIRST, None,
tuple())} tuple())}
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._title = _('Choose a color') self._title = _('Choose a color')
self._color = gtk.gdk.Color(0, 0, 0) self._color = Gdk.Color(0, 0, 0)
self._has_palette = True self._has_palette = True
self._has_invoker = True self._has_invoker = True
self._palette = None self._palette = None
self._accept_drag = True self._accept_drag = True
self._preview = Icon(icon_name='color-preview', self._preview = Icon(icon_name='color-preview',
icon_size=gtk.ICON_SIZE_BUTTON) icon_size=Gtk.IconSize.BUTTON)
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
if self._accept_drag: if self._accept_drag:
self.drag_dest_set(gtk.DEST_DEFAULT_MOTION | Gtk.drag_dest_set(self, Gtk.DEST_DEFAULT_MOTION |
gtk.DEST_DEFAULT_HIGHLIGHT | Gtk.DEST_DEFAULT_HIGHLIGHT |
gtk.DEST_DEFAULT_DROP, Gtk.DEST_DEFAULT_DROP,
[('application/x-color', 0, 0)], [('application/x-color', 0, 0)],
gtk.gdk.ACTION_COPY) Gdk.DragAction.COPY)
self.drag_source_set(gtk.gdk.BUTTON1_MASK | gtk.gdk.BUTTON3_MASK, self.drag_source_set(Gdk.EventMask.BUTTON1_MASK | Gdk.EventMask.BUTTON3_MASK,
[('application/x-color', 0, 0)], [('application/x-color', 0, 0)],
gtk.gdk.ACTION_COPY) Gdk.DragAction.COPY)
self.connect('drag_data_received', self.__drag_data_received_cb) self.connect('drag_data_received', self.__drag_data_received_cb)
self.connect('drag_data_get', self.__drag_data_get_cb) self.connect('drag_data_get', self.__drag_data_get_cb)
self._preview.fill_color = get_svg_color_string(self._color) self._preview.fill_color = get_svg_color_string(self._color)
self._preview.stroke_color = \ self._preview.stroke_color = \
get_svg_color_string(self.style.fg[gtk.STATE_NORMAL]) get_svg_color_string(self.style.fg[Gtk.StateType.NORMAL])
self.set_image(self._preview) self.set_image(self._preview)
if self._has_palette and self._has_invoker: if self._has_palette and self._has_invoker:
@ -102,7 +102,7 @@ class _ColorButton(gtk.Button):
def do_style_set(self, previous_style): def do_style_set(self, previous_style):
self._preview.stroke_color = \ self._preview.stroke_color = \
get_svg_color_string(self.style.fg[gtk.STATE_NORMAL]) get_svg_color_string(self.style.fg[Gtk.StateType.NORMAL])
def do_clicked(self): def do_clicked(self):
if self._palette: if self._palette:
@ -114,14 +114,14 @@ class _ColorButton(gtk.Button):
return True return True
def set_color(self, color): def set_color(self, color):
assert isinstance(color, gtk.gdk.Color) assert isinstance(color, Gdk.Color)
if self._color.red == color.red and \ if self._color.red == color.red and \
self._color.green == color.green and \ self._color.green == color.green and \
self._color.blue == color.blue: self._color.blue == color.blue:
return return
self._color = gtk.gdk.Color(color.red, color.green, color.blue) self._color = Gdk.Color(color.red, color.green, color.blue)
self._preview.fill_color = get_svg_color_string(self._color) self._preview.fill_color = get_svg_color_string(self._color)
if self._palette: if self._palette:
self._palette.props.color = self._color self._palette.props.color = self._color
@ -130,7 +130,7 @@ class _ColorButton(gtk.Button):
def get_color(self): def get_color(self):
return self._color return self._color
color = gobject.property(type=object, getter=get_color, setter=set_color) color = GObject.property(type=object, getter=get_color, setter=set_color)
def set_icon_name(self, icon_name): def set_icon_name(self, icon_name):
self._preview.props.icon_name = icon_name self._preview.props.icon_name = icon_name
@ -138,7 +138,7 @@ class _ColorButton(gtk.Button):
def get_icon_name(self): def get_icon_name(self):
return self._preview.props.icon_name return self._preview.props.icon_name
icon_name = gobject.property(type=str, icon_name = GObject.property(type=str,
getter=get_icon_name, setter=set_icon_name) getter=get_icon_name, setter=set_icon_name)
def set_icon_size(self, icon_size): def set_icon_size(self, icon_size):
@ -147,7 +147,7 @@ class _ColorButton(gtk.Button):
def get_icon_size(self): def get_icon_size(self):
return self._preview.props.icon_size return self._preview.props.icon_size
icon_size = gobject.property(type=int, icon_size = GObject.property(type=int,
getter=get_icon_size, setter=set_icon_size) getter=get_icon_size, setter=set_icon_size)
def set_title(self, title): def set_title(self, title):
@ -158,7 +158,7 @@ class _ColorButton(gtk.Button):
def get_title(self): def get_title(self):
return self._title return self._title
title = gobject.property(type=str, getter=get_title, setter=set_title) title = GObject.property(type=str, getter=get_title, setter=set_title)
def _set_has_invoker(self, has_invoker): def _set_has_invoker(self, has_invoker):
self._has_invoker = has_invoker self._has_invoker = has_invoker
@ -166,9 +166,9 @@ class _ColorButton(gtk.Button):
def _get_has_invoker(self): def _get_has_invoker(self):
return self._has_invoker return self._has_invoker
has_invoker = gobject.property(type=bool, default=True, has_invoker = GObject.property(type=bool, default=True,
flags=gobject.PARAM_READWRITE | flags=GObject.PARAM_READWRITE |
gobject.PARAM_CONSTRUCT_ONLY, GObject.PARAM_CONSTRUCT_ONLY,
getter=_get_has_invoker, getter=_get_has_invoker,
setter=_set_has_invoker) setter=_set_has_invoker)
@ -178,9 +178,9 @@ class _ColorButton(gtk.Button):
def _get_has_palette(self): def _get_has_palette(self):
return self._has_palette return self._has_palette
has_palette = gobject.property(type=bool, default=True, has_palette = GObject.property(type=bool, default=True,
flags=gobject.PARAM_READWRITE | flags=GObject.PARAM_READWRITE |
gobject.PARAM_CONSTRUCT_ONLY, GObject.PARAM_CONSTRUCT_ONLY,
getter=_get_has_palette, getter=_get_has_palette,
setter=_set_has_palette) setter=_set_has_palette)
@ -190,15 +190,15 @@ class _ColorButton(gtk.Button):
def _get_accept_drag(self): def _get_accept_drag(self):
return self._accept_drag return self._accept_drag
accept_drag = gobject.property(type=bool, default=True, accept_drag = GObject.property(type=bool, default=True,
flags=gobject.PARAM_READWRITE | flags=GObject.PARAM_READWRITE |
gobject.PARAM_CONSTRUCT_ONLY, GObject.PARAM_CONSTRUCT_ONLY,
getter=_get_accept_drag, getter=_get_accept_drag,
setter=_set_accept_drag) setter=_set_accept_drag)
def __drag_begin_cb(self, widget, context): def __drag_begin_cb(self, widget, context):
# Drag and Drop # Drag and Drop
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, pixbuf = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, True, 8,
style.SMALL_ICON_SIZE, style.SMALL_ICON_SIZE,
style.SMALL_ICON_SIZE) style.SMALL_ICON_SIZE)
@ -226,7 +226,7 @@ class _ColorButton(gtk.Button):
blue = struct.unpack_from('=H', dropped, 4)[0] blue = struct.unpack_from('=H', dropped, 4)[0]
# dropped[6] and dropped[7] is alpha, but we ignore the alpha channel # dropped[6] and dropped[7] is alpha, but we ignore the alpha channel
color = gtk.gdk.Color(red, green, blue) color = Gdk.Color(red, green, blue)
self.set_color(color) self.set_color(color)
@ -242,11 +242,11 @@ class _ColorPalette(Palette):
# The color-set signal is emitted when the user is finished selecting # The color-set signal is emitted when the user is finished selecting
# a color. # a color.
__gsignals__ = {'color-set': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, __gsignals__ = {'color-set': (GObject.SignalFlags.RUN_FIRST, None,
tuple())} tuple())}
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._color = gtk.gdk.Color(0, 0, 0) self._color = Gdk.Color(0, 0, 0)
self._previous_color = self._color.copy() self._previous_color = self._color.copy()
self._scales = None self._scales = None
@ -255,16 +255,16 @@ class _ColorPalette(Palette):
self.connect('popup', self.__popup_cb) self.connect('popup', self.__popup_cb)
self.connect('popdown', self.__popdown_cb) self.connect('popdown', self.__popdown_cb)
self._picker_hbox = gtk.HBox() self._picker_hbox = Gtk.HBox()
self.set_content(self._picker_hbox) self.set_content(self._picker_hbox)
self._swatch_tray = gtk.Table() self._swatch_tray = Gtk.Table()
self._picker_hbox.pack_start(self._swatch_tray) self._picker_hbox.pack_start(self._swatch_tray, True, True, 0)
self._picker_hbox.pack_start(gtk.VSeparator(), self._picker_hbox.pack_start(Gtk.VSeparator(, True, True, 0),
padding=style.DEFAULT_SPACING) padding=style.DEFAULT_SPACING)
self._chooser_table = gtk.Table(3, 2) self._chooser_table = Gtk.Table(3, 2)
self._chooser_table.set_col_spacing(0, style.DEFAULT_PADDING) self._chooser_table.set_col_spacing(0, style.DEFAULT_PADDING)
self._scales = [] self._scales = []
@ -282,9 +282,9 @@ class _ColorPalette(Palette):
self._build_swatches() self._build_swatches()
def _create_color_scale(self, text, color, row): def _create_color_scale(self, text, color, row):
label = gtk.Label(text) label = Gtk.Label(label=text)
label.props.xalign = 1.0 label.props.xalign = 1.0
scale = gtk.HScale() scale = Gtk.HScale()
scale.set_size_request(style.zoom(250), -1) scale.set_size_request(style.zoom(250), -1)
scale.set_draw_value(False) scale.set_draw_value(False)
scale.set_range(0, 1.0) scale.set_range(0, 1.0)
@ -322,10 +322,10 @@ class _ColorPalette(Palette):
self._swatch_tray.props.n_columns = (len(colors) + rows - 1) / rows self._swatch_tray.props.n_columns = (len(colors) + rows - 1) / rows
for color in colors: for color in colors:
button = _ColorButton(has_palette=False, button = _ColorButton(has_palette=False,
color=gtk.gdk.color_parse(color), color=Gdk.color_parse(color),
accept_drag=False, accept_drag=False,
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) icon_size=Gtk.IconSize.LARGE_TOOLBAR)
button.set_relief(gtk.RELIEF_NONE) button.set_relief(Gtk.ReliefStyle.NONE)
self._swatch_tray.attach(button, self._swatch_tray.attach(button,
i % rows, i % rows + 1, i % rows, i % rows + 1,
i / rows, i / rows + 1, i / rows, i / rows + 1,
@ -352,11 +352,11 @@ class _ColorPalette(Palette):
self.color = new_color self.color = new_color
def do_key_press_event(self, event): def do_key_press_event(self, event):
if event.keyval == gtk.keysyms.Escape: if event.keyval == Gdk.KEY_Escape:
self.props.color = self._previous_color self.props.color = self._previous_color
self.popdown(immediate=True) self.popdown(immediate=True)
return True return True
elif event.keyval == gtk.keysyms.Return: elif event.keyval == Gdk.KEY_Return:
self.popdown(immediate=True) self.popdown(immediate=True)
return True return True
return False return False
@ -365,7 +365,7 @@ class _ColorPalette(Palette):
self.props.color = button.get_color() self.props.color = button.get_color()
def set_color(self, color): def set_color(self, color):
assert isinstance(color, gtk.gdk.Color) assert isinstance(color, Gdk.Color)
if self._color.red == color.red and \ if self._color.red == color.red and \
self._color.green == color.green and \ self._color.green == color.green and \
@ -384,26 +384,26 @@ class _ColorPalette(Palette):
def get_color(self): def get_color(self):
return self._color return self._color
color = gobject.property(type=object, getter=get_color, setter=set_color) color = GObject.property(type=object, getter=get_color, setter=set_color)
def _add_accelerator(tool_button): def _add_accelerator(tool_button):
if not tool_button.props.accelerator or not tool_button.get_toplevel() or \ if not tool_button.props.accelerator or not tool_button.get_toplevel() or \
not tool_button.child: not tool_button.get_child():
return return
# TODO: should we remove the accelerator from the prev top level? # TODO: should we remove the accelerator from the prev top level?
accel_group = tool_button.get_toplevel().get_data('sugar-accel-group') accel_group = tool_button.get_toplevel().get_data('sugar-accel-group')
if not accel_group: if not accel_group:
logging.warning('No gtk.AccelGroup in the top level window.') logging.warning('No Gtk.AccelGroup in the top level window.')
return return
keyval, mask = gtk.accelerator_parse(tool_button.props.accelerator) keyval, mask = Gtk.accelerator_parse(tool_button.props.accelerator)
# the accelerator needs to be set at the child, so the gtk.AccelLabel # the accelerator needs to be set at the child, so the Gtk.AccelLabel
# in the palette can pick it up. # in the palette can pick it up.
tool_button.child.add_accelerator('clicked', accel_group, keyval, mask, tool_button.get_child().add_accelerator('clicked', accel_group, keyval, mask,
gtk.ACCEL_LOCKED | gtk.ACCEL_VISIBLE) Gtk.AccelFlags.LOCKED | Gtk.AccelFlags.VISIBLE)
def _hierarchy_changed_cb(tool_button, previous_toplevel): def _hierarchy_changed_cb(tool_button, previous_toplevel):
@ -415,13 +415,13 @@ def setup_accelerator(tool_button):
tool_button.connect('hierarchy-changed', _hierarchy_changed_cb) tool_button.connect('hierarchy-changed', _hierarchy_changed_cb)
class ColorToolButton(gtk.ToolItem): class ColorToolButton(Gtk.ToolItem):
# This not ideal. It would be better to subclass gtk.ToolButton, however # This not ideal. It would be better to subclass Gtk.ToolButton, however
# the python bindings do not seem to be powerfull enough for that. # the python bindings do not seem to be powerfull enough for that.
# (As we need to change a variable in the class structure.) # (As we need to change a variable in the class structure.)
__gtype_name__ = 'SugarColorToolButton' __gtype_name__ = 'SugarColorToolButton'
__gsignals__ = {'color-set': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, __gsignals__ = {'color-set': (GObject.SignalFlags.RUN_FIRST, None,
tuple())} tuple())}
def __init__(self, icon_name='color-preview', **kwargs): def __init__(self, icon_name='color-preview', **kwargs):
@ -430,16 +430,16 @@ class ColorToolButton(gtk.ToolItem):
self._palette_invoker = ToolInvoker() self._palette_invoker = ToolInvoker()
self._palette = None self._palette = None
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
# The gtk.ToolButton has already added a normal button. # The Gtk.ToolButton has already added a normal button.
# Replace it with a ColorButton # Replace it with a ColorButton
color_button = _ColorButton(icon_name=icon_name, has_invoker=False) color_button = _ColorButton(icon_name=icon_name, has_invoker=False)
self.add(color_button) self.add(color_button)
# The following is so that the behaviour on the toolbar is correct. # The following is so that the behaviour on the toolbar is correct.
color_button.set_relief(gtk.RELIEF_NONE) color_button.set_relief(Gtk.ReliefStyle.NONE)
color_button.icon_size = gtk.ICON_SIZE_LARGE_TOOLBAR color_button.icon_size = Gtk.IconSize.LARGE_TOOLBAR
self._palette_invoker.attach_tool(self) self._palette_invoker.attach_tool(self)
@ -463,7 +463,7 @@ class ColorToolButton(gtk.ToolItem):
def get_accelerator(self): def get_accelerator(self):
return self._accelerator return self._accelerator
accelerator = gobject.property(type=str, setter=set_accelerator, accelerator = GObject.property(type=str, setter=set_accelerator,
getter=get_accelerator) getter=get_accelerator)
def create_palette(self): def create_palette(self):
@ -477,7 +477,7 @@ class ColorToolButton(gtk.ToolItem):
self._palette_invoker.detach() self._palette_invoker.detach()
self._palette_invoker = palette_invoker self._palette_invoker = palette_invoker
palette_invoker = gobject.property( palette_invoker = GObject.property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker) type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def set_color(self, color): def set_color(self, color):
@ -486,7 +486,7 @@ class ColorToolButton(gtk.ToolItem):
def get_color(self): def get_color(self):
return self.get_child().props.color return self.get_child().props.color
color = gobject.property(type=object, getter=get_color, setter=set_color) color = GObject.property(type=object, getter=get_color, setter=set_color)
def set_icon_name(self, icon_name): def set_icon_name(self, icon_name):
self.get_child().props.icon_name = icon_name self.get_child().props.icon_name = icon_name
@ -494,7 +494,7 @@ class ColorToolButton(gtk.ToolItem):
def get_icon_name(self): def get_icon_name(self):
return self.get_child().props.icon_name return self.get_child().props.icon_name
icon_name = gobject.property(type=str, icon_name = GObject.property(type=str,
getter=get_icon_name, setter=set_icon_name) getter=get_icon_name, setter=set_icon_name)
def set_icon_size(self, icon_size): def set_icon_size(self, icon_size):
@ -503,7 +503,7 @@ class ColorToolButton(gtk.ToolItem):
def get_icon_size(self): def get_icon_size(self):
return self.get_child().props.icon_size return self.get_child().props.icon_size
icon_size = gobject.property(type=int, icon_size = GObject.property(type=int,
getter=get_icon_size, setter=set_icon_size) getter=get_icon_size, setter=set_icon_size)
def set_title(self, title): def set_title(self, title):
@ -512,7 +512,7 @@ class ColorToolButton(gtk.ToolItem):
def get_title(self): def get_title(self):
return self.get_child().props.title return self.get_child().props.title
title = gobject.property(type=str, getter=get_title, setter=set_title) title = GObject.property(type=str, getter=get_title, setter=set_title)
def do_expose_event(self, event): def do_expose_event(self, event):
child = self.get_child() child = self.get_child()
@ -520,14 +520,14 @@ class ColorToolButton(gtk.ToolItem):
if self._palette and self._palette.is_up(): if self._palette and self._palette.is_up():
invoker = self._palette.props.invoker invoker = self._palette.props.invoker
invoker.draw_rectangle(event, self._palette) invoker.draw_rectangle(event, self._palette)
elif child.state == gtk.STATE_PRELIGHT: elif child.state == Gtk.StateType.PRELIGHT:
child.style.paint_box(event.window, gtk.STATE_PRELIGHT, child.style.paint_box(event.window, Gtk.StateType.PRELIGHT,
gtk.SHADOW_NONE, event.area, Gtk.ShadowType.NONE, event.area,
child, 'toolbutton-prelight', child, 'toolbutton-prelight',
allocation.x, allocation.y, allocation.x, allocation.y,
allocation.width, allocation.height) allocation.width, allocation.height)
gtk.ToolButton.do_expose_event(self, event) Gtk.ToolButton.do_expose_event(self, event)
def __notify_change(self, widget, pspec): def __notify_change(self, widget, pspec):
self.notify(pspec.name) self.notify(pspec.name)

View File

@ -19,24 +19,24 @@
STABLE. STABLE.
""" """
import gobject from gi.repository import GObject
import gtk from gi.repository import Gtk
class ComboBox(gtk.ComboBox): class ComboBox(Gtk.ComboBox):
__gtype_name__ = 'SugarComboBox' __gtype_name__ = 'SugarComboBox'
def __init__(self): def __init__(self):
gtk.ComboBox.__init__(self) GObject.GObject.__init__(self)
self._text_renderer = None self._text_renderer = None
self._icon_renderer = None self._icon_renderer = None
self._model = gtk.ListStore(gobject.TYPE_PYOBJECT, self._model = Gtk.ListStore(GObject.TYPE_PYOBJECT,
gobject.TYPE_STRING, GObject.TYPE_STRING,
gtk.gdk.Pixbuf, GdkPixbuf.Pixbuf,
gobject.TYPE_BOOLEAN) GObject.TYPE_BOOLEAN)
self.set_model(self._model) self.set_model(self._model)
self.set_row_separator_func(self._is_separator, None) self.set_row_separator_func(self._is_separator, None)
@ -57,12 +57,12 @@ class ComboBox(gtk.ComboBox):
return None return None
return row[0] return row[0]
value = gobject.property( value = GObject.property(
type=object, getter=get_value, setter=None) type=object, getter=get_value, setter=None)
def _get_real_name_from_theme(self, name, size): def _get_real_name_from_theme(self, name, size):
icon_theme = gtk.icon_theme_get_default() icon_theme = Gtk.IconTheme.get_default()
width, height = gtk.icon_size_lookup(size) width, height = Gtk.icon_size_lookup(size)
info = icon_theme.lookup_icon(name, max(width, height), 0) info = icon_theme.lookup_icon(name, max(width, height), 0)
if not info: if not info:
raise ValueError('Icon %r not found.' % name) raise ValueError('Icon %r not found.' % name)
@ -88,32 +88,32 @@ class ComboBox(gtk.ComboBox):
""" """
if not self._icon_renderer and (icon_name or file_name): if not self._icon_renderer and (icon_name or file_name):
self._icon_renderer = gtk.CellRendererPixbuf() self._icon_renderer = Gtk.CellRendererPixbuf()
settings = self.get_settings() settings = self.get_settings()
w, h = gtk.icon_size_lookup_for_settings( w, h = Gtk.icon_size_lookup_for_settings(
settings, gtk.ICON_SIZE_MENU) settings, Gtk.IconSize.MENU)
self._icon_renderer.props.stock_size = max(w, h) self._icon_renderer.props.stock_size = max(w, h)
self.pack_start(self._icon_renderer, False) self.pack_start(self._icon_renderer, False)
self.add_attribute(self._icon_renderer, 'pixbuf', 2) self.add_attribute(self._icon_renderer, 'pixbuf', 2)
if not self._text_renderer and text: if not self._text_renderer and text:
self._text_renderer = gtk.CellRendererText() self._text_renderer = Gtk.CellRendererText()
self.pack_end(self._text_renderer, True) self.pack_end(self._text_renderer, True)
self.add_attribute(self._text_renderer, 'text', 1) self.add_attribute(self._text_renderer, 'text', 1)
if icon_name or file_name: if icon_name or file_name:
if text: if text:
size = gtk.ICON_SIZE_MENU size = Gtk.IconSize.MENU
else: else:
size = gtk.ICON_SIZE_LARGE_TOOLBAR size = Gtk.IconSize.LARGE_TOOLBAR
width, height = gtk.icon_size_lookup(size) width, height = Gtk.icon_size_lookup(size)
if icon_name: if icon_name:
file_name = self._get_real_name_from_theme(icon_name, size) file_name = self._get_real_name_from_theme(icon_name, size)
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
file_name, width, height) file_name, width, height)
else: else:
pixbuf = None pixbuf = None

View File

@ -25,8 +25,8 @@ import re
import math import math
import logging import logging
import gobject from gi.repository import GObject
import gtk from gi.repository import Gtk
import cairo import cairo
from sugar3.graphics.xocolor import XoColor from sugar3.graphics.xocolor import XoColor
@ -120,11 +120,11 @@ class _IconBuffer(object):
return self._loader.load(file_name, entities, self.cache) return self._loader.load(file_name, entities, self.cache)
def _get_attach_points(self, info, size_request): def _get_attach_points(self, info, size_request):
attach_points = info.get_attach_points() return 0,0;has_attach_points_, attach_points = info.get_attach_points()
if attach_points: if attach_points:
attach_x = float(attach_points[0][0]) / size_request attach_x = float(attach_points[0].x) / size_request
attach_y = float(attach_points[0][1]) / size_request attach_y = float(attach_points[0].y) / size_request
else: else:
attach_x = attach_y = 0 attach_x = attach_y = 0
@ -136,7 +136,7 @@ class _IconBuffer(object):
if self.file_name: if self.file_name:
icon_info.file_name = self.file_name icon_info.file_name = self.file_name
elif self.icon_name: elif self.icon_name:
theme = gtk.icon_theme_get_default() theme = Gtk.IconTheme.get_default()
size = 50 size = 50
if self.width != None: if self.width != None:
@ -158,7 +158,7 @@ class _IconBuffer(object):
return icon_info return icon_info
def _draw_badge(self, context, size, sensitive, widget): def _draw_badge(self, context, size, sensitive, widget):
theme = gtk.icon_theme_get_default() theme = Gtk.IconTheme.get_default()
badge_info = theme.lookup_icon(self.badge_name, int(size), 0) badge_info = theme.lookup_icon(self.badge_name, int(size), 0)
if badge_info: if badge_info:
badge_file_name = badge_info.get_filename() badge_file_name = badge_info.get_filename()
@ -171,7 +171,7 @@ class _IconBuffer(object):
pixbuf = handle.get_pixbuf() pixbuf = handle.get_pixbuf()
else: else:
pixbuf = gtk.gdk.pixbuf_new_from_file(badge_file_name) pixbuf = GdkPixbuf.Pixbuf.new_from_file(badge_file_name)
icon_width = pixbuf.get_width() icon_width = pixbuf.get_width()
icon_height = pixbuf.get_height() icon_height = pixbuf.get_height()
@ -231,16 +231,16 @@ class _IconBuffer(object):
if not (widget and widget.style): if not (widget and widget.style):
return pixbuf return pixbuf
icon_source = gtk.IconSource() icon_source = Gtk.IconSource()
# Special size meaning "don't touch" # Special size meaning "don't touch"
icon_source.set_size(-1) icon_source.set_size(-1)
icon_source.set_pixbuf(pixbuf) icon_source.set_pixbuf(pixbuf)
icon_source.set_state(gtk.STATE_INSENSITIVE) icon_source.set_state(Gtk.StateType.INSENSITIVE)
icon_source.set_direction_wildcarded(False) icon_source.set_direction_wildcarded(False)
icon_source.set_size_wildcarded(False) icon_source.set_size_wildcarded(False)
pixbuf = widget.style.render_icon(icon_source, widget.get_direction(), pixbuf = widget.style.render_icon(icon_source, widget.get_direction(),
gtk.STATE_INSENSITIVE, -1, widget, Gtk.StateType.INSENSITIVE, -1, widget,
'sugar-icon') 'sugar-icon')
return pixbuf return pixbuf
@ -262,7 +262,7 @@ class _IconBuffer(object):
icon_width = int(dimensions[0]) icon_width = int(dimensions[0])
icon_height = int(dimensions[1]) icon_height = int(dimensions[1])
else: else:
pixbuf = gtk.gdk.pixbuf_new_from_file(icon_info.file_name) pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon_info.file_name)
icon_width = pixbuf.get_width() icon_width = pixbuf.get_width()
icon_height = pixbuf.get_height() icon_height = pixbuf.get_height()
@ -278,7 +278,7 @@ class _IconBuffer(object):
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(width), surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(width),
int(height)) int(height))
context = cairo.Context(surface) context = cairo.Context(surface)
context = gtk.gdk.CairoContext(context) context = Gdk.CairoContext(context)
context.set_source_color(self.background_color) context.set_source_color(self.background_color)
context.paint() context.paint()
@ -314,7 +314,7 @@ class _IconBuffer(object):
xo_color = property(_get_xo_color, _set_xo_color) xo_color = property(_get_xo_color, _set_xo_color)
class Icon(gtk.Image): class Icon(Gtk.Image):
__gtype_name__ = 'SugarIcon' __gtype_name__ = 'SugarIcon'
@ -327,7 +327,7 @@ class Icon(gtk.Image):
self._alpha = 1.0 self._alpha = 1.0
self._scale = 1.0 self._scale = 1.0
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
def get_file(self): def get_file(self):
return self._file return self._file
@ -336,7 +336,7 @@ class Icon(gtk.Image):
self._file = file_name self._file = file_name
self._buffer.file_name = file_name self._buffer.file_name = file_name
file = gobject.property(type=object, setter=set_file, getter=get_file) file = GObject.property(type=object, setter=set_file, getter=get_file)
def _sync_image_properties(self): def _sync_image_properties(self):
if self._buffer.icon_name != self.props.icon_name: if self._buffer.icon_name != self.props.icon_name:
@ -346,7 +346,7 @@ class Icon(gtk.Image):
self._buffer.file_name = self.props.file self._buffer.file_name = self.props.file
if self.props.pixel_size == -1: if self.props.pixel_size == -1:
width, height = gtk.icon_size_lookup(self.props.icon_size) width, height = Gtk.icon_size_lookup(self.props.icon_size)
else: else:
width = height = self.props.pixel_size width = height = self.props.pixel_size
if self._buffer.width != width or self._buffer.height != height: if self._buffer.width != width or self._buffer.height != height:
@ -396,7 +396,7 @@ class Icon(gtk.Image):
""" """
self._sync_image_properties() self._sync_image_properties()
sensitive = (self.state != gtk.STATE_INSENSITIVE) sensitive = (self.is_sensitive())
surface = self._buffer.get_surface(sensitive, self) surface = self._buffer.get_surface(sensitive, self)
if surface is None: if surface is None:
return return
@ -404,7 +404,7 @@ class Icon(gtk.Image):
xpad, ypad = self.get_padding() xpad, ypad = self.get_padding()
xalign, yalign = self.get_alignment() xalign, yalign = self.get_alignment()
requisition = self.get_child_requisition() requisition = self.get_child_requisition()
if self.get_direction() != gtk.TEXT_DIR_LTR: if self.get_direction() != Gtk.TextDirection.LTR:
xalign = 1.0 - xalign xalign = 1.0 - xalign
allocation = self.get_allocation() allocation = self.get_allocation()
@ -413,7 +413,7 @@ class Icon(gtk.Image):
y = math.floor(allocation.y + ypad + y = math.floor(allocation.y + ypad +
(allocation.height - requisition[1]) * yalign) (allocation.height - requisition[1]) * yalign)
cr = self.window.cairo_create() cr = self.get_window().cairo_create()
if self._scale != 1.0: if self._scale != 1.0:
cr.scale(self._scale, self._scale) cr.scale(self._scale, self._scale)
@ -446,7 +446,7 @@ class Icon(gtk.Image):
self._buffer.xo_color = value self._buffer.xo_color = value
self.queue_draw() self.queue_draw()
xo_color = gobject.property( xo_color = GObject.property(
type=object, getter=None, setter=set_xo_color) type=object, getter=None, setter=set_xo_color)
def set_fill_color(self, value): def set_fill_color(self, value):
@ -477,7 +477,7 @@ class Icon(gtk.Image):
""" """
return self._buffer.fill_color return self._buffer.fill_color
fill_color = gobject.property( fill_color = GObject.property(
type=object, getter=get_fill_color, setter=set_fill_color) type=object, getter=get_fill_color, setter=set_fill_color)
def set_stroke_color(self, value): def set_stroke_color(self, value):
@ -508,7 +508,7 @@ class Icon(gtk.Image):
""" """
return self._buffer.stroke_color return self._buffer.stroke_color
stroke_color = gobject.property( stroke_color = GObject.property(
type=object, getter=get_stroke_color, setter=set_stroke_color) type=object, getter=get_stroke_color, setter=set_stroke_color)
def set_badge_name(self, value): def set_badge_name(self, value):
@ -529,7 +529,7 @@ class Icon(gtk.Image):
def get_badge_name(self): def get_badge_name(self):
return self._buffer.badge_name return self._buffer.badge_name
badge_name = gobject.property( badge_name = GObject.property(
type=str, getter=get_badge_name, setter=set_badge_name) type=str, getter=get_badge_name, setter=set_badge_name)
def set_alpha(self, value): def set_alpha(self, value):
@ -537,7 +537,7 @@ class Icon(gtk.Image):
self._alpha = value self._alpha = value
self.queue_draw() self.queue_draw()
alpha = gobject.property( alpha = GObject.property(
type=float, setter=set_alpha) type=float, setter=set_alpha)
def set_scale(self, value): def set_scale(self, value):
@ -545,16 +545,16 @@ class Icon(gtk.Image):
self._scale = value self._scale = value
self.queue_draw() self.queue_draw()
scale = gobject.property( scale = GObject.property(
type=float, setter=set_scale) type=float, setter=set_scale)
class CellRendererIcon(gtk.GenericCellRenderer): class CellRendererIcon(Gtk.CellRenderer):
__gtype_name__ = 'SugarCellRendererIcon' __gtype_name__ = 'SugarCellRendererIcon'
__gsignals__ = { __gsignals__ = {
'clicked': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, [object]), 'clicked': (GObject.SignalFlags.RUN_FIRST, None, [object]),
} }
def __init__(self, tree_view): def __init__(self, tree_view):
@ -569,7 +569,7 @@ class CellRendererIcon(gtk.GenericCellRenderer):
self._prelit_stroke_color = None self._prelit_stroke_color = None
self._palette_invoker = CellRendererInvoker() self._palette_invoker = CellRendererInvoker()
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._palette_invoker.attach_cell_renderer(tree_view, self) self._palette_invoker.attach_cell_renderer(tree_view, self)
@ -584,19 +584,19 @@ class CellRendererIcon(gtk.GenericCellRenderer):
def get_palette_invoker(self): def get_palette_invoker(self):
return self._palette_invoker return self._palette_invoker
palette_invoker = gobject.property(type=object, getter=get_palette_invoker) palette_invoker = GObject.property(type=object, getter=get_palette_invoker)
def set_file_name(self, value): def set_file_name(self, value):
if self._buffer.file_name != value: if self._buffer.file_name != value:
self._buffer.file_name = value self._buffer.file_name = value
file_name = gobject.property(type=str, setter=set_file_name) file_name = GObject.property(type=str, setter=set_file_name)
def set_icon_name(self, value): def set_icon_name(self, value):
if self._buffer.icon_name != value: if self._buffer.icon_name != value:
self._buffer.icon_name = value self._buffer.icon_name = value
icon_name = gobject.property(type=str, setter=set_icon_name) icon_name = GObject.property(type=str, setter=set_icon_name)
def get_xo_color(self): def get_xo_color(self):
return self._xo_color return self._xo_color
@ -604,40 +604,40 @@ class CellRendererIcon(gtk.GenericCellRenderer):
def set_xo_color(self, value): def set_xo_color(self, value):
self._xo_color = value self._xo_color = value
xo_color = gobject.property(type=object, xo_color = GObject.property(type=object,
getter=get_xo_color, setter=set_xo_color) getter=get_xo_color, setter=set_xo_color)
def set_fill_color(self, value): def set_fill_color(self, value):
if self._fill_color != value: if self._fill_color != value:
self._fill_color = value self._fill_color = value
fill_color = gobject.property(type=object, setter=set_fill_color) fill_color = GObject.property(type=object, setter=set_fill_color)
def set_stroke_color(self, value): def set_stroke_color(self, value):
if self._stroke_color != value: if self._stroke_color != value:
self._stroke_color = value self._stroke_color = value
stroke_color = gobject.property(type=object, setter=set_stroke_color) stroke_color = GObject.property(type=object, setter=set_stroke_color)
def set_prelit_fill_color(self, value): def set_prelit_fill_color(self, value):
if self._prelit_fill_color != value: if self._prelit_fill_color != value:
self._prelit_fill_color = value self._prelit_fill_color = value
prelit_fill_color = gobject.property(type=object, prelit_fill_color = GObject.property(type=object,
setter=set_prelit_fill_color) setter=set_prelit_fill_color)
def set_prelit_stroke_color(self, value): def set_prelit_stroke_color(self, value):
if self._prelit_stroke_color != value: if self._prelit_stroke_color != value:
self._prelit_stroke_color = value self._prelit_stroke_color = value
prelit_stroke_color = gobject.property(type=object, prelit_stroke_color = GObject.property(type=object,
setter=set_prelit_stroke_color) setter=set_prelit_stroke_color)
def set_background_color(self, value): def set_background_color(self, value):
if self._buffer.background_color != value: if self._buffer.background_color != value:
self._buffer.background_color = value self._buffer.background_color = value
background_color = gobject.property(type=object, background_color = GObject.property(type=object,
setter=set_background_color) setter=set_background_color)
def set_size(self, value): def set_size(self, value):
@ -645,7 +645,7 @@ class CellRendererIcon(gtk.GenericCellRenderer):
self._buffer.width = value self._buffer.width = value
self._buffer.height = value self._buffer.height = value
size = gobject.property(type=object, setter=set_size) size = GObject.property(type=object, setter=set_size)
def on_get_size(self, widget, cell_area): def on_get_size(self, widget, cell_area):
width = self._buffer.width + self.props.xpad * 2 width = self._buffer.width + self.props.xpad * 2
@ -655,7 +655,7 @@ class CellRendererIcon(gtk.GenericCellRenderer):
if width > 0 and height > 0 and cell_area is not None: if width > 0 and height > 0 and cell_area is not None:
if widget.get_direction() == gtk.TEXT_DIR_RTL: if widget.get_direction() == Gtk.TextDirection.RTL:
xoffset = 1.0 - self.props.xalign xoffset = 1.0 - self.props.xalign
else: else:
xoffset = self.props.xalign xoffset = self.props.xalign
@ -707,7 +707,7 @@ class CellRendererIcon(gtk.GenericCellRenderer):
has_prelit_colors = None not in [prelit_fill_color, has_prelit_colors = None not in [prelit_fill_color,
prelit_stroke_color] prelit_stroke_color]
if flags & gtk.CELL_RENDERER_PRELIT and has_prelit_colors and \ if flags & Gtk.CELL_RENDERER_PRELIT and has_prelit_colors and \
self._is_prelit(widget): self._is_prelit(widget):
self._buffer.fill_color = prelit_fill_color self._buffer.fill_color = prelit_fill_color
@ -733,7 +733,7 @@ class CellRendererIcon(gtk.GenericCellRenderer):
def get_icon_state(base_name, perc, step=5): def get_icon_state(base_name, perc, step=5):
strength = round(perc / step) * step strength = round(perc / step) * step
icon_theme = gtk.icon_theme_get_default() icon_theme = Gtk.IconTheme.get_default()
while strength <= 100 and strength >= 0: while strength <= 100 and strength >= 0:
icon_name = '%s-%03d' % (base_name, strength) icon_name = '%s-%03d' % (base_name, strength)
@ -744,8 +744,8 @@ def get_icon_state(base_name, perc, step=5):
def get_icon_file_name(icon_name): def get_icon_file_name(icon_name):
icon_theme = gtk.icon_theme_get_default() icon_theme = Gtk.IconTheme.get_default()
info = icon_theme.lookup_icon(icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR, 0) info = icon_theme.lookup_icon(icon_name, Gtk.IconSize.LARGE_TOOLBAR, 0)
if not info: if not info:
return None return None
filename = info.get_filename() filename = info.get_filename()

View File

@ -15,19 +15,19 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import gtk from gi.repository import Gtk
from sugar3.graphics import style from sugar3.graphics import style
from sugar3.graphics.icon import _SVGLoader from sugar3.graphics.icon import _SVGLoader
ICON_ENTRY_PRIMARY = gtk.ENTRY_ICON_PRIMARY ICON_ENTRY_PRIMARY = Gtk.EntryIconPosition.PRIMARY
ICON_ENTRY_SECONDARY = gtk.ENTRY_ICON_SECONDARY ICON_ENTRY_SECONDARY = Gtk.EntryIconPosition.SECONDARY
class IconEntry(gtk.Entry): class IconEntry(Gtk.Entry):
def __init__(self): def __init__(self):
gtk.Entry.__init__(self) GObject.GObject.__init__(self)
self._clear_icon = None self._clear_icon = None
self._clear_shown = False self._clear_shown = False
@ -35,9 +35,9 @@ class IconEntry(gtk.Entry):
self.connect('key_press_event', self._keypress_event_cb) self.connect('key_press_event', self._keypress_event_cb)
def set_icon_from_name(self, position, name): def set_icon_from_name(self, position, name):
icon_theme = gtk.icon_theme_get_default() icon_theme = Gtk.IconTheme.get_default()
icon_info = icon_theme.lookup_icon(name, icon_info = icon_theme.lookup_icon(name,
gtk.ICON_SIZE_SMALL_TOOLBAR, Gtk.IconSize.SMALL_TOOLBAR,
0) 0)
if icon_info.get_filename().endswith('.svg'): if icon_info.get_filename().endswith('.svg'):
@ -47,12 +47,12 @@ class IconEntry(gtk.Entry):
handle = loader.load(icon_info.get_filename(), entities, None) handle = loader.load(icon_info.get_filename(), entities, None)
pixbuf = handle.get_pixbuf() pixbuf = handle.get_pixbuf()
else: else:
pixbuf = gtk.gdk.pixbuf_new_from_file(icon_info.get_filename()) pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon_info.get_filename())
del icon_info del icon_info
self.set_icon(position, pixbuf) self.set_icon(position, pixbuf)
def set_icon(self, position, pixbuf): def set_icon(self, position, pixbuf):
if type(pixbuf) is not gtk.gdk.Pixbuf: if type(pixbuf) is not GdkPixbuf.Pixbuf:
raise ValueError('Argument must be a pixbuf, not %r.' % pixbuf) raise ValueError('Argument must be a pixbuf, not %r.' % pixbuf)
self.set_icon_from_pixbuf(position, pixbuf) self.set_icon_from_pixbuf(position, pixbuf)
@ -80,7 +80,7 @@ class IconEntry(gtk.Entry):
self._clear_shown = False self._clear_shown = False
def _keypress_event_cb(self, widget, event): def _keypress_event_cb(self, widget, event):
keyval = gtk.gdk.keyval_name(event.keyval) keyval = Gdk.keyval_name(event.keyval)
if keyval == 'Escape': if keyval == 'Escape':
self.props.text = '' self.props.text = ''
return True return True

View File

@ -21,39 +21,39 @@ STABLE.
import logging import logging
import gobject from gi.repository import GObject
import pango from gi.repository import Pango
import gtk from gi.repository import Gtk
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
class MenuItem(gtk.ImageMenuItem): class MenuItem(Gtk.ImageMenuItem):
def __init__(self, text_label=None, icon_name=None, text_maxlen=60, def __init__(self, text_label=None, icon_name=None, text_maxlen=60,
xo_color=None, file_name=None): xo_color=None, file_name=None):
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._accelerator = None self._accelerator = None
label = gtk.AccelLabel(text_label) label = Gtk.AccelLabel(label=text_label)
label.set_alignment(0.0, 0.5) label.set_alignment(0.0, 0.5)
label.set_accel_widget(self) label.set_accel_widget(self)
if text_maxlen > 0: if text_maxlen > 0:
label.set_ellipsize(pango.ELLIPSIZE_MIDDLE) label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
label.set_max_width_chars(text_maxlen) label.set_max_width_chars(text_maxlen)
self.add(label) self.add(label)
label.show() label.show()
if icon_name is not None: if icon_name is not None:
icon = Icon(icon_name=icon_name, icon = Icon(icon_name=icon_name,
icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR) icon_size=Gtk.IconSize.SMALL_TOOLBAR)
if xo_color is not None: if xo_color is not None:
icon.props.xo_color = xo_color icon.props.xo_color = xo_color
self.set_image(icon) self.set_image(icon)
icon.show() icon.show()
elif file_name is not None: elif file_name is not None:
icon = Icon(file=file_name, icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR) icon = Icon(file=file_name, icon_size=Gtk.IconSize.SMALL_TOOLBAR)
if xo_color is not None: if xo_color is not None:
icon.props.xo_color = xo_color icon.props.xo_color = xo_color
self.set_image(icon) self.set_image(icon)
@ -77,12 +77,12 @@ class MenuItem(gtk.ImageMenuItem):
accel_group = self.get_toplevel().get_data('sugar-accel-group') accel_group = self.get_toplevel().get_data('sugar-accel-group')
if not accel_group: if not accel_group:
logging.warning('No gtk.AccelGroup in the top level window.') logging.warning('No Gtk.AccelGroup in the top level window.')
return return
keyval, mask = gtk.accelerator_parse(self._accelerator) keyval, mask = Gtk.accelerator_parse(self._accelerator)
self.add_accelerator('activate', accel_group, keyval, mask, self.add_accelerator('activate', accel_group, keyval, mask,
gtk.ACCEL_LOCKED | gtk.ACCEL_VISIBLE) Gtk.AccelFlags.LOCKED | Gtk.AccelFlags.VISIBLE)
def set_accelerator(self, accelerator): def set_accelerator(self, accelerator):
self._accelerator = accelerator self._accelerator = accelerator
@ -91,5 +91,5 @@ class MenuItem(gtk.ImageMenuItem):
def get_accelerator(self): def get_accelerator(self):
return self._accelerator return self._accelerator
accelerator = gobject.property(type=str, setter=set_accelerator, accelerator = GObject.property(type=str, setter=set_accelerator,
getter=get_accelerator) getter=get_accelerator)

View File

@ -17,24 +17,24 @@
"""Notebook class """Notebook class
This class create a gtk.Notebook() widget supporting This class create a Gtk.Notebook() widget supporting
a close button in every tab when the 'can-close-tabs' gproperty a close button in every tab when the 'can-close-tabs' gproperty
is enabled (True) is enabled (True)
STABLE. STABLE.
""" """
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
class Notebook(gtk.Notebook): class Notebook(Gtk.Notebook):
__gtype_name__ = 'SugarNotebook' __gtype_name__ = 'SugarNotebook'
__gproperties__ = { __gproperties__ = {
'can-close-tabs': (bool, None, None, False, 'can-close-tabs': (bool, None, None, False,
gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT_ONLY), GObject.PARAM_READWRITE | GObject.PARAM_CONSTRUCT_ONLY),
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -74,26 +74,26 @@ class Notebook(gtk.Notebook):
raise AssertionError raise AssertionError
def _add_icon_to_button(self, button): def _add_icon_to_button(self, button):
icon_box = gtk.HBox() icon_box = Gtk.HBox()
image = gtk.Image() image = Gtk.Image()
image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU) image.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU)
gtk.Button.set_relief(button, gtk.RELIEF_NONE) Gtk.Button.set_relief(button, Gtk.ReliefStyle.NONE)
settings = gtk.Widget.get_settings(button) settings = Gtk.Widget.get_settings(button)
w, h = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) w, h = Gtk.icon_size_lookup_for_settings(settings, Gtk.IconSize.MENU)
gtk.Widget.set_size_request(button, w + 4, h + 4) Gtk.Widget.set_size_request(button, w + 4, h + 4)
image.show() image.show()
icon_box.pack_start(image, True, False, 0) icon_box.pack_start(image, True, False, 0)
button.add(icon_box) button.add(icon_box)
icon_box.show() icon_box.show()
def _create_custom_tab(self, text, child): def _create_custom_tab(self, text, child):
event_box = gtk.EventBox() event_box = Gtk.EventBox()
tab_box = gtk.HBox(False, 2) tab_box = Gtk.HBox(False, 2)
tab_label = gtk.Label(text) tab_label = Gtk.Label(label=text)
tab_button = gtk.Button() tab_button = Gtk.Button()
tab_button.connect('clicked', self._close_page, child) tab_button.connect('clicked', self._close_page, child)
# Add a picture on a button # Add a picture on a button
@ -132,7 +132,7 @@ class Notebook(gtk.Notebook):
eventbox = self._create_custom_tab(text_label, widget) eventbox = self._create_custom_tab(text_label, widget)
self.append_page(widget, eventbox) self.append_page(widget, eventbox)
else: else:
self.append_page(widget, gtk.Label(text_label)) self.append_page(widget, Gtk.Label(label=text_label))
pages = self.get_n_pages() pages = self.get_n_pages()

View File

@ -21,8 +21,8 @@ STABLE.
import logging import logging
import gobject from gi.repository import GObject
import gtk from gi.repository import Gtk
import dbus import dbus
from sugar3.datastore import datastore from sugar3.datastore import datastore
@ -39,7 +39,7 @@ class ObjectChooser(object):
what_filter=None): what_filter=None):
# For backwards compatibility: # For backwards compatibility:
# - We ignore title, flags and buttons. # - We ignore title, flags and buttons.
# - 'parent' can be a xid or a gtk.Window # - 'parent' can be a xid or a Gtk.Window
if title is not None or flags is not None or buttons is not None: if title is not None or flags is not None or buttons is not None:
logging.warning('Invocation of ObjectChooser() has deprecated ' logging.warning('Invocation of ObjectChooser() has deprecated '
@ -57,13 +57,13 @@ class ObjectChooser(object):
self._object_id = None self._object_id = None
self._bus = None self._bus = None
self._chooser_id = None self._chooser_id = None
self._response_code = gtk.RESPONSE_NONE self._response_code = Gtk.ResponseType.NONE
self._what_filter = what_filter self._what_filter = what_filter
def run(self): def run(self):
self._object_id = None self._object_id = None
self._main_loop = gobject.MainLoop() self._main_loop = GObject.MainLoop()
self._bus = dbus.SessionBus(mainloop=self._main_loop) self._bus = dbus.SessionBus(mainloop=self._main_loop)
self._bus.add_signal_receiver( self._bus.add_signal_receiver(
@ -86,11 +86,11 @@ class ObjectChooser(object):
self._chooser_id = journal.ChooseObject(self._parent_xid, what_filter) self._chooser_id = journal.ChooseObject(self._parent_xid, what_filter)
gtk.gdk.threads_leave() Gdk.threads_leave()
try: try:
self._main_loop.run() self._main_loop.run()
finally: finally:
gtk.gdk.threads_enter() Gdk.threads_enter()
self._main_loop = None self._main_loop = None
return self._response_code return self._response_code
@ -114,7 +114,7 @@ class ObjectChooser(object):
if chooser_id != self._chooser_id: if chooser_id != self._chooser_id:
return return
logging.debug('ObjectChooser.__chooser_response_cb: %r', object_id) logging.debug('ObjectChooser.__chooser_response_cb: %r', object_id)
self._response_code = gtk.RESPONSE_ACCEPT self._response_code = Gtk.ResponseType.ACCEPT
self._object_id = object_id self._object_id = object_id
self._cleanup() self._cleanup()
@ -122,11 +122,11 @@ class ObjectChooser(object):
if chooser_id != self._chooser_id: if chooser_id != self._chooser_id:
return return
logging.debug('ObjectChooser.__chooser_cancelled_cb: %r', chooser_id) logging.debug('ObjectChooser.__chooser_cancelled_cb: %r', chooser_id)
self._response_code = gtk.RESPONSE_CANCEL self._response_code = Gtk.ResponseType.CANCEL
self._cleanup() self._cleanup()
def __name_owner_changed_cb(self, name, old, new): def __name_owner_changed_cb(self, name, old, new):
logging.debug('ObjectChooser.__name_owner_changed_cb') logging.debug('ObjectChooser.__name_owner_changed_cb')
# Journal service disappeared from the bus # Journal service disappeared from the bus
self._response_code = gtk.RESPONSE_CANCEL self._response_code = Gtk.ResponseType.CANCEL
self._cleanup() self._cleanup()

View File

@ -21,16 +21,16 @@
STABLE. STABLE.
""" """
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
import pango from gi.repository import Pango
from sugar3.graphics import palettegroup from sugar3.graphics import palettegroup
from sugar3.graphics import animator from sugar3.graphics import animator
from sugar3.graphics import style from sugar3.graphics import style
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
from sugar3.graphics.palettewindow import PaletteWindow from sugar3.graphics.palettewindow import PaletteWindow
from sugar import _sugarext from gi.repository import SugarExt
# DEPRECATED # DEPRECATED
# Import these for backwards compatibility # Import these for backwards compatibility
@ -56,50 +56,50 @@ class Palette(PaletteWindow):
self._icon_visible = True self._icon_visible = True
self._palette_state = self.PRIMARY self._palette_state = self.PRIMARY
palette_box = gtk.VBox() palette_box = Gtk.VBox()
primary_box = gtk.HBox() primary_box = Gtk.HBox()
palette_box.pack_start(primary_box, expand=False) palette_box.pack_start(primary_box, False, True, 0)
primary_box.show() primary_box.show()
self._icon_box = gtk.HBox() self._icon_box = Gtk.HBox()
self._icon_box.set_size_request(style.GRID_CELL_SIZE, -1) self._icon_box.set_size_request(style.GRID_CELL_SIZE, -1)
primary_box.pack_start(self._icon_box, expand=False) primary_box.pack_start(self._icon_box, False, True, 0)
labels_box = gtk.VBox() labels_box = Gtk.VBox()
self._label_alignment = gtk.Alignment(xalign=0, yalign=0.5, self._label_alignment = Gtk.Alignment.new(xalign=0, yalign=0.5,
xscale=1, yscale=0.33) xscale=1, yscale=0.33)
self._label_alignment.set_padding(0, 0, style.DEFAULT_SPACING, self._label_alignment.set_padding(0, 0, style.DEFAULT_SPACING,
style.DEFAULT_SPACING) style.DEFAULT_SPACING)
self._label_alignment.add(labels_box) self._label_alignment.add(labels_box)
self._label_alignment.show() self._label_alignment.show()
primary_box.pack_start(self._label_alignment, expand=True) primary_box.pack_start(self._label_alignment, True, True, 0)
labels_box.show() labels_box.show()
self._label = gtk.AccelLabel('') self._label = Gtk.AccelLabel(label='')
self._label.set_alignment(0, 0.5) self._label.set_alignment(0, 0.5)
if text_maxlen > 0: if text_maxlen > 0:
self._label.set_max_width_chars(text_maxlen) self._label.set_max_width_chars(text_maxlen)
self._label.set_ellipsize(pango.ELLIPSIZE_MIDDLE) self._label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
labels_box.pack_start(self._label, expand=True) labels_box.pack_start(self._label, True, True, 0)
self._secondary_label = gtk.Label() self._secondary_label = Gtk.Label()
self._secondary_label.set_alignment(0, 0.5) self._secondary_label.set_alignment(0, 0.5)
if text_maxlen > 0: if text_maxlen > 0:
self._secondary_label.set_max_width_chars(text_maxlen) self._secondary_label.set_max_width_chars(text_maxlen)
self._secondary_label.set_ellipsize(pango.ELLIPSIZE_END) self._secondary_label.set_ellipsize(Pango.EllipsizeMode.END)
labels_box.pack_start(self._secondary_label, expand=True) labels_box.pack_start(self._secondary_label, True, True, 0)
self._secondary_box = gtk.VBox() self._secondary_box = Gtk.VBox()
palette_box.pack_start(self._secondary_box) palette_box.pack_start(self._secondary_box, True, True, 0)
self._separator = gtk.HSeparator() self._separator = Gtk.HSeparator()
self._secondary_box.pack_start(self._separator) self._secondary_box.pack_start(self._separator, True, True, 0)
self._menu_content_separator = gtk.HSeparator() self._menu_content_separator = Gtk.HSeparator()
self._secondary_anim = animator.Animator(2.0, 10) self._secondary_anim = animator.Animator(2.0, 10)
self._secondary_anim.add(_SecondaryAnimation(self)) self._secondary_anim.add(_SecondaryAnimation(self))
@ -119,11 +119,11 @@ class Palette(PaletteWindow):
self.props.primary_text = label self.props.primary_text = label
self._add_menu() self._add_menu()
self._secondary_box.pack_start(self._menu_content_separator) self._secondary_box.pack_start(self._menu_content_separator, True, True, 0)
self._add_content() self._add_content()
self.action_bar = PaletteActionBar() self.action_bar = PaletteActionBar()
self._secondary_box.pack_start(self.action_bar) self._secondary_box.pack_start(self.action_bar, True, True, 0)
self.action_bar.show() self.action_bar.show()
self.add(palette_box) self.add(palette_box)
@ -145,7 +145,7 @@ class Palette(PaletteWindow):
def do_style_set(self, previous_style): def do_style_set(self, previous_style):
# Prevent a warning from pygtk # Prevent a warning from pygtk
if previous_style is not None: if previous_style is not None:
gtk.Window.do_style_set(self, previous_style) Gtk.Window.do_style_set(self, previous_style)
self.set_border_width(self.get_style().xthickness) self.set_border_width(self.get_style().xthickness)
def __menu_item_inserted_cb(self, menu): def __menu_item_inserted_cb(self, menu):
@ -155,7 +155,7 @@ class Palette(PaletteWindow):
self._secondary_anim.stop() self._secondary_anim.stop()
self.popdown(immediate=True) self.popdown(immediate=True)
# Break the reference cycle. It looks like the gc is not able to free # Break the reference cycle. It looks like the gc is not able to free
# it, possibly because gtk.Menu memory handling is very special. # it, possibly because Gtk.Menu memory handling is very special.
self.menu.disconnect_by_func(self.__menu_item_inserted_cb) self.menu.disconnect_by_func(self.__menu_item_inserted_cb)
self.menu = None self.menu = None
@ -216,15 +216,15 @@ class Palette(PaletteWindow):
self._secondary_anim.start() self._secondary_anim.start()
def _add_menu(self): def _add_menu(self):
self._menu_box = gtk.VBox() self._menu_box = Gtk.VBox()
self._secondary_box.pack_start(self._menu_box) self._secondary_box.pack_start(self._menu_box, True, True, 0)
self._menu_box.show() self._menu_box.show()
def _add_content(self): def _add_content(self):
# The content is not shown until a widget is added # The content is not shown until a widget is added
self._content = gtk.VBox() self._content = Gtk.VBox()
self._content.set_border_width(style.DEFAULT_SPACING) self._content.set_border_width(style.DEFAULT_SPACING)
self._secondary_box.pack_start(self._content) self._secondary_box.pack_start(self._content, True, True, 0)
def _update_accel_widget(self): def _update_accel_widget(self):
assert self.props.invoker is not None assert self.props.invoker is not None
@ -240,7 +240,7 @@ class Palette(PaletteWindow):
def get_primary_text(self): def get_primary_text(self):
return self._primary_text return self._primary_text
primary_text = gobject.property(type=str, primary_text = GObject.property(type=str,
getter=get_primary_text, getter=get_primary_text,
setter=set_primary_text) setter=set_primary_text)
@ -258,7 +258,7 @@ class Palette(PaletteWindow):
def get_secondary_text(self): def get_secondary_text(self):
return self._secondary_text return self._secondary_text
secondary_text = gobject.property(type=str, getter=get_secondary_text, secondary_text = GObject.property(type=str, getter=get_secondary_text,
setter=set_secondary_text) setter=set_secondary_text)
def _show_icon(self): def _show_icon(self):
@ -278,14 +278,14 @@ class Palette(PaletteWindow):
if self._icon: if self._icon:
self._icon_box.remove(self._icon_box.get_children()[0]) self._icon_box.remove(self._icon_box.get_children()[0])
event_box = gtk.EventBox() event_box = Gtk.EventBox()
event_box.connect('button-release-event', event_box.connect('button-release-event',
self.__icon_button_release_event_cb) self.__icon_button_release_event_cb)
self._icon_box.pack_start(event_box) self._icon_box.pack_start(event_box, True, True, 0)
event_box.show() event_box.show()
self._icon = icon self._icon = icon
self._icon.props.icon_size = gtk.ICON_SIZE_LARGE_TOOLBAR self._icon.props.icon_size = Gtk.IconSize.LARGE_TOOLBAR
event_box.add(self._icon) event_box.add(self._icon)
self._icon.show() self._icon.show()
self._show_icon() self._show_icon()
@ -293,7 +293,7 @@ class Palette(PaletteWindow):
def get_icon(self): def get_icon(self):
return self._icon return self._icon
icon = gobject.property(type=object, getter=get_icon, setter=set_icon) icon = GObject.property(type=object, getter=get_icon, setter=set_icon)
def __icon_button_release_event_cb(self, icon, event): def __icon_button_release_event_cb(self, icon, event):
self.emit('activate') self.emit('activate')
@ -309,13 +309,13 @@ class Palette(PaletteWindow):
def get_icon_visible(self): def get_icon_visible(self):
return self._icon_visilbe return self._icon_visilbe
icon_visible = gobject.property(type=bool, icon_visible = GObject.property(type=bool,
default=True, default=True,
getter=get_icon_visible, getter=get_icon_visible,
setter=set_icon_visible) setter=set_icon_visible)
def set_content(self, widget): def set_content(self, widget):
if len(self._content.get_children()) > 0: if self._content.get_children():
self._content.remove(self._content.get_children()[0]) self._content.remove(self._content.get_children()[0])
if widget is not None: if widget is not None:
@ -330,7 +330,7 @@ class Palette(PaletteWindow):
def do_size_request(self, requisition): def do_size_request(self, requisition):
PaletteWindow.do_size_request(self, requisition) PaletteWindow.do_size_request(self, requisition)
# gtk.AccelLabel request doesn't include the accelerator. # Gtk.AccelLabel request doesn't include the accelerator.
label_width = self._label_alignment.size_request()[0] + \ label_width = self._label_alignment.size_request()[0] + \
self._label.get_accel_width() + \ self._label.get_accel_width() + \
2 * self.get_border_width() 2 * self.get_border_width()
@ -340,12 +340,12 @@ class Palette(PaletteWindow):
self._full_request[0]) self._full_request[0])
def _update_separators(self): def _update_separators(self):
visible = len(self.menu.get_children()) > 0 or \ visible = self.menu.get_children() or \
len(self._content.get_children()) > 0 self._content.get_children()
self._separator.props.visible = visible self._separator.props.visible = visible
visible = len(self.menu.get_children()) > 0 and \ visible = self.menu.get_children() and \
len(self._content.get_children()) > 0 self._content.get_children()
self._menu_content_separator.props.visible = visible self._menu_content_separator.props.visible = visible
def _update_accept_focus(self): def _update_accept_focus(self):
@ -382,40 +382,40 @@ class Palette(PaletteWindow):
self._palette_state = state self._palette_state = state
class PaletteActionBar(gtk.HButtonBox): class PaletteActionBar(Gtk.HButtonBox):
def add_action(self, label, icon_name=None): def add_action(self, label, icon_name=None):
button = gtk.Button(label) button = Gtk.Button(label)
if icon_name: if icon_name:
icon = Icon(icon_name) icon = Icon(icon_name)
button.set_image(icon) button.set_image(icon)
icon.show() icon.show()
self.pack_start(button) self.pack_start(button, True, True, 0)
button.show() button.show()
class _Menu(_sugarext.Menu): class _Menu(SugarExt.Menu):
__gtype_name__ = 'SugarPaletteMenu' __gtype_name__ = 'SugarPaletteMenu'
__gsignals__ = { __gsignals__ = {
'item-inserted': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'item-inserted': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
def __init__(self, palette): def __init__(self, palette):
_sugarext.Menu.__init__(self) SugarExt.Menu.__init__(self)
self._palette = palette self._palette = palette
def do_insert(self, item, position): def do_insert(self, item, position):
_sugarext.Menu.do_insert(self, item, position) SugarExt.Menu.do_insert(self, item, position)
self.emit('item-inserted') self.emit('item-inserted')
self.show() self.show()
def attach(self, child, left_attach, right_attach, def attach(self, child, left_attach, right_attach,
top_attach, bottom_attach): top_attach, bottom_attach):
_sugarext.Menu.attach(self, child, left_attach, right_attach, SugarExt.Menu.attach(self, child, left_attach, right_attach,
top_attach, bottom_attach) top_attach, bottom_attach)
self.emit('item-inserted') self.emit('item-inserted')
self.show() self.show()
@ -424,7 +424,7 @@ class _Menu(_sugarext.Menu):
# Ignore the Menu expose, just do the MenuShell expose to prevent any # Ignore the Menu expose, just do the MenuShell expose to prevent any
# border from being drawn here. A border is drawn by the palette object # border from being drawn here. A border is drawn by the palette object
# around everything. # around everything.
gtk.MenuShell.do_expose_event(self, event) Gtk.MenuShell.do_expose_event(self, event)
def do_grab_notify(self, was_grabbed): def do_grab_notify(self, was_grabbed):
# Ignore grab_notify as the menu would close otherwise # Ignore grab_notify as the menu would close otherwise

View File

@ -19,7 +19,7 @@
STABLE. STABLE.
""" """
import gobject from gi.repository import GObject
_groups = {} _groups = {}
@ -40,15 +40,15 @@ def popdown_all():
group.popdown() group.popdown()
class Group(gobject.GObject): class Group(GObject.GObject):
__gsignals__ = { __gsignals__ = {
'popup': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'popup': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'popdown': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'popdown': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
def __init__(self): def __init__(self):
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._up = False self._up = False
self._palettes = [] self._palettes = []
self._sig_ids = {} self._sig_ids = {}

View File

@ -23,9 +23,9 @@ STABLE.
import logging import logging
from gtk import gdk from gi.repository import Gdk
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
from sugar3.graphics import palettegroup from sugar3.graphics import palettegroup
from sugar3.graphics import animator from sugar3.graphics import animator
@ -39,22 +39,22 @@ def _calculate_gap(a, b):
gap = True gap = True
if a.y + a.height == b.y: if a.y + a.height == b.y:
gap_side = gtk.POS_BOTTOM gap_side = Gtk.PositionType.BOTTOM
elif a.x + a.width == b.x: elif a.x + a.width == b.x:
gap_side = gtk.POS_RIGHT gap_side = Gtk.PositionType.RIGHT
elif a.x == b.x + b.width: elif a.x == b.x + b.width:
gap_side = gtk.POS_LEFT gap_side = Gtk.PositionType.LEFT
elif a.y == b.y + b.height: elif a.y == b.y + b.height:
gap_side = gtk.POS_TOP gap_side = Gtk.PositionType.TOP
else: else:
gap = False gap = False
if gap: if gap:
if gap_side == gtk.POS_BOTTOM or gap_side == gtk.POS_TOP: if gap_side == Gtk.PositionType.BOTTOM or gap_side == Gtk.PositionType.TOP:
gap_start = min(a.width, max(0, b.x - a.x)) gap_start = min(a.width, max(0, b.x - a.x))
gap_size = max(0, min(a.width, gap_size = max(0, min(a.width,
(b.x + b.width) - a.x) - gap_start) (b.x + b.width) - a.x) - gap_start)
elif gap_side == gtk.POS_RIGHT or gap_side == gtk.POS_LEFT: elif gap_side == Gtk.PositionType.RIGHT or gap_side == Gtk.PositionType.LEFT:
gap_start = min(a.height, max(0, b.y - a.y)) gap_start = min(a.height, max(0, b.y - a.y))
gap_size = max(0, min(a.height, gap_size = max(0, min(a.height,
(b.y + b.height) - a.y) - gap_start) (b.y + b.height) - a.y) - gap_start)
@ -65,11 +65,11 @@ def _calculate_gap(a, b):
return False return False
class MouseSpeedDetector(gobject.GObject): class MouseSpeedDetector(GObject.GObject):
__gsignals__ = { __gsignals__ = {
'motion-slow': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'motion-slow': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'motion-fast': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'motion-fast': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
_MOTION_SLOW = 1 _MOTION_SLOW = 1
@ -80,7 +80,7 @@ class MouseSpeedDetector(gobject.GObject):
delay in msec delay in msec
threshold in pixels (per tick of 'delay' msec)""" threshold in pixels (per tick of 'delay' msec)"""
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._threshold = thresh self._threshold = thresh
self._parent = parent self._parent = parent
@ -93,15 +93,15 @@ class MouseSpeedDetector(gobject.GObject):
self.stop() self.stop()
self._mouse_pos = self._get_mouse_position() self._mouse_pos = self._get_mouse_position()
self._timeout_hid = gobject.timeout_add(self._delay, self._timer_cb) self._timeout_hid = GObject.timeout_add(self._delay, self._timer_cb)
def stop(self): def stop(self):
if self._timeout_hid is not None: if self._timeout_hid is not None:
gobject.source_remove(self._timeout_hid) GObject.source_remove(self._timeout_hid)
self._state = None self._state = None
def _get_mouse_position(self): def _get_mouse_position(self):
display = gtk.gdk.display_get_default() display = Gdk.Display.get_default()
screen_, x, y, mask_ = display.get_pointer() screen_, x, y, mask_ = display.get_pointer()
return (x, y) return (x, y)
@ -128,14 +128,14 @@ class MouseSpeedDetector(gobject.GObject):
return True return True
class PaletteWindow(gtk.Window): class PaletteWindow(Gtk.Window):
__gtype_name__ = 'SugarPaletteWindow' __gtype_name__ = 'SugarPaletteWindow'
__gsignals__ = { __gsignals__ = {
'popup': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'popup': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'popdown': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'popdown': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'activate': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'activate': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -155,14 +155,14 @@ class PaletteWindow(gtk.Window):
self._popdown_anim = animator.Animator(0.6, 10) self._popdown_anim = animator.Animator(0.6, 10)
self._popdown_anim.add(_PopdownAnimation(self)) self._popdown_anim.add(_PopdownAnimation(self))
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
self.set_decorated(False) self.set_decorated(False)
self.set_resizable(False) self.set_resizable(False)
# Just assume xthickness and ythickness are the same # Just assume xthickness and ythickness are the same
self.set_border_width(self.get_style().xthickness) self.set_border_width(self.get_style().xthickness)
accel_group = gtk.AccelGroup() accel_group = Gtk.AccelGroup()
self.set_data('sugar-accel-group', accel_group) self.set_data('sugar-accel-group', accel_group)
self.add_accel_group(accel_group) self.add_accel_group(accel_group)
@ -199,12 +199,12 @@ class PaletteWindow(gtk.Window):
def get_invoker(self): def get_invoker(self):
return self._invoker return self._invoker
invoker = gobject.property(type=object, invoker = GObject.property(type=object,
getter=get_invoker, getter=get_invoker,
setter=set_invoker) setter=set_invoker)
def __realize_cb(self, widget): def __realize_cb(self, widget):
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
def _mouse_slow_cb(self, widget): def _mouse_slow_cb(self, widget):
self._mouse_detector.stop() self._mouse_detector.stop()
@ -240,16 +240,16 @@ class PaletteWindow(gtk.Window):
def get_group_id(self): def get_group_id(self):
return self._group_id return self._group_id
group_id = gobject.property(type=str, group_id = GObject.property(type=str,
getter=get_group_id, getter=get_group_id,
setter=set_group_id) setter=set_group_id)
def do_size_request(self, requisition): def do_size_request(self, requisition):
gtk.Window.do_size_request(self, requisition) Gtk.Window.do_size_request(self, requisition)
requisition.width = max(requisition.width, style.GRID_CELL_SIZE * 2) requisition.width = max(requisition.width, style.GRID_CELL_SIZE * 2)
def do_size_allocate(self, allocation): def do_size_allocate(self, allocation):
gtk.Window.do_size_allocate(self, allocation) Gtk.Window.do_size_allocate(self, allocation)
if self._old_alloc is None or \ if self._old_alloc is None or \
self._old_alloc.x != allocation.x or \ self._old_alloc.x != allocation.x or \
@ -260,7 +260,7 @@ class PaletteWindow(gtk.Window):
# We need to store old allocation because when size_allocate # We need to store old allocation because when size_allocate
# is called widget.allocation is already updated. # is called widget.allocation is already updated.
# gtk.Window resizing is different from normal containers: # Gtk.Window resizing is different from normal containers:
# the X window is resized, widget.allocation is updated from # the X window is resized, widget.allocation is updated from
# the configure request handler and finally size_allocate is called. # the configure request handler and finally size_allocate is called.
self._old_alloc = allocation self._old_alloc = allocation
@ -279,18 +279,18 @@ class PaletteWindow(gtk.Window):
wstyle = self.get_style() wstyle = self.get_style()
if gap: if gap:
wstyle.paint_box_gap(event.window, gtk.STATE_PRELIGHT, wstyle.paint_box_gap(event.window, Gtk.StateType.PRELIGHT,
gtk.SHADOW_IN, event.area, self, 'palette', Gtk.ShadowType.IN, event.area, self, 'palette',
0, 0, allocation.width, allocation.height, 0, 0, allocation.width, allocation.height,
gap[0], gap[1], gap[2]) gap[0], gap[1], gap[2])
else: else:
wstyle.paint_box(event.window, gtk.STATE_PRELIGHT, wstyle.paint_box(event.window, Gtk.StateType.PRELIGHT,
gtk.SHADOW_IN, event.area, self, 'palette', Gtk.ShadowType.IN, event.area, self, 'palette',
0, 0, allocation.width, allocation.height) 0, 0, allocation.width, allocation.height)
# Fall trough to the container expose handler. # Fall trough to the container expose handler.
# (Leaving out the window expose handler which redraws everything) # (Leaving out the window expose handler which redraws everything)
gtk.Bin.do_expose_event(self, event) Gtk.Bin.do_expose_event(self, event)
def update_position(self): def update_position(self):
invoker = self._invoker invoker = self._invoker
@ -362,13 +362,13 @@ class PaletteWindow(gtk.Window):
self.popup(immediate=True) self.popup(immediate=True)
def __enter_notify_event_cb(self, widget, event): def __enter_notify_event_cb(self, widget, event):
if event.detail != gtk.gdk.NOTIFY_INFERIOR and \ if event.detail != Gdk.NOTIFY_INFERIOR and \
event.mode == gtk.gdk.CROSSING_NORMAL: event.mode == Gdk.CROSSING_NORMAL:
self.on_enter(event) self.on_enter(event)
def __leave_notify_event_cb(self, widget, event): def __leave_notify_event_cb(self, widget, event):
if event.detail != gtk.gdk.NOTIFY_INFERIOR and \ if event.detail != Gdk.NOTIFY_INFERIOR and \
event.mode == gtk.gdk.CROSSING_NORMAL: event.mode == Gdk.CROSSING_NORMAL:
self.on_leave(event) self.on_leave(event)
def __show_cb(self, widget): def __show_cb(self, widget):
@ -393,7 +393,7 @@ class PaletteWindow(gtk.Window):
y = win_y + rectangle.y y = win_y + rectangle.y
width, height = self.size_request() width, height = self.size_request()
return gtk.gdk.Rectangle(x, y, width, height) return (x, y, width, height)
def get_palette_state(self): def get_palette_state(self):
return self._palette_state return self._palette_state
@ -429,15 +429,15 @@ class _PopdownAnimation(animator.Animation):
self._palette.popdown(immediate=True) self._palette.popdown(immediate=True)
class Invoker(gobject.GObject): class Invoker(GObject.GObject):
__gtype_name__ = 'SugarPaletteInvoker' __gtype_name__ = 'SugarPaletteInvoker'
__gsignals__ = { __gsignals__ = {
'mouse-enter': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'mouse-enter': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'mouse-leave': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'mouse-leave': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'right-click': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'right-click': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'focus-out': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'focus-out': (GObject.SignalFlags.RUN_FIRST, None, ([])),
} }
ANCHORED = 0 ANCHORED = 0
@ -449,12 +449,12 @@ class Invoker(gobject.GObject):
LEFT = [(-1.0, 0.0, 0.0, 0.0), (-1.0, -1.0, 0.0, 1.0)] LEFT = [(-1.0, 0.0, 0.0, 0.0), (-1.0, -1.0, 0.0, 1.0)]
def __init__(self): def __init__(self):
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self.parent = None self.parent = None
self._screen_area = gtk.gdk.Rectangle(0, 0, gtk.gdk.screen_width(), self._screen_area = (0, 0, Gdk.Screen.width(),
gtk.gdk.screen_height()) Gdk.Screen.height())
self._position_hint = self.ANCHORED self._position_hint = self.ANCHORED
self._cursor_x = -1 self._cursor_x = -1
self._cursor_y = -1 self._cursor_y = -1
@ -477,7 +477,7 @@ class Invoker(gobject.GObject):
invoker_valign = alignment[3] invoker_valign = alignment[3]
if self._cursor_x == -1 or self._cursor_y == -1: if self._cursor_x == -1 or self._cursor_y == -1:
display = gtk.gdk.display_get_default() display = Gdk.Display.get_default()
screen_, x, y, mask_ = display.get_pointer() screen_, x, y, mask_ = display.get_pointer()
self._cursor_x = x self._cursor_x = x
self._cursor_y = y self._cursor_y = y
@ -486,7 +486,7 @@ class Invoker(gobject.GObject):
rect = self.get_rect() rect = self.get_rect()
else: else:
dist = style.PALETTE_CURSOR_DISTANCE dist = style.PALETTE_CURSOR_DISTANCE
rect = gtk.gdk.Rectangle(self._cursor_x - dist, rect = (self._cursor_x - dist,
self._cursor_y - dist, self._cursor_y - dist,
dist * 2, dist * 2) dist * 2, dist * 2)
@ -498,7 +498,7 @@ class Invoker(gobject.GObject):
y = rect.y + rect.height * invoker_valign + \ y = rect.y + rect.height * invoker_valign + \
palette_height * palette_valign palette_height * palette_valign
return gtk.gdk.Rectangle(int(x), int(y), return (int(x), int(y),
palette_width, palette_height) palette_width, palette_height)
def _in_screen(self, rect): def _in_screen(self, rect):
@ -647,9 +647,9 @@ class Invoker(gobject.GObject):
# menu item. We need to postpone destruction of the palette until # menu item. We need to postpone destruction of the palette until
# after all signals have propagated from the menu item to the # after all signals have propagated from the menu item to the
# palette owner. # palette owner.
gobject.idle_add(lambda old_palette=self._palette: GObject.idle_add(lambda old_palette=self._palette:
old_palette.destroy(), old_palette.destroy(),
priority=gobject.PRIORITY_LOW) priority=GObject.PRIORITY_LOW)
self._palette = palette self._palette = palette
@ -657,7 +657,7 @@ class Invoker(gobject.GObject):
self._palette.props.invoker = self self._palette.props.invoker = self
self._palette.connect('popdown', self.__palette_popdown_cb) self._palette.connect('popdown', self.__palette_popdown_cb)
palette = gobject.property( palette = GObject.property(
type=object, setter=set_palette, getter=get_palette) type=object, setter=set_palette, getter=get_palette)
def get_cache_palette(self): def get_cache_palette(self):
@ -666,7 +666,7 @@ class Invoker(gobject.GObject):
def set_cache_palette(self, cache_palette): def set_cache_palette(self, cache_palette):
self._cache_palette = cache_palette self._cache_palette = cache_palette
cache_palette = gobject.property(type=object, setter=set_cache_palette, cache_palette = GObject.property(type=object, setter=set_cache_palette,
getter=get_cache_palette) getter=get_cache_palette)
"""Whether the invoker will cache the palette after its creation. Defaults """Whether the invoker will cache the palette after its creation. Defaults
to True. to True.
@ -723,20 +723,20 @@ class WidgetInvoker(Invoker):
x = 0 x = 0
y = 0 y = 0
if self._widget.flags() & gtk.NO_WINDOW: if self._widget.flags() & Gtk.NO_WINDOW:
x += allocation.x x += allocation.x
y += allocation.y y += allocation.y
width = allocation.width width = allocation.width
height = allocation.height height = allocation.height
return gtk.gdk.Rectangle(x, y, width, height) return (x, y, width, height)
def has_rectangle_gap(self): def has_rectangle_gap(self):
return True return True
def draw_rectangle(self, event, palette): def draw_rectangle(self, event, palette):
if self._widget.flags() & gtk.NO_WINDOW: if self._widget.flags() & Gtk.NO_WINDOW:
x, y = self._widget.allocation.x, self._widget.allocation.y x, y = self._widget.allocation.x, self._widget.allocation.y
else: else:
x = y = 0 x = y = 0
@ -745,15 +745,15 @@ class WidgetInvoker(Invoker):
gap = _calculate_gap(self.get_rect(), palette.get_rect()) gap = _calculate_gap(self.get_rect(), palette.get_rect())
if gap: if gap:
wstyle.paint_box_gap(event.window, gtk.STATE_PRELIGHT, wstyle.paint_box_gap(event.window, Gtk.StateType.PRELIGHT,
gtk.SHADOW_IN, event.area, self._widget, Gtk.ShadowType.IN, event.area, self._widget,
'palette-invoker', x, y, 'palette-invoker', x, y,
self._widget.allocation.width, self._widget.allocation.width,
self._widget.allocation.height, self._widget.allocation.height,
gap[0], gap[1], gap[2]) gap[0], gap[1], gap[2])
else: else:
wstyle.paint_box(event.window, gtk.STATE_PRELIGHT, wstyle.paint_box(event.window, Gtk.StateType.PRELIGHT,
gtk.SHADOW_IN, event.area, self._widget, Gtk.ShadowType.IN, event.area, self._widget,
'palette-invoker', x, y, 'palette-invoker', x, y,
self._widget.allocation.width, self._widget.allocation.width,
self._widget.allocation.height) self._widget.allocation.height)
@ -784,7 +784,7 @@ class WidgetInvoker(Invoker):
def _get_widget(self): def _get_widget(self):
return self._widget return self._widget
widget = gobject.property(type=object, getter=_get_widget, setter=None) widget = GObject.property(type=object, getter=_get_widget, setter=None)
class ToolInvoker(WidgetInvoker): class ToolInvoker(WidgetInvoker):
@ -796,14 +796,14 @@ class ToolInvoker(WidgetInvoker):
self.attach_tool(parent) self.attach_tool(parent)
def attach_tool(self, widget): def attach_tool(self, widget):
self.attach_widget(widget, widget.child) self.attach_widget(widget, widget.get_child())
def _get_alignments(self): def _get_alignments(self):
parent = self._widget.get_parent() parent = self._widget.get_parent()
if parent is None: if parent is None:
return WidgetInvoker._get_alignments(self) return WidgetInvoker._get_alignments(self)
if parent.get_orientation() is gtk.ORIENTATION_HORIZONTAL: if parent.get_orientation() is Gtk.Orientation.HORIZONTAL:
return self.BOTTOM + self.TOP return self.BOTTOM + self.TOP
else: else:
return self.LEFT + self.RIGHT return self.LEFT + self.RIGHT
@ -851,14 +851,14 @@ class CellRendererInvoker(Invoker):
x = 0 x = 0
y = 0 y = 0
if self._tree_view.flags() & gtk.NO_WINDOW: if self._tree_view.flags() & Gtk.NO_WINDOW:
x += allocation.x x += allocation.x
y += allocation.y y += allocation.y
width = allocation.width width = allocation.width
height = allocation.height height = allocation.height
return gtk.gdk.Rectangle(x, y, width, height) return (x, y, width, height)
def __motion_notify_event_cb(self, widget, event): def __motion_notify_event_cb(self, widget, event):
if event.window != widget.get_bin_window(): if event.window != widget.get_bin_window():

View File

@ -19,12 +19,12 @@
STABLE. STABLE.
""" """
import gtk from gi.repository import Gtk
class Panel(gtk.VBox): class Panel(Gtk.VBox):
__gtype_name__ = 'SugarPanel' __gtype_name__ = 'SugarPanel'
def __init__(self): def __init__(self):
gtk.VBox.__init__(self) GObject.GObject.__init__(self)

View File

@ -15,7 +15,7 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import gtk from gi.repository import Gtk
from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.palette import Palette from sugar3.graphics.palette import Palette
@ -63,7 +63,7 @@ class RadioPalette(Palette):
def __init__(self, **kwargs): def __init__(self, **kwargs):
Palette.__init__(self, **kwargs) Palette.__init__(self, **kwargs)
self.button_box = gtk.HBox() self.button_box = Gtk.HBox()
self.button_box.show() self.button_box.show()
self.set_content(self.button_box) self.set_content(self.button_box)
@ -75,7 +75,7 @@ class RadioPalette(Palette):
button.show() button.show()
button.connect('clicked', self.__clicked_cb) button.connect('clicked', self.__clicked_cb)
self.button_box.pack_start(button, fill=False) self.button_box.pack_start(button, True, False, 0)
button.palette_label = label button.palette_label = label
if not children: if not children:

View File

@ -20,15 +20,15 @@
STABLE. STABLE.
""" """
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
from sugar3.graphics.palette import Palette, ToolInvoker from sugar3.graphics.palette import Palette, ToolInvoker
from sugar3.graphics import toolbutton from sugar3.graphics import toolbutton
class RadioToolButton(gtk.RadioToolButton): class RadioToolButton(Gtk.RadioToolButton):
""" """
An implementation of a "push" button. An implementation of a "push" button.
@ -42,7 +42,7 @@ class RadioToolButton(gtk.RadioToolButton):
self._xo_color = None self._xo_color = None
self._palette_invoker = ToolInvoker() self._palette_invoker = ToolInvoker()
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
self._palette_invoker.attach_tool(self) self._palette_invoker.attach_tool(self)
@ -73,12 +73,12 @@ class RadioToolButton(gtk.RadioToolButton):
self._tooltip = tooltip self._tooltip = tooltip
# Set label, shows up when toolbar overflows # Set label, shows up when toolbar overflows
gtk.RadioToolButton.set_label(self, tooltip) Gtk.RadioToolButton.set_label(self, tooltip)
def get_tooltip(self): def get_tooltip(self):
return self._tooltip return self._tooltip
tooltip = gobject.property(type=str, setter=set_tooltip, tooltip = GObject.property(type=str, setter=set_tooltip,
getter=get_tooltip) getter=get_tooltip)
def set_accelerator(self, accelerator): def set_accelerator(self, accelerator):
@ -112,13 +112,13 @@ class RadioToolButton(gtk.RadioToolButton):
""" """
return self._accelerator return self._accelerator
accelerator = gobject.property(type=str, setter=set_accelerator, accelerator = GObject.property(type=str, setter=set_accelerator,
getter=get_accelerator) getter=get_accelerator)
def set_named_icon(self, named_icon): def set_named_icon(self, named_icon):
icon = Icon(icon_name=named_icon, icon = Icon(icon_name=named_icon,
xo_color=self._xo_color, xo_color=self._xo_color,
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) icon_size=Gtk.IconSize.LARGE_TOOLBAR)
self.set_icon_widget(icon) self.set_icon_widget(icon)
icon.show() icon.show()
@ -128,7 +128,7 @@ class RadioToolButton(gtk.RadioToolButton):
else: else:
return None return None
named_icon = gobject.property(type=str, setter=set_named_icon, named_icon = GObject.property(type=str, setter=set_named_icon,
getter=get_named_icon) getter=get_named_icon)
def set_xo_color(self, xo_color): def set_xo_color(self, xo_color):
@ -140,7 +140,7 @@ class RadioToolButton(gtk.RadioToolButton):
def get_xo_color(self): def get_xo_color(self):
return self._xo_color return self._xo_color
xo_color = gobject.property(type=object, setter=set_xo_color, xo_color = GObject.property(type=object, setter=set_xo_color,
getter=get_xo_color) getter=get_xo_color)
def create_palette(self): def create_palette(self):
@ -152,7 +152,7 @@ class RadioToolButton(gtk.RadioToolButton):
def set_palette(self, palette): def set_palette(self, palette):
self._palette_invoker.palette = palette self._palette_invoker.palette = palette
palette = gobject.property( palette = GObject.property(
type=object, setter=set_palette, getter=get_palette) type=object, setter=set_palette, getter=get_palette)
def get_palette_invoker(self): def get_palette_invoker(self):
@ -162,7 +162,7 @@ class RadioToolButton(gtk.RadioToolButton):
self._palette_invoker.detach() self._palette_invoker.detach()
self._palette_invoker = palette_invoker self._palette_invoker = palette_invoker
palette_invoker = gobject.property( palette_invoker = GObject.property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker) type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def do_expose_event(self, event): def do_expose_event(self, event):
@ -172,11 +172,11 @@ class RadioToolButton(gtk.RadioToolButton):
if self.palette and self.palette.is_up(): if self.palette and self.palette.is_up():
invoker = self.palette.props.invoker invoker = self.palette.props.invoker
invoker.draw_rectangle(event, self.palette) invoker.draw_rectangle(event, self.palette)
elif child.state == gtk.STATE_PRELIGHT: elif child.state == Gtk.StateType.PRELIGHT:
child.style.paint_box(event.window, gtk.STATE_PRELIGHT, child.style.paint_box(event.window, Gtk.StateType.PRELIGHT,
gtk.SHADOW_NONE, event.area, Gtk.ShadowType.NONE, event.area,
child, 'toolbutton-prelight', child, 'toolbutton-prelight',
allocation.x, allocation.y, allocation.x, allocation.y,
allocation.width, allocation.height) allocation.width, allocation.height)
gtk.RadioToolButton.do_expose_event(self, event) Gtk.RadioToolButton.do_expose_event(self, event)

View File

@ -25,10 +25,10 @@ STABLE.
import os import os
import logging import logging
from gtk import gdk from gi.repository import Gdk
import gtk from gi.repository import Gtk
import pango from gi.repository import Pango
import gconf from gi.repository import GConf
FOCUS_LINE_WIDTH = 2 FOCUS_LINE_WIDTH = 2
@ -54,7 +54,7 @@ class Font(object):
return self._desc return self._desc
def get_pango_desc(self): def get_pango_desc(self):
return pango.FontDescription(self._desc) return Pango.FontDescription(self._desc)
class Color(object): class Color(object):
@ -71,7 +71,7 @@ class Color(object):
(int(self._g * 255) << 16) + (int(self._r * 255) << 24) (int(self._g * 255) << 16) + (int(self._r * 255) << 24)
def get_gdk_color(self): def get_gdk_color(self):
return gtk.gdk.Color(int(self._r * 65535), int(self._g * 65535), return Gdk.Color(int(self._r * 65535), int(self._g * 65535),
int(self._b * 65535)) int(self._b * 65535))
def get_html(self): def get_html(self):
@ -116,7 +116,7 @@ MEDIUM_ICON_SIZE = zoom(55 * 1.5)
LARGE_ICON_SIZE = zoom(55 * 2.0) LARGE_ICON_SIZE = zoom(55 * 2.0)
XLARGE_ICON_SIZE = zoom(55 * 2.75) XLARGE_ICON_SIZE = zoom(55 * 2.75)
client = gconf.client_get_default() client = GConf.Client.get_default()
FONT_SIZE = client.get_float('/desktop/sugar/font/default_size') FONT_SIZE = client.get_float('/desktop/sugar/font/default_size')
FONT_FACE = client.get_string('/desktop/sugar/font/default_face') FONT_FACE = client.get_string('/desktop/sugar/font/default_face')

View File

@ -19,19 +19,19 @@
STABLE. STABLE.
""" """
import gobject from gi.repository import GObject
import gtk from gi.repository import Gtk
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
from sugar3.graphics.palette import Palette, ToolInvoker from sugar3.graphics.palette import Palette, ToolInvoker
class ToggleToolButton(gtk.ToggleToolButton): class ToggleToolButton(Gtk.ToggleToolButton):
__gtype_name__ = 'SugarToggleToolButton' __gtype_name__ = 'SugarToggleToolButton'
def __init__(self, named_icon=None): def __init__(self, named_icon=None):
gtk.ToggleToolButton.__init__(self) GObject.GObject.__init__(self)
self._palette_invoker = ToolInvoker(self) self._palette_invoker = ToolInvoker(self)
self.set_named_icon(named_icon) self.set_named_icon(named_icon)
@ -56,7 +56,7 @@ class ToggleToolButton(gtk.ToggleToolButton):
def set_palette(self, palette): def set_palette(self, palette):
self._palette_invoker.palette = palette self._palette_invoker.palette = palette
palette = gobject.property( palette = GObject.property(
type=object, setter=set_palette, getter=get_palette) type=object, setter=set_palette, getter=get_palette)
def get_palette_invoker(self): def get_palette_invoker(self):
@ -66,7 +66,7 @@ class ToggleToolButton(gtk.ToggleToolButton):
self._palette_invoker.detach() self._palette_invoker.detach()
self._palette_invoker = palette_invoker self._palette_invoker = palette_invoker
palette_invoker = gobject.property( palette_invoker = GObject.property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker) type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def set_tooltip(self, text): def set_tooltip(self, text):
@ -79,13 +79,13 @@ class ToggleToolButton(gtk.ToggleToolButton):
if self.palette and self.palette.is_up(): if self.palette and self.palette.is_up():
invoker = self.palette.props.invoker invoker = self.palette.props.invoker
invoker.draw_rectangle(event, self.palette) invoker.draw_rectangle(event, self.palette)
elif child.state == gtk.STATE_PRELIGHT: elif child.state == Gtk.StateType.PRELIGHT:
child.style.paint_box(event.window, gtk.STATE_PRELIGHT, child.style.paint_box(event.window, Gtk.StateType.PRELIGHT,
gtk.SHADOW_NONE, event.area, Gtk.ShadowType.NONE, event.area,
child, 'toolbutton-prelight', child, 'toolbutton-prelight',
allocation.x, allocation.y, allocation.x, allocation.y,
allocation.width, allocation.height) allocation.width, allocation.height)
gtk.ToggleToolButton.do_expose_event(self, event) Gtk.ToggleToolButton.do_expose_event(self, event)
palette = property(get_palette, set_palette) palette = property(get_palette, set_palette)

View File

@ -15,8 +15,8 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
from sugar3.graphics import style from sugar3.graphics import style
from sugar3.graphics.palette import PaletteWindow, ToolInvoker from sugar3.graphics.palette import PaletteWindow, ToolInvoker
@ -42,7 +42,7 @@ class ToolbarButton(ToolButton):
if hasattr(self.parent, 'owner'): if hasattr(self.parent, 'owner'):
if self.page_widget and previous_toplevel is None: if self.page_widget and previous_toplevel is None:
self._unparent() self._unparent()
self.parent.owner.pack_start(self.page_widget) self.parent.owner.pack_start(self.page_widget, True, True, 0)
self.set_expanded(False) self.set_expanded(False)
def get_toolbar_box(self): def get_toolbar_box(self):
@ -68,7 +68,7 @@ class ToolbarButton(ToolButton):
self.props.palette = _ToolbarPalette(invoker=ToolInvoker(self)) self.props.palette = _ToolbarPalette(invoker=ToolInvoker(self))
self._move_page_to_palette() self._move_page_to_palette()
page = gobject.property(type=object, getter=get_page, setter=set_page) page = GObject.property(type=object, getter=get_page, setter=set_page)
def is_in_palette(self): def is_in_palette(self):
return self.page is not None and \ return self.page is not None and \
@ -103,9 +103,9 @@ class ToolbarButton(ToolButton):
self._unparent() self._unparent()
self.modify_bg(gtk.STATE_NORMAL, box.background) self.modify_bg(Gtk.StateType.NORMAL, box.background)
_setup_page(self.page_widget, box.background, box.props.padding) _setup_page(self.page_widget, box.background, box.props.padding)
box.pack_start(self.page_widget) box.pack_start(self.page_widget, True, True, 0)
def _move_page_to_palette(self): def _move_page_to_palette(self):
if self.is_in_palette(): if self.is_in_palette():
@ -125,43 +125,43 @@ class ToolbarButton(ToolButton):
if not self.is_expanded() or self.props.palette is not None and \ if not self.is_expanded() or self.props.palette is not None and \
self.props.palette.is_up(): self.props.palette.is_up():
ToolButton.do_expose_event(self, event) ToolButton.do_expose_event(self, event)
_paint_arrow(self, event, gtk.ARROW_DOWN) _paint_arrow(self, event, Gtk.ArrowType.DOWN)
return return
alloc = self.allocation alloc = self.allocation
self.get_style().paint_box(event.window, self.get_style().paint_box(event.window,
gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, self, Gtk.StateType.NORMAL, Gtk.ShadowType.IN, event.area, self,
'palette-invoker', alloc.x, 0, 'palette-invoker', alloc.x, 0,
alloc.width, alloc.height + style.FOCUS_LINE_WIDTH) alloc.width, alloc.height + style.FOCUS_LINE_WIDTH)
if self.child.state != gtk.STATE_PRELIGHT: if self.get_child().state != Gtk.StateType.PRELIGHT:
self.get_style().paint_box(event.window, self.get_style().paint_box(event.window,
gtk.STATE_NORMAL, gtk.SHADOW_NONE, event.area, self, None, Gtk.StateType.NORMAL, Gtk.ShadowType.NONE, event.area, self, None,
alloc.x + style.FOCUS_LINE_WIDTH, style.FOCUS_LINE_WIDTH, alloc.x + style.FOCUS_LINE_WIDTH, style.FOCUS_LINE_WIDTH,
alloc.width - style.FOCUS_LINE_WIDTH * 2, alloc.height) alloc.width - style.FOCUS_LINE_WIDTH * 2, alloc.height)
gtk.ToolButton.do_expose_event(self, event) Gtk.ToolButton.do_expose_event(self, event)
_paint_arrow(self, event, gtk.ARROW_UP) _paint_arrow(self, event, Gtk.ArrowType.UP)
class ToolbarBox(gtk.VBox): class ToolbarBox(Gtk.VBox):
def __init__(self, padding=style.TOOLBOX_HORIZONTAL_PADDING): def __init__(self, padding=style.TOOLBOX_HORIZONTAL_PADDING):
gtk.VBox.__init__(self) GObject.GObject.__init__(self)
self._expanded_button_index = -1 self._expanded_button_index = -1
self.background = None self.background = None
self._toolbar = gtk.Toolbar() self._toolbar = Gtk.Toolbar()
self._toolbar.owner = self self._toolbar.owner = self
self._toolbar.connect('remove', self.__remove_cb) self._toolbar.connect('remove', self.__remove_cb)
self._toolbar_widget, self._toolbar_alignment = \ self._toolbar_widget, self._toolbar_alignment = \
_embed_page(gtk.EventBox, self._toolbar) _embed_page(Gtk.EventBox, self._toolbar)
self.pack_start(self._toolbar_widget) self.pack_start(self._toolbar_widget, True, True, 0)
self.props.padding = padding self.props.padding = padding
self.modify_bg(gtk.STATE_NORMAL, self.modify_bg(Gtk.StateType.NORMAL,
style.COLOR_TOOLBAR_GREY.get_gdk_color()) style.COLOR_TOOLBAR_GREY.get_gdk_color())
def get_toolbar(self): def get_toolbar(self):
@ -188,11 +188,11 @@ class ToolbarBox(gtk.VBox):
def set_padding(self, pad): def set_padding(self, pad):
self._toolbar_alignment.set_padding(0, 0, pad, pad) self._toolbar_alignment.set_padding(0, 0, pad, pad)
padding = gobject.property(type=object, padding = GObject.property(type=object,
getter=get_padding, setter=set_padding) getter=get_padding, setter=set_padding)
def modify_bg(self, state, color): def modify_bg(self, state, color):
if state == gtk.STATE_NORMAL: if state == Gtk.StateType.NORMAL:
self.background = color self.background = color
self._toolbar_widget.modify_bg(state, color) self._toolbar_widget.modify_bg(state, color)
self.toolbar.modify_bg(state, color) self.toolbar.modify_bg(state, color)
@ -246,9 +246,9 @@ class _ToolbarPalette(PaletteWindow):
self.popdown() self.popdown()
def do_size_request(self, requisition): def do_size_request(self, requisition):
gtk.Window.do_size_request(self, requisition) Gtk.Window.do_size_request(self, requisition)
requisition.width = max(requisition.width, requisition.width = max(requisition.width,
gtk.gdk.screen_width()) Gdk.Screen.width())
def popup(self, immediate=False): def popup(self, immediate=False):
button = self.expanded_button button = self.expanded_button
@ -264,10 +264,10 @@ class _ToolbarPalette(PaletteWindow):
self.popdown(immediate=True) self.popdown(immediate=True)
class _Box(gtk.EventBox): class _Box(Gtk.EventBox):
def __init__(self): def __init__(self):
gtk.EventBox.__init__(self) GObject.GObject.__init__(self)
self.connect('expose-event', self.do_expose_event) self.connect('expose-event', self.do_expose_event)
self.set_app_paintable(True) self.set_app_paintable(True)
@ -276,12 +276,12 @@ class _Box(gtk.EventBox):
return return
alloc = self.parent.expanded_button.allocation alloc = self.parent.expanded_button.allocation
self.get_style().paint_box(event.window, self.get_style().paint_box(event.window,
gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, self, Gtk.StateType.NORMAL, Gtk.ShadowType.IN, event.area, self,
'palette-invoker', -style.FOCUS_LINE_WIDTH, 0, 'palette-invoker', -style.FOCUS_LINE_WIDTH, 0,
self.allocation.width + style.FOCUS_LINE_WIDTH * 2, self.allocation.width + style.FOCUS_LINE_WIDTH * 2,
self.allocation.height + style.FOCUS_LINE_WIDTH) self.allocation.height + style.FOCUS_LINE_WIDTH)
self.get_style().paint_box(event.window, self.get_style().paint_box(event.window,
gtk.STATE_NORMAL, gtk.SHADOW_NONE, event.area, self, None, Gtk.StateType.NORMAL, Gtk.ShadowType.NONE, event.area, self, None,
alloc.x + style.FOCUS_LINE_WIDTH, 0, alloc.x + style.FOCUS_LINE_WIDTH, 0,
alloc.width - style.FOCUS_LINE_WIDTH * 2, alloc.width - style.FOCUS_LINE_WIDTH * 2,
style.FOCUS_LINE_WIDTH) style.FOCUS_LINE_WIDTH)
@ -289,27 +289,27 @@ class _Box(gtk.EventBox):
def _setup_page(page_widget, color, hpad): def _setup_page(page_widget, color, hpad):
vpad = style.FOCUS_LINE_WIDTH vpad = style.FOCUS_LINE_WIDTH
page_widget.child.set_padding(vpad, vpad, hpad, hpad) page_widget.get_child().set_padding(vpad, vpad, hpad, hpad)
page = _get_embedded_page(page_widget) page = _get_embedded_page(page_widget)
page.modify_bg(gtk.STATE_NORMAL, color) page.modify_bg(Gtk.StateType.NORMAL, color)
if isinstance(page, gtk.Container): if isinstance(page, Gtk.Container):
for i in page.get_children(): for i in page.get_children():
i.modify_bg(gtk.STATE_INSENSITIVE, color) i.modify_bg(Gtk.StateType.INSENSITIVE, color)
page_widget.modify_bg(gtk.STATE_NORMAL, color) page_widget.modify_bg(Gtk.StateType.NORMAL, color)
page_widget.modify_bg(gtk.STATE_PRELIGHT, color) page_widget.modify_bg(Gtk.StateType.PRELIGHT, color)
def _embed_page(box_class, page): def _embed_page(box_class, page):
page.show() page.show()
alignment = gtk.Alignment(0.0, 0.0, 1.0, 1.0) alignment = Gtk.Alignment.new(0.0, 0.0, 1.0, 1.0)
alignment.add(page) alignment.add(page)
alignment.show() alignment.show()
page_widget = box_class() page_widget = box_class()
page_widget.modify_bg(gtk.STATE_ACTIVE, page_widget.modify_bg(Gtk.StateType.ACTIVE,
style.COLOR_BUTTON_GREY.get_gdk_color()) style.COLOR_BUTTON_GREY.get_gdk_color())
page_widget.add(alignment) page_widget.add(alignment)
page_widget.show() page_widget.show()
@ -318,7 +318,7 @@ def _embed_page(box_class, page):
def _get_embedded_page(page_widget): def _get_embedded_page(page_widget):
return page_widget.child.child return page_widget.get_child().child
def _paint_arrow(widget, event, arrow_type): def _paint_arrow(widget, event, arrow_type):
@ -327,6 +327,6 @@ def _paint_arrow(widget, event, arrow_type):
y = alloc.y + alloc.height - int(style.TOOLBAR_ARROW_SIZE * .85) y = alloc.y + alloc.height - int(style.TOOLBAR_ARROW_SIZE * .85)
widget.get_style().paint_arrow(event.window, widget.get_style().paint_arrow(event.window,
gtk.STATE_NORMAL, gtk.SHADOW_NONE, event.area, widget, Gtk.StateType.NORMAL, Gtk.ShadowType.NONE, event.area, widget,
None, arrow_type, True, None, arrow_type, True,
x, y, style.TOOLBAR_ARROW_SIZE, style.TOOLBAR_ARROW_SIZE) x, y, style.TOOLBAR_ARROW_SIZE, style.TOOLBAR_ARROW_SIZE)

View File

@ -19,35 +19,35 @@
STABLE. STABLE.
""" """
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
from sugar3.graphics import style from sugar3.graphics import style
class Toolbox(gtk.VBox): class Toolbox(Gtk.VBox):
__gtype_name__ = 'SugarToolbox' __gtype_name__ = 'SugarToolbox'
__gsignals__ = { __gsignals__ = {
'current-toolbar-changed': (gobject.SIGNAL_RUN_FIRST, 'current-toolbar-changed': (GObject.SignalFlags.RUN_FIRST,
gobject.TYPE_NONE, ([int])), None, ([int])),
} }
def __init__(self): def __init__(self):
gtk.VBox.__init__(self) GObject.GObject.__init__(self)
self._notebook = gtk.Notebook() self._notebook = Gtk.Notebook()
self._notebook.set_tab_pos(gtk.POS_BOTTOM) self._notebook.set_tab_pos(Gtk.PositionType.BOTTOM)
self._notebook.set_show_border(False) self._notebook.set_show_border(False)
self._notebook.set_show_tabs(False) self._notebook.set_show_tabs(False)
self._notebook.props.tab_vborder = style.TOOLBOX_TAB_VBORDER self._notebook.props.tab_vborder = style.TOOLBOX_TAB_VBORDER
self._notebook.props.tab_hborder = style.TOOLBOX_TAB_HBORDER self._notebook.props.tab_hborder = style.TOOLBOX_TAB_HBORDER
self.pack_start(self._notebook) self.pack_start(self._notebook, True, True, 0)
self._notebook.show() self._notebook.show()
self._separator = gtk.HSeparator() self._separator = Gtk.HSeparator()
self._separator.modify_bg(gtk.STATE_NORMAL, self._separator.modify_bg(Gtk.StateType.NORMAL,
style.COLOR_PANEL_GREY.get_gdk_color()) style.COLOR_PANEL_GREY.get_gdk_color())
self._separator.set_size_request(1, style.TOOLBOX_SEPARATOR_HEIGHT) self._separator.set_size_request(1, style.TOOLBOX_SEPARATOR_HEIGHT)
self.pack_start(self._separator, False) self.pack_start(self._separator, False)
@ -58,14 +58,14 @@ class Toolbox(gtk.VBox):
self.emit('current-toolbar-changed', notebook.props.page) self.emit('current-toolbar-changed', notebook.props.page)
def add_toolbar(self, name, toolbar): def add_toolbar(self, name, toolbar):
label = gtk.Label(name) label = Gtk.Label(label=name)
width, height_ = label.size_request() width, height_ = label.size_request()
label.set_size_request(max(width, style.TOOLBOX_TAB_LABEL_WIDTH), -1) label.set_size_request(max(width, style.TOOLBOX_TAB_LABEL_WIDTH), -1)
label.set_alignment(0.0, 0.5) label.set_alignment(0.0, 0.5)
event_box = gtk.EventBox() event_box = Gtk.EventBox()
alignment = gtk.Alignment(0.0, 0.0, 1.0, 1.0) alignment = Gtk.Alignment.new(0.0, 0.0, 1.0, 1.0)
alignment.set_padding(0, 0, style.TOOLBOX_HORIZONTAL_PADDING, alignment.set_padding(0, 0, style.TOOLBOX_HORIZONTAL_PADDING,
style.TOOLBOX_HORIZONTAL_PADDING) style.TOOLBOX_HORIZONTAL_PADDING)

View File

@ -22,8 +22,8 @@ STABLE.
import logging import logging
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
from sugar3.graphics.palette import Palette, ToolInvoker from sugar3.graphics.palette import Palette, ToolInvoker
@ -31,21 +31,21 @@ from sugar3.graphics.palette import Palette, ToolInvoker
def _add_accelerator(tool_button): def _add_accelerator(tool_button):
if not tool_button.props.accelerator or not tool_button.get_toplevel() or \ if not tool_button.props.accelerator or not tool_button.get_toplevel() or \
not tool_button.child: not tool_button.get_child():
return return
# TODO: should we remove the accelerator from the prev top level? # TODO: should we remove the accelerator from the prev top level?
accel_group = tool_button.get_toplevel().get_data('sugar-accel-group') accel_group = tool_button.get_toplevel().get_data('sugar-accel-group')
if not accel_group: if not accel_group:
logging.warning('No gtk.AccelGroup in the top level window.') logging.warning('No Gtk.AccelGroup in the top level window.')
return return
keyval, mask = gtk.accelerator_parse(tool_button.props.accelerator) keyval, mask = Gtk.accelerator_parse(tool_button.props.accelerator)
# the accelerator needs to be set at the child, so the gtk.AccelLabel # the accelerator needs to be set at the child, so the Gtk.AccelLabel
# in the palette can pick it up. # in the palette can pick it up.
tool_button.child.add_accelerator('clicked', accel_group, keyval, mask, tool_button.get_child().add_accelerator('clicked', accel_group, keyval, mask,
gtk.ACCEL_LOCKED | gtk.ACCEL_VISIBLE) Gtk.AccelFlags.LOCKED | Gtk.AccelFlags.VISIBLE)
def _hierarchy_changed_cb(tool_button, previous_toplevel): def _hierarchy_changed_cb(tool_button, previous_toplevel):
@ -57,7 +57,7 @@ def setup_accelerator(tool_button):
tool_button.connect('hierarchy-changed', _hierarchy_changed_cb) tool_button.connect('hierarchy-changed', _hierarchy_changed_cb)
class ToolButton(gtk.ToolButton): class ToolButton(Gtk.ToolButton):
__gtype_name__ = 'SugarToolButton' __gtype_name__ = 'SugarToolButton'
@ -66,7 +66,7 @@ class ToolButton(gtk.ToolButton):
self._tooltip = None self._tooltip = None
self._palette_invoker = ToolInvoker() self._palette_invoker = ToolInvoker()
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
self._palette_invoker.attach_tool(self) self._palette_invoker.attach_tool(self)
@ -97,12 +97,12 @@ class ToolButton(gtk.ToolButton):
self._tooltip = tooltip self._tooltip = tooltip
# Set label, shows up when toolbar overflows # Set label, shows up when toolbar overflows
gtk.ToolButton.set_label(self, tooltip) Gtk.ToolButton.set_label(self, tooltip)
def get_tooltip(self): def get_tooltip(self):
return self._tooltip return self._tooltip
tooltip = gobject.property(type=str, setter=set_tooltip, tooltip = GObject.property(type=str, setter=set_tooltip,
getter=get_tooltip) getter=get_tooltip)
def set_accelerator(self, accelerator): def set_accelerator(self, accelerator):
@ -112,7 +112,7 @@ class ToolButton(gtk.ToolButton):
def get_accelerator(self): def get_accelerator(self):
return self._accelerator return self._accelerator
accelerator = gobject.property(type=str, setter=set_accelerator, accelerator = GObject.property(type=str, setter=set_accelerator,
getter=get_accelerator) getter=get_accelerator)
def set_icon(self, icon_name): def set_icon(self, icon_name):
@ -129,7 +129,7 @@ class ToolButton(gtk.ToolButton):
def set_palette(self, palette): def set_palette(self, palette):
self._palette_invoker.palette = palette self._palette_invoker.palette = palette
palette = gobject.property( palette = GObject.property(
type=object, setter=set_palette, getter=get_palette) type=object, setter=set_palette, getter=get_palette)
def get_palette_invoker(self): def get_palette_invoker(self):
@ -139,7 +139,7 @@ class ToolButton(gtk.ToolButton):
self._palette_invoker.detach() self._palette_invoker.detach()
self._palette_invoker = palette_invoker self._palette_invoker = palette_invoker
palette_invoker = gobject.property( palette_invoker = GObject.property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker) type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def do_expose_event(self, event): def do_expose_event(self, event):
@ -148,14 +148,14 @@ class ToolButton(gtk.ToolButton):
if self.palette and self.palette.is_up(): if self.palette and self.palette.is_up():
invoker = self.palette.props.invoker invoker = self.palette.props.invoker
invoker.draw_rectangle(event, self.palette) invoker.draw_rectangle(event, self.palette)
elif child.state == gtk.STATE_PRELIGHT: elif child.state == Gtk.StateType.PRELIGHT:
child.style.paint_box(event.window, gtk.STATE_PRELIGHT, child.style.paint_box(event.window, Gtk.StateType.PRELIGHT,
gtk.SHADOW_NONE, event.area, Gtk.ShadowType.NONE, event.area,
child, 'toolbutton-prelight', child, 'toolbutton-prelight',
allocation.x, allocation.y, allocation.x, allocation.y,
allocation.width, allocation.height) allocation.width, allocation.height)
gtk.ToolButton.do_expose_event(self, event) Gtk.ToolButton.do_expose_event(self, event)
def do_clicked(self): def do_clicked(self):
if self.palette: if self.palette:

View File

@ -19,30 +19,30 @@
STABLE. STABLE.
""" """
import gtk from gi.repository import Gtk
import gobject from gi.repository import GObject
from sugar3.graphics.combobox import ComboBox from sugar3.graphics.combobox import ComboBox
from sugar3.graphics import style from sugar3.graphics import style
class ToolComboBox(gtk.ToolItem): class ToolComboBox(Gtk.ToolItem):
__gproperties__ = { __gproperties__ = {
'label-text': (str, None, None, None, gobject.PARAM_WRITABLE), 'label-text': (str, None, None, None, GObject.PARAM_WRITABLE),
} }
def __init__(self, combo=None, **kwargs): def __init__(self, combo=None, **kwargs):
self.label = None self.label = None
self._label_text = '' self._label_text = ''
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
self.set_border_width(style.DEFAULT_PADDING) self.set_border_width(style.DEFAULT_PADDING)
hbox = gtk.HBox(False, style.DEFAULT_SPACING) hbox = Gtk.HBox(False, style.DEFAULT_SPACING)
self.label = gtk.Label(self._label_text) self.label = Gtk.Label(label=self._label_text)
hbox.pack_start(self.label, False, False, 0) hbox.pack_start(self.label, False, False, 0)
self.label.show() self.label.show()
@ -51,7 +51,7 @@ class ToolComboBox(gtk.ToolItem):
else: else:
self.combo = ComboBox() self.combo = ComboBox()
hbox.pack_start(self.combo) hbox.pack_start(self.combo, True, True, 0)
self.combo.show() self.combo.show()
self.add(hbox) self.add(hbox)

View File

@ -19,8 +19,8 @@
STABLE. STABLE.
""" """
import gobject from gi.repository import GObject
import gtk from gi.repository import Gtk
from sugar3.graphics import style from sugar3.graphics import style
from sugar3.graphics.palette import ToolInvoker from sugar3.graphics.palette import ToolInvoker
@ -32,12 +32,12 @@ _PREVIOUS_PAGE = 0
_NEXT_PAGE = 1 _NEXT_PAGE = 1
class _TrayViewport(gtk.Viewport): class _TrayViewport(Gtk.Viewport):
__gproperties__ = { __gproperties__ = {
'scrollable': (bool, None, None, False, gobject.PARAM_READABLE), 'scrollable': (bool, None, None, False, GObject.PARAM_READABLE),
'can-scroll-prev': (bool, None, None, False, gobject.PARAM_READABLE), 'can-scroll-prev': (bool, None, None, False, GObject.PARAM_READABLE),
'can-scroll-next': (bool, None, None, False, gobject.PARAM_READABLE), 'can-scroll-next': (bool, None, None, False, GObject.PARAM_READABLE),
} }
def __init__(self, orientation): def __init__(self, orientation):
@ -46,11 +46,11 @@ class _TrayViewport(gtk.Viewport):
self._can_scroll_next = False self._can_scroll_next = False
self._can_scroll_prev = False self._can_scroll_prev = False
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self.set_shadow_type(gtk.SHADOW_NONE) self.set_shadow_type(Gtk.ShadowType.NONE)
self.traybar = gtk.Toolbar() self.traybar = Gtk.Toolbar()
self.traybar.set_orientation(orientation) self.traybar.set_orientation(orientation)
self.traybar.set_show_arrow(False) self.traybar.set_show_arrow(False)
self.add(self.traybar) self.add(self.traybar)
@ -58,7 +58,7 @@ class _TrayViewport(gtk.Viewport):
self.connect('size_allocate', self._size_allocate_cb) self.connect('size_allocate', self._size_allocate_cb)
if self.orientation == gtk.ORIENTATION_HORIZONTAL: if self.orientation == Gtk.Orientation.HORIZONTAL:
adj = self.get_hadjustment() adj = self.get_hadjustment()
else: else:
adj = self.get_vadjustment() adj = self.get_vadjustment()
@ -76,7 +76,7 @@ class _TrayViewport(gtk.Viewport):
assert item in self.traybar.get_children() assert item in self.traybar.get_children()
# Get the allocation, and make sure that it is visible # Get the allocation, and make sure that it is visible
if self.orientation == gtk.ORIENTATION_HORIZONTAL: if self.orientation == Gtk.Orientation.HORIZONTAL:
adj = self.get_hadjustment() adj = self.get_hadjustment()
start = item.allocation.x start = item.allocation.x
stop = item.allocation.x + item.allocation.width stop = item.allocation.x + item.allocation.width
@ -92,7 +92,7 @@ class _TrayViewport(gtk.Viewport):
def _scroll_next(self): def _scroll_next(self):
allocation = self.get_allocation() allocation = self.get_allocation()
if self.orientation == gtk.ORIENTATION_HORIZONTAL: if self.orientation == Gtk.Orientation.HORIZONTAL:
adj = self.get_hadjustment() adj = self.get_hadjustment()
new_value = adj.value + allocation.width new_value = adj.value + allocation.width
adj.value = min(new_value, adj.upper - allocation.width) adj.value = min(new_value, adj.upper - allocation.width)
@ -103,7 +103,7 @@ class _TrayViewport(gtk.Viewport):
def _scroll_previous(self): def _scroll_previous(self):
allocation = self.get_allocation() allocation = self.get_allocation()
if self.orientation == gtk.ORIENTATION_HORIZONTAL: if self.orientation == Gtk.Orientation.HORIZONTAL:
adj = self.get_hadjustment() adj = self.get_hadjustment()
new_value = adj.value - allocation.width new_value = adj.value - allocation.width
adj.value = max(adj.lower, new_value) adj.value = max(adj.lower, new_value)
@ -114,7 +114,7 @@ class _TrayViewport(gtk.Viewport):
def do_size_request(self, requisition): def do_size_request(self, requisition):
child_requisition = self.get_child().size_request() child_requisition = self.get_child().size_request()
if self.orientation == gtk.ORIENTATION_HORIZONTAL: if self.orientation == Gtk.Orientation.HORIZONTAL:
requisition[0] = 0 requisition[0] = 0
requisition[1] = child_requisition[1] requisition[1] = child_requisition[1]
else: else:
@ -131,7 +131,7 @@ class _TrayViewport(gtk.Viewport):
def _size_allocate_cb(self, viewport, allocation): def _size_allocate_cb(self, viewport, allocation):
bar_requisition = self.traybar.get_child_requisition() bar_requisition = self.traybar.get_child_requisition()
if self.orientation == gtk.ORIENTATION_HORIZONTAL: if self.orientation == Gtk.Orientation.HORIZONTAL:
scrollable = bar_requisition[0] > allocation.width scrollable = bar_requisition[0] > allocation.width
else: else:
scrollable = bar_requisition[1] > allocation.height scrollable = bar_requisition[1] > allocation.height
@ -171,10 +171,10 @@ class _TrayScrollButton(ToolButton):
self.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE) self.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE)
self.icon = Icon(icon_name=icon_name, self.icon = Icon(icon_name=icon_name,
icon_size=gtk.ICON_SIZE_SMALL_TOOLBAR) icon_size=Gtk.IconSize.SMALL_TOOLBAR)
# The alignment is a hack to work around gtk.ToolButton code # The alignment is a hack to work around Gtk.ToolButton code
# that sets the icon_size when the icon_widget is a gtk.Image # that sets the icon_size when the icon_widget is a Gtk.Image
alignment = gtk.Alignment(0.5, 0.5) alignment = Gtk.Alignment.new(0.5, 0.5)
alignment.add(self.icon) alignment.add(self.icon)
self.set_icon_widget(alignment) self.set_icon_widget(alignment)
alignment.show_all() alignment.show_all()
@ -216,27 +216,27 @@ ALIGN_TO_START = 0
ALIGN_TO_END = 1 ALIGN_TO_END = 1
class HTray(gtk.HBox): class HTray(Gtk.HBox):
__gtype_name__ = 'SugarHTray' __gtype_name__ = 'SugarHTray'
__gproperties__ = { __gproperties__ = {
'align': (int, None, None, 0, 1, ALIGN_TO_START, 'align': (int, None, None, 0, 1, ALIGN_TO_START,
gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT_ONLY), GObject.PARAM_READWRITE | GObject.PARAM_CONSTRUCT_ONLY),
'drag-active': (bool, None, None, False, gobject.PARAM_READWRITE), 'drag-active': (bool, None, None, False, GObject.PARAM_READWRITE),
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._drag_active = False self._drag_active = False
self.align = ALIGN_TO_START self.align = ALIGN_TO_START
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
scroll_left = _TrayScrollButton('go-left', _PREVIOUS_PAGE) scroll_left = _TrayScrollButton('go-left', _PREVIOUS_PAGE)
self.pack_start(scroll_left, False, False, 0) self.pack_start(scroll_left, False, False, 0)
self._viewport = _TrayViewport(gtk.ORIENTATION_HORIZONTAL) self._viewport = _TrayViewport(Gtk.Orientation.HORIZONTAL)
self.pack_start(self._viewport) self.pack_start(self._viewport, True, True, 0)
self._viewport.show() self._viewport.show()
scroll_right = _TrayScrollButton('go-right', _NEXT_PAGE) scroll_right = _TrayScrollButton('go-right', _NEXT_PAGE)
@ -246,7 +246,7 @@ class HTray(gtk.HBox):
scroll_right.viewport = self._viewport scroll_right.viewport = self._viewport
if self.align == ALIGN_TO_END: if self.align == ALIGN_TO_END:
spacer = gtk.SeparatorToolItem() spacer = Gtk.SeparatorToolItem()
spacer.set_size_request(0, 0) spacer.set_size_request(0, 0)
spacer.props.draw = False spacer.props.draw = False
spacer.set_expand(True) spacer.set_expand(True)
@ -273,10 +273,10 @@ class HTray(gtk.HBox):
if self._drag_active != active: if self._drag_active != active:
self._drag_active = active self._drag_active = active
if self._drag_active: if self._drag_active:
self._viewport.traybar.modify_bg(gtk.STATE_NORMAL, self._viewport.traybar.modify_bg(Gtk.StateType.NORMAL,
style.COLOR_BLACK.get_gdk_color()) style.COLOR_BLACK.get_gdk_color())
else: else:
self._viewport.traybar.modify_bg(gtk.STATE_NORMAL, None) self._viewport.traybar.modify_bg(Gtk.StateType.NORMAL, None)
def get_children(self): def get_children(self):
children = self._viewport.traybar.get_children()[:] children = self._viewport.traybar.get_children()[:]
@ -302,27 +302,27 @@ class HTray(gtk.HBox):
self._viewport.scroll_to_item(item) self._viewport.scroll_to_item(item)
class VTray(gtk.VBox): class VTray(Gtk.VBox):
__gtype_name__ = 'SugarVTray' __gtype_name__ = 'SugarVTray'
__gproperties__ = { __gproperties__ = {
'align': (int, None, None, 0, 1, ALIGN_TO_START, 'align': (int, None, None, 0, 1, ALIGN_TO_START,
gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT_ONLY), GObject.PARAM_READWRITE | GObject.PARAM_CONSTRUCT_ONLY),
'drag-active': (bool, None, None, False, gobject.PARAM_READWRITE), 'drag-active': (bool, None, None, False, GObject.PARAM_READWRITE),
} }
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._drag_active = False self._drag_active = False
self.align = ALIGN_TO_START self.align = ALIGN_TO_START
gobject.GObject.__init__(self, **kwargs) GObject.GObject.__init__(self, **kwargs)
scroll_up = _TrayScrollButton('go-up', _PREVIOUS_PAGE) scroll_up = _TrayScrollButton('go-up', _PREVIOUS_PAGE)
self.pack_start(scroll_up, False, False, 0) self.pack_start(scroll_up, False, False, 0)
self._viewport = _TrayViewport(gtk.ORIENTATION_VERTICAL) self._viewport = _TrayViewport(Gtk.Orientation.VERTICAL)
self.pack_start(self._viewport) self.pack_start(self._viewport, True, True, 0)
self._viewport.show() self._viewport.show()
scroll_down = _TrayScrollButton('go-down', _NEXT_PAGE) scroll_down = _TrayScrollButton('go-down', _NEXT_PAGE)
@ -332,7 +332,7 @@ class VTray(gtk.VBox):
scroll_down.viewport = self._viewport scroll_down.viewport = self._viewport
if self.align == ALIGN_TO_END: if self.align == ALIGN_TO_END:
spacer = gtk.SeparatorToolItem() spacer = Gtk.SeparatorToolItem()
spacer.set_size_request(0, 0) spacer.set_size_request(0, 0)
spacer.props.draw = False spacer.props.draw = False
spacer.set_expand(True) spacer.set_expand(True)
@ -359,10 +359,10 @@ class VTray(gtk.VBox):
if self._drag_active != active: if self._drag_active != active:
self._drag_active = active self._drag_active = active
if self._drag_active: if self._drag_active:
self._viewport.traybar.modify_bg(gtk.STATE_NORMAL, self._viewport.traybar.modify_bg(Gtk.StateType.NORMAL,
style.COLOR_BLACK.get_gdk_color()) style.COLOR_BLACK.get_gdk_color())
else: else:
self._viewport.traybar.modify_bg(gtk.STATE_NORMAL, None) self._viewport.traybar.modify_bg(Gtk.StateType.NORMAL, None)
def get_children(self): def get_children(self):
children = self._viewport.traybar.get_children()[:] children = self._viewport.traybar.get_children()[:]
@ -394,17 +394,17 @@ class TrayButton(ToolButton):
ToolButton.__init__(self, **kwargs) ToolButton.__init__(self, **kwargs)
class _IconWidget(gtk.EventBox): class _IconWidget(Gtk.EventBox):
__gtype_name__ = 'SugarTrayIconWidget' __gtype_name__ = 'SugarTrayIconWidget'
def __init__(self, icon_name=None, xo_color=None): def __init__(self, icon_name=None, xo_color=None):
gtk.EventBox.__init__(self) GObject.GObject.__init__(self)
self.set_app_paintable(True) self.set_app_paintable(True)
self._icon = Icon(icon_name=icon_name, xo_color=xo_color, self._icon = Icon(icon_name=icon_name, xo_color=xo_color,
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) icon_size=Gtk.IconSize.LARGE_TOOLBAR)
self.add(self._icon) self.add(self._icon)
self._icon.show() self._icon.show()
@ -414,18 +414,18 @@ class _IconWidget(gtk.EventBox):
invoker = palette.props.invoker invoker = palette.props.invoker
invoker.draw_rectangle(event, palette) invoker.draw_rectangle(event, palette)
gtk.EventBox.do_expose_event(self, event) Gtk.EventBox.do_expose_event(self, event)
def get_icon(self): def get_icon(self):
return self._icon return self._icon
class TrayIcon(gtk.ToolItem): class TrayIcon(Gtk.ToolItem):
__gtype_name__ = 'SugarTrayIcon' __gtype_name__ = 'SugarTrayIcon'
def __init__(self, icon_name=None, xo_color=None): def __init__(self, icon_name=None, xo_color=None):
gtk.ToolItem.__init__(self) Gtk.ToolItem.__init__(self)
self._icon_widget = _IconWidget(icon_name, xo_color) self._icon_widget = _IconWidget(icon_name, xo_color)
self.add(self._icon_widget) self.add(self._icon_widget)
@ -450,7 +450,7 @@ class TrayIcon(gtk.ToolItem):
def set_palette(self, palette): def set_palette(self, palette):
self._palette_invoker.palette = palette self._palette_invoker.palette = palette
palette = gobject.property( palette = GObject.property(
type=object, setter=set_palette, getter=get_palette) type=object, setter=set_palette, getter=get_palette)
def get_palette_invoker(self): def get_palette_invoker(self):
@ -460,7 +460,7 @@ class TrayIcon(gtk.ToolItem):
self._palette_invoker.detach() self._palette_invoker.detach()
self._palette_invoker = palette_invoker self._palette_invoker = palette_invoker
palette_invoker = gobject.property( palette_invoker = GObject.property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker) type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def get_icon(self): def get_icon(self):

View File

@ -20,9 +20,9 @@
STABLE. STABLE.
""" """
import gobject from gi.repository import GObject
from gtk import gdk from gi.repository import Gdk
import gtk from gi.repository import Gtk
import warnings import warnings
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
@ -32,21 +32,21 @@ from sugar3.graphics import palettegroup
_UNFULLSCREEN_BUTTON_VISIBILITY_TIMEOUT = 2 _UNFULLSCREEN_BUTTON_VISIBILITY_TIMEOUT = 2
class UnfullscreenButton(gtk.Window): class UnfullscreenButton(Gtk.Window):
def __init__(self): def __init__(self):
gtk.Window.__init__(self) GObject.GObject.__init__(self)
self.set_decorated(False) self.set_decorated(False)
self.set_resizable(False) self.set_resizable(False)
self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
self.set_border_width(0) self.set_border_width(0)
self.props.accept_focus = False self.props.accept_focus = False
#Setup estimate of width, height #Setup estimate of width, height
w, h = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR) w, h = Gtk.icon_size_lookup(Gtk.IconSize.LARGE_TOOLBAR)
self._width = w self._width = w
self._height = h self._height = h
@ -55,11 +55,11 @@ class UnfullscreenButton(gtk.Window):
screen = self.get_screen() screen = self.get_screen()
screen.connect('size-changed', self._screen_size_changed_cb) screen.connect('size-changed', self._screen_size_changed_cb)
self._button = gtk.Button() self._button = Gtk.Button()
self._button.set_relief(gtk.RELIEF_NONE) self._button.set_relief(Gtk.ReliefStyle.NONE)
self._icon = Icon(icon_name='view-return', self._icon = Icon(icon_name='view-return',
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) icon_size=Gtk.IconSize.LARGE_TOOLBAR)
self._icon.show() self._icon.show()
self._button.add(self._icon) self._button.add(self._icon)
@ -70,7 +70,7 @@ class UnfullscreenButton(gtk.Window):
self._button.connect('button-press-event', cb) self._button.connect('button-press-event', cb)
def _reposition(self): def _reposition(self):
x = gtk.gdk.screen_width() - self._width x = Gdk.Screen.width() - self._width
self.move(x, 0) self.move(x, 0)
def _size_request_cb(self, widget, req): def _size_request_cb(self, widget, req):
@ -82,12 +82,12 @@ class UnfullscreenButton(gtk.Window):
self._reposition() self._reposition()
class Window(gtk.Window): class Window(Gtk.Window):
def __init__(self, **args): def __init__(self, **args):
self._enable_fullscreen_mode = True self._enable_fullscreen_mode = True
gtk.Window.__init__(self, **args) GObject.GObject.__init__(self, **args)
self.set_decorated(False) self.set_decorated(False)
self.maximize() self.maximize()
@ -99,13 +99,13 @@ class Window(gtk.Window):
self._canvas = None self._canvas = None
self.tray = None self.tray = None
self.__vbox = gtk.VBox() self.__vbox = Gtk.VBox()
self.__hbox = gtk.HBox() self.__hbox = Gtk.HBox()
self.__vbox.pack_start(self.__hbox) self.__vbox.pack_start(self.__hbox, True, True, 0)
self.__hbox.show() self.__hbox.show()
self.add_events(gtk.gdk.POINTER_MOTION_HINT_MASK self.add_events(Gdk.EventMask.POINTER_MOTION_HINT_MASK
| gtk.gdk.POINTER_MOTION_MASK) | Gdk.EventMask.POINTER_MOTION_MASK)
self.connect('motion-notify-event', self.__motion_notify_cb) self.connect('motion-notify-event', self.__motion_notify_cb)
self.add(self.__vbox) self.add(self.__vbox)
@ -128,9 +128,9 @@ class Window(gtk.Window):
if self.window is None: if self.window is None:
self.show() self.show()
return return
timestamp = gtk.get_current_event_time() timestamp = Gtk.get_current_event_time()
if not timestamp: if not timestamp:
timestamp = gtk.gdk.x11_get_server_time(self.window) timestamp = GdkX11.get_server_time(self.window)
self.window.focus(timestamp) self.window.focus(timestamp)
def fullscreen(self): def fullscreen(self):
@ -146,11 +146,11 @@ class Window(gtk.Window):
self._unfullscreen_button.show() self._unfullscreen_button.show()
if self._unfullscreen_button_timeout_id is not None: if self._unfullscreen_button_timeout_id is not None:
gobject.source_remove(self._unfullscreen_button_timeout_id) GObject.source_remove(self._unfullscreen_button_timeout_id)
self._unfullscreen_button_timeout_id = None self._unfullscreen_button_timeout_id = None
self._unfullscreen_button_timeout_id = \ self._unfullscreen_button_timeout_id = \
gobject.timeout_add_seconds( \ GObject.timeout_add_seconds( \
_UNFULLSCREEN_BUTTON_VISIBILITY_TIMEOUT, \ _UNFULLSCREEN_BUTTON_VISIBILITY_TIMEOUT, \
self.__unfullscreen_button_timeout_cb) self.__unfullscreen_button_timeout_cb)
@ -166,7 +166,7 @@ class Window(gtk.Window):
self._unfullscreen_button.hide() self._unfullscreen_button.hide()
if self._unfullscreen_button_timeout_id: if self._unfullscreen_button_timeout_id:
gobject.source_remove(self._unfullscreen_button_timeout_id) GObject.source_remove(self._unfullscreen_button_timeout_id)
self._unfullscreen_button_timeout_id = None self._unfullscreen_button_timeout_id = None
def set_canvas(self, canvas): def set_canvas(self, canvas):
@ -174,7 +174,7 @@ class Window(gtk.Window):
self.__hbox.remove(self._canvas) self.__hbox.remove(self._canvas)
if canvas: if canvas:
self.__hbox.pack_start(canvas) self.__hbox.pack_start(canvas, True, True, 0)
self._canvas = canvas self._canvas = canvas
self.__vbox.set_focus_child(self._canvas) self.__vbox.set_focus_child(self._canvas)
@ -204,11 +204,11 @@ class Window(gtk.Window):
box = self.tray.get_parent() box = self.tray.get_parent()
box.remove(self.tray) box.remove(self.tray)
if position == gtk.POS_LEFT: if position == Gtk.PositionType.LEFT:
self.__hbox.pack_start(tray, False) self.__hbox.pack_start(tray, False)
elif position == gtk.POS_RIGHT: elif position == Gtk.PositionType.RIGHT:
self.__hbox.pack_end(tray, False) self.__hbox.pack_end(tray, False)
elif position == gtk.POS_BOTTOM: elif position == Gtk.PositionType.BOTTOM:
self.__vbox.pack_end(tray, False) self.__vbox.pack_end(tray, False)
self.tray = tray self.tray = tray
@ -236,13 +236,13 @@ class Window(gtk.Window):
self.__vbox.reorder_child(self._alert[0], 0) self.__vbox.reorder_child(self._alert[0], 0)
def __window_realize_cb(self, window): def __window_realize_cb(self, window):
group = gtk.Window() group = Gtk.Window()
group.realize() group.realize()
window.window.set_group(group.window) window.window.set_group(group.window)
def __key_press_cb(self, widget, event): def __key_press_cb(self, widget, event):
key = gtk.gdk.keyval_name(event.keyval) key = Gdk.keyval_name(event.keyval)
if event.state & gtk.gdk.MOD1_MASK: if event.get_state() & Gdk.ModifierType.MOD1_MASK:
if self.tray is not None and key == 'space': if self.tray is not None and key == 'space':
self.tray.props.visible = not self.tray.props.visible self.tray.props.visible = not self.tray.props.visible
return True return True
@ -262,11 +262,11 @@ class Window(gtk.Window):
else: else:
# Reset the timer # Reset the timer
if self._unfullscreen_button_timeout_id is not None: if self._unfullscreen_button_timeout_id is not None:
gobject.source_remove(self._unfullscreen_button_timeout_id) GObject.source_remove(self._unfullscreen_button_timeout_id)
self._unfullscreen_button_timeout_id = None self._unfullscreen_button_timeout_id = None
self._unfullscreen_button_timeout_id = \ self._unfullscreen_button_timeout_id = \
gobject.timeout_add_seconds( \ GObject.timeout_add_seconds( \
_UNFULLSCREEN_BUTTON_VISIBILITY_TIMEOUT, \ _UNFULLSCREEN_BUTTON_VISIBILITY_TIMEOUT, \
self.__unfullscreen_button_timeout_cb) self.__unfullscreen_button_timeout_cb)
return False return False
@ -282,7 +282,7 @@ class Window(gtk.Window):
def get_enable_fullscreen_mode(self): def get_enable_fullscreen_mode(self):
return self._enable_fullscreen_mode return self._enable_fullscreen_mode
enable_fullscreen_mode = gobject.property(type=object, enable_fullscreen_mode = GObject.property(type=object,
setter=set_enable_fullscreen_mode, getter=get_enable_fullscreen_mode) setter=set_enable_fullscreen_mode, getter=get_enable_fullscreen_mode)
# DEPRECATED # DEPRECATED

View File

@ -22,7 +22,7 @@ STABLE.
import random import random
import logging import logging
import gconf from gi.repository import GConf
colors = [ colors = [
['#B20008', '#FF2B34'], \ ['#B20008', '#FF2B34'], \
@ -237,7 +237,7 @@ class XoColor:
elif not is_valid(color_string): elif not is_valid(color_string):
logging.debug('Color string is not valid: %s, ' logging.debug('Color string is not valid: %s, '
'fallback to default', color_string) 'fallback to default', color_string)
client = gconf.client_get_default() client = GConf.Client.get_default()
color_string = client.get_string('/desktop/sugar/user/color') color_string = client.get_string('/desktop/sugar/user/color')
randomize = False randomize = False
else: else:

View File

@ -25,7 +25,7 @@ import urllib
import fcntl import fcntl
import tempfile import tempfile
import gobject from gi.repository import GObject
import SimpleHTTPServer import SimpleHTTPServer
import SocketServer import SocketServer
@ -60,12 +60,12 @@ class GlibTCPServer(SocketServer.TCPServer):
self.socket.setblocking(0) # Set nonblocking self.socket.setblocking(0) # Set nonblocking
# Watch the listener socket for data # Watch the listener socket for data
gobject.io_add_watch(self.socket, gobject.IO_IN, self._handle_accept) GObject.io_add_watch(self.socket, GObject.IO_IN, self._handle_accept)
def _handle_accept(self, source, condition): def _handle_accept(self, source, condition):
"""Process incoming data on the server's socket by doing an accept() """Process incoming data on the server's socket by doing an accept()
via handle_request().""" via handle_request()."""
if not (condition & gobject.IO_IN): if not (condition & GObject.IO_IN):
return True return True
self.handle_request() self.handle_request()
return True return True
@ -103,17 +103,17 @@ class ChunkedGlibHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
"""Serve a GET request.""" """Serve a GET request."""
self._file = self.send_head() self._file = self.send_head()
if self._file: if self._file:
self._srcid = gobject.io_add_watch(self.wfile, gobject.IO_OUT | self._srcid = GObject.io_add_watch(self.wfile, GObject.IO_OUT |
gobject.IO_ERR, GObject.IO_ERR,
self._send_next_chunk) self._send_next_chunk)
else: else:
self._cleanup() self._cleanup()
def _send_next_chunk(self, source, condition): def _send_next_chunk(self, source, condition):
if condition & gobject.IO_ERR: if condition & GObject.IO_ERR:
self._cleanup() self._cleanup()
return False return False
if not (condition & gobject.IO_OUT): if not (condition & GObject.IO_OUT):
self._cleanup() self._cleanup()
return False return False
data = self._file.read(self.CHUNK_SIZE) data = self._file.read(self.CHUNK_SIZE)
@ -128,7 +128,7 @@ class ChunkedGlibHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self._file.close() self._file.close()
self._file = None self._file = None
if self._srcid > 0: if self._srcid > 0:
gobject.source_remove(self._srcid) GObject.source_remove(self._srcid)
self._srcid = 0 self._srcid = 0
if not self.wfile.closed: if not self.wfile.closed:
self.wfile.flush() self.wfile.flush()
@ -183,16 +183,16 @@ class ChunkedGlibHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
return f return f
class GlibURLDownloader(gobject.GObject): class GlibURLDownloader(GObject.GObject):
"""Grabs a URL in chunks, returning to the mainloop after each chunk""" """Grabs a URL in chunks, returning to the mainloop after each chunk"""
__gsignals__ = { __gsignals__ = {
'finished': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'finished': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT])),
'error': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'error': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT])),
'progress': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'progress': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT])),
} }
CHUNK_SIZE = 4096 CHUNK_SIZE = 4096
@ -208,7 +208,7 @@ class GlibURLDownloader(gobject.GObject):
self._suggested_fname = None self._suggested_fname = None
self._info = None self._info = None
self._written = 0 self._written = 0
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
def start(self, destfile=None, destfd=None): def start(self, destfile=None, destfd=None):
self._info = urllib.urlopen(self._url) self._info = urllib.urlopen(self._url)
@ -238,8 +238,8 @@ class GlibURLDownloader(gobject.GObject):
dir=self._destdir) dir=self._destdir)
fcntl.fcntl(self._info.fp.fileno(), fcntl.F_SETFD, os.O_NDELAY) fcntl.fcntl(self._info.fp.fileno(), fcntl.F_SETFD, os.O_NDELAY)
self._srcid = gobject.io_add_watch(self._info.fp.fileno(), self._srcid = GObject.io_add_watch(self._info.fp.fileno(),
gobject.IO_IN | gobject.IO_ERR, GObject.IO_IN | GObject.IO_ERR,
self._read_next_chunk) self._read_next_chunk)
def cancel(self): def cancel(self):
@ -264,11 +264,11 @@ class GlibURLDownloader(gobject.GObject):
return fname return fname
def _read_next_chunk(self, source, condition): def _read_next_chunk(self, source, condition):
if condition & gobject.IO_ERR: if condition & GObject.IO_ERR:
self.cleanup(remove=True) self.cleanup(remove=True)
self.emit('error', 'Error downloading file.') self.emit('error', 'Error downloading file.')
return False return False
elif not (condition & gobject.IO_IN): elif not (condition & GObject.IO_IN):
# shouldn't get here, but... # shouldn't get here, but...
return True return True
@ -298,7 +298,7 @@ class GlibURLDownloader(gobject.GObject):
def cleanup(self, remove=False): def cleanup(self, remove=False):
if self._srcid > 0: if self._srcid > 0:
gobject.source_remove(self._srcid) GObject.source_remove(self._srcid)
self._srcid = 0 self._srcid = 0
del self._info del self._info
self._info = None self._info = None

View File

@ -26,7 +26,7 @@ from functools import partial
import dbus import dbus
from dbus import PROPERTIES_IFACE from dbus import PROPERTIES_IFACE
import gobject from gi.repository import GObject
from telepathy.client import Channel from telepathy.client import Channel
from telepathy.interfaces import CHANNEL, \ from telepathy.interfaces import CHANNEL, \
CHANNEL_INTERFACE_GROUP, \ CHANNEL_INTERFACE_GROUP, \
@ -47,7 +47,7 @@ CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
_logger = logging.getLogger('sugar3.presence.activity') _logger = logging.getLogger('sugar3.presence.activity')
class Activity(gobject.GObject): class Activity(GObject.GObject):
"""UI interface for an Activity in the presence service """UI interface for an Activity in the presence service
Activities in the presence service represent your and other user's Activities in the presence service represent your and other user's
@ -61,24 +61,24 @@ class Activity(gobject.GObject):
joined joined
""" """
__gsignals__ = { __gsignals__ = {
'buddy-joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'buddy-joined': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT])),
'buddy-left': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'buddy-left': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT])),
'new-channel': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'new-channel': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT])),
'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'joined': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT])),
} }
__gproperties__ = { __gproperties__ = {
'id': (str, None, None, None, gobject.PARAM_READABLE), 'id': (str, None, None, None, GObject.PARAM_READABLE),
'name': (str, None, None, None, gobject.PARAM_READWRITE), 'name': (str, None, None, None, GObject.PARAM_READWRITE),
'tags': (str, None, None, None, gobject.PARAM_READWRITE), 'tags': (str, None, None, None, GObject.PARAM_READWRITE),
'color': (str, None, None, None, gobject.PARAM_READWRITE), 'color': (str, None, None, None, GObject.PARAM_READWRITE),
'type': (str, None, None, None, gobject.PARAM_READABLE), 'type': (str, None, None, None, GObject.PARAM_READABLE),
'private': (bool, None, None, True, gobject.PARAM_READWRITE), 'private': (bool, None, None, True, GObject.PARAM_READWRITE),
'joined': (bool, None, None, False, gobject.PARAM_READABLE), 'joined': (bool, None, None, False, GObject.PARAM_READABLE),
} }
def __init__(self, account_path, connection, room_handle=None, def __init__(self, account_path, connection, room_handle=None,
@ -89,7 +89,7 @@ class Activity(gobject.GObject):
if properties is None: if properties is None:
properties = {} properties = {}
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._account_path = account_path self._account_path = account_path
self.telepathy_conn = connection self.telepathy_conn = connection
@ -469,14 +469,14 @@ class Activity(gobject.GObject):
self.telepathy_text_chan.Close() self.telepathy_text_chan.Close()
class _BaseCommand(gobject.GObject): class _BaseCommand(GObject.GObject):
__gsignals__ = { __gsignals__ = {
'finished': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'finished': (GObject.SignalFlags.RUN_FIRST, None,
([object])), ([object])),
} }
def __init__(self): def __init__(self):
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self.text_channel = None self.text_channel = None
self.text_channel_group_flags = None self.text_channel_group_flags = None

View File

@ -23,9 +23,9 @@ STABLE.
import logging import logging
import gobject from gi.repository import GObject
import dbus import dbus
import gconf from gi.repository import GConf
from telepathy.interfaces import CONNECTION, \ from telepathy.interfaces import CONNECTION, \
CONNECTION_INTERFACE_ALIASING, \ CONNECTION_INTERFACE_ALIASING, \
CONNECTION_INTERFACE_CONTACTS CONNECTION_INTERFACE_CONTACTS
@ -39,7 +39,7 @@ CONN_INTERFACE_BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo'
_logger = logging.getLogger('sugar3.presence.buddy') _logger = logging.getLogger('sugar3.presence.buddy')
class BaseBuddy(gobject.GObject): class BaseBuddy(GObject.GObject):
"""UI interface for a Buddy in the presence service """UI interface for a Buddy in the presence service
Each buddy interface tracks a set of activities and properties Each buddy interface tracks a set of activities and properties
@ -57,16 +57,16 @@ class BaseBuddy(gobject.GObject):
__gtype_name__ = 'PresenceBaseBuddy' __gtype_name__ = 'PresenceBaseBuddy'
__gsignals__ = { __gsignals__ = {
'joined-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'joined-activity': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT])),
'left-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'left-activity': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT])),
'property-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'property-changed': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT])), ([GObject.TYPE_PYOBJECT])),
} }
def __init__(self): def __init__(self):
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._key = None self._key = None
self._nick = None self._nick = None
@ -82,7 +82,7 @@ class BaseBuddy(gobject.GObject):
def set_key(self, key): def set_key(self, key):
self._key = key self._key = key
key = gobject.property(type=str, getter=get_key, setter=set_key) key = GObject.property(type=str, getter=get_key, setter=set_key)
def get_nick(self): def get_nick(self):
return self._nick return self._nick
@ -90,7 +90,7 @@ class BaseBuddy(gobject.GObject):
def set_nick(self, nick): def set_nick(self, nick):
self._nick = nick self._nick = nick
nick = gobject.property(type=str, getter=get_nick, setter=set_nick) nick = GObject.property(type=str, getter=get_nick, setter=set_nick)
def get_color(self): def get_color(self):
return self._color return self._color
@ -98,7 +98,7 @@ class BaseBuddy(gobject.GObject):
def set_color(self, color): def set_color(self, color):
self._color = color self._color = color
color = gobject.property(type=str, getter=get_color, setter=set_color) color = GObject.property(type=str, getter=get_color, setter=set_color)
def get_current_activity(self): def get_current_activity(self):
if self._current_activity is None: if self._current_activity is None:
@ -108,7 +108,7 @@ class BaseBuddy(gobject.GObject):
return activity return activity
return None return None
current_activity = gobject.property(type=object, current_activity = GObject.property(type=object,
getter=get_current_activity) getter=get_current_activity)
def get_owner(self): def get_owner(self):
@ -117,7 +117,7 @@ class BaseBuddy(gobject.GObject):
def set_owner(self, owner): def set_owner(self, owner):
self._owner = owner self._owner = owner
owner = gobject.property(type=bool, getter=get_owner, setter=set_owner, owner = GObject.property(type=bool, getter=get_owner, setter=set_owner,
default=False) default=False)
def get_ip4_address(self): def get_ip4_address(self):
@ -126,7 +126,7 @@ class BaseBuddy(gobject.GObject):
def set_ip4_address(self, ip4_address): def set_ip4_address(self, ip4_address):
self._ip4_address = ip4_address self._ip4_address = ip4_address
ip4_address = gobject.property(type=str, getter=get_ip4_address, ip4_address = GObject.property(type=str, getter=get_ip4_address,
setter=set_ip4_address) setter=set_ip4_address)
def get_tags(self): def get_tags(self):
@ -135,7 +135,7 @@ class BaseBuddy(gobject.GObject):
def set_tags(self, tags): def set_tags(self, tags):
self._tags = tags self._tags = tags
tags = gobject.property(type=str, getter=get_tags, setter=set_tags) tags = GObject.property(type=str, getter=get_tags, setter=set_tags)
def object_path(self): def object_path(self):
"""Retrieve our dbus object path""" """Retrieve our dbus object path"""
@ -243,6 +243,6 @@ class Owner(BaseBuddy):
def __init__(self): def __init__(self):
BaseBuddy.__init__(self) BaseBuddy.__init__(self)
client = gconf.client_get_default() client = GConf.Client.get_default()
self.props.nick = client.get_string('/desktop/sugar/user/nick') self.props.nick = client.get_string('/desktop/sugar/user/nick')
self.props.color = client.get_string('/desktop/sugar/user/color') self.props.color = client.get_string('/desktop/sugar/user/color')

View File

@ -22,7 +22,7 @@ STABLE.
import logging import logging
import gobject from gi.repository import GObject
import dbus import dbus
import dbus.exceptions import dbus.exceptions
import dbus.glib import dbus.glib
@ -46,18 +46,18 @@ ACCOUNT_MANAGER_PATH = '/org/freedesktop/Telepathy/AccountManager'
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties' CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
class PresenceService(gobject.GObject): class PresenceService(GObject.GObject):
"""Provides simplified access to the Telepathy framework to activities""" """Provides simplified access to the Telepathy framework to activities"""
__gsignals__ = { __gsignals__ = {
'activity-shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, 'activity-shared': (GObject.SignalFlags.RUN_FIRST, None,
([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, ([GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT,
gobject.TYPE_PYOBJECT])), GObject.TYPE_PYOBJECT])),
} }
def __init__(self): def __init__(self):
"""Initialise the service and attempt to connect to events """Initialise the service and attempt to connect to events
""" """
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self._activity_cache = None self._activity_cache = None
self._buddy_cache = {} self._buddy_cache = {}

View File

@ -20,7 +20,7 @@
DEPRECATED. We are using GConf now to store preferences. DEPRECATED. We are using GConf now to store preferences.
""" """
import gconf from gi.repository import GConf
import os import os
import logging import logging
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
@ -68,7 +68,7 @@ class Profile(object):
privkey_hash = property(fget=_get_privkey_hash) privkey_hash = property(fget=_get_privkey_hash)
def is_valid(self): def is_valid(self):
client = gconf.client_get_default() client = GConf.Client.get_default()
nick = client.get_string('/desktop/sugar/user/nick') nick = client.get_string('/desktop/sugar/user/nick')
color = client.get_string('/desktop/sugar/user/color') color = client.get_string('/desktop/sugar/user/color')
@ -140,7 +140,7 @@ class Profile(object):
path = os.path.join(env.get_profile_path(), 'config') path = os.path.join(env.get_profile_path(), 'config')
cp.read([path]) cp.read([path])
client = gconf.client_get_default() client = GConf.Client.get_default()
if cp.has_option('Buddy', 'NickName'): if cp.has_option('Buddy', 'NickName'):
name = cp.get('Buddy', 'NickName') name = cp.get('Buddy', 'NickName')
@ -224,12 +224,12 @@ def get_profile():
def get_nick_name(): def get_nick_name():
client = gconf.client_get_default() client = GConf.Client.get_default()
return client.get_string('/desktop/sugar/user/nick') return client.get_string('/desktop/sugar/user/nick')
def get_color(): def get_color():
client = gconf.client_get_default() client = GConf.Client.get_default()
color = client.get_string('/desktop/sugar/user/color') color = client.get_string('/desktop/sugar/user/color')
return XoColor(color) return XoColor(color)

View File

@ -21,23 +21,23 @@ UNSTABLE. Used only internally by jarabe.
import os import os
from sugar import _sugarext from gi.repository import SugarExt
class XSMPClient(_sugarext.SMClientXSMP): class XSMPClient(SugarExt.Client):
def __init__(self): def __init__(self):
_sugarext.SMClientXSMP.__init__(self) SugarExt.Client.__init__(self)
class SessionManager(object): class SessionManager(object):
def __init__(self): def __init__(self):
address = _sugarext.xsmp_init() address = SugarExt.xsmp_init()
os.environ['SESSION_MANAGER'] = address os.environ['SESSION_MANAGER'] = address
_sugarext.xsmp_run() SugarExt.xsmp_run()
self.session = _sugarext.session_create_global() self.session = SugarExt.Session.create_global()
def start(self): def start(self):
self.session.start() self.session.start()
@ -48,7 +48,7 @@ class SessionManager(object):
self.session.initiate_shutdown() self.session.initiate_shutdown()
def shutdown_completed(self): def shutdown_completed(self):
_sugarext.xsmp_shutdown() SugarExt.xsmp_shutdown()
def __shutdown_completed_cb(self, session): def __shutdown_completed_cb(self, session):
self.shutdown_completed() self.shutdown_completed()

View File

@ -19,18 +19,18 @@
UNSTABLE. Used only internally by Activity and jarabe. UNSTABLE. Used only internally by Activity and jarabe.
""" """
import gtk from gi.repository import Gtk
from gtk import gdk from gi.repository import Gdk
import logging import logging
def _property_get_trapped(window, prop, prop_type): def _property_get_trapped(window, prop, prop_type):
gtk.gdk.error_trap_push() Gdk.error_trap_push()
prop_info = window.property_get(prop, prop_type) prop_info = window.property_get(prop, prop_type)
# We just log a message # We just log a message
error = gtk.gdk.error_trap_pop() error = Gdk.error_trap_pop()
if error: if error:
logging.debug('Received X Error (%i) while getting ' logging.debug('Received X Error (%i) while getting '
'a property on a window', error) 'a property on a window', error)
@ -40,11 +40,11 @@ def _property_get_trapped(window, prop, prop_type):
def _property_change_trapped(window, prop, prop_type, format, mode, data): def _property_change_trapped(window, prop, prop_type, format, mode, data):
# pylint: disable=W0622 # pylint: disable=W0622
gtk.gdk.error_trap_push() Gdk.error_trap_push()
window.property_change(prop, prop_type, format, mode, data) window.property_change(prop, prop_type, format, mode, data)
error = gtk.gdk.error_trap_pop() error = Gdk.error_trap_pop()
if error: if error:
logging.debug('Received X Error (%i) while setting ' logging.debug('Received X Error (%i) while setting '
'a property on a window', error) 'a property on a window', error)
@ -53,7 +53,7 @@ def _property_change_trapped(window, prop, prop_type, format, mode, data):
def get_activity_id(wnck_window): def get_activity_id(wnck_window):
window = gtk.gdk.window_foreign_new(wnck_window.get_xid()) window = Gdk.window_foreign_new(wnck_window.get_xid())
prop_info = _property_get_trapped(window, '_SUGAR_ACTIVITY_ID', 'STRING') prop_info = _property_get_trapped(window, '_SUGAR_ACTIVITY_ID', 'STRING')
if prop_info is None: if prop_info is None:
return None return None
@ -62,7 +62,7 @@ def get_activity_id(wnck_window):
def get_bundle_id(wnck_window): def get_bundle_id(wnck_window):
window = gtk.gdk.window_foreign_new(wnck_window.get_xid()) window = Gdk.window_foreign_new(wnck_window.get_xid())
prop_info = _property_get_trapped(window, '_SUGAR_BUNDLE_ID', 'STRING') prop_info = _property_get_trapped(window, '_SUGAR_BUNDLE_ID', 'STRING')
if prop_info is None: if prop_info is None:
return None return None
@ -71,7 +71,7 @@ def get_bundle_id(wnck_window):
def get_sugar_window_type(wnck_window): def get_sugar_window_type(wnck_window):
window = gtk.gdk.window_foreign_new(wnck_window.get_xid()) window = Gdk.window_foreign_new(wnck_window.get_xid())
prop_info = _property_get_trapped(window, '_SUGAR_WINDOW_TYPE', 'STRING') prop_info = _property_get_trapped(window, '_SUGAR_WINDOW_TYPE', 'STRING')
if prop_info is None: if prop_info is None:
return None return None
@ -81,9 +81,9 @@ def get_sugar_window_type(wnck_window):
def set_activity_id(window, activity_id): def set_activity_id(window, activity_id):
_property_change_trapped(window, '_SUGAR_ACTIVITY_ID', 'STRING', 8, _property_change_trapped(window, '_SUGAR_ACTIVITY_ID', 'STRING', 8,
gtk.gdk.PROP_MODE_REPLACE, activity_id) Gdk.PROP_MODE_REPLACE, activity_id)
def set_bundle_id(window, bundle_id): def set_bundle_id(window, bundle_id):
_property_change_trapped(window, '_SUGAR_BUNDLE_ID', 'STRING', 8, _property_change_trapped(window, '_SUGAR_BUNDLE_ID', 'STRING', 8,
gtk.gdk.PROP_MODE_REPLACE, bundle_id) Gdk.PROP_MODE_REPLACE, bundle_id)

View File

@ -15,21 +15,21 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import gtk from gi.repository import Gtk
from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.toolbutton import ToolButton
class Test(gtk.VBox): class Test(Gtk.VBox):
def __init__(self): def __init__(self):
gtk.VBox.__init__(self) GObject.GObject.__init__(self)
class TestPalette(Test): class TestPalette(Test):
def __init__(self): def __init__(self):
Test.__init__(self) Test.__init__(self)
toolbar = gtk.Toolbar() toolbar = Gtk.Toolbar()
self._invoker = ToolButton('go-previous') self._invoker = ToolButton('go-previous')
toolbar.insert(self._invoker, -1) toolbar.insert(self._invoker, -1)
@ -44,8 +44,8 @@ class TestPalette(Test):
class TestRunner(object): class TestRunner(object):
def run(self, test): def run(self, test):
window = gtk.Window() window = Gtk.Window()
window.connect('destroy', lambda w: gtk.main_quit()) window.connect('destroy', lambda w: Gtk.main_quit())
window.add(test) window.add(test)
test.show() test.show()
@ -56,4 +56,4 @@ def main(test):
runner = TestRunner() runner = TestRunner()
runner.run(test) runner.run(test)
gtk.main() Gtk.main()

View File

@ -19,7 +19,7 @@
Test the sugar3.graphics.icon.* cache. Test the sugar3.graphics.icon.* cache.
""" """
import gtk from gi.repository import Gtk
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
from sugar3.graphics.xocolor import XoColor from sugar3.graphics.xocolor import XoColor
@ -54,13 +54,13 @@ def _button_activated_cb(button):
for d in data: for d in data:
icon = Icon(icon_name=d[0], icon = Icon(icon_name=d[0],
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, icon_size=Gtk.IconSize.LARGE_TOOLBAR,
xo_color=XoColor(d[1])) xo_color=XoColor(d[1]))
test.pack_start(icon) test.pack_start(icon, True, True, 0)
icon.show() icon.show()
button = gtk.Button('mec mac') button = Gtk.Button('mec mac')
test.pack_start(button) test.pack_start(button, True, True, 0)
button.connect('activate', _button_activated_cb) button.connect('activate', _button_activated_cb)
button.show() button.show()

View File

@ -19,7 +19,7 @@
Test the sugar3.graphics.icon.Icon widget. Test the sugar3.graphics.icon.Icon widget.
""" """
import gtk from gi.repository import Gtk
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
from sugar3.graphics.xocolor import XoColor from sugar3.graphics.xocolor import XoColor
@ -28,41 +28,41 @@ import common
test = common.Test() test = common.Test()
hbox = gtk.HBox() hbox = Gtk.HBox()
test.pack_start(hbox) test.pack_start(hbox, True, True, 0)
sensitive_box = gtk.VBox() sensitive_box = Gtk.VBox()
insensitive_box = gtk.VBox() insensitive_box = Gtk.VBox()
hbox.pack_start(sensitive_box) hbox.pack_start(sensitive_box, True, True, 0)
hbox.pack_start(insensitive_box) hbox.pack_start(insensitive_box, True, True, 0)
hbox.show_all() hbox.show_all()
def create_icon_widgets(box, sensitive=True): def create_icon_widgets(box, sensitive=True):
icon = Icon(icon_name='go-previous') icon = Icon(icon_name='go-previous')
icon.props.icon_size = gtk.ICON_SIZE_LARGE_TOOLBAR icon.props.icon_size = Gtk.IconSize.LARGE_TOOLBAR
box.pack_start(icon) box.pack_start(icon, True, True, 0)
icon.set_sensitive(sensitive) icon.set_sensitive(sensitive)
icon.show() icon.show()
icon = Icon(icon_name='computer-xo', icon = Icon(icon_name='computer-xo',
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, icon_size=Gtk.IconSize.LARGE_TOOLBAR,
xo_color=XoColor()) xo_color=XoColor())
box.pack_start(icon) box.pack_start(icon, True, True, 0)
icon.set_sensitive(sensitive) icon.set_sensitive(sensitive)
icon.show() icon.show()
icon = Icon(icon_name='battery-000', icon = Icon(icon_name='battery-000',
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, icon_size=Gtk.IconSize.LARGE_TOOLBAR,
badge_name='emblem-busy') badge_name='emblem-busy')
box.pack_start(icon) box.pack_start(icon, True, True, 0)
icon.set_sensitive(sensitive) icon.set_sensitive(sensitive)
icon.show() icon.show()
icon = Icon(icon_name='gtk-new', icon = Icon(icon_name='gtk-new',
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR, icon_size=Gtk.IconSize.LARGE_TOOLBAR,
badge_name='gtk-cancel') badge_name='gtk-cancel')
box.pack_start(icon) box.pack_start(icon, True, True, 0)
icon.set_sensitive(sensitive) icon.set_sensitive(sensitive)
icon.show() icon.show()
@ -80,8 +80,8 @@ test.show()
# test.queue_draw() # test.queue_draw()
# return True # return True
# #
#import gobject #from gi.repository import GObject
#gobject.idle_add(idle_cb) #GObject.idle_add(idle_cb)
if __name__ == '__main__': if __name__ == '__main__':
common.main(test) common.main(test)

View File

@ -21,7 +21,7 @@ contains only an icon and should be rendered similarly to the toolbar
controls. Ticket #2855. controls. Ticket #2855.
""" """
import gtk from gi.repository import Gtk
from sugar3.graphics.palette import Palette from sugar3.graphics.palette import Palette
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
@ -33,19 +33,19 @@ test = common.TestPalette()
palette = Palette('Test radio and toggle') palette = Palette('Test radio and toggle')
test.set_palette(palette) test.set_palette(palette)
box = gtk.HBox() box = Gtk.HBox()
toggle = gtk.ToggleButton() toggle = Gtk.ToggleButton()
icon = Icon(icon_name='go-previous', icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) icon = Icon(icon_name='go-previous', icon_size=Gtk.IconSize.LARGE_TOOLBAR)
toggle.set_image(icon) toggle.set_image(icon)
box.pack_start(toggle, False) box.pack_start(toggle, False)
toggle.show() toggle.show()
radio = gtk.RadioButton() radio = Gtk.RadioButton()
icon = Icon(icon_name='go-next', icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR) icon = Icon(icon_name='go-next', icon_size=Gtk.IconSize.LARGE_TOOLBAR)
radio.set_image(icon) radio.set_image(icon)
radio.set_mode(False) radio.set_mode(False)

View File

@ -19,7 +19,7 @@
Spec in ticket #2999. Spec in ticket #2999.
""" """
import gtk from gi.repository import Gtk
from sugar3.graphics.palette import Palette from sugar3.graphics.palette import Palette
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
@ -29,9 +29,9 @@ import common
test = common.Test() test = common.Test()
test.set_border_width(60) test.set_border_width(60)
text_view = gtk.TextView() text_view = Gtk.TextView()
text_view.props.buffer.props.text = 'Blah blah blah, blah blah blah.' text_view.props.buffer.props.text = 'Blah blah blah, blah blah blah.'
test.pack_start(text_view) test.pack_start(text_view, True, True, 0)
text_view.show() text_view.show()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -19,7 +19,7 @@
Spec in ticket #3000. Spec in ticket #3000.
""" """
import gtk from gi.repository import Gtk
from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.toolbutton import ToolButton
@ -27,7 +27,7 @@ import common
test = common.Test() test = common.Test()
toolbar = gtk.Toolbar() toolbar = Gtk.Toolbar()
test.pack_start(toolbar, False) test.pack_start(toolbar, False)
toolbar.show() toolbar.show()
@ -35,7 +35,7 @@ button = ToolButton('go-previous')
toolbar.insert(button, -1) toolbar.insert(button, -1)
button.show() button.show()
separator = gtk.SeparatorToolItem() separator = Gtk.SeparatorToolItem()
toolbar.add(separator) toolbar.add(separator)
separator.show() separator.show()

View File

@ -19,7 +19,7 @@
Test palette positioning for toolbar and tray. Test palette positioning for toolbar and tray.
""" """
import gtk from gi.repository import Gtk
from sugar3.graphics.tray import HTray, TrayButton from sugar3.graphics.tray import HTray, TrayButton
from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.toolbutton import ToolButton
@ -28,11 +28,11 @@ import common
test = common.Test() test = common.Test()
vbox = gtk.VBox() vbox = Gtk.VBox()
theme_icons = gtk.icon_theme_get_default().list_icons() theme_icons = Gtk.IconTheme.get_default().list_icons()
toolbar = gtk.Toolbar() toolbar = Gtk.Toolbar()
vbox.pack_start(toolbar, False) vbox.pack_start(toolbar, False)
toolbar.show() toolbar.show()
@ -42,8 +42,8 @@ for i in range(0, 5):
toolbar.insert(button, -1) toolbar.insert(button, -1)
button.show() button.show()
content = gtk.Label() content = Gtk.Label()
vbox.pack_start(content) vbox.pack_start(content, True, True, 0)
content.show() content.show()
tray = HTray() tray = HTray()
@ -56,7 +56,7 @@ for i in range(0, 30):
tray.add_item(button) tray.add_item(button)
button.show() button.show()
test.pack_start(vbox) test.pack_start(vbox, True, True, 0)
vbox.show() vbox.show()
test.show() test.show()

View File

@ -19,7 +19,7 @@
Test the sugar3.graphics.icon.Icon widget. Test the sugar3.graphics.icon.Icon widget.
""" """
import gtk from gi.repository import Gtk
from sugar3.graphics.tray import HTray, VTray from sugar3.graphics.tray import HTray, VTray
from sugar3.graphics.tray import TrayButton, TrayIcon from sugar3.graphics.tray import TrayButton, TrayIcon
@ -28,13 +28,13 @@ import common
test = common.Test() test = common.Test()
vbox = gtk.VBox() vbox = Gtk.VBox()
tray = HTray() tray = HTray()
vbox.pack_start(tray, False) vbox.pack_start(tray, False)
tray.show() tray.show()
theme_icons = gtk.icon_theme_get_default().list_icons() theme_icons = Gtk.IconTheme.get_default().list_icons()
for i in range(0, 100): for i in range(0, 100):
button = TrayButton(icon_name=theme_icons[i]) button = TrayButton(icon_name=theme_icons[i])
@ -50,7 +50,7 @@ for i in range(0, 10):
tray.add_item(icon) tray.add_item(icon)
icon.show() icon.show()
hbox = gtk.HBox() hbox = Gtk.HBox()
tray = VTray() tray = VTray()
hbox.pack_start(tray, False) hbox.pack_start(tray, False)
@ -70,10 +70,10 @@ for i in range(0, 4):
tray.add_item(button) tray.add_item(button)
button.show() button.show()
vbox.pack_start(hbox) vbox.pack_start(hbox, True, True, 0)
hbox.show() hbox.show()
test.pack_start(vbox) test.pack_start(vbox, True, True, 0)
vbox.show() vbox.show()
test.show() test.show()