Wxwidgets' messages in Spanish

Monday, June 18, 2007

In a cpp wxwidgets app...

1 - Within the source wxwidgets , there's a samples folder.

2 - cd to samples folder , and then to calendar folder.

3 - Add this line before the end of the wxApp class in calendar.cpp...


wxLocale m_locale;

4 - Add these four at the beginning of the OnInit method of the inherited wxApp...

if( m_locale.Init()){
m_locale.AddCatalog(wxT("es"));
m_locale.AddCatalogLookupPathPrefix( wxT("."));

}

5 - Compile the sample with ... make -f makefile.unx ( this in MacOSX or any Unix)

6 - Do this if in MacOSX ...

$ mkdir calendar.app
$ cd calendar.app
$ mkdir Contents
$ cd Contents
$ mkdir MacOS
$ cd MacOS
$ ln -s ../../../calendar calendar
$ cd ../../..
$ open calendar.app

7 - If everything goes as expected days and months of the calendar widget get displayed in spanish.

In you want to apply this in a wxpython program...

1 - If you started your wxpython program with wx.PySimpleApp, ie ...
app = wx.PySimpleApp()

2 - add these lines after that ...

locale = wx.Locale()
if locale.Init(wx.LANGUAGE_DEFAULT , wx.LOCALE_LOAD_DEFAULT | wx.LOCALE_CONV_ENCODING ):
locale.AddCatalog("es")
locale.AddCatalogLookupPathPrefix(".")


3 - After this if your program , for example, uses wx.PreviewFrame, all messages in the frame and widgets will be displayed in Spanish!

wxPython ArtProvider images mini browser

Friday, March 23, 2007


import wx
class MyFrame(wx.Frame):
def __init__(self):
title = "wx.ART browser"
wx.Frame.__init__(self, None, -1, title, size = (200,300))

li = ["wx.%s" % x for x in dir(wx) if x.startswith("ART")]

lb = wx.ListBox(self, -1, choices = li, style=wx.LB_SINGLE)
self.sb = wx.StaticBitmap(self, -1, wx.ArtProvider.GetBitmap(eval(li[0])))

sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(lb)
sizer.Add( [ 20, 20 ] , 0, wx.ALIGN_CENTER|wx.ALL, 5 )
sizer.Add(self.sb, wx.ALIGN_CENTER|wx.ALL, 5)
self.SetSizer(sizer)

self.Bind(wx.EVT_LISTBOX, self.OnUpdateBitmap, lb)

def OnUpdateBitmap(self, event):
name = event.GetString()
im = wx.ArtProvider.GetBitmap(eval(name))
w, h = im.GetSize()
self.sb.SetSize((w,h))
self.sb.SetBitmap(im)


app = wx.PySimpleApp()
f = MyFrame()
f.Center()
f.Show()
app.MainLoop()