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()
pywikipedia-l@lists.wikimedia.org