#!/usr/bin/python import wx import ConfigParser import os import string #-c"MY_COMMAND" class MainFrame(wx.Frame): def __init__(self, parent, id, title): self.readcfg() wx.Frame.__init__(self, parent, id, title, (-1, -1), wx.Size(350, 250)) 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, -1, choices=self.mods, size=(-1, 80)) mod_sizer.Add(self.selectmod, 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, 3, 'Launch!'),1, wx.ALIGN_BOTTOM) #Netplay net= wx.StaticBox(panel, -1, 'Multiplayer') net_sizer = wx.StaticBoxSizer(net, wx.VERTICAL) self.server = wx.CheckBox(panel, -1, 'Connect to Server') if self.netplay=='true': self.server.SetValue(True) else: self.server.SetValue(False) net_sizer.Add(wx.CheckBox(panel, -1, 'Splitscreen')) self.serverip =wx.TextCtrl(panel, -1, self.ip, size=(200, -1)) net_sizer.Add(self.server) net_sizer.Add(self.serverip) sizer.Add(mod_sizer, 0, wx.EXPAND) sizer.Add(net_sizer, 1, wx.EXPAND) sizer.Add(button_sizer, 0, wx.EXPAND) panel.SetSizer(sizer) 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) 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 readcfg(self): config = ConfigParser.ConfigParser() config.read('guslauncher.cfg') self.ip = config.get('MULTIPLAYER', 'ip') self.splitscreen= config.get('MULTIPLAYER', 'splitscreen') self.netplay=config.get('MULTIPLAYER', 'netplay') self.mods = config.get('MODS','mods').split(',') self.moddirs = config.get('MODS','moddirs').split(',') print self.ip, self.splitscreen, self.netplay, self.mods, self.moddirs def OnSelect(self, event): item = event.GetSelection() self.currentmod= self.moddirs[item] def quit(self, event): self.savecfg() self.Close(True) def savecfg(self): config = ConfigParser.ConfigParser() config.read('guslauncher.cfg') # config.set('MULTIPLAYER', 'splitscreen', str(self.splitscreen)) if self.server: config.set('MULTIPLAYER', 'netplay', 'true') else: config.set('MULTIPLAYER', 'netplay', 'false') config.set('MULTIPLAYER', 'ip', str(self.serverip.GetValue())) config.write(open('guslauncher.cfg', 'w')) def launch(self, launch): guscmd = 'gusanos -c \'game '+string.replace(self.currentmod,"'",'')+'\'' if self.server: guscmd += ' -c'+' \'connect '+str(self.serverip.GetValue())+'\'' #guscmd += '\'' 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 True app = App(0) app.MainLoop()