aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Abstract.py76
-rw-r--r--lib/Buttons.py590
-rw-r--r--lib/CSplit.py124
-rw-r--r--lib/DEVICE.py794
-rw-r--r--lib/GL.py176
-rw-r--r--lib/HVSplit.py84
-rw-r--r--lib/Histogram.py54
-rw-r--r--lib/Sliders.py270
-rw-r--r--lib/Soundogram.py54
-rw-r--r--lib/Split.py212
-rw-r--r--lib/StripChart.py118
-rw-r--r--lib/Tcl.py712
-rw-r--r--lib/TclShell.py434
-rw-r--r--lib/TclUtil.py386
-rw-r--r--lib/TestCSplit.py32
-rw-r--r--lib/TransParent.py174
-rw-r--r--lib/VUMeter.py76
-rw-r--r--lib/WindowParent.py180
-rw-r--r--lib/adv.py426
-rw-r--r--lib/anywin.py12
-rw-r--r--lib/auds.py148
-rw-r--r--lib/calendar.py216
-rw-r--r--lib/clock.py292
-rw-r--r--lib/cmp.py92
-rw-r--r--lib/cmpcache.py80
-rw-r--r--lib/commands.py64
-rw-r--r--lib/dircache.py40
-rw-r--r--lib/dircmp.py318
-rw-r--r--lib/dirwin.py32
-rw-r--r--lib/dis.py172
-rw-r--r--lib/dump.py60
-rw-r--r--lib/fact.py48
-rw-r--r--lib/filewin.py12
-rw-r--r--lib/fnmatch.py52
-rw-r--r--lib/getopt.py54
-rw-r--r--lib/glob.py66
-rw-r--r--lib/grep.py52
-rw-r--r--lib/gwin.py176
-rw-r--r--lib/lambda.py88
-rw-r--r--lib/listwin.py64
-rw-r--r--lib/localtime.py70
-rw-r--r--lib/maccache.py52
-rw-r--r--lib/macglob.py64
-rw-r--r--lib/macpath.py110
-rw-r--r--lib/macshell.py594
-rw-r--r--lib/packmail.py62
-rw-r--r--lib/panel.py344
-rw-r--r--lib/panelparser.py122
-rw-r--r--lib/path.py114
-rw-r--r--lib/poly.py66
-rw-r--r--lib/rand.py6
-rw-r--r--lib/rect.py76
-rw-r--r--lib/selection.py78
-rw-r--r--lib/shutil.py78
-rw-r--r--lib/stat.py44
-rw-r--r--lib/statcache.py72
-rw-r--r--lib/stdwinevents.py62
-rw-r--r--lib/stdwinsupport.py42
-rw-r--r--lib/string.py140
-rw-r--r--lib/sunaudio.py64
-rw-r--r--lib/tablewin.py382
-rw-r--r--lib/tb.py360
-rw-r--r--lib/testall.py106
-rw-r--r--lib/textwin.py196
-rw-r--r--lib/util.py24
-rw-r--r--lib/whrandom.py82
-rw-r--r--lib/zmod.py92
67 files changed, 5306 insertions, 5306 deletions
diff --git a/lib/Abstract.py b/lib/Abstract.py
index 385e6e5..9d9013b 100644
--- a/lib/Abstract.py
+++ b/lib/Abstract.py
@@ -11,45 +11,45 @@
# define() while split creation methods are called create().
class AbstractParent():
- #
- # Upcalls from child to parent
- #
- def addchild(self, child): unimpl()
- def delchild(self, child): unimpl()
- #
- def need_mouse(self, child): unimpl()
- def no_mouse(self, child): unimpl()
- #
- def need_timer(self, child): unimpl()
- def no_timer(self, child): unimpl()
- #
- # XXX need_kbd, no_kbd; focus???
- #
- def begindrawing(self): return unimpl()
- def beginmeasuring(self): return unimpl()
- #
- def change(self, area): unimpl()
- def scroll(self, (area, (dh, dv))): unimpl()
- def settimer(self, itimer): unimpl()
+ #
+ # Upcalls from child to parent
+ #
+ def addchild(self, child): unimpl()
+ def delchild(self, child): unimpl()
+ #
+ def need_mouse(self, child): unimpl()
+ def no_mouse(self, child): unimpl()
+ #
+ def need_timer(self, child): unimpl()
+ def no_timer(self, child): unimpl()
+ #
+ # XXX need_kbd, no_kbd; focus???
+ #
+ def begindrawing(self): return unimpl()
+ def beginmeasuring(self): return unimpl()
+ #
+ def change(self, area): unimpl()
+ def scroll(self, (area, (dh, dv))): unimpl()
+ def settimer(self, itimer): unimpl()
class AbstractChild():
- #
- # Downcalls from parent to child
- #
- def destroy(self): unimpl()
- #
- def minsize(self, m): return unimpl()
- def getbounds(self): return unimpl()
- def setbounds(self, bounds): unimpl()
- def draw(self, (d, area)): unimpl()
- #
- # Downcalls only made after certain upcalls
- #
- def mouse_down(self, detail): unimpl()
- def mouse_move(self, detail): unimpl()
- def mouse_up(self, detail): unimpl()
- #
- def timer(self): unimpl()
+ #
+ # Downcalls from parent to child
+ #
+ def destroy(self): unimpl()
+ #
+ def minsize(self, m): return unimpl()
+ def getbounds(self): return unimpl()
+ def setbounds(self, bounds): unimpl()
+ def draw(self, (d, area)): unimpl()
+ #
+ # Downcalls only made after certain upcalls
+ #
+ def mouse_down(self, detail): unimpl()
+ def mouse_move(self, detail): unimpl()
+ def mouse_up(self, detail): unimpl()
+ #
+ def timer(self): unimpl()
# A "Split" is a child that manages one or more children.
# (This terminology is due to DEC SRC, except for CSplits.)
@@ -58,4 +58,4 @@ class AbstractChild():
# for others (e.g., all geometry related calls) this is not possible.
class AbstractSplit() = AbstractChild(), AbstractParent():
- pass
+ pass
diff --git a/lib/Buttons.py b/lib/Buttons.py
index 7c36021..3ad5605 100644
--- a/lib/Buttons.py
+++ b/lib/Buttons.py
@@ -20,374 +20,374 @@ _MASK = 3
# LabelAppearance provides defaults for all appearance methods.
# selected state not visible
# disabled --> crossed out
-# hilited --> inverted
+# hilited --> inverted
#
class LabelAppearance():
- #
- # Initialization
- #
- def init_appearance(self):
- self.bounds = _rect.empty
- self.enabled = 1
- self.hilited = 0
- self.selected = 0
- self.text = ''
- #
- # Size enquiry
- #
- def minsize(self, m):
- try:
- self.text = self.text
- except NameError:
- self.text = ''
- return m.textwidth(self.text) + 6, m.lineheight() + 6
- #
- def getbounds(self):
- return self.bounds
- #
- # Changing the parameters
- #
- def settext(self, text):
- self.text = text
- if self.bounds <> _rect.empty:
- self.recalctextpos()
- self.redraw()
- #
- def setbounds(self, bounds):
- if self.bounds <> _rect.empty:
- self.parent.change(self.bounds)
- self.bounds = bounds
- if self.bounds <> _rect.empty:
- self.recalc()
- self.parent.change(bounds)
- #
- # Changing the state bits
- #
- def enable(self, flag):
- if flag <> self.enabled:
- self.enabled = flag
- if self.bounds <> _rect.empty:
- self.flipenable(self.parent.begindrawing())
- #
- def hilite(self, flag):
- if flag <> self.hilited:
- self.hilited = flag
- if self.bounds <> _rect.empty:
- self.fliphilite(self.parent.begindrawing())
- #
- def select(self, flag):
- if flag <> self.selected:
- self.selected = flag
- if self.bounds <> _rect.empty:
- self.redraw()
- #
- # Recalculate the box bounds and text position.
- # This can be overridden by buttons that draw different boxes
- # or want their text in a different position.
- #
- def recalc(self):
- if self.bounds <> _rect.empty:
- self.recalcbounds()
- self.recalctextpos()
- #
- def recalcbounds(self):
- self.hilitebounds = _rect.inset(self.bounds, (3, 3))
- self.crossbounds = self.bounds
- #
- def recalctextpos(self):
- (left, top), (right, bottom) = self.bounds
- m = self.parent.beginmeasuring()
- h = (left + right - m.textwidth(self.text)) / 2
- v = (top + bottom - m.lineheight()) / 2
- self.textpos = h, v
- #
- # Generic drawing interface.
- # Do not override redraw() or draw() methods; override drawit() c.s.
- #
- def redraw(self):
- if self.bounds <> _rect.empty:
- self.draw(self.parent.begindrawing(), self.bounds)
- #
- def draw(self, (d, area)):
- area = _rect.intersect(area, self.bounds)
- if area = _rect.empty:
- return
- d.cliprect(area)
- d.erase(self.bounds)
- self.drawit(d)
- d.noclip()
- #
- # The drawit() method is fairly generic but may be overridden.
- #
- def drawit(self, d):
- self.drawpict(d)
- if self.text:
- d.text(self.textpos, self.text)
- if not self.enabled:
- self.flipenable(d)
- if self.hilited:
- self.fliphilite(d)
- #
- # Default drawing detail functions.
- # Overriding these is normally sufficient to get different
- # appearances.
- #
- def drawpict(self, d):
- pass
- #
- def flipenable(self, d):
- _xorcross(d, self.crossbounds)
- #
- def fliphilite(self, d):
- d.invert(self.hilitebounds)
+ #
+ # Initialization
+ #
+ def init_appearance(self):
+ self.bounds = _rect.empty
+ self.enabled = 1
+ self.hilited = 0
+ self.selected = 0
+ self.text = ''
+ #
+ # Size enquiry
+ #
+ def minsize(self, m):
+ try:
+ self.text = self.text
+ except NameError:
+ self.text = ''
+ return m.textwidth(self.text) + 6, m.lineheight() + 6
+ #
+ def getbounds(self):
+ return self.bounds
+ #
+ # Changing the parameters
+ #
+ def settext(self, text):
+ self.text = text
+ if self.bounds <> _rect.empty:
+ self.recalctextpos()
+ self.redraw()
+ #
+ def setbounds(self, bounds):
+ if self.bounds <> _rect.empty:
+ self.parent.change(self.bounds)
+ self.bounds = bounds
+ if self.bounds <> _rect.empty:
+ self.recalc()
+ self.parent.change(bounds)
+ #
+ # Changing the state bits
+ #
+ def enable(self, flag):
+ if flag <> self.enabled:
+ self.enabled = flag
+ if self.bounds <> _rect.empty:
+ self.flipenable(self.parent.begindrawing())
+ #
+ def hilite(self, flag):
+ if flag <> self.hilited:
+ self.hilited = flag
+ if self.bounds <> _rect.empty:
+ self.fliphilite(self.parent.begindrawing())
+ #
+ def select(self, flag):
+ if flag <> self.selected:
+ self.selected = flag
+ if self.bounds <> _rect.empty:
+ self.redraw()
+ #
+ # Recalculate the box bounds and text position.
+ # This can be overridden by buttons that draw different boxes
+ # or want their text in a different position.
+ #
+ def recalc(self):
+ if self.bounds <> _rect.empty:
+ self.recalcbounds()
+ self.recalctextpos()
+ #
+ def recalcbounds(self):
+ self.hilitebounds = _rect.inset(self.bounds, (3, 3))
+ self.crossbounds = self.bounds
+ #
+ def recalctextpos(self):
+ (left, top), (right, bottom) = self.bounds
+ m = self.parent.beginmeasuring()
+ h = (left + right - m.textwidth(self.text)) / 2
+ v = (top + bottom - m.lineheight()) / 2
+ self.textpos = h, v
+ #
+ # Generic drawing interface.
+ # Do not override redraw() or draw() methods; override drawit() c.s.
+ #
+ def redraw(self):
+ if self.bounds <> _rect.empty:
+ self.draw(self.parent.begindrawing(), self.bounds)
+ #
+ def draw(self, (d, area)):
+ area = _rect.intersect(area, self.bounds)
+ if area = _rect.empty:
+ return
+ d.cliprect(area)
+ d.erase(self.bounds)
+ self.drawit(d)
+ d.noclip()
+ #
+ # The drawit() method is fairly generic but may be overridden.
+ #
+ def drawit(self, d):
+ self.drawpict(d)
+ if self.text:
+ d.text(self.textpos, self.text)
+ if not self.enabled:
+ self.flipenable(d)
+ if self.hilited:
+ self.fliphilite(d)
+ #
+ # Default drawing detail functions.
+ # Overriding these is normally sufficient to get different
+ # appearances.
+ #
+ def drawpict(self, d):
+ pass
+ #
+ def flipenable(self, d):
+ _xorcross(d, self.crossbounds)
+ #
+ def fliphilite(self, d):
+ d.invert(self.hilitebounds)
# ButtonAppearance displays a centered string in a box.
# selected --> bold border
# disabled --> crossed out
-# hilited --> inverted
+# hilited --> inverted
#
class ButtonAppearance() = LabelAppearance():
- #
- def drawpict(self, d):
- d.box(_rect.inset(self.bounds, (1, 1)))
- if self.selected:
- # Make a thicker box
- d.box(self.bounds)
- d.box(_rect.inset(self.bounds, (2, 2)))
- d.box(_rect.inset(self.bounds, (3, 3)))
- #
+ #
+ def drawpict(self, d):
+ d.box(_rect.inset(self.bounds, (1, 1)))
+ if self.selected:
+ # Make a thicker box
+ d.box(self.bounds)
+ d.box(_rect.inset(self.bounds, (2, 2)))
+ d.box(_rect.inset(self.bounds, (3, 3)))
+ #
# CheckAppearance displays a small square box and a left-justified string.
# selected --> a cross appears in the box
# disabled --> whole button crossed out
-# hilited --> box is inverted
+# hilited --> box is inverted
#
class CheckAppearance() = LabelAppearance():
- #
- def minsize(self, m):
- width, height = m.textwidth(self.text) + 6, m.lineheight() + 6
- return width + height + m.textwidth(' '), height
- #
- def drawpict(self, d):
- d.box(self.boxbounds)
- if self.selected: _xorcross(d, self.boxbounds)
- #
- def recalcbounds(self):
- LabelAppearance.recalcbounds(self)
- (left, top), (right, bottom) = self.bounds
- self.size = bottom - top - 4
- self.boxbounds = (left+2, top+2), (left+2+self.size, bottom-2)
- self.hilitebounds = self.boxbounds
- #
- def recalctextpos(self):
- m = self.parent.beginmeasuring()
- (left, top), (right, bottom) = self.boxbounds
- h = right + m.textwidth(' ')
- v = top + (self.size - m.lineheight()) / 2
- self.textpos = h, v
- #
+ #
+ def minsize(self, m):
+ width, height = m.textwidth(self.text) + 6, m.lineheight() + 6
+ return width + height + m.textwidth(' '), height
+ #
+ def drawpict(self, d):
+ d.box(self.boxbounds)
+ if self.selected: _xorcross(d, self.boxbounds)
+ #
+ def recalcbounds(self):
+ LabelAppearance.recalcbounds(self)
+ (left, top), (right, bottom) = self.bounds
+ self.size = bottom - top - 4
+ self.boxbounds = (left+2, top+2), (left+2+self.size, bottom-2)
+ self.hilitebounds = self.boxbounds
+ #
+ def recalctextpos(self):
+ m = self.parent.beginmeasuring()
+ (left, top), (right, bottom) = self.boxbounds
+ h = right + m.textwidth(' ')
+ v = top + (self.size - m.lineheight()) / 2
+ self.textpos = h, v
+ #
# RadioAppearance displays a round indicator and a left-justified string.
# selected --> a dot appears in the indicator
# disabled --> whole button crossed out
-# hilited --> indicator is inverted
+# hilited --> indicator is inverted
#
class RadioAppearance() = CheckAppearance():
- #
- def drawpict(self, d):
- (left, top), (right, bottom) = self.boxbounds
- radius = self.size / 2
- h, v = left + radius, top + radius
- d.circle((h, v), radius)
- if self.selected:
- some = radius/3
- d.paint((h-some, v-some), (h+some, v+some))
- #
+ #
+ def drawpict(self, d):
+ (left, top), (right, bottom) = self.boxbounds
+ radius = self.size / 2
+ h, v = left + radius, top + radius
+ d.circle((h, v), radius)
+ if self.selected:
+ some = radius/3
+ d.paint((h-some, v-some), (h+some, v+some))
+ #
# NoReactivity ignores mouse events.
#
class NoReactivity():
- def init_reactivity(self): pass
+ def init_reactivity(self): pass
# BaseReactivity defines hooks and asks for mouse events,
# but provides only dummy mouse event handlers.
# The trigger methods call the corresponding hooks set by the user.
# Hooks (and triggers) mean the following:
-# down_hook called on some mouse-down events
-# move_hook called on some mouse-move events
-# up_hook called on mouse-up events
-# on_hook called for buttons with on/off state, when it goes on
-# hook called when a button 'fires' or a radiobutton goes on
+# down_hook called on some mouse-down events
+# move_hook called on some mouse-move events
+# up_hook called on mouse-up events
+# on_hook called for buttons with on/off state, when it goes on
+# hook called when a button 'fires' or a radiobutton goes on
# There are usually extra conditions, e.g., hooks are only called
# when the button is enabled, or active, or selected (on).
#
class BaseReactivity():
- #
- def init_reactivity(self):
- self.down_hook = self.move_hook = self.up_hook = \
- self.on_hook = self.off_hook = \
- self.hook = self.active = 0
- self.parent.need_mouse(self)
- #
- def mousetest(self, hv):
- return _rect.pointinrect(hv, self.bounds)
- #
- def mouse_down(self, detail):
- pass
- #
- def mouse_move(self, detail):
- pass
- #
- def mouse_up(self, detail):
- pass
- #
- def down_trigger(self):
- if self.down_hook: self.down_hook(self)
- #
- def move_trigger(self):
- if self.move_hook: self.move_hook(self)
- #
- def up_trigger(self):
- if self.up_hook: self.up_hook(self)
- #
- def on_trigger(self):
- if self.on_hook: self.on_hook(self)
- #
- def off_trigger(self):
- if self.off_hook: self.off_hook(self)
- #
- def trigger(self):
- if self.hook: self.hook(self)
+ #
+ def init_reactivity(self):
+ self.down_hook = self.move_hook = self.up_hook = \
+ self.on_hook = self.off_hook = \
+ self.hook = self.active = 0
+ self.parent.need_mouse(self)
+ #
+ def mousetest(self, hv):
+ return _rect.pointinrect(hv, self.bounds)
+ #
+ def mouse_down(self, detail):
+ pass
+ #
+ def mouse_move(self, detail):
+ pass
+ #
+ def mouse_up(self, detail):
+ pass
+ #
+ def down_trigger(self):
+ if self.down_hook: self.down_hook(self)
+ #
+ def move_trigger(self):
+ if self.move_hook: self.move_hook(self)
+ #
+ def up_trigger(self):
+ if self.up_hook: self.up_hook(self)
+ #
+ def on_trigger(self):
+ if self.on_hook: self.on_hook(self)
+ #
+ def off_trigger(self):
+ if self.off_hook: self.off_hook(self)
+ #
+ def trigger(self):
+ if self.hook: self.hook(self)
# ToggleReactivity acts like a simple pushbutton.
# It toggles its hilite state on mouse down events.
#
class ToggleReactivity() = BaseReactivity():
- #
- def mouse_down(self, detail):
- if self.enabled and self.mousetest(detail[_HV]):
- self.active = 1
- self.hilite(not self.hilited)
- self.down_trigger()
- #
- def mouse_move(self, detail):
- if self.active:
- self.move_trigger()
- #
- def mouse_up(self, detail):
- if self.active:
- self.up_trigger()
- self.active = 0
- #
- def down_trigger(self):
- if self.hilited:
- self.on_trigger()
- else:
- self.off_trigger()
- self.trigger()
- #
+ #
+ def mouse_down(self, detail):
+ if self.enabled and self.mousetest(detail[_HV]):
+ self.active = 1
+ self.hilite(not self.hilited)
+ self.down_trigger()
+ #
+ def mouse_move(self, detail):
+ if self.active:
+ self.move_trigger()
+ #
+ def mouse_up(self, detail):
+ if self.active:
+ self.up_trigger()
+ self.active = 0
+ #
+ def down_trigger(self):
+ if self.hilited:
+ self.on_trigger()
+ else:
+ self.off_trigger()
+ self.trigger()
+ #
# TriggerReactivity acts like a fancy pushbutton.
# It hilites itself while the mouse is down within its bounds.
#
class TriggerReactivity() = BaseReactivity():
- #
- def mouse_down(self, detail):
- if self.enabled and self.mousetest(detail[_HV]):
- self.active = 1
- self.hilite(1)
- self.down_trigger()
- #
- def mouse_move(self, detail):
- if self.active:
- self.hilite(self.mousetest(detail[_HV]))
- if self.hilited:
- self.move_trigger()
- #
- def mouse_up(self, detail):
- if self.active:
- self.hilite(self.mousetest(detail[_HV]))
- if self.hilited:
- self.up_trigger()
- self.trigger()
- self.active = 0
- self.hilite(0)
- #
+ #
+ def mouse_down(self, detail):
+ if self.enabled and self.mousetest(detail[_HV]):
+ self.active = 1
+ self.hilite(1)
+ self.down_trigger()
+ #
+ def mouse_move(self, detail):
+ if self.active:
+ self.hilite(self.mousetest(detail[_HV]))
+ if self.hilited:
+ self.move_trigger()
+ #
+ def mouse_up(self, detail):
+ if self.active:
+ self.hilite(self.mousetest(detail[_HV]))
+ if self.hilited:
+ self.up_trigger()
+ self.trigger()
+ self.active = 0
+ self.hilite(0)
+ #
# CheckReactivity handles mouse events like TriggerReactivity,
# It overrides the up_trigger method to flip its selected state.
#
class CheckReactivity() = TriggerReactivity():
- #
- def up_trigger(self):
- self.select(not self.selected)
- if self.selected:
- self.on_trigger()
- else:
- self.off_trigger()
- self.trigger()
+ #
+ def up_trigger(self):
+ self.select(not self.selected)
+ if self.selected:
+ self.on_trigger()
+ else:
+ self.off_trigger()
+ self.trigger()
# RadioReactivity turns itself on and the other buttons in its group
# off when its up_trigger method is called.
#
class RadioReactivity() = TriggerReactivity():
- #
- def init_reactivity(self):
- TriggerReactivity.init_reactivity(self)
- self.group = []
- #
- def up_trigger(self):
- for b in self.group:
- if b <> self:
- if b.selected:
- b.select(0)
- b.off_trigger()
- self.select(1)
- self.on_trigger()
- self.trigger()
+ #
+ def init_reactivity(self):
+ TriggerReactivity.init_reactivity(self)
+ self.group = []
+ #
+ def up_trigger(self):
+ for b in self.group:
+ if b <> self:
+ if b.selected:
+ b.select(0)
+ b.off_trigger()
+ self.select(1)
+ self.on_trigger()
+ self.trigger()
# Auxiliary class for 'define' method.
# Call the initializers in the right order.
#
class Define():
- #
- def define(self, parent):
- self.parent = parent
- parent.addchild(self)
- self.init_appearance()
- self.init_reactivity()
- return self
- #
- def destroy(self):
- self.parent = 0
- #
- def definetext(self, (parent, text)):
- self = self.define(parent)
- self.settext(text)
- return self
+ #
+ def define(self, parent):
+ self.parent = parent
+ parent.addchild(self)
+ self.init_appearance()
+ self.init_reactivity()
+ return self
+ #
+ def destroy(self):
+ self.parent = 0
+ #
+ def definetext(self, (parent, text)):
+ self = self.define(parent)
+ self.settext(text)
+ return self
# Subroutine to cross out a rectangle.
#
def _xorcross(d, bounds):
- ((left, top), (right, bottom)) = bounds
- # This is s bit funny to make it look better
- left = left + 2
- right = right - 2
- top = top + 2
- bottom = bottom - 3
- d.xorline(((left, top), (right, bottom)))
- d.xorline((left, bottom), (right, top))
+ ((left, top), (right, bottom)) = bounds
+ # This is s bit funny to make it look better
+ left = left + 2
+ right = right - 2
+ top = top + 2
+ bottom = bottom - 3
+ d.xorline(((left, top), (right, bottom)))
+ d.xorline((left, bottom), (right, top))
# Ready-made button classes.
diff --git a/lib/CSplit.py b/lib/CSplit.py
index a28b1c8..03559c1 100644
--- a/lib/CSplit.py
+++ b/lib/CSplit.py
@@ -1,70 +1,70 @@
# A CSplit is a Clock-shaped split: the children are grouped in a circle.
# The numbering is a little different from a real clock: the 12 o'clock
-# position is called 0, not 12. This is a little easier since Python
-# usually counts from zero. (BTW, there needn't be exactly 12 children.)
+# position is called 0, not 12. This is a little easier since Python
+# usually counts from zero. (BTW, there needn't be exactly 12 children.)
from math import pi, sin, cos
from Split import Split
class CSplit() = Split():
- #
- def minsize(self, m):
- # Since things look best if the children are spaced evenly
- # along the circle (and often all children have the same
- # size anyway) we compute the max child size and assume
- # this is each child's size.
- width, height = 0, 0
- for child in self.children:
- wi, he = child.minsize(m)
- width = max(width, wi)
- height = max(height, he)
- # In approximation, the diameter of the circle we need is
- # (diameter of box) * (#children) / pi.
- # We approximate pi by 3 (so we slightly overestimate
- # our minimal size requirements -- not so bad).
- # Because the boxes stick out of the circle we add the
- # box size to each dimension.
- # Because we really deal with ellipses, do everything
- # separate in each dimension.
- n = len(self.children)
- return width + (width*n + 2)/3, height + (height*n + 2)/3
- #
- def getbounds(self):
- return self.bounds
- #
- def setbounds(self, bounds):
- self.bounds = bounds
- # Place the children. This involves some math.
- # Compute center positions for children as if they were
- # ellipses with a diameter about 1/N times the
- # circumference of the big ellipse.
- # (There is some rounding involved to make it look
- # reasonable for small and large N alike.)
- # XXX One day Python will have automatic conversions...
- n = len(self.children)
- fn = float(n)
- if n = 0: return
- (left, top), (right, bottom) = bounds
- width, height = right-left, bottom-top
- child_width, child_height = width*3/(n+4), height*3/(n+4)
- half_width, half_height = \
- float(width-child_width)/2.0, \
- float(height-child_height)/2.0
- center_h, center_v = center = (left+right)/2, (top+bottom)/2
- fch, fcv = float(center_h), float(center_v)
- alpha = 2.0 * pi / fn
- for i in range(n):
- child = self.children[i]
- fi = float(i)
- fh, fv = \
- fch + half_width*sin(fi*alpha), \
- fcv - half_height*cos(fi*alpha)
- left, top = \
- int(fh) - child_width/2, \
- int(fv) - child_height/2
- right, bottom = \
- left + child_width, \
- top + child_height
- child.setbounds((left, top), (right, bottom))
- #
+ #
+ def minsize(self, m):
+ # Since things look best if the children are spaced evenly
+ # along the circle (and often all children have the same
+ # size anyway) we compute the max child size and assume
+ # this is each child's size.
+ width, height = 0, 0
+ for child in self.children:
+ wi, he = child.minsize(m)
+ width = max(width, wi)
+ height = max(height, he)
+ # In approximation, the diameter of the circle we need is
+ # (diameter of box) * (#children) / pi.
+ # We approximate pi by 3 (so we slightly overestimate
+ # our minimal size requirements -- not so bad).
+ # Because the boxes stick out of the circle we add the
+ # box size to each dimension.
+ # Because we really deal with ellipses, do everything
+ # separate in each dimension.
+ n = len(self.children)
+ return width + (width*n + 2)/3, height + (height*n + 2)/3
+ #
+ def getbounds(self):
+ return self.bounds
+ #
+ def setbounds(self, bounds):
+ self.bounds = bounds
+ # Place the children. This involves some math.
+ # Compute center positions for children as if they were
+ # ellipses with a diameter about 1/N times the
+ # circumference of the big ellipse.
+ # (There is some rounding involved to make it look
+ # reasonable for small and large N alike.)
+ # XXX One day Python will have automatic conversions...
+ n = len(self.children)
+ fn = float(n)
+ if n = 0: return
+ (left, top), (right, bottom) = bounds
+ width, height = right-left, bottom-top
+ child_width, child_height = width*3/(n+4), height*3/(n+4)
+ half_width, half_height = \
+ float(width-child_width)/2.0, \
+ float(height-child_height)/2.0
+ center_h, center_v = center = (left+right)/2, (top+bottom)/2
+ fch, fcv = float(center_h), float(center_v)
+ alpha = 2.0 * pi / fn
+ for i in range(n):
+ child = self.children[i]
+ fi = float(i)
+ fh, fv = \
+ fch + half_width*sin(fi*alpha), \
+ fcv - half_height*cos(fi*alpha)
+ left, top = \
+ int(fh) - child_width/2, \
+ int(fv) - child_height/2
+ right, bottom = \
+ left + child_width, \
+ top + child_height
+ child.setbounds((left, top), (right, bottom))
+ #
diff --git a/lib/DEVICE.py b/lib/DEVICE.py
index 4f2fadc..00eddfc 100644
--- a/lib/DEVICE.py
+++ b/lib/DEVICE.py
@@ -1,17 +1,17 @@
#/**************************************************************************
-# * *
-# * Copyright (C) 1984, Silicon Graphics, Inc. *
-# * *
-# * These coded instructions, statements, and computer programs contain *
-# * unpublished proprietary information of Silicon Graphics, Inc., and *
-# * are protected by Federal copyright law. They may not be disclosed *
-# * to third parties or copied or duplicated in any form, in whole or *
-# * in part, without the prior written consent of Silicon Graphics, Inc. *
-# * *
+# * *
+# * Copyright (C) 1984, Silicon Graphics, Inc. *
+# * *
+# * These coded instructions, statements, and computer programs contain *
+# * unpublished proprietary information of Silicon Graphics, Inc., and *
+# * are protected by Federal copyright law. They may not be disclosed *
+# * to third parties or copied or duplicated in any form, in whole or *
+# * in part, without the prior written consent of Silicon Graphics, Inc. *
+# * *
# **************************************************************************/
#/* file with device definitions (see /usr/include/device.h) */
-NULLDEV = 0
+NULLDEV = 0
BUTOFFSET = 1
VALOFFSET = 256
TIMOFFSET = 515
@@ -22,402 +22,402 @@ BUTCOUNT = 190
VALCOUNT = 27
TIMCOUNT = 4
XKBDCOUNT = 28
-INCOUNT = 8
+INCOUNT = 8
OUTCOUNT = 8
#
#
#
#
-BUT0 = 1
-BUT1 = 2
-BUT2 = 3
-BUT3 = 4
-BUT4 = 5
-BUT5 = 6
-BUT6 = 7
-BUT7 = 8
-BUT8 = 9
-BUT9 = 10
-BUT10 = 11
-BUT11 = 12
-BUT12 = 13
-BUT13 = 14
-BUT14 = 15
-BUT15 = 16
-BUT16 = 17
-BUT17 = 18
-BUT18 = 19
-BUT19 = 20
-BUT20 = 21
-BUT21 = 22
-BUT22 = 23
-BUT23 = 24
-BUT24 = 25
-BUT25 = 26
-BUT26 = 27
-BUT27 = 28
-BUT28 = 29
-BUT29 = 30
-BUT30 = 31
-BUT31 = 32
-BUT32 = 33
-BUT33 = 34
-BUT34 = 35
-BUT35 = 36
-BUT36 = 37
-BUT37 = 38
-BUT38 = 39
-BUT39 = 40
-BUT40 = 41
-BUT41 = 42
-BUT42 = 43
-BUT43 = 44
-BUT44 = 45
-BUT45 = 46
-BUT46 = 47
-BUT47 = 48
-BUT48 = 49
-BUT49 = 50
-BUT50 = 51
-BUT51 = 52
-BUT52 = 53
-BUT53 = 54
-BUT54 = 55
-BUT55 = 56
-BUT56 = 57
-BUT57 = 58
-BUT58 = 59
-BUT59 = 60
-BUT60 = 61
-BUT61 = 62
-BUT62 = 63
-BUT63 = 64
-BUT64 = 65
-BUT65 = 66
-BUT66 = 67
-BUT67 = 68
-BUT68 = 69
-BUT69 = 70
-BUT70 = 71
-BUT71 = 72
-BUT72 = 73
-BUT73 = 74
-BUT74 = 75
-BUT75 = 76
-BUT76 = 77
-BUT77 = 78
-BUT78 = 79
-BUT79 = 80
-BUT80 = 81
-BUT81 = 82
-BUT82 = 83
-MAXKBDBUT = 83
-BUT100 = 101
-BUT101 = 102
-BUT102 = 103
-BUT110 = 111
-BUT111 = 112
-BUT112 = 113
-BUT113 = 114
-BUT114 = 115
-BUT115 = 116
-BUT116 = 117
-BUT117 = 118
-BUT118 = 119
-BUT119 = 120
-BUT120 = 121
-BUT121 = 122
-BUT122 = 123
-BUT123 = 124
-BUT124 = 125
-BUT125 = 126
-BUT126 = 127
-BUT127 = 128
-BUT128 = 129
-BUT129 = 130
-BUT130 = 131
-BUT131 = 132
-BUT132 = 133
-BUT133 = 134
-BUT134 = 135
-BUT135 = 136
-BUT136 = 137
-BUT137 = 138
-BUT138 = 139
-BUT139 = 140
-BUT140 = 141
-BUT141 = 142
-BUT142 = 143
-BUT143 = 144
-BUT144 = 145
-BUT145 = 146
-BUT146 = 147
-BUT147 = 148
-BUT148 = 149
-BUT149 = 150
-BUT150 = 151
-BUT151 = 152
-BUT152 = 153
-BUT153 = 154
-BUT154 = 155
-BUT155 = 156
-BUT156 = 157
-BUT157 = 158
-BUT158 = 159
-BUT159 = 160
-BUT160 = 161
-BUT161 = 162
-BUT162 = 163
-BUT163 = 164
-BUT164 = 165
-BUT165 = 166
-BUT166 = 167
-BUT167 = 168
-BUT168 = 169
-BUT181 = 182
-BUT182 = 183
-BUT183 = 184
-BUT184 = 185
-BUT185 = 186
-BUT186 = 187
-BUT187 = 188
-BUT188 = 189
-BUT189 = 190
-MOUSE1 = 101
-MOUSE2 = 102
-MOUSE3 = 103
-LEFTMOUSE = 103
-MIDDLEMOUSE = 102
-RIGHTMOUSE = 101
-LPENBUT = 104
-BPAD0 = 105
-BPAD1 = 106
-BPAD2 = 107
-BPAD3 = 108
-LPENVALID = 109
-SWBASE = 111
-SW0 = 111
-SW1 = 112
-SW2 = 113
-SW3 = 114
-SW4 = 115
-SW5 = 116
-SW6 = 117
-SW7 = 118
-SW8 = 119
-SW9 = 120
-SW10 = 121
-SW11 = 122
-SW12 = 123
-SW13 = 124
-SW14 = 125
-SW15 = 126
-SW16 = 127
-SW17 = 128
-SW18 = 129
-SW19 = 130
-SW20 = 131
-SW21 = 132
-SW22 = 133
-SW23 = 134
-SW24 = 135
-SW25 = 136
-SW26 = 137
-SW27 = 138
-SW28 = 139
-SW29 = 140
-SW30 = 141
-SW31 = 142
-SBBASE = 182
-SBPICK = 182
-SBBUT1 = 183
-SBBUT2 = 184
-SBBUT3 = 185
-SBBUT4 = 186
-SBBUT5 = 187
-SBBUT6 = 188
-SBBUT7 = 189
-SBBUT8 = 190
-AKEY = 11
-BKEY = 36
-CKEY = 28
-DKEY = 18
-EKEY = 17
-FKEY = 19
-GKEY = 26
-HKEY = 27
-IKEY = 40
-JKEY = 34
-KKEY = 35
-LKEY = 42
-MKEY = 44
-NKEY = 37
-OKEY = 41
-PKEY = 48
-QKEY = 10
-RKEY = 24
-SKEY = 12
-TKEY = 25
-UKEY = 33
-VKEY = 29
-WKEY = 16
-XKEY = 21
-YKEY = 32
-ZKEY = 20
-ZEROKEY = 46
-ONEKEY = 8
-TWOKEY = 14
-THREEKEY = 15
-FOURKEY = 22
-FIVEKEY = 23
-SIXKEY = 30
-SEVENKEY = 31
-EIGHTKEY = 38
-NINEKEY = 39
-BREAKKEY = 1
-SETUPKEY = 2
-CTRLKEY = 3
-LEFTCTRLKEY = CTRLKEY
-CAPSLOCKKEY = 4
-RIGHTSHIFTKEY = 5
-LEFTSHIFTKEY = 6
-NOSCRLKEY = 13
-ESCKEY = 7
-TABKEY = 9
-RETKEY = 51
-SPACEKEY = 83
-LINEFEEDKEY = 60
-BACKSPACEKEY = 61
-DELKEY = 62
-SEMICOLONKEY = 43
-PERIODKEY = 52
-COMMAKEY = 45
-QUOTEKEY = 50
-ACCENTGRAVEKEY = 55
-MINUSKEY = 47
-VIRGULEKEY = 53
-BACKSLASHKEY = 57
-EQUALKEY = 54
-LEFTBRACKETKEY = 49
-RIGHTBRACKETKEY = 56
-LEFTARROWKEY = 73
-DOWNARROWKEY = 74
-RIGHTARROWKEY = 80
-UPARROWKEY = 81
-PAD0 = 59
-PAD1 = 58
-PAD2 = 64
-PAD3 = 65
-PAD4 = 63
-PAD5 = 69
-PAD6 = 70
-PAD7 = 67
-PAD8 = 68
-PAD9 = 75
-PADPF1 = 72
-PADPF2 = 71
-PADPF3 = 79
-PADPF4 = 78
-PADPERIOD = 66
-PADMINUS = 76
-PADCOMMA = 77
-PADENTER = 82
-LEFTALTKEY = 143
-RIGHTALTKEY = 144
-RIGHTCTRLKEY = 145
-F1KEY = 146
-F2KEY = 147
-F3KEY = 148
-F4KEY = 149
-F5KEY = 150
-F6KEY = 151
-F7KEY = 152
-F8KEY = 153
-F9KEY = 154
-F10KEY = 155
-F11KEY = 156
-F12KEY = 157
+BUT0 = 1
+BUT1 = 2
+BUT2 = 3
+BUT3 = 4
+BUT4 = 5
+BUT5 = 6
+BUT6 = 7
+BUT7 = 8
+BUT8 = 9
+BUT9 = 10
+BUT10 = 11
+BUT11 = 12
+BUT12 = 13
+BUT13 = 14
+BUT14 = 15
+BUT15 = 16
+BUT16 = 17
+BUT17 = 18
+BUT18 = 19
+BUT19 = 20
+BUT20 = 21
+BUT21 = 22
+BUT22 = 23
+BUT23 = 24
+BUT24 = 25
+BUT25 = 26
+BUT26 = 27
+BUT27 = 28
+BUT28 = 29
+BUT29 = 30
+BUT30 = 31
+BUT31 = 32
+BUT32 = 33
+BUT33 = 34
+BUT34 = 35
+BUT35 = 36
+BUT36 = 37
+BUT37 = 38
+BUT38 = 39
+BUT39 = 40
+BUT40 = 41
+BUT41 = 42
+BUT42 = 43
+BUT43 = 44
+BUT44 = 45
+BUT45 = 46
+BUT46 = 47
+BUT47 = 48
+BUT48 = 49
+BUT49 = 50
+BUT50 = 51
+BUT51 = 52
+BUT52 = 53
+BUT53 = 54
+BUT54 = 55
+BUT55 = 56
+BUT56 = 57
+BUT57 = 58
+BUT58 = 59
+BUT59 = 60
+BUT60 = 61
+BUT61 = 62
+BUT62 = 63
+BUT63 = 64
+BUT64 = 65
+BUT65 = 66
+BUT66 = 67
+BUT67 = 68
+BUT68 = 69
+BUT69 = 70
+BUT70 = 71
+BUT71 = 72
+BUT72 = 73
+BUT73 = 74
+BUT74 = 75
+BUT75 = 76
+BUT76 = 77
+BUT77 = 78
+BUT78 = 79
+BUT79 = 80
+BUT80 = 81
+BUT81 = 82
+BUT82 = 83
+MAXKBDBUT = 83
+BUT100 = 101
+BUT101 = 102
+BUT102 = 103
+BUT110 = 111
+BUT111 = 112
+BUT112 = 113
+BUT113 = 114
+BUT114 = 115
+BUT115 = 116
+BUT116 = 117
+BUT117 = 118
+BUT118 = 119
+BUT119 = 120
+BUT120 = 121
+BUT121 = 122
+BUT122 = 123
+BUT123 = 124
+BUT124 = 125
+BUT125 = 126
+BUT126 = 127
+BUT127 = 128
+BUT128 = 129
+BUT129 = 130
+BUT130 = 131
+BUT131 = 132
+BUT132 = 133
+BUT133 = 134
+BUT134 = 135
+BUT135 = 136
+BUT136 = 137
+BUT137 = 138
+BUT138 = 139
+BUT139 = 140
+BUT140 = 141
+BUT141 = 142
+BUT142 = 143
+BUT143 = 144
+BUT144 = 145
+BUT145 = 146
+BUT146 = 147
+BUT147 = 148
+BUT148 = 149
+BUT149 = 150
+BUT150 = 151
+BUT151 = 152
+BUT152 = 153
+BUT153 = 154
+BUT154 = 155
+BUT155 = 156
+BUT156 = 157
+BUT157 = 158
+BUT158 = 159
+BUT159 = 160
+BUT160 = 161
+BUT161 = 162
+BUT162 = 163
+BUT163 = 164
+BUT164 = 165
+BUT165 = 166
+BUT166 = 167
+BUT167 = 168
+BUT168 = 169
+BUT181 = 182
+BUT182 = 183
+BUT183 = 184
+BUT184 = 185
+BUT185 = 186
+BUT186 = 187
+BUT187 = 188
+BUT188 = 189
+BUT189 = 190
+MOUSE1 = 101
+MOUSE2 = 102
+MOUSE3 = 103
+LEFTMOUSE = 103
+MIDDLEMOUSE = 102
+RIGHTMOUSE = 101
+LPENBUT = 104
+BPAD0 = 105
+BPAD1 = 106
+BPAD2 = 107
+BPAD3 = 108
+LPENVALID = 109
+SWBASE = 111
+SW0 = 111
+SW1 = 112
+SW2 = 113
+SW3 = 114
+SW4 = 115
+SW5 = 116
+SW6 = 117
+SW7 = 118
+SW8 = 119
+SW9 = 120
+SW10 = 121
+SW11 = 122
+SW12 = 123
+SW13 = 124
+SW14 = 125
+SW15 = 126
+SW16 = 127
+SW17 = 128
+SW18 = 129
+SW19 = 130
+SW20 = 131
+SW21 = 132
+SW22 = 133
+SW23 = 134
+SW24 = 135
+SW25 = 136
+SW26 = 137
+SW27 = 138
+SW28 = 139
+SW29 = 140
+SW30 = 141
+SW31 = 142
+SBBASE = 182
+SBPICK = 182
+SBBUT1 = 183
+SBBUT2 = 184
+SBBUT3 = 185
+SBBUT4 = 186
+SBBUT5 = 187
+SBBUT6 = 188
+SBBUT7 = 189
+SBBUT8 = 190
+AKEY = 11
+BKEY = 36
+CKEY = 28
+DKEY = 18
+EKEY = 17
+FKEY = 19
+GKEY = 26
+HKEY = 27
+IKEY = 40
+JKEY = 34
+KKEY = 35
+LKEY = 42
+MKEY = 44
+NKEY = 37
+OKEY = 41
+PKEY = 48
+QKEY = 10
+RKEY = 24
+SKEY = 12
+TKEY = 25
+UKEY = 33
+VKEY = 29
+WKEY = 16
+XKEY = 21
+YKEY = 32
+ZKEY = 20
+ZEROKEY = 46
+ONEKEY = 8
+TWOKEY = 14
+THREEKEY = 15
+FOURKEY = 22
+FIVEKEY = 23
+SIXKEY = 30
+SEVENKEY = 31
+EIGHTKEY = 38
+NINEKEY = 39
+BREAKKEY = 1
+SETUPKEY = 2
+CTRLKEY = 3
+LEFTCTRLKEY = CTRLKEY
+CAPSLOCKKEY = 4
+RIGHTSHIFTKEY = 5
+LEFTSHIFTKEY = 6
+NOSCRLKEY = 13
+ESCKEY = 7
+TABKEY = 9
+RETKEY = 51
+SPACEKEY = 83
+LINEFEEDKEY = 60
+BACKSPACEKEY = 61
+DELKEY = 62
+SEMICOLONKEY = 43
+PERIODKEY = 52
+COMMAKEY = 45
+QUOTEKEY = 50
+ACCENTGRAVEKEY = 55
+MINUSKEY = 47
+VIRGULEKEY = 53
+BACKSLASHKEY = 57
+EQUALKEY = 54
+LEFTBRACKETKEY = 49
+RIGHTBRACKETKEY = 56
+LEFTARROWKEY = 73
+DOWNARROWKEY = 74
+RIGHTARROWKEY = 80
+UPARROWKEY = 81
+PAD0 = 59
+PAD1 = 58
+PAD2 = 64
+PAD3 = 65
+PAD4 = 63
+PAD5 = 69
+PAD6 = 70
+PAD7 = 67
+PAD8 = 68
+PAD9 = 75
+PADPF1 = 72
+PADPF2 = 71
+PADPF3 = 79
+PADPF4 = 78
+PADPERIOD = 66
+PADMINUS = 76
+PADCOMMA = 77
+PADENTER = 82
+LEFTALTKEY = 143
+RIGHTALTKEY = 144
+RIGHTCTRLKEY = 145
+F1KEY = 146
+F2KEY = 147
+F3KEY = 148
+F4KEY = 149
+F5KEY = 150
+F6KEY = 151
+F7KEY = 152
+F8KEY = 153
+F9KEY = 154
+F10KEY = 155
+F11KEY = 156
+F12KEY = 157
PRINTSCREENKEY = 158
SCROLLLOCKKEY = 159
PAUSEKEY = 160
INSERTKEY = 161
-HOMEKEY = 162
-PAGEUPKEY = 163
-ENDKEY = 164
+HOMEKEY = 162
+PAGEUPKEY = 163
+ENDKEY = 164
PAGEDOWNKEY = 165
NUMLOCKKEY = 166
-PADVIRGULEKEY = 167
-PADASTERKEY = 168
-PADPLUSKEY = 169
-SGIRESERVED = 256
-DIAL0 = 257
-DIAL1 = 258
-DIAL2 = 259
-DIAL3 = 260
-DIAL4 = 261
-DIAL5 = 262
-DIAL6 = 263
-DIAL7 = 264
-DIAL8 = 265
-MOUSEX = 266
-MOUSEY = 267
-LPENX = 268
-LPENY = 269
-BPADX = 270
-BPADY = 271
-CURSORX = 272
-CURSORY = 273
-GHOSTX = 274
-GHOSTY = 275
-SBTX = 276
-SBTY = 277
-SBTZ = 278
-SBRX = 279
-SBRY = 280
-SBRZ = 281
-SBPERIOD = 282
-TIMER0 = 515
-TIMER1 = 516
-TIMER2 = 517
-TIMER3 = 518
-KEYBD = 513
-RAWKEYBD = 514
-VALMARK = 523
-GERROR = 524
-REDRAW = 528
-WMSEND = 529
-WMREPLY = 530
-WMGFCLOSE = 531
-WMTXCLOSE = 532
-MODECHANGE = 533
-INPUTCHANGE = 534
-QFULL = 535
-PIECECHANGE = 536
-WINCLOSE = 537
-QREADERROR = 538
-WINFREEZE = 539
-WINTHAW = 540
-REDRAWICONIC = 541
-WINQUIT = 542
-DEPTHCHANGE = 543
-KEYBDFNAMES = 544
-KEYBDFSTRINGS = 545
-WINSHUT = 546
-INPUT0 = 1024
-INPUT1 = 1025
-INPUT2 = 1026
-INPUT3 = 1027
-INPUT4 = 1028
-INPUT5 = 1029
-INPUT6 = 1030
-INPUT7 = 1032
-OUTPUT0 = 1033
-OUTPUT1 = 1034
-OUTPUT2 = 1035
-OUTPUT3 = 1036
-OUTPUT4 = 1037
-OUTPUT5 = 1038
-OUTPUT6 = 1039
-OUTPUT7 = 1040
+PADVIRGULEKEY = 167
+PADASTERKEY = 168
+PADPLUSKEY = 169
+SGIRESERVED = 256
+DIAL0 = 257
+DIAL1 = 258
+DIAL2 = 259
+DIAL3 = 260
+DIAL4 = 261
+DIAL5 = 262
+DIAL6 = 263
+DIAL7 = 264
+DIAL8 = 265
+MOUSEX = 266
+MOUSEY = 267
+LPENX = 268
+LPENY = 269
+BPADX = 270
+BPADY = 271
+CURSORX = 272
+CURSORY = 273
+GHOSTX = 274
+GHOSTY = 275
+SBTX = 276
+SBTY = 277
+SBTZ = 278
+SBRX = 279
+SBRY = 280
+SBRZ = 281
+SBPERIOD = 282
+TIMER0 = 515
+TIMER1 = 516
+TIMER2 = 517
+TIMER3 = 518
+KEYBD = 513
+RAWKEYBD = 514
+VALMARK = 523
+GERROR = 524
+REDRAW = 528
+WMSEND = 529
+WMREPLY = 530
+WMGFCLOSE = 531
+WMTXCLOSE = 532
+MODECHANGE = 533
+INPUTCHANGE = 534
+QFULL = 535
+PIECECHANGE = 536
+WINCLOSE = 537
+QREADERROR = 538
+WINFREEZE = 539
+WINTHAW = 540
+REDRAWICONIC = 541
+WINQUIT = 542
+DEPTHCHANGE = 543
+KEYBDFNAMES = 544
+KEYBDFSTRINGS = 545
+WINSHUT = 546
+INPUT0 = 1024
+INPUT1 = 1025
+INPUT2 = 1026
+INPUT3 = 1027
+INPUT4 = 1028
+INPUT5 = 1029
+INPUT6 = 1030
+INPUT7 = 1032
+OUTPUT0 = 1033
+OUTPUT1 = 1034
+OUTPUT2 = 1035
+OUTPUT3 = 1036
+OUTPUT4 = 1037
+OUTPUT5 = 1038
+OUTPUT6 = 1039
+OUTPUT7 = 1040
MAXSGIDEVICE = 20000
-MENUBUTTON = RIGHTMOUSE
+MENUBUTTON = RIGHTMOUSE
diff --git a/lib/GL.py b/lib/GL.py
index b733e51..35487a7 100644
--- a/lib/GL.py
+++ b/lib/GL.py
@@ -1,15 +1,15 @@
# Constants defined in <gl.h>
#**************************************************************************
-#* *
-#* Copyright (C) 1984, Silicon Graphics, Inc. *
-#* *
-#* These coded instructions, statements, and computer programs contain *
-#* unpublished proprietary information of Silicon Graphics, Inc., and *
-#* are protected by Federal copyright law. They may not be disclosed *
-#* to third parties or copied or duplicated in any form, in whole or *
-#* in part, without the prior written consent of Silicon Graphics, Inc. *
-#* *
+#* *
+#* Copyright (C) 1984, Silicon Graphics, Inc. *
+#* *
+#* These coded instructions, statements, and computer programs contain *
+#* unpublished proprietary information of Silicon Graphics, Inc., and *
+#* are protected by Federal copyright law. They may not be disclosed *
+#* to third parties or copied or duplicated in any form, in whole or *
+#* in part, without the prior written consent of Silicon Graphics, Inc. *
+#* *
#**************************************************************************
# Graphics Libary constants
@@ -18,17 +18,17 @@
TRUE = 1
FALSE = 0
-# maximum X and Y screen coordinates
+# maximum X and Y screen coordinates
XMAXSCREEN = 1279
YMAXSCREEN = 1023
-XMAXMEDIUM = 1023 # max for medium res monitor
+XMAXMEDIUM = 1023 # max for medium res monitor
YMAXMEDIUM = 767
-XMAX170 = 645 # max for RS-170
+XMAX170 = 645 # max for RS-170
YMAX170 = 484
-XMAXPAL = 779 # max for PAL
+XMAXPAL = 779 # max for PAL
YMAXPAL = 574
-# various hardware/software limits
+# various hardware/software limits
ATTRIBSTACKDEPTH = 10
VPSTACKDEPTH = 8
MATRIXSTACKDEPTH = 32
@@ -37,7 +37,7 @@ STARTTAG = -2
ENDTAG = -3
CPOSX_INVALID = -(2*XMAXSCREEN)
-# names for colors in color map loaded by greset
+# names for colors in color map loaded by greset
BLACK = 0
RED = 1
GREEN = 2
@@ -47,20 +47,20 @@ MAGENTA = 5
CYAN = 6
WHITE = 7
-# popup colors
+# popup colors
PUP_CLEAR = 0
PUP_COLOR = 1
PUP_BLACK = 2
PUP_WHITE = 3
-# defines for drawmode
+# defines for drawmode
NORMALDRAW = 0
PUPDRAW = 1
OVERDRAW = 2
UNDERDRAW = 3
CURSORDRAW = 4
-# defines for defpattern
+# defines for defpattern
PATTERN_16 = 16
PATTERN_32 = 32
PATTERN_64 = 64
@@ -69,7 +69,7 @@ PATTERN_16_SIZE = 16
PATTERN_32_SIZE = 64
PATTERN_64_SIZE = 256
-# defines for readsource
+# defines for readsource
SRC_AUTO = 0
SRC_FRONT = 1
SRC_BACK = 2
@@ -79,7 +79,7 @@ SRC_OVER = 5
SRC_UNDER = 6
SRC_FRAMEGRABBER = 7
-# defines for blendfunction
+# defines for blendfunction
BF_ZERO = 0
BF_ONE = 1
BF_DC = 2
@@ -91,7 +91,7 @@ BF_MSA = 5
BF_DA = 6
BF_MDA = 7
-# defines for zfunction
+# defines for zfunction
ZF_NEVER = 0
ZF_LESS = 1
ZF_EQUAL = 2
@@ -101,38 +101,38 @@ ZF_NOTEQUAL = 5
ZF_GEQUAL = 6
ZF_ALWAYS = 7
-# defines for zsource
+# defines for zsource
ZSRC_DEPTH = 0
ZSRC_COLOR = 1
-# defines for pntsmooth
+# defines for pntsmooth
SMP_OFF = 0
SMP_ON = 1
-# defines for linesmooth
+# defines for linesmooth
SML_OFF = 0
SML_ON = 1
-# defines for setpup
+# defines for setpup
PUP_NONE = 0
PUP_GREY = 1
-# defines for glcompat
+# defines for glcompat
GLC_OLDPOLYGON = 0
GLC_ZRANGEMAP = 1
-# defines for curstype
+# defines for curstype
C16X1 = 0
C16X2 = 1
C32X1 = 2
C32X2 = 3
CCROSS = 4
-# defines for shademodel
+# defines for shademodel
FLAT = 0
GOURAUD = 1
-# defines for logicop
+# defines for logicop
### LO_ZERO = 0x0
### LO_AND = 0x1
### LO_ANDR = 0x2
@@ -152,7 +152,7 @@ GOURAUD = 1
#
-# START defines for getgdesc
+# START defines for getgdesc
#
GD_XPMAX = 0
@@ -175,7 +175,7 @@ GD_BITS_NORM_ZBUFFER = 16
GD_BITS_OVER_SNG_CMODE = 17
GD_BITS_UNDR_SNG_CMODE = 18
GD_BITS_PUP_SNG_CMODE = 19
-GD_BITS_NORM_SNG_ALPHA = 21
+GD_BITS_NORM_SNG_ALPHA = 21
GD_BITS_NORM_DBL_ALPHA = 22
GD_BITS_CURSOR = 23
GD_OVERUNDER_SHARED = 24
@@ -234,16 +234,16 @@ GD_WSYS_4S = 1
GD_SCRNTYPE_WM = 0
GD_SCRNTYPE_NOWM = 1
-#
-# END defines for getgdesc
+#
+# END defines for getgdesc
#
-#
-# START NURBS interface definitions
+#
+# START NURBS interface definitions
#
-# NURBS Rendering Properties
+# NURBS Rendering Properties
N_PIXEL_TOLERANCE = 1
N_CULLING = 2
N_DISPLAY = 3
@@ -253,59 +253,59 @@ N_S_STEPS = 6
N_T_STEPS = 7
N_TILES = 8
-N_SHADED = 1.0
+N_SHADED = 1.0
# ---------------------------------------------------------------------------
-# FLAGS FOR NURBS SURFACES AND CURVES
-#
-# Bit: 9876 5432 1 0
-# |tttt|nnnn|f|r| : r - 1 bit = 1 if rational coordinate exists
-# : f - 1 bit = 1 if rational coordinate is before rest
-# : = 0 if rational coordinate is after rest
-# : nnnn - 4 bits for number of coordinates
-# : tttt - 4 bits for type of data (color, position, etc.)
-#
+# FLAGS FOR NURBS SURFACES AND CURVES
+#
+# Bit: 9876 5432 1 0
+# |tttt|nnnn|f|r| : r - 1 bit = 1 if rational coordinate exists
+# : f - 1 bit = 1 if rational coordinate is before rest
+# : = 0 if rational coordinate is after rest
+# : nnnn - 4 bits for number of coordinates
+# : tttt - 4 bits for type of data (color, position, etc.)
+#
# NURBS data type
-# N_T_ST 0 parametric space data
-# N_T_XYZ 1 model space data
-#
-# rational or non-rational data and position in memory
-# N_NONRATIONAL 0 non-rational data
-# N_RATAFTER 1 rational data with rat coord after rest
-# N_RATBEFORE 3 rational data with rat coord before rest
-#
+# N_T_ST 0 parametric space data
+# N_T_XYZ 1 model space data
+#
+# rational or non-rational data and position in memory
+# N_NONRATIONAL 0 non-rational data
+# N_RATAFTER 1 rational data with rat coord after rest
+# N_RATBEFORE 3 rational data with rat coord before rest
+#
# N_MKFLAG(a,b,c) ((a<<6) | (b<<2) | c)
-#
+#
# ---------------------------------------------------------------------------
-#
-N_ST = 0x8 # N_MKFLAG( N_T_ST, 2, N_NONRATIONAL )
-N_STW = 0xd # N_MKFLAG( N_T_ST, 3, N_RATAFTER )
-N_WST = 0xf # N_MKFLAG( N_T_ST, 3, N_RATBEFORE )
-N_XYZ = 0x4c # N_MKFLAG( N_T_XYZ, 3, N_NONRATIONAL )
-N_XYZW = 0x51 # N_MKFLAG( N_T_XYZ, 4, N_RATAFTER )
-N_WXYZ = 0x53 # N_MKFLAG( N_T_XYZ, 4, N_RATBEFORE )
+#
+N_ST = 0x8 # N_MKFLAG( N_T_ST, 2, N_NONRATIONAL )
+N_STW = 0xd # N_MKFLAG( N_T_ST, 3, N_RATAFTER )
+N_WST = 0xf # N_MKFLAG( N_T_ST, 3, N_RATBEFORE )
+N_XYZ = 0x4c # N_MKFLAG( N_T_XYZ, 3, N_NONRATIONAL )
+N_XYZW = 0x51 # N_MKFLAG( N_T_XYZ, 4, N_RATAFTER )
+N_WXYZ = 0x53 # N_MKFLAG( N_T_XYZ, 4, N_RATBEFORE )
-#
-# END NURBS interface definitions
-#
+#
+# END NURBS interface definitions
+#
-#
-# START lighting model defines
-#
+#
+# START lighting model defines
+#
LMNULL = 0.0
-# MATRIX modes
+# MATRIX modes
MSINGLE = 0
MPROJECTION = 1
MVIEWING = 2
-# LIGHT constants
+# LIGHT constants
MAXLIGHTS = 8
MAXRESTRICTIONS = 4
-# MATERIAL properties
+# MATERIAL properties
DEFMATERIAL = 0
EMISSION = 1
AMBIENT = 2
@@ -315,17 +315,17 @@ SHININESS = 5
COLORINDEXES = 6
ALPHA = 7
-# LIGHT properties
+# LIGHT properties
DEFLIGHT = 100
LCOLOR = 101
POSITION = 102
-# LIGHTINGMODEL properties
+# LIGHTINGMODEL properties
DEFLMODEL = 200
LOCALVIEWER = 201
ATTENUATION = 202
-# TARGET constants
+# TARGET constants
MATERIAL = 1000
LIGHT0 = 1100
LIGHT1 = 1101
@@ -337,7 +337,7 @@ LIGHT6 = 1106
LIGHT7 = 1107
LMODEL = 1200
-# lmcolor modes
+# lmcolor modes
LMC_COLOR = 0
LMC_EMISSION = 1
LMC_AMBIENT = 2
@@ -346,20 +346,20 @@ LMC_SPECULAR = 4
LMC_AD = 5
LMC_NULL = 6
-#
-# END lighting model defines
-#
+#
+# END lighting model defines
+#
-#
-# START distributed graphics library defines
-#
+#
+# START distributed graphics library defines
+#
-DGLSINK = 0 # sink connection
-DGLLOCAL = 1 # local connection
-DGLTSOCKET = 2 # tcp socket connection
-DGL4DDN = 3 # 4DDN (DECnet)
+DGLSINK = 0 # sink connection
+DGLLOCAL = 1 # local connection
+DGLTSOCKET = 2 # tcp socket connection
+DGL4DDN = 3 # 4DDN (DECnet)
-#
-# END distributed graphics library defines
-#
+#
+# END distributed graphics library defines
+#
diff --git a/lib/HVSplit.py b/lib/HVSplit.py
index d52af8e..36192a7 100644
--- a/lib/HVSplit.py
+++ b/lib/HVSplit.py
@@ -8,49 +8,49 @@
from Split import Split
class HVSplit() = Split():
- #
- def create(self, (parent, hv)):
- # hv is 0 or 1 for HSplit or VSplit
- self = Split.create(self, parent)
- self.hv = hv
- return self
- #
- def minsize(self, m):
- hv, vh = self.hv, 1 - self.hv
- size = [0, 0]
- for c in self.children:
- csize = c.minsize(m)
- if csize[vh] > size[vh]: size[vh] = csize[vh]
- size[hv] = size[hv] + csize[hv]
- return size[0], size[1]
- #
- def getbounds(self):
- return self.bounds
- #
- def setbounds(self, bounds):
- self.bounds = bounds
- hv, vh = self.hv, 1 - self.hv
- mf = self.parent.beginmeasuring
- size = self.minsize(mf())
- # XXX not yet used! Later for stretching
- maxsize_hv = bounds[1][hv] - bounds[0][hv]
- origin = [self.bounds[0][0], self.bounds[0][1]]
- for c in self.children:
- size = c.minsize(mf())
- corner = [0, 0]
- corner[vh] = bounds[1][vh]
- corner[hv] = origin[hv] + size[hv]
- c.setbounds((origin[0], origin[1]), \
- (corner[0], corner[1]))
- origin[hv] = corner[hv]
- # XXX stretch
- # XXX too-small
- #
+ #
+ def create(self, (parent, hv)):
+ # hv is 0 or 1 for HSplit or VSplit
+ self = Split.create(self, parent)
+ self.hv = hv
+ return self
+ #
+ def minsize(self, m):
+ hv, vh = self.hv, 1 - self.hv
+ size = [0, 0]
+ for c in self.children:
+ csize = c.minsize(m)
+ if csize[vh] > size[vh]: size[vh] = csize[vh]
+ size[hv] = size[hv] + csize[hv]
+ return size[0], size[1]
+ #
+ def getbounds(self):
+ return self.bounds
+ #
+ def setbounds(self, bounds):
+ self.bounds = bounds
+ hv, vh = self.hv, 1 - self.hv
+ mf = self.parent.beginmeasuring
+ size = self.minsize(mf())
+ # XXX not yet used! Later for stretching
+ maxsize_hv = bounds[1][hv] - bounds[0][hv]
+ origin = [self.bounds[0][0], self.bounds[0][1]]
+ for c in self.children:
+ size = c.minsize(mf())
+ corner = [0, 0]
+ corner[vh] = bounds[1][vh]
+ corner[hv] = origin[hv] + size[hv]
+ c.setbounds((origin[0], origin[1]), \
+ (corner[0], corner[1]))
+ origin[hv] = corner[hv]
+ # XXX stretch
+ # XXX too-small
+ #
class HSplit() = HVSplit():
- def create(self, parent):
- return HVSplit.create(self, (parent, 0))
+ def create(self, parent):
+ return HVSplit.create(self, (parent, 0))
class VSplit() = HVSplit():
- def create(self, parent):
- return HVSplit.create(self, (parent, 1))
+ def create(self, parent):
+ return HVSplit.create(self, (parent, 1))
diff --git a/lib/Histogram.py b/lib/Histogram.py
index 3f6da76..505bbaf 100644
--- a/lib/Histogram.py
+++ b/lib/Histogram.py
@@ -5,32 +5,32 @@ from Buttons import *
# A Histogram displays a histogram of numeric data.
#
class HistogramAppearance() = LabelAppearance(), Define():
- #
- def define(self, parent):
- Define.define(self, (parent, ''))
- self.ydata = []
- self.scale = (0, 100)
- return self
- #
- def setdata(self, (ydata, scale)):
- self.ydata = ydata
- self.scale = scale # (min, max)
- self.parent.change(self.bounds)
- #
- def drawpict(self, d):
- (left, top), (right, bottom) = self.bounds
- min, max = self.scale
- size = max-min
- width, height = right-left, bottom-top
- ydata = self.ydata
- npoints = len(ydata)
- v1 = top + height # constant
- h1 = left # changed in loop
- for i in range(npoints):
- h0 = h1
- v0 = top + height - (ydata[i]-min)*height/size
- h1 = left + (i+1) * width/npoints
- d.paint((h0, v0), (h1, v1))
- #
+ #
+ def define(self, parent):
+ Define.define(self, (parent, ''))
+ self.ydata = []
+ self.scale = (0, 100)
+ return self
+ #
+ def setdata(self, (ydata, scale)):
+ self.ydata = ydata
+ self.scale = scale # (min, max)
+ self.parent.change(self.bounds)
+ #
+ def drawpict(self, d):
+ (left, top), (right, bottom) = self.bounds
+ min, max = self.scale
+ size = max-min
+ width, height = right-left, bottom-top
+ ydata = self.ydata
+ npoints = len(ydata)
+ v1 = top + height # constant
+ h1 = left # changed in loop
+ for i in range(npoints):
+ h0 = h1
+ v0 = top + height - (ydata[i]-min)*height/size
+ h1 = left + (i+1) * width/npoints
+ d.paint((h0, v0), (h1, v1))
+ #
class Histogram() = NoReactivity(), HistogramAppearance(): pass
diff --git a/lib/Sliders.py b/lib/Sliders.py
index e44b466..f655e77 100644
--- a/lib/Sliders.py
+++ b/lib/Sliders.py
@@ -23,153 +23,153 @@ _MASK = 3
# but defines its own setval_trigger and setval_hook.
#
class DragSliderReactivity() = BaseReactivity():
- #
- def mouse_down(self, detail):
- h, v = hv = detail[_HV]
- if self.enabled and self.mousetest(hv):
- self.anchor = h
- self.oldval = self.val
- self.active = 1
- #
- def mouse_move(self, detail):
- if self.active:
- h, v = detail[_HV]
- self.setval(self.oldval + (h - self.anchor))
- #
- def mouse_up(self, detail):
- if self.active:
- h, v = detail[_HV]
- self.setval(self.oldval + (h - self.anchor))
- self.active = 0
- #
+ #
+ def mouse_down(self, detail):
+ h, v = hv = detail[_HV]
+ if self.enabled and self.mousetest(hv):
+ self.anchor = h
+ self.oldval = self.val
+ self.active = 1
+ #
+ def mouse_move(self, detail):
+ if self.active:
+ h, v = detail[_HV]
+ self.setval(self.oldval + (h - self.anchor))
+ #
+ def mouse_up(self, detail):
+ if self.active:
+ h, v = detail[_HV]
+ self.setval(self.oldval + (h - self.anchor))
+ self.active = 0
+ #
class DragSliderAppearance() = ButtonAppearance():
- #
- # INVARIANTS maintained by the setval method:
- #
- # self.min <= self.val <= self.max
- # self.text = self.pretext + `self.val` + self.postext
- #
- # (Notice that unlike Python ranges, the end point belongs
- # to the range.)
- #
- def init_appearance(self):
- ButtonAppearance.init_appearance(self)
- self.min = 0
- self.val = 0
- self.max = 100
- self.hook = 0
- self.pretext = self.postext = ''
- self.recalctext()
- #
- # The 'get*' and 'set*' methods belong to the generic slider interface
- #
- def getval(self): return self.val
- #
- def sethook(self, hook):
- self.hook = hook
- #
- def setminvalmax(self, (min, val, max)):
- self.min = min
- self.max = max
- self.setval(val)
- #
- def settexts(self, (pretext, postext)):
- self.pretext = pretext
- self.postext = postext
- self.recalctext()
- #
- def setval(self, val):
- val = min(self.max, max(self.min, val))
- if val <> self.val:
- self.val = val
- self.recalctext()
- self.trigger()
- #
- def trigger(self):
- if self.hook:
- self.hook(self)
- #
- def recalctext(self):
- self.settext(self.pretext + `self.val` + self.postext)
- #
+ #
+ # INVARIANTS maintained by the setval method:
+ #
+ # self.min <= self.val <= self.max
+ # self.text = self.pretext + `self.val` + self.postext
+ #
+ # (Notice that unlike Python ranges, the end point belongs
+ # to the range.)
+ #
+ def init_appearance(self):
+ ButtonAppearance.init_appearance(self)
+ self.min = 0
+ self.val = 0
+ self.max = 100
+ self.hook = 0
+ self.pretext = self.postext = ''
+ self.recalctext()
+ #
+ # The 'get*' and 'set*' methods belong to the generic slider interface
+ #
+ def getval(self): return self.val
+ #
+ def sethook(self, hook):
+ self.hook = hook
+ #
+ def setminvalmax(self, (min, val, max)):
+ self.min = min
+ self.max = max
+ self.setval(val)
+ #
+ def settexts(self, (pretext, postext)):
+ self.pretext = pretext
+ self.postext = postext
+ self.recalctext()
+ #
+ def setval(self, val):
+ val = min(self.max, max(self.min, val))
+ if val <> self.val:
+ self.val = val
+ self.recalctext()
+ self.trigger()
+ #
+ def trigger(self):
+ if self.hook:
+ self.hook(self)
+ #
+ def recalctext(self):
+ self.settext(self.pretext + `self.val` + self.postext)
+ #
class DragSlider() = DragSliderReactivity(), DragSliderAppearance(), Define():
- def definetext(self, (parent, text)):
- raise RuntimeError, 'DragSlider.definetext() not supported'
+ def definetext(self, (parent, text)):
+ raise RuntimeError, 'DragSlider.definetext() not supported'
# Auxiliary class for PushButton incorporated in ComplexSlider
#
class _StepButton() = PushButton():
- def define(self, parent):
- self = PushButton.define(self, parent)
- self.step = 0
- return self
- def setstep(self, step):
- self.step = step
- def definetextstep(self, (parent, text, step)):
- self = self.definetext(parent, text)
- self.setstep(step)
- return self
- def init_reactivity(self):
- PushButton.init_reactivity(self)
- self.parent.need_timer(self)
- def step_trigger(self):
- self.parent.setval(self.parent.getval() + self.step)
- def down_trigger(self):
- self.step_trigger()
- self.parent.settimer(5)
- def timer(self):
- if self.hilited:
- self.step_trigger()
- if self.active:
- self.parent.settimer(1)
+ def define(self, parent):
+ self = PushButton.define(self, parent)
+ self.step = 0
+ return self
+ def setstep(self, step):
+ self.step = step
+ def definetextstep(self, (parent, text, step)):
+ self = self.definetext(parent, text)
+ self.setstep(step)
+ return self
+ def init_reactivity(self):
+ PushButton.init_reactivity(self)
+ self.parent.need_timer(self)
+ def step_trigger(self):
+ self.parent.setval(self.parent.getval() + self.step)
+ def down_trigger(self):
+ self.step_trigger()
+ self.parent.settimer(5)
+ def timer(self):
+ if self.hilited:
+ self.step_trigger()
+ if self.active:
+ self.parent.settimer(1)
# A complex slider is an HSplit initialized to three buttons:
# one to step down, a dragslider, and one to step up.
#
class ComplexSlider() = HSplit():
- #
- # Override Slider define() method
- #
- def define(self, parent):
- self = self.create(parent) # HSplit
- #
- self.downbutton = _StepButton().definetextstep(self, '-', -1)
- self.dragbutton = DragSlider().define(self)
- self.upbutton = _StepButton().definetextstep(self, '+', 1)
- #
- return self
- #
- # Override HSplit methods
- #
- def minsize(self, m):
- w1, h1 = self.downbutton.minsize(m)
- w2, h2 = self.dragbutton.minsize(m)
- w3, h3 = self.upbutton.minsize(m)
- height = max(h1, h2, h3)
- w1 = max(w1, height)
- w3 = max(w3, height)
- return w1+w2+w3, height
- #
- def setbounds(self, bounds):
- (left, top), (right, bottom) = self.bounds = bounds
- size = bottom - top
- self.downbutton.setbounds((left, top), (left+size, bottom))
- self.dragbutton.setbounds((left+size, top), \
- (right-size, bottom))
- self.upbutton.setbounds((right-size, top), (right, bottom))
- #
- # Pass other Slider methods on to dragbutton
- #
- def getval(self): return self.dragbutton.getval()
- def sethook(self, hook): self.dragbutton.sethook(hook)
- def setminvalmax(self, args): self.dragbutton.setminvalmax(args)
- def settexts(self, args): self.dragbutton.settexts(args)
- def setval(self, val): self.dragbutton.setval(val)
- def enable(self, flag):
- self.downbutton.enable(flag)
- self.dragbutton.enable(flag)
- self.upbutton.enable(flag)
+ #
+ # Override Slider define() method
+ #
+ def define(self, parent):
+ self = self.create(parent) # HSplit
+ #
+ self.downbutton = _StepButton().definetextstep(self, '-', -1)
+ self.dragbutton = DragSlider().define(self)
+ self.upbutton = _StepButton().definetextstep(self, '+', 1)
+ #
+ return self
+ #
+ # Override HSplit methods
+ #
+ def minsize(self, m):
+ w1, h1 = self.downbutton.minsize(m)
+ w2, h2 = self.dragbutton.minsize(m)
+ w3, h3 = self.upbutton.minsize(m)
+ height = max(h1, h2, h3)
+ w1 = max(w1, height)
+ w3 = max(w3, height)
+ return w1+w2+w3, height
+ #
+ def setbounds(self, bounds):
+ (left, top), (right, bottom) = self.bounds = bounds
+ size = bottom - top
+ self.downbutton.setbounds((left, top), (left+size, bottom))
+ self.dragbutton.setbounds((left+size, top), \
+ (right-size, bottom))
+ self.upbutton.setbounds((right-size, top), (right, bottom))
+ #
+ # Pass other Slider methods on to dragbutton
+ #
+ def getval(self): return self.dragbutton.getval()
+ def sethook(self, hook): self.dragbutton.sethook(hook)
+ def setminvalmax(self, args): self.dragbutton.setminvalmax(args)
+ def settexts(self, args): self.dragbutton.settexts(args)
+ def setval(self, val): self.dragbutton.setval(val)
+ def enable(self, flag):
+ self.downbutton.enable(flag)
+ self.dragbutton.enable(flag)
+ self.upbutton.enable(flag)
diff --git a/lib/Soundogram.py b/lib/Soundogram.py
index 38dd5ef..aa2edd1 100644
--- a/lib/Soundogram.py
+++ b/lib/Soundogram.py
@@ -4,33 +4,33 @@ import audio
from Histogram import Histogram
class Soundogram() = Histogram():
- #
- def define(self, (win, chunk)):
- width, height = corner = win.getwinsize()
- bounds = (0, 0), corner
- self.chunk = chunk
- self.step = (len(chunk)-1)/(width/2+1) + 1
- ydata = _make_ydata(chunk, self.step)
- return Histogram.define(self, (win, bounds, ydata, (0, 128)))
- #
- def setchunk(self, chunk):
- self.chunk = chunk
- self.recompute()
- #
- def recompute(self):
- (left, top), (right, bottom) = self.bounds
- width = right - left
- self.step = (len(chunk)-1)/width + 1
- ydata = _make_ydata(chunk, self.step)
- self.setdata(ydata, (0, 128))
- #
+ #
+ def define(self, (win, chunk)):
+ width, height = corner = win.getwinsize()
+ bounds = (0, 0), corner
+ self.chunk = chunk
+ self.step = (len(chunk)-1)/(width/2+1) + 1
+ ydata = _make_ydata(chunk, self.step)
+ return Histogram.define(self, (win, bounds, ydata, (0, 128)))
+ #
+ def setchunk(self, chunk):
+ self.chunk = chunk
+ self.recompute()
+ #
+ def recompute(self):
+ (left, top), (right, bottom) = self.bounds
+ width = right - left
+ self.step = (len(chunk)-1)/width + 1
+ ydata = _make_ydata(chunk, self.step)
+ self.setdata(ydata, (0, 128))
+ #
def _make_ydata(chunk, step):
- ydata = []
- for i in range(0, len(chunk), step):
- piece = audio.chr2num(chunk[i:i+step])
- mi, ma = min(piece), max(piece)
- y = max(abs(mi), abs(ma))
- ydata.append(y)
- return ydata
+ ydata = []
+ for i in range(0, len(chunk), step):
+ piece = audio.chr2num(chunk[i:i+step])
+ mi, ma = min(piece), max(piece)
+ y = max(abs(mi), abs(ma))
+ ydata.append(y)
+ return ydata
diff --git a/lib/Split.py b/lib/Split.py
index 8c0a8dc..63f5d5f 100644
--- a/lib/Split.py
+++ b/lib/Split.py
@@ -3,114 +3,114 @@
# Derived classes should at least implement the methods that call
# unimpl() below: minsize(), getbounds() and setbounds().
-Error = 'Split.Error' # Exception
+Error = 'Split.Error' # Exception
import rect
from util import remove
class Split():
- #
- # Calls from creator
- # NB derived classes may add parameters to create()
- #
- def create(self, parent):
- parent.addchild(self)
- self.parent = parent
- self.children = []
- self.mouse_interest = []
- self.timer_interest = []
- self.mouse_focus = 0
- return self
- #
- # Downcalls from parent to child
- #
- def destroy(self):
- self.parent = None
- for child in self.children:
- child.destroy()
- del self.children[:]
- del self.mouse_interest[:]
- del self.timer_interest[:]
- self.mouse_focus = None
- #
- def minsize(self, m): return unimpl()
- def getbounds(self): return unimpl()
- def setbounds(self, bounds): unimpl()
- #
- def draw(self, d_detail):
- # (Could avoid calls to children outside the area)
- for child in self.children:
- child.draw(d_detail)
- #
- # Downcalls only made after certain upcalls
- #
- def mouse_down(self, detail):
- if self.mouse_focus:
- self.mouse_focus.mouse_down(detail)
- p = detail[0]
- for child in self.mouse_interest:
- if rect.pointinrect(p, child.getbounds()):
- self.mouse_focus = child
- child.mouse_down(detail)
- def mouse_move(self, detail):
- if self.mouse_focus:
- self.mouse_focus.mouse_move(detail)
- def mouse_up(self, detail):
- if self.mouse_focus:
- self.mouse_focus.mouse_up(detail)
- self.mouse_focus = 0
- #
- def timer(self):
- for child in self.timer_interest:
- child.timer()
- #
- # Upcalls from child to parent
- #
- def addchild(self, child):
- if child in self.children:
- raise Error, 'addchild: child already inlist'
- self.children.append(child)
- def delchild(self, child):
- if child not in self.children:
- raise Error, 'delchild: child not in list'
- remove(child, self.children)
- if child in self.mouse_interest:
- remove(child, self.mouse_interest)
- if child in self.timer_interest:
- remove(child, self.timer_interest)
- if child = self.mouse_focus:
- self.mouse_focus = 0
- #
- def need_mouse(self, child):
- if child not in self.mouse_interest:
- self.mouse_interest.append(child)
- self.parent.need_mouse(self)
- def no_mouse(self, child):
- if child in self.mouse_interest:
- remove(child, self.mouse_interest)
- if not self.mouse_interest:
- self.parent.no_mouse(self)
- #
- def need_timer(self, child):
- if child not in self.timer_interest:
- self.timer_interest.append(child)
- self.parent.need_timer(self)
- def no_timer(self, child):
- if child in self.timer_interest:
- remove(child, self.timer_interest)
- if not self.timer_interest:
- self.parent.no_timer(self)
- #
- # The rest are transparent:
- #
- def begindrawing(self):
- return self.parent.begindrawing()
- def beginmeasuring(self):
- return self.parent.beginmeasuring()
- #
- def change(self, area):
- self.parent.change(area)
- def scroll(self, area_vector):
- self.parent.scroll(area_vector)
- def settimer(self, itimer):
- self.parent.settimer(itimer)
+ #
+ # Calls from creator
+ # NB derived classes may add parameters to create()
+ #
+ def create(self, parent):
+ parent.addchild(self)
+ self.parent = parent
+ self.children = []
+ self.mouse_interest = []
+ self.timer_interest = []
+ self.mouse_focus = 0
+ return self
+ #
+ # Downcalls from parent to child
+ #
+ def destroy(self):
+ self.parent = None
+ for child in self.children:
+ child.destroy()
+ del self.children[:]
+ del self.mouse_interest[:]
+ del self.timer_interest[:]
+ self.mouse_focus = None
+ #
+ def minsize(self, m): return unimpl()
+ def getbounds(self): return unimpl()
+ def setbounds(self, bounds): unimpl()
+ #
+ def draw(self, d_detail):
+ # (Could avoid calls to children outside the area)
+ for child in self.children:
+ child.draw(d_detail)
+ #
+ # Downcalls only made after certain upcalls
+ #
+ def mouse_down(self, detail):
+ if self.mouse_focus:
+ self.mouse_focus.mouse_down(detail)
+ p = detail[0]
+ for child in self.mouse_interest:
+ if rect.pointinrect(p, child.getbounds()):
+ self.mouse_focus = child
+ child.mouse_down(detail)
+ def mouse_move(self, detail):
+ if self.mouse_focus:
+ self.mouse_focus.mouse_move(detail)
+ def mouse_up(self, detail):
+ if self.mouse_focus:
+ self.mouse_focus.mouse_up(detail)
+ self.mouse_focus = 0
+ #
+ def timer(self):
+ for child in self.timer_interest:
+ child.timer()
+ #
+ # Upcalls from child to parent
+ #
+ def addchild(self, child):
+ if child in self.children:
+ raise Error, 'addchild: child already inlist'
+ self.children.append(child)
+ def delchild(self, child):
+ if child not in self.children:
+ raise Error, 'delchild: child not in list'
+ remove(child, self.children)
+ if child in self.mouse_interest:
+ remove(child, self.mouse_interest)
+ if child in self.timer_interest:
+ remove(child, self.timer_interest)
+ if child = self.mouse_focus:
+ self.mouse_focus = 0
+ #
+ def need_mouse(self, child):
+ if child not in self.mouse_interest:
+ self.mouse_interest.append(child)
+ self.parent.need_mouse(self)
+ def no_mouse(self, child):
+ if child in self.mouse_interest:
+ remove(child, self.mouse_interest)
+ if not self.mouse_interest:
+ self.parent.no_mouse(self)
+ #
+ def need_timer(self, child):
+ if child not in self.timer_interest:
+ self.timer_interest.append(child)
+ self.parent.need_timer(self)
+ def no_timer(self, child):
+ if child in self.timer_interest:
+ remove(child, self.timer_interest)
+ if not self.timer_interest:
+ self.parent.no_timer(self)
+ #
+ # The rest are transparent:
+ #
+ def begindrawing(self):
+ return self.parent.begindrawing()
+ def beginmeasuring(self):
+ return self.parent.beginmeasuring()
+ #
+ def change(self, area):
+ self.parent.change(area)
+ def scroll(self, area_vector):
+ self.parent.scroll(area_vector)
+ def settimer(self, itimer):
+ self.parent.settimer(itimer)
diff --git a/lib/StripChart.py b/lib/StripChart.py
index fc707cb..ac767c3 100644
--- a/lib/StripChart.py
+++ b/lib/StripChart.py
@@ -7,62 +7,62 @@ from Buttons import LabelAppearance, NoReactivity
# LabelAppearance allows it to be disabled and hilited.
class StripChart() = LabelAppearance(), NoReactivity():
- #
- def define(self, (parent, scale)):
- self.parent = parent
- parent.addchild(self)
- self.init_appearance()
- self.init_reactivity()
- self.ydata = []
- self.scale = scale
- self.resetbounds()
- return self
- #
- def setbounds(self, bounds):
- LabelAppearance.setbounds(self, bounds)
- self.resetbounds()
- #
- def resetbounds(self):
- (left, top), (right, bottom) = self.bounds
- self.width = right-left
- self.height = bottom-top
- excess = len(self.ydata) - self.width
- if excess > 0:
- del self.ydata[:excess]
- elif excess < 0:
- while len(self.ydata) < self.width:
- self.ydata.insert(0, 0)
- #
- def append(self, y):
- self.ydata.append(y)
- excess = len(self.ydata) - self.width
- if excess > 0:
- del self.ydata[:excess]
- if self.bounds <> rect.empty:
- self.parent.scroll(self.bounds, (-excess, 0))
- if self.bounds <> rect.empty:
- (left, top), (right, bottom) = self.bounds
- i = len(self.ydata)
- area = (left+i-1, top), (left+i, bottom)
- self.draw(self.parent.begindrawing(), area)
- #
- def draw(self, (d, area)):
- area = rect.intersect(area, self.bounds)
- if area = rect.empty:
- print 'mt'
- return
- d.cliprect(area)
- d.erase(self.bounds)
- (a_left, a_top), (a_right, a_bottom) = area
- (left, top), (right, bottom) = self.bounds
- height = bottom - top
- i1 = a_left - left
- i2 = a_right - left
- for i in range(max(0, i1), min(len(self.ydata), i2)):
- split = bottom-self.ydata[i]*height/self.scale
- d.paint((left+i, split), (left+i+1, bottom))
- if not self.enabled:
- self.flipenable(d)
- if self.hilited:
- self.fliphilite(d)
- d.noclip()
+ #
+ def define(self, (parent, scale)):
+ self.parent = parent
+ parent.addchild(self)
+ self.init_appearance()
+ self.init_reactivity()
+ self.ydata = []
+ self.scale = scale
+ self.resetbounds()
+ return self
+ #
+ def setbounds(self, bounds):
+ LabelAppearance.setbounds(self, bounds)
+ self.resetbounds()
+ #
+ def resetbounds(self):
+ (left, top), (right, bottom) = self.bounds
+ self.width = right-left
+ self.height = bottom-top
+ excess = len(self.ydata) - self.width
+ if excess > 0:
+ del self.ydata[:excess]
+ elif excess < 0:
+ while len(self.ydata) < self.width:
+ self.ydata.insert(0, 0)
+ #
+ def append(self, y):
+ self.ydata.append(y)
+ excess = len(self.ydata) - self.width
+ if excess > 0:
+ del self.ydata[:excess]
+ if self.bounds <> rect.empty:
+ self.parent.scroll(self.bounds, (-excess, 0))
+ if self.bounds <> rect.empty:
+ (left, top), (right, bottom) = self.bounds
+ i = len(self.ydata)
+ area = (left+i-1, top), (left+i, bottom)
+ self.draw(self.parent.begindrawing(), area)
+ #
+ def draw(self, (d, area)):
+ area = rect.intersect(area, self.bounds)
+ if area = rect.empty:
+ print 'mt'
+ return
+ d.cliprect(area)
+ d.erase(self.bounds)
+ (a_left, a_top), (a_right, a_bottom) = area
+ (left, top), (right, bottom) = self.bounds
+ height = bottom - top
+ i1 = a_left - left
+ i2 = a_right - left
+ for i in range(max(0, i1), min(len(self.ydata), i2)):
+ split = bottom-self.ydata[i]*height/self.scale
+ d.paint((left+i, split), (left+i+1, bottom))
+ if not self.enabled:
+ self.flipenable(d)
+ if self.hilited:
+ self.fliphilite(d)
+ d.noclip()
diff --git a/lib/Tcl.py b/lib/Tcl.py
index 9d45e37..7f5c8c2 100644
--- a/lib/Tcl.py
+++ b/lib/Tcl.py
@@ -4,27 +4,27 @@
# Design choices:
#
# - Names used for functions are not exactly those used by C Tcl.
-# In Python, names without 'Tcl_' prefix are acceptable because
-# names are less global than in C (and often they are prefixed
-# with a module name anyway). Parameter conventions also differ.
+# In Python, names without 'Tcl_' prefix are acceptable because
+# names are less global than in C (and often they are prefixed
+# with a module name anyway). Parameter conventions also differ.
#
# - The Tcl Interpreter type is implemented using a Python class.
-# Almost all functions with an Interpreter as first parameter are
-# methods of this class.
-# Applications can create derived classes to add additional commands
-# or to override specific internal functions.
+# Almost all functions with an Interpreter as first parameter are
+# methods of this class.
+# Applications can create derived classes to add additional commands
+# or to override specific internal functions.
#
# - Tcl errors are mapped to Python exceptions.
-# (I bet Ousterhout would have done the same in a language with
-# a proper exception mechanism).
+# (I bet Ousterhout would have done the same in a language with
+# a proper exception mechanism).
#
# - Tcl expressions are evaluated by Python's built-in function eval().
-# This makes Python Tcl scripts incompatible with C Tcl scripts,
-# but is the only sensible solution for a quick-and-dirty version.
-# It also makes an escape to Python possible.
+# This makes Python Tcl scripts incompatible with C Tcl scripts,
+# but is the only sensible solution for a quick-and-dirty version.
+# It also makes an escape to Python possible.
#
# - The Backslash function interprets \<newline>, since it
-# can return a string instead of a character.
+# can return a string instead of a character.
from TclUtil import *
@@ -38,59 +38,59 @@ TclReturn = 'TclReturn'
class CmdBuf():
- #
- def Create(buffer):
- buffer.string = ''
- return buffer
- #
- def Assemble(buffer, str):
- buffer.string = buffer.string + str
- if buffer.string[-1:] = '\n':
- i, end = 0, len(buffer.string)
- try:
- while i < end:
- list, i = FindNextCommand( \
- buffer.string, i, end, 0)
- except TclMatchingError:
- return ''
- except TclSyntaxError:
- pass # Let Eval() return the error
- ret = buffer.string
- buffer.string = ''
- return ret
- else:
- return ''
+ #
+ def Create(buffer):
+ buffer.string = ''
+ return buffer
+ #
+ def Assemble(buffer, str):
+ buffer.string = buffer.string + str
+ if buffer.string[-1:] = '\n':
+ i, end = 0, len(buffer.string)
+ try:
+ while i < end:
+ list, i = FindNextCommand( \
+ buffer.string, i, end, 0)
+ except TclMatchingError:
+ return ''
+ except TclSyntaxError:
+ pass # Let Eval() return the error
+ ret = buffer.string
+ buffer.string = ''
+ return ret
+ else:
+ return ''
class _Frame():
- def Create(frame):
- frame.locals = {}
- return frame
+ def Create(frame):
+ frame.locals = {}
+ return frame
class _Proc():
- #
- def Create(proc, (interp, args, body)):
- proc.interp = interp
- proc.args = SplitList(args) # Do this once here
- proc.body = body
- return proc
- #
- def Call(proc, argv):
- if len(argv) <> len(proc.args)+1:
- raise TclRuntimeError, \
- 'wrong # args to proc "' + \
- argv[0] + '"'
- # XXX No defaults or variable length 'args' yet
- frame = _Frame().Create()
- for i in range(len(proc.args)):
- frame.locals[proc.args[i]] = argv[i+1]
- proc.interp.stack.append(frame)
- try:
- value = proc.interp.Eval(proc.body)
- except TclReturn, value:
- pass
- del proc.interp.stack[-1:]
- return value
+ #
+ def Create(proc, (interp, args, body)):
+ proc.interp = interp
+ proc.args = SplitList(args) # Do this once here
+ proc.body = body
+ return proc
+ #
+ def Call(proc, argv):
+ if len(argv) <> len(proc.args)+1:
+ raise TclRuntimeError, \
+ 'wrong # args to proc "' + \
+ argv[0] + '"'
+ # XXX No defaults or variable length 'args' yet
+ frame = _Frame().Create()
+ for i in range(len(proc.args)):
+ frame.locals[proc.args[i]] = argv[i+1]
+ proc.interp.stack.append(frame)
+ try:
+ value = proc.interp.Eval(proc.body)
+ except TclReturn, value:
+ pass
+ del proc.interp.stack[-1:]
+ return value
import regexp
@@ -98,311 +98,311 @@ _expand_prog = regexp.compile('([^[$\\]+|\n)*')
del regexp
class Interpreter():
- #
- def Create(interp):
- interp.globals = {}
- interp.commands = {}
- interp.stack = []
- interp.commands['break'] = interp.BreakCmd
- interp.commands['concat'] = interp.ConcatCmd
- interp.commands['continue'] = interp.ContinueCmd
- interp.commands['echo'] = interp.EchoCmd
- interp.commands['eval'] = interp.EvalCmd
- interp.commands['expr'] = interp.ExprCmd
- interp.commands['for'] = interp.ForCmd
- interp.commands['glob'] = interp.GlobCmd
- interp.commands['global'] = interp.GlobalCmd
- interp.commands['if'] = interp.IfCmd
- interp.commands['index'] = interp.IndexCmd
- interp.commands['list'] = interp.ListCmd
- interp.commands['proc'] = interp.ProcCmd
- interp.commands['rename'] = interp.RenameCmd
- interp.commands['return'] = interp.ReturnCmd
- interp.commands['set'] = interp.SetCmd
- return interp
- #
- def Delete(interp):
- #
- # Only break circular references here;
- # most things will be garbage-collected.
- #
- for name in interp.commands.keys():
- del interp.commands[name]
- #
- def CreateCommand(interp, (name, proc)):
- interp.commands[name] = proc
- #
- def DeleteCommand(interp, (name)):
- del interp.commands[name]
- #
- # Local variables are maintained on the stack.
- # A local variable with value "None" is a dummy
- # meaning that the corresponding global variable
- # should be used.
- #
- def GetVar(interp, varName):
- dict = interp.globals
- if interp.stack:
- d = interp.stack[-1:][0].locals
- if d.has_key(varName) and d[varName] = None:
- pass
- else:
- dict = d
- if not dict.has_key(varName):
- raise TclRuntimeError, \
- 'Variable "' + varName + '" not found'
- return dict[varName]
- #
- def SetVar(interp, (varName, newValue)):
- dict = interp.globals
- if interp.stack:
- d = interp.stack[-1:][0].locals
- if d.has_key(varName) and d[varName] = None:
- pass
- else:
- dict = d
- dict[varName] = newValue
- #
- def Expand(interp, (str, i, end)):
- if end <= i: return ''
- if str[i] = '{' and str[end-1] = '}':
- return str[i+1:end-1]
- if str[i] = '"' and str[end-1] = '"':
- i, end = i+1, end-1
- result = ''
- while i < end:
- c = str[i]
- if c = '\\':
- x, i = Backslash(str, i, end)
- result = result + x
- elif c = '[':
- j = BalanceBrackets(str, i, end)
- x = interp.EvalBasic(str, i+1, j-1, 1)
- result = result + x
- i = j
- elif c = '$':
- i = i+1
- j = FindVarName(str, i, end)
- name = str[i:j]
- i = j
- if not name:
- result = result + '$'
- else:
- if name[:1] = '{' and name[-1:] = '}':
- name = name[1:-1]
- result = result + interp.GetVar(name)
- else:
- j = _expand_prog.exec(str, i)
- j = min(j, end)
- result = result + str[i:j]
- i = j
- return result
- #
- def EvalBasic(interp, (str, i, end, bracketed)):
- result = ''
- while i < end:
- indexargv, i = FindNextCommand( \
- str, i, end, bracketed)
- if indexargv:
- argv = []
- for x, y in indexargv:
- arg = interp.Expand(str, x, y)
- argv.append(arg)
- name = argv[0]
- if not interp.commands.has_key(name):
- raise TclRuntimeError, \
- 'Command "' + name + \
- '" not found'
- result = interp.commands[name](argv)
- return result
- #
- def Eval(interp, str):
- return interp.EvalBasic(str, 0, len(str), 0)
- #
- def ExprBasic(interp, (str, begin, end)):
- expr = interp.Expand(str, begin, end)
- i = SkipSpaces(expr, 0, len(expr))
- expr = expr[i:]
- try:
- return eval(expr, {})
- except (NameError, TypeError, RuntimeError, EOFError), msg:
- import sys
- raise TclRuntimeError, sys.exc_type + ': ' + msg
- #
- def Expr(interp, str):
- return interp.ExprBasic(str, 0, len(str))
- #
- # The rest are command implementations
- #
- def BreakCmd(interp, argv):
- if len(argv) <> 1:
- raise TclRuntimeError, 'usage: break'
- raise TclBreak
- #
- def ConcatCmd(interp, argv):
- if len(argv) < 2:
- raise TclRuntimeError, 'usage: concat arg ...'
- return Concat(argv[1:])
- #
- def ContinueCmd(interp, argv):
- if len(argv) <> 1:
- raise TclRuntimeError, 'usage: continue'
- raise TclContinue
- #
- def EchoCmd(interp, argv):
- for arg in argv[1:]: print arg,
- print
- return ''
- #
- def EvalCmd(interp, argv):
- if len(argv) < 2:
- raise TclRuntimeError, 'usage: eval arg [arg ...]'
- str = Concat(argv[1:])
- return interp.Eval(str)
- #
- def ExprCmd(interp, argv):
- if len(argv) <> 2:
- raise TclRuntimeError, 'usage: expr expression'
- expr = argv[1]
- result = interp.Expr(expr)
- if type(result) <> type(''): result = `result`
- return result
- #
- def ForCmd(interp, argv):
- if len(argv) <> 5:
- raise TclRuntimeError, \
- 'usage: for start test next body'
- x = interp.Eval(argv[1])
- while interp.Expr(argv[2]):
- try:
- x = interp.Eval(argv[4])
- except TclBreak:
- break
- except TclContinue:
- pass
- x = interp.Eval(argv[3])
- return ''
- #
- def GlobCmd(interp, argv):
- import macglob
- if len(argv) < 2:
- raise TclRuntimeError, 'usage: glob pattern ...'
- list = []
- for pat in argv[1:]:
- list = list + macglob.glob(pat)
- if not list:
- raise TclRuntimeError, 'no match for glob pattern(s)'
- return BuildList(list)
- #
- def GlobalCmd(interp, argv):
- if len(argv) < 2:
- raise TclRuntimeError, 'usage: global varname ...'
- if not interp.stack:
- raise TclRuntimeError, 'global used outside proc'
- dict = interp.stack[-1:][0].locals
- for name in argv[1:]:
- dict[name] = None
- return ''
- #
- def IfCmd(interp, argv):
- argv = argv[:]
- if len(argv) > 2 and argv[2] = 'then': del argv[2]
- if len(argv) > 3 and argv[3] = 'else': del argv[3]
- if not 3 <= len(argv) <= 4:
- raise TclRuntimeError, \
- 'usage: if test [then] trueBody [else] falseBody'
- if interp.Expr(argv[1]):
- return interp.Eval(argv[2])
- if len(argv) > 3:
- return interp.Eval(argv[3])
- return ''
- #
- def IndexCmd(interp, argv):
- if len(argv) <> 3:
- raise TclRuntimeError, 'usage: index value index'
- import string
- try:
- index = string.atoi(argv[2])
- if index < 0: raise string.atoi_error
- except string.atoi_error:
- raise TclRuntimeError, 'bad index: ' + argv[2]
- list = SplitList(argv[1])
- if index >= len(list): return ''
- return list[index]
- #
- def ListCmd(interp, argv):
- if len(argv) < 2:
- raise TclRuntimeError, 'usage: list arg ...'
- return BuildList(argv[1:])
- #
- def ProcCmd(interp, argv):
- if len(argv) <> 4:
- raise TclRuntimeError, 'usage: proc name args body'
- x = _Proc().Create(interp, argv[2], argv[3])
- interp.CreateCommand(argv[1], x.Call)
- return ''
- #
- def RenameCmd(interp, argv):
- if len(argv) <> 3:
- raise TclRuntimeError, 'usage: rename oldName newName'
- oldName, newName = argv[1], argv[2]
- if not interp.commands.has_key(oldName):
- raise TclRuntimeError, \
- 'command "' + oldName + '" not found'
- if newName: interp.commands[newName] = interp.commands[oldName]
- del interp.commands[oldName]
- return ''
- #
- def ReturnCmd(interp, argv):
- if not 1 <= len(argv) <= 2:
- raise TclRuntimeError, 'usage: return [arg]'
- if len(argv) = 1: raise TclReturn, ''
- raise TclReturn, argv[1]
- #
- def SetCmd(interp, argv):
- n = len(argv)
- if not 2 <= n <= 3:
- raise TclRuntimeError, 'usage: set varname [newvalue]'
- if n = 2: return interp.GetVar(argv[1])
- interp.SetVar(argv[1], argv[2])
- return ''
+ #
+ def Create(interp):
+ interp.globals = {}
+ interp.commands = {}
+ interp.stack = []
+ interp.commands['break'] = interp.BreakCmd
+ interp.commands['concat'] = interp.ConcatCmd
+ interp.commands['continue'] = interp.ContinueCmd
+ interp.commands['echo'] = interp.EchoCmd
+ interp.commands['eval'] = interp.EvalCmd
+ interp.commands['expr'] = interp.ExprCmd
+ interp.commands['for'] = interp.ForCmd
+ interp.commands['glob'] = interp.GlobCmd
+ interp.commands['global'] = interp.GlobalCmd
+ interp.commands['if'] = interp.IfCmd
+ interp.commands['index'] = interp.IndexCmd
+ interp.commands['list'] = interp.ListCmd
+ interp.commands['proc'] = interp.ProcCmd
+ interp.commands['rename'] = interp.RenameCmd
+ interp.commands['return'] = interp.ReturnCmd
+ interp.commands['set'] = interp.SetCmd
+ return interp
+ #
+ def Delete(interp):
+ #
+ # Only break circular references here;
+ # most things will be garbage-collected.
+ #
+ for name in interp.commands.keys():
+ del interp.commands[name]
+ #
+ def CreateCommand(interp, (name, proc)):
+ interp.commands[name] = proc
+ #
+ def DeleteCommand(interp, (name)):
+ del interp.commands[name]
+ #
+ # Local variables are maintained on the stack.
+ # A local variable with value "None" is a dummy
+ # meaning that the corresponding global variable
+ # should be used.
+ #
+ def GetVar(interp, varName):
+ dict = interp.globals
+ if interp.stack:
+ d = interp.stack[-1:][0].locals
+ if d.has_key(varName) and d[varName] = None:
+ pass
+ else:
+ dict = d
+ if not dict.has_key(varName):
+ raise TclRuntimeError, \
+ 'Variable "' + varName + '" not found'
+ return dict[varName]
+ #
+ def SetVar(interp, (varName, newValue)):
+ dict = interp.globals
+ if interp.stack:
+ d = interp.stack[-1:][0].locals
+ if d.has_key(varName) and d[varName] = None:
+ pass
+ else:
+ dict = d
+ dict[varName] = newValue
+ #
+ def Expand(interp, (str, i, end)):
+ if end <= i: return ''
+ if str[i] = '{' and str[end-1] = '}':
+ return str[i+1:end-1]
+ if str[i] = '"' and str[end-1] = '"':
+ i, end = i+1, end-1
+ result = ''
+ while i < end:
+ c = str[i]
+ if c = '\\':
+ x, i = Backslash(str, i, end)
+ result = result + x
+ elif c = '[':
+ j = BalanceBrackets(str, i, end)
+ x = interp.EvalBasic(str, i+1, j-1, 1)
+ result = result + x
+ i = j
+ elif c = '$':
+ i = i+1
+ j = FindVarName(str, i, end)
+ name = str[i:j]
+ i = j
+ if not name:
+ result = result + '$'
+ else:
+ if name[:1] = '{' and name[-1:] = '}':
+ name = name[1:-1]
+ result = result + interp.GetVar(name)
+ else:
+ j = _expand_prog.exec(str, i)
+ j = min(j, end)
+ result = result + str[i:j]
+ i = j
+ return result
+ #
+ def EvalBasic(interp, (str, i, end, bracketed)):
+ result = ''
+ while i < end:
+ indexargv, i = FindNextCommand( \
+ str, i, end, bracketed)
+ if indexargv:
+ argv = []
+ for x, y in indexargv:
+ arg = interp.Expand(str, x, y)
+ argv.append(arg)
+ name = argv[0]
+ if not interp.commands.has_key(name):
+ raise TclRuntimeError, \
+ 'Command "' + name + \
+ '" not found'
+ result = interp.commands[name](argv)
+ return result
+ #
+ def Eval(interp, str):
+ return interp.EvalBasic(str, 0, len(str), 0)
+ #
+ def ExprBasic(interp, (str, begin, end)):
+ expr = interp.Expand(str, begin, end)
+ i = SkipSpaces(expr, 0, len(expr))
+ expr = expr[i:]
+ try:
+ return eval(expr, {})
+ except (NameError, TypeError, RuntimeError, EOFError), msg:
+ import sys
+ raise TclRuntimeError, sys.exc_type + ': ' + msg
+ #
+ def Expr(interp, str):
+ return interp.ExprBasic(str, 0, len(str))
+ #
+ # The rest are command implementations
+ #
+ def BreakCmd(interp, argv):
+ if len(argv) <> 1:
+ raise TclRuntimeError, 'usage: break'
+ raise TclBreak
+ #
+ def ConcatCmd(interp, argv):
+ if len(argv) < 2:
+ raise TclRuntimeError, 'usage: concat arg ...'
+ return Concat(argv[1:])
+ #
+ def ContinueCmd(interp, argv):
+ if len(argv) <> 1:
+ raise TclRuntimeError, 'usage: continue'
+ raise TclContinue
+ #
+ def EchoCmd(interp, argv):
+ for arg in argv[1:]: print arg,
+ print
+ return ''
+ #
+ def EvalCmd(interp, argv):
+ if len(argv) < 2:
+ raise TclRuntimeError, 'usage: eval arg [arg ...]'
+ str = Concat(argv[1:])
+ return interp.Eval(str)
+ #
+ def ExprCmd(interp, argv):
+ if len(argv) <> 2:
+ raise TclRuntimeError, 'usage: expr expression'
+ expr = argv[1]
+ result = interp.Expr(expr)
+ if type(result) <> type(''): result = `result`
+ return result
+ #
+ def ForCmd(interp, argv):
+ if len(argv) <> 5:
+ raise TclRuntimeError, \
+ 'usage: for start test next body'
+ x = interp.Eval(argv[1])
+ while interp.Expr(argv[2]):
+ try:
+ x = interp.Eval(argv[4])
+ except TclBreak:
+ break
+ except TclContinue:
+ pass
+ x = interp.Eval(argv[3])
+ return ''
+ #
+ def GlobCmd(interp, argv):
+ import macglob
+ if len(argv) < 2:
+ raise TclRuntimeError, 'usage: glob pattern ...'
+ list = []
+ for pat in argv[1:]:
+ list = list + macglob.glob(pat)
+ if not list:
+ raise TclRuntimeError, 'no match for glob pattern(s)'
+ return BuildList(list)
+ #
+ def GlobalCmd(interp, argv):
+ if len(argv) < 2:
+ raise TclRuntimeError, 'usage: global varname ...'
+ if not interp.stack:
+ raise TclRuntimeError, 'global used outside proc'
+ dict = interp.stack[-1:][0].locals
+ for name in argv[1:]:
+ dict[name] = None
+ return ''
+ #
+ def IfCmd(interp, argv):
+ argv = argv[:]
+ if len(argv) > 2 and argv[2] = 'then': del argv[2]
+ if len(argv) > 3 and argv[3] = 'else': del argv[3]
+ if not 3 <= len(argv) <= 4:
+ raise TclRuntimeError, \
+ 'usage: if test [then] trueBody [else] falseBody'
+ if interp.Expr(argv[1]):
+ return interp.Eval(argv[2])
+ if len(argv) > 3:
+ return interp.Eval(argv[3])
+ return ''
+ #
+ def IndexCmd(interp, argv):
+ if len(argv) <> 3:
+ raise TclRuntimeError, 'usage: index value index'
+ import string
+ try:
+ index = string.atoi(argv[2])
+ if index < 0: raise string.atoi_error
+ except string.atoi_error:
+ raise TclRuntimeError, 'bad index: ' + argv[2]
+ list = SplitList(argv[1])
+ if index >= len(list): return ''
+ return list[index]
+ #
+ def ListCmd(interp, argv):
+ if len(argv) < 2:
+ raise TclRuntimeError, 'usage: list arg ...'
+ return BuildList(argv[1:])
+ #
+ def ProcCmd(interp, argv):
+ if len(argv) <> 4:
+ raise TclRuntimeError, 'usage: proc name args body'
+ x = _Proc().Create(interp, argv[2], argv[3])
+ interp.CreateCommand(argv[1], x.Call)
+ return ''
+ #
+ def RenameCmd(interp, argv):
+ if len(argv) <> 3:
+ raise TclRuntimeError, 'usage: rename oldName newName'
+ oldName, newName = argv[1], argv[2]
+ if not interp.commands.has_key(oldName):
+ raise TclRuntimeError, \
+ 'command "' + oldName + '" not found'
+ if newName: interp.commands[newName] = interp.commands[oldName]
+ del interp.commands[oldName]
+ return ''
+ #
+ def ReturnCmd(interp, argv):
+ if not 1 <= len(argv) <= 2:
+ raise TclRuntimeError, 'usage: return [arg]'
+ if len(argv) = 1: raise TclReturn, ''
+ raise TclReturn, argv[1]
+ #
+ def SetCmd(interp, argv):
+ n = len(argv)
+ if not 2 <= n <= 3:
+ raise TclRuntimeError, 'usage: set varname [newvalue]'
+ if n = 2: return interp.GetVar(argv[1])
+ interp.SetVar(argv[1], argv[2])
+ return ''
# The rest are just demos:
def MainLoop(interp):
- buffer = CmdBuf().Create()
- if not interp.globals.has_key('ps1'): interp.globals['ps1'] = '% '
- if not interp.globals.has_key('ps2'): interp.globals['ps2'] = ''
- psname = 'ps1'
- while 1:
- try:
- line = raw_input(interp.globals[psname])
- except (EOFError, KeyboardInterrupt):
- print
- break
- line = buffer.Assemble(line + '\n')
- if not line:
- psname = 'ps2'
- else:
- psname = 'ps1'
- try:
- x = interp.Eval(line)
- if x <> '': print 'Result:', `x`
- except (TclRuntimeError, TclSyntaxError, \
- TclMatchingError), msg:
- print 'Error:', msg
- except (TclBreak, TclContinue):
- print 'Error: break or continue outside loop'
- except TclReturn, value:
- # Return outside proc returns to main loop
- if value: print value
+ buffer = CmdBuf().Create()
+ if not interp.globals.has_key('ps1'): interp.globals['ps1'] = '% '
+ if not interp.globals.has_key('ps2'): interp.globals['ps2'] = ''
+ psname = 'ps1'
+ while 1:
+ try:
+ line = raw_input(interp.globals[psname])
+ except (EOFError, KeyboardInterrupt):
+ print
+ break
+ line = buffer.Assemble(line + '\n')
+ if not line:
+ psname = 'ps2'
+ else:
+ psname = 'ps1'
+ try:
+ x = interp.Eval(line)
+ if x <> '': print 'Result:', `x`
+ except (TclRuntimeError, TclSyntaxError, \
+ TclMatchingError), msg:
+ print 'Error:', msg
+ except (TclBreak, TclContinue):
+ print 'Error: break or continue outside loop'
+ except TclReturn, value:
+ # Return outside proc returns to main loop
+ if value: print value
the_interpreter = Interpreter().Create()
def main():
- MainLoop(the_interpreter)
+ MainLoop(the_interpreter)
# XXX To do:
diff --git a/lib/TclShell.py b/lib/TclShell.py
index 78d8dc4..8d0ef19 100644
--- a/lib/TclShell.py
+++ b/lib/TclShell.py
@@ -10,246 +10,246 @@ from macpath import isfile, isdir, exists
UsageError = TclRuntimeError
class ShellInterpreter() = Interpreter():
- #
- def ResetVariables(interp):
- interp.globals['ps1'] = '$ '
- interp.globals['ps2'] = '> '
- interp.globals['home'] = mac.getcwd()
- #
- def DefineCommands(interp):
- interp.commands['cd'] = interp.CdCmd
- interp.commands['grep'] = interp.GrepCmd
- interp.commands['ls'] = interp.LsCmd
- interp.commands['mkdir'] = interp.MkdirCmd
- interp.commands['mv'] = interp.MvCmd
- interp.commands['pg'] = interp.PgCmd
- interp.commands['pwd'] = interp.PwdCmd
- interp.commands['rm'] = interp.RmCmd
- interp.commands['rmdir'] = interp.RmdirCmd
- interp.commands['sync'] = interp.SyncCmd
- #
- def Reset(interp):
- interp.ResetVariables()
- interp.DefineCommands()
- #
- def Create(interp):
- interp = Interpreter.Create(interp) # initialize base class
- interp.Reset()
- return interp
- #
- # Command-implementing functions
- #
- def CdCmd(interp, argv):
- if len(argv) > 2:
- raise UsageError, 'usage: cd [dirname]'
- if len(argv) = 2:
- chdirto(argv[1])
- else:
- chdirto(interp.globals['home'])
- return ''
- #
- def GrepCmd(interp, argv):
- if len(argv) < 3:
- raise UsageError, 'usage: grep regexp file ...'
- import regexp
- try:
- prog = regexp.compile(argv[1])
- except regexp.error, msg:
- raise TclRuntimeError, \
- ('grep', argv[1], ': bad regexp :', msg)
- for file in argv[2:]:
- grepfile(prog, file)
- return ''
- #
- def LsCmd(interp, argv):
- if len(argv) < 2:
- lsdir(':')
- else:
- for dirname in argv[1:]:
- lsdir(dirname)
- return ''
- #
- def MkdirCmd(interp, argv):
- if len(argv) < 2:
- raise UsageError, 'usage: mkdir name ...'
- for name in argv[1:]:
- makedir(name)
- return ''
- #
- def MvCmd(interp, argv):
- if len(argv) <> 3:
- raise UsageError, 'usage: mv src dst'
- src, dst = argv[1], argv[2]
- if not exists(src):
- raise TclRuntimeError, \
- ('mv', src, dst, ': source does not exist')
- if exists(dst):
- raise TclRuntimeError, \
- ('mv', src, dst, ': destination already exists')
- try:
- mac.rename(src, dst)
- except mac.error, msg:
- raise TclRuntimeError, \
- (src, dst, ': rename failed :', msg)
- return ''
- #
- def PgCmd(interp, argv):
- if len(argv) < 2:
- raise UsageError, 'usage: page file ...'
- for name in argv[1:]:
- pagefile(name)
- return ''
- #
- def PwdCmd(interp, argv):
- if len(argv) > 1:
- raise UsageError, 'usage: pwd'
- else:
- return mac.getcwd()
- #
- def RmCmd(interp, argv):
- if len(argv) < 2:
- raise UsageError, 'usage: rm file ...'
- for name in argv[1:]:
- remove(name)
- return ''
- #
- def RmdirCmd(interp, argv):
- if len(argv) < 2:
- raise UsageError, 'usage: rmdir dir ...'
- for name in argv[1:]:
- rmdir(name)
- return ''
- #
- def SyncCmd(interp, argv):
- if len(argv) > 1:
- raise UsageError, 'usage: sync'
- try:
- mac.sync()
- except mac.error, msg:
- raise TclRuntimeError, ('sync failed :', msg)
- #
+ #
+ def ResetVariables(interp):
+ interp.globals['ps1'] = '$ '
+ interp.globals['ps2'] = '> '
+ interp.globals['home'] = mac.getcwd()
+ #
+ def DefineCommands(interp):
+ interp.commands['cd'] = interp.CdCmd
+ interp.commands['grep'] = interp.GrepCmd
+ interp.commands['ls'] = interp.LsCmd
+ interp.commands['mkdir'] = interp.MkdirCmd
+ interp.commands['mv'] = interp.MvCmd
+ interp.commands['pg'] = interp.PgCmd
+ interp.commands['pwd'] = interp.PwdCmd
+ interp.commands['rm'] = interp.RmCmd
+ interp.commands['rmdir'] = interp.RmdirCmd
+ interp.commands['sync'] = interp.SyncCmd
+ #
+ def Reset(interp):
+ interp.ResetVariables()
+ interp.DefineCommands()
+ #
+ def Create(interp):
+ interp = Interpreter.Create(interp) # initialize base class
+ interp.Reset()
+ return interp
+ #
+ # Command-implementing functions
+ #
+ def CdCmd(interp, argv):
+ if len(argv) > 2:
+ raise UsageError, 'usage: cd [dirname]'
+ if len(argv) = 2:
+ chdirto(argv[1])
+ else:
+ chdirto(interp.globals['home'])
+ return ''
+ #
+ def GrepCmd(interp, argv):
+ if len(argv) < 3:
+ raise UsageError, 'usage: grep regexp file ...'
+ import regexp
+ try:
+ prog = regexp.compile(argv[1])
+ except regexp.error, msg:
+ raise TclRuntimeError, \
+ ('grep', argv[1], ': bad regexp :', msg)
+ for file in argv[2:]:
+ grepfile(prog, file)
+ return ''
+ #
+ def LsCmd(interp, argv):
+ if len(argv) < 2:
+ lsdir(':')
+ else:
+ for dirname in argv[1:]:
+ lsdir(dirname)
+ return ''
+ #
+ def MkdirCmd(interp, argv):
+ if len(argv) < 2:
+ raise UsageError, 'usage: mkdir name ...'
+ for name in argv[1:]:
+ makedir(name)
+ return ''
+ #
+ def MvCmd(interp, argv):
+ if len(argv) <> 3:
+ raise UsageError, 'usage: mv src dst'
+ src, dst = argv[1], argv[2]
+ if not exists(src):
+ raise TclRuntimeError, \
+ ('mv', src, dst, ': source does not exist')
+ if exists(dst):
+ raise TclRuntimeError, \
+ ('mv', src, dst, ': destination already exists')
+ try:
+ mac.rename(src, dst)
+ except mac.error, msg:
+ raise TclRuntimeError, \
+ (src, dst, ': rename failed :', msg)
+ return ''
+ #
+ def PgCmd(interp, argv):
+ if len(argv) < 2:
+ raise UsageError, 'usage: page file ...'
+ for name in argv[1:]:
+ pagefile(name)
+ return ''
+ #
+ def PwdCmd(interp, argv):
+ if len(argv) > 1:
+ raise UsageError, 'usage: pwd'
+ else:
+ return mac.getcwd()
+ #
+ def RmCmd(interp, argv):
+ if len(argv) < 2:
+ raise UsageError, 'usage: rm file ...'
+ for name in argv[1:]:
+ remove(name)
+ return ''
+ #
+ def RmdirCmd(interp, argv):
+ if len(argv) < 2:
+ raise UsageError, 'usage: rmdir dir ...'
+ for name in argv[1:]:
+ rmdir(name)
+ return ''
+ #
+ def SyncCmd(interp, argv):
+ if len(argv) > 1:
+ raise UsageError, 'usage: sync'
+ try:
+ mac.sync()
+ except mac.error, msg:
+ raise TclRuntimeError, ('sync failed :', msg)
+ #
def chdirto(dirname):
- try:
- mac.chdir(dirname)
- except mac.error, msg:
- raise TclRuntimeError, (dirname, ': chdir failed :', msg)
+ try:
+ mac.chdir(dirname)
+ except mac.error, msg:
+ raise TclRuntimeError, (dirname, ': chdir failed :', msg)
def grepfile(prog, file):
- try:
- fp = open(file, 'r')
- except RuntimeError, msg:
- raise TclRuntimeError, (file, ': open failed :', msg)
- lineno = 0
- while 1:
- line = fp.readline()
- if not line: break
- lineno = lineno+1
- if prog.exec(line):
- print file+'('+`lineno`+'):', line,
+ try:
+ fp = open(file, 'r')
+ except RuntimeError, msg:
+ raise TclRuntimeError, (file, ': open failed :', msg)
+ lineno = 0
+ while 1:
+ line = fp.readline()
+ if not line: break
+ lineno = lineno+1
+ if prog.exec(line):
+ print file+'('+`lineno`+'):', line,
def lsdir(dirname):
- if not isdir(dirname):
- print dirname, ': no such directory'
- return
- names = mac.listdir(dirname)
- lsfiles(names, dirname)
+ if not isdir(dirname):
+ print dirname, ': no such directory'
+ return
+ names = mac.listdir(dirname)
+ lsfiles(names, dirname)
def lsfiles(names, dirname):
- names = names[:] # Make a copy so we can modify it
- for i in range(len(names)):
- name = names[i]
- if isdir(macpath.cat(dirname, name)):
- names[i] = ':' + name + ':'
- columnize(names)
+ names = names[:] # Make a copy so we can modify it
+ for i in range(len(names)):
+ name = names[i]
+ if isdir(macpath.cat(dirname, name)):
+ names[i] = ':' + name + ':'
+ columnize(names)
def makedir(name):
- if exists(name):
- print name, ': already exists'
- return
- try:
- mac.mkdir(name, 0777)
- except mac.error, msg:
- raise TclRuntimeError, (name, ': mkdir failed :', msg)
+ if exists(name):
+ print name, ': already exists'
+ return
+ try:
+ mac.mkdir(name, 0777)
+ except mac.error, msg:
+ raise TclRuntimeError, (name, ': mkdir failed :', msg)
def pagefile(name):
- import string
- if not isfile(name):
- print name, ': no such file'
- return
- LINES = 24 - 1
- # For THINK C 3.0, make the path absolute:
- # if not macpath.isabs(name):
- # name = macpath.cat(mac.getcwd(), name)
- try:
- fp = open(name, 'r')
- except RuntimeError, msg:
- raise TclRuntimeError, (name, ': open failed :', msg)
- line = fp.readline()
- while line:
- for i in range(LINES):
- print line,
- line = fp.readline()
- if not line: break
- if line:
- try:
- more = raw_input('[more]')
- except (EOFError, KeyboardInterrupt):
- print
- break
- if string.strip(more)[:1] in ('q', 'Q'):
- break
+ import string
+ if not isfile(name):
+ print name, ': no such file'
+ return
+ LINES = 24 - 1
+ # For THINK C 3.0, make the path absolute:
+ # if not macpath.isabs(name):
+ # name = macpath.cat(mac.getcwd(), name)
+ try:
+ fp = open(name, 'r')
+ except RuntimeError, msg:
+ raise TclRuntimeError, (name, ': open failed :', msg)
+ line = fp.readline()
+ while line:
+ for i in range(LINES):
+ print line,
+ line = fp.readline()
+ if not line: break
+ if line:
+ try:
+ more = raw_input('[more]')
+ except (EOFError, KeyboardInterrupt):
+ print
+ break
+ if string.strip(more)[:1] in ('q', 'Q'):
+ break
def remove(name):
- if not isfile(name):
- print name, ': no such file'
- return
- try:
- mac.unlink(name)
- except mac.error, msg:
- raise TclRuntimeError, (name, ': unlink failed :', msg)
+ if not isfile(name):
+ print name, ': no such file'
+ return
+ try:
+ mac.unlink(name)
+ except mac.error, msg:
+ raise TclRuntimeError, (name, ': unlink failed :', msg)
def rmdir(name):
- if not isdir(name):
- raise TclRuntimeError, (name, ': no such directory')
- try:
- mac.rmdir(name)
- except mac.error, msg:
- raise TclRuntimeError, (name, ': rmdir failed :', msg)
+ if not isdir(name):
+ raise TclRuntimeError, (name, ': no such directory')
+ try:
+ mac.rmdir(name)
+ except mac.error, msg:
+ raise TclRuntimeError, (name, ': rmdir failed :', msg)
def printlist(list):
- for word in list:
- print word,
+ for word in list:
+ print word,
def columnize(list):
- import string
- COLUMNS = 80-1
- n = len(list)
- colwidth = maxwidth(list)
- ncols = (COLUMNS + 1) / (colwidth + 1)
- if ncols < 1: ncols = 1
- nrows = (n + ncols - 1) / ncols
- for irow in range(nrows):
- line = ''
- for icol in range(ncols):
- i = irow + nrows*icol
- if 0 <= i < n:
- word = list[i]
- if i+nrows < n:
- word = string.ljust(word, colwidth)
- if icol > 0:
- word = ' ' + word
- line = line + word
- print line
+ import string
+ COLUMNS = 80-1
+ n = len(list)
+ colwidth = maxwidth(list)
+ ncols = (COLUMNS + 1) / (colwidth + 1)
+ if ncols < 1: ncols = 1
+ nrows = (n + ncols - 1) / ncols
+ for irow in range(nrows):
+ line = ''
+ for icol in range(ncols):
+ i = irow + nrows*icol
+ if 0 <= i < n:
+ word = list[i]
+ if i+nrows < n:
+ word = string.ljust(word, colwidth)
+ if icol > 0:
+ word = ' ' + word
+ line = line + word
+ print line
def maxwidth(list):
- width = 0
- for word in list:
- if len(word) > width:
- width = len(word)
- return width
+ width = 0
+ for word in list:
+ if len(word) > width:
+ width = len(word)
+ return width
the_interpreter = ShellInterpreter().Create()
def main():
- Tcl.MainLoop(the_interpreter)
+ Tcl.MainLoop(the_interpreter)
diff --git a/lib/TclUtil.py b/lib/TclUtil.py
index 0990530..fb7b530 100644
--- a/lib/TclUtil.py
+++ b/lib/TclUtil.py
@@ -12,7 +12,7 @@
# For efficiency, the Tcl "tokenizing" routines used pre-compiled
-# regular expressions. This is less readable but should be much faster
+# regular expressions. This is less readable but should be much faster
# than scanning the string a character at a time.
#
# The global variables
@@ -21,9 +21,9 @@
#
# The patterns always
# have the form <something>* so they always match at the start of the
-# search buffer---maybe with the empty string. This makes it possible
+# search buffer---maybe with the empty string. This makes it possible
# to use the expression "_foo_prog.exec(str, i)[0][1]" to find the first
-# character beyond the matched string. Note that this may be beyond the
+# character beyond the matched string. Note that this may be beyond the
# end variable -- where this matters, "min(i, end)" is used.
# Constructs that cannot
@@ -33,19 +33,19 @@
#
# Many regular expressions contain an expression that matches
# a Tcl backslash sequence as a subpart:
-# \\\\C?M?(.|\n)
+# \\\\C?M?(.|\n)
#
# This is a bit hard to
# read because the backslash contained in it must be doubled twice:
# once to get past Python's backslash mechanism, once to get past that
-# of regular expressions. It uses (.|\n) to match absolutely
+# of regular expressions. It uses (.|\n) to match absolutely
# *every character*, becase the MULTILINE regular expression package does
# not accept '\n' as a match for '.'.
#
# There is also a simplification in the pattern for backslashes:
# *any* single character following a backslash is escaped,
# so hex and octal
-# excapes are not scanned fully. The forms \Cx, \Mx and \CMx are
+# excapes are not scanned fully. The forms \Cx, \Mx and \CMx are
# scanned correctly, as these may hide a special character.
# (This does not invalidate the recognition of strings, although the
# match is effectuated in a different way than by the Backslash function.)
@@ -69,28 +69,28 @@ TclMatchingError = 'Tcl matching error'
_varname_prog = regexp.compile('[a-zA-Z0-9_]*')
def FindVarName(str, i, end):
- if i < end and str[i] = '{': return BalanceBraces(str, i, end)
- i = _varname_prog.exec(str, i)[0][1]
- return min(i, end)
+ if i < end and str[i] = '{': return BalanceBraces(str, i, end)
+ i = _varname_prog.exec(str, i)[0][1]
+ return min(i, end)
# Split a list into its elements.
# Return a list of elements (strings).
def SplitList(str):
- i, end = 0, len(str)
- list = []
- while 1:
- i = SkipSpaces(str, i, end)
- if i >= end: break
- j = i
- i = FindNextElement(str, i, end)
- if str[j] = '{' and str[i-1] = '}':
- element = str[j+1:i-1]
- else:
- element = Collapse(str[j:i])
- list.append(element)
- return list
+ i, end = 0, len(str)
+ list = []
+ while 1:
+ i = SkipSpaces(str, i, end)
+ if i >= end: break
+ j = i
+ i = FindNextElement(str, i, end)
+ if str[j] = '{' and str[i-1] = '}':
+ element = str[j+1:i-1]
+ else:
+ element = Collapse(str[j:i])
+ list.append(element)
+ return list
# Find the next element from a list.
@@ -98,13 +98,13 @@ def SplitList(str):
_element_prog = regexp.compile('([^ \t\n\\]+|\\\\C?M?(.|\n))*')
def FindNextElement(str, i, end):
- if i < end and str[i] = '{':
- i = BalanceBraces(str, i, end)
- if i < end and str[i] not in ' \t\n':
- raise TclSyntaxError, 'Garbage after } in list'
- return i
- i = _element_prog.exec(str, i)[0][1]
- return min(i, end)
+ if i < end and str[i] = '{':
+ i = BalanceBraces(str, i, end)
+ if i < end and str[i] not in ' \t\n':
+ raise TclSyntaxError, 'Garbage after } in list'
+ return i
+ i = _element_prog.exec(str, i)[0][1]
+ return min(i, end)
# Copy a string, expanding all backslash sequences.
@@ -112,19 +112,19 @@ def FindNextElement(str, i, end):
_collapse_prog = regexp.compile('(\n|[^\\]+)*')
def Collapse(str):
- if '\\' not in str: return str
- i, end = 0, len(str)
- result = ''
- while i < end:
- j = _collapse_prog.exec(str, i)[0][1]
- j = min(j, end)
- result = result + str[i:j]
- if j >= end: break
- c = str[j]
- if c <> '\\': raise TclAssertError, 'collapse error'
- x, i = Backslash(str, j, end)
- result = result + x
- return result
+ if '\\' not in str: return str
+ i, end = 0, len(str)
+ result = ''
+ while i < end:
+ j = _collapse_prog.exec(str, i)[0][1]
+ j = min(j, end)
+ result = result + str[i:j]
+ if j >= end: break
+ c = str[j]
+ if c <> '\\': raise TclAssertError, 'collapse error'
+ x, i = Backslash(str, j, end)
+ result = result + x
+ return result
# Find the next full command.
@@ -138,25 +138,25 @@ def Collapse(str):
_eol_prog = regexp.compile('[^\n]*')
def FindNextCommand(str, i, end, bracketed):
- i = SkipSpaces(str, i, end)
- if i >= end: return [], end
- if str[i] = '#':
- i = _eol_prog.exec(str, i)
- i = min(i, end)
- if i < end and str[i] = '\n': i = i+1
- return [], i
- if bracketed: terminators = [';']
- else: terminators = [';', '\n']
- list = []
- while i < end:
- j = FindNextWord(str, i, end)
- word = str[i:j]
- if word in terminators:
- i = j
- break
- if word <> '\n': list.append(i, j)
- i = SkipSpaces(str, j, end)
- return list, i
+ i = SkipSpaces(str, i, end)
+ if i >= end: return [], end
+ if str[i] = '#':
+ i = _eol_prog.exec(str, i)
+ i = min(i, end)
+ if i < end and str[i] = '\n': i = i+1
+ return [], i
+ if bracketed: terminators = [';']
+ else: terminators = [';', '\n']
+ list = []
+ while i < end:
+ j = FindNextWord(str, i, end)
+ word = str[i:j]
+ if word in terminators:
+ i = j
+ break
+ if word <> '\n': list.append(i, j)
+ i = SkipSpaces(str, j, end)
+ return list, i
# Find the next word of a command.
@@ -167,26 +167,26 @@ def FindNextCommand(str, i, end, bracketed):
_word_prog = regexp.compile('([^ \t\n;[\\]+|\\\\C?M?(.|\n))*')
def FindNextWord(str, i, end):
- if i >= end: return end
- if str[i] in '{"':
- if str[i] = '{': i = BalanceBraces(str, i, end)
- else: i = BalanceQuotes(str, i, end)
- if i >= end or str[i] in ' \t\n;': return min(i, end)
- raise TclSyntaxError, 'Garbage after } or "'
- begin = i
- while i < end:
- i = _word_prog.exec(str, i)[0][1]
- if i >= end:
- i = end
- break
- c = str[i]
- if c in ' \t': break
- if c in ';\n':
- if i = begin: i = i+1
- break
- if c = '[': i = BalanceBrackets(str, i, end)
- else: raise TclAssertError, 'word error'
- return i
+ if i >= end: return end
+ if str[i] in '{"':
+ if str[i] = '{': i = BalanceBraces(str, i, end)
+ else: i = BalanceQuotes(str, i, end)
+ if i >= end or str[i] in ' \t\n;': return min(i, end)
+ raise TclSyntaxError, 'Garbage after } or "'
+ begin = i
+ while i < end:
+ i = _word_prog.exec(str, i)[0][1]
+ if i >= end:
+ i = end
+ break
+ c = str[i]
+ if c in ' \t': break
+ if c in ';\n':
+ if i = begin: i = i+1
+ break
+ if c = '[': i = BalanceBrackets(str, i, end)
+ else: raise TclAssertError, 'word error'
+ return i
# Parse balanced brackets from str[i:end].
@@ -197,22 +197,22 @@ def FindNextWord(str, i, end):
_brackets_prog = regexp.compile('([^][{\\]+|\n|\\\\C?M?(.|\n))*')
def BalanceBrackets(str, i, end):
- if i >= end or str[i] <> '[':
- raise TclAssertError, 'BalanceBrackets'
- nesting = 0
- while i < end:
- i = _brackets_prog.exec(str, i)[0][1]
- if i >= end: break
- c = str[i]
- if c = '{': i = BalanceBraces(str, i, end)
- else:
- i = i+1
- if c = '[': nesting = nesting + 1
- elif c = ']':
- nesting = nesting - 1
- if nesting = 0: return i
- else: raise TclAssertError, 'brackets error'
- raise TclMatchingError, 'Unmatched bracket ([)'
+ if i >= end or str[i] <> '[':
+ raise TclAssertError, 'BalanceBrackets'
+ nesting = 0
+ while i < end:
+ i = _brackets_prog.exec(str, i)[0][1]
+ if i >= end: break
+ c = str[i]
+ if c = '{': i = BalanceBraces(str, i, end)
+ else:
+ i = i+1
+ if c = '[': nesting = nesting + 1
+ elif c = ']':
+ nesting = nesting - 1
+ if nesting = 0: return i
+ else: raise TclAssertError, 'brackets error'
+ raise TclMatchingError, 'Unmatched bracket ([)'
# Parse balanced braces from str[i:end].
@@ -223,20 +223,20 @@ def BalanceBrackets(str, i, end):
_braces_prog = regexp.compile('([^{}\\]+|\n|\\\\C?M?(.|\n))*')
def BalanceBraces(str, i, end):
- if i >= end or str[i] <> '{':
- raise TclAssertError, 'BalanceBraces'
- nesting = 0
- while i < end:
- i = _braces_prog.exec(str, i)[0][1]
- if i >= end: break
- c = str[i]
- i = i+1
- if c = '{': nesting = nesting + 1
- elif c = '}':
- nesting = nesting - 1
- if nesting = 0: return i
- else: raise TclAssertError, 'braces error'
- raise TclMatchingError, 'Unmatched brace ({)'
+ if i >= end or str[i] <> '{':
+ raise TclAssertError, 'BalanceBraces'
+ nesting = 0
+ while i < end:
+ i = _braces_prog.exec(str, i)[0][1]
+ if i >= end: break
+ c = str[i]
+ i = i+1
+ if c = '{': nesting = nesting + 1
+ elif c = '}':
+ nesting = nesting - 1
+ if nesting = 0: return i
+ else: raise TclAssertError, 'braces error'
+ raise TclMatchingError, 'Unmatched brace ({)'
# Parse double quotes from str[i:end].
@@ -246,11 +246,11 @@ def BalanceBraces(str, i, end):
_quotes_prog = regexp.compile('([^"\\]+|\n|\\\\C?M?(.|\n))*')
def BalanceQuotes(str, i, end):
- if i >= end or str[i] <> '"':
- raise TclAssertError, 'BalanceQuotes'
- i = _quotes_prog.exec(str, i+1)[0][1]
- if i < end and str[i] = '"': return i+1
- raise TclMatchingError, 'Unmatched quote (")'
+ if i >= end or str[i] <> '"':
+ raise TclAssertError, 'BalanceQuotes'
+ i = _quotes_prog.exec(str, i+1)[0][1]
+ if i < end and str[i] = '"': return i+1
+ raise TclMatchingError, 'Unmatched quote (")'
# Static data used by Backslash()
@@ -272,44 +272,44 @@ del c
# this takes only the backslash itself off the string.
def Backslash(str, i, end):
- if i >= end or str[i] <> '\\':
- raise TclAssertError, 'Backslash'
- i = i+1
- if i = end: return '\\', i
- c = str[i]
- i = i+1
- if _bstab.has_key(c): return _bstab[c], i
- if c = 'C':
- if i = end: return '\\', i-1
- c = str[i]
- i = i+1
- if c = 'M':
- if i = end: return '\\', i-2
- c = str[i]
- i = i+1
- x = ord(c) % 040 + 0200
- else:
- x = ord(c) % 040
- return chr(x), i
- elif c = 'M':
- if i = end: return '\\', i-1
- c = str[i]
- i = i+1
- x = ord(c)
- if x < 0200: x = x + 0200
- return chr(x), i
- elif c and c in '0123456789':
- x = ord(c) - ord('0')
- end = min(end, i+2)
- while i < end:
- c = str[i]
- if c not in '0123456789': break
- i = i+1
- x = x*8 + ord(c) - ord('0')
- return ord(x), i
- else:
- # Not something that we recognize
- return '\\', i-1
+ if i >= end or str[i] <> '\\':
+ raise TclAssertError, 'Backslash'
+ i = i+1
+ if i = end: return '\\', i
+ c = str[i]
+ i = i+1
+ if _bstab.has_key(c): return _bstab[c], i
+ if c = 'C':
+ if i = end: return '\\', i-1
+ c = str[i]
+ i = i+1
+ if c = 'M':
+ if i = end: return '\\', i-2
+ c = str[i]
+ i = i+1
+ x = ord(c) % 040 + 0200
+ else:
+ x = ord(c) % 040
+ return chr(x), i
+ elif c = 'M':
+ if i = end: return '\\', i-1
+ c = str[i]
+ i = i+1
+ x = ord(c)
+ if x < 0200: x = x + 0200
+ return chr(x), i
+ elif c and c in '0123456789':
+ x = ord(c) - ord('0')
+ end = min(end, i+2)
+ while i < end:
+ c = str[i]
+ if c not in '0123456789': break
+ i = i+1
+ x = x*8 + ord(c) - ord('0')
+ return ord(x), i
+ else:
+ # Not something that we recognize
+ return '\\', i-1
# Skip over spaces and tabs (but not newlines).
@@ -317,61 +317,61 @@ def Backslash(str, i, end):
_spaces_prog = regexp.compile('[ \t]*')
def SkipSpaces(str, i, end):
- i = _spaces_prog.exec(str, i)[0][1]
- return min(i, end)
+ i = _spaces_prog.exec(str, i)[0][1]
+ return min(i, end)
# Concatenate the elements of a list with intervening spaces.
def Concat(argv):
- result = ''
- sep = ''
- for arg in argv:
- result = result + (sep + arg)
- sep = ' '
- return result
+ result = ''
+ sep = ''
+ for arg in argv:
+ result = result + (sep + arg)
+ sep = ' '
+ return result
# Concatenate list elements, adding braces etc. to make them parseable
# again with SplitList.
def BuildList(argv):
- result = ''
- sep = ''
- for arg in argv:
- arg = AddBraces(arg)
- result = result + (sep + arg)
- sep = ' '
- return result
+ result = ''
+ sep = ''
+ for arg in argv:
+ arg = AddBraces(arg)
+ result = result + (sep + arg)
+ sep = ' '
+ return result
# Add braces around a string if necessary to make it parseable by SplitList.
def AddBraces(str):
- # Special case for empty string
- if str = '': return '{}'
- # See if it contains balanced braces
- res = '{' + str + '}'
- if TryNextElement(res):
- # See if it would survive unquoted
- # XXX should escape [] and $ as well???
- if TryNextElement(str) and Collapse(str) = str: return str
- # No -- return with added braces
- return res
- # Unbalanced braces. Add backslashes before suspect characters
- res = ''
- for c in str:
- if c in '$\\[]{} ;': c = '\\' + c
- elif c = '\n': c = '\\n'
- elif c = '\t': c = '\\t'
- res = res + c
- return res
+ # Special case for empty string
+ if str = '': return '{}'
+ # See if it contains balanced braces
+ res = '{' + str + '}'
+ if TryNextElement(res):
+ # See if it would survive unquoted
+ # XXX should escape [] and $ as well???
+ if TryNextElement(str) and Collapse(str) = str: return str
+ # No -- return with added braces
+ return res
+ # Unbalanced braces. Add backslashes before suspect characters
+ res = ''
+ for c in str:
+ if c in '$\\[]{} ;': c = '\\' + c
+ elif c = '\n': c = '\\n'
+ elif c = '\t': c = '\\t'
+ res = res + c
+ return res
def TryNextElement(str):
- end = len(str)
- try:
- i = FindNextElement(str, 0, end)
- return i = end
- except (TclSyntaxError, TclMatchingError):
- return 0
+ end = len(str)
+ try:
+ i = FindNextElement(str, 0, end)
+ return i = end
+ except (TclSyntaxError, TclMatchingError):
+ return 0
diff --git a/lib/TestCSplit.py b/lib/TestCSplit.py
index b638f81..5da55c4 100644
--- a/lib/TestCSplit.py
+++ b/lib/TestCSplit.py
@@ -6,21 +6,21 @@ from WindowParent import WindowParent
from Buttons import PushButton
def main(n):
- from CSplit import CSplit
-
- the_window = WindowParent().create('TestCSplit', (0, 0))
- the_csplit = CSplit().create(the_window)
-
- for i in range(n):
- the_child = PushButton().define(the_csplit)
- the_child.settext(`(i+n-1)%n+1`)
-
- the_window.realize()
-
- while 1:
- the_event = stdwin.getevent()
- if the_event[0] = WE_CLOSE: break
- the_window.dispatch(the_event)
- the_window.destroy()
+ from CSplit import CSplit
+
+ the_window = WindowParent().create('TestCSplit', (0, 0))
+ the_csplit = CSplit().create(the_window)
+
+ for i in range(n):
+ the_child = PushButton().define(the_csplit)
+ the_child.settext(`(i+n-1)%n+1`)
+
+ the_window.realize()
+
+ while 1:
+ the_event = stdwin.getevent()
+ if the_event[0] = WE_CLOSE: break
+ the_window.dispatch(the_event)
+ the_window.destroy()
main(12)
diff --git a/lib/TransParent.py b/lib/TransParent.py
index a07b4c4..8cee283 100644
--- a/lib/TransParent.py
+++ b/lib/TransParent.py
@@ -3,94 +3,94 @@
# Use this as a base class for objects that are almost transparent.
# Don't use as a base class for parents with multiple children.
-Error = 'TransParent.Error' # Exception
+Error = 'TransParent.Error' # Exception
class ManageOneChild():
- #
- # Upcalls shared with other single-child parents
- #
- def addchild(self, child):
- if self.child:
- raise Error, 'addchild: one child only'
- if not child:
- raise Error, 'addchild: bad child'
- self.child = child
- #
- def delchild(self, child):
- if not self.child:
- raise Error, 'delchild: no child'
- if child <> self.child:
- raise Error, 'delchild: not my child'
- self.child = 0
+ #
+ # Upcalls shared with other single-child parents
+ #
+ def addchild(self, child):
+ if self.child:
+ raise Error, 'addchild: one child only'
+ if not child:
+ raise Error, 'addchild: bad child'
+ self.child = child
+ #
+ def delchild(self, child):
+ if not self.child:
+ raise Error, 'delchild: no child'
+ if child <> self.child:
+ raise Error, 'delchild: not my child'
+ self.child = 0
class TransParent() = ManageOneChild():
- #
- # Calls from creator
- # NB derived classes may add parameters to create()
- #
- def create(self, parent):
- parent.addchild(self)
- self.parent = parent
- self.child = 0 # No child yet
- #
- # Downcalls from parent to child
- #
- def destroy(self):
- del self.parent
- if self.child: self.child.destroy()
- del self.child
- #
- def minsize(self, m):
- if not self.child:
- return 0, 0
- else:
- return self.child.minsize(m)
- def getbounds(self, bounds):
- if not self.child:
- raise Error, 'getbounds w/o child'
- else:
- return self.child.getbounds()
- def setbounds(self, bounds):
- if not self.child:
- raise Error, 'setbounds w/o child'
- else:
- self.child.setbounds(bounds)
- def draw(self, args):
- if self.child:
- self.child.draw(args)
- #
- # Downcalls only made after certain upcalls
- #
- def mouse_down(self, detail):
- if self.child: self.child.mouse_down(detail)
- def mouse_move(self, detail):
- if self.child: self.child.mouse_move(detail)
- def mouse_up(self, detail):
- if self.child: self.child.mouse_up(detail)
- #
- def timer(self):
- if self.child: self.child.timer()
- #
- # Upcalls from child to parent
- #
- def need_mouse(self, child):
- self.parent.need_mouse(self)
- def no_mouse(self, child):
- self.parent.no_mouse(self)
- #
- def need_timer(self, child):
- self.parent.need_timer(self)
- def no_timer(self, child):
- self.parent.no_timer(self)
- #
- def begindrawing(self):
- return self.parent.begindrawing()
- def beginmeasuring(self):
- return self.parent.beginmeasuring()
- #
- def change(self, area):
- self.parent.change(area)
- def scroll(self, args):
- self.parent.scroll(args)
- def settimer(self, itimer):
- self.parent.settimer(itimer)
+ #
+ # Calls from creator
+ # NB derived classes may add parameters to create()
+ #
+ def create(self, parent):
+ parent.addchild(self)
+ self.parent = parent
+ self.child = 0 # No child yet
+ #
+ # Downcalls from parent to child
+ #
+ def destroy(self):
+ del self.parent
+ if self.child: self.child.destroy()
+ del self.child
+ #
+ def minsize(self, m):
+ if not self.child:
+ return 0, 0
+ else:
+ return self.child.minsize(m)
+ def getbounds(self, bounds):
+ if not self.child:
+ raise Error, 'getbounds w/o child'
+ else:
+ return self.child.getbounds()
+ def setbounds(self, bounds):
+ if not sel