All pastes #408012 Raw Edit

Unnamed

public python v1 · immutable
#408012 ·published 2007-03-24 14:41 UTC
rendered paste body
#!/usr/bin/pythonimport wximport ConfigParserimport osimport stringclass MainFrame(wx.Frame):    def __init__(self, parent, id, title):        self.readcfg()        self.getdefaultmaps()        wx.Frame.__init__(self, parent, id, title, (-1, -1), wx.Size(350, 350))        panel = wx.Panel(self, -1)        sizer = wx.BoxSizer(wx.VERTICAL)                #Mods        mod = wx.StaticBox(panel, -1, 'Select a mod')                mod_sizer = wx.StaticBoxSizer(mod)        self.selectmod = wx.ListBox(panel, 4, choices=self.mods, size=(-1, 80))        mod_sizer.Add(self.selectmod, 1)                #Maps        map = wx.StaticBox(panel, -1, 'Select a map')        map_sizer = wx.StaticBoxSizer(map)        self.selectmap = wx.ListBox(panel, 5, choices=self.maps, size=(-1, 80))        map_sizer.Add(self.selectmap, 1)        #Buttons        buttons = wx.StaticBox(panel, -1, '')        button_sizer = wx.StaticBoxSizer(buttons,)                button_sizer.Add(wx.Button(panel, 1, 'Quit'),1, wx.ALIGN_BOTTOM)        button_sizer.Add(wx.Button(panel, 2, 'About'),1, wx.ALIGN_BOTTOM)        button_sizer.Add(wx.Button(panel, 6, 'Detect Mods'),1, wx.ALIGN_BOTTOM)        button_sizer.Add(wx.Button(panel, 3, 'Launch!'),1, wx.ALIGN_BOTTOM)                        #Netplay        net= wx.StaticBox(panel, -1, 'Multiplayer')        net_sizer = wx.StaticBoxSizer(net, wx.VERTICAL)                cb_sizer = wx.GridSizer(rows=2, cols=2,)        sv_sizer = wx.StaticBoxSizer(net, wx.HORIZONTAL)                self.server = wx.RadioButton(panel, -1, 'Connect to Server',  style=wx.RB_GROUP)        self.splitscreencb = wx.RadioButton(panel, -1, 'Splitscreen')        self.host = wx.RadioButton(panel, -1, 'Host Server')        self.single = wx.RadioButton(panel, -1, 'SinglePlayer')               self.serverip = wx.TextCtrl(panel, -1, self.ip, size=(200,-1))        self.register = wx.CheckBox(panel, -1, 'Register Online')        self.updatevisibility(-1)        self.loadcfg()                cb_sizer.Add(self.server)        cb_sizer.Add(self.splitscreencb)        cb_sizer.Add(self.host)        cb_sizer.Add(self.single)                sv_sizer.Add(self.serverip)        sv_sizer.Add(self.register)                net_sizer.Add(cb_sizer, 0,wx.EXPAND)        net_sizer.Add(sv_sizer, 0,wx.EXPAND)                sizer.Add(mod_sizer, 0, wx.EXPAND)        sizer.Add(map_sizer, 0, wx.EXPAND)        sizer.Add(net_sizer, 1, wx.EXPAND)        sizer.Add(button_sizer, 0, wx.EXPAND)                panel.SetSizer(sizer)                #Set the mod to default in case the user hasn't selected anything        self.currentmod= 'default'        self.currentmodname= 'Default Gusanos-Mod'        #Set the map to blat in case the user hasn't selected anything        self.currentmap = 'blat'                self.Centre()        self.Bind(wx.EVT_BUTTON, self.quit, id=1)        self.Bind(wx.EVT_BUTTON, self.about, id=2)        self.Bind(wx.EVT_BUTTON, self.launch, id=3)        self.Bind(wx.EVT_LISTBOX, self.OnSelect, id=4)        self.Bind(wx.EVT_LISTBOX, self.OnMapSelect, id=5)        self.Bind(wx.EVT_BUTTON, self.detectmods, id=6)        self.Bind(wx.EVT_RADIOBUTTON, self.updatevisibility)                if len(self.mods) != len(self.moddirs):            warning = wx.MessageDialog(self, "The number of moddirs in your guslauncher.cfg doesn't seem to to be the same as the number of mods!\n\n"                                       'Please try to fix that, otherwise things might start getting nasty.' ,'Warning!', wx.OK | wx.ICON_WARNING)            warning.ShowModal()            warning.Destroy()                def detectmods(self, event):        newmods = [i for i in os.listdir('.') if os.path.isdir(i)]        newmods = list(set(newmods) - set(self.moddirs) -set(['screenshots']))        self.moddirs += newmods        self.mods += newmods        popup = wx.MessageDialog(self, 'Successfully detected '+str(len(newmods))+' new mod(s).', 'Success!', wx.OK | wx.ICON_INFORMATION)        popup.ShowModal()        popup.Destroy()        self.selectmod.SetItems(self.mods)    def updatevisibility(self, event):        if self.server.GetValue():            self.serverip.Enable()            self.selectmap.Disable()        else:            self.serverip.Disable()            self.selectmap.Enable()        if self.host.GetValue():            self.register.Enable()        else:            self.register.Disable()                def readcfg(self):        config = ConfigParser.ConfigParser()        config.read('guslauncher.cfg')        self.ip = config.get('MULTIPLAYER', 'ip')        self.mptype = config.get('MULTIPLAYER', 'type')        self.register_online = config.get('MULTIPLAYER', 'register_online')        self.mods = config.get('MODS','mods').split(',')        self.moddirs = config.get('MODS','moddirs').split(',')        print 'Loaded cfg:',self.ip, self.mptype, self.mods, self.moddirs,self.register_online    def loadcfg(self):        if self.mptype == 'connect':            self.server.SetValue(True)        if self.mptype == 'splitscreen':            self.splitscreencb.SetValue(True)        if self.mptype == 'host':            self.host.SetValue(True)        if self.mptype == 'single':            self.single.SetValue(True)        if self.register_online == 'true':            self.register.SetValue(True)        else:            self.register.SetValue(False)                def getdefaultmaps(self):        self.defaultmaps = os.listdir('./default/maps')        self.defaultmaps.remove('llp')        llpmaps =os.listdir('./default/maps/llp')        llpmaps = [string[:-4] for string in llpmaps]        self.defaultmaps += llpmaps        self.defaultmaps.insert(0,'====DEFAULT MAPS====')        self.maps = self.defaultmaps            def getmodmaps(self):        if self.currentmod != 'default':            modmaps = os.listdir('./'+self.currentmod+'/maps')            if modmaps != []:                modmaps.insert(0,'===='+self.currentmodname+'\'s MAPS====')                self.maps = self.defaultmaps+modmaps        else:            self.maps = self.defaultmaps        self.selectmap.SetItems(self.maps)                                        def OnSelect(self, event):        item = event.GetSelection()        self.currentmod= self.moddirs[item]        self.currentmodname = self.mods[item]        self.getmodmaps()            def OnMapSelect(self, event):        item = event.GetSelection()        if self.maps[item]!='====DEFAULT MAPS====' and self.maps[item]!='===='+self.currentmodname+'\'s MAPS====':            self.currentmap = self.maps[item]                    def quit(self, event):        self.savecfg()        self.Close(True)        def savecfg(self):        config = ConfigParser.ConfigParser()        config.read('guslauncher.cfg')        if self.server.GetValue():            config.set('MULTIPLAYER', 'type', 'connect')        if self.splitscreencb.GetValue():            config.set('MULTIPLAYER', 'type', 'splitscreen')        if self.host.GetValue():            config.set('MULTIPLAYER', 'type', 'host')        if self.single.GetValue():            config.set('MULTIPLAYER', 'type', 'single')        config.set('MULTIPLAYER', 'ip', str(self.serverip.GetValue()))        if self.register.GetValue():            config.set('MULTIPLAYER', 'register_online', 'true')        else:            config.set('MULTIPLAYER', 'register_online', 'false')        config.set('MODS', 'mods',  ','.join(self.mods))        config.set('MODS', 'moddirs', ','.join(self.moddirs))        config.write(open('guslauncher.cfg', 'w'))                    def launch(self, launch):        guscmd = './gusanos -c \'game '+string.replace(self.currentmod,"'",'')+'\' -c \'map '+string.replace(self.currentmap,"'",'')+' \''+'-c \'cl_splitscreen '        if self.splitscreencb.GetValue():            guscmd += '1\''        else:            guscmd += '0\''        if self.server.GetValue():            guscmd+=' -c'+' \'connect '+str(self.serverip.GetValue())+'\''        if self.host.GetValue():            guscmd += ' -c'+' \'host 1\''            if self.register.GetValue():                guscmd+=' -c'+' \'net_register 1\''            else:                guscmd+=' -c'+' \'net_register 0\''        print 'Launching: \''+guscmd + '\''        os.system(guscmd)                    def about(self, about):        popup = wx.MessageDialog(self, 'Gusanos Launcher by mots\n'        'Version 0.1\n\n'        'visit #liero on irc.quakenet.org for more information', 'About', wx.OK | wx.ICON_INFORMATION)        popup.ShowModal()        popup.Destroy()class App(wx.App):     def OnInit(self):         frame = MainFrame(None, -1, 'Gusanos Launcher')         frame.Show(True)         return Trueapp = App(0)app.MainLoop()