Exemple #1
0
def open(title, data):  # Public function to open a table window
    #
    # Set geometry parameters (one day, these may be changeable)
    #
    margin = stdwin.textwidth('  ')
    lineheight = stdwin.lineheight()
    #
    # Geometry calculations
    #
    colstarts = [0]
    totwidth = 0
    maxrows = 0
    for coldata in data:
        # Height calculations
        rows = len(coldata)
        if rows > maxrows: maxrows = rows
        # Width calculations
        width = colwidth(coldata) + margin
        totwidth = totwidth + width
        colstarts.append(totwidth)
    #
    # Calculate document and window height
    #
    docwidth, docheight = totwidth, maxrows * lineheight
    winwidth, winheight = docwidth, docheight
    if winwidth > stdwin.textwidth('n') * 100: winwidth = 0
    if winheight > stdwin.lineheight() * 30: winheight = 0
    #
    # Create the window
    #
    stdwin.setdefwinsize(winwidth, winheight)
    w = gwin.open(title)
    #
    # Set properties and override methods
    #
    w.data = data
    w.margin = margin
    w.lineheight = lineheight
    w.colstarts = colstarts
    w.totwidth = totwidth
    w.maxrows = maxrows
    w.selection = (-1, -1)
    w.lastselection = (-1, -1)
    w.selshown = 0
    w.setdocsize(docwidth, docheight)
    w.draw = draw
    w.mup = mup
    w.arrow = arrow
    #
    # Return
    #
    return w
Exemple #2
0
def open(title, data): # Public function to open a table window
	#
	# Set geometry parameters (one day, these may be changeable)
	#
	margin = stdwin.textwidth('  ')
	lineheight = stdwin.lineheight()
	#
	# Geometry calculations
	#
	colstarts = [0]
	totwidth = 0
	maxrows = 0
	for coldata in data:
		# Height calculations
		rows = len(coldata)
		if rows > maxrows: maxrows = rows
		# Width calculations
		width = colwidth(coldata) + margin
		totwidth = totwidth + width
		colstarts.append(totwidth)
	#
	# Calculate document and window height
	#
	docwidth, docheight = totwidth, maxrows*lineheight
	winwidth, winheight = docwidth, docheight
	if winwidth > stdwin.textwidth('n')*100: winwidth = 0
	if winheight > stdwin.lineheight()*30: winheight = 0
	#
	# Create the window
	#
	stdwin.setdefwinsize(winwidth, winheight)
	w = gwin.open(title)
	#
	# Set properties and override methods
	#
	w.data = data
	w.margin = margin
	w.lineheight = lineheight
	w.colstarts = colstarts
	w.totwidth = totwidth
	w.maxrows = maxrows
	w.selection = (-1, -1)
	w.lastselection = (-1, -1)
	w.selshown = 0
	w.setdocsize(docwidth, docheight)
	w.draw = draw
	w.mup = mup
	w.arrow = arrow
	#
	# Return
	#
	return w
Exemple #3
0
def open(title, data):  # Display a list of texts in a window
    lineheight = stdwin.lineheight()
    h, v = maxlinewidth(data), len(data) * lineheight
    h0, v0 = h + stdwin.textwidth(' '), v + lineheight
    if h0 > stdwin.textwidth(' ') * 80: h0 = 0
    if v0 > stdwin.lineheight() * 24: v0 = 0
    stdwin.setdefwinsize(h0, v0)
    w = gwin.open(title)
    w.setdocsize(h, v)
    w.lineheight = lineheight
    w.data = data
    w.draw = draw
    w.action = action
    w.mup = mup
    return w
Exemple #4
0
def open(title, data): # Display a list of texts in a window
       lineheight = stdwin.lineheight()
       h, v = maxlinewidth(data), len(data)*lineheight
       h0, v0 = h + stdwin.textwidth(' '), v + lineheight
       if h0 > stdwin.textwidth(' ')*80: h0 = 0
       if v0 > stdwin.lineheight()*24: v0 = 0
       stdwin.setdefwinsize(h0, v0)
       w = gwin.open(title)
       w.setdocsize(h, v)
       w.lineheight = lineheight
       w.data = data
       w.draw = draw
       w.action = action
       w.mup = mup
       return w
Exemple #5
0
 def loadnextact(self):
     if not self.acts: return 0
     actors, lines = self.acts[0]
     del self.acts[0]
     prevactor = 0
     for i in range(len(lines)):
         tp, data = lines[i]
         if tp == NOTHING:
             continue
         elif tp in (NEWSCENE, ACT):
             lines[i] = 0, data
         elif tp == TEXT:
             prevactor = actors.index(data[0])
             lines[i] = prevactor + 1, data[1]
         else:
             lines[i] = prevactor + 1, data
     self.lines = lines
     self.actors = [''] + actors
     self.actorlines = [''] * len(self.actors)
     if self.speaker:
         self.speaker.newvoices(len(self.actors) - 1)
     self.prevline = 0
     self.actwidth = 0
     for a in self.actors:
         w = stdwin.textwidth(a)
         if w > self.actwidth:
             self.actwidth = w
     return 1
Exemple #6
0
def main():
    stdwin.setdefwinsize(NCOLS * stdwin.textwidth('12345'), \
       NROWS * stdwin.lineheight() * 3)
    w = stdwin.open('TestColors')
    #
    while 1:
        type, window, detail = stdwin.getevent()
        if type == WE_CLOSE:
            print 'Bye.'
            break
        elif type == WE_SIZE:
            w.change((0, 0), (10000, 10000))
        elif type == WE_DRAW:
            width, height = w.getwinsize()
            d = w.begindrawing()
            for row in range(NROWS):
                for col in range(NCOLS):
                    color = row * NCOLS + col
                    d.setfgcolor(color)
                    p = col * width / NCOLS, row * height / NROWS
                    q = (col+1)*width/NCOLS, \
                     (row+1)*height/NROWS
                    d.paint((p, q))
                    d.setfgcolor(0)
                    d.box((p, q))
                    d.text(p, ` color `)
                    p = p[0], p[1] + d.lineheight()
                    d.setfgcolor(7)
                    d.text(p, ` color `)
            del d
Exemple #7
0
	def loadnextact(self):
		if not self.acts: return 0
		actors, lines = self.acts[0]
		del self.acts[0]
		prevactor = 0
		for i in range(len(lines)):
			tp, data = lines[i]
			if tp == NOTHING:
				continue
			elif tp in (NEWSCENE, ACT):
				lines[i] = 0, data
			elif tp == TEXT:
				prevactor = actors.index(data[0])
				lines[i] = prevactor+1, data[1]
			else:
				lines[i] = prevactor+1, data
		self.lines = lines
		self.actors = [''] + actors
		self.actorlines = [''] * len(self.actors)
		if self.speaker:
			self.speaker.newvoices(len(self.actors)-1)
		self.prevline = 0
		self.actwidth = 0
		for a in self.actors:
			w = stdwin.textwidth(a)
			if w > self.actwidth:
				self.actwidth = w
		return 1
Exemple #8
0
def main():
	stdwin.setdefwinsize(NCOLS * stdwin.textwidth('12345'), \
				NROWS * stdwin.lineheight() * 3)
	w = stdwin.open('TestColors')
	#
	while 1:
		type, window, detail = stdwin.getevent()
		if type == WE_CLOSE:
			print 'Bye.'
			break
		elif type == WE_SIZE:
			w.change((0,0), (10000, 10000))
		elif type == WE_DRAW:
			width, height = w.getwinsize()
			d = w.begindrawing()
			for row in range(NROWS):
				for col in range(NCOLS):
					color = row*NCOLS + col
					d.setfgcolor(color)
					p = col*width/NCOLS, row*height/NROWS
					q = (col+1)*width/NCOLS, \
						(row+1)*height/NROWS
					d.paint((p, q))
					d.setfgcolor(0)
					d.box((p, q))
					d.text(p, `color`)
					p = p[0] , p[1]+ d.lineheight()
					d.setfgcolor(7)
					d.text(p, `color`)
			del d
Exemple #9
0
def openlistwindow(dirname):
	list = posix.listdir(dirname)
	list.sort()
	i = 0
	while i < len(list):
		if list[i] == '.' or list[i] == '..':
			del list[i]
		else:
			i = i+1
	for i in range(len(list)):
		name = list[i]
		if path.isdir(path.join(dirname, name)):
			list[i] = list[i] + '/'
	width = maxwidth(list)
	width = width + stdwin.textwidth(' ')	# XXX X11 stdwin bug workaround
	height = len(list) * stdwin.lineheight()
	stdwin.setdefwinsize(width, min(height, 500))
	w = stdwin.open(dirname)
	stdwin.setdefwinsize(0, 0)
	w.setdocsize(width, height)
	w.drawproc = drawlistwindow
	w.mouse = mouselistwindow
	w.close = closelistwindow
	w.dirname = dirname
	w.list = list
	w.selected = -1
	return w
Exemple #10
0
	def __init__(self):
		self.sourcewindows = {}
		self.framewindows = {}
		bdb.Bdb.__init__(self)
		width = WIDTH*stdwin.textwidth('0')
		height = HEIGHT*stdwin.lineheight()
		stdwin.setdefwinsize(width, height)
		basewin.BaseWindow.__init__(self, '--Stack--')
		self.closed = 0
Exemple #11
0
 def __init__(self):
     self.sourcewindows = {}
     self.framewindows = {}
     bdb.Bdb.__init__(self)
     width = WIDTH * stdwin.textwidth('0')
     height = HEIGHT * stdwin.lineheight()
     stdwin.setdefwinsize(width, height)
     basewin.BaseWindow.__init__(self, '--Stack--')
     self.closed = 0
 def open(self, title):
     stdwin.setfont("7x14")
     self.charwidth = stdwin.textwidth("m")
     self.lineheight = stdwin.lineheight()
     self.docwidth = self.width * self.charwidth
     self.docheight = self.height * self.lineheight
     stdwin.setdefwinsize(self.docwidth + 2, self.docheight + 2)
     stdwin.setdefscrollbars(0, 0)
     self.window = stdwin.open(title)
     self.window.setdocsize(self.docwidth + 2, self.docheight + 2)
Exemple #13
0
 def open(self, title):
     stdwin.setfont('7x14')
     self.charwidth = stdwin.textwidth('m')
     self.lineheight = stdwin.lineheight()
     self.docwidth = self.width * self.charwidth
     self.docheight = self.height * self.lineheight
     stdwin.setdefwinsize(self.docwidth + 2, self.docheight + 2)
     stdwin.setdefscrollbars(0, 0)
     self.window = stdwin.open(title)
     self.window.setdocsize(self.docwidth + 2, self.docheight + 2)
Exemple #14
0
	def define_field(self, name, label, lines, chars):
		self.fieldnames.append(name)
		lh = stdwin.lineheight()
		cw = stdwin.textwidth('m')
		left = 20*cw
		top = self.formheight + 4
		right = left + chars*cw
		bottom = top + lines*lh
		te = None
		self.fields[name] = (label, left, top, right, bottom, te)
		self.formheight = bottom + 2
		self.formwidth = max(self.formwidth, right + 4)
Exemple #15
0
def main():
	global ok
	digits_seen = 0
	thread.start_new_thread(worker, ())
	tw = stdwin.textwidth('0 ')
	lh = stdwin.lineheight()
	stdwin.setdefwinsize(20 * tw, 20 * lh)
	stdwin.setdefscrollbars(0, 1)
	win = stdwin.open('digits of pi')
	options = win.menucreate('Options')
	options.additem('Auto scroll')
	autoscroll = 1
	options.check(0, autoscroll)
	while 1:
		win.settimer(1)
		type, w, detail = stdwin.getevent()
		if type == WE_CLOSE:
			ok = 0
			sys.exit(0)
		elif type == WE_DRAW:
			(left, top), (right, bottom) = detail
			digits_seen = len(digits)
			d = win.begindrawing()
			for i in range(digits_seen):
				h = (i % 20) * tw
				v = (i / 20) * lh
				if top-lh < v < bottom:
					d.text((h, v), digits[i])
			d.close()
		elif type == WE_TIMER:
			n = len(digits)
			if n > digits_seen:
				win.settitle(`n` + ' digits of pi')
				d = win.begindrawing()
				for i in range(digits_seen, n):
					h = (i % 20) * tw
					v = (i / 20) * lh
					d.text((h, v), digits[i])
				d.close()
				digits_seen = n
				height = (v + 20*lh) / (20*lh) * (20*lh)
				win.setdocsize(0, height)
				if autoscroll:
					win.show((0, v), (h+tw, v+lh))
		elif type == WE_MENU:
			menu, item = detail
			if menu == options:
				if item == 0:
					autoscroll = (not autoscroll)
					options.check(0, autoscroll)
def main():
    global ok
    digits_seen = 0
    thread.start_new_thread(worker, ())
    tw = stdwin.textwidth('0 ')
    lh = stdwin.lineheight()
    stdwin.setdefwinsize(20 * tw, 20 * lh)
    stdwin.setdefscrollbars(0, 1)
    win = stdwin.open('digits of pi')
    options = win.menucreate('Options')
    options.additem('Auto scroll')
    autoscroll = 1
    options.check(0, autoscroll)
    while 1:
        win.settimer(1)
        type, w, detail = stdwin.getevent()
        if type == WE_CLOSE:
            ok = 0
            sys.exit(0)
        elif type == WE_DRAW:
            (left, top), (right, bottom) = detail
            digits_seen = len(digits)
            d = win.begindrawing()
            for i in range(digits_seen):
                h = (i % 20) * tw
                v = (i / 20) * lh
                if top - lh < v < bottom:
                    d.text((h, v), digits[i])
            d.close()
        elif type == WE_TIMER:
            n = len(digits)
            if n > digits_seen:
                win.settitle( ` n ` + ' digits of pi')
                d = win.begindrawing()
                for i in range(digits_seen, n):
                    h = (i % 20) * tw
                    v = (i / 20) * lh
                    d.text((h, v), digits[i])
                d.close()
                digits_seen = n
                height = (v + 20 * lh) / (20 * lh) * (20 * lh)
                win.setdocsize(0, height)
                if autoscroll:
                    win.show((0, v), (h + tw, v + lh))
        elif type == WE_MENU:
            menu, item = detail
            if menu == options:
                if item == 0:
                    autoscroll = (not autoscroll)
                    options.check(0, autoscroll)
Exemple #17
0
	def __init__(self, debugger, frame, dict, name):
		self.debugger = debugger
		self.frame = frame # Not used except for identity tests
		self.dict = dict
		self.name = name
		nl = max(MINHEIGHT, len(self.dict) + 5)
		nl = min(nl, MAXHEIGHT)
		width = WIDTH*stdwin.textwidth('0')
		height = nl*stdwin.lineheight()
		stdwin.setdefwinsize(width, height)
		basewin.BaseWindow.__init__(
			  self, '--Frame ' + name + '--')
		# XXX Should use current function name
		self.initeditor()
		self.displaylist = ['>>>', '', '-'*WIDTH]
		self.refreshframe()
Exemple #18
0
 def __init__(self, title, contents):
     self.contents = contents
     self.linecount = countlines(self.contents)
     #
     self.lineheight = lh = stdwin.lineheight()
     self.leftmargin = self.getmargin()
     self.top = 0
     self.rightmargin = 30000  # Infinity
     self.bottom = lh * self.linecount
     #
     width = WIDTH * stdwin.textwidth('0')
     height = lh * min(MAXHEIGHT, self.linecount)
     stdwin.setdefwinsize(width, height)
     basewin.BaseWindow.__init__(self, title)
     #
     self.win.setdocsize(0, self.bottom)
     self.initeditor()
Exemple #19
0
	def __init__(self, title, contents):
		self.contents = contents
		self.linecount = countlines(self.contents)
		#
		self.lineheight = lh = stdwin.lineheight()
		self.leftmargin = self.getmargin()
		self.top = 0
		self.rightmargin = 30000 # Infinity
		self.bottom = lh * self.linecount
		#
		width = WIDTH*stdwin.textwidth('0')
		height = lh*min(MAXHEIGHT, self.linecount)
		stdwin.setdefwinsize(width, height)
		basewin.BaseWindow.__init__(self, title)
		#
		self.win.setdocsize(0, self.bottom)
		self.initeditor()
def main():
	delay = DEF_DELAY
	#
	try:
		thisuser = posix.environ['LOGNAME']
	except:
		thisuser = posix.environ['USER']
	#
	printers = sys.argv[1:]
	if printers:
		# Strip '-P' from printer names just in case
		# the user specified it...
		for i in range(len(printers)):
			if printers[i][:2] == '-P':
				printers[i] = printers[i][2:]
	else:
		if posix.environ.has_key('PRINTER'):
			printers = [posix.environ['PRINTER']]
		else:
			printers = [DEF_PRINTER]
	#
	width = stdwin.textwidth('in')*20
	height = len(printers) * stdwin.lineheight() + 5
	stdwin.setdefwinsize(width, height)
	stdwin.setdefscrollbars(0, 0)
	#
	win = stdwin.open('lpwin')
	#
	win.printers = printers
	win.colors = [c_unknown] * len(printers)
	win.texts = printers[:]
	win.next = 0
	win.delay = DEF_DELAY
	win.thisuser = thisuser
	win.dispatch = lpdispatch
	#
	win.settimer(1)
	#
	mainloop.register(win)
	mainloop.mainloop()
Exemple #21
0
	def getmargin(self):
		return stdwin.textwidth(`self.linecount + 1` + ' ')
Exemple #22
0
def maxwidth(list):
	width = 1
	for name in list:
		w = stdwin.textwidth(name)
		if w > width: width = w
	return width
Exemple #23
0
def itutor(win):
    # The course looks best at 76x22...
    stdwin.setdefwinsize(76 * stdwin.textwidth('x'), 22 * stdwin.lineheight())
    makewindow('ibrowse', 'Help')
Exemple #24
0
def maxwidth(list):
	width = 1
	for name, info in list:
		w = stdwin.textwidth(name + '  ' + info)
		if w > width: width = w
	return width
Exemple #25
0
def isummary(win):
    stdwin.setdefwinsize(76 * stdwin.textwidth('x'), 22 * stdwin.lineheight())
    makewindow('ibrowse', 'Summary')
Exemple #26
0
def start(ref):
	stdwin.setdefscrollbars(0, 1)
	stdwin.setfont(FONT)
	stdwin.setdefwinsize(76*stdwin.textwidth('x'), 22*stdwin.lineheight())
	makewindow('ibrowse', ref)
	mainloop()
Exemple #27
0
def itutor(win):
	# The course looks best at 76x22...
	stdwin.setdefwinsize(76*stdwin.textwidth('x'), 22*stdwin.lineheight())
	makewindow('ibrowse', 'Help')
Exemple #28
0
def colwidth(coldata): # Subroutine to calculate column width
	maxwidth = 0
	for string, action in coldata:
		width = stdwin.textwidth(string)
		if width > maxwidth: maxwidth = width
	return maxwidth
Exemple #29
0
# Pass this program the Holy Grail script on stdin.
Exemple #30
0
def openlistwindow(dirname):
       list = posix.listdir(dirname)
       list.sort()
       i = 0
       while i < len(list):
               if list[i] = '.' or list[i] = '..':
                       del list[i]
               else:
                       i = i+1
       for i in range(len(list)):
               name = list[i]
               if path.isdir(path.cat(dirname, name)):
                       list[i] = list[i] + '/'
       width = maxwidth(list)
       width = width + stdwin.textwidth(' ')   # XXX X11 stdwin bug workaround
       height = len(list) * stdwin.lineheight()
       stdwin.setdefwinsize(width, min(height, 500))
       w = stdwin.open(dirname)
       stdwin.setdefwinsize(0, 0)
       w.setdocsize(width, height)
       w.drawproc = drawlistwindow
       w.mouse = mouselistwindow
       w.close = closelistwindow
       w.dirname = dirname
       w.list = list
       w.selected = -1
       return w

def maxwidth(list):
       width = 1
Exemple #31
0
def start(ref):
    stdwin.setdefscrollbars(0, 1)
    stdwin.setfont(FONT)
    stdwin.setdefwinsize(76 * stdwin.textwidth('x'), 22 * stdwin.lineheight())
    makewindow('ibrowse', ref)
    mainloop()
Exemple #32
0
def maxlinewidth(a): # Compute maximum textwidth of lines in a sequence
       max = 0
       for line in a:
               width = stdwin.textwidth(line)
               if width > max: max = width
       return max
Exemple #33
0
def maxwidth(list):
	width = 1
	for name in list:
		w = stdwin.textwidth(name)
		if w > width: width = w
	return width
Exemple #34
0
def isummary(win):
	stdwin.setdefwinsize(76*stdwin.textwidth('x'), 22*stdwin.lineheight())
	makewindow('ibrowse', 'Summary')
def main():
	#
	# Set a reasonable default window size.
	# If we are using a fixed-width font this will open a 80x24 window;
	# for variable-width fonts we approximate this based on an average
	#
	stdwin.setdefwinsize(40*stdwin.textwidth('in'), 24*stdwin.lineheight())
	#
	# Create global menus (as local variables)
	#
	filemenu = make_file_menu(stdwin)
	editmenu = make_edit_menu(stdwin)
	findmenu = make_find_menu(stdwin)
	#
	# Get the list of files from the command line (maybe none)
	#
	files = sys.argv[1:]
	#
	# Open any files -- errors will be reported but do won't stop us
	#
	for filename in files:
		open_file(filename)
	#
	# If there were no files, or none of them could be opened,
	# put up a dialog asking for a filename
	#
	if not windows:
		try:
			open_dialog(None)
		except KeyboardInterrupt:
			pass		# User cancelled
	#
	# If the dialog was cancelled, create an empty new window
	#
	if not windows:
		new_window(None)
	#
	# Main event loop -- stop when we have no open windows left
	#
	while windows:
		#
		# Get the next event -- ignore interrupts
		#
		try:
			type, window, detail = event = stdwin.getevent()
		except KeyboardInterrupt:
			type, window, detail = event = WE_NONE, None, None
		#
		# Event decoding switch
		#
		if not window:
			pass		# Ignore such events
		elif type == WE_MENU:
			#
			# Execute menu operation
			#
			menu, item = detail
			try:
				menu.actions[item](window)
			except KeyboardInterrupt:
				pass	# User cancelled
		elif type == WE_CLOSE:
			#
			# Close a window
			#
			try:
				close_dialog(window)
			except KeyboardInterrupt:
				pass	# User cancelled
		elif type == WE_SIZE:
			#
			# A window was resized --
			# let the text object recompute the line breaks
			# and change the document size accordingly,
			# so scroll bars will work
			#
			fix_textsize(window)
		elif window.textobject.event(event):
			#
			# The event was eaten by the text object --
			# set the changed flag if not already set
			#
			if type == WE_CHAR or \
			   type == WE_COMMAND and detail in changing:
				window.changed = 1
				fix_docsize(window)
		#
		# Delete all objects that may still reference the window
		# in the event -- this is needed otherwise the window
		# won't actually be closed and may receive further
		# events, which will confuse the event decoder
		#
		del type, window, detail, event
Exemple #36
0
def colwidth(coldata):  # Subroutine to calculate column width
    maxwidth = 0
    for string, action in coldata:
        width = stdwin.textwidth(string)
        if width > maxwidth: maxwidth = width
    return maxwidth
Exemple #37
0
def maxlinewidth(a):  # Compute maximum textwidth of lines in a sequence
    max = 0
    for line in a:
        width = stdwin.textwidth(line)
        if width > max: max = width
    return max
Exemple #38
0
def maxwidth(list):
    width = 1
    for name, info in list:
        w = stdwin.textwidth(name + '  ' + info)
        if w > width: width = w
    return width
Exemple #39
0
def openlistwindow(dirname):
	list = posix.listdir(dirname)
	list.sort()
	i = 0
	while i < len(list):
		if list[i] = '.' or list[i] = '..':
			del list[i]
		else:
			i = i+1
	for i in range(len(list)):
		name = list[i]
		if path.isdir(path.cat(dirname, name)):
			list[i] = list[i] + '/'
	width = maxwidth(list)
	width = width + stdwin.textwidth(' ')	# XXX X11 stdwin bug workaround
	height = len(list) * stdwin.lineheight()
	stdwin.setdefwinsize(width, min(height, 500))
	w = stdwin.open(dirname)
	stdwin.setdefwinsize(0, 0)
	w.setdocsize(width, height)
	w.drawproc = drawlistwindow
	w.mouse = mouselistwindow
	w.close = closelistwindow
	w.dirname = dirname
	w.list = list
	w.selected = -1
	return w

def maxwidth(list):
	width = 1
Exemple #40
0
	def getmargin(self):
		return stdwin.textwidth('[' + `self.linecount+1` + ']->B ')
Exemple #41
0
	def initeditor(self):
		r = (stdwin.textwidth('>>> '), 0), (30000, stdwin.lineheight())
		self.editor = self.win.textcreate(r)