~ubuntu-branches/ubuntu/precise/gnome-games/precise-proposed

« back to all changes in this revision

Viewing changes to glchess/src/glchess.in.in

  • Committer: Package Import Robot
  • Author(s): Rodrigo Moya
  • Date: 2011-05-30 13:32:04 UTC
  • mfrom: (1.3.4)
  • mto: (163.1.3 precise)
  • mto: This revision was merged to the branch mainline in revision 143.
  • Revision ID: package-import@ubuntu.com-20110530133204-celaq1v1dsxc48q1
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
# -*- coding: utf-8 -*-
3
 
 
4
 
# glChess is a 2D/3D chess game for GNOME. This is the startup
5
 
# script which imports the relevant modules. Please keep the startup
6
 
# script in sync between glChess and gnome-sudoku.
7
 
#
8
 
# Copyright (c) 2008  You may use and distribute this
9
 
# software under the terms of the GNU General Public License, 
10
 
# version 2 or later.
11
 
 
12
 
import sys
13
 
import os
14
 
 
15
 
# Some version of PyGTK require this to be called before importing the gtk module
16
 
import pygtk
17
 
pygtk.require('2.0')
18
 
 
19
 
# Ignore any exceptions writing to stdout using print statements
20
 
class SafeStdout:
21
 
    def __init__(self):
22
 
        self.stdout = sys.stdout
23
 
    
24
 
    def fileno(self):
25
 
        return self.stdout.fileno()
26
 
 
27
 
    def write(self, data):
28
 
        try:
29
 
            self.stdout.write(data)
30
 
        except:
31
 
            pass
32
 
sys.stdout = SafeStdout()
33
 
 
34
 
# Setup bugbuddy to report unhandled exceptions.
35
 
try: 
36
 
    import bugbuddy
37
 
    bugbuddy.install('glchess')
38
 
except:
39
 
    #No bugbuddy support
40
 
    pass
41
 
 
42
 
def report_error():
43
 
    import os.path
44
 
    import gettext
45
 
    import traceback
46
 
    from gettext import gettext as _
47
 
 
48
 
    gettext.bindtextdomain('gnome-games', os.path.join('@prefix@', 'share', 'locale'))
49
 
    gettext.textdomain('gnome-games')
50
 
    # Translators: This is the title of the dialog displayed if glChess cannot start
51
 
    title = _("Chess incorrectly installed")
52
 
    # Translators: This is the contents of the dialog displayed if glChess cannot start
53
 
    description = _("""Chess 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.""")
54
 
 
55
 
    traceback.print_exc()
56
 
    try:
57
 
        import gtk
58
 
    except ImportError:
59
 
        print title
60
 
        print '-' * len(title)
61
 
        print description
62
 
    else:
63
 
        dialog = gtk.MessageDialog(type = gtk.MESSAGE_ERROR, message_format = title)
64
 
        dialog.format_secondary_text(description)
65
 
        dialog.add_button(gtk.STOCK_QUIT, gtk.RESPONSE_CLOSE)
66
 
        dialog.run()
67
 
    sys.exit(0)
68
 
 
69
 
# Chek if we are installed
70
 
root_dir = os.path.dirname(__file__)
71
 
if os.path.exists(os.path.join(root_dir, 'Makefile.am')):
72
 
    sys.path.insert(0, os.path.abspath(root_dir))
73
 
    import lib
74
 
    sys.modules['glchess'] = sys.modules['lib']
75
 
 
76
 
try:
77
 
    # Import glChess from pyexecdir or system installation.
78
 
    from glchess.glchess import start_game
79
 
    start_game()
80
 
except ImportError:
81
 
    # Import of glChess failed. Show error message.
82
 
    report_error()
83