示例#1
0
def mainloop():
    while windows:
        event = stdwin.getevent()
        if event[1] in windows:
            try:
                event[1].dispatch(event)
            except KeyboardInterrupt:
                # The user can type Control-C (or whatever)
                # to leave the browser without closing
                # the window.  Mainly useful for
                # debugging.
                break
            except:
                # During debugging, it was annoying if
                # every mistake in a callback caused the
                # whole browser to crash, hence this
                # handler.  In a production version
                # it may be better to disable this.
                #
                msg = sys.exc_type
                if sys.exc_value:
                    val = sys.exc_value
                    if type(val) <> type(''):
                        val = ` val `
                    msg = msg + ': ' + val
                msg = 'Oops, an exception occurred: ' + msg
                event = None
                stdwin.message(msg)
        event = None
示例#2
0
def testStdwin():
	import stdwin, fmt
	from stdwinevents import *
	if sys.argv[1:]: file = sys.argv[1]
	else: file = 'test.html'
	data = open(file, 'r').read()
	window = stdwin.open('testStdwin')
	b = None
	while 1:
		etype, ewin, edetail = stdwin.getevent()
		if etype == WE_CLOSE:
			break
		if etype == WE_SIZE:
			window.setdocsize(0, 0)
			window.setorigin(0, 0)
			window.change((0, 0), (10000, 30000)) # XXX
		if etype == WE_DRAW:
			if not b:
				b = fmt.StdwinBackEnd(window, 1)
				f = fmt.BaseFormatter(b.d, b)
				p = FormattingParser(f, \
							    MacStylesheet)
				p.feed(data)
				p.close()
				b.finish()
			else:
				b.redraw(edetail)
	window.close()
def testStdwin():
    import stdwin, fmt
    from stdwinevents import *
    if sys.argv[1:]: file = sys.argv[1]
    else: file = 'test.html'
    data = open(file, 'r').read()
    window = stdwin.open('testStdwin')
    b = None
    while 1:
        etype, ewin, edetail = stdwin.getevent()
        if etype == WE_CLOSE:
            break
        if etype == WE_SIZE:
            window.setdocsize(0, 0)
            window.setorigin(0, 0)
            window.change((0, 0), (10000, 30000))  # XXX
        if etype == WE_DRAW:
            if not b:
                b = fmt.StdwinBackEnd(window, 1)
                f = fmt.BaseFormatter(b.d, b)
                p = FormattingParser(f, \
                       MacStylesheet)
                p.feed(data)
                p.close()
                b.finish()
            else:
                b.redraw(edetail)
    window.close()
示例#4
0
def getevent():
    if queue:
        event = queue[0]
        del queue[0]
        return event
    else:
        return stdwin.getevent()
示例#5
0
 def run(self):
     self.win.settimer(10)
     while 1:
         ev, win, arg = stdwin.getevent()
         if ev == WE_DRAW:
             ((left, top), (right, bot)) = arg
             self.redraw(top, bot, self.win.begindrawing())
         elif ev == WE_TIMER:
             self.timerevent()
         elif ev == WE_CLOSE:
             self.win.close()
             raise done
         elif ev == WE_MENU and arg[0] == self.menu:
             if arg[1] == 0:
                 if self.speed > 1:
                     self.speed = self.speed / 2
                     if self.speaker:
                         self.speaker.setrate(1.4)
             elif arg[1] == 1:
                 self.speed = self.speed * 2
                 if self.speaker:
                     self.speaker.setrate(0.7)
             elif arg[1] == 2:
                 self.win.close()
                 raise done
示例#6
0
def getevent():
	if queue:
		event = queue[0]
		del queue[0]
		return event
	else:
		return stdwin.getevent()
示例#7
0
	def run(self):
		self.win.settimer(10)
		while 1:
			ev, win, arg = stdwin.getevent()
			if ev == WE_DRAW:
				((left, top), (right, bot)) = arg
				self.redraw(top, bot, self.win.begindrawing())
			elif ev == WE_TIMER:
				self.timerevent()
			elif ev == WE_CLOSE:
				self.win.close()
				raise done
			elif ev == WE_MENU and arg[0] == self.menu:
				if arg[1] == 0:
					if self.speed > 1:
						self.speed = self.speed/2
						if self.speaker:
							self.speaker.setrate(1.4)
				elif arg[1] == 1:
					self.speed = self.speed * 2
					if self.speaker:
						self.speaker.setrate(0.7)
				elif arg[1] == 2:
					self.win.close()
					raise done
示例#8
0
文件: tcolor.py 项目: 8Banana/py1.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
示例#9
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
示例#10
0
def mainloop():
	while windows:
		event = stdwin.getevent()
		if event[1] in windows:
			try:
				event[1].dispatch(event)
			except KeyboardInterrupt:
				# The user can type Control-C (or whatever)
				# to leave the browser without closing
				# the window.  Mainly useful for
				# debugging.
				break
			except:
				# During debugging, it was annoying if
				# every mistake in a callback caused the
				# whole browser to crash, hence this
				# handler.  In a production version
				# it may be better to disable this.
				#
				msg = sys.exc_type
				if sys.exc_value:
					val = sys.exc_value
					if type(val) <> type(''):
						val = `val`
					msg = msg + ': ' + val
				msg = 'Oops, an exception occurred: ' + msg
				event = None
				stdwin.message(msg)
		event = None
示例#11
0
def main():
	size = 12
	w = stdwin.open('Font chart ' + `size`)
	while 1:
		type, window, detail = stdwin.getevent()
		if type == WE_CLOSE:
			break
		if type == WE_DRAW:
			width, height = w.getwinsize()
			d = w.begindrawing()
			d.setsize(size)
			h, v = 0, 0
			for c in range(32, 256):
				ch = chr(c)
				chw = d.textwidth(ch)
				if h + chw > width:
					v = v + d.lineheight()
					h = 0
					if v >= height:
						break
				d.text((h, v), ch)
				h = h + chw
			del d
		if type == WE_MOUSE_UP:
			size = size + 1
			w.settitle('Font chart ' + `size`)
			w.change((0, 0), (2000, 2000))
示例#12
0
def main():
    size = 12
    w = stdwin.open('Font chart ' + ` size `)
    while 1:
        type, window, detail = stdwin.getevent()
        if type == WE_CLOSE:
            break
        if type == WE_DRAW:
            width, height = w.getwinsize()
            d = w.begindrawing()
            d.setsize(size)
            h, v = 0, 0
            for c in range(32, 256):
                ch = chr(c)
                chw = d.textwidth(ch)
                if h + chw > width:
                    v = v + d.lineheight()
                    h = 0
                    if v >= height:
                        break
                d.text((h, v), ch)
                h = h + chw
            del d
        if type == WE_MOUSE_UP:
            size = size + 1
            w.settitle('Font chart ' + ` size `)
            w.change((0, 0), (2000, 2000))
示例#13
0
def main():
	w = stdwin.open('TestMenus')
	#
	items1 = 'Aap', 'Noot', 'Mies'
	m1 = w.menucreate('Menu-1')
	for item in items1:
		m1.additem(item, item[0])
	#
	items2 = 'Wim', 'Zus', 'Jet', 'Teun', 'Vuur'
	m2 = w.menucreate('Menu-2')
	for item in items2:
		m2.additem(item, `len(item)`)
	#
	m1.enable(1, 0)
	m2.check(1, 1)
	#
	while 1:
		type, window, detail = stdwin.getevent()
		if type == WE_CLOSE:
			break
		elif type == WE_DRAW:
			d = w.begindrawing()
			d.box(((50,50), (100,100)))
			del d
		elif type == WE_MENU:
			mp, i = detail
			if mp == m1:
				print 'Choice:', items1[i]
			elif mp == m2:
				print 'Choice:', items2[i]
			else:
				print 'Not one of my menus!'
		elif type == WE_CHAR:
			print 'Character', `detail`
示例#14
0
def maineventloop():
       mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP
       while G.windows:
               type, w, detail = event = stdwin.getevent()
               if w = G.cw.win:
                       if type = WE_CLOSE:
                               return
                       G.cw.dispatch(event)
示例#15
0
def maineventloop():
	mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP
	while G.windows:
		type, w, detail = event = stdwin.getevent()
		if w = G.cw.win:
			if type = WE_CLOSE:
				return
			G.cw.dispatch(event)
示例#16
0
def main():
	audio.setrate(3)
	audio.setoutgain(0)
	w = WindowParent().create('VU Meter', (200, 100))
	v = MyVUMeter().define(w)
	v.start()
	w.realize()
	while 1:
		w.dispatch(stdwin.getevent())
示例#17
0
def main():
       audio.setrate(3)
       audio.setoutgain(0)
       w = WindowParent().create('VU Meter', (200, 100))
       v = MyVUMeter().define(w)
       v.start()
       w.realize()
       while 1:
               w.dispatch(stdwin.getevent())
示例#18
0
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)
示例#19
0
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
示例#20
0
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
示例#21
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)
示例#22
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)
示例#23
0
def main(n):
       from CSplit import CSplit

       the_window = WindowParent().create('TestCSplit', (0, 0))
       the_csplit = CSplit().create(the_window)

       for i in range(n):
               the_child = PushButton().define(the_csplit)
               the_child.settext(`(i+n-1)%n+1`)

       the_window.realize()

       while 1:
               the_event = stdwin.getevent()
               if the_event[0] = WE_CLOSE: break
               the_window.dispatch(the_event)
       the_window.destroy()
示例#24
0
def main(n):
	from CSplit import CSplit
	
	the_window = WindowParent().create('TestCSplit', (0, 0))
	the_csplit = CSplit().create(the_window)
	
	for i in range(n):
		the_child = PushButton().define(the_csplit)
		the_child.settext(`(i+n-1)%n+1`)
	
	the_window.realize()
	
	while 1:
		the_event = stdwin.getevent()
		if the_event[0] = WE_CLOSE: break
		the_window.dispatch(the_event)
	the_window.destroy()
示例#25
0
def wtest():
	fp = openfile()
	w = stdwin.open('wtest')
	while 1:
		type, win, detail = stdwin.getevent()
		if type == WE_CLOSE:
			break
		if type == WE_DRAW:
			TSTART()
			left, top = 0, 0
			right, bottom = w.getwinsize()
			d = w.begindrawing()
			fmt = StdwinFormatter().init(d, left, top, right)
			fp.seek(0)
			feedfile(fp, fmt)
			d.close()
			TSTOP()
	w.close()
示例#26
0
def wtest():
    fp = openfile()
    w = stdwin.open('wtest')
    while 1:
        type, win, detail = stdwin.getevent()
        if type == WE_CLOSE:
            break
        if type == WE_DRAW:
            TSTART()
            left, top = 0, 0
            right, bottom = w.getwinsize()
            d = w.begindrawing()
            fmt = StdwinFormatter().init(d, left, top, right)
            fp.seek(0)
            feedfile(fp, fmt)
            d.close()
            TSTOP()
    w.close()
示例#27
0
def maineventloop():
	mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP
	while G.windows:
		type, w, detail = event = stdwin.getevent()
		if w == G.cw.win:
			if type == WE_CLOSE:
				return
			G.cw.dispatch(event)
		else:
			if type == WE_DRAW:
				w.drawproc(w, detail)
			elif type in mouse_events:
				w.mouse(w, type, detail)
			elif type == WE_CLOSE:
				w.close(w)
				del w, event
			else:
				if G.debug: print type, w, detail
示例#28
0
def wwwtest():
    fp = openfile()
    TSTART()
    calls = makecalls(fp, StdwinFormatter)
    TSTOP()
    w = stdwin.open('wwwtest')
    TSTART()
    left, top = 0, 0
    right, bottom = w.getwinsize()
    fmt = BufferingStdwinFormatter().init(left, top, right)
    feedcalls(calls, fmt)
    bottom = fmt.getbottom()
    w.setdocsize(0, bottom)
    TSTOP()
    ##	for x in fmt.buffer: print x
    while 1:
        type, win, detail = stdwin.getevent()
        if type == WE_CLOSE:
            break
        if type == WE_SIZE:
            width, height = w.getwinsize()
            if width <> right:
                TSTART()
                left, top = 0, 0
                right, bottom = w.getwinsize()
                fmt = BufferingStdwinFormatter(). \
                 init(left, top, right)
                feedcalls(calls, fmt)
                bottom = fmt.getbottom()
                w.setdocsize(0, bottom)
                TSTOP()
        if type == WE_DRAW:
            TSTART()
            d = w.begindrawing()
            fmt.render(d, detail)
            d.close()
            TSTOP()
    w.close()
示例#29
0
def wwwtest():
	fp = openfile()
	TSTART()
	calls = makecalls(fp, StdwinFormatter)
	TSTOP()
	w = stdwin.open('wwwtest')
	TSTART()
	left, top = 0, 0
	right, bottom = w.getwinsize()
	fmt = BufferingStdwinFormatter().init(left, top, right)
	feedcalls(calls, fmt)
	bottom = fmt.getbottom()
	w.setdocsize(0, bottom)
	TSTOP()
##	for x in fmt.buffer: print x
	while 1:
		type, win, detail = stdwin.getevent()
		if type == WE_CLOSE:
			break
		if type == WE_SIZE:
			width, height = w.getwinsize()
			if width <> right:
				TSTART()
				left, top = 0, 0
				right, bottom = w.getwinsize()
				fmt = BufferingStdwinFormatter(). \
					init(left, top, right)
				feedcalls(calls, fmt)
				bottom = fmt.getbottom()
				w.setdocsize(0, bottom)
				TSTOP()
		if type == WE_DRAW:
			TSTART()
			d = w.begindrawing()
			fmt.render(d, detail)
			d.close()
			TSTOP()
	w.close()
示例#30
0
def maineventloop():
	mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP
	while G.windows:
		try:
			type, w, detail = event = stdwin.getevent()
		except KeyboardInterrupt:
			killchild()
			continue
		if w == G.cw.win:
			if type == WE_CLOSE:
				return
			if type == WE_TIMER:
				checkchild()
				if G.busy:
					G.cw.win.settimer(1)
			elif type == WE_MENU:
				menu, item = detail
				if menu is G.ratemenu:
					clearcache()
					if item == 0:
						G.rate = 0
					else:
						G.rate = eval(rates[item])
					for i in range(len(rates)):
						menu.check(i, (i == item))
			else:
				G.cw.dispatch(event)
		else:
			if type == WE_DRAW:
				w.drawproc(w, detail)
			elif type in mouse_events:
				w.mouse(w, type, detail)
			elif type == WE_CLOSE:
				w.close(w)
				del w, event
			else:
				if G.debug > 1: print type, w, detail
示例#31
0
def maineventloop():
    mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP
    while G.windows:
        try:
            type, w, detail = event = stdwin.getevent()
        except KeyboardInterrupt:
            killchild()
            continue
        if w == G.cw.win:
            if type == WE_CLOSE:
                return
            if type == WE_TIMER:
                checkchild()
                if G.busy:
                    G.cw.win.settimer(1)
            elif type == WE_MENU:
                menu, item = detail
                if menu is G.ratemenu:
                    clearcache()
                    if item == 0:
                        G.rate = 0
                    else:
                        G.rate = eval(rates[item])
                    for i in range(len(rates)):
                        menu.check(i, (i == item))
            else:
                G.cw.dispatch(event)
        else:
            if type == WE_DRAW:
                w.drawproc(w, detail)
            elif type in mouse_events:
                w.mouse(w, type, detail)
            elif type == WE_CLOSE:
                w.close(w)
                del w, event
            else:
                if G.debug > 1: print type, w, detail
示例#32
0
def test():
	import stdwin
	from stdwinevents import *
	words = 'The', 'quick', 'brown', 'fox', 'jumps', 'over', \
		'the', 'lazy', 'dog.'
	paralist = []
	for just in 'l', 'r', 'lr', 'c':
		p = Para()
		p.just = just
		p.addword(stdwin, ('New York', 'p', 12), words[0], 1, 1)
		for word in words[1:-1]:
			p.addword(stdwin, None, word, 1, 1)
		p.addword(stdwin, None, words[-1], 2, 4)
		p.addword(stdwin, ('New York', 'b', 18), 'Bye!', 0, 0)
		p.addword(stdwin, ('New York', 'p', 10), 'Bye!', 0, 0)
		paralist.append(p)
	window = stdwin.open('Para.test()')
	start = stop = selpara = None
	while 1:
		etype, win, detail = stdwin.getevent()
		if etype == WE_CLOSE:
			break
		if etype == WE_SIZE:
			window.change((0, 0), (1000, 1000))
		if etype == WE_DRAW:
			width, height = window.getwinsize()
			d = None
			try:
				d = window.begindrawing()
				d.cliprect(detail)
				d.erase(detail)
				v = 0
				for p in paralist:
					v = p.render(d, 0, v, width)
					if p == selpara and \
					   start <> None and stop <> None:
						p.invert(d, start, stop)
			finally:
				if d: d.close()
		if etype == WE_MOUSE_DOWN:
			if selpara and start <> None and stop <> None:
				d = window.begindrawing()
				selpara.invert(d, start, stop)
				d.close()
			start = stop = selpara = None
			mouseh, mousev = detail[0]
			for p in paralist:
				start = p.whereis(stdwin, mouseh, mousev)
				if start <> None:
					selpara = p
					break
		if etype == WE_MOUSE_UP and start <> None and selpara:
			mouseh, mousev = detail[0]
			stop = selpara.whereis(stdwin, mouseh, mousev)
			if stop == None: start = selpara = None
			else:
				if start > stop:
					start, stop = stop, start
				d = window.begindrawing()
				selpara.invert(d, start, stop)
				d.close()
	window.close()
示例#33
0
def main():
	#
	# Get the filename argument and read its contents as one very
	# large string.
	# An exception will terminate the program if there is no argument
	# or if the file could not be read...
	#
	filename = sys.argv[1]
	fp = open(filename, 'r')
	contents = fp.read()
	del fp				# Close the file
	#
	# Create the window, using the filename as window title
	#
	window = stdwin.open(filename)
	#
	# Add a simple File menu to the window with two items
	#
	filemenu = window.menucreate('File')
	filemenu.additem('Save', 'S')	# Item 0 (shortcut Meta-S)
	filemenu.additem('Save As...')	# Item 1
	#
	# Create a text object occupying the entire window
	# and fill it with the file's contents
	#
	corner = window.getwinsize()	# (width, height)
	area = (0, 0), corner		# Rectangle as large as the window
	text = window.textcreate(area)
	text.settext(contents)
	del contents			# Get rid of contents object
	fix_textsize(window, text)	# Set document size accordingly
	#
	# Main event loop -- stop if a close request comes in.
	#
	# STDWIN applications should regularly call stdwin.getevent()
	# otherwise the windows won't function as expected.
	#
	while 1:
		#
		# Get the next event
		#
		type, w, detail = e = stdwin.getevent()
		#
		# Event decoding switch
		#
		if type == WE_CLOSE:
			break		# Stop (no check for saved file!)
		elif type == WE_SIZE:
			#
			# The 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, text)
		elif type == WE_MENU:
			#
			# Execute a file menu request (our only menu)
			#
			menu, item = detail
			if item == 0:
				#
				# "Save": save to the current filename
				#
				dummy = save_file(window, text, filename)
			elif item == 1:
				#
				# "Save As": ask a new filename, save to it,
				# and make it the current filename
				#
				# NB: askfile raises KeyboardInterrupt
				# if the user cancels the dialog, hence
				# the try statement
				#
				try:
					newfile = stdwin.askfile( \
						'Save as:', filename, 1)
				except KeyboardInterrupt:
					newfile = ''
				if newfile:
					if save_file(window, text, newfile):
						filename = newfile
						window.settitle(filename)
		elif text.event(e):
			#
			# The text object has handled the event.
			# Fix the document size if necessary.
			# Note: this sometimes fixes the size
			# unnecessarily, e.g., for arrow keys.
			#
			if type in (WE_CHAR, WE_COMMAND):
				fix_docsize(window, text)
示例#34
0
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
示例#35
0
def main():
    #
    # Get the filename argument and read its contents as one very
    # large string.
    # An exception will terminate the program if there is no argument
    # or if the file could not be read...
    #
    filename = sys.argv[1]
    fp = open(filename, 'r')
    contents = fp.read()
    del fp  # Close the file
    #
    # Create the window, using the filename as window title
    #
    window = stdwin.open(filename)
    #
    # Add a simple File menu to the window with two items
    #
    filemenu = window.menucreate('File')
    filemenu.additem('Save', 'S')  # Item 0 (shortcut Meta-S)
    filemenu.additem('Save As...')  # Item 1
    #
    # Create a text object occupying the entire window
    # and fill it with the file's contents
    #
    corner = window.getwinsize()  # (width, height)
    area = (0, 0), corner  # Rectangle as large as the window
    text = window.textcreate(area)
    text.settext(contents)
    del contents  # Get rid of contents object
    fix_textsize(window, text)  # Set document size accordingly
    #
    # Main event loop -- stop if a close request comes in.
    #
    # STDWIN applications should regularly call stdwin.getevent()
    # otherwise the windows won't function as expected.
    #
    while 1:
        #
        # Get the next event
        #
        type, w, detail = e = stdwin.getevent()
        #
        # Event decoding switch
        #
        if type == WE_CLOSE:
            break  # Stop (no check for saved file!)
        elif type == WE_SIZE:
            #
            # The 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, text)
        elif type == WE_MENU:
            #
            # Execute a file menu request (our only menu)
            #
            menu, item = detail
            if item == 0:
                #
                # "Save": save to the current filename
                #
                dummy = save_file(window, text, filename)
            elif item == 1:
                #
                # "Save As": ask a new filename, save to it,
                # and make it the current filename
                #
                # NB: askfile raises KeyboardInterrupt
                # if the user cancels the dialog, hence
                # the try statement
                #
                try:
                    newfile = stdwin.askfile( \
                     'Save as:', filename, 1)
                except KeyboardInterrupt:
                    newfile = ''
                if newfile:
                    if save_file(window, text, newfile):
                        filename = newfile
                        window.settitle(filename)
        elif text.event(e):
            #
            # The text object has handled the event.
            # Fix the document size if necessary.
            # Note: this sometimes fixes the size
            # unnecessarily, e.g., for arrow keys.
            #
            if type in (WE_CHAR, WE_COMMAND):
                fix_docsize(window, text)
示例#36
0
def mainloop():                                # Handle events until no windows left
       while windows:
               treatevent(stdwin.getevent())
示例#37
0
       #
       G.savebtn = PushButton().definetext(w, 'Save...')
       G.savebtn.hook = save_hook
       #
       G.quitbtn = PushButton().definetext(w, 'Quit')
       G.quitbtn.hook = quit_hook
       G.playbtn.enable(0)
       G.savebtn.enable(0)
       #G.showbtn.enable(0)
       start_vu()
       G.window.realize()
       #
       # Event loop
       #
       while 1:
               e = stdwin.getevent()
               G.window.dispatch(e)

# XXX Disabled...
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 close_sogram():
       if G.sogram:
示例#38
0
def test():
	import stdwin
	from stdwinevents import *
	words = 'The', 'quick', 'brown', 'fox', 'jumps', 'over', \
		'the', 'lazy', 'dog.'
	paralist = []
	for just in 'l', 'r', 'lr', 'c':
		p = Para()
		p.just = just
		p.addword(stdwin, ('New York', 'p', 12), words[0], 1, 1)
		for word in words[1:-1]:
			p.addword(stdwin, None, word, 1, 1)
		p.addword(stdwin, None, words[-1], 2, 4)
		p.addword(stdwin, ('New York', 'b', 18), 'Bye!', 0, 0)
		p.addword(stdwin, ('New York', 'p', 10), 'Bye!', 0, 0)
		paralist.append(p)
	window = stdwin.open('Para.test()')
	start = stop = selpara = None
	while 1:
		etype, win, detail = stdwin.getevent()
		if etype == WE_CLOSE:
			break
		if etype == WE_SIZE:
			window.change((0, 0), (1000, 1000))
		if etype == WE_DRAW:
			width, height = window.getwinsize()
			d = None
			try:
				d = window.begindrawing()
				d.cliprect(detail)
				d.erase(detail)
				v = 0
				for p in paralist:
					v = p.render(d, 0, v, width)
					if p == selpara and \
					   start <> None and stop <> None:
						p.invert(d, start, stop)
			finally:
				if d: d.close()
		if etype == WE_MOUSE_DOWN:
			if selpara and start <> None and stop <> None:
				d = window.begindrawing()
				selpara.invert(d, start, stop)
				d.close()
			start = stop = selpara = None
			mouseh, mousev = detail[0]
			for p in paralist:
				start = p.whereis(stdwin, mouseh, mousev)
				if start <> None:
					selpara = p
					break
		if etype == WE_MOUSE_UP and start <> None and selpara:
			mouseh, mousev = detail[0]
			stop = selpara.whereis(stdwin, mouseh, mousev)
			if stop == None: start = selpara = None
			else:
				if start > stop:
					start, stop = stop, start
				d = window.begindrawing()
				selpara.invert(d, start, stop)
				d.close()
	window.close()
示例#39
0
文件: grail.py 项目: mcyril/ravel-ftn
# Pass this program the Holy Grail script on stdin.