Revision: 4299 Author: leogregianin Date: 2007-09-15 19:23:22 +0000 (Sat, 15 Sep 2007)
Log Message: ----------- remove imports typos
Modified Paths: -------------- trunk/pywikipedia/movepages.py
Modified: trunk/pywikipedia/movepages.py =================================================================== --- trunk/pywikipedia/movepages.py 2007-09-15 19:18:52 UTC (rev 4298) +++ trunk/pywikipedia/movepages.py 2007-09-15 19:23:22 UTC (rev 4299) @@ -29,9 +29,8 @@
__version__='$Id$'
-import wikipedia, pagegenerators, catlib, config -import sys -import re +import wikipedia, pagegenerators +import sys, re
# This is required for the text that is shown when you run this script # with the parameter -help. @@ -103,12 +102,14 @@ newPageTitle = (u'%s%s' % (self.addprefix, pagetitle)) if self.addprefix or self.appendAll or self.regexAll: if not self.always: - choice2 = wikipedia.inputChoice(u'Change the page title to "%s"?' % newPageTitle, ['yes', 'no', 'quit'], ['y', 'n', 'q']) - if choice2 == 'y': + choice2 = wikipedia.inputChoice(u'Change the page title to "%s"?' % newPageTitle, ['yes', 'no', 'all', 'quit'], ['y', 'n', 'a', 'q']) + if choice2 in ['y', 'Yes', 'Y']: self.moveOne(page,newPageTitle,self.delete) - elif choice2 == 'q': + elif choice2 in ['a', 'all', 'A']: + self.always = True + elif choice2 in ['q', 'Q', 'quit']: sys.exit() - elif choice2 == 'n': + elif choice2 in ['n', 'N', 'no']: pass else: self.treat(page) @@ -130,14 +131,14 @@ else: newPageTitle = (u'%s:%s' % (namesp, newPageTitle)) choice2 = wikipedia.inputChoice(u'Change the page title to "%s"?' % newPageTitle, ['yes', 'no', 'all', 'quit'], ['y', 'n', 'a', 'q']) - if choice2 == 'y': + if choice2 in ['y', 'Y', 'yes']: self.moveOne(page,newPageTitle,self.delete) - elif choice2 == 'a': + elif choice2 in ['a', 'A', 'all']: self.appendAll = True self.moveOne(page,newPageTitle,self.delete) - elif choice2 == 'q': + elif choice2 in ['q', 'Q', 'quit']: sys.exit() - elif choice2 == 'n': + elif choice2 in ['n', 'no', 'N']: pass else: self.treat(page) @@ -155,20 +156,20 @@ else: newPageTitle = self.regex.sub(self.replacePattern, page.title()) choice2 = wikipedia.inputChoice(u'Change the page title to "%s"?' % newPageTitle, ['yes', 'no', 'all', 'quit'], ['y', 'n', 'a', 'q']) - if choice2 == 'y': + if choice2 in ['y', 'Y', 'yes']: self.moveOne(page,newPageTitle,self.delete) - elif choice2 == 'a': + elif choice2 in ['a', 'A', 'all']: self.regexAll = True self.moveOne(page,newPageTitle,self.delete) - elif choice2 == 'q': + elif choice2 in ['q', 'Q', 'quit']: sys.exit() - elif choice2 == 'n': + elif choice2 in ['n', 'no', 'N']: pass else: self.treat(page) - elif choice == 'n': + elif choice in ['n', 'N', 'no']: pass - elif choice == 'q': + elif choice in ['q', 'Q', 'quit']: sys.exit() else: self.treat(page)
Revision: 4299 Author: leogregianin Date: 2007-09-15 19:23:22 +0000 (Sat, 15 Sep 2007)
choice2 = wikipedia.inputChoice(u'Change the page title
to "%s"?' % newPageTitle, ['yes', 'no', 'all', 'quit'], ['y', 'n', 'a', 'q'])
(...)
elif choice2 == 'n':
elif choice2 in ['n', 'N', 'no']:
from terminal_interface.py: if answer.lower() in hotkeys or answer.upper() in hotkeys: return answer elif default and answer=='': # empty string entered return default
What's the point of the 'no', as it should never be returned?
On a side note; does anyone have suggestions for the inputChoice format? Is the current inputChoice(text, choices, keys, default) the preferred one, and is the 'N' or 'n' output the preferred one?
For the i18n branch, I have thought of several possibilities: For the function call: * inputChoice(text, subst, choices, keys, default) i.e.: inputChoice("Save %s", page.aslink(), ['yes','no'], ['y','n'], 'y') * inputChoice(text, subst, choiceskeys, default) i.e.: inputChoice("Save %s", page.aslink(), [('yes', 'y'),('no','n')], 'y') * inputChoice(text, subst, choiceskeys) (caps means default) i.e.: inputChoice("Save %s", page.aslink(), [('yes', 'Y'),('no','n')]) * inputChoice(text, subst, choiceskeys) (triple tuple means default) i.e.: inputChoice("Save %s", page.aslink(), [('yes', 'y', default),('no','n')]) (with default a variable)
For the return value (which will always be the english values): 'Y' or 'y', depending on the entered caps (current system) 'Y'; 'y', always lower or upper case 'yes', the text used
Because the i18n branch introduces breaking changes anyway, this might be a good moment to sort this out. Please comment :)
--valhallasw
Author: leogregianin choice2 = wikipedia.inputChoice(u'Change the page title to "%s"?' % newPageTitle, ['yes', 'no', 'all', 'quit'], ['y', 'n', 'a', 'q'])
On Saturday 15 September 2007 23:08:16 Merlijn van Deen wrote:
What's the point of the 'no', as it should never be returned?
There is none, comparing the choice to 'n' is enough.
On a side note; does anyone have suggestions for the inputChoice format? Is the current inputChoice(text, choices, keys, default) the preferred one, and is the 'N' or 'n' output the preferred one?
When I wrote it, my intention was to show what's the default by capitalizing that character. This is the way it's done in many command-line tools, for example apt-get.
However, this makes i18n hard: for example, in German, all nouns are capitalized, so the english 'show [l]ist' becomes '[L]iste anzeigen', making L look like the default hotkey.
As we now have proper colorization support on nearly all platforms (the only exception I know of is Python 2.4 or lower on Windows), we could instead use colors to indicate the default choice, e.g.:
choice2 = wikipedia.inputChoice(u'Continue?', ['yes', 'no'], ['y', 'n'], 'n')
Would give:
Continue? ([y]es, [n]o)
Where the n is printed in blue.
We could also try to get rid of the square brackets, for example (yes, no) with the y in low-saturation blue and the n in high-saturation blue. But that would require lots of testing, to make sure that this doesn't reduce usability on any system.
Daniel
On a side note; does anyone have suggestions for the inputChoice format? Is the current inputChoice(text, choices, keys, default) the preferred one, and is the 'N' or 'n' output the preferred one?
When I wrote it, my intention was to show what's the default by capitalizing that character. This is the way it's done in many command-line tools, for example apt-get.
However, this makes i18n hard: for example, in German, all nouns are capitalized, so the english 'show [l]ist' becomes '[L]iste anzeigen', making L look like the default hotkey.
Actually I meant the return value of inputChoice :). The way to show the keys is another, but maybe even more important, point.
As we now have proper colorization support on nearly all platforms (the only exception I know of is Python 2.4 or lower on Windows), we could instead use colors to indicate the default choice, e.g.:
(...)
Continue? ([y]es, [n]o) Where the n is printed in blue.
Colors have one big disadvantage: they either are bad on a white background or bad on a black background; but the two other solutions I could think don't really look good: * 'Continue? ([y]es, [n]o) (no)' * 'Continue? ([y]es, [N]O)' (fully capitalized word)
Too bad apt-get does not translate choices. Maybe someone has a German console programming book that covers multiple choice prompts? :D
--valhallasw
Am Dienstag, 18. September 2007 11:49 schrieb Merlijn van Deen:
is the 'N' or 'n' output the preferred one?
Actually I meant the return value of inputChoice :).
I think lowercase 'n' should be fine.
Colors have one big disadvantage: they either are bad on a white background or bad on a black background
Maybe we could highlight the hotkeys by changing their background colors. After the hotkey, we switch back to the default background color. The text color stays the same. When we choose the colors carefully, it should work both with black on white and with white on black consoles. For example, gray background for hotkeys and magenta background for the default hotkey should work (although it would probably look funny).
Of course there might be people with custom background colors, but they just have bad luck then. Or we offer config variables for the colors.
Daniel