#!/usr/local/bin/python2.7

# GNOME Sudoku is a simple sudoku generator and player. Sudoku is a 
# japanese logic puzzle. This is the startup script which imports 
# the relevant modules. Please keep the startup script in sync 
# between glChess and gnome-sudoku.
#
# Copyright (c) 2005 Tom Hinkle You may use and distribute this
# software under the terms of the GNU General Public License, version
# 2 or later.

# Ignore any exceptions writing to stdout using print statements
class SafeStdout:
    def __init__(self):
        self.stdout = sys.stdout
    
    def fileno(self):
        return self.stdout.fileno()

    def write(self, data):
        try:
            self.stdout.write(data)
        except:
            pass
import sys
sys.stdout = SafeStdout()

# Setup bugbuddy to report unhandled exceptions.
try: 
  import bugbuddy
  bugbuddy.install('gnome-sudoku')
except:
  #No bugbuddy support
  pass 

import sys

try:
    # Import gnome-sudoku module from source distribution.
    import lib;
    sys.modules["gnome_sudoku"] = sys.modules["lib"];
    from gnome_sudoku.gnome_sudoku import start_game

except ImportError:
    try:
      # Import gnome-sudoku from pyexecdir or system installation.
      from gnome_sudoku.gnome_sudoku import start_game

    except ImportError:
      # Import of gnome-sudoku failed. Show error message.
      import gtk
      import os.path
      import gettext
      from gettext import gettext as _
        
      gettext.bindtextdomain('gnome-games', os.path.join('/usr/local', 'share', 'locale'))
      gettext.textdomain('gnome-games')
      title = _("Sudoku incorrectly installed")
      description = _("""Sudoku is not able to start because required application files are not installed. If you are currently upgrading your system please wait until the upgrade has completed.""")
      dialog = gtk.MessageDialog(type = gtk.MESSAGE_ERROR, message_format = title)
      dialog.format_secondary_text(description)
      dialog.add_button(gtk.STOCK_QUIT, gtk.RESPONSE_CLOSE)
      dialog.run()
      sys.exit(0)

start_game()
