-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwin_list.py
More file actions
executable file
·227 lines (211 loc) · 8.16 KB
/
win_list.py
File metadata and controls
executable file
·227 lines (211 loc) · 8.16 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
###
# Application: wah!cade
# File: win_list.py
# Description: Wah!Cade Setup - Edit Games List window
# Copyright (c) 2005-2010 Andy Balcombe <http://www.anti-particle.com>
###
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
import os
from constants import *
from glade2 import *
from mamewah_ini import MameWahIni
from wc_common import WahCade
import filters
_ = gettext.gettext
class WinList(GladeSupport, WahCade):
"""wahcade setup - edit list window"""
NUM_COLS = 13
def __init__(self, glade_filename, window_name, emu_name, emu_list_idx):
"""build the window"""
WahCade.__init__(self)
GladeSupport.__init__(self, glade_filename, window_name, APP_NAME)
self.config_dir = CONFIG_DIR
self.emu_name = emu_name
self.emu_list_idx = emu_list_idx
#games list
self.tvwList, self.lsList, self.tvwsList = self.setup_treeview(
columns = [
'Game Name',
'ROM Name',
'Year',
'Manufacturer',
'Clone Of',
'Rom Of',
'Display Type',
'Screen Type',
'Controller Type',
'Driver Status',
'Colour Status',
'Sound Status',
'Category'],
column_types = [gobject.TYPE_STRING] * self.NUM_COLS,
container = self.scwList,
edit_cell_cb = self.on_tvwList_edited,
resizeable_cols = True,
highlight_rows = False)
#self.tvwList.connect('row-activated', self.on_tvwList_activated)
self.tvwList.connect('key-release-event', self.on_tvwList_key_event)
#activate multiple selection mode on tvwsList
self.tvwsList.set_mode(gtk.SELECTION_MULTIPLE)
#load lists
i = 0
emu_game_lists = []
while True:
ini_file = os.path.join(self.config_dir, 'ini', '%s-%s.ini' % (self.emu_name, i))
if os.path.isfile(ini_file):
list_ini = MameWahIni(ini_file)
emu_game_lists.append(list_ini.get('list_title'))
i += 1
else:
break
l = ['%s: %s' % (i, r) for i, r in enumerate(emu_game_lists)]
self.setup_combo_box(self.cboList, l)
#setup filters & emu ini
emu_ini_filename = os.path.join(self.config_dir, 'ini', '%s.ini' % (self.emu_name))
if os.path.isfile(emu_ini_filename):
self.emu_ini = MameWahIni(emu_ini_filename)
#filters._mameinfo_file = os.path.join(self.emu_ini.get('dat_file'))
filters._catver_ini = os.path.join(self.emu_ini.get('catver_ini_file'))
else:
print _("Error: Emulator Ini file: [%s] doesn't exist" % (emu_ini_filename))
#load filter
self.new_iter = None
self.new_path = None
self.new_col = 0
self.list_altered = False
self.cboList.set_active(self.emu_list_idx)
def on_winList_delete_event(self, *args):
"""window closed"""
self.save_list_query()
#close window
self.winList.destroy()
return False
def on_btnAdd_clicked(self, *args):
"""add a new row"""
self.new_iter = self.lsList.append(([''] * self.NUM_COLS))
self.new_path = self.lsList.get_path(self.new_iter)
self.new_col = 0
tvc = self.tvwList.get_column(0)
self.tvwList.set_cursor(self.new_path, tvc, True)
def on_btnRemove_clicked(self, *args):
"""remove selected rows"""
rows2remove = []
self.tvwsList.selected_foreach(self.remove_selected, rows2remove)
if len(rows2remove) > 0:
for row in rows2remove:
self.lsList.remove(row)
self.update_total_games()
self.list_altered = True
def remove_selected(self, model, path, iter, data=None):
"""remove selected rows from list"""
data.append(iter)
def on_btnSave_clicked(self, *args):
"""save"""
filters.write_filtered_list(
self.list_filename,
self.lsList)
self.list_altered = False
def on_btnClose_clicked(self, *args):
"""close"""
self.on_winList_delete_event()
def on_tvwList_key_event(self, widget, event, *args):
"""keyboard event on list"""
if event.type == gtk.gdk.KEY_RELEASE:
#keyboard pressed, get gtk keyname
keyname = gtk.gdk.keyval_name(event.keyval).lower()
if keyname == 'tab' and self.new_iter and self.new_path:
self.new_col += 1
if self.new_col >= self.NUM_COLS:
self.new_col = 0
tvc = self.tvwList.get_column(self.new_col)
self.tvwList.scroll_to_cell(self.new_path, tvc)
self.tvwList.set_cursor(self.new_path, tvc, True)
def on_tvwList_edited(self, cell, path, new_text, user_data, *args):
"""list edited"""
ls, col = user_data
if col == 0 and new_text == '':
dlg = gtk.MessageDialog(
self.winList,
gtk.DIALOG_MODAL,
gtk.MESSAGE_ERROR,
gtk.BUTTONS_CLOSE,
_('You must set a rom name'))
resp = dlg.run()
dlg.destroy()
else:
#set
self.list_altered = True
ls[path][col] = new_text
self.update_total_games()
def on_cboList_changed(self, *args):
"""emulator list combo"""
#get settings for current emu list
self.save_list_query()
self.emu_list_idx = self.cboList.get_active()
if self.emu_list_idx >= 0:
self.load_list()
def load_list(self):
"""load games list"""
#clear games list
self.lsList.clear()
#set filename
self.list_filename = os.path.join(
self.config_dir,
'files',
'%s-%s.lst' % (self.emu_name, self.emu_list_idx))
#load list (if it exists)
if os.path.isfile(self.list_filename):
games_list, games_list_len = filters.read_filtered_list(self.list_filename)
games_list.sort()
[self.lsList.append(r) for r in games_list]
self.update_total_games()
elif self.emu_list_idx == 0:
print _('Please Wait. Creating initial filter...')
#self.message.display_message(_('Please Wait'), _('Creating initial filter...'))
#self.list_creation_attempted = True
#self.do_events()
filters.create_initial_filter(
self.emu_ini.get('dat_file'),
os.path.join(
self.config_dir,
'files',
'%s-0.ftr' % (self.emu_name)),
self.list_filename,
self.emu_ini)
self.load_list()
def save_list_query(self):
"""prompt to save changes if necessary"""
if self.list_altered:
dlg = gtk.MessageDialog(
self.winList,
gtk.DIALOG_MODAL,
gtk.MESSAGE_QUESTION,
gtk.BUTTONS_YES_NO,
_('Save List changes?'))
resp = dlg.run()
if resp == gtk.RESPONSE_YES:
self.on_btnSave_clicked()
dlg.destroy()
return True
else:
return False
def update_total_games(self):
"""Refresh the total number of the games"""
self.lblTotalGames.set_text(_('%s games' % (len(self.lsList))))