~ubuntu-branches/ubuntu/saucy/solfege/saucy

« back to all changes in this revision

Viewing changes to src/runtime.py

  • Committer: Bazaar Package Importer
  • Author(s): Tom Cato Amundsen
  • Date: 2010-03-28 06:34:28 UTC
  • mfrom: (1.1.10 upstream) (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100328063428-wg2bqvoce2aq4xfb
Tags: 3.15.9-1
* New upstream release.
* Redo packaging. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# GNU Solfege - free ear training software
2
 
# Copyright (C) 2005, 2007, 2008  Tom Cato Amundsen
3
 
#
4
 
# This program is free software: you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation, either version 3 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 
17
 
"""
18
 
This file does the checking for optional features that depend on
19
 
python modules the user can have installed.
20
 
 
21
 
It also does sanity check on the python and pygtk versions and some
22
 
other initial setup tasks.
23
 
"""
24
 
 
25
 
import sys
26
 
import os
27
 
 
28
 
_use_gtkhtml2 = False
29
 
use_cairo_widgets = None
30
 
 
31
 
def assert_python_version(required_version):
32
 
    if sys.version_info < required_version:
33
 
        print "*"* 67
34
 
        print "Solfege need Python %s or newer. The configure script told you so!" % (".".join([str(i) for i in required_version]))
35
 
        print "*"* 67
36
 
        sys.exit(-1)
37
 
 
38
 
def setup_pygtk(required_version):
39
 
    import pygtk
40
 
    # this is needed for py2exe
41
 
    if sys.platform == 'win32':
42
 
        os.environ['PATH'] += ";lib;bin;"
43
 
    else:
44
 
        pygtk.require("2.0")
45
 
    import gtk
46
 
    gtk.rc_parse("solfege.gtkrc")
47
 
    # The rest of this function is just for sanity check. Not really required.
48
 
    if gtk.pygtk_version < required_version:
49
 
        print "-"*55
50
 
        print " GNU Solfege requires pygtk version %s or newer." % (".".join([str(i) for i in required_version]))
51
 
        print " The version installed appears to be %s" % (".".join([str(i) for i in gtk.pygtk_version]))
52
 
        print " Exiting program."
53
 
        print "-"*55+"\n"
54
 
        sys.exit(-1)
55
 
 
56
 
 
57
 
def init(options):
58
 
    global _use_gtkhtml2
59
 
    global use_cairo_widgets
60
 
    assert_python_version((2, 4))
61
 
    setup_pygtk((2, 12))
62
 
    if options.enable_gtkhtml:
63
 
        _use_gtkhtml2 = True
64
 
    if options.no_cairo_widgets:
65
 
        use_cairo_widgets = False
66
 
    else:
67
 
        import gtk
68
 
        if gtk.pygtk_version < (2, 8, 0):
69
 
            use_cairo_widgets = False
70
 
        else:
71
 
            use_cairo_widgets = True
72
 
 
73
 
 
74
 
 
75
 
def use_gtkhtml2():
76
 
    global _use_gtkhtml2
77
 
    if _use_gtkhtml2:
78
 
        import gtkhtml2
79
 
        return True
80
 
    else:
81
 
        return False
82