code cleanup

This commit is contained in:
punkrockguy318 2008-06-17 15:04:13 +00:00
parent d547cc57ba
commit e6cc29b7d2
1 changed files with 22 additions and 41 deletions

61
gfceu
View File

@ -35,11 +35,10 @@ from subprocess import Popen
# Messaging Functions # Messaging Functions
def gfceu_print(text, use_gtk=False): def gfceu_print(text, use_gtk=False):
""" """
gqfceu_message() gfceu_print()
This function prints messages to the user. This is generally used for status This function prints messages to the user. This is generally used for status
messages. However, it can be used for important messages as well. If a messages. If a GTK message_box is requried, the use_gtk flag can be enabled.
GTK message_box is requried, the use_gtk flag can be enabled
""" """
print text print text
if use_gtk: if use_gtk:
@ -53,13 +52,9 @@ def gfceu_error(message, code, use_gtk=True, fatal=True):
""" """
gfceu_error() gfceu_error()
TODO: This can be reworked to use the raise/except methods already defined Presents the user with an error message and optionally quits the program.
in the standard python language. One of these days...
""" """
print '# # # #' print title + ' error code '+str(code)+': ' + message
print title + ' ERROR code '+str(code)+':'
print message
print '# # # #'
if use_gtk: if use_gtk:
msgbox = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_ERROR, msgbox = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_ERROR,
buttons=gtk.BUTTONS_CLOSE) buttons=gtk.BUTTONS_CLOSE)
@ -85,15 +80,6 @@ except ImportError:
On Debian based systems (like Ubuntu), try this command:\n\ On Debian based systems (like Ubuntu), try this command:\n\
sudo apt-get install python-gtk2 libgtk2.0-0', 1, False) sudo apt-get install python-gtk2 libgtk2.0-0', 1, False)
try:
#import gtk.glade
pass
except ImportError:
gfceu_error('The glade libraries cannot be found.\n\
Ensure that libglade is installed on this system.\n\
On Debian based systems (like Ubuntu), try this command:\n\
sudo apt-get install libglade2-0 python-gtk2', 2, False)
try: try:
import gnomevfs import gnomevfs
have_gnomevfs = True have_gnomevfs = True
@ -123,6 +109,8 @@ class game_options:
extra_entry = '' extra_entry = ''
romfile = '' romfile = ''
opengl_check = False opengl_check = False
# network
join_radio = False join_radio = False
join_add = '' join_add = ''
join_port = 4046 join_port = 4046
@ -185,7 +173,7 @@ def give_widgets():
widgets.get_object("host_port").set_value(float(options.host_port)) widgets.get_object("host_port").set_value(float(options.host_port))
widgets.get_object("host_pass").set_text(options.host_pass) widgets.get_object("host_pass").set_text(options.host_pass)
except AttributeError: except:
# When new widgets are added, old pickle files might break. # When new widgets are added, old pickle files might break.
options = game_options() options = game_options()
give_widgets() give_widgets()
@ -199,8 +187,7 @@ def setup_environment ():
a separate directory. a separate directory.
""" """
global appconfigdir, old_optionsfile, optionsfile global appconfigdir, optionsfile
if not os.path.exists(appconfigdir): if not os.path.exists(appconfigdir):
# this is the first time the application is run. # this is the first time the application is run.
@ -208,12 +195,6 @@ def setup_environment ():
gfceu_print("Creating application settings directory") gfceu_print("Creating application settings directory")
os.mkdir(appconfigdir) os.mkdir(appconfigdir)
if os.path.exists(old_optionsfile):
# for full backwards compatibility, this file is processed, but moved
# to the new directory and filename for future compatibility
gfceu_print("Old version of options file found, converting to new version")
shutil.move(old_optionsfile,optionsfile)
def set_options(): def set_options():
""" """
set_options() set_options()
@ -286,6 +267,8 @@ def launch(rom_name, local=False):
video_options += ' ' video_options += ' '
# Netplay is fucked right now
"""
if options.join_radio: if options.join_radio:
if options.join_pass == '': if options.join_pass == '':
netpass = '' netpass = ''
@ -304,17 +287,17 @@ def launch(rom_name, local=False):
network = '--net localhost --port '+\ network = '--net localhost --port '+\
str(options.host_port) + netpass + ' ' str(options.host_port) + netpass + ' '
if local: if local:
network = '' network = ''
"""
network = ''
command = fceux_binary + ' ' + sound_options + video_options +\ command = fceux_binary + ' ' + sound_options + video_options +\
network + options.extra_entry + ' '+ rom_name network + options.extra_entry + ' '+ rom_name
gfceu_print('Command: ' + command) gfceu_print('Command: ' + command)
# more code to disable because netplay is fucked
"""
if options.host_radio: if options.host_radio:
xterm_binary = find_binary("xterm") xterm_binary = find_binary("xterm")
if xterm_binary == None: if xterm_binary == None:
@ -329,7 +312,7 @@ def launch(rom_name, local=False):
args.append("--password") args.append("--password")
args.append(options.host_pass) args.append(options.host_pass)
pid = Popen(args).pid pid = Popen(args).pid
"""
widgets.get_object("main_window").hide() widgets.get_object("main_window").hide()
# os.system() is a blocker, so we must force # os.system() is a blocker, so we must force
@ -338,9 +321,14 @@ def launch(rom_name, local=False):
gtk.main_iteration_do() gtk.main_iteration_do()
os.system(command) os.system(command)
widgets.get_object("main_window").show()
# another part of netplay code
"""
if options.host_radio: if options.host_radio:
os.kill(pid, 9) os.kill(pid, 9)
widgets.get_object("main_window").show() """
def find_binary(file): def find_binary(file):
@ -364,21 +352,14 @@ def find_binary(file):
return None return None
# # # # # # # #
# GTK Signal Handlers
class GladeHandlers:
pass
############################################################################## ##############################################################################
# Globals # Globals
options = None options = None
appconfigdir = os.getenv('HOME') + '/.'+ title appconfigdir = os.getenv('HOME') + '/.'+ title
old_optionsfile = os.getenv('HOME')+'/.' + title + '_options'
optionsfile = appconfigdir + 'gfceu_options.dat' optionsfile = appconfigdir + 'gfceu_options.dat'
fceux_binary = None fceux_binary = None
fceu_server_binary = None fceu_server_binary = None
#version is defined earlier in the code
#have_vfs is defined earlier in the code
class WidgetsWrapper: class WidgetsWrapper:
def __init__(self): def __init__(self):