| 48 | ################################################################################ |
| 49 | |
| 50 | def main(): |
| 51 | # Create the opening window for the program. |
| 52 | NoDefaultRoot() |
| 53 | root = Tk() |
| 54 | assert not (USE_WINDOW and FULLSCREEN), \ |
| 55 | 'Only Window or Fullscreen may be used.' |
| 56 | # Define the closing event handler. |
| 57 | if COME_BACK < 0: |
| 58 | def close(event=None): |
| 59 | root.destroy() |
| 60 | else: |
| 61 | def close(event=None): |
| 62 | if COME_BACK: |
| 63 | root.withdraw() |
| 64 | sleep(COME_BACK) |
| 65 | for child in root.children.values(): |
| 66 | if isinstance(child, BoidGUI): |
| 67 | child.last_time += COME_BACK |
| 68 | root.deiconify() |
| 69 | # Create window based on settings. |
| 70 | if USE_WINDOW: |
| 71 | root.resizable(False, False) |
| 72 | root.title(TITLE) |
| 73 | width = WIDTH |
| 74 | height = HEIGHT |
| 75 | position = '' |
| 76 | elif FULLSCREEN: |
| 77 | root.overrideredirect(True) |
| 78 | if not SCR_SAVER: |
| 79 | root.bind_all('<Escape>', close) |
| 80 | width = root.winfo_screenwidth() |
| 81 | height = root.winfo_screenheight() |
| 82 | position = '+0+0' |
| 83 | else: |
| 84 | raise ValueError('Cannot determine window type to use.') |
| 85 | # Configure the root window as needed. |
| 86 | root.protocol('WM_DELETE_WINDOW', close) |
| 87 | if SCR_SAVER: |
| 88 | assert COME_BACK, 'Screen may not be locked as screensaver.' |
| 89 | root.bind_all('<Motion>', close) |
| 90 | root.bind_all('<Key>', close) |
| 91 | root.geometry('{0}x{1}{2}'.format(width, height, position)) |
| 92 | # Create the application object that handles the GUI. |
| 93 | app = BoidGUI(root, width, height, BACKGROUND, BOIDS) |
| 94 | app.grid() |
| 95 | root.mainloop() |
| 96 | |
| 97 | ################################################################################ |
| 98 | |