# -*- 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 *

        

class 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.

        Unlike raw_input, this function automatically adds a space after the
        question.
        """
        # TODO: hide input if password = True
        answer = dialog = wxTextEntryDialog ( None, 'question', 'Title Here', '' )

#tkSimpleDialog.askstring('title', question)
        return answer or ''

    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)

            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?')

@@ -1,553 +1,199 @@
-# -*- coding: utf-8  -*-%0A#%0A# (C) Pywikipedia bot team, 2005-2008%0A#%0A# Distributed under the terms of the MIT license.%0A#%0A__version__ = '$Id$'%0A%0Aimport sys; sys.path.append('..')%0A%0Aimport config, re, sys%0Afrom wxPython.wx import *%0A%0A        %0A%0Aclass UI:%0A    def __init__(self):%0A        pass%0A%0A    def output(self, text, ):%0A        %22%22%22%0A        If a character can't be displayed, it will be replaced with a%0A        question mark.%0A        %22%22%22%0A        # comma at the end means %22don't print newline%22%0A        print text.encode(config.console_encoding, 'replace'),%0A
+%0A__version__ = '$Id$'%0A%0Aimport sys; sys.path.append('..')%0A%0Aimport re%0Aimport terminal_interface%0Aimport wx%0A%0Aapp = wx.App()%0A%0Aclass UI(terminal_interface.UI):%0A    def __init__(self):%0A        pass%0A    
 %0A   
@@ -495,28 +495,166 @@
     
-answer = dialog
+%0A        self.output(question)%0A        if password:%0A            answer = wx.PasswordEntryDialog( None, question, '','')%0A        else:%0A            answer
  = wx
+.
 Text
@@ -668,17 +668,16 @@
 alog
- 
 ( None, 
 'que
@@ -676,17 +676,16 @@
 ne, 
-'
 question
 ', '
@@ -684,31 +684,87 @@
 tion
-'
 , '
-Title Here', '' )%0A%0A
+', '' )%0A        answer.ShowModal()%0A        self.output(answer+'%5Cn')%0A        
 #tkS
@@ -825,16 +825,27 @@
 n answer
+.GetValue()
  or ''%0A%0A
@@ -900,72 +900,27 @@
 keys
-):%0A        goodAnswer = False%0A        while not goodAnswer:%0A    
+, default = None):%0A
     
@@ -961,28 +961,24 @@
             
-    
 option = opt
@@ -981,28 +981,24 @@
  options%5Bi%5D%0A
-    
             
@@ -1029,20 +1029,16 @@
         
-    
 m = re.s
@@ -1108,20 +1108,16 @@
         
-    
 if m:%0A  
@@ -1130,20 +1130,16 @@
         
-  
-  
 pos = m.
@@ -1146,20 +1146,16 @@
 start()%0A
-    
         
@@ -1240,38 +1240,30 @@
             
-   
- 
 else:%0A
-    
             
@@ -1312,30 +1312,126 @@
 ey)%0A
-%0A            prompt = 
+        %0A        while True:%0A            prompt = '%25s%5Cn(%25s)' %25 (question, ', '.join(options))%0A            self.output(
 '%25s 
@@ -1460,32 +1460,33 @@
 '.join(options))
+)
 %0A            ans
@@ -1495,27 +1495,175 @@
 r = 
-self.input(prompt
+wx.TextEntryDialog(None, prompt, question, '')%0A            answer.ShowModal()%0A            answer = answer.GetValue()%0A            self.output(answer+'%5Cn'
 )%0A
+            %0A
     
@@ -1759,16 +1759,142 @@
  answer%0A
+            elif default and answer=='':# empty string entered%0A                return default%0A%0Aif __name__ == '__main__':%0A    
 ui = UI(
@@ -1895,16 +1895,20 @@
  = UI()%0A
+    
 print ui
@@ -1923,8 +1923,25 @@
 Test?')%0A
+%0Aapp.MainLoop()%0A%0A

update current wxpython_interface.py fix and sync to pywikibot module