Novell Home

HowTo: Create a Home Cook's Recipe Book using the Linux Shell and RunRev GUI

Novell Cool Solutions: Feature
By Stomfi

Digg This - Slashdot This

Posted: 8 Jun 2005
 

StomfiLearning to use Linux at Home and Work
Welcome to my ongoing series of HowTo articles designed to help Linux newbies get comfortable with Linux. Before trying any of these HowTos, take a few minutes to study the prerequisites so you can hit the ground running.
--Stomfi

This HowTo describes the creation of a home cook's recipe system using the shell and Runtime Revolution. Unlike MS Windows versions, it does not track nutritional information, as it is just for collecting favourite recipes, which you are going to eat because you like them. It does, however, attempt to give you a shopping list based on common package sizes, or where relevant a delicatessen quantity. It also has a space for a picture, which you can take to remind you what it should look like.

I think other useful bits of information for a home cook are what cooking pots, pans, bowls or dishes are needed, and if any special tools like graters, mixers, etc., are required, so you can plan your work accordingly. We can make this an added note so that useful information can be recorded.

Besides the recipe, the number of servings and total preparation and cooking time can be shown.

Special Offer for Cool Solutions Readers: Free Copy of Runtime Revolution

The good folks at Runtime Revolution have extended a special offer to Cool Solutions readers to make it easier for you to implement the great ideas in Stomfi's articles. They are offering it for free to Novell customers who know the secret code. See this page for details.

This is a view of the first screen:

Using RunRev start a new stack and name it COOKBOOK. Call the card RTSELECT with the label "Cook Boo". Populate it with a scrolling list field called RTYPES, the label as shown, and these two buttons. The image field is just to fill up the blank space - Choose a nice one for your book.

The card script for RTSELECT is:

on openCard

global COOK

put ( $HOME & "/cookbook" ) into COOK

replace return with empty in COOK

global CBOOK

put ( COOK & "/book" ) into CBOOK

replace return with empty in CBOOK

put ( COOK & "/bin/rtypes.sh" ) into GETTYPES

replace return with empty in GETTYPES

open process GETTYPES for read

read from process GETTYPES until EOF

close process GETTYPES

put it into field "RTYPES"

end openCard

This script sets up a couple of global variables for the Cook Book home folder and the book folder, then it calls the shell script "rtypes.sh" which is in the Cook Book bin folder. This is the shell script:

#!/bin/bash

#rtypes.sh

#

#Get recipe types from recipe book and echo the list

#This is the second field of the recipe book. The first field is an index no

#which we use to join to the multi line records stored in separate files

#

#set up a variable name for the recipe book folder

RBOOK="$HOME/cookbook/book"

#create the list. Print the second field, sort it and print unique lines

RTYPES=`awk -F# '{print $2}' $RBOOK/recipes.txt | sort | uniq`

echo $RTYPES

Types are things like casserole, dessert, main, bbq, salad, etc. When we add a new recipe, we give it a type. We also have an index search button which can find all the recipes which contain a word like, steak or chocolate.

This is the RTYPES field script:

on mouseDown

global SRTYPES

put the selectedText of me into SRTYPE

if SRTYPE <> empty

then

go card "RLIST"

end if

end mouseDown

Which means you use the Objects ? New Card menu item to create a new card for this stack and name it RLIST. We shall have a look at this card a bit later as we first need to add a few recipes.

The Add Recipe button contains this script:

on mouseUp

go card "RNEW"

end mouseUp 

This means you have to create a new card in the current stack and name it RNEW. This is the card:

This is a highly populated card. There are 8 fields, 4 of them scrolling, and 8 buttons.

The Add Ingredient and the Add Notes buttons take you to a new card, which return you to this one. The Save and Discard buttons take you back to the RTSELECT card.

All the rest of the buttons ask you to enter information which is then displayed in the field underneath the button.

If you use the Save button, after it checks for minimal information, it writes the recipe details into the recipes.txt file, the ingredients.txt file, the instructions.txt file and the notes.txt generating an index number which it uses as the first field for each of the entries.

The Application Browser shows the names of the fields and buttons for this card. You can also see the names of the other cards we have to create for this stack. The order in the Browser is the order of the objects on this card from top left to bottom right.

Field 1 and Field 2 are the labels.

You can see which objects have scripts in the script lines column.

I shall print each script for objects that have them, in the order they are listed in the Browser.

RTYPES Field

on mouseDown

global NRTYPE

put the selectedText of me into NRTYPE

put NRTYPE into field "NEWRTYPE"

end mouseDown

NEWTYPE Button

on mouseUp

ask "Enter Type for new recipe"

put it into NEWTYPE

if NEWTYPE <> empty

then

global NRTYPE

put NEWTYPE into NRTYPE

put NRTYPE into field "NEWRTYPE"

end if

end mouseUp

NEWNAME Button

on mouseUp

ask "Enter a Name for this Recipe"

put it into NEWNAME

if NEWNAME &lt;&lt; empty

then

global NRNAME

put NEWNAME into NRNAME

put NRNAME into field "NEWRNAME"

end if

end mouseUp

ADDINGRED Button

on mouseUp

go card "RINGRED"

end mouseUp

ADDSERVE Button

on mouseUp

ask "Enter Number of Serves"

global NSERVES

put it into NSERVES

put NSERVES into field "SERVES"

end mouseUp

RTTIME Button

on mouseUp

ask "Add Total Recipe Time in Minutes"

global TRTIME

put it into TRTIME

put TRTIME into field "TTRTIME"

end mouseUp

ADDNOTE Button

on mouseUp

go card "RNOTES"

end mouseUp

RSAVE Button

on mouseUp

#These are the field values for the recipes.txt file

put field "TTRTIME" into TRTIME

put field "SERVES" into RSERVE

put field "NEWRTYPE" into NRTYPE

put field "NEWRNAME" into NRNAME

#This is the folder path for the txt files

global CBOOK

#This is the application folder

global COOK

#First check that the four values are filled in and there is something in ingredients and instructions

if TRTIME <> empty and RSERVE <> empty and NRTYPE <> empty and NRNAME <> empty

then

if field "NEWINGREDS" <> empty and field "NEWINSTRUCTS" <> empty

then

#Next we have to create an index number

put (COOK & "/bin/idxno.sh") into IDXNO

replace return with empty in IDXNO

put the shell of IDXNO into THISIDX

#Now we can write to the recipes.txt file

put (CBOOK & "/recipes.txt") into RFILE

replace return with empty in RFILE

# Create the file entry

put (THISIDX & "#" & NRTYPE & "#" & NRNAME & "#" & RSERVE & "#" & TRTIME) into RECIPE

replace return with empty in RECIPE

open file RFILE for append

write RECIPE to file RFILE

write return to file RFILE

close file RFILE

#Now we write the ingredients

put (CBOOK & "/ingredients.txt") into IFILE

replace return with empty in IFILE

#Create the file entry

put field "NEWINGREDS" into NEWING

open file IFILE for append

write THISIDX & return to file IFILE

write NEWING & return to file IFILE

write "#" & return to file IFILE

close file IFILE

#Now we write the instructions

put (CBOOK & "/instructions.txt") into SFILE

replace return with empty in SFILE

put field "NEWINSTRUCTS" into NEWINS

open file SFILE for append

write THISIDX & return to file SFILE

write NEWINS & return to file SFILE

write "#" & return to file SFILE

close file SFILE

#Now we write the notes if any

if field "RNOTES" <> empty

then

put (CBOOK & "/notes.txt") into NFILE

replace return with empty in NFILE

put field "RNOTES" into RNOT

open file NFILE for append

write THISIDX & return to file NFILE

write RNOT & return to file NFILE

write "#" & return to file NFILE

close file NFILE

end if

end if

end if

go card "RTSELECT"

end mouseUp

DISCARD Button

on mouseUp

go card "RTSELECT"

end mouseUp

idxno.sh shell script

#!/bin/bash

#idxno.sh

#Create an index number based on the lines in recipes.txt

CURRNO=`cat $HOME/cookbook/book/recipes.txt | wc | awk '{print $1}' `

let IDXNO=$CURRNO+1

echo $IDXNO 

When you've finished these scripts create the txt files with the shell command in the cookbook/book folder:

touch recipes.txt ingredients.txt instructions.txt notes.txt

The next card we look at is the Add Ingredients card:

I entered the lists for group and measurement in the Content window of the field property inspector.

You can enter any I've forgotten by typing them in.

These are the scripts for the objects on this card.

on mouseDown

put the selectedText of me into NEWINGGRP

if NEWINGGRP <> empty

then

global NINGGRP

put NEWINGGRP into NINGGRP

put NINGGRP into field "NEWINGGRP"

end if

end mouseDown

on mouseDown

put the selectedText of me into NEWINGMEAS

if NEWINGMEAS <> empty

then

global NINGMEAS

put NEWINGMEAS into NINGMEAS

put NINGMEAS into field "NEWINGMEAS"

end if

end mouseDow

on mouseUp

ask "Enter Ingredient Name"

put it into NEWINGNAME

if NEWINGNAME <> empty

then

global NINGNAME

put NEWINGNAME into NINGNAME

put NINGNAME into field "NEWINGNAME"

end if

end mouseUp

on mouseUp

ask "Enter the Quantity Number"

put it into NEWINGQUANT

if NEWINGQUANT <> empty

then

global NINGQUANT

put NEWINGQUANT into NINGQUANT

put NINGQUANT into field "NEWINGQUANT"

end if

end mouseUp

SAVE Button

on mouseUp

global NINGGRP

global NINGMEAS

global NINGNAME

global NINGQUANT


if NINGGRP <> empty and NINGMEAS <> empty and NINGNAME <> empty and NINGQUANT <> empty

then

if NINGMEAS = "NUMBER"

then

put space into NINGMEAS

end if

put ( NINGGRP & space & PNINGQUANT & space & NINGMEAS & space & NINGNAME ) into NING

replace return with empty in NING

put ( NING & return ) after field "NEWINGREDS" of card "RNEW"

end if

go card "RNEW"

end mouseUp

DISCARD Button

on mouseUp

go card "RNEW"

end mouseUp

And this is the card script to make sure the fields are empty when we go to the card.

on openCard

put empty into field "NEWINGGRP"

put empty into field "NEWINGMEAS"

put empty into field "NEWINGNAME"

put empty into field "NEWINGQUANT"

end openCard

The next card is the Notes card.


These are the object scripts:


SAVE Button

on mouseUp

put field "NRNOTES" into NEWNOT

if NEWNOT <> empty

then

put ( NEWNOT & return ) after field "RNOTES" of card "RNEW"

end if

go card "RNEW"

end mouseUp

DISCARD Button

on mouseUp

go card "RNEW"

end mouseUp

And this is the card script

on openCard

put empty into field "NRNOTES"

end openCard

Save all this and test it out by entering some of your favourite recipes.

This is what the book files should look like:

recipes.txt

1#Casserole#Chicken and Olive Casserole#6#60

ingredients.txt

1

MAIN 6 Chicken Legs

MAIN 3 Chicken Thighs #

instructions.txt

1

Lay chicken into Casserole dish

#

notes.txt

1

Large low dish to fit chicken in one layer

Piece of aluminium foil to cover dish

#

I haven't created all the on openCard scripting for the RNEW card yet as it is good to leave the information there for testing. But it should be created like the ones for the ingredients and notes cards, so that the card fields are empty for a new recipe to be entered. See if you can work this out for yourselves. I'll put my script in the next HowTo, so you can copy it if you have any trouble.

In the next HowTo in this Recipe series we shall create the rest of the cards and compile it into a Stand Alone program. I shall also include the whole recipe for my example as it is absolutely delicious and easy to make.


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell