From aaeadf736a441ddc0d18b29a341124d6f764c376 Mon Sep 17 00:00:00 2001 From: Jeff Armstrong Date: Tue, 19 Jul 2011 22:01:34 -0400 Subject: Started implementing Pythonic interfaces to GEM routines. --- gem/aes.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 gem/aes.py (limited to 'gem/aes.py') diff --git a/gem/aes.py b/gem/aes.py new file mode 100644 index 0000000..ac29463 --- /dev/null +++ b/gem/aes.py @@ -0,0 +1,64 @@ +import _gem + +from error import GEMError + +def alert(message,type=None,buttons=('Ok',),default=None): + """Displays a generic GEM alert box with the specified + message. The type of box may also be specified as one + of ('none', 'exclamation', 'question', 'stop', 'info', + 'disk', 'bomb'). The buttons parameter can contain a + tuple or list of button texts (up to 3, as limited by + GEM.""" + + alert_types = ['none', 'exclamation', 'question', + 'stop', 'info', 'disk', 'bomb'] + try: + internal_type = alert_type.index(type.lower()) + except ValueError: + raise GEMError('Unknown alert box type') + except AttributeError: + if type is None: + internal_type = 0 + else: + internal_type = type + + if default is None: + default = 0 + elif type(default) is str: + try: + default = buttons.index(default) + except ValueError: + raise GEMError('Could not locate default button') + + bstring = '' + if len(buttons) > 3: + buttons = buttons[0:3] + for button in buttons: + if len(button) > 10: + button = button[0:10] + bstring = bstring + button + '|' + bstring = bstring[:-1] + + astring = "[{0}][{1}][{2}]".format(repr(internal_type), + message, bstring) + + return _gem.form_alert(default, astring) + +class Window: + def __init__(self, type): + + self.id = _gem.wind_create(type,(0,0,10,10)) + + +class Application: + + def __init__(self): + self.id = _gem.appl_init() + if self.id == -1: + raise GEMError("The application failed to initialize") + + self.windows = [] + + def destroy(self): + _gem.appl_exit(self.id) + \ No newline at end of file -- cgit v1.2.3