Archive

Archive for December, 2008

GWT XML Indenter/Formatter

December 31st, 2008 5 comments

So while I was working on one of my outreach projects as a graduate student, I wanted to write a simple XML indenter to make my GWT generated xml more aesthetically appealing using stock GWT. The xml document is assumed to be as lean as possible (There are no empty #text nodes that are usually in xml because of the indentation.)

I should also mention that I’m posting this because I didn’t really see any stock simple GWT indenters after a quick google. The following is not meant to be a complete indenter, just something quick and simple to organize xml.

Here’s a basic indenter.

	public String formatXML(Node node,String tab_str)
	{
		String formatted="";
 
		if (node.getNodeType()==Node.ELEMENT_NODE)
		{
			String attributes="";
			for (int k=0;k < node.getAttributes().getLength();k++)
				attributes+=" "+node.getAttributes().item(k).getNodeName()+"=\""+node.getAttributes().item(k).getNodeValue()+"\"";
 
			formatted=tab_str+"<"+node.getNodeName()+attributes+">\n";
 
			for (int i=0;i< node.getChildNodes().getLength();i++)
			{
				formatted=formatted+formatXML(node.getChildNodes().item(i),tab_str+"    ");
			}
			formatted=formatted+tab_str+"</"+node.getNodeName()+">\n";
		}
		else
		{
			if (node.toString().trim().length()>0)
				formatted=tab_str+node.toString()+"\n";
		}
 
		return formatted;
	}
Categories: Education Tags: , , , ,

Renaming Window Title’s

December 29th, 2008 6 comments

So, a few days ago, a friend of mine complained about not being able to rename the title captions of his windows. You may be wondering why anyone would want to do this. Well, the main reason is for code development. At the company I used to work at, we used an IDE called IAR. While for the most part, it is decent, when a person loads more than one workspace when debugging multiple chips, the IAR windows are all named the same thing, and so it gradually becomes more frustrating as more and more IAR instances are started.

My friend wanted a quick and dirty way to rename windows. I googled for an app, but there didn’t seem to be any “free” utilities that did this. Being the ex-windows API geek I am (from messing with vb5/6 in the old-days), I decided I’d give it a with. Fortunately, I found a great codeproject project to start as a base. Turns out the project has been done quite well (at least to my liking). I believe credit should be given where it’s due, and so I will simply highlight the minor changes I made to modify the project to make it change window titles in addition to hiding/showing windows.

To make the little app more useable, I’ve added a hotkey for editing the title of the current window (Alt+F2). It should be configurable from the menu. My friend has tried it and it seems to work. For the time being, I’ll upload the binary and source. There aren’t really any real comments as it’s pretty much the code project source with about a page’s worth of code modifications and additions.

Modifications:

In summary, I simply added in the SetWindowText api function and added an extra hot-key. I also modified the interface code to allow people to rename windows; however it seemed cumbersome so I added a hot-key feature, which seems to work for most of my friend. I guess I’m getting a little lazy, especially since most of the code is not mine, so I probably won’t even bother to paste the bits of code I did write. I believe it’s pretty clear, so it shouldn’t be an issue.

Download: Windows_Hider_Renamer.zip

Pbox2avi for windows

December 17th, 2008 No comments

It appears that windows is incompatible with some of the shelling parts of my python script, so I have uploaded a windows specific version to take care of these issues.

Issues are:

  • piping
  • commands.getstatusoutput (doesn’t work on windows)

Download: pbox2avi_win.py

Pbox2avi update!

December 15th, 2008 No comments

Thanks to Phil’s advice on how to use exiftool more effectively, I’ve decided to update the script so it’s a little shorter.

Download:pbox2avi.py

# python script to extract lecture slides and mp3's from UCSF lecture files for conversion
 
#requires swfextract
 
import commands,sys,re
 
def parse(filename):
    #check filename for .swf extension
    if not filename.find('.swf'): # not a comprehensive check
        return
 
    #open file
    status, output = commands.getstatusoutput("swfextract %s" % (filename,))
 
    print output
 
    #find "JPEGs: ID(s)"
    slide_identifier = "JPEGs: ID(s)"
    start=output.find(slide_identifier)
    slide_extract=[]
    if start:
        start += len(slide_identifier)+1
        slide_end = output.find("[-s]",start)
        print start,slide_end
        slide_extract=output[start:slide_end-2].replace(" ","")
 
    #find "Sounds: ID(s)"
    sound_identifier = "Sounds: ID(s)"
    start=output.find(sound_identifier)
    sound_extract=[]
    if start:
        start += len(sound_identifier)+1
        sound_end = output.find("[-f]",start)
        sound_extract=output[start:sound_end-2].replace(" ","")
 
    # now extract all the data
    print "swfextract %s -P -j %s -s %s" % (filename,slide_extract,sound_extract)
 
    status, output = commands.getstatusoutput("swfextract %s -P -j %s -s %s" % (filename,slide_extract,sound_extract))
 
    return slide_extract,sound_extract
 
def create(slide_extract,sound_extract,outputfile):
    #first throw out every other picture because second picture is always a thumbnail
    slides=slide_extract.replace(","," ").split(" ");
    slides=[slides[i] for i in range(len(slides)) if i%2 ==0]
 
    sounds=sound_extract.replace(","," ").split(" ");
 
    print "Number of slides: %s, number of mp3's: %s" % (len(slides),len(sounds))
    for i in range(len(sounds)):
 
        vidcmd="jpeg2yuv -n %d -I p -f 2 -j %s | yuv2lav -o temp.avi" % (int(round(2*10*(duration("sound%s.mp3" % (sounds[i],))))/10),"pic%s.jpg" % (slides[i],))
        # print vidcmd
        status,output=commands.getstatusoutput(vidcmd)
 
        sndcmd="mencoder temp.avi -o slide%d.avi -ovc lavc -lavcopts vcodec=msmpeg4 -oac copy -audiofile sound%s.mp3" %(i,sounds[i])
 
        # print sndcmd
        commands.getstatusoutput(sndcmd)
        print "Finished processing slide %d" % (i,)
 
    print "Cleaning up..."
    # remove unnecessary data
    commands.getstatusoutput("rm *.jpg *.mp3 temp.avi")
 
    slidevids=["slide%s.avi" % (i,) for i in range(len(slides))]
 
    slidevids=" ".join(slidevids)
 
    print "Combining slides..."
    # combine all of them
    commands.getstatusoutput("mencoder -oac copy -ovc copy %s -o %s" % (slidevids,outputfile))
 
    print "Cleaning up..."
    commands.getstatusoutput("rm slide*.avi")
 
def duration(mp3):
    # find duration of mp3 using exiftool
    cmd="exiftool %s -Duration -n -S -s" % (mp3,)
    status,output = commands.getstatusoutput(cmd)
    return float(output)
 
if __name__=="__main__":
    slides,sounds=parse(sys.argv[1])
    if len(sys.argv)==2:
        create(slides,sounds,"output.avi")
    elif len(sys.argv)==3:
        create(slides,sounds,sys.argv[2])
Categories: Education, Releases, Useful Apps Tags: