pynemo_settings_editor.py 1.91 KB
Newer Older
James Harle's avatar
James Harle committed
1 2 3 4 5 6 7
'''
Created on 7 Jan 2015

@author: Mr. Srikanth Nagella
'''
# pylint: disable=E1103
# pylint: disable=no-name-in-module
James Harle's avatar
James Harle committed
8
from PyQt5 import QtGui
James Harle's avatar
James Harle committed
9

James Harle's avatar
James Harle committed
10 11
from .gui.nemo_bdy_input_window import InputWindow
from . import nemo_bdy_setup
James Harle's avatar
James Harle committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

import sys, getopt

def open_settings_window(fname):
    """ Main method which starts a Qt application and gives user
    an option to pick a namelist.bdy file to edit. Once user selects it
    it will open a dialog box where users can edit the parameters"""
    app = QtGui.QApplication(sys.argv)
    if fname is None:
        fname = QtGui.QFileDialog.getOpenFileName(None, 'Open file')

    setup = nemo_bdy_setup.Setup(fname)#'../../data/namelisttest.bdy')
    ex = InputWindow(setup)
    ex.nl_editor.btn_cancel.clicked.connect(lambda: sys.exit(0))
    return app.exec_(), ex.mpl_widget.mask

def open_settings_dialog(setup):
    """ This method is to start the settings window using the setup settings provided
    in the input. On clicking the cancel button it doesn't shutdown the applicaiton
    but carries on with the execution"""
    app = QtGui.QApplication(sys.argv)
    ex = InputWindow(setup)
    ex.nl_editor.btn_cancel.clicked.connect(app.quit)
    return app.exec_(), ex.mpl_widget.mask

def main():
    """ Command line execution method which check the input arguments and passes on to
    method to open the settings window"""
    setup_file = None
    try:
        opts, dummy_args = getopt.getopt(sys.argv[1:], "hs:", ["help", "setup="])
    except getopt.GetoptError:
James Harle's avatar
James Harle committed
44
        print("usage: pynemo_settings_editor -s <namelist.bdy> ")
James Harle's avatar
James Harle committed
45 46 47 48
        sys.exit(2)

    for opt, arg in opts:
        if opt == "-h":
James Harle's avatar
James Harle committed
49
            print("usage: pynemo_settings_editor -s <namelist.bdy> ")
James Harle's avatar
James Harle committed
50 51 52 53 54 55 56
            sys.exit()
        elif opt in ("-s", "--setup"):
            setup_file = arg
    sys.exit(open_settings_window(setup_file))

if __name__ == '__main__':
    main()