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 / Split.py < prev    next >
Text File  |  2000-12-21  |  6KB  |  212 lines

  1. # Generic Split implementation.
  2. # Use as a base class for other splits.
  3. # Derived classes should at least implement the methods that call
  4. # unimpl() below: getminsize(), getbounds() and setbounds().
  5.  
  6. Error = 'Split.Error'    # Exception
  7.  
  8. import rect
  9. from stdwinevents import *
  10.  
  11. class Split:
  12.     #
  13.     # Calls from creator
  14.     # NB derived classes may add parameters to create()
  15.     #
  16.     def create(self, parent):
  17.         parent.addchild(self)
  18.         self.parent = parent
  19.         self.children = []
  20.         self.mouse_interest = []
  21.         self.keybd_interest = []
  22.         self.timer_interest = []
  23.         self.altdraw_interest = []
  24.         self.mouse_focus = None
  25.         self.keybd_focus = None
  26.         return self
  27.     #
  28.     # Downcalls from parent to child
  29.     #
  30.     def destroy(self):
  31.         self.parent = None
  32.         for child in self.children:
  33.             child.destroy()
  34.         del self.children[:]
  35.         del self.mouse_interest[:]
  36.         del self.keybd_interest[:]
  37.         del self.timer_interest[:]
  38.         del self.altdraw_interest[:]
  39.         self.mouse_focus = None
  40.         self.keybd_focus = None
  41.     #
  42.     def getminsize(self, m, (width, height)):
  43.         return unimpl()            # Should ask children
  44.     def getbounds(self):
  45.         return unimpl()
  46.     def setbounds(self, bounds):
  47.         unimpl()            # Should tell children
  48.     #
  49.     def realize(self):
  50.         for child in self.children:
  51.             child.realize()
  52.     #
  53.     def draw(self, d, detail):
  54.         # (Could avoid calls to children outside the area)
  55.         for child in self.children:
  56.             child.draw(d, detail)
  57.     #
  58.     def altdraw(self, detail):
  59.         for child in self.altdraw_interest:
  60.             child.altdraw(detail)
  61.     #
  62.     # Keyboard focus handling (used internally)
  63.     # XXX This is not enough if two levels of splits
  64.     # XXX surround text fields!
  65.     #
  66.     def set_keybd_focus(self, child):
  67.         if self.keybd_focus <> child:
  68.             if self.keybd_focus:
  69.                 self.keybd_focus.deactivate()
  70.                 self.keybd_focus = None
  71.             if child:
  72.                 child.activate()
  73.                 self.keybd_focus = child
  74.     def next_keybd_focus(self):
  75.         if not self.keybd_interest:
  76.             self.set_keybd_focus(None)
  77.             return
  78.         if self.keybd_focus in self.keybd_interest:
  79.             i = self.keybd_interest.index(self.keybd_focus)
  80.             i = (i+1) % len(self.keybd_interest)
  81.         else:
  82.             i = 0
  83.         self.set_keybd_focus(self.keybd_interest[i])
  84.     #
  85.     # Downcalls only made after certain upcalls
  86.     #
  87.     def mouse_down(self, detail):
  88.         if self.mouse_focus:
  89.             self.mouse_focus.mouse_down(detail)
  90.             return
  91.         p = detail[0]
  92.         for child in self.mouse_interest:
  93.             if rect.pointinrect(p, child.getbounds()):
  94.                 self.mouse_focus = child
  95.                 if child in self.keybd_interest:
  96.                     self.set_keybd_focus(child)
  97.                 child.mouse_down(detail)
  98.     def mouse_move(self, detail):
  99.         if self.mouse_focus:
  100.             self.mouse_focus.mouse_move(detail)
  101.     def mouse_up(self, detail):
  102.         if self.mouse_focus:
  103.             self.mouse_focus.mouse_up(detail)
  104.             self.mouse_focus = None
  105.     #
  106.     def activate(self):
  107.         if self.keybd_focus:
  108.             self.keybd_focus.activate()
  109.         else:
  110.             self.next_keybd_focus()
  111.     def deactivate(self):
  112.         if self.keybd_focus:
  113.             self.keybd_focus.deactivate()
  114.     #
  115.     def keybd(self, type, detail):
  116.         if not self.keybd_focus:
  117.             self.set_keybd_focus(self.keybd_interest[0])
  118.         if type == WE_COMMAND and detail == WC_TAB and \
  119.                     len(self.keybd_interest) > 1:
  120.             self.next_keybd_focus()
  121.             return
  122.         self.keybd_focus.keybd(type, detail)
  123.     #
  124.     def timer(self):
  125.         for child in self.timer_interest:
  126.             child.timer()
  127.     #
  128.     # Upcalls from child to parent
  129.     #
  130.     def addchild(self, child):
  131.         if child in self.children:
  132.             raise Error, 'addchild: child already inlist'
  133.         self.children.append(child)
  134.     def delchild(self, child):
  135.         if child not in self.children:
  136.             raise Error, 'delchild: child not in list'
  137.         self.children.remove(child)
  138.         if child in self.mouse_interest:
  139.             self.mouse_interest.remove(child)
  140.         if child in self.keybd_interest:
  141.             self.keybd_interest.remove(child)
  142.         if child in self.timer_interest:
  143.             self.timer_interest.remove(child)
  144.         if child in self.altdraw_interest:
  145.             self.altdraw_interest.remove(child)
  146.         if child == self.mouse_focus:
  147.             self.mouse_focus = None
  148.         if child == self.keybd_focus:
  149.             self.keybd_focus = None
  150.     #
  151.     def need_mouse(self, child):
  152.         if child not in self.mouse_interest:
  153.             self.mouse_interest.append(child)
  154.             self.parent.need_mouse(self)
  155.     def no_mouse(self, child):
  156.         if child == self.mouse_focus:
  157.             self.mouse_focus = None
  158.         if child in self.mouse_interest:
  159.             self.mouse_interest.remove(child)
  160.             if not self.mouse_interest:
  161.                 self.parent.no_mouse(self)
  162.     #
  163.     def need_keybd(self, child):
  164.         if child not in self.keybd_interest:
  165.             self.keybd_interest.append(child)
  166.             self.parent.need_keybd(self)
  167.         if not self.keybd_focus:
  168.             self.set_keybd_focus(child)
  169.     def no_keybd(self, child):
  170.         if child == self.keybd_focus:
  171.             self.keybd_focus = None # Don't call child.deactivate()
  172.         if child in self.keybd_interest:
  173.             self.keybd_interest.remove(child)
  174.             if not self.keybd_interest:
  175.                 self.parent.no_keybd(self)
  176.     #
  177.     def need_timer(self, child):
  178.         if child not in self.timer_interest:
  179.             self.timer_interest.append(child)
  180.             self.parent.need_timer(self)
  181.     def no_timer(self, child):
  182.         if child in self.timer_interest:
  183.             self.timer_interest.remove(child)
  184.             if not self.timer_interest:
  185.                 self.parent.no_timer(self)
  186.     #
  187.     def need_altdraw(self, child):
  188.         if child not in self.altdraw_interest:
  189.             self.altdraw_interest.append(child)
  190.             self.parent.need_altdraw(self)
  191.     def no_altdraw(self, child):
  192.         if child in self.altdraw_interest:
  193.             self.altdraw_interest.remove(child)
  194.             if not self.altdraw_interest:
  195.                 self.parent.no_altdraw(self)
  196.     #
  197.     # The rest are transparent:
  198.     #
  199.     def begindrawing(self):
  200.         return self.parent.begindrawing()
  201.     def beginmeasuring(self):
  202.         return self.parent.beginmeasuring()
  203.     def getwindow(self):
  204.         return self.parent.getwindow()
  205.     #
  206.     def change(self, area):
  207.         self.parent.change(area)
  208.     def scroll(self, area, vector):
  209.         self.parent.scroll(area, vector)
  210.     def settimer(self, itimer):
  211.         self.parent.settimer(itimer)
  212.