Skip to content

Commit

Permalink
Adding parent to QTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
dkratzert committed Sep 20, 2023
1 parent d06a7c6 commit 1ee1c70
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions finalcif/appwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def resizeEvent(self, a0: QtGui.QResizeEvent) -> None:
if left_frame <= 300:
left_frame = 300
self.ui.LeftFrame.setMinimumWidth(int(left_frame))
QtCore.QTimer.singleShot(0, self.ui.cif_main_table.resizeRowsToContents)
QtCore.QTimer(self).singleShot(0, self.ui.cif_main_table.resizeRowsToContents)

def moveEvent(self, a0: QtGui.QMoveEvent) -> None:
"""Is called when the main window moves."""
Expand Down Expand Up @@ -1455,7 +1455,7 @@ def load_cif_file(self, filepath: Path, block=0, load_changes: bool = True) -> N
self.ui.datanameComboBox.blockSignals(False)
if self.cif.is_multi_cif:
# short after start, because window size is not finished
QTimer.singleShot(1000, self.ui.datanameComboBox.showPopup)
QtCore.QTimer(self).singleShot(1000, self.ui.datanameComboBox.showPopup)

def add_data_names_to_combobox(self) -> None:
self.ui.datanameComboBox.clear()
Expand Down Expand Up @@ -1688,7 +1688,7 @@ def show_residuals(self) -> None:
if self.cif.res_file_data:
self.ui.shelx_TextEdit.setPlainText(cif.as_string(self.cif.res_file_data))
try:
QTimer.singleShot(0, self.view_molecule)
QtCore.QTimer(self).singleShot(0, self.view_molecule)
except Exception:
print('Molecule view crashed!')

Expand Down Expand Up @@ -1836,7 +1836,7 @@ def fill_cif_table(self) -> None:
txt = 'FinalCif V{} by Daniel Kratzert, Freiburg {}, https://dkratzert.de/finalcif.html'
strval = txt.format(VERSION, datetime.now().year)
self.ui.cif_main_table.setText(key=key, column=Column.DATA, txt=strval)
QTimer.singleShot(200, self.ui.cif_main_table.resizeRowsToContents)
QtCore.QTimer(self).singleShot(200, self.ui.cif_main_table.resizeRowsToContents)
# print(key, value)
if not self.cif.test_res_checksum():
show_res_checksum_warning()
Expand Down
2 changes: 1 addition & 1 deletion finalcif/equip_property/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def check_for_duplicates(self):
self.lb.setText(f'key {key} already exists')
self.lb.move(self.app.ui.cifKeywordLineEdit.mapToGlobal(QtCore.QPoint(15, 25)))
self.lb.show()
QtCore.QTimer.singleShot(4000, self.lb.hide)
QtCore.QTimer(self).singleShot(4000, self.lb.hide)
else:
self.app.ui.SavePropertiesButton.setEnabled(True)
self.lb.hide()
Expand Down
7 changes: 3 additions & 4 deletions finalcif/tools/platon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path

from PyQt5 import QtCore
from PyQt5.QtCore import QProcess, QTimer, QTime
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QLabel, \
QPlainTextEdit

Expand All @@ -34,7 +33,7 @@ def run_process(self):
#os.chdir(self.cif_file.parent)
self.formula_moiety = ''
self.Z = ''
self.process = QProcess()
self.process = QtCore.QProcess()
self.output_widget.clear()
threading.Thread(target=self._monitor_output_log).start()
# self.process.readyReadStandardOutput.connect(self.on_ready_read)
Expand Down Expand Up @@ -139,12 +138,12 @@ def __init__(self):
self.runner.finished.connect(lambda x: self.button.setEnabled(True))

# Only to show that the main thread works continuously:
self.timer = QTimer(self)
self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.update_time)
self.timer.start(1000)

def update_time(self):
current_time = QTime.currentTime()
current_time = QtCore.QTime.currentTime()
time_text = current_time.toString("hh:mm:ss")
self.time_label.setText(f"Current Time: {time_text}")

Expand Down

0 comments on commit 1ee1c70

Please sign in to comment.