Coverage for ui/pyqt_utils.py: 50%
40 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"""
29from PyQt5 import QtGui
30from PyQt5.QtCore import *
31from PyQt5.QtWidgets import *
32from PyQt5.QtGui import *
33import matplotlib
34matplotlib.use('Qt5Agg')
35from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
36try:
37 from ..utils.file_manager import input_types
38except: # for coverage
39 from utils.file_manager import input_types
41print("Qt version:", QT_VERSION_STR)
43img_filter = 'Pattern ('
44for t in input_types:
45 img_filter += ' *.' + str(t)
46img_filter += ')'
48def getAFile(filtr=None, path='', add_txt=False):
49 """
50 Open a file finder and return the name of the file selected
51 """
52 if filtr is None:
53 filtr = img_filter
54 if add_txt and filtr != '':
55 filtr += ';;Failed cases (*.txt)'
56 file_name = QFileDialog.getOpenFileName(None, 'Select a file', path, filtr, None)
57 if isinstance(file_name, tuple):
58 file_name = file_name[0]
59 return str(file_name)
61def getFiles(path='', filtr=None):
62 """
63 Give the list of the files in a folder
64 """
65 if filtr is None:
66 filtr = img_filter
67 fileList = QFileDialog.getOpenFileNames(None, "Select frame(s) to average", path, filtr)
68 if isinstance(fileList, tuple):
69 fileList = fileList[0]
70 return list(map(str, fileList))
72def getAFolder():
73 """
74 Open a folder finder and return the name of the folder selected
75 """
76 dir_path = QFileDialog.getExistingDirectory(None, "Select a Folder")
77 return str(dir_path)
79def getSaveFile(path='', filtr='Images (*.png);;SVG (*.svg)'):
80 """
81 Open a file finder and let the user save the file where he wants
82 and return the file path
83 """
84 file_name = QFileDialog.getSaveFileName(None, "Save a file", path, filtr)
85 if isinstance(file_name, tuple):
86 file_name = file_name[0]
87 return str(file_name)