def mainloop(): global recursion_level recursion_level = recursion_level + 1 try: stdwin_select_handler() # Process events already in queue while 1: if windows and not fdlist: while windows and not fdlist: try: event = stdwinq.getevent() except KeyboardInterrupt: event = (WE_COMMAND, \ None, WC_CANCEL) dispatch(event) elif windows and fdlist: fd = stdwin.fileno() if recursion_level == 1: registerfd(fd, 'r', stdwin_select_handler) try: while windows: do_select() stdwin_select_handler() finally: if recursion_level == 1: unregisterfd(fd) elif fdlist: while fdlist and not windows: do_select() else: break finally: recursion_level = recursion_level - 1
def delayfunc(msecs): msecs = int(msecs) # # Check for immediate stdwin event # event = stdwinq.pollevent() if event: mainloop.dispatch(event) return # # Use sleep for very short delays or if there are no windows # if msecs < 100 or mainloop.countwindows() == 0: if msecs > 0: time.sleep(msecs * 0.001) return # # Post a timer event on an arbitrary window and wait for it # window = mainloop.anywindow() window.settimer(msecs/100) event = stdwinq.getevent() window.settimer(0) if event[0] <> WE_TIMER: mainloop.dispatch(event)
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 modaldialog(window): if window not in windows: raise ValueError, 'modaldialog window not registered' while window in windows: try: event = stdwinq.getevent() except KeyboardInterrupt: event = WE_COMMAND, None, WC_CANCEL etype, ewindow, edetail = event if etype not in passthrough and ewindow <> window: if etype in beeping: stdwin.fleep() continue dispatch(event)
def run(): while not empty(): if q.empty(): mainloop.dispatch(stdwinq.getevent()) else: q.run()