dabo Commit
Revision 1203
Date: 2005-08-27 19:41:10 -0700 (Sat, 27 Aug 2005)
Author: ed

Changed:
U   trunk/dabo/ui/uiwx/__init__.py
U   trunk/dabo/ui/uiwx/dGridSizer.py
U   trunk/dabo/ui/uiwx/dSizerMixin.py

Log:
Corrected some copy/paste bugs in __init__.py. Seems that I left the 'self' 
parameters in some methods after I moved them out of the dImage class.

dSizerMixin: Added the following methods:
- appendItems: you can pass a sequence of items to be added, along with any 
other append parameters, and each item in the sequence will be added with those 
settings.
- showItem: wrapper around the wx method Show()
- hideItem: wrapper around the wx method Hide()


dGridSizer:
- added moveObject() method. Refactored the moveCell() method to use 
moveObject().
- added getItemByRowCol() method. Given a row and column, returns the control 
in that position in the sizer, or None if there is no such item.
- added getItemAtOffset() method. Given and object and a (row,col) tuple 
offset, returns the control in the sizer that far offset from the original 
object.
- added getNeighbor() method. Accepts an object and a direction, and returns 
the object in the neighboring cell in the given direction.



Diff:
Modified: trunk/dabo/ui/uiwx/__init__.py
===================================================================
--- trunk/dabo/ui/uiwx/__init__.py      2005-08-27 17:56:50 UTC (rev 1202)
+++ trunk/dabo/ui/uiwx/__init__.py      2005-08-28 02:41:10 UTC (rev 1203)
@@ -540,13 +540,13 @@
        return ret
        
        
-def pathToBmp(self, pth):
+def pathToBmp(pth):
        img = wx.NullImage
        img.LoadFile(pth)
        return img.ConvertToBitmap()
 
 
-def resizeBmp(self, bmp, wd, ht):
+def resizeBmp(bmp, wd, ht):
        img = bmp.ConvertToImage()
        img.Rescale(wd, ht)
        return img.ConvertToBitmap()

Modified: trunk/dabo/ui/uiwx/dGridSizer.py
===================================================================
--- trunk/dabo/ui/uiwx/dGridSizer.py    2005-08-27 17:56:50 UTC (rev 1202)
+++ trunk/dabo/ui/uiwx/dGridSizer.py    2005-08-28 02:41:10 UTC (rev 1203)
@@ -209,12 +209,17 @@
                sz = self.FindItemAtPosition( (fromRow, fromCol) )
                if sz:
                        if sz.IsWindow():
-                               item = sz.GetWindow()
-                               self.SetItemPosition(item, (toRow, toCol) )
-                               if not delay:
-                                       self.layout()
+                               obj = sz.GetWindow()
+                               self.moveObject(obj, toRow, toCol, delay=delay)
 
                        
+       def moveObject(self, obj, targetRow, targetCol, delay=False):
+               """Moves the object to the given row/col if possible."""
+               self.SetItemPosition(obj, (targetRow, targetCol) )
+               if not delay:
+                       self.layout()
+               
+               
        def determineAvailableCell(self, row, col):
                (targetRow, targetCol) = (row, col)
                if (row == -1) or (col == -1):
@@ -282,6 +287,45 @@
                        # Window isn't controlled by this sizer
                        row, col = None, None
                return (row, col)
+       
+       
+       def getItemByRowCol(self, row, col):
+               """Returns the item at the given position if one 
+               exists. If not, returns None.
+               """
+               try:
+                       itm = self.FindItemAtPosition((row, col))
+                       ret = itm.GetWindow()
+               except:
+                       ret = None
+               return ret
+       
+       
+       def getNeighbor(self, obj, dir):
+               """Returns the object adjacent to the given object. Possible
+               values for 'dir' are: left, right, up, down.
+               """
+               dir = dir[0].lower()
+               if dir not in "lrud":
+                       return None             
+               offsets = {"l" : (0, -1), "r" : (0, 1), "u" : (-1, 0), "d" : 
(1, 0)}
+               off = offsets[dir]
+               return self.getItemAtOffset(obj, off)
+               
+       
+       def getItemAtOffset(self, obj, off):
+               """Given an object and a (row, col) offset, returns
+               the object at the offset position, or None if no such 
+               object exists.
+               """
+               row, col = self.getGridPos(obj)
+               newRow = row + off[0]
+               newCol = col + off[1]
+               try:
+                       ret = self.getItemByRowCol(newRow, newCol)
+               except:
+                       ret = None
+               return ret
 
        
        def copyGrid(self, oldGrid):

Modified: trunk/dabo/ui/uiwx/dSizerMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dSizerMixin.py   2005-08-27 17:56:50 UTC (rev 1202)
+++ trunk/dabo/ui/uiwx/dSizerMixin.py   2005-08-28 02:41:10 UTC (rev 1203)
@@ -53,7 +53,13 @@
        growFlag = wx.EXPAND
        fixedFlag = wx.FIXED_MINSIZE 
                        
+       
+       def appendItems(self, items, *args, **kwargs):
+               """Append each item to the sizer."""
+               for item in items:
+                       self.append(item, *args, **kwargs)
                        
+                       
        def append(self, item, layout="normal", proportion=0, alignment=None,
                        halign="left", valign="top", border=None, 
borderFlags=None):
                """Adds the passed object to the end of the list of items 
controlled
@@ -184,8 +190,20 @@
        def release(self):
                """Wrapper method for wx's Destroy"""
                self.Destroy()
+       
+       
+       def showItem(self, itm):
+               """Makes sure that the passed item is visible"""
+               self.Show(itm, show=True, recursive=True)
+               self.layout()
                
                
+       def hideItem(self, itm):
+               """Hides the passed item"""
+               self.Show(itm, show=False, recursive=True)
+               self.layout()
+               
+               
        def drawOutline(self, win, recurse=False):
                """ There are some cases where being able to see the sizer
                is helpful, such as at design time. This method can be called




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

Reply via email to