This is a simple recipe book program written using pythoncard and Gadfly RDBMS. The files can be downloaded here.

template.py

#!/usr/bin/python
 
"""
__version__ = "$Revision: 1.5 $"
__date__ = "$Date: 2004/04/30 16:26:12 $"
"""
 
from PythonCard import model
from PythonCard.components import button, list, statictext, textarea, textfield
import gadfly
import add
import edit
 
class MyBackground(model.Background):
 
    def on_initialize(self, event):
        # if you have any initialization
        # including sizer setup, do it here
 
        rname = []
        connection = gadfly.gadfly("recipe", "db")
        cursor = connection.cursor()
        cursor.execute("select * from recname order by rname")
        for item in cursor.fetchall():
            rname.append(item[0])
            connection.commit()
            #result = self.components.TextArea1.appendText(item[0]+"\n")
        self.components.TextArea1.items = rname
 
    def on_TextArea1_select(self, event):
        path = self.components.TextArea1.stringSelection
        gingredients = ''
        gdirections = ''
 
        rname = []
        connection = gadfly.gadfly("recipe", "db")
        cursor = connection.cursor()
        cursor.execute("select * from ingre where rname='"+path+"'")
        for item in cursor.fetchall():
            ind = 'Ingredients\n-----------------------------------------------------\n' + item[0]
            gingredients = item[0]
        #    rname.append(item[0])
        #    connection.commit()
        #def ind():
        #    ingred = 'Ingredients\n-----------------------------------------------------\n'
        #    for item in rname:
        #        ingred = ingred + item + '\n'
        #    return ingred
        #description = ind()
 
 
        cursor.execute("select * from direct where rname='"+path+"'")
        for item in cursor.fetchall():
            dirc = '\n\nDirections\n-----------------------------------------------------\n' + item[1]
        #    rname.append(item[1])
        #    connection.commit()
        #def dirc():
        #    direct = '\nDirections\n-----------------------------------------------------\n'
        #    for item in rname:
        #        direct = direct + item + '\n'
        #    return direct
        #description = ind() + dirc()
 
        self.components.TextArea2.text = ind + dirc
 
    def on_addBtn_mouseClick(self, event):
        self.addWindow = model.childWindow(self, add.MyBackground)
 
    def on_deleteBtn_mouseClick(self, event):
        path = self.components.TextArea1.stringSelection
        path = str(path)
        connection = gadfly.gadfly("recipe", "db")
        cursor = connection.cursor()
        cursor.execute("Delete from recname where rname='"+path+"'")
        cursor.execute("Delete from ingre where rname='"+path+"'")
        cursor.execute("Delete from direct where rname='"+path+"'")
        connection.commit()
 
        rname = []
        connection = gadfly.gadfly("recipe", "db")
        cursor = connection.cursor()
        cursor.execute("select * from recname order by rname")
        for item in cursor.fetchall():
            rname.append(item[0])
            connection.commit()
        self.components.TextArea1.items = rname
 
    def on_editBtn_mouseClick(self, event):
        self.path = self.components.TextArea1.stringSelection
        self.editWindow = model.childWindow(self, edit.MyBackgroundA)
        self.editWindow.path = self.path
 
    def on_exitBtn_mouseClick(self, event):
        self.exit()
 
if __name__ == '__main__':
    app = model.Application(MyBackground)
    app.MainLoop()
 

template.py

{'application':{'type':'Application',
          'name':'Template',
    'backgrounds': [
    {'type':'Background',
          'name':'bgTemplate',
          'title':'Standard Template with File->Exit menu',
          'size':(626, 547),
          'style':['resizeable'],
 
        'menubar': {'type':'MenuBar',
         'menus': [
             {'type':'Menu',
             'name':'menuFile',
             'label':'&File',
             'items': [
                  {'type':'MenuItem',
                   'name':'menuFileExit',
                   'label':'E&xit',
                   'command':'exit',
                  },
              ]
             },
         ]
     },
         'components': [
 
{'type':'StaticText', 
    'name':'recipeText1', 
    'position':(11, 11), 
    'font':{'style': 'bold', 'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 12}, 
    'text':u'Recipes', 
    },
 
{'type':'List', 
    'name':'TextArea1', 
    'position':(13, 34), 
    'size':(240, 401), 
    'items':[], 
    },
 
{'type':'TextArea', 
    'name':'TextArea2', 
    'position':(263, 35), 
    'size':(344, 400), 
    },
 
{'type':'Button', 
    'name':'addBtn', 
    'position':(12, 450), 
    'label':u'Add', 
    },
 
{'type':'Button', 
    'name':'editBtn', 
    'position':(96, 450), 
    'label':u'Edit', 
    },
 
{'type':'Button', 
    'name':'deleteBtn', 
    'position':(181, 450), 
    'label':u'Delete', 
    },
 
{'type':'Button', 
    'name':'exitBtn', 
    'position':(265, 450), 
    'label':u'Exit', 
    },
 
] # end components
} # end background
] # end backgrounds
} }
 

add.py

#!/usr/bin/python
 
"""
__version__ = "$Revision: 1.5 $"
__date__ = "$Date: 2004/04/30 16:26:12 $"
"""
 
from PythonCard import model
import gadfly
 
class MyBackground(model.Background):
 
    def on_initialize(self, event):
        # if you have any initialization
        # including sizer setup, do it here
        pass
 
    def on_Button1_mouseClick(self, event):
        name = self.components.TextField1.text
        ingredients = self.components.TextArea1.text
        directions = self.components.TextArea2.text
 
        connection = gadfly.gadfly("recipe", "db")
 
        name = str(name)
        ingredients = str(ingredients)
        ingredients = ingredients.replace("'","`")
 
        directions = str(directions)
        directions = directions.replace("'","`")
        if (name != '' or ingredients != '' or directions !=''):
            cursor = connection.cursor()
            cursor.execute("insert into recname(rname) values('"+name+"')")
            cursor.execute("insert into ingre(rname, ingredience) values('"+name+"','"+ingredients+"')")
            cursor.execute("insert into direct(rname, direction) values('"+name+"','"+directions+"')")
            connection.commit()
 
    def on_Button2_mouseClick(self, event):
        self.parent = self.getParent()
        rname = []
        connection = gadfly.gadfly("recipe", "db")
        cursor = connection.cursor()
        cursor.execute("select * from recname order by rname")
        for item in cursor.fetchall():
            rname.append(item[0])
            connection.commit()
        self.parent.components.TextArea1.items = rname
        self.close()
 
if __name__ == '__main__':
    app = model.Application(MyBackground)
    app.MainLoop()
 

add.rsrc.py

{'application':{'type':'Application',
          'name':'Template',
    'backgrounds': [
    {'type':'Background',
          'name':'bgTemplate',
          'title':'Standard Template with File->Exit menu',
          'size':(525, 514),
          'style':['resizeable'],
 
        'menubar': {'type':'MenuBar',
         'menus': [
             {'type':'Menu',
             'name':'menuFile',
             'label':'&File',
             'items': [
                  {'type':'MenuItem',
                   'name':'menuFileExit',
                   'label':'E&xit',
                   'command':'exit',
                  },
              ]
             },
         ]
     },
         'components': [
 
{'type':'TextField', 
    'name':'TextField1', 
    'position':(114, 11), 
    'size':(230, -1), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 8}, 
    },
 
{'type':'TextArea', 
    'name':'TextArea1', 
    'position':(114, 48), 
    'size':(389, 178), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 8}, 
    },
 
{'type':'TextArea', 
    'name':'TextArea2', 
    'position':(115, 242), 
    'size':(386, 178), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 8}, 
    },
 
{'type':'Button', 
    'name':'Button1', 
    'position':(22, 435), 
    'label':u'Save', 
    },
 
{'type':'Button', 
    'name':'Button2', 
    'position':(106, 435), 
    'label':u'Exit', 
    },
 
{'type':'StaticText', 
    'name':'StaticText3', 
    'position':(13, 239), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 12}, 
    'text':u'Directions:', 
    },
 
{'type':'StaticText', 
    'name':'StaticText2', 
    'position':(9, 50), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 12}, 
    'text':u'Ingredients:', 
    },
 
{'type':'StaticText', 
    'name':'StaticText1', 
    'position':(11, 11), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 12}, 
    'text':u'Recipe Name:', 
    },
 
] # end components
} # end background
] # end backgrounds
} }
 

edit.py

#!/usr/bin/python
 
"""
__version__ = "$Revision: 1.5 $"
__date__ = "$Date: 2004/04/30 16:26:12 $"
"""
 
from PythonCard import model
import gadfly
 
class MyBackgroundA(model.Background):
 
    def on_initialize(self, event):
        #Assign recipe name from main window
        oname = self.path
        if (oname == ''):
            self.close()
        else:
            # Fill in values in the child window
            self.components.TextField1.text = oname
            rname = []
            connection = gadfly.gadfly("recipe", "db")
            cursor = connection.cursor()
            cursor.execute("select * from ingre where rname='"+oname+"'")
            for item in cursor.fetchall():
                self.components.TextArea1.text = item[0]
 
            cursor.execute("select * from direct where rname='"+oname+"'")
            for item in cursor.fetchall():
                self.components.TextArea2.text = item[1]
 
 
    def on_Button1_mouseClick(self, event):
        oname = self.path
 
        # Update the database
        name = self.components.TextField1.text
        ingredients = self.components.TextArea1.text
        directions = self.components.TextArea2.text
 
        connection = gadfly.gadfly("recipe", "db")
        oname = str(oname)
        name = str(name)
        ingredients = str(ingredients)
        ingredients = ingredients.replace("'","`")
        directions = str(directions)
        directions = directions.replace("'","`")
 
        if (name != '' or ingredients != '' or directions !=''):
            cursor = connection.cursor()
            cursor.execute("update recname set rname='"+name+"' where rname='"+oname+"'")
            cursor.execute("update ingre set rname='"+name+"' where rname='"+oname+"'")
            cursor.execute("update direct set rname='"+name+"' where rname='"+oname+"'")
            cursor.execute("update ingre set ingredience='"+ingredients+"' where rname='"+name+"'")
            cursor.execute("update direct set direction='"+directions+"' where rname='"+name+"'")
            connection.commit()
 
    def on_Button2_mouseClick(self, event):
        self.parent = self.getParent()
        rname = []
        connection = gadfly.gadfly("recipe", "db")
        cursor = connection.cursor()
        cursor.execute("select * from recname order by rname")
        for item in cursor.fetchall():
            rname.append(item[0])
            connection.commit()
        self.parent.components.TextArea1.items = rname
        self.close()
 
if __name__ == '__main__':
    app = model.Application(MyBackgroundA)
    app.MainLoop()
 

edit.rsrc.py

{'application':{'type':'Application',
          'name':'Template',
    'backgrounds': [
    {'type':'Background',
          'name':'bgTemplate',
          'title':'Standard Template with File->Exit menu',
          'size':(525, 514),
          'style':['resizeable'],
 
        'menubar': {'type':'MenuBar',
         'menus': [
             {'type':'Menu',
             'name':'menuFile',
             'label':'&File',
             'items': [
                  {'type':'MenuItem',
                   'name':'menuFileExit',
                   'label':'E&xit',
                   'command':'exit',
                  },
              ]
             },
         ]
     },
         'components': [
 
{'type':'TextField', 
    'name':'TextField1', 
    'position':(114, 11), 
    'size':(230, -1), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 8}, 
    },
 
{'type':'TextArea', 
    'name':'TextArea1', 
    'position':(114, 48), 
    'size':(389, 178), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 8}, 
    },
 
{'type':'TextArea', 
    'name':'TextArea2', 
    'position':(115, 242), 
    'size':(386, 178), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 8}, 
    },
 
{'type':'Button', 
    'name':'Button1', 
    'position':(22, 435), 
    'label':u'Save', 
    },
 
{'type':'Button', 
    'name':'Button2', 
    'position':(106, 435), 
    'label':u'Exit', 
    },
 
{'type':'StaticText', 
    'name':'StaticText3', 
    'position':(13, 239), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 12}, 
    'text':u'Directions:', 
    },
 
{'type':'StaticText', 
    'name':'StaticText2', 
    'position':(9, 50), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 12}, 
    'text':u'Ingredients:', 
    },
 
{'type':'StaticText', 
    'name':'StaticText1', 
    'position':(11, 11), 
    'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 12}, 
    'text':u'Recipe Name:', 
    },
 
] # end components
} # end background
] # end backgrounds
} }