From 250ef794ed67960da1c3f8231ebf3b19c4f4388c Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Fri, 08 Nov 2013 13:50:53 +0000 Subject: Pep8 & pyflakes fixes Signed-off-by: Gonzalo Odiard --- diff --git a/AbiWordActivity.py b/AbiWordActivity.py index 293de48..546e267 100644 --- a/AbiWordActivity.py +++ b/AbiWordActivity.py @@ -235,7 +235,7 @@ class AbiWordActivity(activity.Activity): if self._new_instance: self.abiword_canvas.select_all() logging.error('Setting default font to %s %d in new documents', - self._default_font_face, self._default_font_size) + self._default_font_face, self._default_font_size) self.abiword_canvas.set_font_name(self._default_font_face) self.abiword_canvas.set_font_size(str(self._default_font_size)) self.abiword_canvas.moveto_bod() diff --git a/gridcreate.py b/gridcreate.py index 9115566..c240934 100644 --- a/gridcreate.py +++ b/gridcreate.py @@ -4,12 +4,12 @@ from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GObject + class GridCreateWidget(Gtk.DrawingArea): __gsignals__ = { 'create-table': ( - GObject.SignalFlags.RUN_FIRST, None, [int, int]), - } + GObject.SignalFlags.RUN_FIRST, None, [int, int]), } def __init__(self): super(GridCreateWidget, self).__init__() @@ -29,15 +29,16 @@ class GridCreateWidget(Gtk.DrawingArea): self.connect('event', self.__event_cb) def __event_cb(self, widget, event): - if event.type in (Gdk.EventType.TOUCH_BEGIN, + if event.type in ( + Gdk.EventType.TOUCH_BEGIN, Gdk.EventType.TOUCH_CANCEL, Gdk.EventType.TOUCH_END, Gdk.EventType.TOUCH_UPDATE, Gdk.EventType.BUTTON_PRESS, Gdk.EventType.BUTTON_RELEASE, Gdk.EventType.MOTION_NOTIFY): x = event.get_coords()[1] y = event.get_coords()[2] - seq = str(event.touch.sequence) - if event.type in (Gdk.EventType.TOUCH_BEGIN, + if event.type in ( + Gdk.EventType.TOUCH_BEGIN, Gdk.EventType.TOUCH_UPDATE, Gdk.EventType.BUTTON_PRESS, Gdk.EventType.MOTION_NOTIFY): # update rows and cols @@ -74,7 +75,7 @@ class GridCreateWidget(Gtk.DrawingArea): # draw grid cr.set_source_rgb(1.0, 1.0, 1.0) self._draw_grid(cr, self._min_rows, self._min_col, self._width, - self._height) + self._height) cr.set_source_rgb(0.0, 0.0, 0.0) self._draw_grid(cr, self._rows, self._columns, width, height) diff --git a/speech_dispatcher.py b/speech_dispatcher.py index 99d35d9..ea3a7db 100644 --- a/speech_dispatcher.py +++ b/speech_dispatcher.py @@ -77,14 +77,14 @@ class EspeakThread(threading.Thread): try: self.client = speechd.SSIPClient('readetexts') self.client._conn.send_command('SET', speechd.Scope.SELF, - 'SSML_MODE', "ON") + 'SSML_MODE', "ON") if speech.voice: self.client.set_language(speech.voice[1]) self.client.set_rate(speech.rate) self.client.set_pitch(speech.pitch) self.client.speak(self.words, self.next_word_cb, - (speechd.CallbackType.INDEX_MARK, - speechd.CallbackType.END)) + (speechd.CallbackType.INDEX_MARK, + speechd.CallbackType.END)) global done done = False while not done: diff --git a/speech_gst.py b/speech_gst.py index 9b026e4..2cf41fd 100644 --- a/speech_gst.py +++ b/speech_gst.py @@ -36,7 +36,7 @@ def get_all_voices(): def _message_cb(bus, message, pipe): if message.type == Gst.MessageType.EOS: pipe.set_state(Gst.State.NULL) - if speech.end_text_cb != None: + if speech.end_text_cb is not None: speech.end_text_cb() if message.type == Gst.MessageType.ERROR: pipe.set_state(Gst.State.NULL) diff --git a/speechtoolbar.py b/speechtoolbar.py index 268879a..91ec21f 100644 --- a/speechtoolbar.py +++ b/speechtoolbar.py @@ -53,7 +53,8 @@ class SpeechToolbar(Gtk.Toolbar): # Play button self.play_btn = ToggleToolButton('media-playback-start') self.play_btn.show() - self.play_toggled_handler = self.play_btn.connect('toggled', self.play_cb) + self.play_toggled_handler = self.play_btn.connect( + 'toggled', self.play_cb) self.insert(self.play_btn, -1) self.play_btn.set_tooltip(_('Play / Pause')) @@ -106,16 +107,17 @@ class SpeechToolbar(Gtk.Toolbar): logging.error('Default voice %s', speech.voice) self._cnf_client.add_dir('/desktop/sugar/speech', - GConf.ClientPreloadType.PRELOAD_NONE) + GConf.ClientPreloadType.PRELOAD_NONE) speech.pitch = self._cnf_client.get_int('/desktop/sugar/speech/pitch') speech.rate = self._cnf_client.get_int('/desktop/sugar/speech/rate') - self._cnf_client.notify_add('/desktop/sugar/speech/pitch', \ - self.__conf_changed_cb, None) - self._cnf_client.notify_add('/desktop/sugar/speech/rate', \ - self.__conf_changed_cb, None) + self._cnf_client.notify_add('/desktop/sugar/speech/pitch', + self.__conf_changed_cb, None) + self._cnf_client.notify_add('/desktop/sugar/speech/rate', + self.__conf_changed_cb, None) def get_default_voice(self): - """Try to figure out the default voice, from the current locale ($LANG) + """Try to figure out the default voice, from the current locale + ($LANG) Fall back to espeak's voice called Default.""" voices = speech.get_all_voices() @@ -130,9 +132,9 @@ class SpeechToolbar(Gtk.Toolbar): language_location = 'es_la' best = voices.get(language_location) or voices.get(language) \ - or 'default' + or 'default' logging.debug('Best voice for LANG %s seems to be %s', - locale, best) + locale, best) return [best, language, variant] def __conf_changed_cb(self, client, connection_id, entry, args): diff --git a/toolbar.py b/toolbar.py index 3b18f13..591cccf 100644 --- a/toolbar.py +++ b/toolbar.py @@ -75,23 +75,23 @@ class EditToolbar(Gtk.Toolbar): undo = UndoButton(sensitive=False) undo.connect('clicked', lambda button: pc.abiword_canvas.undo()) pc.abiword_canvas.connect("can-undo", lambda abi, can_undo: - undo.set_sensitive(can_undo)) + undo.set_sensitive(can_undo)) self.insert(undo, -1) undo.show() redo = RedoButton(sensitive=False) redo.connect('clicked', lambda button: pc.abiword_canvas.redo()) pc.abiword_canvas.connect("can-redo", lambda abi, can_redo: - redo.set_sensitive(can_redo)) + redo.set_sensitive(can_redo)) self.insert(redo, -1) redo.show() pc.abiword_canvas.connect('text-selected', lambda abi, b: - copy.set_sensitive(True)) + copy.set_sensitive(True)) pc.abiword_canvas.connect('image-selected', lambda abi, b: - copy.set_sensitive(True)) + copy.set_sensitive(True)) pc.abiword_canvas.connect('selection-cleared', lambda abi, b: - copy.set_sensitive(False)) + copy.set_sensitive(False)) separator = Gtk.SeparatorToolItem() self.insert(separator, -1) @@ -138,7 +138,6 @@ class EditToolbar(Gtk.Toolbar): if clipboard.wait_is_image_available(): pixbuf_sel = clipboard.wait_for_image() - size = int(pixbuf_sel.get_width()), int(pixbuf_sel.get_height()) activity = self._abiword_canvas.get_toplevel() temp_path = os.path.join(activity.get_activity_root(), 'instance') if not os.path.exists(temp_path): @@ -155,7 +154,7 @@ class EditToolbar(Gtk.Toolbar): elif clipboard.wait_is_uris_available(): selection = clipboard.wait_for_uris() - if selection != None: + if selection is not None: for uri in selection: self._abiword_canvas.insert_image(urlparse(uri).path, False) @@ -172,7 +171,7 @@ class EditToolbar(Gtk.Toolbar): def _search_entry_changed_cb(self, entry): logger.debug('_search_entry_changed_cb search for \'%s\'', - self._search_entry.props.text) + self._search_entry.props.text) if not self._search_entry.props.text: self._search_entry.activate() @@ -235,26 +234,26 @@ class InsertToolbar(Gtk.Toolbar): self._table_rows_after = ToolButton('row-insert') self._table_rows_after.set_tooltip(_('Insert Row')) - self._table_rows_after_id = self._table_rows_after.connect( \ - 'clicked', self._table_rows_after_cb) + self._table_rows_after_id = self._table_rows_after.connect( + 'clicked', self._table_rows_after_cb) self.insert(self._table_rows_after, -1) self._table_delete_rows = ToolButton('row-remove') self._table_delete_rows.set_tooltip(_('Delete Row')) - self._table_delete_rows_id = self._table_delete_rows.connect( \ - 'clicked', self._table_delete_rows_cb) + self._table_delete_rows_id = self._table_delete_rows.connect( + 'clicked', self._table_delete_rows_cb) self.insert(self._table_delete_rows, -1) self._table_cols_after = ToolButton('column-insert') self._table_cols_after.set_tooltip(_('Insert Column')) - self._table_cols_after_id = self._table_cols_after.connect( \ - 'clicked', self._table_cols_after_cb) + self._table_cols_after_id = self._table_cols_after.connect( + 'clicked', self._table_cols_after_cb) self.insert(self._table_cols_after, -1) self._table_delete_cols = ToolButton('column-remove') self._table_delete_cols.set_tooltip(_('Delete Column')) - self._table_delete_cols_id = self._table_delete_cols.connect( \ - 'clicked', self._table_delete_cols_cb) + self._table_delete_cols_id = self._table_delete_cols.connect( + 'clicked', self._table_delete_cols_cb) self.insert(self._table_delete_cols, -1) self.show_all() @@ -298,14 +297,15 @@ class ViewToolbar(Gtk.Toolbar): self._zoom_out = ToolButton('zoom-out') self._zoom_out.set_tooltip(_('Zoom Out')) - self._zoom_out_id = self._zoom_out.connect('clicked', - self._zoom_out_cb) + self._zoom_out_id = self._zoom_out.connect( + 'clicked', self._zoom_out_cb) self.insert(self._zoom_out, -1) self._zoom_out.show() self._zoom_in = ToolButton('zoom-in') self._zoom_in.set_tooltip(_('Zoom In')) - self._zoom_in_id = self._zoom_in.connect('clicked', self._zoom_in_cb) + self._zoom_in_id = self._zoom_in.connect('clicked', + self._zoom_in_cb) self.insert(self._zoom_in, -1) self._zoom_in.show() @@ -424,10 +424,10 @@ class TextToolbar(Gtk.Toolbar): self.font_name_combo = FontComboBox() self.font_name_combo.set_font_name('Sans') - self._fonts_changed_id = self.font_name_combo.connect('changed', - self._font_changed_cb, abiword_canvas) + self._fonts_changed_id = self.font_name_combo.connect( + 'changed', self._font_changed_cb, abiword_canvas) self._abi_handler = abiword_canvas.connect('font-family', - self._font_family_cb) + self._font_family_cb) self.insert(ToolComboBox(self.font_name_combo), -1) self.font_size = FontSize() @@ -441,37 +441,40 @@ class TextToolbar(Gtk.Toolbar): bold.set_tooltip(_('Bold')) bold.props.accelerator = 'B' bold_id = bold.connect('clicked', lambda sender: - abiword_canvas.toggle_bold()) + abiword_canvas.toggle_bold()) abiword_canvas.connect('bold', lambda abi, b: - self._setToggleButtonState(bold, b, bold_id)) + self._setToggleButtonState(bold, b, bold_id)) self.insert(bold, -1) italic = ToggleToolButton('format-text-italic') italic.set_tooltip(_('Italic')) italic.props.accelerator = 'I' italic_id = italic.connect('clicked', lambda sender: - abiword_canvas.toggle_italic()) + abiword_canvas.toggle_italic()) abiword_canvas.connect('italic', lambda abi, b: - self._setToggleButtonState(italic, b, italic_id)) + self._setToggleButtonState(italic, b, + italic_id)) self.insert(italic, -1) underline = ToggleToolButton('format-text-underline') underline.set_tooltip(_('Underline')) underline.props.accelerator = 'U' underline_id = underline.connect('clicked', lambda sender: - abiword_canvas.toggle_underline()) + abiword_canvas.toggle_underline()) abiword_canvas.connect('underline', lambda abi, b: - self._setToggleButtonState(underline, b, underline_id)) + self._setToggleButtonState(underline, b, + underline_id)) self.insert(underline, -1) color = ColorToolButton() color.connect('notify::color', self._text_color_cb, - abiword_canvas) + abiword_canvas) tool_item = Gtk.ToolItem() tool_item.add(color) self.insert(tool_item, -1) - abiword_canvas.connect('color', lambda abi, r, g, b: - color.set_color(Gdk.Color(r * 256, g * 256, b * 256))) + abiword_canvas.connect( + 'color', lambda abi, r, g, b: + color.set_color(Gdk.Color(r * 256, g * 256, b * 256))) # MAGIC NUMBER WARNING: Secondary toolbars are not a standard height? self.set_size_request(-1, style.GRID_CELL_SIZE) @@ -479,7 +482,7 @@ class TextToolbar(Gtk.Toolbar): def append_align(icon_name, tooltip, do_abi_cb, style_name, button, menu_box): menu_item = AbiMenuItem(abiword_canvas, style_name, do_abi_cb, - icon_name, tooltip, button) + icon_name, tooltip, button) menu_box.append_item(menu_item) menu_item.show() @@ -493,20 +496,20 @@ class TextToolbar(Gtk.Toolbar): menu_box.show() append_align('format-justify-left', _('Left justify'), - abiword_canvas.align_left, 'left-align', self._aligment_btn, - menu_box) + abiword_canvas.align_left, 'left-align', + self._aligment_btn, menu_box) append_align('format-justify-center', _('Center justify'), - abiword_canvas.align_center, 'center-align', self._aligment_btn, - menu_box) + abiword_canvas.align_center, 'center-align', + self._aligment_btn, menu_box) append_align('format-justify-right', _('Right justify'), - abiword_canvas.align_right, 'right-align', self._aligment_btn, - menu_box) + abiword_canvas.align_right, 'right-align', + self._aligment_btn, menu_box) append_align('format-justify-fill', _('Fill justify'), - abiword_canvas.align_justify, 'justify-align', self._aligment_btn, - menu_box) + abiword_canvas.align_justify, 'justify-align', + self._aligment_btn, menu_box) self.insert(self._aligment_btn, -1) @@ -545,8 +548,8 @@ class TextToolbar(Gtk.Toolbar): def _text_color_cb(self, button, pspec, abiword_canvas): newcolor = button.get_color() abiword_canvas.set_text_color(int(newcolor.red / 256.0), - int(newcolor.green / 256.0), - int(newcolor.blue / 256.0)) + int(newcolor.green / 256.0), + int(newcolor.blue / 256.0)) class ParagraphToolbar(Gtk.Toolbar): @@ -564,46 +567,43 @@ class ParagraphToolbar(Gtk.Toolbar): group = None - group = append_style('list-none', _('Normal'), - lambda: - abi.set_style('Normal'), - lambda abi, style: - style not in ['Heading 1', - 'Heading 2', - 'Heading 3', - 'Heading 4', - 'Block Text', - 'Plain Text']) + group = append_style( + 'list-none', _('Normal'), + lambda: abi.set_style('Normal'), + lambda abi, style: style not in [ + 'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4', + 'Block Text', 'Plain Text']) append_style('paragraph-h1', _('Heading 1'), - lambda: abi.set_style('Heading 1'), - lambda abi, style: style == 'Heading 1') + lambda: abi.set_style('Heading 1'), + lambda abi, style: style == 'Heading 1') append_style('paragraph-h2', _('Heading 2'), - lambda: abi.set_style('Heading 2'), - lambda abi, style: style == 'Heading 2') + lambda: abi.set_style('Heading 2'), + lambda abi, style: style == 'Heading 2') append_style('paragraph-h3', _('Heading 3'), - lambda: abi.set_style('Heading 3'), - lambda abi, style: style == 'Heading 3') + lambda: abi.set_style('Heading 3'), + lambda abi, style: style == 'Heading 3') append_style('paragraph-h4', _('Heading 4'), - lambda: abi.set_style('Heading 4'), - lambda abi, style: style == 'Heading 4') + lambda: abi.set_style('Heading 4'), + lambda abi, style: style == 'Heading 4') append_style('paragraph-blocktext', _('Block Text'), - lambda: abi.set_style('Block Text'), - lambda abi, style: style == 'Block Text') + lambda: abi.set_style('Block Text'), + lambda abi, style: style == 'Block Text') append_style('paragraph-plaintext', _('Plain Text'), - lambda: abi.set_style('Plain Text'), - lambda abi, style: style == 'Plain Text') + lambda: abi.set_style('Plain Text'), + lambda abi, style: style == 'Plain Text') self.insert(Gtk.SeparatorToolItem(), -1) def append_list(icon_name, tooltip, do_abi_cb, on_abi_cb, button, menu_box, button_icon=None): - menu_item = AbiMenuItem(abi, 'style-name', do_abi_cb, + menu_item = AbiMenuItem( + abi, 'style-name', do_abi_cb, icon_name, tooltip, button, on_abi_cb, button_icon) menu_box.append_item(menu_item) menu_item.show() diff --git a/widgets.py b/widgets.py index 2579007..019a233 100644 --- a/widgets.py +++ b/widgets.py @@ -37,9 +37,9 @@ class AbiButton(RadioToolButton): RadioToolButton.__init__(self, **kwargs) self._abi_handler = abi.connect(abi_signal, self.__abi_cb, - abi_signal, on_abi_cb) + abi_signal, on_abi_cb) self._toggled_handler = self.connect('toggled', self.__toggled_cb, - abi, do_abi_cb) + abi, do_abi_cb) def __toggled_cb(self, button, abi, do_abi_cb): if not button.props.active: @@ -68,7 +68,7 @@ class AbiButton(RadioToolButton): class AbiMenuItem(PaletteMenuItem): def __init__(self, abi, abi_signal, do_abi_cb, icon_name, label, - button, on_abi_cb=None, button_icon_name=None): + button, on_abi_cb=None, button_icon_name=None): self._icon_name = icon_name # _button_icon_name is used only in the first case of # the list menu @@ -77,9 +77,8 @@ class AbiMenuItem(PaletteMenuItem): PaletteMenuItem.__init__(self, icon_name=icon_name, text_label=label) self._abi_handler = abi.connect(abi_signal, self.__abi_cb, - abi_signal, on_abi_cb) - self.connect('activate', self.__activated_cb, - abi, do_abi_cb) + abi_signal, on_abi_cb) + self.connect('activate', self.__activated_cb, abi, do_abi_cb) def __activated_cb(self, button, abi, do_abi_cb): @@ -117,26 +116,26 @@ class ExportButtonFactory(): _EXPORT_FORMATS = [{'mime_type': 'application/rtf', 'title': _('Rich Text (RTF)'), - 'icon':'save-as-rtf', + 'icon': 'save-as-rtf', 'jpostfix': _('RTF'), 'exp_props': ''}, {'mime_type': 'text/html', 'title': _('Hypertext (HTML)'), - 'icon':'save-as-html', + 'icon': 'save-as-html', 'jpostfix': _('HTML'), - 'exp_props': 'html4:yes; declare-xml:no; ' \ - 'embed-css:yes; embed-images:yes;'}, + 'exp_props': 'html4:yes; declare-xml:no; ' + 'embed-css:yes; embed-images:yes;'}, {'mime_type': 'text/plain', 'title': _('Plain Text (TXT)'), - 'icon':'save-as-txt', + 'icon': 'save-as-txt', 'jpostfix': _('TXT'), 'exp_props': ''}, {'mime_type': 'application/pdf', 'title': _('Portable Document Format (PDF)'), - 'icon':'save-as-pdf', + 'icon': 'save-as-pdf', 'jpostfix': _('PDF'), 'exp_props': ''}] @@ -163,12 +162,12 @@ class ExportButtonFactory(): fileObject = datastore.create() act_meta = activity.metadata fileObject.metadata['title'] = \ - act_meta['title'] + ' (' + format['jpostfix'] + ')' + act_meta['title'] + ' (' + format['jpostfix'] + ')' fileObject.metadata['title_set_by_user'] = \ - act_meta['title_set_by_user'] + act_meta['title_set_by_user'] fileObject.metadata['mime_type'] = format['mime_type'] fileObject.metadata['fulltext'] = \ - abi.get_content('text/plain', None)[:3000] + abi.get_content('text/plain', None)[:3000] fileObject.metadata['icon-color'] = act_meta['icon-color'] @@ -187,9 +186,9 @@ class ExportButtonFactory(): # write out the document contents in the requested format fileObject.file_path = os.path.join(activity.get_activity_root(), - 'instance', '%i' % time.time()) + 'instance', '%i' % time.time()) abi.save('file://' + fileObject.file_path, - format['mime_type'], exp_props) + format['mime_type'], exp_props) # store the journal item datastore.write(fileObject, transfer_ownership=True) @@ -239,10 +238,10 @@ class DocumentView(Abi.Widget): allocation.x = 0 allocation.y = 0 allocation.x, allocation.y = \ - widget.get_window().get_root_coords(allocation.x, allocation.y) + widget.get_window().get_root_coords(allocation.x, allocation.y) if clear.y > allocation.y + allocation.height or \ - clear.y + clear.height < allocation.y: + clear.y + clear.height < allocation.y: return False self.dy = allocation.y + allocation.height - clear.y -- cgit v0.9.1