/
emuman.py
executable file
·207 lines (169 loc) · 4.34 KB
/
emuman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#! /usr/bin/python
# File: emuman.py
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import filereader
import gamewidget
import dbreader
import os
from os.path import isfile, join
import subprocess
##
# #
# Variables #
# #
##
rompath = ""
emupath = ""
rom = ""
gamegrid = []
searchterm = ""
##
# #
# Function Declarations #
# #
##
def updatelistGTK(widget, event) :
global conf
global flow
global win
global emupath
global rompath
print("UPDATING GTK LIST!!!!!")
option = (combo.get_active_text()).split()
emupath = conf.ret_path(int(option[0]))
rompath = conf.ret_rom(int(option[0]))
dbfile = conf.get_db(int(option[0]))
db = dbreader.DatabaseReader(dbfile)
print(rompath)
"""
listbox2.delete(0,END)
"""
if rompath != "" :
contents = os.listdir(rompath)
for f in range(0, len(contents)) :
if isfile(join(rompath, contents[f])) :
"""
h = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
h.add(Gtk.Label(contents[f]))
"""
tile = gamewidget.GameLabel(contents[f],"Game!",db.get_value(contents[f]))
gamegrid.append(tile)
print(contents[f])
#flow.add(h)
tile.setCallback(run_game_new)
flow.add(tile.getWidget())
win.show_all()
def run_gameGTK(widget) :
print("RUNNING GAME!!!!")
global win
global rompath
global emupath
global rom
global flow
widgets = flow.get_selected_children()
rom = widgets[0].get_children()[0].get_children()[0].get_text()
print(rom)
if rom == "" or rompath == "" or emupath == "" :
print("Error, not a valid choice")
else :
win.hide()
win.queue_draw()
while(Gtk.events_pending()) :
Gtk.main_iteration()
st = emupath + ' "' + rompath + rom + '"'
#print(st)
os.system(st)
win.show()
while(Gtk.events_pending()) :
Gtk.main_iteration()
def run_game_new(widget, rom_name) :
print("RUNNING GAME!!!!")
global win
global rompath
global emupath
global rom
global flow
rom = rom_name
print(rom)
if rom == "" or rompath == "" or emupath == "" :
print("Error, not a valid choice")
else :
win.hide()
win.queue_draw()
while(Gtk.events_pending()) :
Gtk.main_iteration()
st = emupath + ' "' + rompath + rom + '"'
#print(st)
#subprocess.call([emupath,rompath+rom])
subprocess.Popen([emupath,rompath+rom])
win.show()
def search_callback(widget, flow) :
#print(widget.get_text())
global searchterm
searchterm = widget.get_text()
flow.invalidate_filter()
def game_filter(child,userdata) :
s = child.get_children()[0].get_children()[1].get_text()
if(searchterm is "") :
return True
if(searchterm.lower() in s.lower() or s.lower() in searchterm.lower()) :
return True
return False
def delete_row(widget) :
global glistbox2
print("Deleting Row!!!!")
glistbox2.remove(widget)
##
# #
# Main #
# #
##
win = Gtk.Window()
header = Gtk.HeaderBar()
header.props.show_close_button = True
header.props.title = "Emuman"
win.set_titlebar(header)
win.connect("delete-event", Gtk.main_quit)
win.set_default_size(240,160)
win.set_size_request(240,160) #set minimum size
grid = Gtk.Grid()
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
vbox.pack_start(hbox, False, True, 0)
#vbox.add(grid)
win.add(vbox)
frame1 = Gtk.Frame(expand=False)
store = Gtk.ListStore(int, str)
combo = Gtk.ComboBoxText()
frame1.add(combo)
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
flow = Gtk.FlowBox()
flow.set_valign(Gtk.Align.START)
flow.set_max_children_per_line(30)
flow.set_filter_func(game_filter, None)
flow.set_homogeneous(True)
scrolled.add(flow)
vbox.pack_start(scrolled, True, True, 0)
hbox.pack_end(frame1, False, True, 0)
search = Gtk.Entry()
search.set_placeholder_text("Search")
hbox.pack_end(search, True, True, 0)
text = "default"
conf = filereader.FileReader()
conf.read_config()
num_consoles = conf.get_num_consoles()
for x in range(0, num_consoles) :
text = conf.get_console(x)
hb = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
hb.add(Gtk.Label(x))
hb.add(Gtk.Label(text))
combo.append_text(str(x)+" "+text)
combo.connect("changed", updatelistGTK, None)
search.connect("changed", search_callback, flow)
#Grab focus from search entry
scrolled.grab_focus()
win.show_all()
Gtk.main()