Revision: 4009
Author: misza13
Date: 2007-08-08 20:56:59 +0000 (Wed, 08 Aug 2007)
Log Message:
-----------
Added spaces after all welcome templates (and before signatures).
Modified Paths:
--------------
trunk/pywikipedia/welcome.py
Modified: trunk/pywikipedia/welcome.py
===================================================================
--- trunk/pywikipedia/welcome.py 2007-08-08 14:55:17 UTC (rev 4008)
+++ trunk/pywikipedia/welcome.py 2007-08-08 20:56:59 UTC (rev 4009)
@@ -213,15 +213,15 @@
# that is your signature (the bot has a random parameter to add different
# sign, so in this way it will change according to your parameters).
netext = {
- 'commons':u'{{subst:welcome}}%s',
- 'ar':u'{{نسخ:مستخدم:Alnokta/ترحيب}}%s',
+ 'commons':u'{{subst:welcome}} %s',
+ 'ar':u'{{نسخ:مستخدم:Alnokta/ترحيب}} %s',
'de':u'{{subst:Hallo}} %s',
- 'en':u'{{subst:welcome}}%s',
- 'fa':u'{{جا:خوشامد}}%s',
+ 'en':u'{{subst:welcome}} %s',
+ 'fa':u'{{جا:خوشامد}} %s',
'it':u'{{Benvebot}} %s',
- 'nl':u'{{Welkomstbericht}}%s',
- 'no':u'{{subst:bruker:jhs/vk}}%s',
- 'sq':u'{{subst:tung}}%s',
+ 'nl':u'{{Welkomstbericht}} %s',
+ 'no':u'{{subst:bruker:jhs/vk}} %s',
+ 'sq':u'{{subst:tung}} %s',
}
# The edit summary for updating the welcome log (e.g. Updating log).
summary2 = {
Revision: 4008
Author: valhallasw
Date: 2007-08-08 14:55:17 +0000 (Wed, 08 Aug 2007)
Log Message:
-----------
+input_choice_proposal for wikipedian et al
Added Paths:
-----------
branches/pywikipedia/i18n/input_choice_proposal/
branches/pywikipedia/i18n/input_choice_proposal/ic.py
branches/pywikipedia/i18n/input_choice_proposal/messages.mo
branches/pywikipedia/i18n/input_choice_proposal/messages.po
Added: branches/pywikipedia/i18n/input_choice_proposal/ic.py
===================================================================
--- branches/pywikipedia/i18n/input_choice_proposal/ic.py (rev 0)
+++ branches/pywikipedia/i18n/input_choice_proposal/ic.py 2007-08-08 14:55:17 UTC (rev 4008)
@@ -0,0 +1,58 @@
+import sys
+sys.path.append('../pywikipedia')
+import wikipedia
+ui = wikipedia.ui
+
+from gettext import GNUTranslations
+cat = GNUTranslations(file('messages.mo'))
+
+def i18nChoice(question, answerstring, default = None):
+ """
+ Asks the user a question and offers several options, then returns the
+ user's choice. The user's input will be case-insensitive, so the hotkeys
+ should be distinctive case-insensitively.
+
+ Parameters:
+ * question - a unicode string that will be shown to the user. Don't add a
+ space after the question mark, this method will do this
+ for you.
+ * answers - a list of strings that represent the options.
+ * hotkeys - a list of one-letter strings, one for each answer.
+ * default - an element of hotkeys, or None. The default choice that will
+ be returned when the user just presses Enter.
+
+ Returns a one-letter string in lowercase.
+ """
+
+ # first translate question and answers
+ origQ = question
+ try:
+ transQ = cat._catalog[(question, 0)]
+ except KeyError:
+ transQ = question
+
+ exec('origA = %s' % answerstring, locals(), globals())
+ try:
+ exec('transA = %s' % cat._catalog[(question, 1)], locals(), globals())
+ except KeyError:
+ exec('transA = %s' % answerstring, locals(), globals())
+
+ # get translated answers and hotkeys
+ (answers, hotkeys) = zip(*transA)
+
+ # map translated key to untranslated text
+ keymap = {}
+ for orig, trans in zip(origA, transA):
+ keymap[trans[1].lower()] = orig[0]
+ if orig[0] == default:
+ defaultkey = trans[1]
+
+ answers = list(answers)
+ data = ui.inputChoice(transQ, answers, hotkeys, defaultkey).lower()
+
+ try:
+ return keymap[data]
+ except KeyError:
+ return None
+
+print i18nChoice("Do you want to save?", "[('yes', 'y'), ('no', 'n')]", 'yes')
\ No newline at end of file
Property changes on: branches/pywikipedia/i18n/input_choice_proposal/ic.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: branches/pywikipedia/i18n/input_choice_proposal/messages.mo
===================================================================
(Binary files differ)
Property changes on: branches/pywikipedia/i18n/input_choice_proposal/messages.mo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Name: svn:keywords
+ Id
Added: branches/pywikipedia/i18n/input_choice_proposal/messages.po
===================================================================
--- branches/pywikipedia/i18n/input_choice_proposal/messages.po (rev 0)
+++ branches/pywikipedia/i18n/input_choice_proposal/messages.po 2007-08-08 14:55:17 UTC (rev 4008)
@@ -0,0 +1,23 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2007-08-08 16:50+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL(a)li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: ic.py:60
+msgid "Do you want to save?"
+msgid_plural "[('yes', 'y'), ('no', 'n')]"
+msgstr[0] "Wilt u opslaan?"
+msgstr[1] "[('ja', 'j'), ('nee', 'n')]"
Property changes on: branches/pywikipedia/i18n/input_choice_proposal/messages.po
___________________________________________________________________
Name: svn:keywords
+ Id
Revision: 4006
Author: wikipedian
Date: 2007-08-08 00:17:07 +0000 (Wed, 08 Aug 2007)
Log Message:
-----------
fixed indentation
Modified Paths:
--------------
trunk/pywikipedia/disambredir.py
Modified: trunk/pywikipedia/disambredir.py
===================================================================
--- trunk/pywikipedia/disambredir.py 2007-08-07 23:28:47 UTC (rev 4005)
+++ trunk/pywikipedia/disambredir.py 2007-08-08 00:17:07 UTC (rev 4006)
@@ -44,9 +44,9 @@
# how many bytes should be displayed around the current link
context = 30
- # at the beginning of the link, start red color.
- # at the end of the link, reset the color to default
- wikipedia.output(text[m.start() - context : m.start()] + '\03{lightred}' + text[m.start() : m.end()] + '\03{default}' + text[m.end() : m.end() + context])
+ # at the beginning of the link, start red color.
+ # at the end of the link, reset the color to default
+ wikipedia.output(text[m.start() - context : m.start()] + '\03{lightred}' + text[m.start() : m.end()] + '\03{default}' + text[m.end() : m.end() + context])
while True:
choice = wikipedia.input(u"Option (n=do not change, y=change link to \03{lightpurple}%s\03{default}, r=change and replace text, u=unlink)"%targetPage.title())
try:
Revision: 4002
Author: wikipedian
Date: 2007-08-07 21:38:17 +0000 (Tue, 07 Aug 2007)
Log Message:
-----------
fixed bug: correctly print colorized texts in Windows when color tags
are cascaded.
Modified Paths:
--------------
trunk/pywikipedia/userinterfaces/terminal_interface.py
Modified: trunk/pywikipedia/userinterfaces/terminal_interface.py
===================================================================
--- trunk/pywikipedia/userinterfaces/terminal_interface.py 2007-08-07 20:50:27 UTC (rev 4001)
+++ trunk/pywikipedia/userinterfaces/terminal_interface.py 2007-08-07 21:38:17 UTC (rev 4002)
@@ -29,7 +29,7 @@
#15 = Bright White
unixColors = {
- #None: chr(27) + '[0m', # Unix end tag to switch back to default
+ 'default': chr(27) + '[0m', # Unix end tag to switch back to default
'lightblue': chr(27) + '[94;1m', # Light Blue start tag
'lightgreen': chr(27) + '[92;1m', # Light Green start tag
'lightaqua': chr(27) + '[36;1m', # Light Aqua start tag
@@ -39,6 +39,7 @@
}
windowsColors = {
+ 'default': config.defaultcolor,
'lightblue': 9,
'lightgreen': 10,
'lightaqua': 11,
@@ -48,8 +49,7 @@
}
-startTagR = re.compile('\03{(?P<name>%s)}' % '|'.join(unixColors.keys()))
-endTagR = re.compile('\03{default}')
+colorTagR = re.compile('\03{(?P<name>%s)}' % '|'.join(windowsColors.keys()))
class UI:
def __init__(self):
@@ -62,7 +62,9 @@
lastColor = None
for key, value in unixColors.iteritems():
text = text.replace('\03{%s}' % key, value)
- text = text.replace('\03{default}', chr(27) + '[0m') # Unix end tag to switch back to default
+ # just to be sure, reset the color
+ text += unixColors['default']
+
targetStream.write(text.encode(config.console_encoding, 'replace'))
def printColorizedInWindows(self, text, targetStream):
@@ -71,23 +73,33 @@
"""
if ctypes_found:
std_out_handle = ctypes.windll.kernel32.GetStdHandle(-11)
- # this relies on non-overlapping, non-cascading color tags that are all properly closed.
- # TODO: This assumption is wrong: with transliteration, there can be cascading color tags.
- startM = True
- while startM:
- startM = startTagR.search(text)
- if startM:
+ # Color tags might be cascaded, e.g. because of transliteration.
+ # Therefore we need this stack.
+ colorStack = []
+ tagM = True
+ while tagM:
+ tagM = colorTagR.search(text)
+ if tagM:
# print the text up to the tag.
- targetStream.write(text[:startM.start()].encode(config.console_encoding, 'replace'))
- ctypes.windll.kernel32.SetConsoleTextAttribute(std_out_handle, windowsColors[startM.group('name')])
- # print the colored text inside the tag.
- endM = endTagR.search(text)
- targetStream.write(text[startM.end():endM.start()].encode(config.console_encoding, 'replace'))
- # reset to default color
- ctypes.windll.kernel32.SetConsoleTextAttribute(std_out_handle, config.defaultcolor)
- text = text[endM.end():]
+ targetStream.write(text[:tagM.start()].encode(config.console_encoding, 'replace'))
+ newColor = tagM.group('name')
+ if newColor == 'default':
+ if len(colorStack) > 0:
+ colorStack.pop()
+ if len(colorStack) > 0:
+ lastColor = colorStack[-1]
+ else:
+ lastColor = 'default'
+ ctypes.windll.kernel32.SetConsoleTextAttribute(std_out_handle, windowsColors[lastColor])
+ else:
+ colorStack.append(newColor)
+ # set the new color
+ ctypes.windll.kernel32.SetConsoleTextAttribute(std_out_handle, windowsColors[newColor])
+ text = text[tagM.end():]
# print the rest of the text
targetStream.write(text.encode(config.console_encoding, 'replace'))
+ # just to be sure, reset the color
+ ctypes.windll.kernel32.SetConsoleTextAttribute(std_out_handle, windowsColors['default'])
else:
# ctypes is only available since Python 2.5, and we won't
# try to colorize without it. Instead we add *** after the text as a whole
Revision: 4001
Author: wikipedian
Date: 2007-08-07 20:50:27 +0000 (Tue, 07 Aug 2007)
Log Message:
-----------
removed the colors parameter
Modified Paths:
--------------
trunk/pywikipedia/userinterfaces/cgi_interface.py
trunk/pywikipedia/userinterfaces/terminal_interface.py
trunk/pywikipedia/userinterfaces/tkinter_interface.py
trunk/pywikipedia/userinterfaces/wxpython_interface.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/userinterfaces/cgi_interface.py
===================================================================
--- trunk/pywikipedia/userinterfaces/cgi_interface.py 2007-08-07 20:39:21 UTC (rev 4000)
+++ trunk/pywikipedia/userinterfaces/cgi_interface.py 2007-08-07 20:50:27 UTC (rev 4001)
@@ -4,11 +4,11 @@
def __init__(self):
pass
- def output(self, text, colors = None, newline = True, toStdout = False):
+ def output(self, text, newline = True, toStdout = False):
# all debug output etc. will be ignored.
if toStdout:
sys.stdout.write(text.encode('UTF-8', 'replace'))
- def input(self, question, colors = None, password = False):
+ def input(self, question, password = False):
# CGI is output-only.
self.output(question + ' ', newline = False, toStdout = True)
Modified: trunk/pywikipedia/userinterfaces/terminal_interface.py
===================================================================
--- trunk/pywikipedia/userinterfaces/terminal_interface.py 2007-08-07 20:39:21 UTC (rev 4000)
+++ trunk/pywikipedia/userinterfaces/terminal_interface.py 2007-08-07 20:50:27 UTC (rev 4001)
@@ -58,14 +58,14 @@
# NOTE: We use sys.stdout.write() instead of print because print adds a
# newline.
- def printColorizedInUnix(self, text, colors, targetStream):
+ def printColorizedInUnix(self, text, targetStream):
lastColor = None
for key, value in unixColors.iteritems():
text = text.replace('\03{%s}' % key, value)
text = text.replace('\03{default}', chr(27) + '[0m') # Unix end tag to switch back to default
targetStream.write(text.encode(config.console_encoding, 'replace'))
- def printColorizedInWindows(self, text, colors, targetStream):
+ def printColorizedInWindows(self, text, targetStream):
"""
This only works in Python 2.5 or higher.
"""
@@ -101,28 +101,21 @@
line += '\n'
targetStream.write(line.encode(config.console_encoding, 'replace'))
- def printColorized(self, text, colors, targetStream):
- if colors and config.colorized_output:
+ def printColorized(self, text, targetStream):
+ if config.colorized_output:
if sys.platform == 'win32':
- self.printColorizedInWindows(text, colors, targetStream)
+ self.printColorizedInWindows(text, targetStream)
else:
- self.printColorizedInUnix(text, colors, targetStream)
+ self.printColorizedInUnix(text, targetStream)
else:
targetStream.write(text.encode(config.console_encoding, 'replace'))
- def output(self, text, colors = None, newline = True, toStdout = False):
+ def output(self, text, newline = True, toStdout = False):
"""
If a character can't be displayed in the encoding used by the user's
terminal, it will be replaced with a question mark or by a
transliteration.
"""
- if colors:
- if len(colors) != len(text):
- print "DBG> BUG: Text color list length different from text length!"
- print traceback.print_stack()
- print "DBG> Attempting to recover, but please report this problem"
- else:
- colors = [None for char in text]
if config.transliterate:
# Encode our unicode string in the encoding used by the user's console,
# and decode it back to unicode. Then we can see which characters
@@ -159,15 +152,14 @@
text = transliteratedText
if newline:
text += u'\n'
- colors.append(None)
if toStdout:
targetStream = sys.stdout
else:
targetStream = sys.stderr
- self.printColorized(text, colors, targetStream)
+ self.printColorized(text, targetStream)
- def input(self, question, colors = None, password = False):
+ def input(self, question, password = False):
"""
Works like raw_input(), but returns a unicode string instead of ASCII.
@@ -178,10 +170,7 @@
# sound the terminal bell to notify the user
if config.ring_bell:
sys.stdout.write('\07')
- if colors:
- self.output(question + ' ', colors = colors + [None], newline=False)
- else:
- self.output(question + ' ', newline = False)
+ self.output(question + ' ', newline = False)
if password:
import getpass
text = getpass.getpass('')
Modified: trunk/pywikipedia/userinterfaces/tkinter_interface.py
===================================================================
--- trunk/pywikipedia/userinterfaces/tkinter_interface.py 2007-08-07 20:39:21 UTC (rev 4000)
+++ trunk/pywikipedia/userinterfaces/tkinter_interface.py 2007-08-07 20:50:27 UTC (rev 4001)
@@ -155,7 +155,7 @@
MainloopThread(self.parent).start()
- def output(self, text, urgency = 1, colors = None, newline = True, toStdout = False):
+ def output(self, text, urgency = 1, newline = True, toStdout = False):
"""
urgency levels:
0 - Debug output. Won't be shown in normal mode.
@@ -174,21 +174,22 @@
# Save the line number before appending text
lineCount = float(self.logBox.index(END).split('.')[0]) - 1
self.logBox.insert(END, text)
- if colors:
- # How many characters we already added in this line
- offset = 0
- # We create a tag region for each colored character.
- # It would be more efficient to try to use longer
- # regions.
- for i in range(len(colors)):
- if text[i] == '\n':
- lineCount += 1
- offset = i + 1
- if colors[i]:
- startidx = '%i.%i' % (lineCount, i - offset)
- endidx = '%i.%i' % (lineCount, i + 1 - offset)
- # tag the whole occurence (start included, stop excluded)
- self.logBox.tag_add(colors[i], startidx , endidx)
+ # colors support currently broken, sorry.
+ #if colors:
+ ## How many characters we already added in this line
+ #offset = 0
+ ## We create a tag region for each colored character.
+ ## It would be more efficient to try to use longer
+ ## regions.
+ #for i in range(len(colors)):
+ #if text[i] == '\n':
+ #lineCount += 1
+ #offset = i + 1
+ #if colors[i]:
+ #startidx = '%i.%i' % (lineCount, i - offset)
+ #endidx = '%i.%i' % (lineCount, i + 1 - offset)
+ ## tag the whole occurence (start included, stop excluded)
+ #self.logBox.tag_add(colors[i], startidx , endidx)
if newline:
@@ -196,7 +197,7 @@
# auto-scroll down
self.logBox.see(END)
- def input(self, question, colors=None, password = False):
+ def input(self, question, password = False):
"""
Returns a unicode string.
"""
Modified: trunk/pywikipedia/userinterfaces/wxpython_interface.py
===================================================================
--- trunk/pywikipedia/userinterfaces/wxpython_interface.py 2007-08-07 20:39:21 UTC (rev 4000)
+++ trunk/pywikipedia/userinterfaces/wxpython_interface.py 2007-08-07 20:50:27 UTC (rev 4001)
@@ -12,7 +12,7 @@
def __init__(self):
pass
- def output(self, text, newline = True, colors = None):
+ def output(self, text, newline = True):
"""
If a character can't be displayed, it will be replaced with a
question mark.
@@ -23,7 +23,7 @@
# comma at the end means "don't print newline"
print text.encode(config.console_encoding, 'replace'),
- def input(self, question, colors = None, password = False):
+ def input(self, question, password = False):
"""
Works like raw_input(), but returns a unicode string instead of ASCII.
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2007-08-07 20:39:21 UTC (rev 4000)
+++ trunk/pywikipedia/wikipedia.py 2007-08-07 20:50:27 UTC (rev 4001)
@@ -4440,17 +4440,13 @@
output_lock = threading.Lock()
input_lock = threading.Lock()
output_cache = []
-def output(text, decoder = None, colors = [], newline = True, toStdout = False):
+def output(text, decoder = None, newline = True, toStdout = False):
"""
Works like print, but uses the encoding used by the user's console
(console_encoding in the configuration file) instead of ASCII.
If decoder is None, text should be a unicode string. Otherwise it
should be encoded in the given encoding.
- colors is a list of integers, one for each character of text. If a
- list entry is None, the default color will be used for the
- character at that position.
-
If newline is True, a linebreak will be added after printing the text.
If toStdout is True, the text will be sent to standard output,
@@ -4475,9 +4471,9 @@
logfile.write(text + '\n')
logfile.flush()
if input_lock.locked():
- cache_output(text, colors = colors, newline = newline, toStdout = toStdout)
+ cache_output(text, newline = newline, toStdout = toStdout)
else:
- ui.output(text, colors = colors, newline = newline, toStdout = toStdout)
+ ui.output(text, newline = newline, toStdout = toStdout)
finally:
output_lock.release()
@@ -4489,7 +4485,7 @@
(args, kwargs) = output_cache.pop(0)
ui.output(*args, **kwargs)
-def input(question, colors = None, password = False):
+def input(question, password = False):
"""
Asks the user a question, then returns the user's answer.
@@ -4497,14 +4493,13 @@
* question - a unicode string that will be shown to the user. Don't add a
space after the question mark/colon, this method will do this
for you.
- * colors - same as in output().
* password - if True, hides the user's input (for password entry).
Returns a unicode string.
"""
input_lock.acquire()
try:
- data = ui.input(question, colors, password)
+ data = ui.input(question, password)
finally:
flush_output_cache()
input_lock.release()