-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
executable file
·47 lines (43 loc) · 1.08 KB
/
common.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
#! /usr/bin/python3
import json
import re
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Common:
@staticmethod
def regexvalidation(entery,value):
regExps = Common.loadjson("configurations/regex.json")
return True if re.match(regExps[entery],value) else False
@staticmethod
def is_number(s):
try:
data = float(s)
return True
except:
return False
@staticmethod
def validate(entery,value, message):
if Common.regexvalidation(entery, value):
return True
else:
show_message(QtWidgets.QMessageBox.Critical, message,"XAFS/XRF scan tool", QtWidgets.QMessageBox.Ok)
return False
@staticmethod
def show_message(Icon,Text,WindowTitle,StandardButtons):
msg = QtWidgets.QMessageBox()
msg.setIcon(Icon)
msg.setText(Text)
msg.setWindowTitle(WindowTitle)
msg.setStandardButtons(StandardButtons)
msg.exec_()
return msg
@staticmethod
def loadjson(path):
try:
with open(path, "r") as jsonfile:
jsondata = json.load(jsonfile)
jsonfile.close()
return jsondata
except Exception as e:
print("{} load error".format(path))
print(e)