* 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:
parent
a8993cfe16
commit
89a78697b8
|
@ -217,8 +217,9 @@ class Bdb: # Basic Debugger
|
|||
|
||||
#
|
||||
|
||||
def format_stack_entry(self, (frame, lineno)):
|
||||
def format_stack_entry(self, frame_lineno):
|
||||
import codehack, linecache, repr, string
|
||||
frame, lineno = frame_lineno
|
||||
filename = frame.f_code.co_filename
|
||||
s = filename + '(' + `lineno` + ')'
|
||||
s = s + codehack.getcodename(frame.f_code)
|
||||
|
|
158
Lib/dircmp.py
158
Lib/dircmp.py
|
@ -13,46 +13,46 @@ from stat import *
|
|||
#
|
||||
class dircmp:
|
||||
#
|
||||
def new(dd, (a, b)): # Initialize
|
||||
dd.a = a
|
||||
dd.b = b
|
||||
# Properties that caller may change before calling dd.run():
|
||||
dd.hide = [os.curdir, os.pardir] # Names never to be shown
|
||||
dd.ignore = ['RCS', 'tags'] # Names ignored in comparison
|
||||
def new(self, a, b): # Initialize
|
||||
self.a = a
|
||||
self.b = b
|
||||
# Properties that caller may change before calling self.run():
|
||||
self.hide = [os.curdir, os.pardir] # Names never to be shown
|
||||
self.ignore = ['RCS', 'tags'] # Names ignored in comparison
|
||||
#
|
||||
return dd
|
||||
return self
|
||||
#
|
||||
def run(dd): # Compare everything except common subdirectories
|
||||
dd.a_list = filter(dircache.listdir(dd.a), dd.hide)
|
||||
dd.b_list = filter(dircache.listdir(dd.b), dd.hide)
|
||||
dd.a_list.sort()
|
||||
dd.b_list.sort()
|
||||
dd.phase1()
|
||||
dd.phase2()
|
||||
dd.phase3()
|
||||
def run(self): # Compare everything except common subdirectories
|
||||
self.a_list = filter(dircache.listdir(self.a), self.hide)
|
||||
self.b_list = filter(dircache.listdir(self.b), self.hide)
|
||||
self.a_list.sort()
|
||||
self.b_list.sort()
|
||||
self.phase1()
|
||||
self.phase2()
|
||||
self.phase3()
|
||||
#
|
||||
def phase1(dd): # Compute common names
|
||||
dd.a_only = []
|
||||
dd.common = []
|
||||
for x in dd.a_list:
|
||||
if x in dd.b_list:
|
||||
dd.common.append(x)
|
||||
def phase1(self): # Compute common names
|
||||
self.a_only = []
|
||||
self.common = []
|
||||
for x in self.a_list:
|
||||
if x in self.b_list:
|
||||
self.common.append(x)
|
||||
else:
|
||||
dd.a_only.append(x)
|
||||
self.a_only.append(x)
|
||||
#
|
||||
dd.b_only = []
|
||||
for x in dd.b_list:
|
||||
if x not in dd.common:
|
||||
dd.b_only.append(x)
|
||||
self.b_only = []
|
||||
for x in self.b_list:
|
||||
if x not in self.common:
|
||||
self.b_only.append(x)
|
||||
#
|
||||
def phase2(dd): # Distinguish files, directories, funnies
|
||||
dd.common_dirs = []
|
||||
dd.common_files = []
|
||||
dd.common_funny = []
|
||||
def phase2(self): # Distinguish files, directories, funnies
|
||||
self.common_dirs = []
|
||||
self.common_files = []
|
||||
self.common_funny = []
|
||||
#
|
||||
for x in dd.common:
|
||||
a_path = os.path.join(dd.a, x)
|
||||
b_path = os.path.join(dd.b, x)
|
||||
for x in self.common:
|
||||
a_path = os.path.join(self.a, x)
|
||||
b_path = os.path.join(self.b, x)
|
||||
#
|
||||
ok = 1
|
||||
try:
|
||||
|
@ -70,74 +70,74 @@ class dircmp:
|
|||
a_type = S_IFMT(a_stat[ST_MODE])
|
||||
b_type = S_IFMT(b_stat[ST_MODE])
|
||||
if a_type <> b_type:
|
||||
dd.common_funny.append(x)
|
||||
self.common_funny.append(x)
|
||||
elif S_ISDIR(a_type):
|
||||
dd.common_dirs.append(x)
|
||||
self.common_dirs.append(x)
|
||||
elif S_ISREG(a_type):
|
||||
dd.common_files.append(x)
|
||||
self.common_files.append(x)
|
||||
else:
|
||||
dd.common_funny.append(x)
|
||||
self.common_funny.append(x)
|
||||
else:
|
||||
dd.common_funny.append(x)
|
||||
self.common_funny.append(x)
|
||||
#
|
||||
def phase3(dd): # Find out differences between common files
|
||||
xx = cmpfiles(dd.a, dd.b, dd.common_files)
|
||||
dd.same_files, dd.diff_files, dd.funny_files = xx
|
||||
def phase3(self): # Find out differences between common files
|
||||
xx = cmpfiles(self.a, self.b, self.common_files)
|
||||
self.same_files, self.diff_files, self.funny_files = xx
|
||||
#
|
||||
def phase4(dd): # Find out differences between common subdirectories
|
||||
def phase4(self): # Find out differences between common subdirectories
|
||||
# A new dircmp object is created for each common subdirectory,
|
||||
# these are stored in a dictionary indexed by filename.
|
||||
# The hide and ignore properties are inherited from the parent
|
||||
dd.subdirs = {}
|
||||
for x in dd.common_dirs:
|
||||
a_x = os.path.join(dd.a, x)
|
||||
b_x = os.path.join(dd.b, x)
|
||||
dd.subdirs[x] = newdd = dircmp().new(a_x, b_x)
|
||||
newdd.hide = dd.hide
|
||||
newdd.ignore = dd.ignore
|
||||
self.subdirs = {}
|
||||
for x in self.common_dirs:
|
||||
a_x = os.path.join(self.a, x)
|
||||
b_x = os.path.join(self.b, x)
|
||||
self.subdirs[x] = newdd = dircmp().new(a_x, b_x)
|
||||
newdd.hide = self.hide
|
||||
newdd.ignore = self.ignore
|
||||
newdd.run()
|
||||
#
|
||||
def phase4_closure(dd): # Recursively call phase4() on subdirectories
|
||||
dd.phase4()
|
||||
for x in dd.subdirs.keys():
|
||||
dd.subdirs[x].phase4_closure()
|
||||
def phase4_closure(self): # Recursively call phase4() on subdirectories
|
||||
self.phase4()
|
||||
for x in self.subdirs.keys():
|
||||
self.subdirs[x].phase4_closure()
|
||||
#
|
||||
def report(dd): # Print a report on the differences between a and b
|
||||
def report(self): # Print a report on the differences between a and b
|
||||
# Assume that phases 1 to 3 have been executed
|
||||
# Output format is purposely lousy
|
||||
print 'diff', dd.a, dd.b
|
||||
if dd.a_only:
|
||||
print 'Only in', dd.a, ':', dd.a_only
|
||||
if dd.b_only:
|
||||
print 'Only in', dd.b, ':', dd.b_only
|
||||
if dd.same_files:
|
||||
print 'Identical files :', dd.same_files
|
||||
if dd.diff_files:
|
||||
print 'Differing files :', dd.diff_files
|
||||
if dd.funny_files:
|
||||
print 'Trouble with common files :', dd.funny_files
|
||||
if dd.common_dirs:
|
||||
print 'Common subdirectories :', dd.common_dirs
|
||||
if dd.common_funny:
|
||||
print 'Common funny cases :', dd.common_funny
|
||||
print 'diff', self.a, self.b
|
||||
if self.a_only:
|
||||
print 'Only in', self.a, ':', self.a_only
|
||||
if self.b_only:
|
||||
print 'Only in', self.b, ':', self.b_only
|
||||
if self.same_files:
|
||||
print 'Identical files :', self.same_files
|
||||
if self.diff_files:
|
||||
print 'Differing files :', self.diff_files
|
||||
if self.funny_files:
|
||||
print 'Trouble with common files :', self.funny_files
|
||||
if self.common_dirs:
|
||||
print 'Common subdirectories :', self.common_dirs
|
||||
if self.common_funny:
|
||||
print 'Common funny cases :', self.common_funny
|
||||
#
|
||||
def report_closure(dd): # Print reports on dd and on subdirs
|
||||
def report_closure(self): # Print reports on self and on subdirs
|
||||
# If phase 4 hasn't been done, no subdir reports are printed
|
||||
dd.report()
|
||||
self.report()
|
||||
try:
|
||||
x = dd.subdirs
|
||||
x = self.subdirs
|
||||
except AttributeError:
|
||||
return # No subdirectories computed
|
||||
for x in dd.subdirs.keys():
|
||||
for x in self.subdirs.keys():
|
||||
print
|
||||
dd.subdirs[x].report_closure()
|
||||
self.subdirs[x].report_closure()
|
||||
#
|
||||
def report_phase4_closure(dd): # Report and do phase 4 recursively
|
||||
dd.report()
|
||||
dd.phase4()
|
||||
for x in dd.subdirs.keys():
|
||||
def report_phase4_closure(self): # Report and do phase 4 recursively
|
||||
self.report()
|
||||
self.phase4()
|
||||
for x in self.subdirs.keys():
|
||||
print
|
||||
dd.subdirs[x].report_phase4_closure()
|
||||
self.subdirs[x].report_phase4_closure()
|
||||
|
||||
|
||||
# Compare common files in two directories.
|
||||
|
|
|
@ -208,7 +208,7 @@ def _parse_fd_form(file, name):
|
|||
class _newobj:
|
||||
def init(self):
|
||||
return self
|
||||
def add(self, (name, value)):
|
||||
def add(self, name, value):
|
||||
self.__dict__[name] = value
|
||||
def make(self, dict):
|
||||
for name in dict.keys():
|
||||
|
@ -299,9 +299,9 @@ def _parse_object(file):
|
|||
if datum == FORMLINE:
|
||||
file.seek(pos)
|
||||
return obj
|
||||
if type(datum) <> type(()):
|
||||
if type(datum) <> type(()) or len(datum) <> 2:
|
||||
raise error, 'Parse error, illegal line in object: '+datum
|
||||
obj.add(datum)
|
||||
obj.add(datum[0], datum[1])
|
||||
|
||||
#################################################################
|
||||
# Part 2 - High-level object/form creation routines #
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)))
|
||||
#
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
#
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class mutex:
|
|||
# If the mutex is already locked, place function and argument
|
||||
# in the queue.
|
||||
#
|
||||
def lock(self, (function, argument)):
|
||||
def lock(self, function, argument):
|
||||
if self.testandset():
|
||||
function(argument)
|
||||
else:
|
||||
|
|
|
@ -105,7 +105,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
print '*** Error in argument:', `arg`
|
||||
return
|
||||
filename = self.curframe.f_code.co_filename
|
||||
err = self.set_break(filename, lineno)
|
||||
err = self.clear_break(filename, lineno)
|
||||
if err: print '***', err
|
||||
do_cl = do_clear # 'c' is already an abbreviation for 'continue'
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ def _parse_fd_form(file, name):
|
|||
class _newobj:
|
||||
def init(self):
|
||||
return self
|
||||
def add(self, (name, value)):
|
||||
def add(self, name, value):
|
||||
self.__dict__[name] = value
|
||||
def make(self, dict):
|
||||
for name in dict.keys():
|
||||
|
@ -299,9 +299,9 @@ def _parse_object(file):
|
|||
if datum == FORMLINE:
|
||||
file.seek(pos)
|
||||
return obj
|
||||
if type(datum) <> type(()):
|
||||
if type(datum) <> type(()) or len(datum) <> 2:
|
||||
raise error, 'Parse error, illegal line in object: '+datum
|
||||
obj.add(datum)
|
||||
obj.add(datum[0], datum[1])
|
||||
|
||||
#################################################################
|
||||
# Part 2 - High-level object/form creation routines #
|
||||
|
|
|
@ -34,7 +34,7 @@ class scheduler:
|
|||
#
|
||||
# Initialize a new instance, passing the time and delay functions
|
||||
#
|
||||
def init(self, (timefunc, delayfunc)):
|
||||
def init(self, timefunc, delayfunc):
|
||||
self.queue = []
|
||||
self.timefunc = timefunc
|
||||
self.delayfunc = delayfunc
|
||||
|
@ -44,14 +44,15 @@ class scheduler:
|
|||
# Returns an ID for the event which can be used
|
||||
# to remove it, if necessary.
|
||||
#
|
||||
def enterabs(self, event):
|
||||
def enterabs(self, time, priority, action, argument):
|
||||
event = time, priority, action, argument
|
||||
bisect.insort(self.queue, event)
|
||||
return event # The ID
|
||||
#
|
||||
# A variant that specifies the time as a relative time.
|
||||
# This is actually the more commonly used interface.
|
||||
#
|
||||
def enter(self, (delay, priority, action, argument)):
|
||||
def enter(self, delay, priority, action, argument):
|
||||
time = self.timefunc() + delay
|
||||
return self.enterabs(time, priority, action, argument)
|
||||
#
|
||||
|
@ -95,6 +96,6 @@ class scheduler:
|
|||
self.delayfunc(time - now)
|
||||
else:
|
||||
del q[0]
|
||||
void = action(argument)
|
||||
void = apply(action, argument)
|
||||
self.delayfunc(0) # Let other threads run
|
||||
#
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)))
|
||||
#
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
#
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue