def make_mixed(): try: box.on = 'mixed' except ValueError: e = sys.exc_info()[1] say(e) report()
def select(): i = group.value name = cursor_names[i] say("Selecting cursor no. %d (%s)" % (i, name)) cursor = getattr(StdCursors, name) say("...", cursor) view.cursor = cursor
def do_old_files(self): say("Doing request_old_files") if self.filt.on: file_types = [self.file_type] else: file_types = None result = FileDialogs.request_old_files("Open Dusty Old Files:", default_dir = last_dir, file_types = file_types) self.save_result(result)
def main(): get_test_names() while 1: list_tests() name = get_test() print # cmd = r"c:\python25\python %s" % name cmd = "%s %s" % (sys.executable, name) say("Executing:", repr(cmd)) os.system(cmd)
def do_new_file(self): say("Doing request_new_file with default_dir = %s, default_name = %r" % (last_dir, last_name)) if self.filt.on: file_type = self.file_type else: file_type = None result = FileDialogs.request_new_file("Save Shiny New File:", default_dir = last_dir, default_name = last_name, file_type = file_type) self.save_result(result)
def get_test(): while 1: prefix = ask("Test? ") if not prefix: sys.exit(0) matches = glob("%s-*.py" % prefix) if not matches: say("Unknown test") continue if len(matches) > 1: say("Ambiguous") continue return matches[0]
def modal_dialog(): #global dlog ### dlog = ModalDialog(title = "Spanish Inquisition", size = (200, 140)) dlog.place(Label(text = "Surprise!!!"), left = 20, top = 20) field = TextField() dlog.place(field, left = 20, top = 60, right = -20) field.become_target() dlog.default_button = DefaultButton() dlog.cancel_button = CancelButton() dlog.place(dlog.default_button, right = -20, bottom = -20) dlog.place(dlog.cancel_button, left = 20, bottom = -20) dlog.center() result = dlog.present() say("Result =", result) dlog.destroy()
def mouse_down(self, event): say("Mouse down:", event.position) for event in self.track_mouse(): if event.kind == 'mouse_drag': say("Mouse drag:", event.position) elif event.kind == 'mouse_up': say("Mouse up:", event.position) else: say("Other event:", event.kind)
def draw(self, c, r): if self.report_update_rect: say("Update rect =", r) viewed_rect = self.viewed_rect() c.fillcolor = white c.fill_rect(viewed_rect) c.pensize = 6 c.fillcolor = red x = 20 y = 10 for i in range(0, 20): c.newpath() c.moveto(x - 20, y + 20) c.rlineto(80, -20) c.rlineto(-40, 60) c.closepath() c.fill() c.stroke() x += 80 y += 80 ew, eh = self.extent c.frame_rect((0, 0, ew, eh))
def save_result(self, result): if isinstance(result, list): say("Result:") for item in result: say(" ", item) else: say("Result =", result) print global last_dir, last_name if result: if isinstance(result, FileRef): last_dir = result.dir last_name = result.name elif isinstance(result, DirRef): say("Setting last_dir to", result) ### last_dir = result
def show_text(win): fields = [win.tf1, win.tf2, win.tf3] n = None t = application().target for i, f in enumerate(fields): say("Field %d:" % (i + 1), repr(f.text)) if f is t: n = i + 1 if n: say("Focus: Field %d: Selection = %r" % (n, t.selection)) else: say("No focus")
def key_down(self, e): say(e) Window.key_down(self, e)
def key_down(self, event): say(self.name, "Key down:", event)
def mouse_down(self, event): say(self.name, "Mouse down:", event)
def action(): say("Slider %s value = %s" % (name, slider.value))
def mouse_drag(self, event): say(self.name, "Mouse drag:", event)
from GUI import Window, ListButton, application from testing import say def report(): print "Value =", but.value but = ListButton(position = (20, 20), titles = ["Item %d" % i for i in xrange(30)], action = report) but.value = 42 win = Window(title = "List Button") win.add(but) but.become_target() win.show() instructions = """ There should be a list button containing 30 items. Selecting an item should cause its value to be reported. On Windows, it should be possible to make a selection by typing the first letter of the title. """ say(instructions) application().run()
def key_up(self, event): say(self.name, "Key up:", event) print
from GUI import Window, application from TestViews import TestDrawing, fancy_font as f from TestInput import TestKeyEvents, TestTrackMouse from testing import say class TestView(TestKeyEvents, TestTrackMouse, TestDrawing): pass win = Window(width = 320, height = 200) view = TestView(width = 320, height = 200) win.add(view) view.become_target() win.show() say(""" There should be a red triangle, a blue triangle and half a green triangle, outlined in black, on a yellow background, and three pieces of text. Each text line should sit accurately on the baseline drawn under it. The following events in the view should be reported: mouse down, mouse drag, mouse up, key down, key up, auto key. """) say("Font ascent =", f.ascent, "descent =", f.descent, "height =", f.height) application().run()
def do_new_dir(self): say("Doing request_new_directory") result = FileDialogs.request_new_directory("Create Sparkling New Directory:", default_dir = last_dir, default_name = last_name) self.save_result(result)
def extent(self, w, h): self.view.extent = (w, h) self.view.invalidate() say("Extent =", self.view.extent)
def say_hello(): say("Hello, world!") btn2.enabled = 1
def report_mouse_event(self, mess): say(mess)
def key_down(self, event): which = self.which_key(event) if event.auto: say("Auto key:", which) else: say("Key down:", which)
def key_up(self, event): say("Key up:", self.which_key(event))
def say_goodbye(): say("Goodbye, world!") btn2.enabled = 0
def mouse_down(self, event): say("Mouse down in", self.title)
def untargeted(self): say("%s untargeted" % self.name)
from GUI import FileDialogs functions = {} function_names = [ 'request_old_file', 'request_old_files', 'request_new_file', 'request_old_directory', 'request_old_directories', 'request_new_directory', ] for name in function_names: if hasattr(FileDialogs, name): functions[name] = getattr(FileDialogs, name) else: say("*** Missing function:", name) last_dir = DirRef(path=os.path.abspath(os.path.dirname(sys.argv[0]))) last_name = "" say("last_dir =", last_dir) ### class TestWindow(Window): file_type = FileType(name="TIFF Image", suffix="tiff") def __init__(self): Window.__init__(self, size=(200, 200)) self.filt = CheckBox("%ss only" % self.file_type.name) #self.multi = CheckBox("Multiple Selection")
def do_old_dirs(self): say("Doing request_old_directories") result = FileDialogs.request_old_directories( "Open Mouldy Old Directories:", default_dir=last_dir) self.save_result(result)
bounds = (50, 70, 250, 270), auto_position = False) win1.name = "Win1" win1.show() win2 = TestWindow(title = "Hello Again!", auto_position = False, position = (300, 70), size = (400, 300), resizable = 0) win2.name = "Win2" win2.show() instructions = """ There should be two windows, one titled 'Hello PyGUI!' positioned at (50, 70) with size (200, 200) and resizable, and one titled 'Hello Again!' positioned at (300, 70) with size (400, 300) and not resizable. Both should be movable and closable. Mouse down, mouse drag, mouse up, key down and key up events in both windows should be reported. Mouse drag and mouse up events should be reported for the window in which the preceding mouse down event occurred, and should be reported even if the mouse is moved outside the original window. """ say(instructions) say("win1 position =", win1.position, "size =", win1.size) say("win2 position =", win2.position, "size =", win2.size) run()
def targeted(self): say("%s targeted" % self.name)
def mouse_up(self, event): say(self.name, "Mouse up:", event) print
def key_up(self, event): say("Key up: %s\n" % event)
Window.key_down(self, e) win = TWindow(width = 260, height = btn3.bottom + 30, title = "Btns", resizable = 0, zoomable = 0) win.add(btn1) win.add(btn2) win.add(btn3) win.show() instructions = """ There should be 3 buttons arranged vertically: 1. Title "Hello", natural width, style 'default' 2. Title "Goodbye" in a serif font, width 200, initially disabled 3. Title "Gidday Mate" in red italic, width 200, style 'cancel', right aligned Pressing button 1 should print "Hello, world!" and enable button 2. Pressing button 2 should print "Goodbye, world!" and disable button 2. Pressing button 3 should simulate pressing button 1. """ say(instructions) say("Testing readback of button 3 properties:") say("title =", btn3.title) say("font =", btn3.font) say("color =", btn3.color) say("just =", btn3.just) say("End of readback test") say() application().run()
def key_down(self, event): say("char = %r key = %r unichars = %r _keycode = 0x%04x" % ( event.char, event.key, event.unichars, event._keycode))
def mouse_down(self, e): say("%s clicked" % self.name) self.become_target()
def key_down(self, event): say("Key down: %s\n" % event) if event.char == "E": raise Exception("This is a test exception.")
def key_down(self, event): say("Key down in", self.title) self.other.show()
def auto_key(self, event): say("Auto key: %s\n" % event)
def bing(): say("Bing!")
height=btn3.bottom + 30, title="Btns", resizable=0, zoomable=0) win.add(btn1) win.add(btn2) win.add(btn3) win.show() instructions = """ There should be 3 buttons arranged vertically: 1. Title "Hello", natural width, style 'default' 2. Title "Goodbye" in a serif font, width 200, initially disabled 3. Title "Gidday Mate" in red italic, width 200, style 'cancel', right aligned Pressing button 1 should print "Hello, world!" and enable button 2. Pressing button 2 should print "Goodbye, world!" and disable button 2. Pressing button 3 should simulate pressing button 1. """ say(instructions) say("Testing readback of button 3 properties:") say("title =", btn3.title) say("font =", btn3.font) say("color =", btn3.color) say("just =", btn3.just) say("End of readback test") say() application().run()