class NewIntegerSequenceDateTimeConvertSpecDialog(QDialog): def __init__(self, *args, **kwargs): super(NewIntegerSequenceDateTimeConvertSpecDialog, self).__init__(*args, **kwargs) self.setWindowTitle("New integer sequence datetime") QBtn = QDialogButtonBox.Ok | QDialogButtonBox.Cancel self.buttonBox = QDialogButtonBox(QBtn) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.datetime = QDateTimeEdit() self.start_integer = QSpinBox() self.duration = QLineEdit("1h") self.duration.textChanged.connect(self._validate) self.layout = QVBoxLayout() self.form = QFormLayout() self.form.addRow("Initial datetime", self.datetime) self.form.addRow("Initial integer", self.start_integer) self.form.addRow("Timestep duration", self.duration) self.layout.addLayout(self.form) self.layout.addWidget(self.buttonBox) self.setLayout(self.layout) self._validate() def _validate(self): try: Duration(self.duration.text()) except ParameterValueFormatError: self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) return self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True) def get_spec(self): start_datetime = DateTime(self.datetime.dateTime().toString( Qt.ISODate)) duration = Duration(self.duration.text()) start_int = self.start_integer.value() return IntegerSequenceDateTimeConvertSpec(start_datetime, start_int, duration)
class EventPropertiesDialog(QDialog): def __init__(self): super().__init__(GlobalAccess().get_main_window()) def exec_(self): self.init_ui() return super().exec_() def init_ui(self): self.setFixedWidth(500) self.setWindowTitle(_('Event properties')) self.setWindowIcon(QIcon(config.ICON)) self.setSizeGripEnabled(False) self.setModal(True) self.layout = QFormLayout(self) self.label_main_title = QLabel(_('Main title')) self.item_main_title = QLineEdit() self.layout.addRow(self.label_main_title, self.item_main_title) self.label_sub_title = QLabel(_('Sub title')) self.item_sub_title = QTextEdit() self.item_sub_title.setMaximumHeight(100) self.layout.addRow(self.label_sub_title, self.item_sub_title) self.label_start_date = QLabel(_('Start date')) self.item_start_date = QDateTimeEdit() self.item_start_date.setDisplayFormat('yyyy.MM.dd HH:mm:ss') self.layout.addRow(self.label_start_date, self.item_start_date) self.label_end_date = QLabel(_('End date')) # self.item_end_date = QCalendarWidget() self.item_end_date = QDateTimeEdit() self.item_end_date.setDisplayFormat('yyyy.MM.dd HH:mm:ss') self.layout.addRow(self.label_end_date, self.item_end_date) self.label_location = QLabel(_('Location')) self.item_location = QLineEdit() self.layout.addRow(self.label_location, self.item_location) self.label_type = QLabel(_('Event type')) self.item_type = AdvComboBox() self.item_type.addItems(RaceType.get_titles()) self.layout.addRow(self.label_type, self.item_type) self.label_relay_legs = QLabel(_('Relay legs')) self.item_relay_legs = QSpinBox() self.item_relay_legs.setMinimum(1) self.item_relay_legs.setMaximum(20) self.item_relay_legs.setValue(3) self.layout.addRow(self.label_relay_legs, self.item_relay_legs) self.item_type.currentTextChanged.connect(self.change_type) self.label_refery = QLabel(_('Chief referee')) self.item_refery = QLineEdit() self.layout.addRow(self.label_refery, self.item_refery) self.label_secretary = QLabel(_('Secretary')) self.item_secretary = QLineEdit() self.layout.addRow(self.label_secretary, self.item_secretary) self.label_url = QLabel(_('URL')) self.item_url = QLineEdit() self.layout.addRow(self.label_url, self.item_url) def cancel_changes(): self.close() def apply_changes(): try: self.apply_changes_impl() except Exception as e: logging.error(str(e)) self.close() button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_ok = button_box.button(QDialogButtonBox.Ok) self.button_ok.setText(_('OK')) self.button_ok.clicked.connect(apply_changes) self.button_cancel = button_box.button(QDialogButtonBox.Cancel) self.button_cancel.setText(_('Cancel')) self.button_cancel.clicked.connect(cancel_changes) self.layout.addRow(button_box) self.set_values_from_model() self.show() def change_type(self): flag = self.item_type.currentText() == RaceType.RELAY.get_title() self.label_relay_legs.setVisible(flag) self.item_relay_legs.setVisible(flag) def set_values_from_model(self): obj = race() self.item_main_title.setText(str(obj.data.title)) self.item_sub_title.setText(str(obj.data.description)) self.item_location.setText(str(obj.data.location)) self.item_url.setText(str(obj.data.url)) self.item_refery.setText(str(obj.data.chief_referee)) self.item_secretary.setText(str(obj.data.secretary)) self.item_start_date.setDateTime(obj.data.get_start_datetime()) self.item_end_date.setDateTime(obj.data.get_end_datetime()) self.item_type.setCurrentText(obj.data.race_type.get_title()) self.item_relay_legs.setValue(obj.data.relay_leg_count) self.change_type() def apply_changes_impl(self): obj = race() start_date = self.item_start_date.dateTime().toPython() end_date = self.item_end_date.dateTime().toPython() obj.data.title = self.item_main_title.text() obj.data.description = self.item_sub_title.toPlainText() obj.data.description = obj.data.description.replace('\n', '<br>\n') obj.data.location = self.item_location.text() obj.data.url = self.item_url.text() obj.data.chief_referee = self.item_refery.text() obj.data.secretary = self.item_secretary.text() obj.data.start_datetime = start_date obj.data.end_datetime = end_date t = RaceType.get_by_name(self.item_type.currentText()) if t is not None: obj.data.race_type = t obj.data.relay_leg_count = self.item_relay_legs.value() obj.set_setting('system_zero_time', (start_date.hour, start_date.minute, 0)) ResultCalculation(race()).process_results() GlobalAccess().get_main_window().set_title()
class TransferWidget(AbstractOperationDetails): def __init__(self, parent=None): AbstractOperationDetails.__init__(self, parent) self.name = "Transfer" self.from_date_label = QLabel(self) self.from_account_label = QLabel(self) self.from_amount_label = QLabel(self) self.to_date_label = QLabel(self) self.to_account_label = QLabel(self) self.to_amount_label = QLabel(self) self.fee_account_label = QLabel(self) self.fee_amount_label = QLabel(self) self.comment_label = QLabel(self) self.arrow_account = QLabel(self) self.copy_date_btn = QPushButton(self) self.copy_amount_btn = QPushButton(self) self.main_label.setText(g_tr("TransferWidget", "Transfer")) self.from_date_label.setText(g_tr("TransferWidget", "Date/Time")) self.from_account_label.setText(g_tr("TransferWidget", "From")) self.from_amount_label.setText(g_tr("TransferWidget", "Amount")) self.to_date_label.setText(g_tr("TransferWidget", "Date/Time")) self.to_account_label.setText(g_tr("TransferWidget", "To")) self.to_amount_label.setText(g_tr("TransferWidget", "Amount")) self.fee_account_label.setText(g_tr("TransferWidget", "Fee from")) self.fee_amount_label.setText(g_tr("TransferWidget", "Fee amount")) self.comment_label.setText(g_tr("TransferWidget", "Note")) self.arrow_account.setText(" ➜ ") self.copy_date_btn.setText("➜") self.copy_date_btn.setFixedWidth( self.copy_date_btn.fontMetrics().width("XXXX")) self.copy_amount_btn.setText("➜") self.copy_amount_btn.setFixedWidth( self.copy_amount_btn.fontMetrics().width("XXXX")) self.withdrawal_timestamp = QDateTimeEdit(self) self.withdrawal_timestamp.setCalendarPopup(True) self.withdrawal_timestamp.setTimeSpec(Qt.UTC) self.withdrawal_timestamp.setFixedWidth( self.withdrawal_timestamp.fontMetrics().width( "00/00/0000 00:00:00") * 1.25) self.withdrawal_timestamp.setDisplayFormat("dd/MM/yyyy hh:mm:ss") self.deposit_timestamp = QDateTimeEdit(self) self.deposit_timestamp.setCalendarPopup(True) self.deposit_timestamp.setTimeSpec(Qt.UTC) self.deposit_timestamp.setFixedWidth( self.deposit_timestamp.fontMetrics().width("00/00/0000 00:00:00") * 1.25) self.deposit_timestamp.setDisplayFormat("dd/MM/yyyy hh:mm:ss") self.from_account_widget = AccountSelector(self) self.to_account_widget = AccountSelector(self) self.fee_account_widget = AccountSelector(self) self.withdrawal = AmountEdit(self) self.withdrawal.setAlignment(Qt.AlignRight) self.deposit = AmountEdit(self) self.deposit.setAlignment(Qt.AlignRight) self.fee = AmountEdit(self) self.fee.setAlignment(Qt.AlignRight) self.comment = QLineEdit(self) self.layout.addWidget(self.from_date_label, 1, 0, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.from_account_label, 2, 0, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.from_amount_label, 3, 0, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.comment_label, 5, 0, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.withdrawal_timestamp, 1, 1, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.from_account_widget, 2, 1, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.withdrawal, 3, 1, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.comment, 5, 1, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.copy_date_btn, 1, 2, 1, 1) self.layout.addWidget(self.arrow_account, 2, 2, 1, 1, Qt.AlignCenter) self.layout.addWidget(self.copy_amount_btn, 3, 2, 1, 1) self.layout.addWidget(self.to_date_label, 1, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.to_account_label, 2, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.to_amount_label, 3, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.fee_account_label, 4, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.fee_amount_label, 5, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.deposit_timestamp, 1, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.to_account_widget, 2, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.deposit, 3, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.fee_account_widget, 4, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.fee, 5, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.commit_button, 0, 6, 1, 1) self.layout.addWidget(self.revert_button, 0, 7, 1, 1) self.layout.addItem(self.verticalSpacer, 6, 0, 1, 1) self.layout.addItem(self.horizontalSpacer, 1, 5, 1, 1) self.copy_date_btn.clicked.connect(self.onCopyDate) self.copy_amount_btn.clicked.connect(self.onCopyAmount) super()._init_db("transfers") self.mapper.setItemDelegate(TransferWidgetDelegate(self.mapper)) self.from_account_widget.changed.connect(self.mapper.submit) self.to_account_widget.changed.connect(self.mapper.submit) self.fee_account_widget.changed.connect(self.mapper.submit) self.mapper.addMapping(self.withdrawal_timestamp, self.model.fieldIndex("withdrawal_timestamp")) self.mapper.addMapping(self.from_account_widget, self.model.fieldIndex("withdrawal_account")) self.mapper.addMapping(self.withdrawal, self.model.fieldIndex("withdrawal")) self.mapper.addMapping(self.deposit_timestamp, self.model.fieldIndex("deposit_timestamp")) self.mapper.addMapping(self.to_account_widget, self.model.fieldIndex("deposit_account")) self.mapper.addMapping(self.deposit, self.model.fieldIndex("deposit")) self.mapper.addMapping(self.fee_account_widget, self.model.fieldIndex("fee_account")) self.mapper.addMapping(self.fee, self.model.fieldIndex("fee")) self.mapper.addMapping(self.comment, self.model.fieldIndex("note")) self.model.select() @Slot() def saveChanges(self): record = self.model.record(0) note = record.value(self.model.fieldIndex("note")) if not note: # If we don't have note - set it to NULL value # TODO - is it really needed? self.model.setData( self.model.index(0, self.model.fieldIndex("note")), None) # Set related fields NULL if we don't have fee. This is required for correct transfer processing fee_amount = record.value(self.model.fieldIndex("fee")) if not fee_amount: fee_amount = 0 if abs(float(fee_amount)) < Setup.CALC_TOLERANCE: self.model.setData( self.model.index(0, self.model.fieldIndex("fee_account")), None) self.model.setData( self.model.index(0, self.model.fieldIndex("fee")), None) super().saveChanges() def prepareNew(self, account_id): new_record = self.model.record() new_record.setNull("id") new_record.setValue( "withdrawal_timestamp", int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp())) new_record.setValue("withdrawal_account", account_id) new_record.setValue("withdrawal", 0) new_record.setValue( "deposit_timestamp", int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp())) new_record.setValue("deposit_account", 0) new_record.setValue("deposit", 0) new_record.setValue("fee_account", 0) new_record.setValue("fee", 0) new_record.setValue("asset", None) new_record.setValue("note", None) return new_record def copyToNew(self, row): new_record = self.model.record(row) new_record.setNull("id") new_record.setValue( "withdrawal_timestamp", int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp())) new_record.setValue( "deposit_timestamp", int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp())) return new_record @Slot() def onCopyDate(self): self.deposit_timestamp.setDateTime( self.withdrawal_timestamp.dateTime()) @Slot() def onCopyAmount(self): self.deposit.setText(self.withdrawal.text())
class FilewriterCommandWidget(QWidget): """ Used for the required and optional fields when saving a filewriter command JSON file. """ def __init__(self, parent=None): super(FilewriterCommandWidget, self).__init__() self.setParent(parent) self.setLayout(QFormLayout()) self.nexus_file_name_edit = QLineEdit() self.ok_button = QPushButton("Ok") if parent is not None: self.ok_button.clicked.connect(parent.close) self.broker_line_edit = QLineEdit() self.broker_line_edit.setPlaceholderText("broker:port") self.ok_validator = CommandDialogOKValidator() self.ok_validator.is_valid.connect(self.ok_button.setEnabled) filename_validator = CommandDialogFileNameValidator() self.nexus_file_name_edit.setValidator(filename_validator) filename_validator.is_valid.connect( partial( validate_line_edit, self.nexus_file_name_edit, tooltip_on_reject= f"Invalid NeXus file name - Should end with {HDF_FILE_EXTENSIONS}", )) filename_validator.is_valid.connect( self.ok_validator.set_filename_valid) filename_validator.is_valid.emit(False) broker_validator = NameValidator([]) self.broker_line_edit.setValidator(broker_validator) broker_validator.is_valid.connect( partial( validate_line_edit, self.broker_line_edit, tooltip_on_reject="Broker is required", )) broker_validator.is_valid.connect(self.ok_validator.set_broker_valid) broker_validator.is_valid.emit(False) self.start_time_enabled = QCheckBox() self.start_time_picker = QDateTimeEdit(QDateTime.currentDateTime()) self.start_time_picker.setDisplayFormat(TIME_FORMAT) self.start_time_enabled.stateChanged.connect( partial(self.state_changed, True)) self.start_time_enabled.setChecked(True) self.stop_time_enabled = QCheckBox() self.stop_time_picker = QDateTimeEdit(QDateTime.currentDateTime()) self.stop_time_picker.setDisplayFormat(TIME_FORMAT) self.stop_time_enabled.stateChanged.connect( partial(self.state_changed, False)) self.stop_time_enabled.setChecked(False) self.state_changed(False, Qt.CheckState.Unchecked) self.service_id_lineedit = QLineEdit() self.service_id_lineedit.setPlaceholderText("(Optional)") self.abort_on_uninitialised_stream_checkbox = QCheckBox() self.use_swmr_checkbox = QCheckBox() self.use_swmr_checkbox.setChecked(True) self.layout().addRow("nexus_file_name", self.nexus_file_name_edit) self.layout().addRow("broker", self.broker_line_edit) self.layout().addRow("specify start time?", self.start_time_enabled) self.layout().addRow("start_time", self.start_time_picker) self.layout().addRow("specify stop time?", self.stop_time_enabled) self.layout().addRow("stop_time", self.stop_time_picker) self.layout().addRow("service_id", self.service_id_lineedit) self.layout().addRow("abort_on_uninitialised_stream", self.abort_on_uninitialised_stream_checkbox) self.layout().addRow("use_hdf_swmr", self.use_swmr_checkbox) self.layout().addRow(self.ok_button) def state_changed(self, is_start_time: bool, state: Qt.CheckState): if state != Qt.CheckState.Checked: self.start_time_picker.setEnabled( False) if is_start_time else self.stop_time_picker.setEnabled( False) else: self.start_time_picker.setEnabled( True) if is_start_time else self.stop_time_picker.setEnabled( True) def get_arguments( self, ) -> Tuple[str, str, Union[str, None], Union[str, None], str, bool, bool]: """ gets the arguments of required and optional fields for the filewriter command. :return: Tuple containing all of the fields. """ return ( self.nexus_file_name_edit.text(), self.broker_line_edit.text(), self.start_time_picker.dateTime().toMSecsSinceEpoch() if self.start_time_enabled.checkState() == Qt.CheckState.Checked else None, self.stop_time_picker.dateTime().toMSecsSinceEpoch() if self.stop_time_enabled.checkState() == Qt.CheckState.Checked else None, self.service_id_lineedit.text(), self.abort_on_uninitialised_stream_checkbox.checkState() == Qt.CheckState.Checked, self.use_swmr_checkbox.checkState() == Qt.CheckState.Checked, )