Fruit basket program in IronPython using Layout by Code

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Mon, 10 May 2010 10:19:51 -0400

From the archive at
http://EmpowermentZone.com/ip_fruit.zip

This archive has been updated. The original version of this fruit basket program used the .NET Windows Forms classes to create a GUI. The archive has been updated to include another version, lbc_fruit.py and lbc_fruit.exe, using the Layout by Code support of Homer.NET.

In a recent message to this list, I posted code for a fruit basket program written with standard Windows Python 2.5, using the Python.NET package to connect to .NET classes, including the Layout by Code support of the Homer.NET library -- distributed as part of the Homer application framework, HomerApp, at
http://EmpowermentZone.com/appsetup.exe

or .zip for a manual install.

This IronPython version works with the same source code. IronPython (supporting the Python 2.6 language) is available at
http://IronPython.net

Thus, both a standard Python-based executable and an IronPython-based executable can produce an application with the same behavior using common syntax in Python. The standard Python version has an advantage of full access to native, third-party Python packages. The .NET version has an advantage of broader interoperability with the .NET Framework.

The source code of lbc_fruit.py is pasted below.

Jamal

[Begin lbc_fruit.py]
"""
Fruit Basket program in IronPython
Public domain by Jamal Mazrui
May 10, 2010
"""

# Import namespaces
import clr
clr.AddReference('HomerLbc')
from Homer import *

def OnEvent(oSender, oArgs):
        if oSender == dlg: sEvent = 'Closing'
        else: sEvent = 'Click'
        
        if sEvent == 'Closing':
if Lbc.DialogConfirm('Confirm', 'Exit program?', 'Y') != 'Y': oArgs.Cancel = True
        elif sEvent == 'Click':
                if oSender.Name == 'Button_Add':
                        sFruit = txtFruit.Text
                        if not sFruit: return Lbc.DialogShow('Alert', 'No fruit 
to add!')

                        lstBasket.Items.Add(sFruit)
                        iIndex = lstBasket.Items.Count - 1
                        lstBasket.SelectedIndex = iIndex
                        txtFruit.Clear()
                elif oSender.Name == 'Button_Delete':
                        iIndex = lstBasket.SelectedIndex
                        if iIndex == -1: return Lbc.DialogShow('Alert', 'No 
fruit to delete!')

                        lstBasket.Items.RemoveAt(iIndex)
                        iCount = lstBasket.Items.Count
                        if not iCount: return
                        if iIndex == iCount: iIndex -= 1
                        lstBasket.SelectedIndex = iIndex
        # OnEvent function


dlg = LbcForm('Fruit Basket')
txtFruit = dlg.AddInputBox('Fruit')
btnAdd = dlg.AddButton('Add')
btnAdd.Click += OnEvent
dlg.AcceptButton = btnAdd
dlg.AddBand()
lstBasket = dlg.AddPickBox('Basket')
btnDelete = dlg.AddButton('Delete')
btnDelete.Click += OnEvent
dlg.Closing += OnEvent
dlg.CompleteDialog()

[End of lbc_fruit.py]
__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts:

  • » Fruit basket program in IronPython using Layout by Code - Jamal Mazrui