changeset 531:a7dc55ad9380

Display important messages in popups, instead of the terminal.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 19 Dec 2013 00:44:18 +0100
parents 64d9117b9209
children dacdcca59b66
files eosd pytouhou/lib/_sdl.pxd pytouhou/lib/sdl.pxd pytouhou/lib/sdl.pyx
diffstat 4 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/eosd
+++ b/eosd
@@ -64,7 +64,7 @@ elif args.backend == 'sdl':
     from pytouhou.ui.sdl.gamerenderer import GameRenderer
     opengl = False
 
-from pytouhou.lib.sdl import SDL
+from pytouhou.lib.sdl import SDL, show_simple_message_box
 from pytouhou.ui.window import Window
 from pytouhou.resource.loader import Loader
 from pytouhou.ui.gamerunner import GameRunner
@@ -117,8 +117,8 @@ def main(window, path, data, stage_num, 
     try:
         resource_loader.scan_archives(data)
     except IOError:
-        sys.stderr.write('Some data files were not found, did you forget the -p option?\n')
-        exit(1)
+        show_simple_message_box(u'Some data files were not found, did you forget the -p option?')
+        sys.exit(1)
 
     if stage_num is None:
         story = True
@@ -236,7 +236,7 @@ def main(window, path, data, stage_num, 
                 break
             stage_num += 1
         except GameOver:
-            print('Game over')
+            show_simple_message_box(u'Game over!')
             break
         finally:
             if save_filename:
--- a/pytouhou/lib/_sdl.pxd
+++ b/pytouhou/lib/_sdl.pxd
@@ -193,6 +193,10 @@ cdef extern from "SDL_ttf.h" nogil:
     SDL_Surface *TTF_RenderUTF8_Blended(TTF_Font *font, const char *text, SDL_Color fg)
 
 
+cdef extern from "SDL_messagebox.h" nogil:
+    int SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, SDL_Window *window)
+
+
 cdef extern from "SDL_blendmode.h" nogil:
     ctypedef enum SDL_BlendMode:
         SDL_BLENDMODE_NONE
--- a/pytouhou/lib/sdl.pxd
+++ b/pytouhou/lib/sdl.pxd
@@ -122,3 +122,4 @@ cdef Music load_music(const char *filena
 cdef Chunk load_chunk(file_)
 cdef Uint32 get_ticks() nogil
 cdef void delay(Uint32 ms) nogil
+cpdef int show_simple_message_box(unicode message)
--- a/pytouhou/lib/sdl.pyx
+++ b/pytouhou/lib/sdl.pyx
@@ -351,3 +351,8 @@ cdef Uint32 get_ticks() nogil:
 
 cdef void delay(Uint32 ms) nogil:
     SDL_Delay(ms)
+
+
+cpdef int show_simple_message_box(unicode message):
+    text = message.encode('UTF-8')
+    return SDL_ShowSimpleMessageBox(1, 'PyTouhou', text, NULL)