To fix these problems I attempted to integrate with wxPython, like this:

[code]
#!/usr/bin/env python

FRAMETITLE = 'Basic Frame test'
APPNAME = 'Basic Frame'

import sys, os, wx

pygame = None

class MainFrame(wx.Frame):
    def __init__(self, parent, ID, title, pos=wx.DefaultPosition,
size=wx.DefaultSize):
        # main window init
        wx.Frame.__init__(self, parent, ID, title, pos, size)
        self.Center()

        # menu bar
        menubar = wx.MenuBar()
        menu = wx.Menu()
        menu.Append(wx.ID_EXIT,  'E&xit\tAlt+X',  'Exit the program')
        menu.Append(wx.ID_ANY, '&Open\tCtrl+O', 'Open a file')
        menubar.Append(menu, '&File')
        menu = wx.Menu()
        menu.Append(wx.ID_ABOUT, '&About basicframe', 'About '+APPNAME)
        menubar.Append(menu, '&Help')
        self.SetMenuBar(menubar)

        # status bar
        self.CreateStatusBar()
        self.SetStatusText('This is the status bar')

        # menu event maps
        wx.EVT_MENU(self, wx.ID_EXIT,  self.onExit)
        wx.EVT_MENU(self, wx.ID_ABOUT, self.onAbout)

        self.Bind(wx.EVT_SIZE, self.onSize)

    def startPygame(self):
        global pygame
        hwnd = self.GetHandle()
        os.environ['SDL_WINDOWID'] = str(hwnd)
        if sys.platform == 'win32':
            os.environ['SDL_VIDEODRIVER'] = 'windib'
        import pygame as pgm
        pygame = pgm
        pygame.init()
        pygame.display.init()
        self.framesurface = pygame.display.set_mode(self.GetSizeTuple())

    def onAbout(self, event):
        msg  = "This test program tests out\n"
        msg += "frames, menus, statusbars, and this\n"
        msg += "message dialog."
        dlg = wx.MessageDialog(self, msg, "About basicframe", wx.OK |
wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

    def onExit(self, event):
        self.Close(True)

    def onSize(self, event):
        if pygame:
            self.framesurface = pygame.display.set_mode(self.GetSizeTuple())
        return True

class TheApp(wx.App):
    def OnInit(self):
        frame = MainFrame(None, wx.ID_ANY, FRAMETITLE)
        frame.Show(True)
        self.SetTopWindow(frame)
        frame.startPygame()
        return True

if __name__ == '__main__':
    app = TheApp(0)
    app.MainLoop()

[/code]


The result was interesting.  A second window, titled "pygame window", popped
up above the main window, which is titled "basic frame test".  The pygame
window is not resizable (naturally enough, as I didn't set that style in the
call to set_mode()).  When I resize the main window, the upper left corner
is fixed in place.. while I do that, the 2nd window does resize itself,
quite smoothly - but the lower left corner is fixed in place, so it grows
upward instead of downward, hehe.

In addition, I get this error:

_createMenuRef called with existing principal MenuRef already associated
with menu

.. and I get a second apple menu, with a "services" submenu.




On Sun, Dec 12, 2010 at 3:31 PM, Greg Ewing <[email protected]>wrote:

> Shavais Z wrote:
>
>> it seems weird to me that while there is this "Python" menu up there with
>> a "Quit" option that actually works, when you click it, but the advertised
>> shortcut key (Option Q) for it doesn't work.
>>
>
> +1 from me on fixing this too... it's really quite lame.
>
>
>  For some reason, the whole program just pauses when I click on the top
>> screen menu.  It just stops operating.  Why would that be?
>>
>
> Probably because the pygame event loop doesn't get a chance to
> run until you've finished playing with the menus. You might be
> able to fix this would be to use a separate thread for things
> that need to run regularly, although you might have problems
> getting the screen updated from that thread.
>
> If you can get the threaded approach to work, it might also
> solve the resizing issue, but I don't really know.
>
>
>  I guess we're waiting on a pygame update to make use of a more recent rev
>> of SDL at this point?
>>
>
> Recent SDL definitely eliminates the Quickdraw warnings. I don't
> think it will make a difference to any of the other things, though.
> I expect they're fundamentally related to the way SDL handles
> events.
>
> --
> Greg
>

Reply via email to