From 0a3b384d0b21b8ad700e0b10617a25edf440c6ce Mon Sep 17 00:00:00 2001 From: Kamil Sopko Date: Thu, 1 Jan 2015 23:52:11 +0100 Subject: [PATCH] add cmd line -h for help and --sellfile= to read shell directly --- FlatCAMApp.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 37037efc..4d7aff17 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -1,6 +1,7 @@ import traceback import sys import urllib +import getopt from copy import copy import random import logging @@ -34,6 +35,22 @@ class App(QtCore.QObject): The main application class. The constructor starts the GUI. """ + ## Get Cmd Line Options + + cmd_line_shellfile='' + cmd_line_help="FlatCam.py --shellfile=" + try: + cmd_line_options, args = getopt.getopt(sys.argv[1:],"h:","shellfile=") + except getopt.GetoptError: + print cmd_line_help + sys.exit(2) + for opt, arg in cmd_line_options: + if opt == '-h': + print cmd_line_help + sys.exit() + elif opt == '--shellfile': + cmd_line_shellfile = arg + ## Logging ## log = logging.getLogger('base') log.setLevel(logging.DEBUG) @@ -428,6 +445,8 @@ class App(QtCore.QObject): ### Shell ### ############# # TODO: Move this to its own class + + self.shell = FCShell(self) self.shell.setWindowIcon(self.ui.app_icon) self.shell.setWindowTitle("FlatCAM Shell") @@ -439,6 +458,15 @@ class App(QtCore.QObject): self.tcl = Tkinter.Tcl() self.setup_shell() + if self.cmd_line_shellfile: + try: + with open (self.cmd_line_shellfile, "r") as myfile: + cmd_line_shellfile_text=myfile.read() + self.shell._sysShell.exec_command(cmd_line_shellfile_text) + except Exception as ext: + print "ERROR: ",ext + sys.exit(2) + App.log.debug("END of constructor. Releasing control.") def defaults_read_form(self):