[meld] ui.findbar: PEP8
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] ui.findbar: PEP8
- Date: Fri, 27 Sep 2013 22:06:42 +0000 (UTC)
commit a707bc1ed1c3fb3e5f7c9c78f4411f3913322f4b
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Sep 7 16:52:46 2013 +1000
ui.findbar: PEP8
meld/ui/findbar.py | 53 +++++++++++++++++++++++++++++----------------------
1 files changed, 30 insertions(+), 23 deletions(-)
---
diff --git a/meld/ui/findbar.py b/meld/ui/findbar.py
index 8a2e900..322bee1 100644
--- a/meld/ui/findbar.py
+++ b/meld/ui/findbar.py
@@ -25,6 +25,7 @@ from . import gnomeglade
from gettext import gettext as _
+
class FindBar(gnomeglade.Component):
def __init__(self, parent):
gnomeglade.Component.__init__(self, paths.ui_dir("findbar.ui"),
@@ -97,28 +98,30 @@ class FindBar(gnomeglade.Component):
oldsel = buf.get_selection_bounds()
match = self._find_text(0)
newsel = buf.get_selection_bounds()
- # only replace if there is a match at the cursor and it was already selected
- if match and oldsel and oldsel[0].equal(newsel[0]) and oldsel[1].equal(newsel[1]):
+ # Only replace if there is an already-selected match at the cursor
+ if (match and oldsel and oldsel[0].equal(newsel[0]) and
+ oldsel[1].equal(newsel[1])):
buf.begin_user_action()
- buf.delete_selection(False,False)
- buf.insert_at_cursor( self.replace_entry.get_text() )
- self._find_text( 0 )
+ buf.delete_selection(False, False)
+ buf.insert_at_cursor(self.replace_entry.get_text())
+ self._find_text(0)
buf.end_user_action()
def on_replace_all_button_clicked(self, entry):
buf = self.textview.get_buffer()
- saved_insert = buf.create_mark(None, buf.get_iter_at_mark(buf.get_insert()), True)
+ saved_insert = buf.create_mark(
+ None, buf.get_iter_at_mark(buf.get_insert()), True)
buf.begin_user_action()
while self._find_text(0):
- buf.delete_selection(False,False)
- buf.insert_at_cursor( self.replace_entry.get_text() )
+ buf.delete_selection(False, False)
+ buf.insert_at_cursor(self.replace_entry.get_text())
buf.end_user_action()
if not saved_insert.get_deleted():
- buf.place_cursor( buf.get_iter_at_mark(saved_insert) )
+ buf.place_cursor(buf.get_iter_at_mark(saved_insert))
self.textview.scroll_to_mark(buf.get_insert(), 0.25)
def on_find_entry_changed(self, entry):
- entry.modify_base( gtk.STATE_NORMAL, self.orig_base_color )
+ entry.modify_base(gtk.STATE_NORMAL, self.orig_base_color)
#
# find/replace buffer
@@ -129,23 +132,26 @@ class FindBar(gnomeglade.Component):
regex = self.regex.get_active()
assert self.textview
buf = self.textview.get_buffer()
- insert = buf.get_iter_at_mark( buf.get_insert() )
+ insert = buf.get_iter_at_mark(buf.get_insert())
tofind_utf8 = self.find_entry.get_text()
- tofind = tofind_utf8.decode("utf-8") # tofind is utf-8 encoded
+ tofind = tofind_utf8.decode("utf-8")
start, end = buf.get_bounds()
- text = buf.get_text(start, end, False).decode("utf-8") # as is buffer
+ text = buf.get_text(start, end, False).decode("utf-8")
if not regex:
tofind = re.escape(tofind)
if whole_word:
tofind = r'\b' + tofind + r'\b'
try:
- pattern = re.compile( tofind, (match_case and re.M or (re.M|re.I)) )
+ flags = re.M if match_case else re.M | re.I
+ pattern = re.compile(tofind, flags)
except re.error as e:
- misc.run_dialog( _("Regular expression error\n'%s'") % e, self, messagetype=gtk.MESSAGE_ERROR)
+ misc.run_dialog(_("Regular expression error\n'%s'") % e, self,
+ messagetype=gtk.MESSAGE_ERROR)
else:
self.wrap_box.set_visible(False)
- if backwards == False:
- match = pattern.search(text, insert.get_offset() + start_offset)
+ if not backwards:
+ match = pattern.search(text,
+ insert.get_offset() + start_offset)
if match is None and wrap:
self.wrap_box.set_visible(True)
match = pattern.search(text, 0)
@@ -158,13 +164,14 @@ class FindBar(gnomeglade.Component):
for m in pattern.finditer(text, insert.get_offset()):
match = m
if match:
- it = buf.get_iter_at_offset( match.start() )
- buf.place_cursor( it )
- it.forward_chars( match.end() - match.start() )
- buf.move_mark( buf.get_selection_bound(), it )
+ it = buf.get_iter_at_offset(match.start())
+ buf.place_cursor(it)
+ it.forward_chars(match.end() - match.start())
+ buf.move_mark(buf.get_selection_bound(), it)
self.textview.scroll_to_mark(buf.get_insert(), 0.25)
return True
else:
- buf.place_cursor( buf.get_iter_at_mark(buf.get_insert()) )
- self.find_entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffdddd"))
+ buf.place_cursor(buf.get_iter_at_mark(buf.get_insert()))
+ self.find_entry.modify_base(gtk.STATE_NORMAL,
+ gtk.gdk.color_parse("#ffdddd"))
self.wrap_box.set_visible(False)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]