This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
lfp-viewer.py
executable file
·114 lines (95 loc) · 3.06 KB
/
lfp-viewer.py
1
2
3
4
5
6
7
8
9
10
11
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python
#
# lfp-reader
# LFP (Light Field Photography) File Reader.
#
# http://code.behnam.es/python-lfp-reader/
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2012-2013 Behnam Esfahbod
"""View LFP Picture files with refocus and edof/parallax support
"""
from __future__ import print_function
import os.path
import sys
import argparse
from lfp_reader.tk_lfp_viewer import TkLfpViewer
from lfp_reader import lfp_logging
lfp_logging.set_log_stream(sys.stdout)
DEBUG = False
QUIET = False
def view(file_dir_paths, **null):
"""Create a viewer window and show files
"""
lfp_paths = []
for x in file_dir_paths:
if os.path.isdir(x):
lfp_paths.extend(os.path.join(x, y) for y in os.listdir(x)
if os.path.isfile(os.path.join(x, y))
and os.path.join(x, y).lower().endswith('-stk.lfp'))
else:
lfp_paths.append(x)
viewer = TkLfpViewer(lfp_paths)
viewer.mainloop()
def main(argv=sys.argv[1:]):
"""Parse command-line arguments and call commands
"""
global DEBUG, QUIET
debug_kwargs = dict(
action='store_true',
help="Print debugging information on error",
)
quiet_kwargs = dict(
action='store_true',
help="Do not write anything to standard output",
)
lfp_file_kwargs = dict(
metavar='picture-stk.lfp',
help='LFP Picture (stk) file path',
)
# Main command
p_main = argparse.ArgumentParser(description=__doc__)
p_main.set_defaults(subcmd=view)
p_main.add_argument('-d', '--debug', **debug_kwargs)
p_main.add_argument('-q', '--quiet', **quiet_kwargs)
p_main.add_argument('file_dir_paths', nargs='+', **lfp_file_kwargs)
# Parse arguments
try:
args = p_main.parse_args(argv)
except SystemExit:
print()
if 'info' in argv:
p_info.print_help()
elif 'export' in argv:
p_export.print_help()
else:
p_main.print_help()
sys.exit(2)
# Run subcommand
DEBUG = args.debug
QUIET = args.quiet
args.subcmd(**dict(args._get_kwargs()))
if __name__=='__main__':
try:
main()
except KeyboardInterrupt:
sys.exit(3)
except Exception as err:
if DEBUG:
raise
else:
if not QUIET:
print("%s: error: %s" % (os.path.basename(sys.argv[0]), err), file=sys.stderr)
sys.exit(9)