dabo Commit
Revision 1599
Date: 2005-11-29 14:17:59 -0800 (Tue, 29 Nov 2005)
Author: paul

Changed:
U   trunk/dabo/ui/uiwx/dControlItemMixin.py
U   trunk/dabo/ui/uiwx/dControlMixin.py
U   trunk/dabo/ui/uiwx/dListBox.py

Log:
Working through the obvious problems illuminated by running test.py, I needed
to fix a premature setting of the Value property of dListBox. But then playing
with dListBox I determined that some code written there wasn't running as 
intended. Here's what I did:

+ Removed the binding to the enter key, as it wasn't working anyway.
+ Removed the ListSelection/ListDeselection events, as it wasn't properly
  distinguishing between the two, and in my testing I found that EVT_LISTBOX
  only fires when an item is selected, except for the first item.
+ Mapped EVT_LISTBOX to dEvents.Hit, to match what we've done elsewhere.
+ Removed the binding to EVT_LISTBOX_DCLICK because users can just bind to
  the normal dEvents.MouseLeftDoubleClick Dabo event.
+ Modified the test to accomodate the changes.

Worked around a problem where setting the Value property of a listbox in 
initProperties() would result in the value not getting set because the 
Choices haven't been filled in yet. This is due to Python's non-guaranteed
order of dictionary keys. I simply use a callAfter in this case which
resolves the issue.




Diff:
Modified: trunk/dabo/ui/uiwx/dControlItemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dControlItemMixin.py     2005-11-29 21:07:38 UTC (rev 
1598)
+++ trunk/dabo/ui/uiwx/dControlItemMixin.py     2005-11-29 22:17:59 UTC (rev 
1599)
@@ -56,10 +56,10 @@
                if self.Count > index:
                        self.SetSelection(index)
                else:
-                       ## pkm: I think on Windows the order of property setting
-                       ## matters, and the selected row is getting set before
-                       ## the items have been set. Make a log and ignore for 
now.
-                       dabo.errorLog.write("dControlItemMixin::setSelection(): 
index > count")
+                       ## pkm: The user probably set the Value property from 
inside initProperties(),
+                       ##      and it is getting set before the Choice 
property has been applied.
+                       ##      If this is the case, callAfter is the ticket.
+                       dabo.ui.callAfter(self.SetSelection, index)
 
 
        def _isMultiSelect(self):

Modified: trunk/dabo/ui/uiwx/dControlMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dControlMixin.py 2005-11-29 21:07:38 UTC (rev 1598)
+++ trunk/dabo/ui/uiwx/dControlMixin.py 2005-11-29 22:17:59 UTC (rev 1599)
@@ -4,13 +4,13 @@
 import dabo.dEvents as dEvents
 
 class dControlMixin(dControlMixinBase):
-       def _onWxHit(self, evt):
+       def _onWxHit(self, evt, *args, **kwargs):
                # This is called by a good number of the controls, when the 
default
                # event happens, such as a click in a command button, text 
being 
                # entered in a text control, a timer reaching its interval, etc.
                # We catch the wx event, and raise the dabo Hit event for user 
code
                # to work with.
-               self.raiseEvent(dEvents.Hit, evt)
+               self.raiseEvent(dEvents.Hit, evt, *args, **kwargs)
                
        def getCaptureBitmap(self):
                """Returns a bitmap snapshot of self, as it appears in the UI 
at this moment.

Modified: trunk/dabo/ui/uiwx/dListBox.py
===================================================================
--- trunk/dabo/ui/uiwx/dListBox.py      2005-11-29 21:07:38 UTC (rev 1598)
+++ trunk/dabo/ui/uiwx/dListBox.py      2005-11-29 22:17:59 UTC (rev 1599)
@@ -20,28 +20,14 @@
                        
        def _initEvents(self):
                super(dListBox, self)._initEvents()
-               self.Bind(wx.EVT_LISTBOX_DCLICK, self._onWxHit)
-               self.Bind(wx.EVT_LISTBOX, self.__onSelection)
-               self.bindKey("Enter", self._onEnter)
+               self.Bind(wx.EVT_LISTBOX, self._onWxHit)
        
        
        def clearSelections(self):
                for elem in self.GetSelections():
                        self.SetSelection(elem, False)
 
-       
-       def _onEnter(self, evt):
-               self.raiseEvent(dEvents.Hit, evt)
                
-               
-       def __onSelection(self, evt):
-               """Fired when an item is selected."""
-               if evt.IsSelection():
-                       self.raiseEvent(dEvents.ListSelection, evt)
-               else:
-                       self.raiseEvent(dEvents.ListDeselection, evt)
-               
-       
        def _getMultipleSelect(self):
                return self._hasWindowStyleFlag(wx.LB_EXTENDED)
        def _setMultipleSelect(self, val):
@@ -58,9 +44,6 @@
 
 class _dListBox_test(dListBox):
        def initProperties(self):
-               self.setup()
-
-       def setup(self):
                # Simulate a database:
                actors = ({"lname": "Jason Leigh", "fname": "Jennifer", "iid": 
42},
                        {"lname": "Cates", "fname": "Phoebe", "iid": 23},
@@ -68,32 +51,30 @@
                        
                choices = []
                keys = {}
+
                for actor in actors:
                        choices.append("%s %s" % (actor['fname'], 
actor['lname']))
                        keys[actor["iid"]] = len(choices) - 1
+
                self.MultipleSelect = True
                self.Choices = choices
                self.Keys = keys
                self.ValueMode = 'Key'
                self.Value = 23
-                                               
+
        def onHit(self, evt):
                print "HIT:"
                print "\tKeyValue: ", self.KeyValue
                print "\tPositionValue: ", self.PositionValue
                print "\tStringValue: ", self.StringValue
                print "\tValue: ", self.Value
+               print "\tCount: ", self.Count
        
-       def onListSelection(self, evt):
-               print "SELECTION:"
-               print "\tKeyValue: ", self.KeyValue
-               print "\tPositionValue: ", self.PositionValue
-               print "\tStringValue: ", self.StringValue
-               print "\tValue: ", self.Value
+       def onMouseLeftDoubleClick(self, evt):
+               print "double click at position %s" % self.PositionValue
 
-       def onListDeselection(self, evt):
-               print "Deselected: Item #", evt.EventData["index"]
-       
+       def onMouseLeftDown(self, evt):
+               print "mousedown"       
 
 if __name__ == "__main__":
        import test




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to