* Got entirely rid of path.py.

* Many modules: fixes for new, stricter, argument passing rules
  (most changes were automatic ones -- not all of this is tested!).
* gwin.py: now uses mainloop.py for its main loop and window admin.
* mainloop.py: always call dispatch() with event as a tuple!
* Fix bug in pdb's 'clear' command -- don't set the bpt but clear it!
This commit is contained in:
Guido van Rossum 1992-12-14 12:57:56 +00:00
parent a8993cfe16
commit 89a78697b8
41 changed files with 208 additions and 228 deletions

View file

@ -30,7 +30,7 @@ class AbstractParent:
def getwindow(self): return unimpl() # Only for very special cases
#
def change(self, area): unimpl()
def scroll(self, (area, (dh, dv))): unimpl()
def scroll(self, area, (dh, dv)): unimpl()
def settimer(self, itimer): unimpl()
class AbstractChild:
@ -40,10 +40,10 @@ class AbstractChild:
def destroy(self): unimpl()
#
def realize(self): return unimpl()
def getminsize(self, (m, (width, height))): return unimpl()
def getminsize(self, m, (width, height)): return unimpl()
def getbounds(self): return unimpl()
def setbounds(self, bounds): unimpl()
def draw(self, (d, area)): unimpl()
def draw(self, d, area): unimpl()
#
# Downcalls only made after certain upcalls
#

View file

@ -2,13 +2,13 @@ from TransParent import TransParent
class BoxParent(TransParent):
#
def create(self, (parent, (dh, dv))):
def create(self, parent, (dh, dv)):
self = TransParent.create(self, parent)
self.dh = dh
self.dv = dv
return self
#
def getminsize(self, (m, (width, height))):
def getminsize(self, m, (width, height)):
width = max(0, width - 2*self.dh)
height = max(0, height - 2*self.dv)
width, height = self.child.getminsize(m, (width, height))

View file

@ -35,7 +35,7 @@ class LabelAppearance:
#
# Size enquiry
#
def getminsize(self, (m, (width, height))):
def getminsize(self, m, (width, height)):
width = max(width, m.textwidth(self.text) + 6)
height = max(height, m.lineheight() + 6)
return width, height
@ -108,8 +108,8 @@ class LabelAppearance:
d.erase(self.bounds)
self.draw(d, self.bounds)
#
def draw(self, (d, area)):
area = _rect.intersect(area, self.bounds)
def draw(self, d, area):
area = _rect.intersect([area, self.bounds])
if area == _rect.empty:
return
d.cliprect(area)
@ -145,7 +145,7 @@ class LabelAppearance:
class StrutAppearance(LabelAppearance):
#
def getminsize(self, (m, (width, height))):
def getminsize(self, m, (width, height)):
height = max(height, m.lineheight() + 6)
return width, height
#
@ -175,7 +175,7 @@ class ButtonAppearance(LabelAppearance):
#
class CheckAppearance(LabelAppearance):
#
def getminsize(self, (m, (width, height))):
def getminsize(self, m, (width, height)):
minwidth = m.textwidth(self.text) + 6
minheight = m.lineheight() + 6
width = max(width, minwidth + minheight + m.textwidth(' '))
@ -382,7 +382,7 @@ class Define:
def destroy(self):
self.parent = 0
#
def definetext(self, (parent, text)):
def definetext(self, parent, text):
self = self.define(parent)
self.settext(text)
return self

View file

@ -9,7 +9,7 @@ from Split import Split
class CSplit(Split):
#
def getminsize(self, (m, (width, height))):
def getminsize(self, m, (width, height)):
# 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
@ -65,5 +65,5 @@ class CSplit(Split):
right, bottom = \
left + child_width, \
top + child_height
child.setbounds((left, top), (right, bottom))
child.setbounds(((left, top), (right, bottom)))
#

View file

@ -11,7 +11,7 @@ from HVSplit import HSplit, VSplit
class DirList(VSplit):
#
def create(self, (parent, dirname)):
def create(self, parent, dirname):
self = VSplit.create(self, parent)
names = os.listdir(dirname)
for name in names:

View file

@ -20,7 +20,7 @@ class FormSplit(Split):
self.last_child = None
return Split.create(self, parent)
#
def getminsize(self, (m, sugg_size)):
def getminsize(self, m, sugg_size):
max_width, max_height = 0, 0
for c in self.children:
c.form_width, c.form_height = c.getminsize(m, (0, 0))
@ -38,9 +38,9 @@ class FormSplit(Split):
for c in self.children:
left, top = c.form_left + fleft, c.form_top + ftop
right, bottom = left + c.form_width, top + c.form_height
c.setbounds((left, top), (right, bottom))
c.setbounds(((left, top), (right, bottom)))
#
def placenext(self, (left, top)):
def placenext(self, left, top):
self.next_left = left
self.next_top = top
self.last_child = None

View file

@ -9,13 +9,13 @@ from Split import Split
class HVSplit(Split):
#
def create(self, (parent, hv)):
def create(self, parent, hv):
# hv is 0 for HSplit, 1 for VSplit
self = Split.create(self, parent)
self.hv = hv
return self
#
def getminsize(self, (m, sugg_size)):
def getminsize(self, m, sugg_size):
hv, vh = self.hv, 1 - self.hv
size = [0, 0]
sugg_size = [sugg_size[0], sugg_size[1]]
@ -46,8 +46,8 @@ class HVSplit(Split):
corner = [0, 0]
corner[vh] = end[vh]
corner[hv] = origin[hv] + size[hv]
c.setbounds((origin[0], origin[1]), \
(corner[0], corner[1]))
c.setbounds(((origin[0], origin[1]), \
(corner[0], corner[1])))
origin[hv] = corner[hv]
# XXX stretch
# XXX too-small

View file

@ -12,7 +12,7 @@ class HistogramAppearance(LabelAppearance, Define):
self.scale = (0, 100)
return self
#
def setdata(self, (ydata, scale)):
def setdata(self, ydata, scale):
self.ydata = ydata
self.scale = scale # (min, max)
self.parent.change(self.bounds)

View file

@ -69,12 +69,12 @@ class DragSliderAppearance(ButtonAppearance):
def sethook(self, hook):
self.hook = hook
#
def setminvalmax(self, (min, val, max)):
def setminvalmax(self, min, val, max):
self.min = min
self.max = max
self.setval(val)
#
def settexts(self, (pretext, postext)):
def settexts(self, pretext, postext):
self.pretext = pretext
self.postext = postext
self.recalctext()
@ -95,7 +95,7 @@ class DragSliderAppearance(ButtonAppearance):
#
class DragSlider(DragSliderReactivity, DragSliderAppearance, Define):
def definetext(self, (parent, text)):
def definetext(self, parent, text):
raise RuntimeError, 'DragSlider.definetext() not supported'
@ -108,7 +108,7 @@ class _StepButton(PushButton):
return self
def setstep(self, step):
self.step = step
def definetextstep(self, (parent, text, step)):
def definetextstep(self, parent, text, step):
self = self.definetext(parent, text)
self.setstep(step)
return self
@ -145,7 +145,7 @@ class ComplexSlider(HSplit):
#
# Override HSplit methods
#
def getminsize(self, (m, (width, height))):
def getminsize(self, m, (width, height)):
w1, h1 = self.downbutton.getminsize(m, (0, height))
w3, h3 = self.upbutton.getminsize(m, (0, height))
w1 = max(w1, h1)
@ -156,10 +156,10 @@ class ComplexSlider(HSplit):
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))
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
#

View file

@ -5,7 +5,7 @@ from Histogram import Histogram
class Soundogram(Histogram):
#
def define(self, (win, chunk)):
def define(self, win, chunk):
width, height = corner = win.getwinsize()
bounds = (0, 0), corner
self.chunk = chunk

View file

@ -39,7 +39,7 @@ class Split:
self.mouse_focus = None
self.keybd_focus = None
#
def getminsize(self, (m, (width, height))):
def getminsize(self, m, (width, height)):
return unimpl() # Should ask children
def getbounds(self):
return unimpl()

View file

@ -8,7 +8,7 @@ from Buttons import LabelAppearance, NoReactivity
class StripChart(LabelAppearance, NoReactivity):
#
def define(self, (parent, scale)):
def define(self, parent, scale):
self.parent = parent
parent.addchild(self)
self.init_appearance()
@ -49,8 +49,8 @@ class StripChart(LabelAppearance, NoReactivity):
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)
def draw(self, d, area):
area = rect.intersect([area, self.bounds])
if area == rect.empty:
return
d.cliprect(area)

View file

@ -7,7 +7,7 @@ from stdwinevents import *
class TextEdit:
#
def create(self, (parent, (cols, rows))):
def create(self, parent, (cols, rows)):
parent.addchild(self)
self.parent = parent
self.cols = cols
@ -18,7 +18,7 @@ class TextEdit:
self.dh = self.dv = 0
return self
#
def createboxed(self, (parent, (cols, rows), (dh, dv))):
def createboxed(self, parent, (cols, rows), (dh, dv)):
self = self.create(parent, (cols, rows))
self.dh = max(0, dh)
self.dv = max(0, dv)
@ -37,7 +37,7 @@ class TextEdit:
del self.editor
del self.window
#
def getminsize(self, (m, (width, height))):
def getminsize(self, m, (width, height)):
width = max(0, width - 2*self.dh)
height = max(0, height - 2*self.dv)
if width > 0 and self.editor:
@ -96,7 +96,7 @@ class TextEdit:
self.parent.need_keybd(self)
self.parent.need_altdraw(self)
#
def draw(self, (d, area)):
def draw(self, d, area):
if self.dh and self.dv:
d.box(self.bounds)
#
@ -114,7 +114,7 @@ class TextEdit:
def mouse_up(self, detail):
x = self.editor.event(WE_MOUSE_UP, self.window, detail)
#
def keybd(self, (type, detail)):
def keybd(self, type, detail):
x = self.editor.event(type, self.window, detail)
#
def activate(self):

View file

@ -14,7 +14,7 @@ Error = 'WindowParent.Error' # Exception
class WindowParent(ManageOneChild):
#
def create(self, (title, size)):
def create(self, title, size):
self.title = title
self.size = size # (width, height)
self._reset()
@ -47,7 +47,7 @@ class WindowParent(ManageOneChild):
def close_trigger(self):
if self.close_hook: self.close_hook(self)
#
def menu_trigger(self, (menu, item)):
def menu_trigger(self, menu, item):
if self.menu_hook:
self.menu_hook(self, menu, item)
#
@ -94,7 +94,7 @@ class WindowParent(ManageOneChild):
width = self.size[0]
if self.vbar:
height = self.size[1]
self.child.setbounds((0, 0), (width, height))
self.child.setbounds(((0, 0), (width, height)))
self.child.realize()
self.win.dispatch = self.dispatch
mainloop.register(self.win)
@ -109,7 +109,7 @@ class WindowParent(ManageOneChild):
width = self.size[0]
if self.vbar:
height = self.size[1]
self.child.setbounds((0, 0), (width, height))
self.child.setbounds(((0, 0), (width, height)))
# Force a redraw of the entire window:
self.win.change((0, 0), self.size)
#

View file

@ -13,7 +13,7 @@ class formatter:
# Pass the window's drawing object, and left, top, right
# coordinates of the drawing space as arguments.
#
def init(self, (d, left, top, right)):
def init(self, d, left, top, right):
self.d = d # Drawing object
self.left = left # Left margin
self.right = right # Right margin
@ -50,10 +50,10 @@ class formatter:
# of the current font's space width.
# (Two variations: one without, one with explicit stretch factor.)
#
def addword(self, (word, spacefactor)):
def addword(self, word, spacefactor):
self.addwordstretch(word, spacefactor, spacefactor)
#
def addwordstretch(self, (word, spacefactor, stretchfactor)):
def addwordstretch(self, word, spacefactor, stretchfactor):
width = self.d.textwidth(word)
if width > self.avail_width:
self._flush(1)

View file

@ -2,16 +2,11 @@
# Generic stdwin windows
# This is used as a base class from which to derive other window types.
# The mainloop() function here is an event dispatcher for all window types.
# XXX This is really obsoleted by "mainloop.py".
# XXX Also you should to it class-oriented...
# XXX DON'T USE THIS CODE ANY MORE! It is ages old!
import stdwin, stdwinq
from stdwinevents import *
windows = [] # List of open windows
from mainloop import mainloop, register, unregister, windows
# Open a window
@ -37,16 +32,11 @@ def open(title): # Open a generic window
w.backspace = backspace
w.arrow = arrow
w.kleft = w.kup = w.kright = w.kdown = nop
windows.append(w)
w.dispatch = treatevent
register(w)
return w
# Generic event dispatching
def mainloop(): # Handle events until no windows left
while windows:
treatevent(stdwinq.getevent())
def treatevent(e): # Handle a stdwin event
type, w, detail = e
if type == WE_DRAW:
@ -95,10 +85,9 @@ def treatcommand(w, type): # Handle a we_command event
# Methods
def close(w): # Close method
for i in range(len(windows)):
if windows[i] is w:
del windows[i]
break
unregister(w)
del w.close # Delete our close function
w.close() # Call the close method
def arrow(w, detail): # Arrow key method
if detail == WC_LEFT:
@ -118,4 +107,4 @@ def enter(w): w.char(w, '\n') # 'return' is a Python reserved word
def backspace(w): w.char(w, '\b')
def m2down(w, detail): w.mdown(w, detail)
def m2up(w, detail): w.mup(w, detail)
def nop(args): pass
def nop(*args): pass

View file

@ -23,7 +23,7 @@ last_window = None
def register(win):
# First test the dispatch function by passing it a null event --
# this catches registration of unconforming windows.
win.dispatch(WE_NULL, win, None)
win.dispatch((WE_NULL, win, None))
if win not in windows:
windows.append(win)