Yes, I should have mentioned that. The section name in the ini file corresponds to the title of the dialog.
BTW, here is a revised version of your test script using the new lbc.py import wx, lbc def evt_handler(d, e, n):# This code block prints the type of event and the name of the widget reacting to it
if lbc.IsInitEvent(e): print 'Init' elif lbc.IsFocusEvent(e): print 'Focus' elif lbc.IsClickEvent(e): print 'Click' elif lbc.IsCloseEvent(e): print 'Close' else: print 'Other event' print n if lbc.IsCloseEvent(e): return d.Destroy()elif lbc.IsClickEvent(e): lbc.DialogShow(title="popup", message=n + " was clicked")
app=lbc.App() dlg=lbc.Dialog(title="test") b=dlg.AddButton(label="test") dlg.Complete(buttons=['OK', 'Cancel'], handler=evt_handler) Jamal On 6/17/2011 6:18 AM, Alex Hall wrote:
Thanks for the update, I am going to try it to see if I can get things working better. My only question for now is about the ini file. In the sample, you have a [Fruit Basket] section. How did you decide on that section name? Does it have to match the title of the dialog with which it is associated? On 6/16/11, Jamal Mazrui<empower@xxxxxxxxx> wrote:From the archive at http://EmpowermentZone.com/pyLbc.zip Layout by Code for Python Version 1.3 June 16, 2011 Copyright 2009 - 2011 by Jamal Mazrui GNU Lesser General Public License (LGPL) I have updated a Python module called Layout by Code (lbc), which simplifies design of dialogs with the WxWidgets GUI library. It is another implementation of the Layout by Code approach that I originally developed for the AutoIt language, available at http://EmpowermentZone.com/lbc.zip I also developed a version for .NET languages, such as C# and Visual Basic, which is distributed as part of HomerApp, the Homer Application Framework, available at http://EmpowermentZone.com/appsetup.exe Although the Python version is not as flexible, it is still intended to support most dialogs one might need (based on years of experience with various applications and languages). It should work with Python versions 2.4 through 2.7. It depends on the following 3rd-party Python modules: wxPython http://wxpython.org py2exe http://py2exe.org Python for Windows extensions http://sourceforge.net/projects/pywin32/ odict -- an ordered dictionary http://www.voidspace.org.uk/python/odict.html The py2exe module is only needed if one wants to create a Windows executable like lbc_fruit.exe. The batch file run_setup_lbc_fruit.bat does this, using setup_lbc_fruit.py to specify how the executable is built. After instantiating an lbc dialog object, any of the following controls may be added with a line of code: Button, CheckBox, ListBox, RadioButton, RichEdit, StaticText, or TextCtrl. The control is added to a horizontal band of controls, with layout automatically managed by wxSizer containers. Adding a new band is analagous to pressing carriage return at the end of a line. The lbc Complete method adds a band of buttons at the bottom of the dialog before invoking it. The method returns the ID of the button that ended the dialog. At that point, the dialog object has an ordered dictionary attribute called Controls, containing the names of controls that were added to the dialog before it was invoked. A control name is its class and label, if any, seperated by an underscore, e.g., Button_OK. The dialog also has a dictionary attribute called Results, containing the control names and values when the dialog ended. By default, a status bar is added as the last control of a dialog. It may be used for help messages to the user. For example, each control can trigger a help message when it receives focus. These messages may be defined in a .ini file that accompanies the main script file (with the same name except for the extension). The fruit basket sample script illustrates this feature in the file lbc_fruit.ini. A screen reader user can press a hotkey to read the status bar. Over ten convenience dialogs have been defined using lbc, illustrated with the program test_lbc.py. Also, a fruit basket program is in lbc_fruit.py. Below is a summary of lbc functions. For convenient reference, the code in test_lbc.py and then lbc_fruit.py follows afterward. Jamal ---------- lbc convenience dialogs DialogBrowseForFolder(title='', value='') -- Select a folder DialogChoose(title='Choose', message = '', names=) -- Choose a button DialogConfirm(title='Confirm', message='', value='Y') -- Choose from a Yes/No/Cancel message box DialogInput(title='Input', label='', value='', ) -- Input with a single-line edit box DialogMemo(title='Memo', label='', value='', readonly=False) -- Input or read text with a multiple-line edit box DialogMultiInput(title='MultiInput', labels=, values=, options=) -- Input with multiple edit boxes DialogMultiPick(title='Multi Pick', message='', names=, values=, sort=False, index=0) -- Pick from a multiple-selection listbox DialogOpenFile(title='Open', value='', wildcard='All files (*.*)|*.*') -- Specify a file to open DialogPick(title='Pick', message='', names=, values=, sort=False, index=0) -- Pick from a single-selection listbox DialogSaveFile(title='Save', value='', wildcard='All files (*.*)|*.*') -- Specify a file to save DialogShow(title='Show', message='') -- Show a message ---------- Content of test_lbc.py import lbc labels = 'Label1 Label2 Label3'.split() names = 'Name1 Name2 Name3'.split() values = 'Value1 Value2 Value3'.split() result = lbc.DialogChoose(title='Choose a Button', message='My message', names=['Button1', 'Button2', 'Button3']) lbc.DialogShow(title='result', message=result) result = lbc.DialogConfirm(title='Confirm an Action', message='my question', value='Y') lbc.DialogShow(title='result', message=result) result=lbc.DialogInput(title='Input a Value', label='My Label', value='My Value') lbc.DialogShow(title='result', message=result) result = lbc.DialogMemo(title='Input Multiple Lines', label='', value='line1\nline2\nline3') lbc.DialogShow(title='result', message=result) result = lbc.DialogMultiInput(title='Input Multiple Values', labels=labels, values=values) lbc.DialogShow(title='result', message=result) result = lbc.DialogPick(title='Pick an Item', names=names, values=values, sort=True) lbc.DialogShow(title='result', message=result) result=lbc.DialogMultiPick(title='Pick Multiple Items', names=names, values=values) lbc.DialogShow(title='result', message=result) result = lbc.DialogOpenFile(value=r'c:\temp\test.txt') lbc.DialogShow(title='result', message=result) result = lbc.DialogSaveFile(value=r'c:\temp\test.txt') lbc.DialogShow(title='result', message=result) result = lbc.DialogBrowseForFolder(value=r'c:\temp') lbc.DialogShow(title='result', message=result) ---------- Content of lbc_fruit.py import wx, lbc # Custom event handler def OnEvent(dlg, event, name): if lbc.IsCloseEvent(event): if lbc.DialogConfirm(title='Confirm', message='Exit program?', value='Y') == 'Y': return event.Skip() else: return event.Veto() txt = dlg.Controls['TextCtrl_Fruit'] lst = dlg.Controls['ListBox_Basket'] if not lbc.IsClickEvent(event): pass elif name == 'Button_Add': fruit = txt.GetValue() if len(fruit) == 0: return lbc.DialogShow(title='Alert', message='No fruit to add!') lst.Append(fruit) index = lst.GetCount() - 1 lst.SetSelection(index) txt.Clear() elif name == 'Button_Delete': index = lst.GetSelection() if index == -1: return lbc.DialogShow(title='Alert', message='No fruit to delete!') lst.Delete(index) if index == lst.GetCount(): index -= 1 if index>= 0: lst.SetSelection(index) # Main program app = lbc.App() dlg = lbc.Dialog(title='Fruit Basket') dlg.AddTextCtrl(label='Fruit') dlg.AddListBox(label='Basket') dlg.Complete(buttons=['Add', 'Delete'], handler=OnEvent) app.Exit() __________ View the list's information and change your settings at http://www.freelists.org/list/programmingblind
__________View the list's information and change your settings at http://www.freelists.org/list/programmingblind