From: Alex T. <al...@tw...> - 2005-06-23 13:27:13
|
Bryan Murdock wrote: >There's a nice program called gtkpod for linux that displays your mp3s >and their relavant info like artist, album, genre, etc. in a >multicolumn list looking widget. It allows you to double click on any >of the fields and edit the string right there in place. Is it >possible to do something like this with the PythonCard >multiColumnList? > > No and Yes. No - because the Pythoncard multiColumnList (as distributed) can't do it, but .... Yes - it's fairly easy to modify it to allow it - see instructions below. I got this far by looking at the wxPython demo which has a sample of a ListCtrl_edit (under CoreWindows/Controls). This showed me how to add in the text editing - but doesn't show how to get any events resulting from the edit; I'm not sure if there is an easy way to be notified when an edit has taken place. However, you can add handlers for gainFocus and loseFocus which will be called at the start and/or end of each edit - whether or not a change happened - so you can then retrieve the row and compare it against previous contents (assuming that you do need to take some action :-) Here's what I did. 1. Set up a custom version of the multiColumnList component You need to make your own modified multiColumnList component. I don't remember where the doc describing how to make a customized version of any component is - so here's a brief version of it ..... Go to the directory where your app lives, and create a directory called appcomponents. Copy into it the component file you want to change (pythoncard/components/multiColumnList.py) into it, and create a file within appcomponents called _init_.py (this is needed to let Pythoncard know to use these components - it needn't contain anything useful) This component will now be used in preference to the pythoncard one, only for applications in the directory it is within - so it won't affect any other projects you're doing. 2. Customize it. Go into the multiColumnList.py, and change it like this .... > *** /cygdrive/c/python/PythonCard/components/multicolumnlist.py Sun > Nov 7 17:13:13 2004 > --- ./multicolumnlist.py Thu Jun 23 11:55:14 2005 > *************** > *** 5,11 **** > """ > > import wx > ! from wx.lib.mixins.listctrl import ColumnSorterMixin, > ListCtrlAutoWidthMixin > from types import TupleType, ListType, StringTypes, NoneType, IntType > from PythonCard import event, widget > > --- 5,11 ---- > """ > > import wx > ! from wx.lib.mixins.listctrl import ColumnSorterMixin, > ListCtrlAutoWidthMixin, TextEditMixin > from types import TupleType, ListType, StringTypes, NoneType, IntType > from PythonCard import event, widget > > *************** > *** 80,86 **** > widget.WidgetSpec.__init__( self, 'MultiColumnList', > 'Widget', events, attributes ) > > > ! class MultiColumnList(widget.Widget, wx.ListCtrl, ColumnSorterMixin, > ListCtrlAutoWidthMixin): > """ > A multi-column list. > """ > --- 80,86 ---- > widget.WidgetSpec.__init__( self, 'MultiColumnList', > 'Widget', events, attributes ) > > > ! class MultiColumnList(widget.Widget, wx.ListCtrl, ColumnSorterMixin, > ListCtrlAutoWidthMixin, TextEditMixin): > """ > A multi-column list. > """ > *************** > *** 88,93 **** > --- 88,94 ---- > _spec = MultiColumnListSpec() > > def __init__( self, aParent, aResource ) : > + print "here" > if aResource.rules: > rules = wx.LC_HRULES | wx.LC_VRULES > else: > *************** > *** 115,120 **** > --- 116,122 ---- > # Now that the list exists we can init the other base class, > # see wxPython/lib/mixins/listctrl.py > ColumnSorterMixin.__init__(self, self._maxColumns) > + TextEditMixin.__init__(self) > > # Perform init for AutoWidth (resizes the last column to take up > # the remaining display width) If you're not used to diff output - all I did was add "TextEditMixin" to the import line, add it to the class dependency line, and initialize it immediately after ColumnSorterMixin was init'ed. I also added a diagnostic "print 'here'" just to check whether or not this customized version was being used :-) 3. Make a copy of the multicolumnlist sample copy Pythoncard/samples/multicolumnexample/multicolumnexample.py (and .rsrc.py) into your working directory (i.e. the one above appcomponents) 4. Change it It currently has a handler on_theList_select - at the end of it, I added the following > if not isinstance(row, StringTypes): > row = ' '.join(row) > base.displayArea.text = row > event.skip() > > def on_theList_gainFocus(self, event): > print "gainfocus" > event.skip() > > def on_theList_loseFocus(self, event): > print "losefocus" #, dir(event) > print event.target.curRow, event.this > event.skip() > And now the multicolumn example has editable items - and the event.target.curRow in loseFocus tells you which line has (perhaps) just been edited.... Good luck - let us know if you need more. -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.323 / Virus Database: 267.7.11/26 - Release Date: 22/06/2005 |