Skip to content

Commit

Permalink
Solve Resizing Problem; Solve High DPI Problem; Switch to PyInstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuanhe211 committed Oct 12, 2022
1 parent 09a1024 commit 73ed5ec
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 64 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/UI/Eyring_Eq.psd
/.idea/
/build/
*.pyc
*.pyc
/Obsolete Cx_Freeze/
/dist/
51 changes: 51 additions & 0 deletions Erying_Eq.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
['Erying_Eq.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='Erying_Eq',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['UI\\Erying_Eq.ico'],
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='Erying_Eq',
)
2 changes: 2 additions & 0 deletions Eyring_Eq.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/Obsolete Cx_Freeze" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
116 changes: 54 additions & 62 deletions Eyring_Eq.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,25 @@

if not Qt.QApplication.instance():
Application = Qt.QApplication(sys.argv)


if platform.system() == 'Windows':
import ctypes
set_Windows_scaling_factor_env_var()

Windows_DPI_ratio, PyQt_scaling_ratio = set_Windows_scaling_factor_env_var()

del Application
Application = Qt.QApplication(sys.argv)

APPID = 'LYH.EyringEq.0.1'
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(APPID)

Application.setWindowIcon(Qt.QIcon('UI/Eyring_Eq.png'))
print('If there is a warning above starts with "libpng", ignore that.')


if __name__ == '__main__':
pyqt_ui_compile('Eyring_Eq.py')
from UI.Eyring_Eq import Ui_Eyring_Eq


def evaluate_expression(expression: str):
expression = expression.replace(' × 10^','E')
expression = expression.replace(' × 10^', 'E')
try:
ret = eval(expression)
if is_float(ret):
Expand All @@ -60,33 +56,33 @@ class myWidget(Ui_Eyring_Eq, Qt.QWidget, Qt_Widget_Common_Functions):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.setFixedWidth(460)
self.setFixedHeight(336)
self.setMinimumWidth(460)
self.setMinimumHeight(336)
connect_once(self.unimolecular_radioButton, self.unimolecular_selected)
connect_once(self.bimolecular_AA_radioButton, self.bimolecular_AA_selected)
connect_once(self.bimolecular_AB_radioButton, self.bimolecular_AB_selected)
connect_once(self.reset_all_pushButton, self.reset_all)
connect_once(self.calculate_pushButton, self.calc)

connect_once(self.conversion_lineEdit,self.check_fill_status)
connect_once(self.total_time_lineEdit,self.check_fill_status)
connect_once(self.temp_lineEdit,self.check_fill_status)
connect_once(self.G_neq_lineEdit,self.check_fill_status)
connect_once(self.kTST_lineEdit,self.check_fill_status)
connect_once(self.conc2_lineEdit,self.check_fill_status)
connect_once(self.conc1_lineEdit,self.check_fill_status)
connect_once(self.sigma_lineEdit,self.check_fill_status)
connect_once(self.unimolecular_radioButton,self.check_fill_status)
connect_once(self.bimolecular_AA_radioButton,self.check_fill_status)
connect_once(self.bimolecular_AB_radioButton,self.check_fill_status)
connect_once(self.total_time_lineEdit,self.smart_display_total_time)

connect_once(self.temp_lineEdit,self.clear_kTST)
connect_once(self.G_neq_lineEdit,self.clear_kTST)
connect_once(self.sigma_lineEdit,self.clear_kTST)
connect_once(self.unimolecular_radioButton,self.clear_kTST)
connect_once(self.bimolecular_AA_radioButton,self.clear_kTST)
connect_once(self.bimolecular_AB_radioButton,self.clear_kTST)
connect_once(self.conversion_lineEdit, self.check_fill_status)
connect_once(self.total_time_lineEdit, self.check_fill_status)
connect_once(self.temp_lineEdit, self.check_fill_status)
connect_once(self.G_neq_lineEdit, self.check_fill_status)
connect_once(self.kTST_lineEdit, self.check_fill_status)
connect_once(self.conc2_lineEdit, self.check_fill_status)
connect_once(self.conc1_lineEdit, self.check_fill_status)
connect_once(self.sigma_lineEdit, self.check_fill_status)
connect_once(self.unimolecular_radioButton, self.check_fill_status)
connect_once(self.bimolecular_AA_radioButton, self.check_fill_status)
connect_once(self.bimolecular_AB_radioButton, self.check_fill_status)
connect_once(self.total_time_lineEdit, self.smart_display_total_time)

connect_once(self.temp_lineEdit, self.clear_kTST)
connect_once(self.G_neq_lineEdit, self.clear_kTST)
connect_once(self.sigma_lineEdit, self.clear_kTST)
connect_once(self.unimolecular_radioButton, self.clear_kTST)
connect_once(self.bimolecular_AA_radioButton, self.clear_kTST)
connect_once(self.bimolecular_AB_radioButton, self.clear_kTST)

self.clear_conc1_pushButton.hide()
self.clear_conc2_pushButton.hide()
Expand All @@ -97,12 +93,12 @@ def __init__(self):
self.clear_conv_pushButton.hide()
self.clear_sigma_pushButton.hide()

self.kTST_is_calculated_marker = "⠀" # an unicode blank to tell the program that the kTST is calculated, instead of user input.
self.kTST_is_calculated_marker = "⠀" # an unicode blank to tell the program that the kTST is calculated, instead of user input.
self.unimolecular_selected()
self.check_fill_status()
self.show()
self.center_the_widget()

self.resize(self.minimumSizeHint())

# def clear_G(self):
# self.G_neq_lineEdit.setText("")
Expand Down Expand Up @@ -148,42 +144,41 @@ def clear_kTST(self):
self.kTST_lineEdit.setText("")

def smart_display_total_time(self):
if self.data["t"] and self.data["t"]>60:
self.total_time_display_label.setText("= "+smart_print_time(self.data["t"]))
if self.data["t"] and self.data["t"] > 60:
self.total_time_display_label.setText("= " + smart_print_time(self.data["t"]))
else:
self.total_time_display_label.setText("")

def set_kTST_line_edit(self,kTST):
def set_kTST_line_edit(self, kTST):
if self.unimolecular_radioButton.isChecked():
self.kTST_lineEdit.setText(self.kTST_is_calculated_marker + smart_format_float(kTST))
else:
self.kTST_lineEdit.setText(self.kTST_is_calculated_marker + smart_format_float(kTST*1000))

self.kTST_lineEdit.setText(self.kTST_is_calculated_marker + smart_format_float(kTST * 1000))

def check_fill_status(self):
self.data = {}
self.data["G"] = evaluate_expression(self.G_neq_lineEdit.text())
if self.data['G'] is not None:
self.data['G']*=1000 # kJ-> J
self.data['G'] *= 1000 # kJ-> J
self.data["T"] = evaluate_expression(self.temp_lineEdit.text())
if self.data['T'] is not None:
self.data['T']+=273
self.data['T'] += 273
self.data["c1"] = evaluate_expression(self.conc1_lineEdit.text())
if self.data['c1'] is not None:
self.data['c1']*=1000 #mol/L -> mol/m^3
self.data['c1'] *= 1000 # mol/L -> mol/m^3
self.data["c2"] = evaluate_expression(self.conc2_lineEdit.text())
if self.data['c2'] is not None:
self.data['c2']*=1000 #mol/L -> mol/m^3
self.data['c2'] *= 1000 # mol/L -> mol/m^3
self.data["t"] = evaluate_expression(self.total_time_lineEdit.text())
self.data["conv"] = evaluate_expression(self.conversion_lineEdit.text())
if self.data['conv'] is not None:
self.data['conv']/=100 # percent to number
self.data['conv'] /= 100 # percent to number
if self.kTST_lineEdit.text().startswith(self.kTST_is_calculated_marker):
self.data['kTST'] = None
else:
self.data['kTST'] = evaluate_expression(self.kTST_lineEdit.text())
if not self.unimolecular_radioButton.isChecked() and self.data['kTST']:
self.data['kTST']/=1000 # L/mol·s --> m3/mol·s
self.data['kTST'] /= 1000 # L/mol·s --> m3/mol·s
self.data["σ"] = evaluate_expression(self.sigma_lineEdit.text())
self.is_None = set([key for key, value in self.data.items() if value is None])
if self.unimolecular_radioButton.isChecked():
Expand All @@ -197,18 +192,17 @@ def check_fill_status(self):
self.is_None.remove("c2")
except KeyError:
pass
allowed_missing_situations = [["G",'kTST'],
["T",'kTST'],
["t",'kTST'],
["conv",'kTST'],
["G",'t'],
["G",'conv'],
["T",'t'],
["T",'conv']]
allowed_missing_situations = [["G", 'kTST'],
["T", 'kTST'],
["t", 'kTST'],
["conv", 'kTST'],
["G", 't'],
["G", 'conv'],
["T", 't'],
["T", 'conv']]
allowed = any([set(x) == self.is_None for x in allowed_missing_situations])
self.calculate_pushButton.setEnabled(allowed)


def calc(self):
if self.unimolecular_radioButton.isChecked():
Δn = 0
Expand Down Expand Up @@ -239,24 +233,24 @@ def conv_from_kinetics(kTST, time, conc1, conc2=None):
Δn = 1

def k_from_kinetics(conv, time, conc1, conc2):
if conc1==conc2:
if conc1 == conc2:
return second_order_k_TST_A_plus_A(conv, time, conc1)
else:
return second_order_k_TST_A_plus_B(conv, time, conc1, conc2)

def t_from_kinetics(kTST, conv, conc1, conc2):
if conc1==conc2:
if conc1 == conc2:
return second_order_reaction_time_A_plus_A(kTST, conv, conc1)
else:
return second_order_reaction_time_A_plus_B(kTST, conv, conc1, conc2)

def conv_from_kinetics(kTST, time, conc1, conc2):
if conc1==conc2:
if conc1 == conc2:
return second_order_conv_A_plus_A(kTST, time, conc1)
else:
return second_order_conv_A_plus_B(kTST, time, conc1, conc2)

#print(Δn)
# print(Δn)

G, T, c1, c2, t, conv, σ, kTST = [self.data[key] for key in ["G", "T", "c1", "c2", "t", "conv", "σ", 'kTST']]

Expand All @@ -266,14 +260,14 @@ def conv_from_kinetics(kTST, time, conc1, conc2):
self.set_kTST_line_edit(kTST)

if kTST:
if "G" in self.is_None: #知道G不知道T
if "G" in self.is_None: # 知道G不知道T
G = solve_for_ΔG(kTST, Δn, σ, T)
self.G_neq_lineEdit.setText(smart_format_float(G/1000,precision=4))
elif "T" in self.is_None: # 知道T不知道G
self.G_neq_lineEdit.setText(smart_format_float(G / 1000, precision=4))
elif "T" in self.is_None: # 知道T不知道G
T = solve_for_T(kTST, Δn, σ, G)
self.temp_lineEdit.setText(smart_format_float(T-273.15,precision=2,scientific_notation_limit=6))
self.temp_lineEdit.setText(smart_format_float(T - 273.15, precision=2, scientific_notation_limit=6))

#不知道动力学,从kTST算时间、转化率
# 不知道动力学,从kTST算时间、转化率
if "G" not in self.is_None and "T" not in self.is_None:
print(f"Calculating rate constant from TST.\n Δn: {Δn}, σ: {σ}, T: {T} K, ΔG: {G} J/mol.")
kTST = get_k_TST(Δn, σ, T, G)
Expand All @@ -283,18 +277,16 @@ def conv_from_kinetics(kTST, time, conc1, conc2):
self.total_time_lineEdit.setText(smart_format_float(t))
elif 'conv' in self.is_None:
conv = conv_from_kinetics(kTST, t, c1, c2)
self.conversion_lineEdit.setText(smart_format_float(conv*100))
self.conversion_lineEdit.setText(smart_format_float(conv * 100))

print("---------------------------------\n\n")



if __name__ == '__main__':
my_Qt_Program = myWidget()
my_Qt_Program.show()
sys.exit(Application.exec_())


"""
Verification cases:
Expand Down
51 changes: 51 additions & 0 deletions Eyring_Eq.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
['Eyring_Eq.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='Eyring_Eq',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['UI\\Eyring_Eq.ico'],
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='Eyring_Eq',
)
Loading

0 comments on commit 73ed5ec

Please sign in to comment.