Skip to content

Commit

Permalink
Port from GObject to GLib
Browse files Browse the repository at this point in the history
  • Loading branch information
rhl-bthr authored and quozl committed Jul 26, 2018
1 parent ffe4d50 commit c36b7fb
Show file tree
Hide file tree
Showing 50 changed files with 216 additions and 197 deletions.
9 changes: 5 additions & 4 deletions extensions/cpsection/aboutme/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import GLib
from gettext import gettext as _

from sugar3.graphics import style
Expand Down Expand Up @@ -143,7 +144,7 @@ def set_color(self, color):
self._color = color
self.props.xo_color = self._color

color = GObject.property(type=object, setter=set_color)
color = GObject.Property(type=object, setter=set_color)

def __activate_cb(self, button, picker):
if picker != _CURRENT_COLOR:
Expand Down Expand Up @@ -365,9 +366,9 @@ def _validate(self):

def __nick_changed_cb(self, widget, data=None):
if self._nick_sid:
GObject.source_remove(self._nick_sid)
self._nick_sid = GObject.timeout_add(self._APPLY_TIMEOUT,
self.__nick_timeout_cb, widget)
GLib.source_remove(self._nick_sid)
self._nick_sid = GLib.timeout_add(self._APPLY_TIMEOUT,
self.__nick_timeout_cb, widget)

def __nick_timeout_cb(self, widget):
self._nick_sid = 0
Expand Down
10 changes: 5 additions & 5 deletions extensions/cpsection/background/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import GdkPixbuf

from sugar3.graphics import style
Expand Down Expand Up @@ -129,14 +129,14 @@ def _append_to_store(self, file_paths):
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
file_path, style.XLARGE_ICON_SIZE,
style.XLARGE_ICON_SIZE)
except GObject.GError:
except GLib.GError:
pass
else:
self._store.append([pixbuf, file_path])
self._paths_list.append(file_path)

self._append_to_store_sid = GObject.idle_add(self._append_to_store,
file_paths)
self._append_to_store_sid = GLib.idle_add(self._append_to_store,
file_paths)
else:
self._select_background()
self._images_loaded = True
Expand All @@ -147,7 +147,7 @@ def _append_to_store(self, file_paths):

def _cancel_append_to_store(self):
if self._append_to_store_sid is not None:
GObject.source_remove(self._append_to_store_sid)
GLib.source_remove(self._append_to_store_sid)
self._append_to_store_sid = None

def __realize_cb(self, widget):
Expand Down
10 changes: 5 additions & 5 deletions extensions/cpsection/backup/backends/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from gettext import gettext as _
from gi.repository import Gio
from gi.repository import GObject
from gi.repository import GLib

from sugar3 import env
from sugar3 import profile
Expand Down Expand Up @@ -105,7 +105,7 @@ def _do_continue(self):
elif len(self._entries) == 0:
self._do_finish()
else:
GObject.idle_add(self._do_continue)
GLib.idle_add(self._do_continue)

def _do_cancel(self):
self._tarfile.close()
Expand Down Expand Up @@ -133,7 +133,7 @@ def start(self):
self._entries = self._get_datastore_entries()
self._total = len(self._entries)
self._cancelled = False
GObject.idle_add(self._do_continue)
GLib.idle_add(self._do_continue)

def cancel(self):
self._cancelled = True
Expand Down Expand Up @@ -218,7 +218,7 @@ def _do_continue(self):
self._percent = percent
logging.debug('restore-local progress is %f', percent)
self.emit('progress', float(percent) / 100.0)
GObject.idle_add(self._do_continue)
GLib.idle_add(self._do_continue)
else:
self._do_finish()

Expand All @@ -234,7 +234,7 @@ def start(self):
self._tarfile = tarfile.open(self._checkpoint, 'r:gz')
self._bytes = 0.0
self._reset_datastore()
GObject.idle_add(self._do_continue)
GLib.idle_add(self._do_continue)

def cancel(self):
if not self._cancellable:
Expand Down
15 changes: 8 additions & 7 deletions extensions/cpsection/backup/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from gettext import gettext as _

from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gdk

Expand Down Expand Up @@ -63,9 +64,9 @@ def undo(self):
class _BackupButton(Gtk.EventBox):

__gproperties__ = {
'icon-name': (str, None, None, None, GObject.PARAM_READWRITE),
'pixel-size': (object, None, None, GObject.PARAM_READWRITE),
'title': (str, None, None, None, GObject.PARAM_READWRITE),
'icon-name': (str, None, None, None, GObject.ParamFlags.READWRITE),
'pixel-size': (object, None, None, GObject.ParamFlags.READWRITE),
'title': (str, None, None, None, GObject.ParamFlags.READWRITE),
}

def __init__(self, **kwargs):
Expand Down Expand Up @@ -237,7 +238,7 @@ def __init__(self, operation, view):
self._ask_options(message, combo_options, self._select_backend)
else:
self._backend = self._view.manager.get_backends()[0]
GObject.idle_add(self._start_operation)
GLib.idle_add(self._start_operation)

def _ask_options(self, message, options, continue_cb):
"""
Expand Down Expand Up @@ -291,7 +292,7 @@ def _start_operation(self):
self._operator = self._backend.get_restore()
self._message_label.set_text(_('Starting restore...'))

GObject.idle_add(self._continue_operation)
GLib.idle_add(self._continue_operation)

def _continue_operation(self, options={}):
need_more_information = True
Expand All @@ -306,7 +307,7 @@ def _continue_operation(self, options={}):
self._assign_parameter_backend)
if not need_more_information:
if self._operation == OPERATION_BACKUP:
GObject.idle_add(self._internal_start_operation)
GLib.idle_add(self._internal_start_operation)

if self._operation == OPERATION_RESTORE:
# The restore is potentially dangerous
Expand Down Expand Up @@ -347,7 +348,7 @@ def _internal_start_operation(self):
# disable the accept button until the operation finish
self._view.props.is_valid = False

GObject.idle_add(self._operator.start)
GLib.idle_add(self._operator.start)

def __retry_cb(self, button):
self._start_operation()
Expand Down
7 changes: 4 additions & 3 deletions extensions/cpsection/datetime/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import GLib
from gettext import gettext as _

from sugar3.graphics import style
Expand Down Expand Up @@ -121,9 +122,9 @@ def __zone_changed_cd(self, treeview, data=None):
return False

if self._zone_sid:
GObject.source_remove(self._zone_sid)
self._zone_sid = GObject.timeout_add(self._APPLY_TIMEOUT,
self.__zone_timeout_cb, row)
GLib.source_remove(self._zone_sid)
self._zone_sid = GLib.timeout_add(self._APPLY_TIMEOUT,
self.__zone_timeout_cb, row)
return True

def __zone_timeout_cb(self, row):
Expand Down
20 changes: 10 additions & 10 deletions extensions/cpsection/frame/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import GLib
from gettext import gettext as _

from sugar3.graphics import style
Expand Down Expand Up @@ -157,8 +157,8 @@ def undo(self):

def __corner_delay_changed_cb(self, scale, data=None):
if self._corner_delay_sid:
GObject.source_remove(self._corner_delay_sid)
self._corner_delay_sid = GObject.timeout_add(
GLib.source_remove(self._corner_delay_sid)
self._corner_delay_sid = GLib.timeout_add(
self._APPLY_TIMEOUT, self.__corner_delay_timeout_cb, scale)

def __corner_delay_timeout_cb(self, scale):
Expand All @@ -180,8 +180,8 @@ def __corner_delay_format_cb(self, scale, value):

def __edge_delay_changed_cb(self, scale, data=None):
if self._edge_delay_sid:
GObject.source_remove(self._edge_delay_sid)
self._edge_delay_sid = GObject.timeout_add(
GLib.source_remove(self._edge_delay_sid)
self._edge_delay_sid = GLib.timeout_add(
self._APPLY_TIMEOUT, self.__edge_delay_timeout_cb, scale)

def __edge_delay_timeout_cb(self, scale):
Expand All @@ -203,8 +203,8 @@ def __edge_delay_format_cb(self, scale, value):

def __trigger_size_changed_cb(self, scale, data=None):
if self._trigger_size_sid:
GObject.source_remove(self._trigger_size_sid)
self._trigger_size_sid = GObject.timeout_add(
GLib.source_remove(self._trigger_size_sid)
self._trigger_size_sid = GLib.timeout_add(
self._APPLY_TIMEOUT, self.__trigger_size_timeout_cb, scale)

def __trigger_size_timeout_cb(self, scale):
Expand Down Expand Up @@ -236,11 +236,11 @@ def __trigger_size_format_cb(self, scale, value):

def apply(self):
if self._corner_delay_sid:
GObject.source_remove(self._corner_delay_sid)
GLib.source_remove(self._corner_delay_sid)
self.__corner_delay_timeout_cb(self._corner_delay_slider)
if self._edge_delay_sid:
GObject.source_remove(self._edge_delay_sid)
GLib.source_remove(self._edge_delay_sid)
self.__edge_delay_timeout_cb(self._edge_delay_slider)
if self._trigger_size_sid:
GObject.source_remove(self._trigger_size_sid)
GLib.source_remove(self._trigger_size_sid)
self.__trigger_size_timeout_cb(self._trigger_size_sid)
19 changes: 10 additions & 9 deletions extensions/cpsection/keyboard/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from gi.repository import Gtk
from gi.repository import GdkX11
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Pango

import logging
Expand Down Expand Up @@ -273,10 +274,10 @@ def _setup_kmodel(self):

def __kmodel_changed_cb(self, combobox):
if self.__kmodel_sid is not None:
GObject.source_remove(self.__kmodel_sid)
self.__kmodel_sid = GObject.timeout_add(_APPLY_TIMEOUT,
self.__kmodel_timeout_cb,
combobox)
GLib.source_remove(self.__kmodel_sid)
self.__kmodel_sid = GLib.timeout_add(_APPLY_TIMEOUT,
self.__kmodel_timeout_cb,
combobox)

def __kmodel_timeout_cb(self, combobox):
it = combobox.get_active_iter()
Expand Down Expand Up @@ -341,8 +342,8 @@ def _setup_group_switch_option(self):

def __group_switch_changed_cb(self, combobox):
if self.__group_switch_sid is not None:
GObject.source_remove(self.__group_switch_sid)
self.__group_switch_sid = GObject.timeout_add(
GLib.source_remove(self.__group_switch_sid)
self.__group_switch_sid = GLib.timeout_add(
_APPLY_TIMEOUT, self.__group_switch_timeout_cb, combobox)

def __group_switch_timeout_cb(self, combobox):
Expand Down Expand Up @@ -454,9 +455,9 @@ def _update_klayouts(self):
self.__determine_add_remove_box_visibility()

if self.__layout_sid is not None:
GObject.source_remove(self.__layout_sid)
self.__layout_sid = GObject.timeout_add(_APPLY_TIMEOUT,
self.__layout_timeout_cb)
GLib.source_remove(self.__layout_sid)
self.__layout_sid = GLib.timeout_add(_APPLY_TIMEOUT,
self.__layout_timeout_cb)

def __layout_timeout_cb(self):
if self._selected_klayouts == \
Expand Down
12 changes: 6 additions & 6 deletions extensions/cpsection/language/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
from gi.repository import GLib
import gettext

from sugar3.graphics import style
Expand Down Expand Up @@ -375,15 +375,15 @@ def _check_change(self):
self.restart_alerts.remove('lang')
self._lang_alert.hide()
if self._lang_sid:
GObject.source_remove(self._lang_sid)
GLib.source_remove(self._lang_sid)
self._model.undo()
return False

if self._lang_sid:
GObject.source_remove(self._lang_sid)
self._lang_sid = GObject.timeout_add(self._APPLY_TIMEOUT,
self.__lang_timeout_cb,
selected_langs)
GLib.source_remove(self._lang_sid)
self._lang_sid = GLib.timeout_add(self._APPLY_TIMEOUT,
self.__lang_timeout_cb,
selected_langs)

def __lang_timeout_cb(self, codes):
self._lang_sid = 0
Expand Down
2 changes: 1 addition & 1 deletion extensions/cpsection/modemconfiguration/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, label_text):
def get_entry(self):
return self._entry

entry = GObject.property(type=object, getter=get_entry)
entry = GObject.Property(type=object, getter=get_entry)


class ModemConfiguration(SectionView):
Expand Down
7 changes: 4 additions & 3 deletions extensions/deviceicon/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,10 @@ def __popup_cb(self, palette):

class DeviceModelAudio(GObject.GObject):
__gproperties__ = {
'level': (int, None, None, 0, 100, 0, GObject.PARAM_READWRITE),
'last-level': (int, None, None, 0, 100, 0, GObject.PARAM_READABLE),
'muted': (bool, None, None, False, GObject.PARAM_READWRITE),
'level': (int, None, None, 0, 100, 0, GObject.ParamFlags.READWRITE),
'last-level': (int, None, None, 0, 100, 0,
GObject.ParamFlags.READABLE),
'muted': (bool, None, None, False, GObject.ParamFlags.READWRITE),
}

def __init__(self):
Expand Down
16 changes: 8 additions & 8 deletions extensions/deviceicon/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ def _update_secondary(self):

class DeviceModel(GObject.GObject):
__gproperties__ = {
'level': (int, None, None, 0, 100, 0, GObject.PARAM_READABLE),
'level': (int, None, None, 0, 100, 0, GObject.ParamFlags.READABLE),
'time-remaining': (int, None, None, 0, GLib.MAXINT32, 0,
GObject.PARAM_READABLE), # unit: seconds
'charging': (bool, None, None, False, GObject.PARAM_READABLE),
'discharging': (bool, None, None, False, GObject.PARAM_READABLE),
'present': (bool, None, None, False, GObject.PARAM_READABLE),
GObject.ParamFlags.READABLE), # unit: seconds
'charging': (bool, None, None, False, GObject.ParamFlags.READABLE),
'discharging': (bool, None, None, False, GObject.ParamFlags.READABLE),
'present': (bool, None, None, False, GObject.ParamFlags.READABLE),
}

__gsignals__ = {
Expand Down Expand Up @@ -256,8 +256,8 @@ def __notify_cb(self, device, name):
but without any indication that the burst is complete, so we
use a timeout to respond."""
if self._timeout_sid:
GObject.source_remove(self._timeout_sid)
self._timeout_sid = GObject.timeout_add(100, self.__timeout_cb)
GLib.source_remove(self._timeout_sid)
self._timeout_sid = GLib.timeout_add(100, self.__timeout_cb)

def __timeout_cb(self):
old_level = self._level
Expand Down Expand Up @@ -301,7 +301,7 @@ def __check_capacity(self):
self._level)
sm = get_session_manager()
sm.shutdown()
GObject.timeout_add_seconds(10, sm.shutdown_completed)
GLib.timeout_add_seconds(10, sm.shutdown_completed)

def setup(tray):
bus = dbus.Bus(dbus.Bus.TYPE_SYSTEM)
Expand Down
Loading

0 comments on commit c36b7fb

Please sign in to comment.