home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / Tools / IDE / Wcontrols.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  21.2 KB  |  490 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import Ctl
  5. import Controls
  6. import Win
  7. import Wbase
  8. import Qd
  9. import Evt
  10.  
  11. class ControlWidget(Wbase.ClickableWidget):
  12.     '''Baseclass for all native controls.'''
  13.     
  14.     def __init__(self, possize, title = 'Control', procID = 0, callback = None, value = 0, min = 0, max = 1):
  15.         Wbase.ClickableWidget.__init__(self, possize)
  16.         self._control = None
  17.         self._title = title
  18.         self._callback = callback
  19.         self._procID = procID
  20.         self._value = value
  21.         self._min = min
  22.         self._max = max
  23.         self._enabled = 1
  24.  
  25.     
  26.     def open(self):
  27.         self._calcbounds()
  28.         self._control = Ctl.NewControl(self._parentwindow.wid, self._bounds, self._title, 1, self._value, self._min, self._max, self._procID, 0)
  29.         self.SetPort()
  30.         self.enable(self._enabled)
  31.  
  32.     
  33.     def adjust(self, oldbounds):
  34.         self.SetPort()
  35.         self._control.HideControl()
  36.         self._control.MoveControl(self._bounds[0], self._bounds[1])
  37.         self._control.SizeControl(self._bounds[2] - self._bounds[0], self._bounds[3] - self._bounds[1])
  38.         if self._visible:
  39.             Qd.EraseRect(self._bounds)
  40.             self._control.ShowControl()
  41.             Win.ValidRect(self._bounds)
  42.         
  43.  
  44.     
  45.     def close(self):
  46.         self._control.HideControl()
  47.         self._control = None
  48.         Wbase.ClickableWidget.close(self)
  49.  
  50.     
  51.     def enable(self, onoff):
  52.         if self._control and self._enabled != onoff:
  53.             if not onoff:
  54.                 pass
  55.             self._control.HiliteControl(255)
  56.             self._enabled = onoff
  57.         
  58.  
  59.     
  60.     def show(self, onoff):
  61.         self._visible = onoff
  62.         for w in self._widgets:
  63.             w.show(onoff)
  64.         
  65.  
  66.     
  67.     def activate(self, onoff):
  68.         self._activated = onoff
  69.         if self._enabled:
  70.             if not onoff:
  71.                 pass
  72.             self._control.HiliteControl(255)
  73.         
  74.  
  75.     
  76.     def draw(self, visRgn = None):
  77.         if self._visible:
  78.             self._control.Draw1Control()
  79.         
  80.  
  81.     
  82.     def test(self, point):
  83.         (ctltype, control) = Ctl.FindControl(point, self._parentwindow.wid)
  84.         if self._enabled and control == self._control:
  85.             return 1
  86.         
  87.  
  88.     
  89.     def click(self, point, modifiers):
  90.         if not (self._enabled):
  91.             return None
  92.         
  93.         part = self._control.TrackControl(point)
  94.         if part:
  95.             if self._callback:
  96.                 Wbase.CallbackCall(self._callback, 0)
  97.             
  98.         
  99.  
  100.     
  101.     def settitle(self, title):
  102.         if self._control:
  103.             self._control.SetControlTitle(title)
  104.         
  105.         self._title = title
  106.  
  107.     
  108.     def gettitle(self):
  109.         return self._title
  110.  
  111.  
  112.  
  113. class Button(ControlWidget):
  114.     '''Standard push button.'''
  115.     
  116.     def __init__(self, possize, title = 'Button', callback = None):
  117.         procID = Controls.pushButProc | Controls.useWFont
  118.         ControlWidget.__init__(self, possize, title, procID, callback, 0, 0, 1)
  119.         self._isdefault = 0
  120.  
  121.     
  122.     def push(self):
  123.         if not (self._enabled):
  124.             return None
  125.         
  126.         import time
  127.         self._control.HiliteControl(1)
  128.         time.sleep(0.1)
  129.         self._control.HiliteControl(0)
  130.         if self._callback:
  131.             Wbase.CallbackCall(self._callback, 0)
  132.         
  133.  
  134.     
  135.     def enable(self, onoff):
  136.         if self._control and self._enabled != onoff:
  137.             if not onoff:
  138.                 pass
  139.             self._control.HiliteControl(255)
  140.             self._enabled = onoff
  141.             if self._isdefault and self._visible:
  142.                 self.SetPort()
  143.                 self.drawfatframe(onoff)
  144.             
  145.         
  146.  
  147.     
  148.     def activate(self, onoff):
  149.         self._activated = onoff
  150.         if self._enabled:
  151.             if not onoff:
  152.                 pass
  153.             self._control.HiliteControl(255)
  154.             if self._isdefault and self._visible:
  155.                 self.SetPort()
  156.                 self.drawfatframe(onoff)
  157.             
  158.         
  159.  
  160.     
  161.     def show(self, onoff):
  162.         ControlWidget.show(self, onoff)
  163.         if self._isdefault:
  164.             if onoff:
  165.                 pass
  166.             self.drawfatframe(self._enabled)
  167.         
  168.  
  169.     
  170.     def draw(self, visRgn = None):
  171.         if self._visible:
  172.             self._control.Draw1Control()
  173.             if self._isdefault and self._activated:
  174.                 self.drawfatframe(self._enabled)
  175.             
  176.         
  177.  
  178.     
  179.     def drawfatframe(self, onoff):
  180.         state = Qd.GetPenState()
  181.         if onoff:
  182.             Qd.PenPat(Qd.qd.black)
  183.         else:
  184.             Qd.PenPat(Qd.qd.white)
  185.         fatrect = Qd.InsetRect(self._bounds, -4, -4)
  186.         Qd.PenSize(3, 3)
  187.         Qd.FrameRoundRect(fatrect, 16, 16)
  188.         Qd.SetPenState(state)
  189.  
  190.     
  191.     def _setdefault(self, onoff):
  192.         self._isdefault = onoff
  193.         if self._control and self._enabled:
  194.             self.SetPort()
  195.             self.drawfatframe(onoff)
  196.         
  197.  
  198.     
  199.     def adjust(self, oldbounds):
  200.         if self._isdefault:
  201.             old = Qd.InsetRect(oldbounds, -4, -4)
  202.             new = Qd.InsetRect(self._bounds, -4, -4)
  203.             Qd.EraseRect(old)
  204.             Win.InvalRect(old)
  205.             Win.InvalRect(new)
  206.         
  207.         ControlWidget.adjust(self, oldbounds)
  208.  
  209.  
  210.  
  211. class CheckBox(ControlWidget):
  212.     '''Standard checkbox.'''
  213.     
  214.     def __init__(self, possize, title = 'Checkbox', callback = None, value = 0):
  215.         procID = Controls.checkBoxProc | Controls.useWFont
  216.         ControlWidget.__init__(self, possize, title, procID, callback, value, 0, 1)
  217.  
  218.     
  219.     def click(self, point, modifiers):
  220.         if not (self._enabled):
  221.             return None
  222.         
  223.         part = self._control.TrackControl(point)
  224.         if part:
  225.             self.toggle()
  226.             if self._callback:
  227.                 Wbase.CallbackCall(self._callback, 0, self.get())
  228.             
  229.         
  230.  
  231.     
  232.     def push(self):
  233.         if not (self._enabled):
  234.             return None
  235.         
  236.         self.toggle()
  237.         if self._callback:
  238.             Wbase.CallbackCall(self._callback, 0, self.get())
  239.         
  240.  
  241.     
  242.     def toggle(self):
  243.         self.set(not self.get())
  244.  
  245.     
  246.     def set(self, value):
  247.         if self._control:
  248.             self._control.SetControlValue(value)
  249.         else:
  250.             self._value = value
  251.  
  252.     
  253.     def get(self):
  254.         if self._control:
  255.             return self._control.GetControlValue()
  256.         else:
  257.             return self._value
  258.  
  259.  
  260.  
  261. class RadioButton(ControlWidget):
  262.     '''Standard radiobutton.'''
  263.     
  264.     def __init__(self, possize, title, thebuttons, callback = None, value = 0):
  265.         procID = Controls.radioButProc | Controls.useWFont
  266.         ControlWidget.__init__(self, possize, title, procID, callback, value, 0, 1)
  267.         self.thebuttons = thebuttons
  268.         thebuttons.append(self)
  269.  
  270.     
  271.     def close(self):
  272.         self.thebuttons = None
  273.         ControlWidget.close(self)
  274.  
  275.     
  276.     def click(self, point, modifiers):
  277.         if not (self._enabled):
  278.             return None
  279.         
  280.         part = self._control.TrackControl(point)
  281.         if part:
  282.             self.set(1)
  283.             if self._callback:
  284.                 Wbase.CallbackCall(self._callback, 0, 1)
  285.             
  286.         
  287.  
  288.     
  289.     def push(self):
  290.         if not (self._enabled):
  291.             return None
  292.         
  293.         self.set(1)
  294.         if self._callback:
  295.             Wbase.CallbackCall(self._callback, 0, 1)
  296.         
  297.  
  298.     
  299.     def set(self, value):
  300.         for button in self.thebuttons:
  301.             pass
  302.         
  303.  
  304.     
  305.     def get(self):
  306.         if self._control:
  307.             return self._control.GetControlValue()
  308.         else:
  309.             return self._value
  310.  
  311.  
  312.  
  313. class Scrollbar(ControlWidget):
  314.     '''Standard scrollbar.'''
  315.     
  316.     def __init__(self, possize, callback = None, value = 0, min = 0, max = 0):
  317.         procID = Controls.scrollBarProc
  318.         ControlWidget.__init__(self, possize, '', procID, callback, value, min, max)
  319.  
  320.     
  321.     def set(self, value):
  322.         if self._callback:
  323.             Wbase.CallbackCall(self._callback, 1, value)
  324.         
  325.  
  326.     
  327.     def up(self):
  328.         if self._callback:
  329.             Wbase.CallbackCall(self._callback, 1, '+')
  330.         
  331.  
  332.     
  333.     def down(self):
  334.         if self._callback:
  335.             Wbase.CallbackCall(self._callback, 1, '-')
  336.         
  337.  
  338.     
  339.     def pageup(self):
  340.         if self._callback:
  341.             Wbase.CallbackCall(self._callback, 1, '++')
  342.         
  343.  
  344.     
  345.     def pagedown(self):
  346.         if self._callback:
  347.             Wbase.CallbackCall(self._callback, 1, '--')
  348.         
  349.  
  350.     
  351.     def setmin(self, min):
  352.         self._control.SetControlMinimum(min)
  353.  
  354.     
  355.     def setmax(self, min):
  356.         self._control.SetControlMinimum(max)
  357.  
  358.     
  359.     def getmin(self):
  360.         return self._control.GetControlMinimum()
  361.  
  362.     
  363.     def getmax(self):
  364.         return self._control.GetControlMinimum()
  365.  
  366.     
  367.     def click(self, point, modifiers):
  368.         if not (self._enabled):
  369.             return None
  370.         
  371.         part = self._control.TestControl(point)
  372.         if part <= part:
  373.             pass
  374.         elif part <= Controls.inPageDown:
  375.             self._control.HiliteControl(part)
  376.             self._hit(part)
  377.             oldpart = part
  378.             now = Evt.TickCount()
  379.             while Evt.StillDown():
  380.                 if Evt.TickCount() - now > 18:
  381.                     break
  382.                 
  383.             while Evt.StillDown():
  384.                 part = self._control.TestControl(point)
  385.                 if part == oldpart:
  386.                     self._control.HiliteControl(part)
  387.                     self._hit(part)
  388.                 else:
  389.                     self._control.HiliteControl(0)
  390.                 self.SetPort()
  391.                 point = Evt.GetMouse()
  392.             self._control.HiliteControl(0)
  393.         elif part == Controls.inThumb:
  394.             part = self._control.TrackControl(point)
  395.             if part:
  396.                 self._hit(part)
  397.             
  398.         
  399.  
  400.     
  401.     def _hit(self, part):
  402.         if part == Controls.inThumb:
  403.             value = self._control.GetControlValue()
  404.         elif part == Controls.inUpButton:
  405.             value = '+'
  406.         elif part == Controls.inDownButton:
  407.             value = '-'
  408.         elif part == Controls.inPageUp:
  409.             value = '++'
  410.         elif part == Controls.inPageDown:
  411.             value = '--'
  412.         
  413.         if self._callback:
  414.             Wbase.CallbackCall(self._callback, 1, value)
  415.         
  416.  
  417.     
  418.     def draw(self, visRgn = None):
  419.         if self._visible:
  420.             self._control.Draw1Control()
  421.             Qd.FrameRect(self._bounds)
  422.         
  423.  
  424.     
  425.     def adjust(self, oldbounds):
  426.         self.SetPort()
  427.         Win.InvalRect(oldbounds)
  428.         self._control.HideControl()
  429.         self._control.MoveControl(self._bounds[0], self._bounds[1])
  430.         self._control.SizeControl(self._bounds[2] - self._bounds[0], self._bounds[3] - self._bounds[1])
  431.         if self._visible:
  432.             Qd.EraseRect(self._bounds)
  433.             if self._activated:
  434.                 self._control.ShowControl()
  435.             else:
  436.                 Qd.FrameRect(self._bounds)
  437.             Win.ValidRect(self._bounds)
  438.         
  439.  
  440.     
  441.     def activate(self, onoff):
  442.         self._activated = onoff
  443.         if self._visible:
  444.             if onoff:
  445.                 self._control.ShowControl()
  446.             else:
  447.                 self._control.HideControl()
  448.                 self.draw(None)
  449.                 Win.ValidRect(self._bounds)
  450.         
  451.  
  452.     
  453.     def set(self, value):
  454.         if self._control:
  455.             self._control.SetControlValue(value)
  456.         else:
  457.             self._value = value
  458.  
  459.     
  460.     def get(self):
  461.         if self._control:
  462.             return self._control.GetControlValue()
  463.         else:
  464.             return self._value
  465.  
  466.  
  467.  
  468. class __xxxx_PopupControl(ControlWidget):
  469.     
  470.     def __init__(self, possize, title = 'Button', callback = None):
  471.         procID = Controls.popupMenuProc
  472.         ControlWidget.__init__(self, possize, title, procID, callback, 0, 0, 1)
  473.         self._isdefault = 0
  474.  
  475.  
  476.  
  477. def _scalebarvalue(absmin, absmax, curmin, curmax):
  478.     if curmin <= absmin and curmax >= absmax:
  479.         return None
  480.     
  481.     if curmin <= absmin:
  482.         return 0
  483.     
  484.     if curmax >= absmax:
  485.         return 32767
  486.     
  487.     perc = float(curmin - absmin) / float(absmax - absmin - curmax - curmin)
  488.     return int(perc * 32767)
  489.  
  490.