Skip to content

Commit

Permalink
PEP8 cleanup: ensure lines are shorter than 80 characters
Browse files Browse the repository at this point in the history
This is important for Sugar because the XO has a small screen where long lines
would make the code hard to understand (because you need to constantly scroll horizontally).

Reviewed-by: James Cameron <[email protected]>
CC: Aleksey Lim <[email protected]>
  • Loading branch information
silbe committed Nov 24, 2010
1 parent 31fea8c commit fdb33c3
Show file tree
Hide file tree
Showing 40 changed files with 184 additions and 130 deletions.
3 changes: 2 additions & 1 deletion extensions/cpsection/datetime/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def __init__(self, model, alerts):
self._entry.show()

self._scrolled_window = gtk.ScrolledWindow()
self._scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
self._scrolled_window.set_policy(gtk.POLICY_NEVER,
gtk.POLICY_AUTOMATIC)
self._scrolled_window.set_shadow_type(gtk.SHADOW_IN)

self._store = gtk.ListStore(gobject.TYPE_STRING)
Expand Down
4 changes: 2 additions & 2 deletions extensions/cpsection/frame/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def setup(self):
self._corner_delay_is_valid = True
self._edge_delay_is_valid = True
self.needs_restart = False
self._corner_delay_change_handler = self._corner_delay_slider.connect( \
self._corner_delay_change_handler = self._corner_delay_slider.connect(
'value-changed', self.__corner_delay_changed_cb)
self._edge_delay_change_handler = self._edge_delay_slider.connect( \
self._edge_delay_change_handler = self._edge_delay_slider.connect(
'value-changed', self.__edge_delay_changed_cb)

def undo(self):
Expand Down
4 changes: 2 additions & 2 deletions extensions/cpsection/keyboard/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def get_layouts_for_language(self, language):
def get_options_group(self):
"""Return list of supported options for switching keyboard group"""
options = []
self._configregistry.foreach_option(_GROUP_NAME, self._populate_one, \
options)
self._configregistry.foreach_option(_GROUP_NAME, self._populate_one,
options)
options.sort()
return options

Expand Down
3 changes: 2 additions & 1 deletion extensions/cpsection/keyboard/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ def __kmodel_timeout_cb(self, combobox):
return False

def _setup_group_switch_option(self):
"""Adds the controls for changing the group switch option of keyboard"""
"""Adds the controls for changing the group switch option of keyboard
"""
separator_group_option = gtk.HSeparator()
self._vbox.pack_start(separator_group_option, expand=False)
separator_group_option.show_all()
Expand Down
6 changes: 3 additions & 3 deletions extensions/cpsection/language/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def __init__(self, model, alerts):
self.set_border_width(style.DEFAULT_SPACING * 2)
self.set_spacing(style.DEFAULT_SPACING)

explanation = gettext.gettext("Add languages in the order you prefer." \
" If a translation is not available,"\
" the next in the list will be used.")
explanation = gettext.gettext('Add languages in the order you prefer.'
' If a translation is not available,'
' the next in the list will be used.')
self._text = gtk.Label(explanation)
self._text.set_width_chars(100)
self._text.set_line_wrap(True)
Expand Down
3 changes: 2 additions & 1 deletion extensions/cpsection/network/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ def __jabber_changed_cb(self, widget, data=None):
if self._jabber_sid:
gobject.source_remove(self._jabber_sid)
self._jabber_sid = gobject.timeout_add(_APPLY_TIMEOUT,
self.__jabber_timeout_cb, widget)
self.__jabber_timeout_cb,
widget)

def __jabber_timeout_cb(self, widget):
self._jabber_sid = 0
Expand Down
9 changes: 6 additions & 3 deletions extensions/cpsection/updater/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,17 @@ def _cancel_checking(self):
logging.debug('UpdateModel._cancel_checking')
total = len(bundleregistry.get_registry())
current = total - len(self._bundles_to_check)
self.emit('progress', UpdateModel.ACTION_CHECKING, '', current, current)
self.emit('progress', UpdateModel.ACTION_CHECKING, '', current,
current)
self._bundles_to_check = None
self._cancelling = False

def _cancel_updating(self):
logging.debug('UpdateModel._cancel_updating')
current = self._total_bundles_to_update - len(self._bundles_to_update) - 1
self.emit('progress', UpdateModel.ACTION_UPDATING, '', current, current)
current = (self._total_bundles_to_update -
len(self._bundles_to_update) - 1)
self.emit('progress', UpdateModel.ACTION_UPDATING, '', current,
current)

if self._downloader is not None:
self._downloader.cancel()
Expand Down
3 changes: 2 additions & 1 deletion extensions/cpsection/updater/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def _refresh(self):
self._model.check_updates()

def __install_button_clicked_cb(self, button):
self._top_label.set_markup('<big>%s</big>' % _('Installing updates...'))
text = '<big>%s</big>' % _('Installing updates...')
self._top_label.set_markup(text)
self._model.update(self._update_box.get_bundles_to_update())

def __cancel_button_clicked_cb(self, button):
Expand Down
3 changes: 2 additions & 1 deletion extensions/deviceicon/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def _update_info(self):
else:
status = _STATUS_FULLY_CHARGED

self.icon.props.icon_name = get_icon_state(name, current_level, step=-5)
self.icon.props.icon_name = get_icon_state(name, current_level,
step=-5)
self.icon.props.xo_color = xo_color
self.icon.props.badge_name = badge_name

Expand Down
18 changes: 12 additions & 6 deletions extensions/deviceicon/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def _padded(child, xalign=0, yalign=0.5):
self._disconnect_item = MenuItem(_('Disconnect...'))
icon = Icon(icon_size=gtk.ICON_SIZE_MENU, icon_name='media-eject')
self._disconnect_item.set_image(icon)
self._disconnect_item.connect('activate', self.__disconnect_activate_cb)
self._disconnect_item.connect('activate',
self.__disconnect_activate_cb)
self.menu.append(self._disconnect_item)

def set_connecting(self):
Expand Down Expand Up @@ -327,7 +328,8 @@ def __toggle_state_cb(self, menuitem):

def add_alert(self, error, suggestion):
self._failed_connection = True
self._toggle_state_item.get_child().set_label(_('Try connection again'))
action = _('Try connection again')
self._toggle_state_item.get_child().set_label(action)

title = _('Error: %s') % error
self.error_title_label.set_markup('<b>%s</b>' % title)
Expand Down Expand Up @@ -448,7 +450,8 @@ def __get_active_ap_reply_cb(self, active_ap_op):
return
self._active_ap_op = active_ap_op
active_ap = self._bus.get_object(_NM_SERVICE, active_ap_op)
props = dbus.Interface(active_ap, 'org.freedesktop.DBus.Properties')
props = dbus.Interface(active_ap,
'org.freedesktop.DBus.Properties')

props.GetAll(_NM_ACCESSPOINT_IFACE, byte_arrays=True,
reply_handler=self.__get_all_ap_props_reply_cb,
Expand Down Expand Up @@ -552,7 +555,8 @@ def _update_state(self):
self._icon.props.pulsing = True
elif state == network.DEVICE_STATE_ACTIVATED:
address = self._device_props.Get(_NM_DEVICE_IFACE, 'Ip4Address')
self._palette.set_connected_with_frequency(self._frequency, address)
self._palette.set_connected_with_frequency(self._frequency,
address)
self._icon.props.pulsing = False
else:
self._icon.props.badge_name = None
Expand Down Expand Up @@ -683,7 +687,8 @@ def update_state(self, state):
def __deactivate_connection(self, palette, data=None):
obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
netmgr = dbus.Interface(obj, _NM_IFACE)
netmgr_props = dbus.Interface(netmgr, 'org.freedesktop.DBus.Properties')
netmgr_props = dbus.Interface(netmgr,
'org.freedesktop.DBus.Properties')
active_connections_o = netmgr_props.Get(_NM_IFACE,
'ActiveConnections')

Expand Down Expand Up @@ -792,7 +797,8 @@ def __connect_error_cb(self, error):
def __gsm_disconnect_cb(self, palette, data=None):
obj = self._bus.get_object(_NM_SERVICE, _NM_PATH)
netmgr = dbus.Interface(obj, _NM_IFACE)
netmgr_props = dbus.Interface(netmgr, 'org.freedesktop.DBus.Properties')
netmgr_props = dbus.Interface(netmgr,
'org.freedesktop.DBus.Properties')
active_connections_o = netmgr_props.Get(_NM_IFACE, 'ActiveConnections')

for conn_o in active_connections_o:
Expand Down
3 changes: 2 additions & 1 deletion extensions/deviceicon/speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def _update_info(self):
xo_color = XoColor('%s,%s' % (style.COLOR_WHITE.get_svg(),
style.COLOR_WHITE.get_svg()))

self.icon.props.icon_name = get_icon_state(name, current_level, step=-1)
self.icon.props.icon_name = get_icon_state(name, current_level,
step=-1)
self.icon.props.xo_color = xo_color

def __button_release_event_cb(self, widget, event):
Expand Down
12 changes: 8 additions & 4 deletions extensions/deviceicon/touchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
TOUCHPAD_MODE_CAPACITIVE = 'capacitive'
TOUCHPAD_MODE_RESISTIVE = 'resistive'
TOUCHPAD_MODES = [TOUCHPAD_MODE_CAPACITIVE, TOUCHPAD_MODE_RESISTIVE]
STATUS_TEXT = {TOUCHPAD_MODE_CAPACITIVE: _('finger'),
TOUCHPAD_MODE_RESISTIVE: _('stylus')}
STATUS_ICON = {TOUCHPAD_MODE_CAPACITIVE: 'touchpad-' + TOUCHPAD_MODE_CAPACITIVE,
TOUCHPAD_MODE_RESISTIVE: 'touchpad-' + TOUCHPAD_MODE_RESISTIVE}
STATUS_TEXT = {
TOUCHPAD_MODE_CAPACITIVE: _('finger'),
TOUCHPAD_MODE_RESISTIVE: _('stylus'),
}
STATUS_ICON = {
TOUCHPAD_MODE_CAPACITIVE: 'touchpad-' + TOUCHPAD_MODE_CAPACITIVE,
TOUCHPAD_MODE_RESISTIVE: 'touchpad-' + TOUCHPAD_MODE_RESISTIVE,
}
# NODE_PATH is used to communicate with the touchpad device.
NODE_PATH = '/sys/devices/platform/i8042/serio1/ptmode'

Expand Down
7 changes: 3 additions & 4 deletions src/jarabe/controlpanel/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,10 @@ def _get_options(self):
keywords.append(item)
options[item]['keywords'] = keywords
else:
_logger.error('There is no CLASS constant specifieds ' \
'in the view file \'%s\'.' % item)
_logger.error('There is no CLASS constant specified'
' in the view file %r.', item)
except Exception:
logging.error('Exception while loading extension:\n' + \
''.join(traceback.format_exception(*sys.exc_info())))
logging.exception('Exception while loading extension:')

return options

Expand Down
16 changes: 10 additions & 6 deletions src/jarabe/desktop/favoriteslayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def move_icon(self, icon, x, y, locked=False):
if icon not in self.box.get_children():
raise ValueError('Child not in box.')

if not(hasattr(icon, 'get_bundle_id') and hasattr(icon, 'get_version')):
if not (hasattr(icon, 'get_bundle_id') and
hasattr(icon, 'get_version')):
logging.debug('Not an activity icon %r', icon)
return

Expand Down Expand Up @@ -242,13 +243,15 @@ def _calculate_radius_and_icon_size(self, children_count):
self._spiral_mode = False
distance = style.MEDIUM_ICON_SIZE + style.DEFAULT_SPACING * \
_ICON_SPACING_FACTORS[_ICON_SIZES.index(style.MEDIUM_ICON_SIZE)]
radius = max(children_count * distance / (2 * math.pi), _MINIMUM_RADIUS)
radius = max(children_count * distance / (2 * math.pi),
_MINIMUM_RADIUS)
if radius < _MAXIMUM_RADIUS:
return radius, style.MEDIUM_ICON_SIZE

distance = style.STANDARD_ICON_SIZE + style.DEFAULT_SPACING * \
_ICON_SPACING_FACTORS[_ICON_SIZES.index(style.STANDARD_ICON_SIZE)]
radius = max(children_count * distance / (2 * math.pi), _MINIMUM_RADIUS)
radius = max(children_count * distance / (2 * math.pi),
_MINIMUM_RADIUS)
if radius < _MAXIMUM_RADIUS:
return radius, style.STANDARD_ICON_SIZE

Expand All @@ -266,8 +269,8 @@ def _calculate_radius_and_icon_size(self, children_count):
break
return radius, icon_size

def _calculate_position(self, radius, icon_size, icon_index, children_count,
sin=math.sin, cos=math.cos):
def _calculate_position(self, radius, icon_size, icon_index,
children_count, sin=math.sin, cos=math.cos):
""" Calculate an icon position on a circle or a spiral. """
width, height = self.box.get_allocation()
if self._spiral_mode:
Expand Down Expand Up @@ -408,7 +411,8 @@ def _calculate_radius_and_icon_size(self, children_count):
return None, style.STANDARD_ICON_SIZE

def adjust_index(self, i):
"""Skip floret indices which end up outside the desired bounding box."""
"""Skip floret indices which end up outside the desired bounding box.
"""
for idx in self.skipped_indices:
if i < idx:
break
Expand Down
13 changes: 8 additions & 5 deletions src/jarabe/desktop/favoritesview.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def do_size_allocate(self, allocation):
height = allocation.height

min_w_, my_icon_width = self._my_icon.get_width_request()
min_h_, my_icon_height = self._my_icon.get_height_request(my_icon_width)
min_h_, my_icon_height = self._my_icon.get_height_request(
my_icon_width)
x = (width - my_icon_width) / 2
y = (height - my_icon_height - style.GRID_CELL_SIZE) / 2
self._layout.move_icon(self._my_icon, x, y, locked=True)
Expand All @@ -193,7 +194,8 @@ def do_size_allocate(self, allocation):
# TODO: Dnd methods. This should be merged somehow inside hippo-canvas.
def __button_press_event_cb(self, widget, event):
if event.button == 1 and event.type == gtk.gdk.BUTTON_PRESS:
self._last_clicked_icon = self._get_icon_at_coords(event.x, event.y)
self._last_clicked_icon = self._get_icon_at_coords(event.x,
event.y)
if self._last_clicked_icon is not None:
self._pressed_button = event.button
self._press_start_x = event.x
Expand Down Expand Up @@ -398,8 +400,8 @@ def _get_last_activity_async(self, bundle_id, properties):
error_handler=self.__get_last_activity_error_handler_cb)

def __get_last_activity_reply_handler_cb(self, entries, total_count):
# If there's a problem with the DS index, we may get entries not related
# to this activity.
# If there's a problem with the DS index, we may get entries not
# related to this activity.
checked_entries = []
for entry in entries:
if entry['activity'] == self.bundle_id:
Expand Down Expand Up @@ -624,7 +626,8 @@ def create_palette(self):
backup_url = client.get_string('/desktop/sugar/backup_url')
if not backup_url:
self._register_menu = MenuItem(_('Register'), 'media-record')
self._register_menu.connect('activate', self.__register_activate_cb)
self._register_menu.connect('activate',
self.__register_activate_cb)
palette.menu.append(self._register_menu)
self._register_menu.show()

Expand Down
3 changes: 2 additions & 1 deletion src/jarabe/desktop/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def _detect_collisions(self, child):
for c in self._children:
intersection = child_rect.intersect(self._child_rects[c])
if c != child and intersection.width > 0:
if c not in self._locked_children and c not in self._collisions:
if (c not in self._locked_children and
c not in self._collisions):
collision_found = True
self._collisions.append(c)

Expand Down
2 changes: 1 addition & 1 deletion src/jarabe/desktop/homebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __entry_changed_cb(self, entry):
if self._autosearch_timer:
gobject.source_remove(self._autosearch_timer)
self._autosearch_timer = gobject.timeout_add(_AUTOSEARCH_TIMEOUT,
self.__autosearch_timer_cb)
self.__autosearch_timer_cb)

def __autosearch_timer_cb(self):
self._autosearch_timer = None
Expand Down
5 changes: 3 additions & 2 deletions src/jarabe/desktop/meshbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ def __init__(self, device):
self.device = device

wireless = dbus.Interface(device, _NM_WIRELESS_IFACE)
wireless.GetAccessPoints(reply_handler=self._get_access_points_reply_cb,
error_handler=self._get_access_points_error_cb)
wireless.GetAccessPoints(
reply_handler=self._get_access_points_reply_cb,
error_handler=self._get_access_points_error_cb)

self._bus.add_signal_receiver(self.__access_point_added_cb,
signal_name='AccessPointAdded',
Expand Down
3 changes: 2 additions & 1 deletion src/jarabe/desktop/networkviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ def set_filter(self, query):

def create_keydialog(self, settings, response):
keydialog.create(self._name, self._flags, self._wpa_flags,
self._rsn_flags, self._device_caps, settings, response)
self._rsn_flags, self._device_caps, settings,
response)

def update_strength(self):
if self._active_ap is not None:
Expand Down
3 changes: 2 additions & 1 deletion src/jarabe/frame/activitiestray.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def __init__(self):

self._home_model = shell.get_model()
self._home_model.connect('activity-added', self.__activity_added_cb)
self._home_model.connect('activity-removed', self.__activity_removed_cb)
self._home_model.connect('activity-removed',
self.__activity_removed_cb)
self._home_model.connect('active-activity-changed',
self.__activity_changed_cb)
self._home_model.connect('tabbing-activity-changed',
Expand Down
2 changes: 1 addition & 1 deletion src/jarabe/frame/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def add_object_format(self, object_id, format_type, data, on_disk):
+ ' with path at ' + new_uri)
else:
cb_object.add_format(Format(format_type, data, on_disk))
logging.debug('Added in-memory format of type ' + format_type + '.')
logging.debug('Added in-memory format of type %s.', format_type)

self.emit('object-state-changed', cb_object)

Expand Down
7 changes: 4 additions & 3 deletions src/jarabe/frame/clipboardicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ def get_object_id(self):

def _drag_data_get_cb(self, widget, context, selection, target_type,
event_time):
logging.debug('_drag_data_get_cb: requested target ' + selection.target)
logging.debug('_drag_data_get_cb: requested target %s',
selection.target)
data = self._cb_object.get_formats()[selection.target].get_data()
selection.set(selection.target, 8, data)

def _put_in_clipboard(self):
logging.debug('ClipboardIcon._put_in_clipboard')

if self._cb_object.get_percent() < 100:
raise ValueError('Object is not complete,' \
' cannot be put into the clipboard.')
raise ValueError('Object is not complete, cannot be put into the'
' clipboard.')

targets = self._get_targets()
if targets:
Expand Down
Loading

0 comments on commit fdb33c3

Please sign in to comment.