1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4"""The sample I18N application""" 5 6import os 7 8import wx 9import wx.lib.sized_controls as sc 10 11class AppI18N(sc.SizedFrame): 12 def __init__(self, parent, **kwds): 13 """ 14 A sample application to demonstrate how to enable I18N support 15 """ 16 super(AppI18N, self).__init__(parent, **kwds) 17 self.SetTitle(_(u"The I18N sample application")) 18 19 self.createMenu() 20 self.createOtherCtrls() 21 22 def createMenu(self): 23 menubar = wx.MenuBar() 24 25 # file menu 26 fileMenu = wx.Menu() 27 closeMenuItem = fileMenu.Append(wx.ID_ANY, 28 _(u"Close"), 29 _(u"Close the application")) 30 self.Bind(wx.EVT_MENU, self.onClose, closeMenuItem) 31 menubar.Append(fileMenu, _(u"&File")) 32 33 # edit menu 34 manageMenu = wx.Menu() 35 manageSomethingMenuItem = manageMenu.Append(wx.ID_ANY, 36 _(u"Edit something"), 37 _(u"Edit an entry of something")) 38 self.Bind(wx.EVT_MENU, self.doEditSomething, manageSomethingMenuItem) 39 40 menubar.Append(manageMenu, _(u"&Edit")) 41 42 # help menu 43 helpMenu = wx.Menu() 44 aboutMenuItem = helpMenu.Append(wx.ID_ANY, 45 _(u"&About"), 46 _(u"About the program")) 47 self.Bind(wx.EVT_MENU, self.doAboutBox, aboutMenuItem) 48 menubar.Append(helpMenu, _(u"&Help")) 49 50 self.SetMenuBar(menubar) 51 52 def createOtherCtrls(self): 53 pane = self.GetContentsPane() 54 55 cPane = sc.SizedPanel(pane) 56 cPane.SetSizerType("grid", options={"cols": 2}) 57 st = wx.StaticText(cPane, wx.ID_ANY, 58 _(u"A nice label for the TextCtrl")) 59 st.SetSizerProps(valign='center') 60 tc = wx.TextCtrl(cPane, wx.ID_ANY) 61 62 searchSt = wx.StaticText(cPane, wx.ID_ANY, 63 _(u"a search control")) 64 searchSt.SetSizerProps(valign='center') 65 searchC = wx.SearchCtrl(cPane, wx.ID_ANY) 66 67 sline = wx.StaticLine(pane, wx.ID_ANY) 68 sline.SetSizerProps(expand=True) 69 bPane = sc.SizedPanel(pane) 70 fB = wx.Button(bPane, wx.ID_ANY, _(u"Open a file dialog")) 71 fB.SetSizerProps(align="center") 72 fB.Bind(wx.EVT_BUTTON, self.onFbButton) 73 74 def onFbButton(self, event): 75 wildcard = "Python source (*.py)|*.py|" \ 76 "Compiled Python (*.pyc)|*.pyc|" \ 77 "SPAM files (*.spam)|*.spam|" \ 78 "Egg file (*.egg)|*.egg|" \ 79 "All files (*.*)|*.*" 80 81 with wx.FileDialog( 82 self, message=_(u"Choose a file"), 83 defaultDir=os.getcwd(), 84 defaultFile="", 85 wildcard=wildcard, 86 style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_CHANGE_DIR 87 ) as dlg: 88 89 # Show the dialog and retrieve the user response. If it is the 90 # OK response, 91 # process the data. 92 if dlg.ShowModal() == wx.ID_OK: 93 # This returns a Python list of files that were selected. 94 paths = dlg.GetPaths() 95 96 def onClose(self, event): 97 event.Skip() 98 99 def doEditSomething(self, event): 100 event.Skip() 101 102 def doAboutBox(self, event): 103 event.Skip() 104 105if __name__ == '__main__': 106 import app_base as ab 107 app = ab.BaseApp(redirect=False) 108 109 frame = AppI18N(None) 110 frame.Show() 111 app.MainLoop() 112