Building Blocks

18May/0920

Piping the Machine: PureMVC Multicore with Pipes and the Finite State Machine (FSM)

This is going to be a walkthrough of making use of PureMVC Multicore (AS3). To help in building a PureMVC Multicore application, we are going to make use of the StateMachine utility for initial setup and configuration as well as the Pipes utility for communication between cores.

Here's the Source.

Get Adobe Flash player

18Apr/092

Mockups with Balsamiq

We need mockups. They allow us to communicate with developers, clients, users and everybody in between in a common language. I'm a big fan of the Sharpie and a pad of paper. Balsamiq Mockups has created a really great piece of software to speed up the mockup process.

31Dec/082

Installing PyAMF 0.4.0rc1 on Windows XP

I wanted to give the latest pyamf a go, but when I used the standard 'setup.py install', the following ominous warning was presented:

error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.

Uh oh! I actually DO have Cygwin installed, but unfortunately this message is a default and not entirely helpful. It did put me on the right path to actually getting it to go.

This webpage has a lot of good information on the subject, and it is where I pulled out these steps:

1. Grab the MingW32 Automated Installer and get it installed. I selected all of the available options as I figured it wouldn't hurt (it didn't)

2. Add the mingw32 binaries to your system path environmental variable (ie c:\mingw32\bin)

3. Tell Python to use mingw32 when it needs to compile a distribution by adding a file called distutils.cfg in this folder: {PYTHON_INSTALL}\lib\distutils\distutils.cfg. The file should contain:

[build]
compiler = mingw32

4. Version number parsing was throwing errors, so you actually have to edit {PYTHON_INSTALL}\lib\distutils\version.py to get it compiled. At line 100 make the following change:

from:

1
2
    version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
                        re.VERBOSE)

to:

1
2
    version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? (\. (\d+))?$',
                            re.VERBOSE)

now with all that done, just run 'setup.py install' and it should compile as expected. Easy as... I dunno, it is actually kind of confusing, but it works and now I can give pyamf a whirl with the c-ext enabled.

Filed under: pyAMF, python 2 Comments
21Sep/0811

Django Authorization from Flex/AIR via PyAMF

Django views serve nicely as service end-points for Flex applications. Here are some notes on maintaining authenticated sessions between a Flex/Air/Flash application and your Django backend.

gateway.py

1
2
3
4
5
6
7
8
from pyamf.remoting.gateway.django import DjangoGateway
 
import myproject.myapp.views as views
 
gw = DjangoGateway({
    'login'                       : views.login_user,
    'logout'                     : views.logout_user,
})

views.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pyamf
from django.contrib import auth
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
 
try:
    pyamf.register_class( User,  'django.contrib.auth.models.User')
except ValueError:
    print "Classes already registered"
 
def logout_user(http_request):
    logout(http_request)
 
def login_user(http_request, username, password):
    user = authenticate(username=username, password=password)
    if user is not None:
        login(http_request, user)
        return user
    return None
 
@login_required
def registered_user_protected_function(http_request):
    return "You are a registered user."
 
@login_required
def staff_protected_function(http_request):
    if http_request.user.is_staff != True: return None
    return "You are staff."

from flex

1
2
3
4
var netConnection:NetConnection = new NetConnection();
netConnection.connect("http://mysite.com/gateway");
var responder:Responder = new Responder(loginResult, handleFault);
netConnection.call("login", responder, "username", "password")

The http_request carries a reference to the currently authenticated user throughout the session. This works for web based Flex application as well as AIR applications on the desktop. Note that I am using a try/except on the pyamf class registration calls. Because this is session based, the classes only need to be registered once. Without the trap, it throws a TypeError letting you know the registration has already taken place.

Django User Authentication Documentation
All of the various things you can do with authentication in Django. It is, of course, based mostly on the use of the very nice Django HTML template system. While those bits aren't handy to the likes of us, it is a good read either way.

pyAMF ByteArray example
This example shows the basic structure for setting up Django/Flex communication. It doesn't cover authentication, but covers a good bit of territory with examples in Flash and Flex.

12Sep/080

Dynamic upload paths in Django

I'm refactoring my VE:Session application a bit to the recently released Django 1.0. They have made some outstanding progress with the project overall, but there are enough things that are radically different to cause me to lose sleep searching for answers to small problems. I'd simply overlooked their NewForms branch when I was building the application, and now I am paying for it by standing well behind the curve. It is fun to learn new things though, so that is the upside I suppose.

Anyway, back to the refactoring. In addition to updating the project to the current Django trunk, I want to unify the application under Django. I am currently using SlideshowPro for my image CMS functionality. It is a fine product, but it obsfusicates the application and certainly makes it harder to deploy. This is compounded by the fact that I am using an older version of SSP. Django has some out of the box options for filing your uploads in a data structure. I really need something more customizable for the application though, and I was feverishly searching for a solution. The previous examples were complex hacks to get the job done. Which is fine, but they are now broken with the update to 1.0. D'oh. As luck would have it they are not neccesary any longer, and the same functionality can be added with a few simple lines that Scott Barnham was kind enough to demonstrate:

1
2
3
4
5
6
7
from django.db import models
 
def get_image_path(instance, filename):
    return 'photos/%s/%s' % (instance.id, filename)
 
class Photo(models.Model):
    image = models.ImageField(upload_to=get_image_path)

Awesome.

I've been knee deep in Java for the past few months, so it is really nice to get back into Python for a bit. With Django reaching a comfortable level of maturity, I see many more sleepless nights in my future.

Filed under: django, python No Comments
21Apr/085

Continuous scrolling image thumbnail component for Flex.

I've updated this to a proper component implementation that can be found here.

Here is the beginnings of a full featured open-source continuous scroll thumbnail component for Flex. It is rough right now, but I plan to polish it and make it something useful. This format is really appealing, as it gives the user a seamless view of a gallery, without any jumps or aggravating scroll bars. Up until now I have been using H and V Lists in flex for my thumbnailing, but they are ugly and don't provide as rich of an experience.

The Scroll Panel from AFComponents was my first choice. It is a very nice component, well priced, and would be just what I need, if not for the fact that my project is open-source and using a commercial component sorta kills the whole thing. After scouring the internet I finally stumbled upon the work Peter Wright has put in on a perpetual scrolling list.

I've modified it to accept an XML list of image objects, as well as perform horizontally. It is also functioning as a slideshow, and I want to allow it to go either H or V depending on the need. It should shape up to be a nice reusable component. Much thanks to Peter for supplying the code to get me started.

Source Enabled

18Mar/080

PureMVC Python port has been released

[PureMVC - Python]

I am very excited about the potential of this port. As far as I can tell, there isn't a whole lot out there for MVC and Python. There are a handful of server/web MVC frameworks. Django is the one that I have experience with, and it is a fantastic framework. As is true when comparing PureMVC to most frameworks, however, the PureMVC for Python is dead simple. It is a straight port, implementing PureMVC in the same fashion as we see in the original AS3 version. Structurally it differs from Actionscript - it is Python after all - but fundamentally it is the same.

Many thanks to Toby de Havilland for overcoming some of the initial issues with the port, and getting it up and running. Thanks also to Nathan Levesque for running point on the project and getting the ball rolling with the port

Here it is running the Employee Admin demo on XP and OSX:

pmvc_python.jpg pmvc_py_mac.jpg.

Filed under: puremvc, python No Comments