home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / pippy-0.6beta-src.tar.gz / pippy-0.6beta-src.tar / pippy-0.6beta-src / src / Lib / lib-stdwin / HVSplit.py < prev    next >
Text File  |  2000-12-21  |  2KB  |  63 lines

  1. # HVSplit contains generic code for HSplit and VSplit.
  2. # HSplit and VSplit are specializations to either dimension.
  3.  
  4. # XXX This does not yet stretch/shrink children if there is too much
  5. # XXX or too little space in the split dimension.
  6. # XXX (NB There is no interface to ask children for stretch preferences.)
  7.  
  8. from Split import Split
  9.  
  10. class HVSplit(Split):
  11.     #
  12.     def create(self, parent, hv):
  13.         # hv is 0 for HSplit, 1 for VSplit
  14.         self = Split.create(self, parent)
  15.         self.hv = hv
  16.         return self
  17.     #
  18.     def getminsize(self, m, sugg_size):
  19.         hv, vh = self.hv, 1 - self.hv
  20.         size = [0, 0]
  21.         sugg_size = [sugg_size[0], sugg_size[1]]
  22.         sugg_size[hv] = 0
  23.         sugg_size = sugg_size[0], sugg_size[1] # Make a tuple
  24.         for c in self.children:
  25.             csize = c.getminsize(m, sugg_size)
  26.             if csize[vh] > size[vh]: size[vh] = csize[vh]
  27.             size[hv] = size[hv] + csize[hv]
  28.         return size[0], size[1]
  29.     #
  30.     def getbounds(self):
  31.         return self.bounds
  32.     #
  33.     def setbounds(self, bounds):
  34.         self.bounds = bounds
  35.         hv, vh = self.hv, 1 - self.hv
  36.         mf = self.parent.beginmeasuring
  37.         begin, end = bounds
  38.         sugg_size = end[0] - begin[0], end[1] - begin[1]
  39.         size = self.getminsize(mf(), sugg_size)
  40.         origin = [begin[0], begin[1]]
  41.         sugg_size = [sugg_size[0], sugg_size[1]] # Make a list
  42.         sugg_size[hv] = 0
  43.         sugg_size = sugg_size[0], sugg_size[1] # Make a tuple
  44.         for c in self.children:
  45.             size = c.getminsize(mf(), sugg_size)
  46.             corner = [0, 0]
  47.             corner[vh] = end[vh]
  48.             corner[hv] = origin[hv] + size[hv]
  49.             c.setbounds(((origin[0], origin[1]), \
  50.                     (corner[0], corner[1])))
  51.             origin[hv] = corner[hv]
  52.             # XXX stretch
  53.             # XXX too-small
  54.     #
  55.  
  56. class HSplit(HVSplit):
  57.     def create(self, parent):
  58.         return HVSplit.create(self, parent, 0)
  59.  
  60. class VSplit(HVSplit):
  61.     def create(self, parent):
  62.         return HVSplit.create(self, parent, 1)
  63.