wxpython_interface.py :  » Network » Python-Wikipedia-Robot-Framework » pywikipedia » userinterfaces » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Python Wikipedia Robot Framework 
Python Wikipedia Robot Framework » pywikipedia » userinterfaces » wxpython_interface.py

__version__ = '$Id: wxpython_interface.py 7217 2009-09-06 15:52:15Z alexsh $'

import sys; sys.path.append('..')

import re
import terminal_interface
import wx

app = wx.App()

class UI(terminal_interface.UI):
    def __init__(self):
        pass
    
    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
        
        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 ''

    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

if __name__ == '__main__':
    ui = UI()
    print ui.input('Test?')

app.MainLoop()

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.