Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

main_function_widgets.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. from PyQt5.QtCore import pyqtSignal, QObject, pyqtSlot
  2. from PyQt5.QtWidgets import QVBoxLayout, QHBoxLayout, QLineEdit, QLabel, QPushButton, QGroupBox, QSizePolicy, \
  3. QFormLayout, QWidget, QCheckBox
  4. class MainFunctionAbstract(QGroupBox):
  5. send_data = pyqtSignal(str, dict)
  6. flag_update_signal = pyqtSignal(str, str)
  7. def __init__(
  8. self, parent, button_names=(), flag_names=(),
  9. flag_defaults=(), group_name="", comment=None, stack_vertically=True):
  10. super().__init__(group_name, parent)
  11. if stack_vertically:
  12. layout = QVBoxLayout(self)
  13. else:
  14. layout = QHBoxLayout(self)
  15. if comment is not None:
  16. layout.addWidget(QLabel(comment, parent))
  17. flags_hbox = QHBoxLayout()
  18. self.flag_names = flag_names
  19. self.flag_line_edits = {}
  20. for flag, flag_default_value in zip(flag_names, flag_defaults):
  21. flag_group_box = self.create_get_flags_groupbox(flag, flag_default_value)
  22. flags_hbox.addWidget(flag_group_box)
  23. layout.addLayout(flags_hbox)
  24. buttons_hbox = QHBoxLayout()
  25. self.buttons = {}
  26. for button_name in button_names:
  27. button = QPushButton(button_name)
  28. self.buttons[button_name] = button
  29. button.clicked.connect(self.collect_send_data)
  30. buttons_hbox.addWidget(button)
  31. layout.addLayout(buttons_hbox)
  32. def create_get_flags_groupbox(self, flag, flag_default_value):
  33. flag_group_box = QWidget(self)
  34. flag_form_box = QFormLayout(flag_group_box)
  35. flag_group_box.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
  36. line_edit = QLineEdit(str(flag_default_value))
  37. line_edit.setAccessibleName(flag)
  38. line_edit.editingFinished.connect(self.flag_update_request)
  39. flag_form_box.addRow(flag, line_edit)
  40. self.flag_line_edits[flag] = line_edit
  41. return flag_group_box
  42. def collect_send_data(self):
  43. sender = QObject.sender(self)
  44. self.send_data.emit(
  45. sender.text(),
  46. {flag: flag_line_edit.text() for flag, flag_line_edit in self.flag_line_edits.items()})
  47. def update_flag_defaults(self, flag_defaults):
  48. for flag_name, flag_value in flag_defaults.items():
  49. if flag_name in self.flag_names:
  50. self.flag_line_edits[flag_name].setText(str(flag_value))
  51. def flag_update_request(self):
  52. sender_le = QObject.sender(self)
  53. self.flag_update_signal.emit(sender_le.accessibleName(), sender_le.text())
  54. def reset_flag(self, flag_name, flag_value):
  55. self.flag_line_edits[flag_name].setText(str(flag_value))
  56. class OverviewGenWidget(MainFunctionAbstract):
  57. send_data = pyqtSignal(str, dict, bool, bool)
  58. def __init__(self, parent, current_flags):
  59. gen_overviews_box_flags = ["CTV_Method", "CTV_firstframe", "CTV_lastframe"]
  60. super().__init__(
  61. parent=parent, button_names=["Generate(new)"],
  62. flag_names=gen_overviews_box_flags,
  63. flag_defaults=[current_flags[f] for f in gen_overviews_box_flags],
  64. group_name="Generate overview images",
  65. stack_vertically=True
  66. )
  67. self.check_boxes = {}
  68. self.deactivatable_flag_boxes = {}
  69. extra_hbox = QHBoxLayout()
  70. temp = {
  71. "CTV_FeatureNumber": "Use all features?", "CTV_StimulusNumber": "Use all stimuli?"
  72. }
  73. for flag, check_box_name in temp.items():
  74. flag_group_box = self.create_get_flags_groupbox(
  75. flag=flag, flag_default_value=current_flags[flag])
  76. self.deactivatable_flag_boxes[flag] = flag_group_box
  77. extra_hbox.addWidget(flag_group_box)
  78. check_box = QCheckBox(check_box_name, self)
  79. check_box.setAccessibleName(flag)
  80. check_box.stateChanged.connect(self.inactivate_flag)
  81. self.check_boxes[flag] = check_box
  82. extra_hbox.addWidget(check_box)
  83. self.layout().insertLayout(1, extra_hbox)
  84. @pyqtSlot(int, name="inactivate_flag")
  85. def inactivate_flag(self, state):
  86. sender = QObject.sender(self)
  87. self.deactivatable_flag_boxes[sender.accessibleName()].setEnabled(state != 2)
  88. def collect_send_data(self):
  89. sender = QObject.sender(self)
  90. self.send_data.emit(
  91. sender.text(),
  92. {flag: flag_line_edit.text() for flag, flag_line_edit in self.flag_line_edits.items()},
  93. self.check_boxes["CTV_FeatureNumber"].isChecked(),
  94. self.check_boxes["CTV_StimulusNumber"].isChecked()
  95. )