| 1 |
## Stella.py
|
| 2 |
## Ver .003
|
| 3 |
## This is the custom front-end to Stella the NinoSystems Home Arcade System.
|
| 4 |
## 01.13.03
|
| 5 |
## EBorges
|
| 6 |
##
|
| 7 |
## Update: I had to change this entire program to a class because the ImageTk
|
| 8 |
## Object keeps going out of scope and getting garbage collected.
|
| 9 |
|
| 10 |
|
| 11 |
from Tkinter import *
|
| 12 |
import os, sys, Pmw, Image, ImageTk
|
| 13 |
|
| 14 |
class MainGUI:
|
| 15 |
def __init__(self, gamesList, stellaGamesDB,artWorkDir,screenShotDir):
|
| 16 |
self.root = Pmw.initialise()
|
| 17 |
self.gameListBox = Pmw.ScrolledListBox(self.root, items = gamesList, usehullsize = 1
|
| 18 |
, hull_width = 300, hull_height = 500)
|
| 19 |
#self.gameListBox.configure(selectioncommand = (lambda event = "",gameObj = self.gameListBox
|
| 20 |
# ,DB = stellaGamesDB:RunGame(event,gameObj,DB)))
|
| 21 |
#gameListBox.pack(fill = 'both', expand = 1, padx = 10, pady = 10)
|
| 22 |
self.gameListBox.pack(side = "left",padx = 10, pady = 10)
|
| 23 |
self.gameListBox.bind_all('<Return>',self.test)
|
| 24 |
self.gameListBox.bind_all('<KeyPress-x>',(lambda event = "",gameObj = self.gameListBox,
|
| 25 |
DB = stellaGamesDB:RunGame(event,gameObj,DB)))
|
| 26 |
self.marqueBox = Label(self.root,relief = 'ridge', borderwidth = 2)
|
| 27 |
self.screenShotBox = Label(self.root,relief = 'ridge',borderwidth = 2)
|
| 28 |
self.screenShotBox2 = Label(self.root,relief = 'ridge', borderwidth = 2)
|
| 29 |
self.marqueBox.pack(side = 'top', pady = 10, padx = 10)
|
| 30 |
self.screenShotBox.pack(side = 'top')
|
| 31 |
self.screenShotBox2.pack(side = 'top',pady =10)
|
| 32 |
self.gameListBox.bind_all('<KeyPress-Up>',(lambda event = "", s = self,dir1 = artWorkDir, dir2 = screenShotDir,
|
| 33 |
DB = stellaGamesDB:s.ShowPictures(dir1,dir2,DB)))
|
| 34 |
self.gameListBox.bind_all('<KeyPress-Down>',(lambda event = "", s = self,dir1 = artWorkDir, dir2 = screenShotDir,
|
| 35 |
DB = stellaGamesDB:s.ShowPictures(dir1,dir2,DB)))
|
| 36 |
#self.gameListBox.bind_all('<KeyPress-z>',self.ShowPictures)
|
| 37 |
self.root.title('Stella.PY Ver .003')
|
| 38 |
self.root.mainloop()
|
| 39 |
|
| 40 |
def test(self,event):
|
| 41 |
print "test"
|
| 42 |
|
| 43 |
|
| 44 |
def ShowPictures(self,marqDir,ssDir,DB):
|
| 45 |
infoOnly = "yes"
|
| 46 |
event = ""
|
| 47 |
game = RunGame(event,self.gameListBox,DB,infoOnly)
|
| 48 |
marqDir = marqDir + "\\" + game + ".png"
|
| 49 |
if os.path.isfile(marqDir):
|
| 50 |
pass
|
| 51 |
else:
|
| 52 |
marqDir = os.path.split(marqDir)[0]+ "\\" + "default.png"
|
| 53 |
ssDir2 = ssDir + "\\" + game + "2.png"
|
| 54 |
if os.path.isfile(ssDir2):
|
| 55 |
pass
|
| 56 |
else:
|
| 57 |
ssDir2 = os.path.split(ssDir2)[0] + "\\" + "default.png"
|
| 58 |
ssDir = ssDir + "\\" + game + ".png"
|
| 59 |
if os.path.isfile(ssDir):
|
| 60 |
pass
|
| 61 |
else:
|
| 62 |
ssDir = os.path.split(ssDir)[0] + "\\" + "default.png"
|
| 63 |
self.marq = ImageTk.PhotoImage(file = marqDir)
|
| 64 |
self.marqueBox['image'] = self.marq
|
| 65 |
self.ss1 = ImageTk.PhotoImage(file = ssDir)
|
| 66 |
self.screenShotBox['image'] = self.ss1
|
| 67 |
self.ss2 = ImageTk.PhotoImage(file = ssDir2)
|
| 68 |
self.screenShotBox2['image'] = self.ss2
|
| 69 |
|
| 70 |
def GetGameName(gameName, mameGamesDB):
|
| 71 |
o=open(mameGamesDB,'r')
|
| 72 |
GamesList = o.readlines()
|
| 73 |
position = 0
|
| 74 |
for x in GamesList:
|
| 75 |
found = x.find(gameName)
|
| 76 |
if found != -1:
|
| 77 |
break
|
| 78 |
else:
|
| 79 |
position = position + 1
|
| 80 |
if found == -1:
|
| 81 |
print "%s was not found in the database..." %(gameName)
|
| 82 |
results = "%s was not found in the database..." %(gameName)
|
| 83 |
else:
|
| 84 |
realName = GamesList[position]
|
| 85 |
realName = realName.split("|")
|
| 86 |
realName = realName[1]
|
| 87 |
realName = realName.strip()
|
| 88 |
print "The real name for %s is %s" %(gameName, realName)
|
| 89 |
results = realName
|
| 90 |
o.close()
|
| 91 |
return results
|
| 92 |
|
| 93 |
def Check4NewGames(romsDir, stellaGamesList, artWorkDir, screenShotDir, mameGamesDB):
|
| 94 |
romsList = os.listdir(romsDir)
|
| 95 |
newList = []
|
| 96 |
for x in romsList:
|
| 97 |
y = x.split('.zip')
|
| 98 |
newList.append(y[0])
|
| 99 |
romsList = newList
|
| 100 |
o=open(stellaGamesList, 'r')
|
| 101 |
contents = o.readlines()
|
| 102 |
o.close()
|
| 103 |
stellaGamesDB = {}
|
| 104 |
gamesList = []
|
| 105 |
for x in contents:
|
| 106 |
y = x.rstrip()
|
| 107 |
y = y.split('=',1)
|
| 108 |
gamesList.append(y[0])
|
| 109 |
stellaGamesDB[y[1]] = y[0]
|
| 110 |
for i in romsList:
|
| 111 |
newGame = stellaGamesDB.has_key(i)
|
| 112 |
if newGame == 0:
|
| 113 |
gamesList.append(AddNewGame(i,mameGamesDB,stellaGamesList))
|
| 114 |
print "New Game found. %s" %(i)
|
| 115 |
start = MainGUI(gamesList,stellaGamesDB,artWorkDir,screenShotDir)
|
| 116 |
start()
|
| 117 |
|
| 118 |
def AddNewGame(game,mameGamesDB,stellaGamesList):
|
| 119 |
realName = GetGameName(game,mameGamesDB)
|
| 120 |
w = open(stellaGamesList, 'a')
|
| 121 |
output = realName + "=" + game + "\n"
|
| 122 |
w.write(output)
|
| 123 |
w.close()
|
| 124 |
# Since a new game was added, sort the list.
|
| 125 |
SortGames(stellaGamesList)
|
| 126 |
return realName
|
| 127 |
|
| 128 |
def SortGames(stellaGamesList):
|
| 129 |
r = open(stellaGamesList,'r')
|
| 130 |
output = r.readlines()
|
| 131 |
r.close()
|
| 132 |
output.sort()
|
| 133 |
w = open(stellaGamesList,'w')
|
| 134 |
w.writelines(output)
|
| 135 |
w.close()
|
| 136 |
|
| 137 |
def RunGame (event,gameObj,DB,infoOnly="no"):
|
| 138 |
print
|
| 139 |
game = gameObj.getcurselection()
|
| 140 |
print "Running %s" %(game)
|
| 141 |
list = DB.items()
|
| 142 |
for x in list:
|
| 143 |
if x[1] == game[0]:
|
| 144 |
zipGame = x[0]
|
| 145 |
break
|
| 146 |
if infoOnly =="no":
|
| 147 |
print "exc mame.exe %s.zip" %(zipGame)
|
| 148 |
os.system('cmd /k "C:\\Documents and Settings\\eaborges\\My Documents\\Downloads\\Mame54b\\mamepp.exe %s"'% zipGame)
|
| 149 |
else:
|
| 150 |
return zipGame
|
| 151 |
|
| 152 |
if __name__ == '__main__':
|
| 153 |
mameGamesDB = r"C:\Documents and Settings\eaborges\Desktop\MAME\MameGamesDB.txt"
|
| 154 |
stellaGamesList = r"C:\Documents and Settings\eaborges\Desktop\MAME\MainStellaGamesList.txt"
|
| 155 |
artWorkDir = r"C:\Documents and Settings\eaborges\Desktop\MAME\MameArtWork"
|
| 156 |
screenShotDir = r"C:\Documents and Settings\eaborges\Desktop\MAME\MameScreenShots"
|
| 157 |
romsDir = r"C:\Documents and Settings\eaborges\My Documents\Downloads\Mame54b\roms"
|
| 158 |
Check4NewGames(romsDir,stellaGamesList,artWorkDir,screenShotDir,mameGamesDB)
|
| 159 |
#MainGUI(stellaGamesList, mameGamesDB, artWorkDir, screenShotDir)
|
| 160 |
#GetGameName('mspacman', mameGamesDB) |