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()

Scp of a screenshot ( using wxpython and paramiko )

Thursday, November 16, 2006

Try this one.
This takes a screenshot and send it to a server using scp ( paramiko )
All you need is WxPython.



import wx
import paramiko
import sys
from time import sleep

class Screenshot(object):
def __init__(self, filename = "snap.png"):
self.filename = filename
try:
p = wx.GetDisplaySize()
self.p = p
bitmap = wx.EmptyBitmap( p.x, p.y)
dc = wx.ScreenDC()
memdc = wx.MemoryDC()
memdc.SelectObject(bitmap)
memdc.Blit(0,0, p.x, p.y, dc, 0,0)
memdc.SelectObject(wx.NullBitmap)
bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG )

except:
self.filename = ""

def main():
paramiko.util.log_to_file('snap.log')

caption = u"Required data"
path = "/var/www/html/screenshots" # change this to make it your default path
hostname = "www.whateverdomain.com" # change this to make it your default targe host
username = "batok" # change this to make it your default user
port = 22 # change this to another port if necessary....

app = wx.PySimpleApp()
time_to_wait = wx.GetNumberFromUser(message = "Time",
prompt = "Secs.",
caption = "Enter Seconds to Wait...",
value = 5,
min = 5,
max = 20,
parent= None )
try:
tw = int(time_to_wait)
except:
sys.exit(-1)
sleep( tw )
try:
wx.Bell()
except:
pass

s_shot = Screenshot()

filename = s_shot.filename
if filename == "":
sys.exit(-1)

if wx.YES == wx.MessageBox("Do you want to see the screenshot/nreduced by the half ?", "Hey!", wx.YES_NO | wx.ICON_QUESTION):
dlg = wx.Dialog(None,-1, "Your screenshot half the size")
img = wx.Image("snap.png" , wx.BITMAP_TYPE_ANY)
w = img.GetWidth()
h = img.GetHeight()
img2 = img.Scale(w/2,h/2)
wx.StaticBitmap(dlg,-1, wx.BitmapFromImage(img2))
dlg.Fit()
dlg.Show()


target = "%s/%s" % ( path, filename )
wx.MessageBox("A %s X %s screenshot\nis at %s" % (s_shot.p.x, s_shot.p.y, filename ), "Hey!")
hostname = wx.GetTextFromUser("Host", caption = caption , default_value=hostname)
username = wx.GetTextFromUser("User Name", caption = caption , default_value=username)
password = wx.GetPasswordFromUser("Password", caption = caption )
s_target = wx.GetTextFromUser("Destination File", caption= caption, default_value = target)

if "" in (hostname, username, s_target):
wx.MessageBox("Mmmm... some required fields are empty", "Hey!")
sys.exit(-1)

# Now paramiko's stuff... a.k.a secure copy
try:

t = paramiko.Transport((hostname, port))
t.use_compression(True)
t.connect(username=username, password=password, hostkey=None)
sftp = paramiko.SFTPClient.from_transport(t)
data = open(filename, 'rb').read()
sftp.open(s_target, 'wb').write(data)
t.close()
wx.MessageBox("The %s file was sent to server" % filename, "Hey!")

except Exception, e:
print e
try:
t.close()
except:
pass

return

if __name__ == "__main__":
main()

Turbogears and Genshi baby steps

Wednesday, September 20, 2006

These are the baby steps for using Genshi template system in Turbogears.

1 - In case you have not installed Genshi do....
easy_install Genshi

2 - Create a new turbogears project with...
tg-admin quickstart genshibasic

3 - Go to controllers.py in ./genshibasic/genshibasic directory

add this to the Root class


@expose(template="genshi:genshibasic.templates.genshi")
def genshi(self):
return dict(pretty="basic")


4 - create a new template file ( genshi.html ) in the templates directory of the project.

include this in genshi.html ...

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
lang="en">
pretty ${pretty}
</html>

5 - Start your project with

python start-genshibasic.py


6 - Open your browser and type http://localhost:8080/genshi

Enjoy!
The rest is to study carefully genshi documentation to be a black belt.

A snap of the screen in wxPython and scp afterwards

Wednesday, August 30, 2006

This python program takes a snapshot of the screen, saving it to snap.png file, and copying the file via sftp to a server.

Python 2.4 , Wxpython and paramiko are required.


---------------------------------------------------


import wx
import paramiko

paramiko.util.log_to_file('snap.log')
filename = "snap.png"
app = wx.PySimpleApp()
p = wx.GetDisplaySize()
bitmap = wx.EmptyBitmap( p.x, p.y)
dc = wx.ScreenDC()
memdc = wx.MemoryDC()
memdc.SelectObject(bitmap)
memdc.Blit(0,0, p.x, p.y, dc, 0,0)
memdc.SelectObject(wx.NullBitmap)
bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG )
hostname = wx.GetTextFromUser("Host")
username = wx.GetTextFromUser("User Name")
password = wx.GetPasswordFromUser("Password")
port = 22

wx.MessageBox("A %s X %s snap of the screen\nis at %s" % (p.x, p.y, filename ), "Hey!")

try:
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password, hostkey=None)
sftp = paramiko.SFTPClient.from_transport(t)

data = open(filename, 'rb').read()
sftp.open(filename, 'wb').write(data)

t.close()
wx.MessageBox("The %s file was sent to server" % filename, "Hey!")

except Exception, e:
print e
try:
t.close()
except:
pass

A snap of the screen in wxPython

Saturday, August 26, 2006

This python program takes a snapshot of the screen.
WxPython is required.

import wx
filename = "snap.png"
app = wx.PySimpleApp()
p = wx.GetDisplaySize()
bitmap = wx.EmptyBitmap( p.x, p.y)
dc = wx.ScreenDC()
memdc = wx.MemoryDC()
memdc.SelectObject(bitmap)
memdc.Blit(0,0, p.x, p.y, dc, 0,0)
memdc.SelectObject(wx.NullBitmap)
bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG )
wx.MessageBox("A %s X %s snap of the screen\nis at %s" % (p.x, p.y, filename ), "Hey!")

Friday, August 18, 2006


vmware server win32 console Posted by Picasa

In search of the python web framework

Saturday, June 03, 2006

-Look no further, a good guy yell me at IRC.
Try Nevow.

That was about a year and half.

-If you are looking for a python based web framework try Nevow!, this guy insisted.

There was no Turbogears or Django then, the very hyped framewords of these very days.

TG and Django have good screencast and nice looking websites. Speaking about their features, well, they seem very well integrated. In the case of TG, an impressive tie of disperate projects. Django includes everything from the same project.

Despite facts and popularity of the two, I still love the swiss army knife freedom and power of Nevow.

Nevow has nice features!

Tuesday, January 03, 2006

Nevow , a python based web construction toolkit , has a lot of nice features, that deserve attention:

1 - LivePage ( Ajax ).
2 - Canvas ( Flash to server ).
3 - XUL , the python way.
4 - Stan ( Python...ized XHTML )
5 - Formless ( automatic Form generation ).

Another one on wxPython

Tuesday, August 23, 2005

I've made a python class ( wxpython ) to dump the contents of a wx.Grid or wx.ListCtrl to an excel file.

The class and a demo app is available at www.smartics.biz/site/descargas/index_html

The messages of the class and the demo app are in spanish.

Swatch and sendxmpp to rescue!

Friday, August 12, 2005

In these days there are lots of kids using hacking tools that try to log in via ssh.

My servers are attacked every day in this way.

I decided to add swatch to monitor log files.

Also I installed sendxmpp to send xmpp messages ( jabber ) to my jabber server.

The combination is great!

Both tools, swatch and sendxmpp are written in Perl, and to be installed depend on other perl modules which are properly installed via cpan.

wxPython!

Tuesday, August 09, 2005

wxPython , the marriage of wxWidgets and Python , is a very good option to develop multiplatform GUI apps.

Windows installation is a matter of running and exe, and follow the wizard.

For Mac OS X is a little bit trickier.

And for Linux , depends on the distro. For fedora core 3 or 4 is about compiling RPM source files and then installing the resulting binary RPM files.

Tuesday, May 24, 2005


my desktop Posted by Hello

Tips for today

Saturday, October 02, 2004

Fedora core 2:

Everything was ok with one of my customers. Each user accesing a dos based app from dosemu/freedos had been working smooth... until fedora core 2 arrived...

Well the change from Xfree86 to X.org had its consequences. The new fedora user couldn't run the app as the other people ( which had Mandrake and Redhat 8 and 9 installed ).

After several tries I decided to access the app from one of the RH9 users. So I did this bash script:

#!/bin/sh

FONTDIR=/home/blabla/dosemu/Xfonts
cd $FONTDIR
mkfontdir
xset +fp $FONTDIR
ssh user@machine "dosemu/xdosemu"



.....

Now the problem was with Squid...

How to make a user access everything related to yahoo but nothing else ?

The trick was editing the /etc/squid/squid.conf file by prepending the domain def in dstdomain directive with a . ( dot ) like this ...

acl yahoouser src 192.168.0.152

acl yahoo dstdomain .yahoo.com
acl yahoo2 dstdomain .yimg.com
http_access deny yahoouser !yahoo !yahoo2

( See the . before yahoo.com and yimg.com )



Tuesday, September 28, 2004


Introducing my dhcpf.conf file Posted by Hello

One more on Squid

Sunday, September 26, 2004

One example on configuring squid to let navigate user(s) only to selected places ( it needs Squid to be run on the machine which is resolving names [ may be using bind with resolv.conf pointing to 127.0.0.1 ]. Once I tried this on a machine which was resolved by another one and the dstdomain feature didn't work ):

acl myipaddress src 192.168.0.111
acl firstdomain dstdomain www.oneallowed.com
acl seconddomain dstdomain www.anotherallowed.com
...
...
http_access deny myipaddress !firstdomain !seconddomain

( this means , 192.168.0.111 can't access anything but www.oneallowed and www.anotherallowed ).

Friday, September 24, 2004


Tks Robert for the help on Combos Posted by Hello


Ladies and Gentlemen: Bullwinkle Posted by Hello

Screwdrivers

Thursday, September 23, 2004

One pseudo-cop got my 6 screwdriver set at Mexico City International Airport just before departure:

- You can't have these on the plane.

- Why not, do I look like a terrorist or what?

- No Mr. you don't. You have to go where the clerk is ( 2 miles away ).

- Hey Pal, my plane is about to take off and I need to...

- You must go where the clerk.

Suddenly I looked over my shoulders and the screen displayed -- 5 minutes to go.

- Mmm. Happy Birthday ( damn cop ) . This is my gift ( fk* asshole ).

Goodbye screwdriver set :(

Moral : "Never get a screwdriver set at Mexico City Airport"

this is an audio post - click to play



Music and Lyrics by Mr. Louis Klink