Re: Improved Layout by Code module for Python

  • From: Alex Hall <mehgcap@xxxxxxxxx>
  • To: Jamal Mazrui <empower@xxxxxxxxx>
  • Date: Fri, 17 Jun 2011 07:33:19 -0400

It was; I was using IsClickEvent(). Again, though, the fruit basket
python file failed to run with the new lbc. It opened, but the buttons
were inoperative, and I had not changed anything in that file. I am
not sure why this is so, but as soon as I changed the trigger to 10010
in lbc.py, things worked as expected. See if the fruit basket python
file (not the executable) runs on your computer from the zip file you
posted; it may be something to do with 64-bit vs 32-bit, or some other
oddity.

On 6/17/11, Jamal Mazrui <empower@xxxxxxxxx> wrote:
> The new Layout by Code automatically passes more events to the default
> event handler, which processes them before the custom event handler that
> you define.  The focus event is one of those passed, so yu have to make
> sure your code is reacting specifically to the click event, not just to
> an event on the control of interest.
>
> If a problem remains, please post or send me a sample script, and I will
> try to resolve this.
>
> Jamal
>
> On 6/17/2011 6:36 AM, Alex Hall wrote:
>> Okay, more pressing problem! I tried to use your "IsClickEvent" method
>> since the alert dialog I have set to trigger on a button was happening
>> when I tabbed to the button, not when I activated it. However, the
>> dialog will not appear. Your method returns true if the
>> EventType==10008. However, when I printed out the EventType in my
>> event handler, I saw that I got 10010 when I pressed space or enter on
>> the button. I am tempted to just change the condition for returning in
>> your function, but I am not sure if that will cause problems later on.
>> Your fruit basket executable works as expected, so I am not sure how
>> that works and this does not. Interestingly, the fruit basket python
>> file does not work, I suspect due to the same problem I am having. It
>> confirms exiting with the y/n dialog, but clicking any button does
>> nothing.
>>
>> On 6/17/11, Alex Hall<mehgcap@xxxxxxxxx>  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
>>>> //www.freelists.org/list/programmingblind
>>>>
>>>>
>>>
>>>
>>> --
>>> Have a great day,
>>> Alex (msg sent from GMail website)
>>> mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap
>>>
>>
>>
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: