Building Blocks

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
19Dec/083

Introspective PureMVC Console

This project is intended to help Flex and AS3 application developers, that use the PureMVC framework for AS3 - simple or multicore version - by providing them deep insights on what happens at the framework level: Notifications, Commands, Mediators and Proxies.
PureMVC is a highly recognized MVC framework, that has also many portages in various languages, and that's now quite widely in Flex applications, though not as much as Cairngorm.

What a fantastic tool. You can really dig deep into your application.

  • Monitors the internal flow of PureMVC in real time
  • Discover and inspect Mediators
  • Inspect Views associated to Mediators
  • Discover and inspect Proxies
  • Find starting point in source code
  • Integrated with KapInspect

http://lab.kapit.fr/display/puremvcconsole/PureMVC+Console

6Dec/088

ImageSwap (crossfade) Flex Component

I needed a component that would work in my slideshow component and give a decent crossfade while letting the user know that something was going on. I used TweenLite for the tweening, and it works pretty well. It dispatches an 'imageLoaded' event when the image swap has completed. I needed this so that the slideshow timer can resume. It pauses when the image starts loading because of various image sizes/connection speeds. Pretty simple, but it is a lot nicer than the harsh transition (or lack of) in the current slideshow.

Source Here.

Filed under: components, flex 8 Comments
11Oct/0820

Flex Date and Time (datetime) Picker Control

I saw one of these at some point, but couldn't find it when I needed it again. Pretty simple, the control has a property called selectedDate that returns a date object represented by the selected date and time. You can also feed it a Date and it will adjust to that. It is on a 12 hour clock. It dispatches a change event (Event.CHANGE) as a new date/time is selected.

There is an Inspectable property called minuteIncrement to adjust the increment on the minute stepper. I couldn't figure out how to have double digits on the 0-9 minutes. If anybody knows how I might achieve that, please let me know.

Here's the Source

Filed under: AIR, components, flex 20 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.

16Sep/081

Fabrication – Simplified PureMVC multicore modules (and more)

One of the many reasons I love PureMVC is the community of highly intelligent, skilled, object-oriented (oriented) programmers that are constantly using the framework to build new and interesting utilities. This is a by-product of the very nature of PureMVC. Cliff architected the core framework in such a way that is is truly simple, providing a base from which to build new useful structures.

Fabrication, a new utility developed by Darshan Sawardekar is a shining example of this fact. He has taken the PureMVC multi-core apperatus, combined it with Cliff's Pipes utility, and created a wonderfully abstracted means for creating modular PureMVC applications. Not only does this simplify the connection of modules in your application and allow them to communicate seamlessly, but he provides a router/firewall metaphor for controlling the communication as well as undo/redo functionality.

Thanks Darshan, your efforts are appreciated. And as always, thanks Cliff for providing the base from which our community can build and contribute. Cheers.

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
27Aug/087

Custom JDBC (MySQL) Realm Authentication with Livecycle Data Services (or BlazeDS)

LCDS ships with the default Tomcat roles based security ready to go. You simply add some users to the tomcat-users.xml and there you go. This is probably fine for some, but for my needs I want to be able to authenticate against a MySQL database. I addition, I want to use strong encryption to protect my users personal information, as well as potentially sensitive business data. In this article I am going to explain how to configure Tomcat and Livecycle Data Services to do just that. It is actually fairly painless, once you get all the pieces put together. Hopefully this will be an area of the LCDS documentation that will get some attention in the future.

There are many robust frameworks available to Java that provide authentication functionality. In addition to that, they provide a level of complexity that I want to avoid. My primary purpose is creating enterprise Flex/AIR applications with a strong service layer provided by LCDS. I simply don't want to learn the intrict workings of Spring, JBoss Websphere, or any of the other fine solutions that might solve this particular problem. What I want is a simple solution that provides the functionality I need without a host of extra features I won't ever use. My finite capacity for new information needs all the filtering it can get.

17Aug/089

Integrating Adobe AIR, Cairngorm, PureMVC, LiveCycle Data Services (LCDS), MySQL and Hibernate

This post is going to cover the use of Adobe AIR, PureMVC, cairngorm, MySQL, LiveCycle Data Services (LCDS), and Hibernate. It utilizes these tools to create a simple image management system. The focus is on the configuration of the server to integrate Hibernate with LCDS and access that configuration from an AIR client.

15Jun/082

Complete Flex 3 CSS Style Properties List

I was looking for a list of properties for modal window styles and stumbled across this:

 Flex 3.0 CSS Properties List

Filed under: flex 2 Comments