[Pywikipedia-svn] SVN: [7217]

alexsh at svn.wikimedia.org alexsh at svn.wikimedia.org
Sun Sep 6 15:52:15 UTC 2009


Revision: 7217
Author:   alexsh
Date:     2009-09-06 15:52:15 +0000 (Sun, 06 Sep 2009)

Log Message:
-----------
update current wxpython_interface.py fix and sync to pywikibot module

Modified Paths:
--------------
    branches/rewrite/pywikibot/userinterfaces/wxpython_interface.py
    trunk/pywikipedia/userinterfaces/wxpython_interface.py

Modified: branches/rewrite/pywikibot/userinterfaces/wxpython_interface.py
===================================================================
--- branches/rewrite/pywikibot/userinterfaces/wxpython_interface.py	2009-09-06 15:45:27 UTC (rev 7216)
+++ branches/rewrite/pywikibot/userinterfaces/wxpython_interface.py	2009-09-06 15:52:15 UTC (rev 7217)
@@ -1,30 +1,18 @@
-# -*- coding: utf-8  -*-
-#
-# (C) Pywikipedia bot team, 2005-2008
-#
-# Distributed under the terms of the MIT license.
-#
+
 __version__ = '$Id$'
 
 import sys; sys.path.append('..')
 
-import config, re, sys
-from wxPython.wx import *
+import re
+import terminal_interface
+import wx
 
-        
+app = wx.App()
 
-class UI:
+class UI(terminal_interface.UI):
     def __init__(self):
         pass
-
-    def output(self, text, ):
-        """
-        If a character can't be displayed, it will be replaced with a
-        question mark.
-        """
-        # comma at the end means "don't print newline"
-        print text.encode(config.console_encoding, 'replace'),
-
+    
     def input(self, question, password = False):
         """
         Works like raw_input(), but returns a unicode string instead of ASCII.
@@ -33,27 +21,44 @@
         question.
         """
         # TODO: hide input if password = True
-        answer = dialog = wxTextEntryDialog ( None, 'question', 'Title Here', '' )
+        
+        self.output(question)
+        if password:
+            answer = wx.PasswordEntryDialog( None, question, '','')
+        else:
+            answer = wx.TextEntryDialog( None, question, '', '' )
+        answer.ShowModal()
+        self.output(answer+'\n')
+        #tkSimpleDialog.askstring('title', question)
+        return answer.GetValue() or ''
 
-#tkSimpleDialog.askstring('title', question)
-        return answer or ''
+    def inputChoice(self, question, options, hotkeys, default = None):
+        for i in range(len(options)):
+            option = options[i]
+            hotkey = hotkeys[i]
+            m = re.search('[%s%s]' % (hotkey.lower(), hotkey.upper()), option)
+            if m:
+                pos = m.start()
+                options[i] = '%s[%s]%s' % (option[:pos], option[pos], option[pos+1:])
+            else:
+                options[i] = '%s [%s]' % (option, hotkey)
+        
+        while True:
+            prompt = '%s\n(%s)' % (question, ', '.join(options))
+            self.output('%s (%s)' % (question, ', '.join(options)))
+            answer = wx.TextEntryDialog(None, prompt, question, '')
+            answer.ShowModal()
+            answer = answer.GetValue()
+            self.output(answer+'\n')
+            
+            if answer.lower() in hotkeys or answer.upper() in hotkeys:
+                return answer
+            elif default and answer=='':# empty string entered
+                return default
 
-    def inputChoice(self, question, options, hotkeys):
-        goodAnswer = False
-        while not goodAnswer:
-            for i in range(len(options)):
-                option = options[i]
-                hotkey = hotkeys[i]
-                m = re.search('[%s%s]' % (hotkey.lower(), hotkey.upper()), option)
-                if m:
-                    pos = m.start()
-                    options[i] = '%s[%s]%s' % (option[:pos], option[pos], option[pos+1:])
-                else:
-                    options[i] = '%s [%s]' % (option, hotkey)
+if __name__ == '__main__':
+    ui = UI()
+    print ui.input('Test?')
 
-            prompt = '%s (%s)' % (question, ', '.join(options))
-            answer = self.input(prompt)
-            if answer.lower() in hotkeys or answer.upper() in hotkeys:
-                return answer
-ui = UI()
-print ui.input('Test?')
+app.MainLoop()
+

Modified: trunk/pywikipedia/userinterfaces/wxpython_interface.py
===================================================================
--- trunk/pywikipedia/userinterfaces/wxpython_interface.py	2009-09-06 15:45:27 UTC (rev 7216)
+++ trunk/pywikipedia/userinterfaces/wxpython_interface.py	2009-09-06 15:52:15 UTC (rev 7217)
@@ -3,25 +3,16 @@
 
 import sys; sys.path.append('..')
 
-import config, re, sys, terminal_interface
+import re
+import terminal_interface
 import wx
 
 app = wx.App()
 
-class UI:
+class UI(terminal_interface.UI):
     def __init__(self):
         pass
     
-    def output(self, text, toStdout = False):
-        """
-        If a character can't be displayed, it will be replaced with a
-        question mark.
-        """
-        # comma at the end means "don't print newline"
-        #print text.encode(config.console_encoding, 'replace'),
-        terminal_interface.UI().output(text, toStdout)
-        
-
     def input(self, question, password = False):
         """
         Works like raw_input(), but returns a unicode string instead of ASCII.
@@ -31,39 +22,43 @@
         """
         # TODO: hide input if password = True
         
+        self.output(question)
         if password:
             answer = wx.PasswordEntryDialog( None, question, '','')
         else:
             answer = wx.TextEntryDialog( None, question, '', '' )
         answer.ShowModal()
-        print answer.GetValue()
+        self.output(answer+'\n')
         #tkSimpleDialog.askstring('title', question)
         return answer.GetValue() or ''
 
     def inputChoice(self, question, options, hotkeys, default = None):
-        goodAnswer = False
-        while not goodAnswer:
-            for i in range(len(options)):
-                option = options[i]
-                hotkey = hotkeys[i]
-                m = re.search('[%s%s]' % (hotkey.lower(), hotkey.upper()), option)
-                if m:
-                    pos = m.start()
-                    options[i] = '%s[%s]%s' % (option[:pos], option[pos], option[pos+1:])
-                else:
-                    options[i] = '%s [%s]' % (option, hotkey)
-
-            prompt = '%s (%s)' % (question, ', '.join(options))
+        for i in range(len(options)):
+            option = options[i]
+            hotkey = hotkeys[i]
+            m = re.search('[%s%s]' % (hotkey.lower(), hotkey.upper()), option)
+            if m:
+                pos = m.start()
+                options[i] = '%s[%s]%s' % (option[:pos], option[pos], option[pos+1:])
+            else:
+                options[i] = '%s [%s]' % (option, hotkey)
+        
+        while True:
+            prompt = '%s\n(%s)' % (question, ', '.join(options))
+            self.output('%s (%s)' % (question, ', '.join(options)))
             answer = wx.TextEntryDialog(None, prompt, question, '')
             answer.ShowModal()
             answer = answer.GetValue()
+            self.output(answer+'\n')
             
             if answer.lower() in hotkeys or answer.upper() in hotkeys:
                 return answer
+            elif default and answer=='':# empty string entered
+                return default
 
-
 if __name__ == '__main__':
     ui = UI()
     print ui.input('Test?')
+
 app.MainLoop()
 





More information about the Pywikipedia-svn mailing list