Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Code & GUI created based on data structure?

by jdtoronto (Prior)
on Jun 27, 2006 at 18:52 UTC ( [id://557857]=perlquestion: print w/replies, xml ) Need Help??

jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks,

I have a situation where I think I need some method of essentially creating GUI code based on a data structure, and have code execute itself based on the same structure. Here is my scenario:

I have an application which needs to be able to send PDF documents which are customised, either by email or to a printer. Currently I create a PDF file as a 'template' which has the basic content in it. Data from a database is used to customise the PDF, it might be an address block for a sales letter, or it might be specific text or graphics which are inserted based on user preferences. All of this is currently working.

I have a PDF, I have a Perl-Tk GUI window which creates a Config::Simple file which has the necessary config info. I can cusomtise the document and do what I need with it.

BUT, and there is always a BUT. What about when I need to change documents? I was thinking that I could package the PDF and a config data structure in a zip like package and when the user selects the template the structure is loaded into the config. BUT what if the structure of the document is different? The GUI that has been coded will no longer match the data structure that is needed. So...

How about I build the GUI based on the structure of the data? Then the same data structure could be used to run through a sequence of methods within the templating module. There are actually only maybe 5 methods required to place the data in the template and output it. But some of these 5 might be invoked multiple times depending on the data - getting things like the text position, colour, font choice and size form teh data structures.

Am I proposing something that is out of left field? Any suggestions, any pointers to something like this that may already exist.

jdtoronto

  • Comment on Code & GUI created based on data structure?

Replies are listed 'Best First'.
Re: Code & GUI created based on data structure?
by samtregar (Abbot) on Jun 27, 2006 at 21:05 UTC
    Sounds reasonable enough. This sort of thing is very common in the web world. For example, CGI::FormBuilder dynamically builds an HTML interface based on a data-structure. There's no reason the same thing couldn't work with PerlTk.

    -sam

Re: Code & GUI created based on data structure?
by leriksen (Curate) on Jun 28, 2006 at 00:26 UTC
    I have something exactly the same but I build an XML editor - the widgets are determined by the data types from the schema (spinboxs for integers, text boxes for strings etc) and my code builds these widgets as required by the XML file You'll find yourself using closures a lot to handle the callbacks - most of my methods return subroutines that get assigned to callbacks (-command or -validatecommand params for the Tk widgets) - the closure part comes from those subs having references to data from the time of their creation, to be used at the time their actually called - sounds like a time-warp waiting to happen, but its actually pretty cool.

    And dont forget that things like Firefox are built out of their XUL description - the firefox code interprets the XUL and builds the browser...so its a pretty common, albeit advanced, technique

    ...reality must take precedence over public relations, for nature cannot be fooled. - R P Feynmann

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://557857]
Approved by saberworks
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found