insted of:
PHP Code:
def errors(number):
if number == 1:
error_message("Missing Dependency","The program \"cdrdao\" was not found on your system. You can get it from:\nhttp:/cdrdao.sourceforge.net")
elif number == 2:
error_message("Error!","An error occurred!")
elif number == 3:
error_message("Error!","An error occurred!\n\n1-Did you choose the right CD drive?\n2-Are you sure the game's CD is in the specified drive?\n\nIf none of these solves your problem, contact the author.")
elif number == 4:
error_message("Error","The name can only contain letters and/or numbers")
elif number == 5:
error_message("Error","You must supply a game name.")
elif number == 6:
error_message("Error","The supplied directory does not exist.")
elif number == 7:
error_message("Error","You don't have \"write\" perrmissions to the specified directory.")
elif number == 8:
error_message("Error","You don't have \"execute\" perrmissions to the specified directory.")
elif number == 9:
error_message("Error","Files with the same name already exist.")
PHP Code:
error_messages = (
("Missing Dependency","The program \"cdrdao\" was not found on your system. You can get it from:\nhttp:/cdrdao.sourceforge.net"),
("Error!","An error occurred!"),
("Error!","An error occurred!\n\n1-Did you choose the right CD drive?\n2-Are you sure the game's CD is in the specified drive?\n\nIf none of these solves your problem, contact the author."),
("Error","The name can only contain letters and/or numbers"),
("Error","You must supply a game name."),
("Error","The supplied directory does not exist."),
("Error","You don't have \"write\" perrmissions to the specified directory."),
("Error","You don't have \"execute\" perrmissions to the specified directory."),
("Error","Files with the same name already exist."),
)
def errors(number):
title, text = error_messages[number]
error_message(title, text)
Rename error_message to show_error_message or something more appropriate.
Also:
PHP Code:
def message(title,text):
dialog=gtk.MessageDialog(
parent = window,
flags = gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL,
type = gtk.MESSAGE_INFO,
buttons = gtk.BUTTONS_CLOSE,
message_format = text)
dialog.set_title(title)
dialog.run()
dialog.destroy()
def error_message(title,text):
dialog=gtk.MessageDialog(
parent = window,
flags = gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL,
type = gtk.MESSAGE_ERROR,
buttons = gtk.BUTTONS_CLOSE,
message_format = text)
dialog.set_title(title)
dialog.run()
dialog.destroy()
Code duplication is considered bad. You could do something like this:
PHP Code:
severity_level_for_message_box = {
'INFO' : gtk.MESSAGE_INFO,
'ERROR' : gtk.MESSAGE_ERROR
}
def message_box(title, text, severity):
dialog=gtk.MessageDialog(
parent = window,
flags = gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL,
type = severity_level_for_message_box[severity],
buttons = gtk.BUTTONS_CLOSE,
message_format = text)
dialog.set_title(title)
dialog.run()
dialog.destroy()
def errors(number):
title, text = error_messages[number]
message_box(title, text, 'ERROR')
Bookmarks