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.

View File

@ -45,6 +45,13 @@ wxPython/demo
wxPython/demo/bitmaps
wxPython/demo/bmp_source
wxPython/demo/data
wxPython/demo/data/locale-src
wxPython/demo/data/locale
wxPython/demo/data/locale/af/LC_MESSAGES
wxPython/demo/data/locale/de/LC_MESSAGES
wxPython/demo/data/locale/es/LC_MESSAGES
wxPython/demo/data/locale/fr/LC_MESSAGES
wxPython/demo/data/locale/it/LC_MESSAGES
wxPython/demo/dllwidget
wxPython/distrib
wxPython/distrib/all
@ -107,6 +114,7 @@ wxPython/wx/build
wxPython/wx/lib
wxPython/wx/lib/analogclock
wxPython/wx/lib/analogclock/lib_setup
wxPython/wx/lib/art
wxPython/wx/lib/colourchooser
wxPython/wx/lib/editor
wxPython/wx/lib/floatcanvas

View File

@ -113,6 +113,7 @@ Source: "wx\build\*.py"; DestDir: "{app}\%(PKGDIR)s\wx\bui
Source: "wx\lib\*.py"; DestDir: "{app}\%(PKGDIR)s\wx\lib"; Components: core
Source: "wx\lib\analogclock\*.py"; DestDir: "{app}\%(PKGDIR)s\wx\lib\analogclock"; Components: core
Source: "wx\lib\analogclock\lib_setup\*.py"; DestDir: "{app}\%(PKGDIR)s\wx\lib\analogclock\lib_setup"; Components: core
Source: "wx\lib\art\*.py"; DestDir: "{app}\%(PKGDIR)s\wx\lib\art"; Components: core
Source: "wx\lib\colourchooser\*.py"; DestDir: "{app}\%(PKGDIR)s\wx\lib\colourchooser"; Components: core
Source: "wx\lib\editor\*.py"; DestDir: "{app}\%(PKGDIR)s\wx\lib\editor"; Components: core
Source: "wx\lib\editor\*.txt"; DestDir: "{app}\%(PKGDIR)s\wx\lib\editor"; Components: core
@ -418,6 +419,14 @@ Source: "demo\data\*.xrc"; DestDir: "{app}\demo\data";
Source: "demo\data\*.swf"; DestDir: "{app}\demo\data";
Source: "demo\data\*.mpg"; DestDir: "{app}\demo\data";
Source: "demo\data\locale-src\*.po"; DestDir: "{app}\demo\data\locale-src";
Source: "demo\data\locale-src\install"; DestDir: "{app}\demo\data\locale-src";
Source: "demo\data\locale\af\LC_MESSAGES\*.mo"; DestDir: "{app}\demo\data\locale\af\LC_MESSAGES";
Source: "demo\data\locale\de\LC_MESSAGES\*.mo"; DestDir: "{app}\demo\data\locale\de\LC_MESSAGES";
Source: "demo\data\locale\es\LC_MESSAGES\*.mo"; DestDir: "{app}\demo\data\locale\es\LC_MESSAGES";
Source: "demo\data\locale\fr\LC_MESSAGES\*.mo"; DestDir: "{app}\demo\data\locale\fr\LC_MESSAGES";
Source: "demo\data\locale\it\LC_MESSAGES\*.mo"; DestDir: "{app}\demo\data\locale\it\LC_MESSAGES";
;;Source: "demo\dllwidget\*.cpp"; DestDir: "{app}\demo\dllwidget";
;;Source: "demo\dllwidget\*.py"; DestDir: "{app}\demo\dllwidget";
;;Source: "demo\dllwidget\Makefile"; DestDir: "{app}\demo\dllwidget";

View File

@ -34,6 +34,18 @@ class which can be mixed with a wx.App class and provides a PyCrust
window that can be activated with a Ctrl-Alt-I keystroke (or Cmd-Alt-I
on the Mac.)
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.

View File

@ -0,0 +1 @@
# package

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
#-----------------------------------------------------------------------------
# Name: img2pyartprov.py
# Purpose:
#
# Author: Riaan Booysen
#
# RCS-ID: $Id$
# Copyright: (c) 2006
# Licence: wxPython
#-----------------------------------------------------------------------------
""" ArtProvider class that publishes images from modules generated by img2py.
Image modules must be generated with the -u and -n <name> parameters.
Typical usage:
>>> import wx, wx.lib.art.img2pyartprov, myimagemodule
>>> wx.ArtProvider.PushProvider(wx.lib.art.img2pyartprov.Img2PyArtProvider(myimagemodule))
If myimagemodule.catalog['MYIMAGE'] is defined, it can be accessed as:
>>> wx.ArtProvider.GetBitmap('wxART_MYIMAGE')
"""
import wx
_NULL_BMP = wx.NullBitmap
class Img2PyArtProvider(wx.ArtProvider):
def __init__(self, imageModule, artIdPrefix='wxART_'):
self.catalog = {}
self.index = []
self.UpdateFromImageModule(imageModule)
self.artIdPrefix = artIdPrefix
wx.ArtProvider.__init__(self)
def UpdateFromImageModule(self, imageModule):
try:
self.catalog.update(imageModule.catalog)
except AttributeError:
raise Exception, 'No catalog dictionary defined for the image module'
try:
self.index.extend(imageModule.index)
except AttributeError:
raise Exception, 'No index list defined for the image module'
def GenerateArtIdList(self):
return [self.artIdPrefix+name for name in self.index]
def CreateBitmap(self, artId, artClient, size):
if artId.startswith(self.artIdPrefix):
name = artId[len(self.artIdPrefix):]
if name in self.catalog:
return self.catalog[name].getBitmap()
return _NULL_BMP

View File

@ -0,0 +1,424 @@
#-----------------------------------------------------------------------------
# Name: languagectrls.py
# Purpose:
#
# Author: Riaan Booysen
#
# Created: 2006
# RCS-ID: $Id$
# Copyright: (c) 2006 Riaan Booysen
# License: wxPython
#-----------------------------------------------------------------------------
""" ListCtrl and functions to display languages and the flags of their countries
"""
import wx
from wx.lib.art import flagart
langIdCountryMap = {
# generated from wx.Locale info and locale.windows_locale
wx.LANGUAGE_AFRIKAANS: 'ZA',
wx.LANGUAGE_ALBANIAN: 'AL',
wx.LANGUAGE_ARABIC_ALGERIA: 'DZ',
wx.LANGUAGE_ARABIC_BAHRAIN: 'BH',
wx.LANGUAGE_ARABIC_EGYPT: 'EG',
wx.LANGUAGE_ARABIC_IRAQ: 'IQ',
wx.LANGUAGE_ARABIC_JORDAN: 'JO',
wx.LANGUAGE_ARABIC_KUWAIT: 'KW',
wx.LANGUAGE_ARABIC_LEBANON: 'LB',
wx.LANGUAGE_ARABIC_LIBYA: 'LY',
wx.LANGUAGE_ARABIC_MOROCCO: 'MA',
wx.LANGUAGE_ARABIC_OMAN: 'OM',
wx.LANGUAGE_ARABIC_QATAR: 'QA',
wx.LANGUAGE_ARABIC_SAUDI_ARABIA: 'SA',
wx.LANGUAGE_ARABIC_SUDAN: 'SD',
wx.LANGUAGE_ARABIC_SYRIA: 'SY',
wx.LANGUAGE_ARABIC_TUNISIA: 'TN',
wx.LANGUAGE_ARABIC_UAE: 'AE',
wx.LANGUAGE_ARABIC_YEMEN: 'YE',
wx.LANGUAGE_ARMENIAN: 'AM',
wx.LANGUAGE_AZERI: 'AZ',
wx.LANGUAGE_AZERI_CYRILLIC: 'AZ',
wx.LANGUAGE_AZERI_LATIN: 'AZ',
wx.LANGUAGE_BASQUE: 'ES',
wx.LANGUAGE_BELARUSIAN: 'BY',
wx.LANGUAGE_BENGALI: 'IN',
wx.LANGUAGE_BRETON: 'FR',
wx.LANGUAGE_BULGARIAN: 'BG',
wx.LANGUAGE_CATALAN: 'ES',
wx.LANGUAGE_CHINESE: 'TW',
wx.LANGUAGE_CHINESE_HONGKONG: 'HK',
wx.LANGUAGE_CHINESE_MACAU: 'MO',
wx.LANGUAGE_CHINESE_SIMPLIFIED: 'CN',
wx.LANGUAGE_CHINESE_SINGAPORE: 'SG',
wx.LANGUAGE_CHINESE_TAIWAN: 'TW',
wx.LANGUAGE_CHINESE_TRADITIONAL: 'TW',
wx.LANGUAGE_CROATIAN: 'HR',
wx.LANGUAGE_CZECH: 'CZ',
wx.LANGUAGE_DANISH: 'DK',
# wx.LANGUAGE_DEFAULT: 'ZA',
wx.LANGUAGE_DUTCH: 'NL',
wx.LANGUAGE_DUTCH_BELGIAN: 'BE',
wx.LANGUAGE_ENGLISH: 'GB',
wx.LANGUAGE_ENGLISH_AUSTRALIA: 'AU',
wx.LANGUAGE_ENGLISH_BELIZE: 'BZ',
wx.LANGUAGE_ENGLISH_BOTSWANA: 'BW',
wx.LANGUAGE_ENGLISH_CANADA: 'CA',
wx.LANGUAGE_ENGLISH_CARIBBEAN: 'CB',
wx.LANGUAGE_ENGLISH_DENMARK: 'DK',
wx.LANGUAGE_ENGLISH_EIRE: 'IE',
wx.LANGUAGE_ENGLISH_JAMAICA: 'JM',
wx.LANGUAGE_ENGLISH_NEW_ZEALAND: 'NZ',
wx.LANGUAGE_ENGLISH_PHILIPPINES: 'PH',
wx.LANGUAGE_ENGLISH_SOUTH_AFRICA: 'ZA',
wx.LANGUAGE_ENGLISH_TRINIDAD: 'TT',
wx.LANGUAGE_ENGLISH_UK: 'GB',
wx.LANGUAGE_ENGLISH_US: 'US',
wx.LANGUAGE_ENGLISH_ZIMBABWE: 'ZW',
wx.LANGUAGE_ESTONIAN: 'EE',
wx.LANGUAGE_FAEROESE: 'FO',
wx.LANGUAGE_FARSI: 'IR',
wx.LANGUAGE_FINNISH: 'FI',
wx.LANGUAGE_FRENCH: 'FR',
wx.LANGUAGE_FRENCH_BELGIAN: 'BE',
wx.LANGUAGE_FRENCH_CANADIAN: 'CA',
wx.LANGUAGE_FRENCH_LUXEMBOURG: 'LU',
wx.LANGUAGE_FRENCH_MONACO: 'MC',
wx.LANGUAGE_FRENCH_SWISS: 'CH',
wx.LANGUAGE_FRISIAN: 'NL',
wx.LANGUAGE_GALICIAN: 'ES',
wx.LANGUAGE_GEORGIAN: 'GE',
wx.LANGUAGE_GERMAN: 'DE',
wx.LANGUAGE_GERMAN_AUSTRIAN: 'AT',
wx.LANGUAGE_GERMAN_BELGIUM: 'BE',
wx.LANGUAGE_GERMAN_LIECHTENSTEIN: 'LI',
wx.LANGUAGE_GERMAN_LUXEMBOURG: 'LU',
wx.LANGUAGE_GERMAN_SWISS: 'CH',
wx.LANGUAGE_GREEK: 'GR',
wx.LANGUAGE_GREENLANDIC: 'GL',
wx.LANGUAGE_GUJARATI: 'IN',
wx.LANGUAGE_HEBREW: 'IL',
wx.LANGUAGE_HINDI: 'IN',
wx.LANGUAGE_HUNGARIAN: 'HU',
wx.LANGUAGE_ICELANDIC: 'IS',
wx.LANGUAGE_INDONESIAN: 'ID',
wx.LANGUAGE_INUKTITUT: 'CA',
wx.LANGUAGE_IRISH: 'IE',
wx.LANGUAGE_ITALIAN: 'IT',
wx.LANGUAGE_ITALIAN_SWISS: 'CH',
wx.LANGUAGE_JAPANESE: 'JP',
wx.LANGUAGE_KANNADA: 'IN',
wx.LANGUAGE_KASHMIRI_INDIA: 'IN',
wx.LANGUAGE_KAZAKH: 'KZ',
wx.LANGUAGE_KERNEWEK: 'GB',
wx.LANGUAGE_KIRGHIZ: 'KG',
wx.LANGUAGE_KOREAN: 'KR',
wx.LANGUAGE_LATVIAN: 'LV',
wx.LANGUAGE_LITHUANIAN: 'LT',
wx.LANGUAGE_MACEDONIAN: 'MK',
wx.LANGUAGE_MALAY: 'MY',
wx.LANGUAGE_MALAYALAM: 'IN',
wx.LANGUAGE_MALAY_BRUNEI_DARUSSALAM: 'BN',
wx.LANGUAGE_MALAY_MALAYSIA: 'MY',
wx.LANGUAGE_MALTESE: 'MT',
wx.LANGUAGE_MAORI: 'NZ',
wx.LANGUAGE_MARATHI: 'IN',
wx.LANGUAGE_MONGOLIAN: 'MN',
wx.LANGUAGE_NEPALI: 'NP',
wx.LANGUAGE_NEPALI_INDIA: 'IN',
wx.LANGUAGE_NORWEGIAN_BOKMAL: 'NO',
wx.LANGUAGE_NORWEGIAN_NYNORSK: 'NO',
wx.LANGUAGE_OCCITAN: 'FR',
wx.LANGUAGE_ORIYA: 'IN',
wx.LANGUAGE_PASHTO: 'AF',
wx.LANGUAGE_POLISH: 'PL',
wx.LANGUAGE_PORTUGUESE: 'PT',
wx.LANGUAGE_PORTUGUESE_BRAZILIAN: 'BR',
wx.LANGUAGE_PUNJABI: 'IN',
wx.LANGUAGE_RHAETO_ROMANCE: 'CH',
wx.LANGUAGE_ROMANIAN: 'RO',
wx.LANGUAGE_RUSSIAN: 'RU',
wx.LANGUAGE_RUSSIAN_UKRAINE: 'UA',
wx.LANGUAGE_SANSKRIT: 'IN',
wx.LANGUAGE_SERBIAN_CYRILLIC: 'YU',
wx.LANGUAGE_SERBIAN_LATIN: 'YU',
wx.LANGUAGE_SETSWANA: 'ZA',
wx.LANGUAGE_SLOVAK: 'SK',
wx.LANGUAGE_SLOVENIAN: 'SI',
wx.LANGUAGE_SPANISH: 'ES',
wx.LANGUAGE_SPANISH_ARGENTINA: 'AR',
wx.LANGUAGE_SPANISH_BOLIVIA: 'BO',
wx.LANGUAGE_SPANISH_CHILE: 'CL',
wx.LANGUAGE_SPANISH_COLOMBIA: 'CO',
wx.LANGUAGE_SPANISH_COSTA_RICA: 'CR',
wx.LANGUAGE_SPANISH_DOMINICAN_REPUBLIC: 'DO',
wx.LANGUAGE_SPANISH_ECUADOR: 'EC',
wx.LANGUAGE_SPANISH_EL_SALVADOR: 'SV',
wx.LANGUAGE_SPANISH_GUATEMALA: 'GT',
wx.LANGUAGE_SPANISH_HONDURAS: 'HN',
wx.LANGUAGE_SPANISH_MEXICAN: 'MX',
wx.LANGUAGE_SPANISH_MODERN: 'ES',
wx.LANGUAGE_SPANISH_NICARAGUA: 'NI',
wx.LANGUAGE_SPANISH_PANAMA: 'PA',
wx.LANGUAGE_SPANISH_PARAGUAY: 'PY',
wx.LANGUAGE_SPANISH_PERU: 'PE',
wx.LANGUAGE_SPANISH_PUERTO_RICO: 'PR',
wx.LANGUAGE_SPANISH_URUGUAY: 'UY',
wx.LANGUAGE_SPANISH_US: 'US',
wx.LANGUAGE_SPANISH_VENEZUELA: 'VE',
wx.LANGUAGE_SWAHILI: 'KE',
wx.LANGUAGE_SWEDISH: 'SE',
wx.LANGUAGE_SWEDISH_FINLAND: 'FI',
wx.LANGUAGE_TAGALOG: 'PH',
wx.LANGUAGE_TAMIL: 'IN',
wx.LANGUAGE_TATAR: 'RU',
wx.LANGUAGE_TELUGU: 'IN',
wx.LANGUAGE_THAI: 'TH',
wx.LANGUAGE_TURKISH: 'TR',
wx.LANGUAGE_UKRAINIAN: 'UA',
wx.LANGUAGE_URDU: 'PK',
wx.LANGUAGE_URDU_INDIA: 'IN',
wx.LANGUAGE_URDU_PAKISTAN: 'PK',
wx.LANGUAGE_UZBEK: 'UZ',
wx.LANGUAGE_UZBEK_CYRILLIC: 'UZ',
wx.LANGUAGE_UZBEK_LATIN: 'UZ',
wx.LANGUAGE_VIETNAMESE: 'VN',
wx.LANGUAGE_WELSH: 'GB',
wx.LANGUAGE_XHOSA: 'ZA',
wx.LANGUAGE_ZULU: 'ZA',
# manually defined language/country mapping
wx.LANGUAGE_ABKHAZIAN: 'GE',
wx.LANGUAGE_AFAR: 'ET',
wx.LANGUAGE_AMHARIC: 'ET',
wx.LANGUAGE_ASSAMESE: 'IN',
wx.LANGUAGE_AYMARA: 'BO',
wx.LANGUAGE_ARABIC: 'SA',
wx.LANGUAGE_BASHKIR: 'RU',
wx.LANGUAGE_BHUTANI: 'BT',
wx.LANGUAGE_BIHARI: 'IN',
wx.LANGUAGE_BISLAMA: 'VU',
wx.LANGUAGE_BURMESE: 'MM',
wx.LANGUAGE_CAMBODIAN: 'KH',
wx.LANGUAGE_CORSICAN: 'FR',
wx.LANGUAGE_ESPERANTO: 'ESPERANTO',
wx.LANGUAGE_FIJI: 'FJ',
wx.LANGUAGE_GUARANI: 'PY',
wx.LANGUAGE_HAUSA: 'NG',
wx.LANGUAGE_INTERLINGUA: 'US',
wx.LANGUAGE_INTERLINGUE: 'US',
wx.LANGUAGE_INUPIAK: 'US',
wx.LANGUAGE_JAVANESE: 'IN',
wx.LANGUAGE_KASHMIRI: 'IN',
wx.LANGUAGE_KINYARWANDA: 'RW',
wx.LANGUAGE_KIRUNDI: 'BI',
wx.LANGUAGE_KONKANI: 'IN',
wx.LANGUAGE_KURDISH: 'IQ',
wx.LANGUAGE_LAOTHIAN: 'LA',
wx.LANGUAGE_LATIN: 'VA',
wx.LANGUAGE_LINGALA: 'CD',
wx.LANGUAGE_MALAGASY: 'MG',
wx.LANGUAGE_MANIPURI: 'IN',
wx.LANGUAGE_MOLDAVIAN: 'MD',
wx.LANGUAGE_NAURU: 'NR',
wx.LANGUAGE_OROMO: 'ET',
wx.LANGUAGE_QUECHUA: 'BO',
wx.LANGUAGE_SAMOAN: 'WS',
wx.LANGUAGE_SANGHO: 'CF',
wx.LANGUAGE_SCOTS_GAELIC: 'GB',
wx.LANGUAGE_SERBO_CROATIAN: 'HR',
wx.LANGUAGE_SESOTHO: 'ZA',
wx.LANGUAGE_SHONA: 'ZW',
wx.LANGUAGE_SINDHI: 'PK',
wx.LANGUAGE_SINHALESE: 'IN',
wx.LANGUAGE_SISWATI: 'SZ',
wx.LANGUAGE_SOMALI: 'SB',
wx.LANGUAGE_SUNDANESE: 'SD',
wx.LANGUAGE_TAJIK: 'TJ',
wx.LANGUAGE_TIBETAN: 'CN',
wx.LANGUAGE_TIGRINYA: 'ET',
wx.LANGUAGE_TONGA: 'TO',
wx.LANGUAGE_TSONGA: 'MZ',
wx.LANGUAGE_TURKMEN: 'TM',
wx.LANGUAGE_TWI: 'GH',
wx.LANGUAGE_UIGHUR: 'CN',
wx.LANGUAGE_VOLAPUK: 'VOLAPUK',
wx.LANGUAGE_WOLOF: 'SN',
wx.LANGUAGE_YIDDISH: 'IL',
wx.LANGUAGE_YORUBA: 'NG',
wx.LANGUAGE_ZHUANG: 'CN',
}
LC_AVAILABLE, LC_ALL, LC_ONLY = 1, 2, 4
# wx.LANGUAGE_SERBIAN gives an error for me
_wxLangIds = [n for n in dir(wx) if n.startswith('LANGUAGE_')]
for _l in ('LANGUAGE_UNKNOWN', 'LANGUAGE_USER_DEFINED', 'LANGUAGE_SERBIAN'):
if _l in _wxLangIds:
_wxLangIds.remove(_l)
def CreateLanguagesResourceLists(filter=LC_AVAILABLE, only=()):
""" Returns a tuple of (bitmaps, language descriptions, language ids) """
icons = wx.ImageList(16, 11)
names = []
langs = []
langIdNameMap = BuildLanguageCountryMapping()
wxLangIds = []
for li in _wxLangIds:
wxLI = getattr(wx, li)
try:
if (filter == LC_ONLY and wxLI in only) or \
(filter == LC_AVAILABLE and wx.Locale.IsAvailable(wxLI)) or \
(filter == LC_ALL):
wxLangIds.append(wxLI)
except wx.PyAssertionError:
# invalid language assertions
pass
except AttributeError:
# wx 2.6
wxLangIds.append(wxLI)
langCodes = [(langIdNameMap[wxLangId], wxLangId)
for wxLangId in wxLangIds
if wxLangId in langIdNameMap]
for lc, wxli in langCodes:
l, cnt = lc.split('_')
if cnt in flagart.catalog:
bmp = flagart.catalog[cnt].getBitmap()
else:
bmp = flagart.catalog['BLANK'].getBitmap()
icons.Add(bmp)
name = wx.Locale.GetLanguageName(wxli)
if wxli == wx.LANGUAGE_DEFAULT:
#print cnt, name, lc, wxli
name = 'Default: '+name
names.append(name)
langs.append(wxli)
return icons, names, langs
def GetLanguageFlag(lang):
""" Returns a bitmap of the flag for the country of the language id """
langIdNameMap = BuildLanguageCountryMapping()
if lang in langIdNameMap:
cnt = langIdNameMap[lang].split('_')[1]
if cnt in flagart.catalog:
return flagart.catalog[cnt].getBitmap()
return flagart.catalog['BLANK'].getBitmap()
def BuildLanguageCountryMapping():
""" Builds a mapping of language ids to LANG_COUNTRY codes """
res = {}
for name in _wxLangIds:
n = 'wx.'+name
wn = getattr(wx, name)
li = wx.Locale.GetLanguageInfo(wn)
if li:
code = li.CanonicalName
if wn in langIdCountryMap:
# override, drop country
if '_' in code:
code = code.split('_')[0]
code += '_'+langIdCountryMap[wn]
# map unhandled to blank images
elif '_' not in code:
code += '_BLANK'
res[wn] = code
return res
def GetWxIdentifierForLanguage(lang):
""" Returns the language id as a string """
for n in dir(wx):
if n.startswith('LANGUAGE_') and getattr(wx, n) == lang:
return n
raise Exception, 'Language %s not found'%lang
#-------------------------------------------------------------------------------
class LanguageListCtrl(wx.ListCtrl):
""" wx.ListCtrl derived control that displays languages and flags """
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.LC_REPORT | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL,
filter=LC_AVAILABLE, only=(), select=None, name='languagelistctrl'):
wx.ListCtrl.__init__(self, parent, id, pos, size, style, name=name)
self.SetUpFilter(filter, only)
self.Language = select
def SetUpFilter(self, filter=LC_AVAILABLE, only=()):
""" Filters the languages displayed in the control """
lang = self.GetLanguage()
self.filter, self.only = filter, only
self.icons, self.choices, self.langs = CreateLanguagesResourceLists(filter, only)
self.AssignImageList(self.icons, wx.IMAGE_LIST_SMALL)
self.ClearAll()
self.InsertColumn(0, '', width=175)
for i in range(len(self.choices)):
self.InsertImageStringItem(i, self.choices[i], i)
self.SetLanguage(lang)
def GetLanguage(self):
""" Returns the language id for the currently selected language in the control """
idx = self.GetFirstSelected()
if idx != -1:
return self.langs[idx]
else:
None
def SetLanguage(self, lang):
""" Selects the given language ids item in the control """
if lang is not None:
if lang in self.langs:
idx = self.langs.index(lang)
self.Select(idx)
self.Focus(idx)
Language = property(GetLanguage, SetLanguage, doc="See `GetLanguage` and `SetLanguage`")
#-------------------------------------------------------------------------------
if __name__ == '__main__':
a = wx.PySimpleApp()
print GetLanguageFlag(wx.LANGUAGE_AFRIKAANS)
f=wx.Frame(None, -1)
f.p=wx.Panel(f, -1)
s=wx.BoxSizer(wx.VERTICAL)
f.p.SetSizer(s)
try:
f.lc=LanguageChoice(f.p, pos = (220, 10), size = (200, 25))
s.Add(f.lc, 0, wx.GROW)
except:
pass
f.llc=LanguageListCtrl(f.p, pos = (10, 10), size = (200, 200),
filter=LC_ONLY,
only=(wx.LANGUAGE_AFRIKAANS, wx.LANGUAGE_ENGLISH,
wx.LANGUAGE_FRENCH, wx.LANGUAGE_GERMAN, wx.LANGUAGE_ITALIAN,
wx.LANGUAGE_PORTUGUESE_BRAZILIAN, wx.LANGUAGE_SPANISH),
select=wx.LANGUAGE_ENGLISH)
## filter=LC_ALL)
s.Add(f.llc, 1, wx.GROW)
f.Show()
a.MainLoop()