~mapclient.devs/mapclient/stable

« back to all changes in this revision

Viewing changes to src/mapclient.py

  • Committer: musculoskeletal
  • Date: 2014-06-25 05:38:05 UTC
  • mfrom: (1.6.35 testing)
  • Revision ID: musculoskeletal@bioeng1033-20140625053805-jkqhi5oq74vmlntl
Merging testing into stable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
'''
3
 
MAP Client, a program to generate detailed musculoskeletal models for OpenSim.
4
 
    Copyright (C) 2012  University of Auckland
5
 
    
6
 
This file is part of MAP Client. (http://launchpad.net/mapclient)
7
 
 
8
 
    MAP Client is free software: you can redistribute it and/or modify
9
 
    it under the terms of the GNU General Public License as published by
10
 
    the Free Software Foundation, either version 3 of the License, or
11
 
    (at your option) any later version.
12
 
 
13
 
    MAP Client is distributed in the hope that it will be useful,
14
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
    GNU General Public License for more details.
17
 
 
18
 
    You should have received a copy of the GNU General Public License
19
 
    along with MAP Client.  If not, see <http://www.gnu.org/licenses/>..
20
 
'''
21
 
import os, sys, locale
22
 
 
23
 
# With PEP366 we need to conditionally import the settings module based on
24
 
# whether we are executing the file directly of indirectly.  This is my
25
 
# workaround.
26
 
if __package__:
27
 
    from .settings import info
28
 
else:
29
 
    from settings import info
30
 
 
31
 
# Ensure the MAP Client module directory is in the system path so relative 'import' statements work
32
 
base_path = os.path.dirname(os.path.abspath(__file__))
33
 
if sys.path.count(base_path) == 0:
34
 
    sys.path.insert(0, base_path)
35
 
 
36
 
 
37
 
def progheader():
38
 
    '''
39
 
    Display program header
40
 
    '''
41
 
    programHeader = '   MAP Client (version %s)   ' % info.ABOUT['version']
42
 
    print('-' * len(programHeader))
43
 
    print(programHeader)
44
 
    print('-' * len(programHeader))
45
 
 
46
 
# This method starts MAP Client
47
 
def winmain():
48
 
    '''
49
 
    Initialise common settings and check the operating environment before starting the application.
50
 
    '''
51
 
 
52
 
    progheader()
53
 
    # import the locale, and set the locale. This is used for
54
 
    # locale-aware number to string formatting
55
 
    locale.setlocale(locale.LC_ALL, '')
56
 
 
57
 
    from PySide import QtGui
58
 
    app = QtGui.QApplication(sys.argv)
59
 
 
60
 
    # Set the default organisation name and application name used to store application settings
61
 
    app.setOrganizationDomain(info.ORGANISATION_DOMAIN)
62
 
    app.setOrganizationName(info.ORGANISATION_NAME)
63
 
    app.setApplicationName(info.APPLICATION_NAME)
64
 
    app.setApplicationVersion(info.ABOUT['version'])
65
 
 
66
 
    from core.mainapplication import MainApplication
67
 
    model = MainApplication()
68
 
 
69
 
    from widgets.mainwindow import MainWindow
70
 
    window = MainWindow(model)
71
 
    window.show()
72
 
 
73
 
    return app.exec_()
74
 
 
75
 
class ConsumeOutput(object):
76
 
    def __init__(self):
77
 
        self.messages = list()
78
 
 
79
 
    def write(self, message):
80
 
        self.messages.append(message)
81
 
 
82
 
def main():
83
 
    locale.setlocale(locale.LC_ALL, '')
84
 
 
85
 
    from optparse import OptionParser
86
 
    from PySide import QtCore
87
 
    app = QtCore.QCoreApplication(sys.argv)
88
 
 
89
 
    # Set the default organisation name and application name used to store application settings
90
 
    QtCore.QCoreApplication.setOrganizationName(info.ORGANISATION_NAME)
91
 
    QtCore.QCoreApplication.setOrganizationDomain(info.ORGANISATION_DOMAIN)
92
 
    QtCore.QCoreApplication.setApplicationName(info.APPLICATION_NAME)
93
 
 
94
 
    old_stdout = sys.stdout
95
 
    sys.stdout = redirectstdout = ConsumeOutput()
96
 
    progheader()
97
 
    sys.stdout = old_stdout
98
 
    versionstring = ''.join(redirectstdout.messages)
99
 
 
100
 
    progname = os.path.splitext(__file__)[0]
101
 
    usage = 'usage: {0} [options] workflow\n    Execute the given workflow'.format(progname)
102
 
    parser = OptionParser(usage, version=versionstring)
103
 
    options, args = parser.parse_args()
104
 
 
105
 
    print(sys.argv)
106
 
    print(options, args)
107
 
 
108
 
    # Possibly don't need to run app.exec_()
109
 
    sys.exit(app.quit())
110
 
 
111
 
 
112
 
if __name__ == '__main__':
113
 
    if len(sys.argv) == 1:  # No command line arguments
114
 
        sys.exit(winmain())
115
 
    else:
116
 
        main()