components-based approach, two demos
Posted: Fri Apr 21, 2006 4:54 pm
In have uploaded in my revonline folder two demos of widgets illustrating a mvc approach to programming (Username=Marielle,category = programming).
1. file download widget
The widget doesn't do anything particularly exciting (you specify a url and a target directory and push on the download button and the file gets downloaded.
What is of interest is the way the widget is written. The view is completely separated from the model. The model doesn't need a view to work. The view requires no more than a group called "wg_file_download" with the appropriate functions on the card (could be made invisible). There is no need to put any script in the back of the stack. It is built-in to allow for localisation (thought I didn't fully implement this feature yet).
2. gradient widget
This is a bit more exciting in what it does. I outline a method to easily create using tips from "Simple Method Of Storing Colour Ramps" (Written By Paul Bourke, June 2003; Adapted from OGLE By Dr. Michael J. Gourlay)
What is illustrated here is how such a problem can be divided into 3 main components: (1) a speadsheet object for manipulating the gradient data and reformat, (2) a gradient creation utility that will create a gradient from these data, and (3) a snapshot utility for transforming the gradient in a permanent format
To the ones sceptical about components, I reckon that the script can appear somehow longer than the one you would have written to solve that problem. The interest of adding a few more lines of script the way i did is that you can easily define the widget components (view elements) and script parameters from outside the view. It takes more time to write a component. But any component you write this way is more robust (because used in multiple contexts)
Tested on a Mac only. Any feedback will be much appreciated.
Marielle
1. file download widget
The widget doesn't do anything particularly exciting (you specify a url and a target directory and push on the download button and the file gets downloaded.
What is of interest is the way the widget is written. The view is completely separated from the model. The model doesn't need a view to work. The view requires no more than a group called "wg_file_download" with the appropriate functions on the card (could be made invisible). There is no need to put any script in the back of the stack. It is built-in to allow for localisation (thought I didn't fully implement this feature yet).
2. gradient widget
This is a bit more exciting in what it does. I outline a method to easily create using tips from "Simple Method Of Storing Colour Ramps" (Written By Paul Bourke, June 2003; Adapted from OGLE By Dr. Michael J. Gourlay)
What is illustrated here is how such a problem can be divided into 3 main components: (1) a speadsheet object for manipulating the gradient data and reformat, (2) a gradient creation utility that will create a gradient from these data, and (3) a snapshot utility for transforming the gradient in a permanent format
To the ones sceptical about components, I reckon that the script can appear somehow longer than the one you would have written to solve that problem. The interest of adding a few more lines of script the way i did is that you can easily define the widget components (view elements) and script parameters from outside the view. It takes more time to write a component. But any component you write this way is more robust (because used in multiple contexts)
Tested on a Mac only. Any feedback will be much appreciated.
Marielle