def __init__(self): if macspeech: self.speaker = MacSpeaker() else: self.speaker = None sys.stdin = open('SCRIPT', 'r') self.acts = readscript(sys.stdin) maxactor = 0 for actorlist, actdata in self.acts: if len(actorlist) > maxactor: maxactor = len(actorlist) if not self.loadnextact(): print 'No acts to play!' raise done self.lh = stdwin.lineheight() self.winheight = (maxactor + 2) * self.lh stdwin.setdefwinsize(WINWIDTH, self.winheight) self.win = stdwin.open('The Play') self.win.setdocsize(WINWIDTH, self.winheight) self.win.change(((0, 0), (WINWIDTH, self.winheight))) self.menu = self.win.menucreate('Play') self.menu.additem('Faster', '+') self.menu.additem('Slower', '-') self.menu.additem('Quit', 'Q') self.speed = 4
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
def handle_server_message(*args): data, clientaddr = server_socket.recvfrom(1024) words = string.split(data) if len(words) < 2: print 'Bad message from', clientaddr[0], ':', ` data ` return wname = words[0] function = words[1] try: meth = getattr(WWWWindow, 'msg_' + function) except AttributeError: print 'Bad function', `function`, 'in message from', \ clientaddr[0], ':', `data` return ##print 'Message from', clientaddr[0], ':', `data` new = 0 for w in allwindows: if w.server_name == wname: break else: print 'Creating new window named', ` wname ` stdwin.setdefwinsize(0, 0) w = WWWWindow() w.server_name = wname new = 1 try: getattr(w, 'msg_' + function)(words[2:], clientaddr) except: print '***', sys.exc_type, ':', ` sys.exc_value `
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
def __init__(self): if macspeech: self.speaker = MacSpeaker() else: self.speaker = None sys.stdin = open('SCRIPT', 'r') self.acts = readscript(sys.stdin) maxactor = 0 for actorlist, actdata in self.acts: if len(actorlist) > maxactor: maxactor = len(actorlist) if not self.loadnextact(): print 'No acts to play!' raise done self.lh = stdwin.lineheight() self.winheight = (maxactor+2)*self.lh stdwin.setdefwinsize(WINWIDTH, self.winheight) self.win = stdwin.open('The Play') self.win.setdocsize(WINWIDTH, self.winheight) self.win.change(((0,0),(WINWIDTH, self.winheight))) self.menu = self.win.menucreate('Play') self.menu.additem('Faster', '+') self.menu.additem('Slower', '-') self.menu.additem('Quit', 'Q') self.speed = 4
def realize(self): if self.win: raise Error, 'realize(): called twice' if not self.child: raise Error, 'realize(): no child' # Compute suggested size self.size = self.child.getminsize(self.beginmeasuring(), \ self.size) save_defsize = stdwin.getdefwinsize() scrwidth, scrheight = stdwin.getscrsize() width, height = self.size if width > scrwidth: width = scrwidth * 2/3 if height > scrheight: height = scrheight * 2/3 stdwin.setdefwinsize(width, height) self.hbar, self.vbar = stdwin.getdefscrollbars() self.win = stdwin.open(self.title) stdwin.setdefwinsize(save_defsize) self.win.setdocsize(self.size) if self.itimer: self.win.settimer(self.itimer) width, height = self.win.getwinsize() if self.hbar: width = self.size[0] if self.vbar: height = self.size[1] self.child.setbounds(((0, 0), (width, height))) self.child.realize() self.win.dispatch = self.dispatch mainloop.register(self.win)
def handle_server_message(*args): data, clientaddr = server_socket.recvfrom(1024) words = string.split(data) if len(words) < 2: print 'Bad message from', clientaddr[0], ':', `data` return wname = words[0] function = words[1] try: meth = getattr(WWWWindow, 'msg_' + function) except AttributeError: print 'Bad function', `function`, 'in message from', \ clientaddr[0], ':', `data` return ##print 'Message from', clientaddr[0], ':', `data` new = 0 for w in allwindows: if w.server_name == wname: break else: print 'Creating new window named', `wname` stdwin.setdefwinsize(0, 0) w = WWWWindow() w.server_name = wname new = 1 try: getattr(w, 'msg_' + function)(words[2:], clientaddr) except: print '***', sys.exc_type, ':', `sys.exc_value`
def open(title): # Open a generic window w = stdwin.open(title) stdwin.setdefwinsize(0, 0) # Set default event handlers w.draw = nop w.char = nop w.mdown = nop w.mmove = nop w.mup = nop w.m2down = m2down w.m2up = m2up w.size = nop w.move = nop w.activate = w.deactivate = nop w.timer = nop # default command handlers w.close = close w.tab = tab w.enter = enter w.backspace = backspace w.arrow = arrow w.kleft = w.kup = w.kright = w.kdown = nop w.dispatch = treatevent register(w) return w
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
def show_hook(self): savetext = self.text self.settext('Be patient...') close_sogram() stdwin.setdefwinsize(400, 300) win = stdwin.open('Sound-o-gram') G.sogram = Soundogram().define(win, G.data) win.buttons = [G.sogram] self.settext(savetext)
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 __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)
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)
def make_help_window(): stdwin.setdefwinsize(500, 350) w = WWWWindow() d = '<TITLE>WWWW Help</TITLE>\n' d = d + '<H1>WWWW User Interface Help</H1>\n' d = d + 'Underlined text is linked to other documents.<P>\n' d = d + 'Click left to follow a link.<P>\n' d = d + 'Click middle to show where a link leads.<P>\n' d = d + 'Click right to follow a link in a new window.<P>\n' w.setrawdata('builtin:help', d)
def makewindow(): stdwin.setdefwinsize(DEFWIDTH, DEFHEIGHT + stdwin.lineheight()) win = stdwin.open("clock") setdimensions(win) win.set = 1 # True when alarm is set win.time = 11 * 60 + 40 # Time when alarm must go off win.ring = 0 # True when alarm is ringing win.dispatch = cdispatch mainloop.register(win) settimer(win) return win
def makewindow(): stdwin.setdefwinsize(DEFWIDTH, DEFHEIGHT + stdwin.lineheight()) win = stdwin.open('clock') setdimensions(win) win.set = 1 # True when alarm is set win.time = 11*60 + 40 # Time when alarm must go off win.ring = 0 # True when alarm is ringing win.dispatch = cdispatch mainloop.register(win) settimer(win) return win
def test(): import stdwin, stdwinq from stdwinevents import * try: import mac # Mac font assignments: font1 = 'times', '', 12 font2 = 'times', 'b', 14 except ImportError: # X11R4 font assignments font1 = '*times-medium-r-*-120-*' font2 = '*times-bold-r-*-140-*' words = \ ['The','quick','brown','fox','jumps','over','the','lazy','dog.'] words = words * 2 stage = 0 stages = [(0,0,'ragged'), (1,0,'justified'), (0,1,'centered')] justify, center, title = stages[stage] stdwin.setdefwinsize(300,200) w = stdwin.open(title) winsize = w.getwinsize() while 1: type, window, detail = stdwinq.getevent() if type == WE_CLOSE: break elif type == WE_SIZE: newsize = w.getwinsize() if newsize <> winsize: w.change((0,0), winsize) winsize = newsize w.change((0,0), winsize) elif type == WE_MOUSE_DOWN: stage = (stage + 1) % len(stages) justify, center, title = stages[stage] w.settitle(title) w.change((0, 0), (1000, 1000)) elif type == WE_DRAW: width, height = winsize f = formatter(w.begindrawing(), 0, 0, width) f.center = center f.justify = justify if not center: f.tempindent(5) for font in font1, font2, font1: f.setfont(font) for word in words: space = 1 + (word[-1:] == '.') f.addword(word, space) if center and space > 1: f.flush() f.flush() height = f.v del f w.setdocsize(0, height)
def test(): import stdwin, stdwinq from stdwinevents import * try: import mac # Mac font assignments: font1 = 'times', '', 12 font2 = 'times', 'b', 14 except ImportError: # X11R4 font assignments font1 = '*times-medium-r-*-120-*' font2 = '*times-bold-r-*-140-*' words = \ ['The','quick','brown','fox','jumps','over','the','lazy','dog.'] words = words * 2 stage = 0 stages = [(0, 0, 'ragged'), (1, 0, 'justified'), (0, 1, 'centered')] justify, center, title = stages[stage] stdwin.setdefwinsize(300, 200) w = stdwin.open(title) winsize = w.getwinsize() while 1: type, window, detail = stdwinq.getevent() if type == WE_CLOSE: break elif type == WE_SIZE: newsize = w.getwinsize() if newsize <> winsize: w.change((0, 0), winsize) winsize = newsize w.change((0, 0), winsize) elif type == WE_MOUSE_DOWN: stage = (stage + 1) % len(stages) justify, center, title = stages[stage] w.settitle(title) w.change((0, 0), (1000, 1000)) elif type == WE_DRAW: width, height = winsize f = formatter(w.begindrawing(), 0, 0, width) f.center = center f.justify = justify if not center: f.tempindent(5) for font in font1, font2, font1: f.setfont(font) for word in words: space = 1 + (word[-1:] == '.') f.addword(word, space) if center and space > 1: f.flush() f.flush() height = f.v del f w.setdocsize(0, height)
def realmain(): setdimensions(DEFWIDTH, DEFHEIGHT) stdwin.setdefwinsize(G.farcorner) G.w = stdwin.open('klok') settimer() while 1: type, window, detail = stdwin.getevent() if type = WE_DRAW: drawproc(detail) elif type = WE_TIMER: settimer() drawproc(everywhere)
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
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
def main(): # stdwin.setdefwinsize(300, 300) stdwin.setdefwinpos(0, 0) if color: stdwin.setbgcolor(YELLOW) w1 = stdwin.open('Hello, world') w1.box = (10, 10), (90, 90) # stdwin.setdefwinsize(0, 0) stdwin.setdefwinpos(50, 50) if color: stdwin.setbgcolor(GREEN) w2 = stdwin.open('Second window') w2.box = (10, 10), (90, 90) # while w1 or w2: type, window, detail = stdwin.getevent() if type == WE_DRAW: d = window.begindrawing() if window == w1: if color: d.setfgcolor(BLACK) d.box(((50, 50), (250, 250))) if color: d.setfgcolor(RED) d.cliprect(((50, 50), (250, 250))) d.paint(w1.box) d.noclip() if color: d.setfgcolor(BLUE) d.line((0, 0), w1.box[0]) elif window == w2: if color: d.setfgcolor(WHITE) d.box(w2.box) if color: d.setfgcolor(BLACK) d.text(w2.box[0], 'Hello world') else: print 'Strange draw???', window, detail del d elif type == WE_CLOSE: if needclose: window.close() if window == w1: w1 = None elif window == w2: w2 = None else: print 'weird close event???', window, detail elif type in (WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP): h, v = detail[0] window.box = (h, v), (h+80, v+80) window.change(((0,0), (2000, 2000))) elif type == WE_CHAR: print 'character', `detail` else: print type, window, detail
def main(): # stdwin.setdefwinsize(300, 300) stdwin.setdefwinpos(0, 0) if color: stdwin.setbgcolor(YELLOW) w1 = stdwin.open('Hello, world') w1.box = (10, 10), (90, 90) # stdwin.setdefwinsize(0, 0) stdwin.setdefwinpos(50, 50) if color: stdwin.setbgcolor(GREEN) w2 = stdwin.open('Second window') w2.box = (10, 10), (90, 90) # while w1 or w2: type, window, detail = stdwin.getevent() if type == WE_DRAW: d = window.begindrawing() if window == w1: if color: d.setfgcolor(BLACK) d.box(((50, 50), (250, 250))) if color: d.setfgcolor(RED) d.cliprect(((50, 50), (250, 250))) d.paint(w1.box) d.noclip() if color: d.setfgcolor(BLUE) d.line((0, 0), w1.box[0]) elif window == w2: if color: d.setfgcolor(WHITE) d.box(w2.box) if color: d.setfgcolor(BLACK) d.text(w2.box[0], 'Hello world') else: print 'Strange draw???', window, detail del d elif type == WE_CLOSE: if needclose: window.close() if window == w1: w1 = None elif window == w2: w2 = None else: print 'weird close event???', window, detail elif type in (WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP): h, v = detail[0] window.box = (h, v), (h + 80, v + 80) window.change(((0, 0), (2000, 2000))) elif type == WE_CHAR: print 'character', ` detail ` else: print type, window, detail
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)
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
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
def realize(self): if self.win: raise Error, 'realize(): called twice' if not self.child: raise Error, 'realize(): no child' size = self.child.minsize(self.beginmeasuring()) self.size = max(self.size[0], size[0]), \ max(self.size[1], size[1]) #stdwin.setdefwinsize(self.size) # XXX Compensate stdwin bug: stdwin.setdefwinsize(self.size[0]+4, self.size[1]+2) self.win = stdwin.open(self.title) if self.itimer: self.win.settimer(self.itimer) bounds = (0, 0), self.win.getwinsize() self.child.setbounds(bounds)
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()
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 __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 open(self): if self.window: return self.formwidth = max(100, self.formwidth) self.formheight = max(50, self.formheight) stdwin.setdefwinsize(self.formwidth, self.formheight) stdwin.setdefscrollbars(0, 0) self.window = stdwin.open(self.title) self.window.setdocsize(self.formwidth, self.formheight) for name in self.fieldnames: label, left, top, right, bottom, te = \ self.fields[name] rect = (left, top), (right, bottom) te = self.window.textcreate(rect) te.setactive(0) te.setview(rect) self.fields[name] = \ label, left, top, right, bottom, te if self.fieldnames: self.setfocus(self.fieldnames[0])
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()
def openlistwindow(dirname): list = os.listdir(dirname) list.sort() i = 0 while i < len(list): if list[i][0] == '.': del list[i] else: i = i+1 for i in range(len(list)): fullname = os.path.join(dirname, list[i]) if os.path.isdir(fullname): info = '/' else: try: size = os.stat(fullname)[ST_SIZE] info = `(size + 1023)/1024` + 'k' except IOError: info = '???' info = '(' + info + ')' list[i] = list[i], info width = maxwidth(list) # width = width + stdwin.textwidth(' ') # XXX X11 stdwin bug workaround height = len(list) * stdwin.lineheight() stdwin.setdefwinsize(width, min(height, 500)) stdwin.setdefscrollbars(0, 1) 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 openlistwindow(dirname): list = os.listdir(dirname) list.sort() i = 0 while i < len(list): if list[i][0] == '.': del list[i] else: i = i + 1 for i in range(len(list)): fullname = os.path.join(dirname, list[i]) if os.path.isdir(fullname): info = '/' else: try: size = os.stat(fullname)[ST_SIZE] info = ` (size + 1023) / 1024 ` + 'k' except IOError: info = '???' info = '(' + info + ')' list[i] = list[i], info width = maxwidth(list) # width = width + stdwin.textwidth(' ') # XXX X11 stdwin bug workaround height = len(list) * stdwin.lineheight() stdwin.setdefwinsize(width, min(height, 500)) stdwin.setdefscrollbars(0, 1) 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 itutor(win): # The course looks best at 76x22... stdwin.setdefwinsize(76 * stdwin.textwidth('x'), 22 * stdwin.lineheight()) makewindow('ibrowse', 'Help')
if bookmarks is None: bookmarks = [] if wwwutil.user_home and wwwutil.user_home not in bookmarks: bookmarks.insert(0, wwwutil.user_home) if wwwutil.system_home and wwwutil.system_home not in bookmarks: bookmarks.insert(0, wwwutil.system_home) # history = wwwutil.load_file(history_file, HISTORY) if history is None: history = [] if not server_mode and not args and history: args.append(history[-1]) del history[-1] # if server_mode: start_server() # stdwin.setdefwinsize(0, 0) for addr in args: w = WWWWindow() w.set_raw_mode(raw_mode) if not w.setaddr(addr): w.close() else: w.set_history(history) # if not server_mode and mainloop.countwindows() == 0: # Fallback -- try default pages for addr in wwwutil.user_home, wwwutil.system_home: if addr not in args: w = WWWWindow() w.set_raw_mode(raw_mode) if not w.setaddr(addr):
def start(ref): stdwin.setdefscrollbars(0, 1) stdwin.setfont(FONT) stdwin.setdefwinsize(76*stdwin.textwidth('x'), 22*stdwin.lineheight()) makewindow('ibrowse', ref) mainloop()
def iclone(win): stdwin.setdefwinsize(win.getwinsize()) makewindow(win.file, win.node)
def itutor(win): # The course looks best at 76x22... stdwin.setdefwinsize(76*stdwin.textwidth('x'), 22*stdwin.lineheight()) makewindow('ibrowse', 'Help')
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
# Pass this program the Holy Grail script on stdin.
def isummary(win): stdwin.setdefwinsize(76 * stdwin.textwidth('x'), 22 * stdwin.lineheight()) makewindow('ibrowse', 'Summary')
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 for name in list: w = stdwin.textwidth(name)
def new(self): stdwin.setdefwinsize(self.window.getwinsize()) w = WWWWindow() w.set_raw_mode(self.raw_mode) return w
def start(ref): stdwin.setdefscrollbars(0, 1) stdwin.setfont(FONT) stdwin.setdefwinsize(76 * stdwin.textwidth('x'), 22 * stdwin.lineheight()) makewindow('ibrowse', ref) mainloop()