Categories
Code Sample Flex How-To Programming

How to do custom chart annotations in Flex

Hunting around the ‘Net, I found a few good examples of creating chart annotations in Flex.

One example app which helped me greatly was from a “blog posting by Ely Greenfield”:http://www.quietlyscheming.com/blog/2006/04/03/custom-chart-annotations/. If you’re interested, you can view it on his website: “chart annotation demo”:http://demo.quietlyscheming.com/overlayDemo/index.html.

Unfortunately, the code you can download from his site is a little old so it has problems compiling in Flex Builder 2+. I have updated the code, fixed some bugs in it and have it available here: download OverlayDemo-fixed.zip.

Ely has other interesting demos on his site which are worth checking out. Some of my favorites are: the “variable radius pie chart demo”:http://www.quietlyscheming.com/blog/charts/variable-radius-pie-chart/, the “interactive bubble chart demo”:http://www.quietlyscheming.com/blog/charts/variable-radius-pie-chart/, and the “dashed lines demo”:http://www.quietlyscheming.com/blog/charts/dashed-lines/.

h3. Resources

annotation example by Ely Greenfield

  • “http://www.quietlyscheming.com/blog/2006/04/03/custom-chart-annotations/”:http://www.quietlyscheming.com/blog/2006/04/03/custom-chart-annotations/
  • demo: “http://demo.quietlyscheming.com/overlayDemo/index.html”:http://demo.quietlyscheming.com/overlayDemo/index.html

annotation example by Brendan Meutzner

  • “http://www.stretchmedia.ca/blog/index.cfm/2007/3/28/Chart-Milestones-using-annotationElements”:http://www.stretchmedia.ca/blog/index.cfm/2007/3/28/Chart-Milestones-using-annotationElements
  • demo: “http://www.stretchmedia.ca/code_examples/chart_milestone/main.html”:http://www.stretchmedia.ca/code_examples/chart_milestone/main.html
Categories
Code Sample Geek How-To Technology

How to build and install the Metakit DB for Python on MacOSX

Ever since I used it years ago on a geek-project for my Zaurus, the Metakit DB has always been a favorite of mine. I had the chance to use it again on another personal project and this time on MacOSX. Unfortunately, the prebuilt binaries on the Metakit site are for older versions of MacOSX, so I had to build it myself.

Normally one would simply follow the “Metakit installation instructions”:http://www.equi4.com/pub/mk/, but they are old and didn’t work correctly with 10.5 Leopard. I scraped enough information together from the Internet to get it working, but I had to do a lot of research. To save others the same hassle, I have put together all of the changes and put them here in their entirety:

Building Metakit

Make sure you have Xcode installed on your system before starting.

Get the latest source from the “Metakit downloads page”:http://www.equi4.com/pub/mk/. At this time the latest version is @metakit-2.4.9.7.tar.gz@.

Uncompress the archive in a work directory and run the following commands:

> cd builds
> ../unix/configure --with-python=/System/Library/Frameworks/Python.framework/Versions/2.5

Note: Your Python install might be in a different location. If so, give the @–with-python@ arg the proper value.

“Fat” binary setup

If you need this to run on the PPC architecture you will need to make a couple of modifications to @./builds/Makefile@ after running @configure@, otherwise you can skip this step and build the binaries with @make@.

Find @CXXFLAGS = $(CXX_FLAGS)@ and change to the following:

CXXFLAGS = $(CXX_FLAGS) -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk

Find @SHLIB_LD = g++ -dynamiclib -flat_namespace -undefined suppress@ and change to the following:

SHLIB_LD = g++ -dynamiclib -flat_namespace -undefined suppress -arch ppc -arch i386

Build the binaries

Run your typical @Makefile@ commands:

> make
> make test

Installing Metakit

Rename the shared library which is now in the @./builds@ directory:

> mv Mk4py.dylib Mk4py.so

And copy the following files to @/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python@ (be sure to adjust the path name for your version of Python):

../python/metakit.py
./Mk4py.so

Testing Metakit

At this point you should have a working system and ought to be able to run the following command in a Python shell without issue:

>>>from metakit import *

Enjoy !

h3. Resources

  • “Metakit for Python website”:http://www.equi4.com/metakit/python.html

  • “helpful instructions from www.ospace.net”:http://www.ospace.net/wiki/index.php/ServerHowTo

Categories
Geek How-To

Hacking the front page to display my blog entries

h3. The problem

I wanted the home page of my web site to show my blog entries and also be a little more dynamic by displaying other related content.

The default @index_html@ page for my blog software, Quills, does display the current entries, but from what I read online there was no great solution to get its default page to show at the root.

Plan B was to replace my generic @index_html@ page with one which would query the Quills weblog object for all of its entries and then display them one at a time. I wanted to use one of Plone’s built-in user-addable types for the script but as far as I can tell they are only used to display formatted text and won’t execute any code. I finally used the Zope Management Interface (ZMI) to add a single Zope Page Template (ZPT) called @index_html@.

h3. Understanding how Plone draws a page

I read several chapters in the book The Definitive Guide to Plone to figure out how to proceed, but the one which gave the most pertinent information was Chapter 7 – Customizing the Main Template.

In short, Plone has a special Zope Page Template (ZPT) at @/your_plone_site_folder/portal_skins/plone_templates/main_template@ which contains the HTML and special markup used to render the basic structure of each page in the site. Among other things, the markup defines regions within the page called @define-slots@. These slots are filled in by an object as it is being rendered for view in the browser. Using a master template like this assures that the site has a consistent page layout.

Within this master template there are slots defined for different sections of the HTML like @head_slot@, @css_slot@, @column_one_slot@, and @content@. Some examples of these slot definitions follow. Notice that they can be within different types of tags.


  This content will be replaced.

...

When you are rendering your ZPT, you define the areas which will “fill” these slots and place the pertinent content within them. These areas are appropriately called @fill-slots@. Here are some examples:


  your stuff here


your stuff here

There are other things to know about how a page gets rendered, but this is the basic idea.

h3. Creating the page

With @define-slots@ and @fill-slots@ in mind, I created my ZPT at the root of my Plone site called @index_html@ so I could start hacking. For my purposes I was only interested in changing the fill-slot @main@ so I defined my fill-slot like above and put some bogus content in it to make sure I was on the right track. I filled out the rest of the code with guidance from examples in the book, other code in the Plone @portal_skins@ area as well as in the Quills product directory.

h3. Getting the entries

The Quills file @/Zope/Products/Quills/WeblogArchive.py@ had two methods defined which return a list of blog entries – @getEntries()@ and @getLazyEntries()@. The difference being that the latter only returns the catalog search objects, so it’s fast but the data which can be displayed is limited to the metadata definitions in the @portal_catalog@. I was hoping to get the full text of the entry so initially used @getEntries()@, but it turned out to be too slow.

h3. Keeping with the site look

Next I wanted to use as much of the site style sheet as possible too keep the look consistent. Most of the important entries are in the main style sheet which is found at @/your_plone_site_folder/portal_skins/plone_styles/plone.css@.

h3. Extras

I added this page to the site RAM Cache since this is the front page and the entries don’t change very often. ZMI > Cache Tab > Cache Object Using RAM Cache > Save Changes. Easy.

I also hacked together an RSS icon and feed in the h1 title.

h3. Things to update

My page works, but I should tidy up some of the CSS and change the design to be a little more interesting. I also have hard-coded the name of my weblog object instead of using the @portal_catalog@ to find it for me.

You can click here to download the template.

Categories
Geek How-To Technology

Setup MarsEdit with Quills 0.9 Final

I have been wanting to find a better way to write blogs rather than using the Plone interface. I was happy to find that MarsEdit and Quills both implement several blog APIs. Though it would appear that the implementation for both the BloggerAPI and the MetaWeblogAPI are not complete, MarsEdit can still be used to post articles using the BloggerAPI.

Here are examples of necessary configuration:

Name: MyBlog
Home URL: http://www.davidmccuskey.com/weblog
Software: Other Blogger-compatible
RPC URL: http://www.davidmccuskey.com/weblog
Blog ID: weblog.2006-01-10.2395214781

The tricky part is obtaining the Blog ID. Plone uses an immutable identifier for all objects so that they can be found even after renaming them. Quills in turn uses this ID to get at your weblog object.

In order get this ID you’ll need to login to your Zope Management Interface (ZMI) and go digging through the uid_catalog in Plone. When you have clicked on the catalog object, click on the tab labeled Catalog. Find your blog object in the list of results and click on its link.

Search on the resulting popup page for the key named UID. The value of this key is what you will need to use for the Blog ID.

Note: Because of errors in the implementation of the MetaWeblog API, you will see a Zope error after posting, however the post will be correctly saved.

Categories
How-To Technology

Added AdSense by Google

One thing that I like about Google is that they make things easy.

One thing that I like about Plone and Zope is that they make things easy.

In about an hour or two, I managed to put AdSense ads on my web site.

Go to Google.com/adsense and sign up for your account. Click on all of the emails to activate your account. Log in and grab your AdSense code.

Add a portlet to your custom area in Plone. Paste Google’s AdSense code in the body of your portlet.

Add portlet to your root Plone @right_slots@ property. Refresh your browser to see your Google ads.

h3. Resources

  • “Plone book errata”:http://www.agmweb.ca/plone/book/scripts.html
    This webpage has an Google AdSense portlet example in ZPT. Search for “Page Template: google_ad_portlet”
  • “Plone.org : A webpage with an example Page Template used to create a portlet”:http://plone.org/documentation/how-to/create-static-slot
  • “Plone.org – how to control portlets”:http://plone.org/documentation/how-to/control-portlets
    A website which has instructions on properties which control portlet activation.