Skip to content

Commit 5acce5c

Browse files
authored
Merge pull request #43 from DiamondLightSource/I04_1-168_launch_with_config_file_arg
I04_1-168: program can be launched with config file as argument
2 parents 6c3a84e + f0ac608 commit 5acce5c

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test-output
55
demo-resources
66
*.pyc
77
config.ini
8+
launch_barcode.bat
89

910
build
1011
dist

build.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ pyinstaller --onefile --windowed main.py
88
move dist\main.exe ..\bin\barcode.exe
99
rd /S /Q build
1010
rd /S /Q dist
11-
del main.spec
11+
del main.spec
12+
13+
@echo start barcode.exe --config_file .\config.ini>"..\bin\launch_barcode.bat"

dls_barcode/main.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99

1010
from PyQt4 import QtGui
1111
from gui import DiamondBarcodeMainWindow
12+
import argparse
1213

1314
# Detect if the program is running from source or has been bundled
1415
IS_BUNDLED = getattr(sys, 'frozen', False)
1516
if IS_BUNDLED:
16-
CONFIG_FILE = "./config.ini"
17+
DEFAULT_CONFIG_FILE = "./config.ini"
1718
else:
18-
CONFIG_FILE = "../config.ini"
19+
DEFAULT_CONFIG_FILE = "../config.ini"
1920

2021

21-
def main():
22+
def main(config_file):
2223
app = QtGui.QApplication(sys.argv)
23-
ex = DiamondBarcodeMainWindow(CONFIG_FILE)
24+
ex = DiamondBarcodeMainWindow(config_file)
2425
sys.exit(app.exec_())
2526

2627

@@ -30,4 +31,10 @@ def main():
3031
import multiprocessing
3132
multiprocessing.freeze_support()
3233

33-
main()
34+
parser = argparse.ArgumentParser()
35+
parser.add_argument("-cf", "--config_file", type=str, default=DEFAULT_CONFIG_FILE,
36+
help="The path of the configuration file (default=" + DEFAULT_CONFIG_FILE + ")")
37+
args = parser.parse_args()
38+
print("CONFIG: " + args.config_file)
39+
40+
main(args.config_file)

0 commit comments

Comments
 (0)