Switch amongst GUI input hooks by name. This is just a utility wrapper around the methods of the InputHookManager object. Parameters ---------- gui : optional, string or None If None (or 'none'), clears input hook, otherwise it must be one of the recognized GUI name
(gui=None, app=None)
| 516 | |
| 517 | # Convenience function to switch amongst them |
| 518 | def enable_gui(gui=None, app=None): |
| 519 | """Switch amongst GUI input hooks by name. |
| 520 | |
| 521 | This is just a utility wrapper around the methods of the InputHookManager |
| 522 | object. |
| 523 | |
| 524 | Parameters |
| 525 | ---------- |
| 526 | gui : optional, string or None |
| 527 | If None (or 'none'), clears input hook, otherwise it must be one |
| 528 | of the recognized GUI names (see ``GUI_*`` constants in module). |
| 529 | |
| 530 | app : optional, existing application object. |
| 531 | For toolkits that have the concept of a global app, you can supply an |
| 532 | existing one. If not given, the toolkit will be probed for one, and if |
| 533 | none is found, a new one will be created. Note that GTK does not have |
| 534 | this concept, and passing an app if ``gui=="GTK"`` will raise an error. |
| 535 | |
| 536 | Returns |
| 537 | ------- |
| 538 | The output of the underlying gui switch routine, typically the actual |
| 539 | PyOS_InputHook wrapper object or the GUI toolkit app created, if there was |
| 540 | one. |
| 541 | """ |
| 542 | |
| 543 | if get_return_control_callback() is None: |
| 544 | raise ValueError("A return_control_callback must be supplied as a reference before a gui can be enabled") |
| 545 | |
| 546 | guis = { |
| 547 | GUI_NONE: clear_inputhook, |
| 548 | GUI_OSX: enable_mac, |
| 549 | GUI_TK: enable_tk, |
| 550 | GUI_GTK: enable_gtk, |
| 551 | GUI_WX: enable_wx, |
| 552 | GUI_QT: enable_qt, |
| 553 | GUI_QT4: enable_qt4, |
| 554 | GUI_QT5: enable_qt5, |
| 555 | GUI_GLUT: enable_glut, |
| 556 | GUI_PYGLET: enable_pyglet, |
| 557 | GUI_GTK3: enable_gtk3, |
| 558 | } |
| 559 | try: |
| 560 | gui_hook = guis[gui] |
| 561 | except KeyError: |
| 562 | if gui is None or gui == "": |
| 563 | gui_hook = clear_inputhook |
| 564 | else: |
| 565 | e = "Invalid GUI request %r, valid ones are:%s" % (gui, list(guis.keys())) |
| 566 | raise ValueError(e) |
| 567 | return gui_hook(app) |
| 568 | |
| 569 | |
| 570 | __all__ = [ |
no test coverage detected