Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

Friday, March 13, 2009

Python CGI Debugging howto: Part 2

Ok, in the previous post I wrote that probably there was a better way to display errors for cgi script in python, so, here it is:

import cgitb
cgitb.enable() #This enable it all


Two lines :)

Simply put them at the beginning of a script and they do all the work. It's also possible to output errors in a log file instead of displaying them in the browser of the user (just take a look at python documentation on cgitb.enable()), a far better solution for production environment.

Python CGI Debugging howto

I found this useful when you are trying to debug a python script running on a remote server (that has a previous version of python, in my case :( ).

To show the classic interpreter error messages just do this:

import sys
sys.stderr = sys.stdout

print "Content-type: text/html\n"


In this way, we set the errors to output text on the standard output (in other words, we redirect the errors to the standard output), then we print the standard HTTP header to inform the browser that the following text will be an HTML page (even text/plain works fine) and if we get an error, it will be in some part of the page source :D.

Simple, probably not the best, but it works.

Wednesday, January 21, 2009

FLTK2 howto: Display images on widgets

I spent some time figuring out how to do this. Yes, you simply call:

widgetName->image(myPrettyImage);

But (at least for me) this did not work.
So I searched in the documentation but all seemed right.
The next logical step was "search on Google" (everyone should know that "he is your friend").

I read something on a forum regarding the function fltk::register_images() (Absolutely not documented) and I understood that it must be called before you use any other image-related stuff with fltk2.

So, if you want a widget to display your beautiful image you must code a main() like this:


#include "myMainWindowWithBackgrounImage.h"
#include <fltk/SharedImage.h>
#include <fltk/run.h>

int main()
{
fltk::register_images();
myMainWindowWithBackgroundImage win;
win.show();
return fltk::run();
}
You must then link the executable to libpng, libjpeg and libfltk2_images passing "-lpng -ljpeg -lfltk2_images" to the compiler.