Skip to content

Commit

Permalink
Add parents to all widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
dkratzert committed Sep 22, 2023
1 parent ba71bcf commit 302e485
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 125 deletions.
50 changes: 25 additions & 25 deletions finalcif/appwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def import_text_template(self):
doc = read_document_from_cif_file(filename)
block: gemmi.cif.Block = doc.sole_block()
except Exception:
show_general_warning('This file is not readable.')
show_general_warning(self, 'This file is not readable.')
return
text_list = []
for i in block:
Expand All @@ -500,7 +500,7 @@ def export_text_template(self) -> None:
loop = block.init_loop(blockname, [''])
except RuntimeError:
# Not a valid loop key
show_general_warning('"{}" is not a valid cif keyword.'.format(blockname))
show_general_warning(self, '"{}" is not a valid cif keyword.'.format(blockname))
return
for value in textlist:
if value:
Expand All @@ -514,7 +514,7 @@ def export_text_template(self) -> None:
except PermissionError:
if Path(filename).is_dir():
return
show_general_warning('No permission to write file to {}'.format(Path(filename).resolve()))
show_general_warning(self, 'No permission to write file to {}'.format(Path(filename).resolve()))
self.status_bar.show_message(f'Template exported to {filename}.', timeout=10)

def delete_text_template(self) -> None:
Expand Down Expand Up @@ -703,7 +703,7 @@ def is_update_necessary(self, content: bytes) -> None:
remote_version = int(content.decode('ascii', errors='ignore'))
if remote_version > VERSION:
print('Version {} is outdated (actual is {}).'.format(VERSION, remote_version))
show_update_warning(remote_version)
show_update_warning(self, remote_version)
else:
print('Version {} is up-to-date.'.format(VERSION))

Expand Down Expand Up @@ -1127,13 +1127,13 @@ def make_report_tables(self) -> None:
raise
print('Unable to make report from cif file.')
not_ok = e
show_general_warning("The report templates could not be found:\n" + str(not_ok))
show_general_warning(self, "The report templates could not be found:\n" + str(not_ok))
return
except PermissionError:
if DEBUG:
raise
print('Unable to open cif file')
show_general_warning('The report document {} could not be opened.\n'
show_general_warning(self, 'The report document {} could not be opened.\n'
'Is the file already opened?'.format(report_filename.name))
return
if not self.running_inside_unit_test:
Expand Down Expand Up @@ -1219,7 +1219,7 @@ def save_current_cif_file(self) -> Union[bool, None]:
except Exception as e:
print('Unable to save file:')
print(e)
show_general_warning('Can not save file: ' + str(e))
show_general_warning(self, 'Can not save file: ' + str(e))
return False

def store_data_from_table_rows(self) -> None:
Expand All @@ -1232,7 +1232,7 @@ def store_data_from_table_rows(self) -> None:
changes_cif = self.get_changes_cif(self.finalcif_changes_filename)
except Exception as e:
print('Unable to create changes CIF:', e)
unable_to_open_message(filepath=self.finalcif_changes_filename, not_ok=e)
unable_to_open_message(parent=self, filepath=self.finalcif_changes_filename, not_ok=e)
changes_cif = None
# makes sure also the currently edited item is saved:
self.ui.cif_main_table.setCurrentItem(None)
Expand Down Expand Up @@ -1360,24 +1360,24 @@ def import_additional_cif(self, filename: str):
try:
imp_cif = CifContainer(Path(filename))
except RuntimeError as e:
show_general_warning('Could not import {}:\n'.format(filename) + str(e))
show_general_warning(self, 'Could not import {}:\n'.format(filename) + str(e))
return
except ValueError as e:
warning = 'Problems parsing file: {}:\n'.format(filename) + str(e)
if 'data_' in str(e):
warning = warning + "\n\nA CIF needs to start with 'data_[some_name]'."
show_general_warning(warning)
show_general_warning(self, warning)
return
except IOError as e:
show_general_warning('Unable to open file {}:\n'.format(filename) + str(e))
show_general_warning(self, 'Unable to open file {}:\n'.format(filename) + str(e))
return
self.check_cif_for_missing_values_before_really_open_it()
try:
self.import_key_value_pairs(imp_cif)
self.import_loops(imp_cif)
except Exception as e:
print(e)
unable_to_open_message(Path(self.cif.filename), e)
unable_to_open_message(self, Path(self.cif.filename), e)
# I think I leave the user possibilities to change the imported values:
# self.save_current_cif_file()
# self.load_cif_file(str(self.cif.finalcif_file))
Expand Down Expand Up @@ -1450,7 +1450,7 @@ def load_cif_file(self, filepath: Path, block=0, load_changes: bool = True) -> N
print(e)
not_ok = e
if not_ok:
unable_to_open_message(filepath, not_ok)
unable_to_open_message(self, filepath, not_ok)
return
if not self.cif.chars_ok:
self.warn_about_bad_cif()
Expand Down Expand Up @@ -1487,7 +1487,7 @@ def _load_block(self, index: int, load_changes: bool = True) -> None:
self.fill_cif_table()
except UnicodeDecodeError:
nums = self.cif.get_line_numbers_of_bad_characters(Path(self.cif.doc.source))
show_general_warning(window_title='Unable to open file',
show_general_warning(parent=self, window_title='Unable to open file',
warn_text='Invalid characters in file!',
info_text=f'The file "{Path(self.cif.doc.source)}" has invalid '
f'characters in line(s)'
Expand Down Expand Up @@ -1516,7 +1516,7 @@ def _load_block(self, index: int, load_changes: bool = True) -> None:
try:
self.load_changes_cif()
except Exception as e:
unable_to_open_message(filepath=self.finalcif_changes_filename, not_ok=e)
unable_to_open_message(parent=self, filepath=self.finalcif_changes_filename, not_ok=e)
if self.running_inside_unit_test and changes_exist:
self.load_changes_cif()
self.make_loops_tables()
Expand Down Expand Up @@ -1576,9 +1576,9 @@ def append_cif(self, cif_file: Path):
return
cif2 = CifContainer(cif_file)
if cif2.is_multi_cif:
show_general_warning('Can add single data CIFs only!')
show_general_warning(self, 'Can add single data CIFs only!')
if cif2.block.name in [x.name for x in self.cif.doc]:
show_general_warning(warn_text='Duplicate block', info_text='Data block name "<b>{}</b>" already present '
show_general_warning(self, warn_text='Duplicate block', info_text='Data block name "<b>{}</b>" already present '
'in current CIF!'.format(self.cif.block.name))
return
self.cif.doc.add_copied_block(block=cif2.block, pos=-1)
Expand All @@ -1604,7 +1604,7 @@ def check_cif_for_missing_values_before_really_open_it(self) -> None:
print(str(e))
errlist = str(e).split(':')
if len(errlist) > 1:
show_general_warning(
show_general_warning(self,
f"Attention in CIF line {errlist[1]}:\n'{errlist[2].split()[0]}' has no value.")

def get_last_workdir(self):
Expand All @@ -1625,15 +1625,15 @@ def set_path_display_in_file_selector(self, fname: str) -> None:

def able_to_open(self, filepath: Path) -> bool:
if not filepath.exists():
show_general_warning("The file you tried to open does not exist!")
show_general_warning(self, "The file you tried to open does not exist!")
return False
if filepath.stat().st_size == 0:
show_general_warning('This file has zero byte size!')
show_general_warning(self, 'This file has zero byte size!')
return False
return True

def warn_about_bad_cif(self):
show_general_warning("You have non-ascii characters like umlauts in the SHELX file "
show_general_warning(self, "You have non-ascii characters like umlauts in the SHELX file "
"attached to this CIF.\n\n"
"FinalCif tries to convert them, but be warned "
"(they are not allowed in CIF1 files anyway).\n")
Expand Down Expand Up @@ -1744,7 +1744,7 @@ def check_Z(self) -> None:
or csystem == 'hexagonal' or csystem == 'cubic'):
bad = True
if bad:
bad_z_message(Z)
bad_z_message(self, Z)

def get_data_sources(self) -> None:
"""
Expand Down Expand Up @@ -1848,9 +1848,9 @@ def fill_cif_table(self) -> None:
#threading.Thread(target=self.ui.cif_main_table.resizeRowsToContents).start()
# print(key, value)
if not self.cif.test_res_checksum():
show_res_checksum_warning()
show_res_checksum_warning(parent=self)
if not self.cif.test_hkl_checksum():
show_hkl_checksum_warning()
show_hkl_checksum_warning(parent=self)
if self.cif.is_multi_cif:
self.refresh_combo_boxes()
else:
Expand Down Expand Up @@ -1904,7 +1904,7 @@ def add_res_file_to_loops(self) -> None:
textedit.setReadOnly(True)

def _go_to_new_loop_page(self):
self.loopcreate = LoopCreator(cif=self.cif)
self.loopcreate = LoopCreator(parent=self, cif=self.cif)
self.ui.LoopsTabWidget.addTab(self.loopcreate, 'Create Loops')
self.ui.LoopsTabWidget.setCurrentIndex(self.ui.LoopsTabWidget.count() - 1)
self.ui.revertLoopsPushButton.hide()
Expand Down
6 changes: 3 additions & 3 deletions finalcif/cif/cod/deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def prepare_upload(self, username, password, author_name, author_email,
data = self._enrich_upload_data(author_email, author_name, data, deposition_type, embargo_time)
files = self._get_files_data_for_upload()
if 'hkl' not in files and not self.cif.hkl_file \
and not show_ok_cancel_warning('You are attempting to upload a CIF without hkl data.\n'
and not show_ok_cancel_warning(self.ui.Mainwidget, 'You are attempting to upload a CIF without hkl data.\n'
'Do you really want to proceed?'):
self.ui.depositOutputTextBrowser.setText('Deposition aborted.')
return
Expand Down Expand Up @@ -386,14 +386,14 @@ def _set_external_hkl_file(self) -> None:
cif = CifContainer(file)
list_code = cif['_shelx_refln_list_code']
if list_code != '4':
show_general_warning('Only plain hkl or fcf (LIST 4 style) files should be uploaded.')
show_general_warning(self.ui.Mainwidget, 'Only plain hkl or fcf (LIST 4 style) files should be uploaded.')
return
self.hkl_file = io.StringIO(Path(file).read_text())
self.hkl_file.name = Path(file).name
elif file == '':
self.hkl_file = None
else:
show_general_warning('Only plain hkl or fcf (LIST 4 style) files should be uploaded.')
show_general_warning(self.ui.Mainwidget, 'Only plain hkl or fcf (LIST 4 style) files should be uploaded.')


if __name__ == '__main__':
Expand Down
26 changes: 13 additions & 13 deletions finalcif/datafiles/bruker_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,22 @@ def __init__(self, app, cif: CifContainer):
temperature = ''
if (self.cif['_diffrn_ambient_temperature'].split('(')[0] or
self.cif['_cell_measurement_temperature']).split('(')[0] == '0':
show_general_warning('<b>Warning of impossible temperature specification</b>:<br>'
'You probably entered &minus;273.15 °C instead '
'of &minus;173.15 °C into the SHELX instruction file.<br>'
'A temperature of 0 K is likely to be wrong.')
show_general_warning(self.app, '<b>Warning of impossible temperature specification</b>:<br>'
'You probably entered &minus;273.15 °C instead '
'of &minus;173.15 °C into the SHELX instruction file.<br>'
'A temperature of 0 K is likely to be wrong.')
try:
if abs(int(self.cif['_diffrn_ambient_temperature'].split('(')[0]) - int(temperature)) >= 2 and \
not self.app.temperature_warning_displayed:
not self.app.temperature_warning_displayed:
self.app.temperature_warning_displayed = True
show_general_warning('<b>Warning</b>: The temperature from the measurement and '
'from SHELX differ. Please double-check for correctness.<br><br>'
'SHELX says: {} K<br>'
'The P4P file says: {} K<br>'
'Frame header says: {} K<br><br>'
'You may add a '
'<a href="http://shelx.uni-goettingen.de/shelxl_html.php#TEMP">TEMP</a> '
'instruction to your SHELX file (in °C).'
show_general_warning(self.app, '<b>Warning</b>: The temperature from the measurement and '
'from SHELX differ. Please double-check for correctness.<br><br>'
'SHELX says: {} K<br>'
'The P4P file says: {} K<br>'
'Frame header says: {} K<br><br>'
'You may add a '
'<a href="http://shelx.uni-goettingen.de/shelxl_html.php#TEMP">TEMP</a> '
'instruction to your SHELX file (in °C).'
.format(self.cif['_diffrn_ambient_temperature'].split('(')[0],
round(temp2, 1),
round(temp1, 1)))
Expand Down
4 changes: 2 additions & 2 deletions finalcif/equip_property/author_loop_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def check_if_loop_and_row_size_fit_together(self, gemmi_loop: gemmi.cif.Loop, ro
if cut_row not in gemmi_loop.values:
gemmi_loop.add_row(cut_row)
elif gemmi_loop.width() > len(row):
show_general_warning('An author loop with larger size is already in the CIF. Can not proceed.')
show_general_warning(self, 'An author loop with larger size is already in the CIF. Can not proceed.')
else:
if row not in gemmi_loop.values:
gemmi_loop.add_row(row)
Expand Down Expand Up @@ -283,7 +283,7 @@ def export_author_template(self, filename: str = None) -> None:
except (PermissionError, IOError):
if Path(filename).is_dir():
return
show_general_warning('No permission to write file to {}'.format(Path(filename).resolve()))
show_general_warning(self, 'No permission to write file to {}'.format(Path(filename).resolve()))

def put_author_in_cif_object(self, blockname: str, filename: str) -> CifContainer:
author = self.author_loopdata(author_name=self.get_selected_loop_name())
Expand Down
6 changes: 3 additions & 3 deletions finalcif/equip_property/equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ def save_equipment_template(self) -> None:
for key, _ in table_data:
if key not in cif_all_dict.keys():
if not key.startswith('_'):
show_general_warning('"{}" is not a valid keyword! '
show_general_warning(self.app, '"{}" is not a valid keyword! '
'\nChange the name in order to save.\n'
'Keys must start with an underscore.'.format(key))
return
show_general_warning('"{}" is not an official CIF keyword!'.format(key))
show_general_warning(self.app, '"{}" is not an official CIF keyword!'.format(key))
self.settings.save_settings_list('equipment', self.selected_template_name(), table_data)
self.app.ui.EquipmentTemplatesStackedWidget.setCurrentIndex(0)
print('saved')
Expand Down Expand Up @@ -269,7 +269,7 @@ def export_equipment_template(self, filename: str = None) -> None:
except PermissionError:
if Path(filename).is_dir():
return
show_general_warning('No permission to write file to {}'.format(Path(filename).resolve()))
show_general_warning(self.app, 'No permission to write file to {}'.format(Path(filename).resolve()))

def cancel_equipment_template(self) -> None:
"""
Expand Down
4 changes: 2 additions & 2 deletions finalcif/equip_property/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def export_property_template(self, filename: str = '') -> None:
loop = block.init_loop(cif_key, [''])
except RuntimeError:
# Not a valid loop key
show_general_warning('"{}" is not a valid cif keyword.'.format(cif_key))
show_general_warning(self.app, '"{}" is not a valid cif keyword.'.format(cif_key))
return
for value in table_data:
if value:
Expand All @@ -186,7 +186,7 @@ def export_property_template(self, filename: str = '') -> None:
except PermissionError:
if Path(filename).is_dir():
return
show_general_warning('No permission to write file to {}'.format(Path(filename).resolve()))
show_general_warning(self.app, 'No permission to write file to {}'.format(Path(filename).resolve()))

def selected_template_name(self) -> str:
return self.app.ui.PropertiesTemplatesListWidget.currentIndex().data()
Expand Down
4 changes: 2 additions & 2 deletions finalcif/equip_property/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def read_document_from_cif_file(filename: str) -> Union[gemmi.cif.Document, None
warning = "{}\n{}".format('This CIF is invalid:', str(e))
if 'data_' in str(e):
warning = f"{warning}\n\nA CIF needs to start with 'data_[some_name]'."
show_general_warning(warning)
show_general_warning(parent=None, warn_text=warning)
except IOError as e:
show_general_warning(f'Unable to open file {filename}:\n{str(e)}')
show_general_warning(parent=None, warn_text=f'Unable to open file {filename}:\n{str(e)}')
return doc
2 changes: 1 addition & 1 deletion finalcif/finalcif_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def main():
if len(sys.argv) > 1:
file = Path(sys.argv[1])
if not file.is_file():
show_general_warning(warn_text=f'The file {file.resolve().absolute()} \nyou tried to open does not exist.',
show_general_warning(parent=None, warn_text=f'The file {file.resolve().absolute()} \nyou tried to open does not exist.',
window_title='File not found')
file = None
app.setQuitOnLastWindowClosed(True)
Expand Down
3 changes: 1 addition & 2 deletions finalcif/gui/custom_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ class MyCifTable(QTableWidget, ItemTextMixin):
new_key = QtCore.pyqtSignal(str)

def __init__(self, parent: QWidget = None, *args, **kwargs):
super().__init__(*args, **kwargs)
super().__init__(parent=parent, *args, **kwargs)
self.parent = parent
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setParent(parent)
self.installEventFilter(self)
self.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
Expand Down
Loading

0 comments on commit 302e485

Please sign in to comment.