Ouch

I went to check my site a few minutes ago and found that any page I tried to access returned a “403 Forbidden” error. scary. So I spent a panicked 5 minutes checking error logs, .htaccess files, file permissions, folder permissions…of course the last thing I checked was the permissions on my public_html folder. It seems my host hiccupped and changed the public_html folder’s permissions to 0750…so it was a quick fix (once I found it), but; note to self — check the public_html permissions first.

PocketPyGUI: an intuitive, pythonic wrapper of the native Windows Mobile GUI

In playing around with my Dell Axim X51v, I have discovered PythonCE (the python distribution for windows mobile), and, more recently PocketPyGUI — a reliable, complete and easy to use GUI library. I stress easy to use because this library takes all the Windows out of Windows programming ;), while still providing the slick integration with the rest of the Windows Mobile operating system. I’ve also whipped up a few apps (some more complete than others) while getting to know the library. You can find them here on sourceforge all bundled into one zip file.
Here are a few screenshots of the demo program:

Automating WordPress

Here are a few useful plugins to make you wordpress management easier:

First, an automatic plugin installer:

PlugInstaller

This plugin makes plugin management much easier — you can install from either an uploaded zip file or a url, and it is easy to enable, disable and uninstall plugins.

Next, to upgrade Wordpress itself

Of course, before you upgrade you should backup your database, which is simplified wih the use of

WordPress Database Backup

This plugin provides numerous configuration options for you backup, as well as automatic backup (on an hourly, dayly, or weekly basis).

Now for the actual upgrade:

InstantUpgrade

With minimal configuration,  this plugin makes upgrading your wordpress installation a one-click
operation.

Have you found any other plugins useful for WordPress automation?

Install Python module without root privileges

By default, python tries to install modules to the /usr/lib/pythonXX directory, which is write protected for any user other that root. Here’s how to get around that limitation:

In my case, I will be installing sqlite onto a web server, and so will be doing this all through cgi scripts. It shouldn’t be much different for other situations, though.

The short answer is:

run “python install.py –prefix=/home/username”

whenever you want to use the module, put this at the top of your file:

import sys
sys.path.append('/home/jabapyth/lib64/pythonX.X/site-packages')

For the long answer (how I did it),

Run this file:

#!/usr/bin/python
print "Content-type: text/html\n"

from urllib import urlopen as upen
import tarfile
import os

## the source archive URL
archive = "http://initd.org/pub/software/pysqlite/releases/2.4/2.4.0/pysqlite-2.4.0.tar.gz"

## download the archive
open("pysqlite.tar.gz","w").write(upen(archive).read())

## extract it
tr = tarfile.open("pypy.tar.gz","r:gz")
for m in tr.getmembers():
    tr.extract(m)

## run the installer
import os
os.chdir("pysqlite-2.4.0")
## this is the relevant line for most people: pass --prefix=/home/username to the install file
res = os.popen("python setup.py install --prefix=/home/jabapyth").read()
print res

Run that file, and the module will be installed

again, you will need to put this at the top of any file into which you want to import this module:

import sys
sys.path.append('/home/username/lib64/python2.4/site-packages')

VensterCE: Hello World, again

In this tutorial, we are actually going to make a window, although we will still just be saying “Hello, World”

The Code

from venster.ce import *

class MyWindow(CeMainWindow):
    _window_title = u"Hello World, again"

    @msg_handler(WM_CREATE)
    def OnCreate(self,event):
        self.sizer = BoxSizer(VERTICAL)
        text = StaticCenter(u"Hello World", parent=self)
        self.sizer.append(text)
        CeMainWindow.OnCreate(self,event)

def main():
    mainForm = MyWindow()
    mainForm.ShowWindow()
    application = Application()
    appliation.Run()

if __name__ == "__main__": main()

Step by Step

class MyWindow(CeMainWindow):
    _window_title = u"Hello World, again"

This is the class definition of the main window. It inherits from CeMainWindow, which was imported from venster.ce at the top. “_window_title” is a class variable, and representing the title of your window. Once again, be sure to use unicode (prepend the string literal with a “u” or convert with the unicode(str) function), or it will come out looking like garbage.

    @msg_handler(WM_CREATE)
    def OnCreate(self,event):
        self.sizer = BoxSizer(VERTICAL)
        text = StaticCenter(u"Hello World", parent=self)
        self.sizer.append(text)
        CeMainWindow.OnCreate(self,event)

the @msg_handler(WM_CREATE) is a decorator function, setting this function up as the message handler for the WM_CREATE function; the effect being that this function is called as soon as the window is created.
self.sizer (the name is important) is our main widget sizer — all widgets we create should be appended to it, or one of its children.
There are 4 classes of static text: Static, StaticLeft, StaticCenter, and StaticRight. They all take the same arguments.
Finally we call the parent class’ OnCreate to finish setting up the window.

def main():
    mainForm = MyWindow()
    mainForm.ShowWindow()
    application = Application()
    appliation.Run()

if __name__ == "__main__": main()

These lines of code will probably be at the end of all your programs; they “create” the window and start th eapplication running.

Sync Windows Mobile with Ubuntu

time-saving tip: if you don’t want this all explained to you, you can just download and execute this bash script.

First you need to install SynCE:
Add these lines to your apt sources (type “sudo kate /etc/apt/source.list” and paste these at the bottom)

deb http://ppa.launchpad.net/synce/ubuntu gutsy main
deb-src http://ppa.launchpad.net/synce/ubuntu gutsy main

Install the USB Driver

sudo apt-get install usb-rndis-source cdbs
sudo module-assistant auto-install usb-rndis

Install ODCCM (the connection manager)

sudo apt-get install odccm librra0-tools librapi2-tools

Now we need to install MultiSync (a gui that manages the syncing process)

sudo apt-get install multisync libmultisync-plugin-backup libmultisync-plugin-irmc libmultisync-plugin-evolution synce-multisync-plugin

Now that you’re done installing everything, type “sudo odccm -f” into the konsole to start the connection manager, and plug in device (your device should now recognize that it is connected). To manage the syncing, open up MultiSync (Start Menu->Utilities->MultiSync) and create a new sync pair with the plugins “SynCE Plugin” and “Ximan Evolution 2″. Press sync, and you’re done!

If you dont use evolution, you can get other plugins for MultiSync at their website.

CeGCC Hello World

First, copy this into a file “hello.c”

#include <windows.h>
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
          MessageBox(0, L"Hello!", L"CeGCC says...", MB_OK);
}

Here we have the generic MessageBox function, but with one twist: because we are in unicode, we need to prepend all string literals with ‘L’ (we could use the _T(”mystring”) macro, but I think it looks more ugly). If you try do compile

MessageBox(0, "Hello!", "CeGCC says...", MB_OK);

You will get an error complaining something about converting to LPCWSTR (meaning it wants unicode and didn’t get it).
To compile this source (you need to have first installed CeGCC), enter this at command line:

arm-wince-mingw32ce-gcc hello.c -o hello.exe

You can then copy the .exe file over to your Windows Mobile device and double click on it in the file manager to run your first program!

VensterCE: Hello World

In keeping with tradition, lets start off with a simple “hello world”

from venster.ce import *
msg = MessageBox(None,u"Hello World",u"Venster Says",MB_OK);

First line:

from venster.ce import *

This merely includes the basic functions and classes from the venster library. We will use this in every program.

msg = MessageBox(None,u"Hello World",u"Venster Says",MB_OK);

Here create a simple messagebox and store the return value in the variable “msg”. The function definition for MessageBox is MessageBox(window,message,title,buttons). Here the parent window is None, as we haven’t created one (It’s ok, windows can handle that). Next are the Message and Title strings, but make sure you keep them unicode (bad things can happen if you dont). The “buttons” variable is combination of flags. A few popular ones are MB_OK, MB_OKCANCEL, and MB_HELP for buttons, and MB_ICONWARNING and MB_ICONINFORMATION for the icon. For a full reference of the different flags, go Here.

VensterCE: installation

To use the vensterce library you first need python, so (If you haven’t already) go ahead to the PythonCE Download Page and get either the installer or the CAB file (you choose :). Then you can fetch VensterCE zip archive from here. Inside that zip file you will find several things:

  • “venster”: this folder is the actual library. Copy it into your python library (Usually \Program Files\Python25\Lib\
  • “tutorial”: here is contained 5 “tutorial” files along with an html page describing them, although I’ve found this “tutorial” to be more of a quick-start for those already proficient with C++ win32 programming
  • the contents of the “shared” folder need to be copied into the \Windows directory on your device.
  • “pyceide”: this is an advanced python IDE, built in VensterCE. All you need to do is double-click on the “pyceide.pyw” file and it will run.

That should be all that’s necessary. From now on you can “import venster”.

VensterCE: Native Win32 Api for PythonCE

VensterCE is an open source wrapper of the native win32 controls on a windows mobile device (i believe its also available for regular windows…but its not as good as the win32api module). Its a cool project, but the tutorials provided give a good idea of what it can do, but don’t actually help you understand how to make your own. This can be a big challenge for those win32 noobs out there (hey, i was one too…about a month ago ;), so i decided to start a tutorial series to help out, and teach myself something in the process.