[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] wx Menu



No, I don't think it would go in SDLPanel - I think the menu stuff
should go in MyFrame (the top level wx.Frame) which contains the SDL
panel.

I just copied the menu bar stuff from your first email, into the SDL
inside wx code of your last email and got the code below, which seems
to run just fine (I had to comment out WindowInit() cause it wasn't
defined though)
-------------------
import wx
import thread
import os, sys
global pygame
from pygame.locals import *
class SDLThread:
    def __init__(self,screen):
        self.m_bKeepGoing = self.m_bRunning = False
        self.screen = screen
        self.color = (255,0,0)
        self.rect = (10,10,100,100)
    def Start(self):
        self.m_bKeepGoing = self.m_bRunning = True
        thread.start_new_thread(self.Run, ())
    def Stop(self):
        self.m_bKeepGoing = False
    def IsRunning(self):
        return self.m_bRunning
    def Run(self):
        while self.m_bKeepGoing:
            GetInput()
            Draw()
        self.m_bRunning = False;
class SDLPanel(wx.Panel):
    def __init__(self,parent,ID,tplSize):
        #I'm guessing it goes somewhere in here, but I don't know if
that is true
        #and how I should do it.  I already tried some things, but
they didn't work.

        global pygame
        wx.Panel.__init__(self, parent, ID, size=tplSize)
        self.Fit()
        os.environ['SDL_WINDOWID'] = str(self.GetHandle())
        os.environ['SDL_VIDEODRIVER'] = 'windib'
        import pygame
        pygame.init()
        icon = pygame.Surface((1,1));icon.set_alpha(0);pygame.display.set_icon(icon)
        global Surface
        Surface = pygame.display.set_mode(tplSize)
        #WindowInit()
        self.thread = SDLThread(Surface)
        self.thread.Start()
    def __del__(self):
        self.thread.Stop()
class MyFrame(wx.Frame):
    def __init__(self, parent, ID, strTitle, tplSize):
        wx.Frame.__init__(self, parent, ID, strTitle, size=tplSize)
        self.pnlSDL = SDLPanel(self, -1, tplSize)
        ###########
        # MENU BAR
        ###########

        # First define the menubar object
        menubar = wx.MenuBar()

        # Now define our pulldown menus.
        file_menu = wx.Menu()

        about = wx.MenuItem(file_menu, 2, '&About') # note the id's (2
in this case) must match in the binding below
        self.Bind(wx.EVT_MENU, self.OnDummy, id=2)   # This is the
binding, which tells Python what to do when someone clicks that entry.
The function name (OnDummy in this case) can be anything, but the
function must exist.
        file_menu.AppendItem(about) # add it to the file menu

        file_menu.AppendSeparator() # a separator, strictly cosmetic

        quit_item = wx.MenuItem(file_menu, 3, 'Quit!')
        self.Bind(wx.EVT_MENU, self.OnDummy, id=3) # again, binding an
action. Note that the function name (OnQuit) can be anything, but must
exist.
        file_menu.AppendItem(quit_item)

        # Another pulldown menu
        help_menu = wx.Menu()

        help_item = wx.MenuItem(help_menu, 4, 'Help')
        self.Bind(wx.EVT_MENU, self.OnDummy, id=4)
        help_menu.AppendItem(help_item)

        menubar.Append(file_menu, '&File   ')
        menubar.Append(help_menu, 'Help   ')

        self.SetMenuBar(menubar)
    def OnDummy(self, event):
        print "Clicked!"
if __name__ == '__main__':
    app = wx.PySimpleApp()
    Title = "The Programmer's Paint - v.6.0.0 - Ian Mallett - 2008"
    frame = MyFrame(None, wx.ID_ANY, Title, (800,600))
    frame.Show()
    app.MainLoop()