Coverage for ui/EQStartWindowh.py: 60%
45 statements
« prev ^ index » next coverage.py v7.0.4, created at 2023-01-10 09:27 -0600
« prev ^ index » next coverage.py v7.0.4, created at 2023-01-10 09:27 -0600
1"""
2Copyright 1999 Illinois Institute of Technology
4Permission is hereby granted, free of charge, to any person obtaining
5a copy of this software and associated documentation files (the
6"Software"), to deal in the Software without restriction, including
7without limitation the rights to use, copy, modify, merge, publish,
8distribute, sublicense, and/or sell copies of the Software, and to
9permit persons to whom the Software is furnished to do so, subject to
10the following conditions:
12The above copyright notice and this permission notice shall be
13included in all copies or substantial portions of the Software.
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18IN NO EVENT SHALL ILLINOIS INSTITUTE OF TECHNOLOGY BE LIABLE FOR ANY
19CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23Except as contained in this notice, the name of Illinois Institute
24of Technology shall not be used in advertising or otherwise to promote
25the sale, use or other dealings in this Software without prior written
26authorization from Illinois Institute of Technology.
27"""
29import sys
30import os
31from os.path import split
32try:
33 from ..ui.EquatorWindowh import EquatorWindowh
34except: # for coverage
35 from ui.EquatorWindowh import EquatorWindowh
37class EQStartWindowh:
38 """
39 A class for start-up window or main window. Now, this is used for keep all EquatorWindow objects in a list
40 """
41 def __init__(self, filename, inputsettings, delcache, settingspath):
43 self.dir_path = filename
44 self.inputFlag=inputsettings
45 self.delcache=delcache
46 self.settingspath=settingspath
47 if os.path.isfile(self.dir_path):
48 self.browseFile() # start program by browse a file
49 elif os.path.isdir(self.dir_path):
50 self.browseFolder()
51 else:
52 print("Can't load image file or folder")
53 return
55 def browseFolder(self):
56 """
57 Popup an input folder dialog. Users can select a folder
58 """
59 input_types = ['.adsc', '.cbf', '.edf', '.fit2d', '.mar345', '.marccd', '.pilatus', '.tif', '.hdf5', '.smv']
61 if self.dir_path != "":
62 imgList = os.listdir(self.dir_path)
63 for image in imgList:
64 file_name=os.path.join(self.dir_path,image)
65 if os.path.isfile(file_name):
66 _, ext = os.path.splitext(str(file_name))
67 if ext in input_types:
68 print("filename is", file_name)
69 self.runBioMuscle(file_name)
71 def browseFile(self):
72 """
73 Popup an input file dialog. Users can select an image or .txt for failed cases list
74 """
75 file_name=self.dir_path
76 _, ext = os.path.splitext(str(file_name))
77 _, name = split(str(file_name))
78 if file_name != "":
79 if ext == ".txt" and not name == "failedcases.txt":
80 print("Please select only failedcases.txt or image files\n")
81 self.browseFile()
82 else:
83 # Run BioMuscle if the file is an image or failed cases list
84 self.runBioMuscle(str(file_name))
85 else:
86 sys.exit()
88 def runBioMuscle(self, filename):
89 """
90 Create a EquatorWindow object and launch the window
91 :param filename: input filename (str)
92 :return:
93 """
94 settingspath=self.settingspath
95 if settingspath is None:
96 EquatorWindowh(filename, self.inputFlag, self.delcache)
97 else:
98 EquatorWindowh(filename, self.inputFlag, self.delcache, settingspath)