jenkins-bot has submitted this change and it was merged.
Change subject: [PEP8] changes
......................................................................
[PEP8] changes
Change-Id: I5e45c6f948748dde321cb26725fecc68dd0a875f
---
M generate_user_files.py
M gui.py
2 files changed, 67 insertions(+), 47 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/generate_user_files.py b/generate_user_files.py
index d709614..8a5263d 100644
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -1,15 +1,25 @@
# -*- coding: utf-8 -*-
""" Script to create user files (user-config.py, user-fixes.py)
"""
+#
+# (C) Pywikibot team, 2008-2013
+#
+# Distributed under the terms of the MIT license
+#
__version__ = '$Id$'
+#
-import codecs, os, re, sys
+import codecs
+import os
+import re
+import sys
console_encoding = sys.stdout.encoding
if console_encoding is None or sys.platform == 'cygwin':
console_encoding = "iso-8859-1"
-def listchoice(clist = [], message = None, default = None):
+
+def listchoice(clist=[], message=None, default=None):
if not message:
message = "Select"
@@ -24,11 +34,10 @@
while True:
choice = raw_input(message)
-
if choice == '' and default:
return default
try:
- choice=int(choice)
+ choice = int(choice)
except ValueError:
pass
if isinstance(choice, basestring):
@@ -43,45 +52,48 @@
print("Invalid response")
return response
+
def file_exists(filename):
if os.path.exists(filename):
print("'%s' already exists." % filename)
return True
return False
+
def create_user_config(base_dir):
_fnc = os.path.join(base_dir, "user-config.py")
if not file_exists(_fnc):
known_families = re.findall(r'(.+)_family.py\b',
- '\n'.join(os.listdir(
- os.path.join(base_dir,
- "families"))))
+ '\n'.join(os.listdir(
+ os.path.join(base_dir, "families"))))
fam = listchoice(known_families,
"Select family of sites we are working on, " \
"just enter the number not name",
default='wikipedia')
- codesds=codecs.open("families/%s_family.py" % fam,
"r","utf-8").read()
- rre=re.compile("self\.languages\_by\_size *\= *(.+?)\]",re.DOTALL)
- known_langs=[]
+ codesds = codecs.open("families/%s_family.py"
+ % fam, "r", "utf-8").read()
+ rre = re.compile("self\.languages\_by\_size *\= *(.+?)\]", re.DOTALL)
+ known_langs = []
if not rre.findall(codesds):
- rre=re.compile("self\.langs *\= *(.+?)\}",re.DOTALL)
+ rre = re.compile("self\.langs *\= *(.+?)\}", re.DOTALL)
if rre.findall(codesds):
import ast
-
known_langs=ast.literal_eval(rre.findall(codesds)[0]+u"}").keys()
+ known_langs = ast.literal_eval(
+ rre.findall(codesds)[0] + u"}").keys()
else:
- known_langs=eval(rre.findall(codesds)[0]+u"]")
+ known_langs = eval(rre.findall(codesds)[0] + u"]")
print "This is the list of known language(s):"
print " ".join(sorted(known_langs))
mylang = raw_input(
-"The language code of the site we're working on (default: 'en'): ")
or 'en'
+ "The language code of the site we're working on (default:
'en'): "
+ ) or 'en'
username = raw_input("Username (%s %s): "
% (mylang, fam)) or 'UnnamedBot'
username = unicode(username, console_encoding)
while True:
choice = raw_input(
-"Which variant of user_config.py:\n"\
-"[S]mall or [E]xtended (with further information)? "
- ).upper()
+ "Which variant of user_config.py:\n"
+ "[S]mall or [E]xtended (with further information)? ").upper()
if choice in "SE":
break
@@ -135,6 +147,7 @@
f.close()
print("'%s' written." % _fnc)
+
def create_user_fixes(base_dir):
_fnf = os.path.join(base_dir, "user-fixes.py")
if not file_exists(_fnf):
@@ -159,6 +172,7 @@
f.close()
print("'%s' written." % _fnf)
+
if __name__ == "__main__":
print("1: Create user_config.py file (required)")
print("2: Create user_fixes.py file (optional, for advanced usage)")
diff --git a/gui.py b/gui.py
index 7d52883..8d3c757 100644
--- a/gui.py
+++ b/gui.py
@@ -7,11 +7,12 @@
# (C) Rob W.W. Hooft, 2003
# (C) Daniel Herding, 2004
# Wikiwichtel
-# (C) the PyWikipediabot team, 2008-2010
+# (C) pywikibot team, 2008-2013
#
# Distributed under the terms of the MIT license.
#
-__version__='$Id$'
+__version__ = '$Id$'
+#
from Tkinter import *
from ScrolledText import ScrolledText
@@ -31,28 +32,31 @@
"""
def __init__(self, master=None, **kwargs):
# get default settings from user's IDLE configuration
- currentTheme=idleConf.CurrentTheme()
+ currentTheme = idleConf.CurrentTheme()
textcf = dict(padx=5, wrap='word', undo='True',
foreground=idleConf.GetHighlight(currentTheme,
- 'normal', fgBg='fg'),
+ 'normal',
fgBg='fg'),
background=idleConf.GetHighlight(currentTheme,
- 'normal', fgBg='bg'),
+ 'normal',
fgBg='bg'),
highlightcolor=idleConf.GetHighlight(currentTheme,
- 'hilite', fgBg='fg'),
+ 'hilite',
fgBg='fg'),
highlightbackground=idleConf.GetHighlight(currentTheme,
- 'hilite', fgBg='bg'),
+ 'hilite',
+ fgBg='bg'),
insertbackground=idleConf.GetHighlight(currentTheme,
- 'cursor', fgBg='fg'),
+ 'cursor',
+ fgBg='fg'),
width=idleConf.GetOption('main', 'EditorWindow',
'width'),
height=idleConf.GetOption('main', 'EditorWindow',
'height')
- )
+ )
fontWeight = 'normal'
if idleConf.GetOption('main', 'EditorWindow',
'font-bold', type='bool'):
- fontWeight='bold'
- textcf['font']=(idleConf.GetOption('main',
'EditorWindow', 'font'),
- idleConf.GetOption('main', 'EditorWindow',
'font-size'),
- fontWeight)
+ fontWeight = 'bold'
+ textcf['font'] = (idleConf.GetOption('main',
'EditorWindow', 'font'),
+ idleConf.GetOption('main', 'EditorWindow',
+ 'font-size'),
+ fontWeight)
# override defaults with any user-specified settings
textcf.update(kwargs)
ScrolledText.__init__(self, master, **textcf)
@@ -87,22 +91,23 @@
'<<replace>>': ['<Control-Key-h>',
'<Control-Key-H>'],
'<<select-all>>':
['<Control-Key-a>'],
'<<undo>>': ['<Control-Key-z>',
'<Control-Key-Z>'],
- }
+ }
+
for event, keylist in keydefs.iteritems():
if keylist:
self.event_add(event, *keylist)
- def cut(self,event):
+ def cut(self, event):
if self.tag_ranges("sel"):
self.event_generate("<<Cut>>")
return "break"
- def copy(self,event):
+ def copy(self, event):
if self.tag_ranges("sel"):
self.event_generate("<<Copy>>")
return "break"
- def paste(self,event):
+ def paste(self, event):
self.event_generate("<<Paste>>")
return "break"
@@ -204,8 +209,8 @@
self.focus_set()
def goto_line_event(self, event):
- lineno = tkSimpleDialog.askinteger("Goto",
- "Go to line number:", parent=self)
+ lineno = tkSimpleDialog.askinteger("Goto", "Go to line
number:",
+ parent=self)
if lineno is None:
return "break"
if lineno <= 0:
@@ -217,7 +222,7 @@
class EditBoxWindow(Frame):
- def __init__(self, parent = None, **kwargs):
+ def __init__(self, parent=None, **kwargs):
if parent is None:
# create a new window
parent = Tk()
@@ -323,13 +328,14 @@
# wait for user to push a button which will destroy (close) the window
# enable word wrap
self.editbox.tag_add('all', '1.0', END)
- self.editbox.tag_config('all', wrap = WORD)
+ self.editbox.tag_config('all', wrap=WORD)
# start search if required
if highlight:
self.find_all(highlight)
if jumpIndex:
print jumpIndex
- line = text[:jumpIndex].count('\n') + 1 # lines are indexed starting
at 1
+ # lines are indexed starting at 1
+ line = text[:jumpIndex].count('\n') + 1
column = jumpIndex - (text[:jumpIndex].rfind('\n') + 1)
# don't know how to place the caret, but scrolling to the right line
# should already be helpful.
@@ -376,7 +382,7 @@
#ok closes listbox
self.parent.destroy()
- def __init__(self, parent = None):
+ def __init__(self, parent=None):
if parent is None:
# create a new window
parent = Tk()
@@ -399,21 +405,21 @@
# put list of alternatives into listbox
self.list = list
#find required area
- laenge=len(list)
- maxbreite=0
+ laenge = len(list)
+ maxbreite = 0
for i in range(laenge):
#cycle through all listitems to find maxlength
- if len(list[i])+len(str(i))>maxbreite:
- maxbreite=len(list[i])+len(str(i))
+ if len(list[i]) + len(str(i)) > maxbreite:
+ maxbreite = len(list[i]) + len(str(i))
#show list as formerly in DOS-window
- self.listbox.insert(END, str(i)+ ' - '+ list[i])
+ self.listbox.insert(END, str(i) + ' - ' + list[i])
#set optimized height & width
self.listbox.config(height=laenge, width=maxbreite+2)
# wait for user to push a button which will destroy (close) the window
return self.list
-if __name__=="__main__":
+if __name__ == "__main__":
import wikipedia as pywikibot
try:
root = Tk()
@@ -423,6 +429,6 @@
content = page.get()
myapp = EditBoxWindow(root)
myapp.bind("<Control-d>", myapp.debug)
- v = myapp.edit(content, highlight = page.title())
+ v = myapp.edit(content, highlight=page.title())
finally:
pywikibot.stopme()
--
To view, visit
https://gerrit.wikimedia.org/r/103548
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5e45c6f948748dde321cb26725fecc68dd0a875f
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot