|
| 1 | +import vanilla |
| 2 | + |
| 3 | +instructions = """ |
| 4 | +1. Launch the test window. |
| 5 | +- (Psst, press the button up there.) |
| 6 | +
|
| 7 | +2. Move the test window. |
| 8 | +- "move" - not observed |
| 9 | +
|
| 10 | +3. Resize the test window. |
| 11 | +- "resize" - not observed |
| 12 | +
|
| 13 | +4. Select this window... |
| 14 | +
|
| 15 | +- "resigned main" - not observed |
| 16 | +- "resigned key" - not observed |
| 17 | +
|
| 18 | +... then select the test window. |
| 19 | +
|
| 20 | +- "became main" - not observed |
| 21 | +- "became key" - not observed |
| 22 | +
|
| 23 | +5. Close the test window. |
| 24 | +- "should close" - not observed |
| 25 | +- "close" - not observed |
| 26 | +""" |
| 27 | + |
| 28 | +class TestWindowBindingsLauncher: |
| 29 | + |
| 30 | + def __init__(self): |
| 31 | + self.w = vanilla.Window((250, 500), "Test Launcher") |
| 32 | + self.w.launchButton = vanilla.Button( |
| 33 | + (10, 10, -10, 20), |
| 34 | + "Launch Test Window", |
| 35 | + self.launchButtonCallback |
| 36 | + ) |
| 37 | + self.w.reportField = vanilla.TextEditor( |
| 38 | + (10, 40, -10, -10), |
| 39 | + instructions |
| 40 | + ) |
| 41 | + self.w.open() |
| 42 | + |
| 43 | + def launchButtonCallback(self, sender): |
| 44 | + TestWindowBindings( |
| 45 | + getter=self.w.reportField.get, |
| 46 | + setter=self.w.reportField.set |
| 47 | + ) |
| 48 | + text = self.w.reportField.get() |
| 49 | + text = text.replace("- (Psst, press the button up there.)", "- Done!") |
| 50 | + self.w.reportField.set(text) |
| 51 | + |
| 52 | +class TestWindowBindings: |
| 53 | + |
| 54 | + def __init__(self, setter, getter): |
| 55 | + self.textSetter = setter |
| 56 | + self.textGetter = getter |
| 57 | + self.w = vanilla.Window( |
| 58 | + (300, 300), |
| 59 | + "Test Window", |
| 60 | + minSize=(200, 200) |
| 61 | + ) |
| 62 | + self.w.text = vanilla.EditText( |
| 63 | + (10, 10, -10, -10), |
| 64 | + "Follow the instructions in the launcher window." |
| 65 | + ) |
| 66 | + self.w.open() |
| 67 | + self.w.bind("should close", self.shouldCloseCallback) |
| 68 | + self.w.bind("close", self.closeCallback) |
| 69 | + self.w.bind("move", self.moveCallback) |
| 70 | + self.w.bind("resize", self.resizeCallback) |
| 71 | + self.w.bind("became main", self.becameMainCallback) |
| 72 | + self.w.bind("resigned main", self.resignedMainCallback) |
| 73 | + self.w.bind("became key", self.becameKeyCallback) |
| 74 | + self.w.bind("resigned key", self.resignedKeyCallback) |
| 75 | + |
| 76 | + def shouldCloseCallback(self, sender): |
| 77 | + text = self.textGetter() |
| 78 | + text = text.replace("- \"should close\" - not observed", "- \"should close\" - Done!") |
| 79 | + self.textSetter(text) |
| 80 | + return True |
| 81 | + |
| 82 | + def closeCallback(self, sender): |
| 83 | + text = self.textGetter() |
| 84 | + text = text.replace("- \"close\" - not observed", "- \"close\" - Done!") |
| 85 | + self.textSetter(text) |
| 86 | + |
| 87 | + def moveCallback(self, sender): |
| 88 | + text = self.textGetter() |
| 89 | + text = text.replace("- \"move\" - not observed", "- \"move\" - Done!") |
| 90 | + self.textSetter(text) |
| 91 | + |
| 92 | + def resizeCallback(self, sender): |
| 93 | + text = self.textGetter() |
| 94 | + text = text.replace("- \"resize\" - not observed", "- \"resize\" - Done!") |
| 95 | + self.textSetter(text) |
| 96 | + |
| 97 | + def becameMainCallback(self, sender): |
| 98 | + text = self.textGetter() |
| 99 | + text = text.replace("- \"became main\" - not observed", "- \"became main\" - Done!") |
| 100 | + self.textSetter(text) |
| 101 | + |
| 102 | + def resignedMainCallback(self, sender): |
| 103 | + text = self.textGetter() |
| 104 | + text = text.replace("- \"resigned main\" - not observed", "- \"resigned main\" - Done!") |
| 105 | + self.textSetter(text) |
| 106 | + |
| 107 | + def becameKeyCallback(self, sender): |
| 108 | + text = self.textGetter() |
| 109 | + text = text.replace("- \"became key\" - not observed", "- \"became key\" - Done!") |
| 110 | + self.textSetter(text) |
| 111 | + |
| 112 | + def resignedKeyCallback(self, sender): |
| 113 | + text = self.textGetter() |
| 114 | + text = text.replace("- \"resigned key\" - not observed", "- \"resigned key\" - Done!") |
| 115 | + self.textSetter(text) |
| 116 | + |
| 117 | + |
| 118 | +if __name__ == "__main__": |
| 119 | + from vanilla.test.testTools import executeVanillaTest |
| 120 | + executeVanillaTest(TestWindowBindingsLauncher) |
0 commit comments