Added some modules from Riaan Booysen:

* wx.lib.flagart:  contains icons of the flags of many countries.

    * wx.lib.art.img2pyartprov: makes images embedded in a python file
      with img2py available via the wx.ArtProvider.

    * wx.lib.langlistctrl: A wx.ListCtrl for selecting a language,
      which uses the country flag icons.

    * An I18N sample for the demo.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43737 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2006-12-02 04:51:13 +00:00
parent d8dd53b239
commit 13db99f1f5
22 changed files with 5993 additions and 110 deletions

231
wxPython/demo/I18N.py Normal file
View File

@@ -0,0 +1,231 @@
#Boa:FramePanel:LanguageSelectPanel
import os, sys
import wx
from wx.lib import langlistctrl
from Main import opj
# Normally you would just set _ to be a reference to the
# wx.GetTranslation function, and then wrap all you literal strings in
# _() function calls. Then everytime you use one of your literals, it
# would first pass through the translation function and try to load a
# translated version of the string from the current message catalogs.
# For this example, since we are changinb language on the fly, and
# since we are only translating the label for one widget, we'll not do
# it the automatic way and we'll be more explicit. See the setup in
# __init__() and the translation done in updateLanguage() below.
_ = wx.GetTranslation
exampleStrings = [
'the quick brown fox jumps over the lazy dog', # demo string
'Tip of the Day', # wx built in translation
'Warning', # wx built in translation
]
[wxID_LANGUAGESELECTPANEL, wxID_LANGUAGESELECTPANELENGLISHBASECH,
wxID_LANGUAGESELECTPANELLANGCTRLCONTAINER,
wxID_LANGUAGESELECTPANELLANGFILTERRB, wxID_LANGUAGESELECTPANELSTATICLINE1,
wxID_LANGUAGESELECTPANELSTATICTEXT1, wxID_LANGUAGESELECTPANELSTATICTEXT2,
wxID_LANGUAGESELECTPANELSTATICTEXT3, wxID_LANGUAGESELECTPANELTRANSLATEDST,
] = [wx.NewId() for _init_ctrls in range(9)]
class LanguageSelectPanel(wx.Panel):
def _init_coll_boxSizer3_Items(self, parent):
# generated method, don't edit
parent.AddWindow(self.langCtrlContainer, 1, border=0, flag=wx.GROW)
parent.AddSpacer(wx.Size(8, 8), border=0, flag=0)
parent.AddWindow(self.langFilterRB, 0, border=0, flag=0)
def _init_coll_flexGridSizer1_Growables(self, parent):
# generated method, don't edit
parent.AddGrowableRow(1)
parent.AddGrowableCol(0)
def _init_coll_boxSizer1_Items(self, parent):
# generated method, don't edit
parent.AddWindow(self.staticText1, 0, border=8, flag=wx.ALL)
parent.AddSizer(self.boxSizer3, 1, border=8, flag=wx.ALL | wx.GROW)
parent.AddSizer(self.boxSizer2, 0, border=8, flag=wx.GROW | wx.ALL)
def _init_coll_boxSizer2_Items(self, parent):
# generated method, don't edit
parent.AddWindow(self.staticText2, 0, border=8, flag=wx.ALL)
parent.AddWindow(self.englishBaseCh, 0, border=8, flag=wx.GROW | wx.ALL)
parent.AddWindow(self.staticLine1, 0, border=8, flag=wx.GROW | wx.ALL)
parent.AddWindow(self.staticText3, 0, border=8, flag=wx.ALL)
parent.AddWindow(self.translatedST, 0, border=8, flag=wx.GROW | wx.ALL)
def _init_sizers(self):
# generated method, don't edit
self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)
self.flexGridSizer1 = wx.FlexGridSizer(cols=2, hgap=8, rows=0, vgap=8)
self.boxSizer3 = wx.BoxSizer(orient=wx.HORIZONTAL)
self.boxSizer2 = wx.BoxSizer(orient=wx.VERTICAL)
self._init_coll_boxSizer1_Items(self.boxSizer1)
self._init_coll_flexGridSizer1_Growables(self.flexGridSizer1)
self._init_coll_boxSizer3_Items(self.boxSizer3)
self._init_coll_boxSizer2_Items(self.boxSizer2)
self.SetSizer(self.boxSizer1)
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Panel.__init__(self, id=wxID_LANGUAGESELECTPANEL,
name='LanguageSelectPanel', parent=prnt,
style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE)
self.staticText1 = wx.StaticText(id=wxID_LANGUAGESELECTPANELSTATICTEXT1,
label='Choose a language that will be used for example translation.',
name='staticText1', parent=self, style=0)
self.langCtrlContainer = wx.Panel(id=wxID_LANGUAGESELECTPANELLANGCTRLCONTAINER,
name='langCtrlContainer', parent=self, style=wx.TAB_TRAVERSAL)
self.langCtrlContainer.SetBackgroundColour(wx.Colour(255, 255, 255))
self.langCtrlContainer.Bind(wx.EVT_SIZE, self.OnLangCtrlContainerSize)
self.langFilterRB = wx.RadioBox(choices=['Translated example languages',
'Available languages on your system', 'All languages'],
id=wxID_LANGUAGESELECTPANELLANGFILTERRB, label='Filter',
majorDimension=1, name='langFilterRB', parent=self,
style=wx.RA_SPECIFY_COLS)
self.langFilterRB.Bind(wx.EVT_RADIOBOX, self.OnLangFilterRBRadiobox,
id=wxID_LANGUAGESELECTPANELLANGFILTERRB)
self.staticText2 = wx.StaticText(id=wxID_LANGUAGESELECTPANELSTATICTEXT2,
label='English Text:', name='staticText2', parent=self,
style=0)
self.staticText3 = wx.StaticText(id=wxID_LANGUAGESELECTPANELSTATICTEXT3,
label='Translated Text:', name='staticText3', parent=self,
style=0)
self.englishBaseCh = wx.Choice(choices=self.choices,
id=wxID_LANGUAGESELECTPANELENGLISHBASECH, name='englishBaseCh',
parent=self, style=0)
self.englishBaseCh.Bind(wx.EVT_CHOICE, self.OnLangSelectAndTranslate,
id=wxID_LANGUAGESELECTPANELENGLISHBASECH)
self.staticLine1 = wx.StaticLine(id=wxID_LANGUAGESELECTPANELSTATICLINE1,
name='staticLine1', parent=self, style=0)
self.translatedST = wx.StaticText(id=wxID_LANGUAGESELECTPANELTRANSLATEDST,
label='', name='translatedST', parent=self, style=0)
self._init_sizers()
def __init__(self, parent, log):
self.choices = []
self.choices = exampleStrings
self._init_ctrls(parent)
self.log = log
lang = wx.LANGUAGE_DEFAULT
filter = 'demo'
langs = (wx.LANGUAGE_AFRIKAANS, wx.LANGUAGE_ENGLISH, wx.LANGUAGE_DEFAULT,
wx.LANGUAGE_SPANISH, wx.LANGUAGE_GERMAN, wx.LANGUAGE_ITALIAN,
wx.LANGUAGE_FRENCH)
# usually you would define wx.Locale in your wx.App.OnInit class.
# for the demo we just define it in this module
self.locale = None
wx.Locale.AddCatalogLookupPathPrefix(opj('data/locale'))
self.updateLanguage(wx.LANGUAGE_DEFAULT)
self.filterMap = {'demo': langlistctrl.LC_ONLY,
'available': langlistctrl.LC_AVAILABLE,
'all': langlistctrl.LC_ALL}
self.filterIdxMap = {0: 'demo',
1: 'available',
2: 'all'}
self.langs = langs
self.langCtrl = langlistctrl.LanguageListCtrl(self.langCtrlContainer, -1,
filter=self.filterMap[filter], only=langs, select=lang)
self.langCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnLangSelectAndTranslate)
self.langCtrl.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnClearTranslatedText)
self.OnLangCtrlContainerSize()
self.englishBaseCh.Select(0)
self.OnLangSelectAndTranslate()
def updateLanguage(self, lang):
# Make *sure* any existing locale is deleted before the new
# one is created. The old C++ object needs to be deleted
# before the new one is created, and if we just assign a new
# instance to the old Python variable, the old C++ locale will
# not be destroyed soon enough, likely causing a crash.
if self.locale:
assert sys.getrefcount(self.locale) <= 2
del self.locale
# create a locale object for this language
self.locale = wx.Locale(lang)
self.locale.AddCatalog('wxpydemo')
def translateExample(self):
self.translatedST.SetLabel(_(self.englishBaseCh.GetStringSelection()))
def OnLangCtrlContainerSize(self, event=None):
if event: event.Skip()
self.langCtrl.SetSize(self.langCtrlContainer.GetSize())
def OnLangFilterRBRadiobox(self, event):
self.langCtrl.SetUpFilter(
self.filterMap[self.filterIdxMap[self.langFilterRB.GetSelection()]],
self.langs)
def OnLangSelectAndTranslate(self, event=None):
lang = self.langCtrl.GetLanguage()
if lang is not None:
# set to the selected language
self.updateLanguage(lang)
self.translateExample()
# set back to default
self.updateLanguage(wx.LANGUAGE_DEFAULT)
def OnClearTranslatedText(self, event):
self.translatedST.SetLabel('')
def runTest(frame, nb, log):
win = LanguageSelectPanel(nb, log)
return win
#-------------------------------------------------------------------------------
overview = """<html><body>
<h2>Internationalization (I18N)</h2>
<p>
This demo demonstrates how to setup and use the wx.Locale object to translate text.
<p>
It also shows the langlistctrl.LanguageListCtrl that can be used to display
languages with their associated countries flags, e.g. for setting the language
in your application.
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -0,0 +1,98 @@
import wx
from wx.lib.art import flagart, img2pyartprov
FlagArtProvider = None
#----------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
title = wx.StaticText(self, -1, "Img2PyArtProvider")
title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
sizer.Add(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
sizer.Add((20,20))
box = wx.BoxSizer(wx.HORIZONTAL)
ch = wx.ComboBox(self, -1, 'BLANK', choices=flagart.index,
style=wx.CB_DROPDOWN|wx.CB_READONLY)
self.Bind(wx.EVT_COMBOBOX, self.OnSelectCountry, ch)
box.Add(ch, 0, wx.ALIGN_CENTER_VERTICAL)
box.Add((50,10))
bmp = wx.EmptyBitmap(32,22)
self.bmpFlag = wx.StaticBitmap(self, -1, bmp)
box.Add(self.bmpFlag, 0, wx.ALIGN_CENTER_VERTICAL)
sizer.Add(box, 0, wx.CENTER|wx.ALL, 10)
self.country = 'BLANK'
global FlagArtProvider
if FlagArtProvider is None:
FlagArtProvider = img2pyartprov.Img2PyArtProvider(flagart,
artIdPrefix='wx.ART_')
wx.ArtProvider.Push(FlagArtProvider)
self.getArt()
def OnSelectCountry(self, evt):
self.log.write("OnSelectCountry\n")
self.country = evt.GetString()
self.getArt()
def getArt(self):
bmp = wx.ArtProvider.GetBitmap('wx.ART_'+self.country, wx.ART_OTHER, (32,22))
if not bmp.Ok():
bmp = wx.EmptyBitmap(32,22)
self.clearBmp(bmp)
self.bmpFlag.SetBitmap(bmp)
def clearBmp(self, bmp):
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.SetBackground(wx.Brush("white"))
dc.Clear()
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
overview = """<html><body>
<h2><center>Img2PyArtProvider</center></h2>
Img2PyArtProvider is an ArtProvider class that publishes images from
modules generated by img2py.
<p>
This sample shows how to access the flag images in wx.lib.art.flagart
via the ArtProvider.
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

View File

@@ -73,6 +73,8 @@ _treeList = [
'ComboCtrl',
'OwnerDrawnComboBox',
'BitmapComboBox',
'I18N',
'Img2PyArtProvider',
]),
# managed windows == things with a (optional) caption you can close
@@ -262,6 +264,7 @@ _treeList = [
'Image',
'ImageAlpha',
'ImageFromStream',
'Img2PyArtProvider',
'Mask',
'RawBitmapAccess',
'Throbber',
@@ -278,6 +281,7 @@ _treeList = [
'FontEnumerator',
'GraphicsContext',
'GLCanvas',
'I18N',
'Joystick',
'MimeTypesManager',
'MouseGestures',
@@ -997,7 +1001,7 @@ class DemoErrorPanel(wx.Panel):
boxInfoGrid = wx.FlexGridSizer(0, 2, 0, 0)
textFlags = wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT | wx.TOP
boxInfoGrid.Add(wx.StaticText(self, -1, "Type: "), 0, textFlags, 5 )
boxInfoGrid.Add(wx.StaticText(self, -1, demoError.exception_type) , 0, textFlags, 5 )
boxInfoGrid.Add(wx.StaticText(self, -1, str(demoError.exception_type)) , 0, textFlags, 5 )
boxInfoGrid.Add(wx.StaticText(self, -1, "Details: ") , 0, textFlags, 5 )
boxInfoGrid.Add(wx.StaticText(self, -1, demoError.exception_details) , 0, textFlags, 5 )
boxInfoSizer.Add(boxInfoGrid, 0, wx.ALIGN_CENTRE | wx.ALL, 5 )

View File

@@ -0,0 +1,23 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: wxPython i18n demo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-12-01 09:52-0800\n"
"PO-Revision-Date: 2006-12-01 11:11-0800\n"
"Last-Translator: Robin Dunn <robin@alldunn.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: Afrikaans\n"
"X-Poedit-Country: SOUTH AFRICA\n"
#: I18N.py:9
msgid "the quick brown fox jumps over the lazy dog"
msgstr "die vinnige bruin vos spring oor die lui hond"

View File

@@ -0,0 +1,23 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: wxPython i18n demo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-12-01 09:52-0800\n"
"PO-Revision-Date: 2006-12-01 11:16-0800\n"
"Last-Translator: Robin Dunn <robin@alldunn.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
#: I18N.py:9
msgid "the quick brown fox jumps over the lazy dog"
msgstr "der schnelle braune Fuchs sprang über den faulen Hund"

View File

@@ -0,0 +1,22 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: wxPython i18n demo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-12-01 09:52-0800\n"
"PO-Revision-Date: 2006-12-01 11:25-0800\n"
"Last-Translator: Robin Dunn <robin@alldunn.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: Spanish\n"
#: I18N.py:9
msgid "the quick brown fox jumps over the lazy dog"
msgstr "el zorro marrón rápido saltó sobre el perro perezoso"

View File

@@ -0,0 +1,22 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: wxPython i18n demo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-12-01 09:52-0800\n"
"PO-Revision-Date: 2006-12-01 11:14-0800\n"
"Last-Translator: Robin Dunn <robin@alldunn.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: French\n"
#: I18N.py:9
msgid "the quick brown fox jumps over the lazy dog"
msgstr "le renard brun rapide a sauté par-dessus le chien paresseux"

View File

@@ -0,0 +1,15 @@
#!/bin/bash
#----------------------------------------------------------------------
# Run msgfmt on all the .po files, and install them to ../locale
#----------------------------------------------------------------------
DEST=../locale
NAME=wxpydemo
for po in ??.po ??_??.po; do
echo compiling message catalog for $po
BASE=`basename $po .po`
mkdir -p $DEST/$BASE/LC_MESSAGES
msgfmt -o $DEST/$BASE/LC_MESSAGES/$NAME.mo $po
done

View File

@@ -0,0 +1,23 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: wxPython i18n demo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-12-01 09:52-0800\n"
"PO-Revision-Date: 2006-12-01 11:17-0800\n"
"Last-Translator: Robin Dunn <robin@alldunn.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: Italian\n"
"X-Poedit-Country: ITALY\n"
#: I18N.py:9
msgid "the quick brown fox jumps over the lazy dog"
msgstr "la volpe marrone rapida ha saltato sopra il cane pigro"

View File

@@ -0,0 +1,21 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: wxPython i18n demo\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-12-01 09:52-0800\n"
"PO-Revision-Date: 2006-12-01 11:08-0800\n"
"Last-Translator: Robin Dunn <robin@alldunn.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: I18N.py:9
msgid "the quick brown fox jumps over the lazy dog"
msgstr ""

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.