Re: Fruit basket program with Python.NET

  • From: Chris Hofstader <cdh@xxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 11 Apr 2009 10:34:22 -0400

Oops... I thought I was sending my previous and somewhat cryptic message to Jamal alone.

On Apr 11, 2009, at 12:55 AM, Jamal Mazrui wrote:

From the archive
http://EmpowermentZone.com/pynet_fruit.zip

This fruit basket program is written in Python 2.5, available at
http://python.org

with the Python.NET package, available at
http://pythonnet.sourceforge.net

and an executable builder available at
http://py2exe.org

Python.NET gives traditional Python for Windows programs access to much of
the .NET Framework class library, including the System.Windows.Forms
namespace. It is different from IronPython, which is a .NET language with
Python syntax.

Source code for this program is in the file pynet_fruit.py, and also
pasted below. It is used to build the Windows executable pynet_fruit.exe,
using the batch file RunSetup.bat and script setup.py.  The executable
requires three additional files to run: clr.pyd, Python.Runtime.dll, and
python25.dll.

Also included in this archive are files from a conference presentation
about Python.NET.

Jamal

"""
Fruit Basket program in Python.NET
Public domain by Jamal Mazrui
April 11, 2009
"""

# Import namespaces
import clr
from System.Windows.Forms import *

# Define Add event handler
def HandleAdd(sender, event):
        sFruit = txtFruit.Text
        if len(sFruit) == 0: return MessageBox.Show('No fruit to add!',
'Alert')
        lstBasket.Items.Add(sFruit)
        txtFruit.Clear()
        lstBasket.SelectedIndex = lstBasket.Items.Count - 1

# Define Delete event handler
def HandleDelete(sender, event):
        iFruit = lstBasket.SelectedIndex
        if iFruit == -1: return MessageBox.Show('No fruit to delete.',
'Alert')
        lstBasket.Items.RemoveAt(iFruit)
        if iFruit == lstBasket.Items.Count: iFruit -= 1
        if iFruit >= 0: lstBasket.SelectedIndex = iFruit

# Create controls
lblFruit = Label()
lblFruit.Text='&Fruit:'

txtFruit = TextBox()

btnAdd = Button()
btnAdd.Text='&Add'
btnAdd.Click += HandleAdd

lblBasket = Label()
lblBasket.Text='&Basket:'

lstBasket = ListBox()

btnDelete = Button()
btnDelete.Text='&Delete'
btnDelete.Click += HandleDelete

tlp = TableLayoutPanel()
tlp.ColumnCount=3
tlp.RowCount=2
tlp.Controls.AddRange((lblFruit, txtFruit, btnAdd, lblBasket, lstBasket,
btnDelete))

# Finalize dialog
dlg = Form()
dlg.Text='Fruit Basket'
dlg.AcceptButton=btnAdd
dlg.StartPosition=FormStartPosition.CenterScreen
dlg.AutoSize=True
dlg.AutoSizeMode=AutoSizeMode.GrowAndShrink
dlg.Controls.Add(tlp)
dlg.ShowDialog()

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: