Sunday, September 12, 2010

xulexplorer -- getting your xml gui on

So in my never ending, what project should I start this week,
even though I haven't finished the other twenty I've started
in the last year, I decided to look at Mozilla's xulrunner
and xul interface for a cross platform program.

Having built a never completed help extension for Thunderbird
a few years back, I was familiar with the general concepts.
I looked around to see if anyone had created any kind of GUI
based application that would help create the xul files needed
for an xulrunner based application. I found XULExplorer. It's
still a young program, but had a wizard feature that would
set up your basic application structure and needed files.
Unfortunately the latest version has an bug introduced by
going from a flat file structure to using jar files to hold
it's internal files (see bug https://bugzilla.mozilla.org/show_bug.cgi?id=462561). This broke the application build wizard.

A quick fix to get this feature working on your local copy of the application:
  1. move to the xulexplorer/chrome/ directory
  2. extract en-US/ directory structure from the en-US.jar file
    (using your favorite archive manager) to the chrome/ directory.
    (you should have an en-US/ directory in the chrome directory when finished extracting.)
  3. edit the en-US.manifest file in the chrome/ directory to read:
    locale explorer en-US file:en-US/
Now I have two projects to hack for the price of one. Fix issues I find with XULExplorer as I work on my application -- an even better guarantee that I won't finish anything.

Saturday, January 30, 2010

swfobject 2 tweaking for firefox

Generally I avoid flash if I can, but I found what I thought would be a quick side job (yea craigslist computer gigs category), fixing a flash embedding problem with a website.

The site used swfobject version 1.4, and it wasn't loading files in Internet Explorer. After a little searching I found the swfobject website, saw there was version 2 out. I emailed the person with the problem, and told them I could fix it. I figured a quick upgrade and the problem would be solved.

4 hours later.

So it turns out the Firefox 3.5 has a display issue which is trigger when using version 2 of swfobject. After reading many forums complaining about this or similar problems, I finally found two potential answers to the problem. See comments 6, 33, & 37 at url http://code.google.com/p/swfobject/issues/detail?id=327

After using the code generator at
http://www.bobbyvandersluis.com/swfobject/generator/index.html

I added the following code to the javascript in the header of the html page:
swfobject.switchOffAutoHideShow();  /*line added to help fix firefox issue*/
swfobject.embedSWF("example.swf", "flashContent", "100%", "100%", "8.0.0", "expressInstall.swf", flashvars, params, attributes);
and added the following html tag to the body of the page:

<div id="wrapper"> generated flash content html code </div>

CSS code must also be added to this page for the code to work with Firefox 3.5. I put the code in a linked css file, but it can be placed within the generated code if desired:
html, body, div#wrapper {
border: none;
height: 100%;
margin: 0;
padding: 0;
width: 100%;
}
div#wrapper {
background: none;
}
body {
border: 0px; /* IE MUST have a border set for slideshow to work */
}
the div#wrapper tag and corresponding css make sure that the area of the content block in which the flash file is inserted is not zero. This is necessary when using percentages to set the height and width of the flash object.

Saturday, November 14, 2009

instanceOf in renaissance

I'm learning Objective C and the GNUStep development environment. For my project I'm using the Renaissance library for my GUI. The app will allow adjustments to an image's brightness, white balance, hue, etc. Following is an image of the interface I'm using for making adjustments to these various attributes.

The stepper and slider controls do not have a direct tag representation in gsmarkup, but using the control tag with the instanceOf attribute, the Renaissance library will create these controls. As the saying goes, an example is worth a thousand man pages:

Adjustments.gsmarkup
<?xml version="1.0"?>
<!DOCTYPE gsmarkup>
<gsmarkup>

<objects>
<window title="Image Adjustments" id="WindowAdjustments" delegate="#NSOwner">
<vbox>
<box title="Brightness"><hbox>
<control instanceOf="NSSlider" id="SliderBrightness" action="setBrightnessViaSlider:" height="28" width="256" />
<textField id="TextBrightness" action="setBrightnessViaText:">000</textField>
<control instanceOf="NSStepper" id="StepperBrightness" action="setBrightnessViaStepper:" height="28" width="18" />
</hbox></box>
</vbox>
</window>
</objects>
<connectors>
<outlet source="#NSOwner" target="#SliderBrightness" key="SliderBrightness" />
<outlet source="#NSOwner" target="#TextBrightness" key="TextBrightness" />
<outlet source="#NSOwner" target="#StepperBrightness" key="StepperBrightness" />
</connectors>
</gsmarkup>

Adjustments.h
#import <AppKit/AppKit.h>
#import <Renaissance/Renaissance.h>

@interface Adjustments : NSObject
{
IBOutlet NSSlider *SliderBrightness;
IBOutlet NSTextField *TextBrightness;
IBOutlet NSStepper *StepperBrightness;
}

- (id) init;
- (void) dealloc;

- (void) setAdjustmentsDefaults;

- (void) setBrightnessViaSlider: (id)sender;
- (void) setBrightnessViaText: (id)sender;
- (void) setBrightnessViaStepper: (id)sender;
@end

Adjustments.m
#import <Adjustments.h>

@implementation Adjustments

- (id)init
{
if ((self = [super init]))
{
[NSBundle loadGSMarkupNamed:@"Adjustments" owner:self];
[self setAdjustmentsDefaults];
}
return self;
}

- (void)dealloc
{
[super dealloc];
}

- (void) setAdjustmentsDefaults
{
[SliderBrightness setMaxValue: 255];
[SliderBrightness setMinValue: 0];
[SliderBrightness setIntValue: 227];
[TextBrightness setIntValue: [SliderBrightness intValue]];
[StepperBrightness setMaxValue: [SliderBrightness maxValue]];
[StepperBrightness setMinValue:[SliderBrightness minValue]];
[StepperBrightness setIncrement: 1];
[StepperBrightness setIntValue: [SliderBrightness intValue]];
}

- (void) setBrightnessViaSlider: (id)sender
{
[StepperBrightness setIntValue: [SliderBrightness intValue]];
[TextBrightness setIntValue: [SliderBrightness intValue]];
}

- (void) setBrightnessViaText: (id)sender
{
[StepperBrightness setIntValue: [TextBrightness intValue]];
[SliderBrightness setIntValue: [TextBrightness intValue]];
}

- (void) setBrightnessViaStepper: (id)sender
{
[SliderBrightness setIntValue: [StepperBrightness intValue]];
[TextBrightness setIntValue: [StepperBrightness intValue]];
}

@end

Saturday, November 7, 2009

My first python

Well my first python code in a long time. My first was modifying a zope photo album module to work after an dist-upgrade of a Debian GNU/Linux system.

Any who--I'm working on a project which will store e-mail addresses in a relational DB. I am contemplating storing the the email in two parts--the user name and the domain name. When storing the domain name, I'm considering storing the domain name in reverse order (i.e. "roansbitsnbytes.blogspot.com" stored as "com.blogspot.roansbitsnbytes") for potentially faster indexed searching. Of course this complicates other aspects of the program (at least on the db side), but I'll deal with that as the design comes.

One of my concerns with storing the domain name this way, is not requiring the client program to have to deal with how the e-mail addresses are going to be stored. I know reversing the domain name can be done in a stored SQL based procedure, but I figure another language can probably do it more concisely (and quicker). PostgresSQL allows you to use stored functions created in Python. After a little digging around, here is the one liner I came up with to reverse the domain name:

".".join(((domainname.split('.'))[::-1]))

where domainname is a string passed to my function in PostgreSQL.

I like how concise this is. When I started I was pretty sure I would be using a split and join command. I just wasn't sure if it could all be done with one line of code. Python's slice notation for mutable sequences (aka the list of domain names created using the split command) makes this one liner nice and neat.

See this url: http://docs.python.org/library/stdtypes.html#typesseq-mutable for more on mutable sequences. Unfortunately, I can't find the original link that led me to this solution.

Friday, November 6, 2009