Category Archives: Linux

Army Forms Going to PDF…

After a year of no longer having support of XFDL/Lotus Form Filler documents it would appear that the Open XFDL project had moved on.  At least that was my thought but it has now become apparent that there is still a community in need of improving XFDL interfacing with databases.

Please add comments and discuss what is the future of the XFDL format.  Will this be a legacy format within the military or will it phase out soon?

 

Installing OpenCV

So tinkering with OpenCV the past day has been fun.  This past summer, a co-worker and I made an application to crop images and resize them automatically to speed up booking at the jail we work at.

The first problem was face detection.  To create a method, we first invert the image.  Then run a line from left to right until the background color changes.  Do the same thing from right to left and then find the center.  Do that several times through the picture would lead us to a good center location for the face.

The second problem was that we did all this with Windows API/GDI.  These methods were very low level and difficult to run simple methods on.

For some reason, we never found OpenCV until reading a slashdot article last night.  This library is awesome for face detection and other visual work.  I use a Linux box at home and the work computers use Windows, so I like that code can be compiled with only changes to the compiler going between each computer.

Installation

The install in linux was very easy.  Ubuntu has great documentation for installing anything with apt.  Since I’m using Mint 12 (gotta get away from Gnome 3!), I was able to follow this guide.

For Windows, it was a bit more tricky.  I read guides walking me through CMake and such.  Fortunately, I found that OpenCV 2.0’s installer does not need to be compiled, just extracted.  Using this guide I was able to get it work.  To simplify things, I’ve put two zips on my server for anyone to use.

  1. OpenCV_INSTALL.zip has the installer for OpenCV 2.0, CMake guide for those using Visual C++, and a sample codeblocks project.
  2. OpenCV_DONE.zip includes the extracted source and a sample codeblocks project.

Let me know if you have any issues.  Remember, for the codeblocks project to compile, you’ll have to sent compiler search directory to [src]/include/opencv and the linker search directory to [src]/lib

Enjoy!

XFDL with PHP 2…

Recent progress with doing XFDL forms in PHP.  I put some time into this project recently figuring that this web based viewer would be the most applicable.  Think if AKO’s MyForms, a setup where you can pass forms from one user to the next to get it filled out and signed; if that program never needed to leave the web?  With doing XFDL forms in PHP, that is possible!  My code is a mess right now so I will put up the PHP, Javascript for the page on a later post.

For now, go to the old version to see what the forms should be like and go to the new version to see progress on the viewer.

wxWidgets and ODBC…

Since wxWidgets > 2.8 has dropped wxODBC, I decided to learn how to use sql.h on my own.  I made a simple program to retrieve and print data in C for the command line and everything worked well.  Unfortunately, when I placed this code in my wxWidgets GUI program, it failed.  This was due to wx being unicode, so I had a whole world of learning on how to make sql.h talk with wx.  I’ve outlined the steps to make this work:

With ODBC, sql.h can work with unicode, the functions are the same, but different variables are sent.  WX defines as Unicode (as it’s usually compiled) and ODBC will map the function to the unicode variant.  For example, in a C++ program with #define UNICODE 1, such as WX, SQLDriverConnect will map to SQLDriverConnectW, the unicode variant.  The other option is SQLDriverConnectA which will allow ANSI variables.  Most of the functions you’ll need have an ‘A Variant’, which is what I’ll refer to the functions ending in A.

To Send Data:

  1. Cast your variable as a SQLWCHAR pointer.
  2. Set a string to that pointer, type cast the string too.
  3. Use the functions of ODBC that end with an A.
  4. Send that function a variable type cast as (SQLCHAR*).
SQLWCHAR *connStr;
connStr = (SQLWCHAR*)"DSN=testDB;";
SQLDriverConnectA(dbc, NULL, (SQLCHAR*)connStr, SQL_NTS,
    (SQLCHAR*)outstr, sizeof(outstr), &outstrlen,
     SQL_DRIVER_COMPLETE);

To Return Data:

  1. Do the same steps.
SQLWCHAR colName[256];
SQLDescribeColA(hstmt, i+1, (SQLCHAR*)colName, 255, &colNameLen,
      &dataType, &colSize, &numDecimalDigits, &allowsNullValues);

Convert SQLWCHAR to wxString:

  1. Use wxString’s PrintF() function and interpret the variable with a capital S.
SQLWCHAR colName[256];
wxString test;
test.PrintF(_("Column Name: %S"),colName);

Convert wxString to SQLWCHAR:

  1. Declare your buffer variable as SQLCHAR array.
  2. Cycle through each char in wxString and assign to your SQLCHAR array.
  3. Add a null value on the end (so SQL_NTS knows to stop!)
  4. Typecast the variable as a pointer in send.
wxString send = wxT("SELECT * FROM master");
SQLCHAR sqlTest[1024];
unsigned int j;
for(j=0;j<send.Len();j++) {
sqlTest[j] = send[j];
}
sqlTest[send.Len()] = _T('\0');

SQLPrepareA(hstmt, (SQLCHAR*)sqlTest, SQL_NTS);

XFDL in PHP…

Lately, I have started working on the OpenXFDL project again, concentrating efforts in making a C++ application with WX Widgets that can compile for Windows, Mac, and Linux.  Getting frustrated with libxml2 and wanting to learn more of xpath queries, I decided to make a XFDL reader in PHP.  This can be applied easily as browser/e-mail plugins to view XFDL forms without the need of an external viewer.  I’ve been bad about posting but I’ll work to add more to this blog soon.  For now, here is a sight to try it out with.  Unlike previous stuff, you can do a straight XFDL form instead of converting to XML first.  Try it out!

Fixing libcoolkey…

With my new CAC card, I found that libcoolkey.so was not working with Firefox correctly.  The new, 144k CAC cards do not play well with the old version of libcoolkey.  I did find that the ‘experimental’ release of libcoolkey will fix this problem, here is the fix:

amd64 (64bit)

sudo su
apt-get purge coolkey libckyapplet1 libckyapplet1-dev
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/libckyapplet1_1.1.0-7_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/libckyapplet1-dev_1.1.0-7_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/coolkey_1.1.0-7_amd64.deb
dpkg -i libckyapplet1_1.1.0-7_amd64.deb libckyapplet1-dev_1.1.0-7_amd64.deb coolkey_1.1.0-7_amd64.deb

i386 (32bit)

sudo su
apt-get purge coolkey libckyapplet1 libckyapplet1-dev
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/libckyapplet1_1.1.0-7_i386.deb
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/libckyapplet1-dev_1.1.0-7_i386.deb
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/coolkey_1.1.0-7_i386.deb
dpkg -i libckyapplet1_1.0-7_i386.deb libckyapplet1-dev_1.1.0-7_i386.deb coolkey_1.1.0-7_i386.deb

A side note, if you are registered with https://software.forge.mil/, then there is a fix in the project ‘Community CAC’ that includes libcackey which offers a fix for this as well.

Netflix on Linux.

Netflix is a great resource for watching videos, particularly the ‘Watch Now’ feature for instant streaming.  Unfortunately, for Linux users, Netflix uses a Microsoft PlayReady, Silverlight plugin for this feature.  This is to protect the content from piracy (arrgh, pirates!!) so they have no problems with copyright.  Too bad for Linux, as this feature is not available in any way, shape, or form.  There is no way to develop a fix for to use this in Linux either, as PlayReady is proprietary.  If this angers you as much as it should any Linux user, that the only work around is to use Windows, then please visit and sign this petition.

#! Statler – b43 driver fix.

This week I switched to #! (Crunchbang) because my Ubuntu was getting slow.  I love the speed and was very happy with the wifi because it had the b43 driver working by default.  Except, I could not get on my network after the most recent upgrade, but I found a work-around after a day of reading forums.  Surprisingly, it’s not too complicated!  You just need to create a conf file for b43 to use PIO and it will not through a DMA error anymore… my hardware is: Broadcom Corporation BCM4312 802.11b/g LP-PHY [14e4:4315] (rev 01).  This is the only line you should need.

sudo echo "options b43 pio=0 qos=0" > /etc/modprobe.d/b43.conf

Reference: This article from Ubuntu Forums.

GZip with ZLib

In an effort to use zlib in VBA, I had to first learn to use it.  I’m looking to gunzip the XFDL files to use the data as an MS  Office plugin.  In tinkering with zlib’s GZip functions, I found them to be very much like normal file handling in C.  Here’s a link to the official zlib reference manual, GZip is the tenth section.  So, to test it, I made a “micro-gunzip” which does work well.  When compiling, don’t forget to link to libz.a using gcc -o out -i in.c -lz.   Other than that, enjoy!  The basics are covered in the comments.

#include <stdio.h>
#include <zlib.h>
/* gcc filename.c -o outname -lz */

int main(int argc, char *argv[]) {
	// variables
	gzFile gFile;           // gzip file object
	FILE *pFile;            // out file object
	char *filen = argv[1];  // get the name of the file
	char buffer[100];       // buffer for reading

	// open files
	gFile = gzopen(filen, "rb");        // same as file
	pFile = fopen("example.out","wb");
	if(pFile == NULL || gFile == NULL)
		perror("Error opening file");
	else {
	    // write
		while(!gzeof(gFile)) {
			gzgets(gFile,buffer,100);   // file object first
			fputs(buffer,pFile);        // write to plain tex
		}
		// close
		fclose(pFile);
		gzclose(gFile);
	}
	return 0;
}

Microsoft Access : XFDL Viewer – Introduction

I know, I said it yesterday that it is rare that I develop on Windows, but this is a long promised application.  In 2007, my unit administrator (in the U.S. Army Reserves) suggested code that would allow batch loading XFDL forms from MS Access.  Due to the scope of the Apps 4 The Army project, I was limited to using a web application.  Now that the project is submitted and done, I am free to do my original plan, which is code to do the same process in MS Access.

Starting this today, I realized how much I hate doing Visual Basic.  Particularly, VBA is very painful!!  It’s not that the language is bad but it just always feels bulky and pieced together to me.  It seems to lack the professionalism of C/C++ and the flow of Python.  But, I may be alone in that.

I have a question for my readers though. Would anyone have an interest in seeing this project on SourceForge?  The Apps 4 the Army project is no longer my intellectual right, but a desktop application, a MS Office Plugin, etc… that’s all good to make public.  So let me know, if I get readers saying we’d like to help; then I will happily move this project to SourceForge!

To the authors of Hamster.

I found your project listed on this blog (which is a great read for Linux users)!  I will not rewrite that author’s excellent post, if you’re curious what Hamster is, go read the blog!  This tool is great for anyone obsessed with data and time tracking.  Essentially, it will show you what you do during the day.  For those who are bad at time management (me), then this tool can help increase performance.  But in using it, I found that I wanted something more.  Specifically, I didn’t want to tell it what I was doing.  I mean, I switched from coding my wardriver to blogging five minutes ago and I still haven’t updated.  Even worse, what happens when I’m multitasking between work, programming, army, etc.  I would like this application to update what is happening as I change it, rather than take the five seconds to update my current task.  I know, I’m lazy.

So what do I think should happen?  Well, I’ve commented on the post that I found this program that I would like it to be automated.  Take a ‘picture’ every minute of active processes and then use that data to associate that program with your current activity!  For example, the browser is open (you can even catch the website name) and you have a setting that associates that program/page with an activity, Hamster then updates what you are doing.  You could even go so far as to use what window is in front, the next behind, the next behind, etc to rank the amount of work you are doing with that task.

With my Army project done, my wardriver being worked on at a steady pace, I think this would be a fun program.  Anyone else interested in this?  Let me know through your comments…

Garmin Wardriver – Prototype Released

This project went together smoother than I thought it would.  The source code and application are available on it’s SourceForge page.  I’m still working to create a range for the networks and then use circles as points.  I’m thinking if I factor in strength, I can come up with an approximate (no where near exact) range.  Unfortunately, without the right antenna, it’s not likely to come up with a direction but I can get the entry and exit and create a circle around it from that.  Unfortunately, to convert the minute data to feet will take some fancy math due to variations in minutes with the longitude.  More on that in a future post.

For those wanting to use the application, here are the steps to get it working.

  1. Ensure you have iwlist, gpsbabel and Google Earth installed.
    • sudo apt-get install wireless-tools gpsbabel googleearth-package
  2. Plug in your gps.
  3. Test with ‘sudo gpsbabel -T -i garmin -f /dev/ttyUSB0
  4. If that pulls data, run ‘sudo ./garminwardriver.py
  5. Open your ‘out.kml’ in Google Earth (Start Google Earth->File->Open)

And there you go, data that can be drawn on any wifi card with any GPS device (if you change the code for your device).  Try it out and let me know if it works or what errors you come up with.  This is just a prototype, so expect v1.01 to be out soon with updates.

Update:

I wrote this post and completely forgot to add the screen shots!

apprunning
Gathering Data
googleearth
Google Earth Data

Garmin Wardriver – Part 2

I’m very happy to say, this is a simple project, to get working in its most basic form.  Note, I said it’s most basic form so no hate mail on the fact that this is nothing more than a quick script!  There are plans to actually go deeper, make this open to more than my device, not use already existing programs, etc.  But for the basic concept and starter, I’ve made this program use gpsbabel to get the gps information and iwlist to get the network information.  I had started with pywifi but found this to be a problem because there was an overbound error.  This bug will be reported, it seems it has a problem with converting an integer to a float on a 64bit machine.

So with no futher ado, here is the script:

#!/usr/bin/env python
import os, re, time

# DEATH FUNCTION
def die(msg):
	print ' [*] ERROR: %s' % msg
	exit(1)

# ENSURE WE ARE ROOT
def checkroot():
	if os.getuid() != 0:
		die('Run this program as root.')
	return

# GET NETWORK INFO
def getessid(dev):
	nets = os.popen('iwlist %s scan' % dev).read()
	pat  = re.compile(r'ESSID:".*"')
	mess = re.findall(pat, nets)
	found= []
	for find in mess:
		found.append(find.split('"')[1].split('"')[0])
	return found

# GET GPS INFO
def getposition(dev):
	pos = os.popen('gpsbabel -i garmin,get_posn -f %s' % dev).read()
	pos = pos.splitlines()[1].split(' ')
	return [pos[1],pos[2]]

# RUN IT
def main():
	checkroot()
	found = getessid('eth1')
	pos   = getposition('/dev/ttyUSB0')
	for find in found:
		print 'ESSID: %s @ %s | %s' % (find,pos[0],pos[1])
	exit(0)

if __name__ == '__main__':
	main()

So what you see here is that I’m using os.popen() to call my programs to draw data.  Unfortunately, iwlist is painfully slow, to the point there’d be a five second delay on some slower machines between the call and having the data ready.  This is why I want to develop the application to not be dependent on other programs, but for the time being, this works as proof of concept in the data gathering stage.  It’s now just a matter of adjusting the code to run this constantly and load data to an overlay when entering and leaving an ESSID’s area.

Any comments for improvements?  Don’t forget, you can join this project any time on SourceForge!

Garmin Wardriver

For my birthday, my wife got me a GPS (Garmin Venture HC).  I have been disappointed in it’s integration with Linux, most particularly it’s ability to communicate with gpsd (usb input, not serial).  I had high hopes of doing some wardriving and kismet does not gather any of the data despite it’s configuration.  I can get gpsd to get some cryptic messages from the device but I found that this command: `gpsbabel -T -t garmin -f /dev/ttyUSB0` will generate the current coordinates.  So instead of getting frustrated, I’ve decided to open my first SourceForge project.  You can find it listed as Garmin Wardriver.

The concept seems simple enough, generate location through direct communication with the GPS device or through the gpsbabel command above and then gather a list of local ESSID’s with their strength.  With this data, updated each second, one could generate a location for entering an ESSID’s area, it’s strength as you move through and when out.  Output this to an overlay for a program such as Google Earth and that is a wardriver!  I can see this branching to more advanced uses but for the basic proof of concept, a command line program should suffice.  This will be written in Python and I’ve looked into utilizing the pygarmin and pywifi modules instead of generating information from preexisting programs.

DONE!!!

It is done!  The XFDL Loader is completed and it is functional.  It came down to the wire, with less than an hour left in submission time to complete but it did get done.  Here is a sample XFDL form and a sample CSV data file (RIGHT CLICK BOTH TO SAVE) to use.  The process to use the web application is (each step is a different page):

  1. Load the two sample files by file type.
  2. Set up data to merge to the form.
    • Use the drop down box on the right to select data by the header
    • Write data in the middle column input boxes to have default data for all forms.
  3. It’ll take awhile to generate the forms, be patient.  When completed, there will be a link to download a zipped archive of your forms.

And that’s it.  Be aware, because the project changed from PHP to Python, we had 10 days to generate the web application.  Therefore, there is no styling (it’s not pretty) and it might not work on all forms.  Also, it only selects text inputs.  Check boxes, more options, etc are yet to come, but this was needed to be functional by May 15th, and with only minutes to spare, it was done!

Approaching the final hours!

The project is due tomorrow!  I have a lot of work to do, but it finally appears possible to have this all done.  Thank you to my team member who contributed the code to correct the xml.dom.minidom’s output to be read correctly by PureEdge and Lotus Forms Viewer.  This will enable me to save, although I’m a bit sad that I spent so much time  this week working on that.  At this point, I need to complete the parsing scheme, develop a function to save the data to forms per the CSV file and then send back those files in a zipped archive.  All small steps, and assuming no road blocks, able to get done today.  A quick bit of documentation and packaging and this barely beta, functional web application will be ready for submission.  This may require an all-nighter and it’s down to the wire, but I think it will work.  Keep your eyes on the XFDL Loader as it will be updated through the day!

Frustration…

So I have now made a front page to upload a CSV file and an XFDL file for this XFDL web application. Nothing is more surprising than being a few short steps from having a working prototype to discover you’ve made a grave error. Here’s my mistake. I used python’s xml.dom.minidom module to parse and edit the file in it’s XML form. But when saving it back, it becomes obvious that the encoding causes some minor problems, but the major problem comes in the form for it’s saved state. Where the XFDL file will have a set of tabs, the minidom would correct these to read just which then is not able to be read by Lotus Forms Viewer or PureEdge! I’ll be frantically rewriting my parsing in other modules tonight to find one that is compatible in it’s write method!

XFDL Viewer Update…

As I dig through miles of XML, I realize I have not posted lately. I’ve been a bit busy meeting the May 15th deadline for my project. But here’s a quick update. First, don’t forget to view the update viewer. It’s not pretty, but it works to the point I’ve set it. I’ve changed from PHP to using Python CGI (a language I’m more comfortable with) and I’ve done what took two weeks in two days. Too bad this wasn’t thought of before!! Anyhow, I figured I’d pass along this bit of code from Neil Funk that shows a better method for decompression of an XFDL in Python:

#!/usr/bin/python
from base64 import *
import zlib

# OPEN FILES
inp = open('example.xfdl','rb').read()
out = open('example.xml,'wb')

# TAKE OUT THE MIME DATA
magic = inp.splitlines()[0]
data   = inp.split(magic)

# THE TRICKY PART -- Look to the python manual for explanation.
wbits = 15+32
newData = zlib.decompress(b64decode(data),wbits)

out.write(newData)
out.close()

And drumroll please, for Chris Hutton contributed this PHP code for recompressing an XFDL from XML.  I’m working to translate this to Python, but for the time being, an XML with an XFDL extension works.

// Export XML, gzip, and base64 encode. Append XFDL header information and output to user.
// XML is the raw data to be saved.
$newxml = $xml->asXML();
// chunk_split is new to me!
$output = chunk_split(base64_encode(gzencode($newxml)));
// Add the header!
$output = "application/vnd.xfdl;content-encoding=\"base64-gzip\"\n". $output;

header("Content-disposition: attachment; filename=\"{$filename}\"");
header("Content-type: application/vnd.xfdl");

echo $output;

So thank you all for your contributions!  I’ll try to keep this blog more up-to-date.

XFDL Viewer – Good and Bad.

I used to think of myself as a decent coder, but this XFDL project is a monster.  Particularly with the parsing schemes.  Let alone the May 15th suspense on the project!!  Oh well, if it doesn’t get done, I’m still working on it…  So I broke apart the XML and just to give a taste of the parsing for this, here’s my notes:

Mind you, I’m skipping the globals but here what needs to be parsed from there:

  • Title
  • Version
  • Fontinfo
  • Bgcolor
  • Print Settings
  • Bindings

This first block is the “field” form.  This is the main part to parse because this is where all values except checks and signatures will go.

<field sid="TO"> --> sid == div id
	<itemlocation>
		<ae>
			<ae>absolute</ae> -- style='position:absolute'
			<ae>y</ae>
			<ae>x</ae>
		</ae>
		<ae>
			<ae>extent</ae> -- dimensions
			<ae>l</ae>
			<ae>w</ae>
		</ae>
		<value>THIS IS WHAT NEEDS EDITTING!</value> - input, no border
		<broderwidth>0</broderwidth> --> style
		<fontinfo> --> style
			<ae>type</ae>
			<ae>size</ae>
			<ae>attribute</ae>
		</fontinfo>
		<justify>center</justify> --> style
		<scrollhoriz>wordwrap</scrollhoriz>
		<scrollvert>fixed</scrollvert>
		<next>TO</next> -> form taborder
		<previous>DATE_A</previous> -> form taborder
		<acclabel>lorum ipsum</acclabel>
		<format>
			<ae>string</ae> --> set form input type
			<ae>optional</ae> --> validation check
			<length>
				<ae>0</ae> vert
				<ae>18</ae> horiz
			</length>
		</format>
	</itemlocation>
</field>

Next part, check boxes.  Nothing too scary here.  Much the same as above.

<check sid=""> same
	<itemlocation></itemlocation> same
	<value>on|off</value>
	<fontinfo></fontinfo> same
	<next></next> same
	<previous></previous> same
	<acclabel></acclabel> same
</check>

Here we get complicated.  Nothing bad about the labels, except there form uses labels for definitions at the end and you’ll see it later where it is reused for a new purpose.  This could pose a good challenge!

<label sid=""> same
	<itemlocation></itemlocation> same
	<value>TEXT</value>
	<linespacing>1</linespacing> OPITONAL
	<fontinfo></fontinfo> same
	<fontcolor>black</fontcolor>
	<format></format> same
</label>

Lines, not too bad… will just be a simple parsing the xml to putting them on the page.

<line sid=""> same
	<itemlocation></itemlocation>same
</line>

Buttons!  These would be easy but they will associate with signatures.

<button sid=""> same
	<itemlocation></itemlocation> same
	<value compute="">FROM CERT</value>
	<type>signature|</type>
	<vfd_signmode>custom</vfd_signmode>
	<printvisible compute="">on|off</printvisible>
	<signformat>???WTF???</signformat>
	<signature>FOR BINDINGS</signature>
	<signer>FROM CERT</signer>
	<custom:onClick>function</custom:onClick>
	<signoptions>
		<ae>omit</ae>
		<ae>triggeritem</ae>
		<ae>coordinates</ae>
		<ae>ufv_settings</ae>
	</signoptions>
	<vfd_group>??</vfd_group>
	<format></format> same
	<previous></previous> same
	<next></next> same
	<image>FROM CERT?</image>
	<signatureimage>FROM CERT?</signatureimage>
	<signitemrefs>
		<ae>LOCK BINDS</ae> -- USE FOR VALIDATION
	</signitemrefs>
</button>

Not even touching signatures until I get the parsing scheme in place!

<signature>
	WILL DO LATER
</signature>

Data will be easy enough, just needs to be decoded and displayed.  Whew… may need to save the files to the server to display but I think HTML can handle an image from data.

<data sid=""> relates to signatures & images
	<filename></filename> -- image (optional)
	<mimedata encoding="base64-gzip"></mimedata>
</data>

Do I really need the toolbar if I’m not using it’s functions?

<toolbar sid="TOOLBAR">
	<bgcolor>
		<ae>gray60</ae>
	</bgcolor>
</toolbar>

Is IBM so dense they can’t find a new name for the toolbar tags instead of reusing label?

<label sid="TOP">
	<itemlocation>
		<ae>
			<ae>within</ae>
			<ae>TOOLBAR</ae>
		</ae>
		<ae>
			<ae>absolute</ae>
			<ae>0</ae>
			<ae>0</ae>
		</ae>
	</itemlocation>
	<image>PAGE1.ArmyLogoTop</image>
	<imagemode>clip</imagemode> -- style
	<active>off</active>
</label>

I won’t complain about this one!  Seems pretty simple, just like lines…

<spacer sid=""> same
	<itemlocation></itemlocation> same
</spacer>

So keep watching the blog… I’ll post more when I figure out how to handle all this data.  And this all needs to be cycled per page to output to the browser… yuck.

XFDL Viewer

The scope of the “Apps 4 the Army” competition that I am making my XFDL Viewer for is to use web apps.  So I did a quick change to PHP and read up and got a framework setup.  The idea is to be able to import the XFDL file and then parse the resulting XML to input values, either on a single form or by batch through an uploaded database.

The framework is complete and I’m pretty happy with the results as I’ve done much more application programming than web development, but PHP isn’t too bad.  After getting the frame work together, I started to work on parsing.  I mistakenly uploaded a XFDL file rather than the decompressed XML and I found something remarkable.  PHP’s SimpleXML apparently can decompress the XFDL file!! This takes out a very complicated step of my project!!!  I’m still working to figure out why the recompression does not produce the same output but that may not be a problem with the web interface.  Stay tuned for more updates.

Ubuntu 10.04 – Fixing Title Bar Buttons (Place on the right)

After downloading Ubuntu 10.04 Lucid Lynx, I noticed that the biggest user interface change is the title bar buttons.  Unlike Windows or Mac, the buttons are located on the left side.  This is not too bad if you can get used to it, but I found several complaints online.  So, for those who are not used to gconf-editor, here are instructions to fixing the title bar.

  1. Open a terminal or use Alt+F2 and type ‘gconf-editor’.
  2. In the tree menu on the left side go to: apps -> metacity -> general
  3. On the options menu (right side of the editor) find the option midway down for ‘button_layout’.
  4. Editing these options can let you customize the menu, here’s how:
    • The colon ‘ : ‘ sets the middle, so anything on the left of the colon is on the left of the title bar.
    • Settings are comma separated values of menu, minimize, maximize, close, separator
      • Duplicates and unknown values are silently ignored.
    • Example #1: menu:minimize,maximize,close
    • Example #2: close,minimize,maximize:
    • Example #3: minimize,maximize,close:

See, one of the great things with Linux is that these configurations are available.  If you take a moment to look around your gconf-editor, you’ll see how powerful this tool is to your user interface customization.  Feel free to contact me or comment here with questions regarding this process.

Ubuntu 10.04 Alpha 2 – Review

So I decided to update my laptop to Ubuntu 10.04.  This process got off to a rough start because a pesky dog ran into my laptop, shutting the lid and causing a sleep halfway through the upgrade.  The problem came in that the computer was not set to be able to resume and so I only had half the updates done.  So when I rebooted, there was no graphical display, and for awhile, not even the ability to use a terminal.  Thankful, grub had been updated and I was able to boot into the recovery counsel, compile a wireless driver, get an internet connection and download and install the rest of the updates manually rather than through ‘sudo upgrade-manager -d’.  Once that was done, I was amazed at the new Ubuntu.

Improvements that I noticed:

  1. Better Graphical Display (Finally away from the orange/brown theme!)
  2. Applets, as per the past four releases, are better in bothe appearance and use.
  3. Ubuntu is keeping with its integration of web based applications and social networking through the Desktop.

There are many more improvements but these are the ones that I’ve noticed first.  I’ve also seen through Launchpad that bugs are being addressed, which in this pre-review from last year, it would appear the the integration of fixes for the bugs in Linux has improved quite aways in the past year, and this release appears to be continuing the quality product of Ubuntu Linux!

XFDL in Linux :: Update

So, after talking with the Army’s G6 (essential the IT Department), the competition I’m entering (which because I’m not an active duty Reservist, I cannot receive prize money) is focused on web applications, not desktop applications.  The changes you can expect to see in my coding is that there will be quite a bit of php, perl and python that I’ll be using rather than the application side.  At the same time though, I’ll take what I do in this web application and use it for developing a desktop application and a Microsoft Office plugin that can be used to batch load files.  Just figured I’d acknowledge the reason for changes.  On the plus side of all of this, perl has a specific Mime module and php has a great and simple interface to xml parsing, so this may end up easier as a web application.

Python Curses – Custom Menu

Continuing on the same project as the previous post, I came to wanting to make a custom menu with curses in Python.  Realizing that there are functions to create menus in curses already, I wanted to build this fro m the bottom up.  The concept was to produce a menu that would highlight the selection change on the arrow keys or direct input, and then on a press of the Enter key the menu would return that selection.

Now, while writing this, you’ll see in my code that I took probable the least efficient way of building this menu, but it helps in making itself explanatory for the person learning curses.  As for the context of this coding, I built it as a function in my XFDL viewer, so there are 5 options in the menu.  I used win.keypad(0) to enable the use of the arrow keys but for some reason, the curses.KEY_UP was not being detected so the arrow key up and arrow key down are 259 and 258, respectively.  This does work though, I also have the menu catch numbers 1-5 and set the highlighted line accordingly.

def menu():
    curses.init_pair(1,curses.COLOR_RED, curses.COLOR_WHITE)
    screen.keypad(1)
    pos = 1
    x = None
    # I'm going to be lazy and save some typing here.
    h = curses.color_pair(1)
    n = curses.A_NORMAL
    while x != ord('\n'):
        # Gotta reset the screen from the root or lose the border, window, etc.
        screen.clear()
        screen.border(0)
        screen.addstr(2,2, "XFDL VIEWER", curses.A_STANDOUT)
        screen.addstr(4,2, "Please select an option...", curses.A_BOLD)
        # Detect what is highlighted by the 'pos' variable.
        if pos == 1:
            screen.addstr(5,4, "1 - XFDL -> XML",h)
        else:
            screen.addstr(5,4, "1 - XFDL -> XML",n)
        if pos == 2:
            screen.addstr(6,4, "2 - XML  -> XFDL",h)
        else:
            screen.addstr(6,4, "2 - XML  -> XFDL",n)
        if pos == 3:
            screen.addstr(7,4, "3 - Show XML",h)
        else:
            screen.addstr(7,4, "3 - Show XML",n)
        if pos == 4:
            screen.addstr(8,4, "4 - Exit",h)
        else:
            screen.addstr(8,4, "4 - Exit",n)
        if pos == 5:
            screen.addstr(9,4, "5 - DEBUG", h)
        else:
            screen.addstr(9,4, "5 - DEBUG", n)
        screen.refresh()
        x = screen.getch()
        # Is 'x' 1-5 or arrow up, arrow down?
        if x == ord('1'):
            pos = 1
        elif x == ord('2'):
            pos = 2
        elif x == ord('3'):
            pos = 3
        elif x == ord('4'):
            pos = 4
        elif x == ord('5'):
            pos = 5
        # It was a pain in the ass trying to get the arrows working.
        elif x == 258:
            if pos < 5:
                pos += 1
            else:
                pos = 1
        # Since the curses.KEY_* did not work, I used the raw return value.
        elif x == 259:
            if pos > 1:
                pos += -1
            else:
                pos = 5
        elif x != ord('\n'):
            curses.flash()
            # show_error() is my custom function for displaying a message:
            # show_error(str:message, int:line#, int:seconds_to_display)
            show_error('Invalid Key',11,1)

    return ord(str(pos))

I’ve highlighted the lines pertaining to my work around for the key pad.  This function will return the menu option and then that is processed for a reaction.  Reminder: the ‘screen’ object for my curses window is a global variable. I’m quite thrilled at the simplicity of this and the curses library, although I am disappointed in the lack of tutorials on the web deeper than typical ‘Hello World’ tutorials, but I hope these posts go to help others exploring this library!

Here’s a nice picture of the library in action:

Customize menu in action...
Be sure to comment on these tutorials and let me know if there is more detail needed or if they are helpful!!