Categories
Programming

How to access your xml in flex

I’ve had a request to explain how I access the XML (using Flex) once I created the XML file out of the csv file using my csv2xml python script.

To access the XML in Flex, I’ve defined an XML variable in Flex :

private var content:XML;

And I then load the XML file into the content file.

fileStream.open(file, FileMode.READ);
content = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
fileStream.close();

If you are using my csv2xml.py script, the xml file was written with ‘root’ in the top and then for each row in the csv file an ‘element’ tag was used.

Between the element tags the content of one row of the csv is written, using the header of the csv file as the tag name for each item.

In order to access one of these tags below the element, for example the content of the tag ‘assigned’ you would specify the following :

var result:XMLList = content.element.assigned

As you can see, you do *not* mention ‘root’. This was a Gotcha for me for a while… This will store all the assigned in the result variable, which you can then
further manipulate.

BTW, I use the trace command a lot to check on the content of my vars…

In a variation on the previous, say you want to only get the unique values out of a tag, to store in a combobox so the user can use these for filtering the data :

// Function called from each filter to extract the unique values
private function addUniqueValue(alllist:XMLList):XMLList{
var list:XMLList = new XMLList;
//trace("*** Setting up unique values.");
for each ( var property:XML in alllist){
//trace("*** Property : " + property.toXMLString());
if(!list.contains(property)){
list += property;
}
}
return list;
}

You would get the unique values by calling the function in the following way :

var filterStatus:XMLList = addUniqueValue(filtercontent.element.Status);

This will get you a unique list of all the statuses in the xml file.

I hope this helps you get the goods out of your xml file !

Categories
Programming

Showing a popup image in flex and passing variables to a mxml module

I already show a thumbnail image in my Quickwins application, but I wanted to show the full image when one clicked on the thumbnail. The image should open in a window on top of the current application window, and can be closed again.

I had to google for a while (I got a lot of help from reading “Web Development Central” ) and search the Flex built-in help before I figured it out, but I think it’s because it’s so damn easy to do this in just a few lines of code !  Here’s how you do this :

Say you want to show an image – the image’s path is “c:\windows\test.jpg” and that path is stored in a string variable screenshot_path

  1. Create a new mxml module in your project, for example call it ‘ViewWindow.mxml’ – Make it a TitleWindow
  2. In your main program, call the module via the PopUpManager  (you’ll need to import it via “import mx.managers.PopUpManager;”):
    PopUpManager.createPopUp(this, ViewWindow, false);
  3. In your ViewWindow module you create a mx:image – let’s say we give it the id “Image2View”. This image will be loaded upon initialisation of the window via the init() function which is automatically executed when the module is called. We wil use the screenshot_path variable from the main application. To do that, we need to tell ViewWindow from where the variable is coming from: from the parent application. Appropriately, you can use the referrer ‘parentApplication’ :
    Image2View.load(parentApplication.screenshot_path);
  4. Upon closing the window (notice that we have activated the close button) we tell the popupmanager to remove this window.

See the full code for the ViewWindow.mxml below.

Categories
Blog News

What would Twitter sound in real life ?

This is how Twitter sounds in real life – proves all sorts of points about it…

Watch Real Life Twitterдивани and more funny videos on CollegeHumor
Categories
Blog News

Getting easy_install to run for Python 2.6

StackOverflow is a great new website for all kinds of programmers.

Flex, Python or any other language programmers can ask questions there and receive answers, or usually, find out their questions have already been asked before and the answers are already there.

Python 2.6 has just come out, and a very easy install tool (called, appropriately, easy_install) has not yet been ported to the windows version of Python 2.6.

StackOverflow has the question, and several answers !

Once easy_install is installed and has been added to your PATH, it’s a breeze to install additional site-packages to your python setup, like pyodbc or the cheetah templating engine or pyamf just by running the command ‘easy_install <programname>’ in a dos box where <programname> is the name of your program.

Categories
Programming

Using Adobe Flex to Show CSV to XML converted data

After having converted all your enormous spreadsheet data to xml using my python script csv2xml, what do you do with it ? Why, you display it using Adobe Flex of course ! Well, at least that’s what I did with my data (YMMV).

The following AIR tool displays issues that have been identified for a website. It uses an XML file on a windows file system as a source and a screenshot directory that shows screenshots linked to the issue description.

Here’s how my user interface looks like after a few iterations; the goal is to show the key facts in the lines in the datagrid, with the issue description and other more detail fields to be filled in below the datagrid when a line is selected in the datagrid.

(click once to see more info, click then again for original large size picture – WordPress has changed how you publish pictures, and it’s annoying me a lot, but not enough to fix it)

The above shows a TabNavigator with in it

  • an Overview tab : this is the main pane that has an overview of the xml data in a layout that makes sense (at least sense for the data)
  • an Overall stats tab : this is based on the most important key field, being the status of implementation and the priority assigned to each item
  • a Stats – Filtered tab : this shows the same graphs as above but filtered based on the dropdown filters in the overview tab
  • and an About tab that gives you an explanation of how it works and incidently, where the free icons come from (Axialis).

Inside the overview tab I have identified the main fields I want to filter on and put them in drop-down buttons. The filters are cumulative, meaning once you use a filter, you can use another filter again on the remaining list of items. Once you are done filtering, you hit the reset button to restore the full list. This has the advantage of just using one filter function to call, each time giving it the previously filtered XML. The disadvantage is that you can’t easily select a different field from the same filter once used, and need to hit the reset button to restart (I keep a copy of the original xml list when starting out).

The data is shown in a datagrid, with the website field having a custom icon renderer that shows an icon for the url link. Clicking on a line in the datagrid shows you the relevant info fields below. If a screenshot of the page exists, the screenshot is shown dynamically on the bottom right.

The stats graphics are draggable. With the inclusion of a simple action script class, found here, and specifying which graphic you want to make draggable, my graphics can be dragged over to the desktop, and are saved as jpegs.

On the bottom of the pane you find 3 buttons : one to select the source xml file, one to select the directory that contains the referenced screenshots and one that lets you exit the application.

What’s still missing that I would like to implement ?

  • a search box : for that I need to figure out how to search inside xml nodes and which ones are important.
  • filters that can be reset individually (lots of work, I will probably keep it as-is)
  • so far this is read-only stuff, the most made comment is that writing back changes would be a great thing. Since excel is the masterfile, this is currently not possible without a major rewrite, however I have some ideas of connecting to databases using Cheetah and pyamf and pydobc !
  • a lightbox style overlay when you click on the thumbnail to see the original picture : I’m trying to get this programmed in, but it’s hard going for the moment as I’m just about done with this app for the moment.

What’s still not working as it should be ?

  • If the preferences file does not exist I get plenty of errors; these disappear once the screenshot path and xml file have been selected once. I think this means that my error checking for empty preferences files is not yet up to a good standard. Plus I cobbled the preferences programming together from different sources; a major review would be needed to fix this.
  • If a screenshot related to a quickwin does not exist, I want it to give a message instead of a broken image icon.
  • Sorting the data in the graphs; haven’t figured that out yet.
  • Exporting your selection to pdf. Printing it.
  • Must be a lot of others, but those are the most glaring ones.

Frankly, as this is the first major flex AIR application that I wrote, and the first time I worked with XML code, I hope you’ll excuse me for stating that the code is in a bit of a mess, and could use some cleanup.

For example, there’s a function that I could reuse a lot that I couldn’t be bothered about at the time to find out how to pass it the right variable in just the right way, so I just hit copy/paste of the same function five times with different starting variables (Yes – it’s blasphemy. Yes, I know. I still cringe when I look at it). As I said, I was a bit drained of getting Flex to work (or adapting myself to Flex).

However, I also found out by writing this that Flex can do some pretty nice stuff with just a few lines of code. Linking the graphics to the numbers was not so a big task as I feared. So in the end I’m pretty proud of it, and I learned a lot about xml and how to massage it and show it in Flex.

Should somebody be interested in parts of the code to have a look at, I’m willing to publish it and/or go over it, just drop me a comment. I just don’t think it’s very high quality code…

Categories
Programming

Version 1.8 of CSV2XML is out

Thanks to a comment from a user of the program who had problems getting the script to process csv files on the mac, I’ve updated the script to version 1.8 so it will now open them without first needing to save the file in unix format when exporting to csv from Office for Mac.

For those of you who noted the version skip, version 1.7 has not been released, but just includes a simple test to see if the first field is empty or not. If empty the line is dropped. It’s been commented out in the latest version. Since my hosting provider also does python, I have renamed the file to .txt. Simply rename it to .py to have it working.

csv2xml_v18

[For the Pythonistas : I’ve set the csv module to now open the files in read ‘universal’ mode]

Categories
Blog News Programming

Revoking a Flex 3 License Activation is not easy.

This is a bit of a weird story, which most people probably won’t have happened to them. Still for those out there in the same situation, this is what happened.

Previously I had bought the “Flex builder Standard edition”, which comes without graphic elements (bars, charts, pies, whatnot). In order to show the results of filtering in my flex program I found it didn’t do all I needed. So I purchased the Flex Builder Pro edition (the full build, not an upgrade).

When you register your products on the Adobe website, you can see on your adobe.com profile page that each flex builder product can be installed two times – typically used for installing once on Windows and once on Mac, so you can test your products on both environments. This suited me fine, as I have a windows XP laptop and an iMac.

Each time you install Flex builder, you can see in your profile page on Adobe.com that the license count for the registered product decrements by one. My standard edition was installed on both my Mac and my XP, so I had zero licenses left to install (which it showed on my Adobe profile page).

After buying the full Flex Builder, I no longer needed the Standard edition. So I wanted to uninstall and if possible sell the standard edition. So I searched for a deactivation routine inside of the Flex builder Standard edition. Most recent Adobe products like Photoshop and so on have online activation, but I did not find one, so I uninstalled my standard Flex Builder 3 completely, thinking that uninstalling would also revoke the used Flex license with the Adobe server. This does not appear to be the case, as the license count does not increase again.

Erasing the license key from your machine and replacing it with the full flex license also does nothing for the used-up licenses on adobe.com.

So in the end I asked for help at Adobe (Benelux). They too asked me if I could not start the deactivation routing, but admitted they did not have much training in supporting Flex builder. After some more mails and phone calls, the technicians could not help me further, and had no further information to give me, as Flex Builder is a server product, only used in big corporations ( I told them I had bought it in via the Adobe.be online shop as a retail customer, so it’s not only just for big corporations) . After inquiring internally, they told me the only support for Flex on the issue I was experiencing was in America, which I could try to call, but probably would not get in as I would need a support contract.

I reopened the by-now closed support case and wrote quite a lengthy mail explaining that I was not satisfied with the solution. An extremely helpful (dutch) lady has since then tried to help me and has herself contacted the Flex support guys.

It seems Flex is considered an enterprise product, so it is not supported by retail support people and you need an enterprise support contract.

However, the upshot of it seems to be that a normal uninstall should be sufficient. There should be no penalty or license deactivation apparently needed, you can reinstall the Standard edition elsewhere. However, I have not yet tried to sell my license, and probably will not for some time. I’m a bit scared of trying it, and not everybody around me is so deep into programming as I am…

All in all, I have mixed feelings about the support I’m getting for this issue. On the positive side, I was always courteously treated by the support people, and all of them were helpful (but in particular Helene was helpful above and beyond her duty, for which I thank her). On the negative side, it seems that Flex is not considered a retail product, although there are scores of people out there using it to create lots and lots of cool things with it in flex/flash.

Categories
Blog News

Do-Re-Mi in Anwerp Central Station

Categories
Blog News

Flex update is coming

I’ve not been posting a lot on my blog lately, as I have been busy on several things at the same time. But I’m still programming in Flex (and in Python) and have been trying out ways to get them to work together. More details later on, including on my pet flex project that uses converted xml.

Categories
Blog News

MacHeist 7 Days Left

There’s still 7 days left over to sign up for the Macheist software package. For 39$ you get 600$ worth of software ! For me, it was worth it. Just hoping we can get ‘espresso’ as well…

Btw, using the link provided lets me earn some more software too.