class PMGTimeCtrl(BaseExtendedWidget): def __init__(self, layout_dir: str, title, initial_date): super().__init__(layout_dir) self.prefix = lab_title = QLabel(text=title) path_layout = QHBoxLayout() path_layout.addWidget(lab_title) self.ctrl = QDateEdit() path_layout.addWidget(self.ctrl) calendar_widget = QCalendar() self.ctrl.setCalendar(calendar_widget) self.central_layout.addLayout(path_layout) self.set_value(initial_date) def set_value(self, value: Union[Tuple[int, int, int], float, int]): if isinstance(value, tuple): assert len(value) == 3 date = QDate(*value) elif isinstance(value, (float, int)): loc_time = time.localtime(value) print(loc_time) date = QDate(loc_time.tm_year, loc_time.tm_mon, loc_time.tm_mday) else: raise ValueError("value is not allowed", value) self.ctrl.setDate(date) def get_value(self) -> float: """ 计算值 :return: """ return time.mktime(self.ctrl.date().toPyDate().timetuple())
def __insert_new_row(self, row=-1): self.ui.tableWidget.insertRow(row) self.ui.tableWidget.setRowHeight(row, self.table_row_height) button_width = 80 new_entry_level = self.entry_level + 1 self.entry_level = new_entry_level #column0 - entry col = 0 _name = str(new_entry_level) item = QTableWidgetItem(str(_name)) self.ui.tableWidget.setItem(row, col, item) #new column - sample environment col = 1 sample_combobox = QComboBox() sample_combobox.setEditable(True) sample_combobox.setMaximumHeight(40) master_list_sample_environment = self.get_master_list_sample_environment( ) sample_combobox.addItems(master_list_sample_environment) master_list_sample_environment_index_selected = self.ui.sample_environment_combobox.currentIndex( ) sample_combobox.setCurrentIndex( master_list_sample_environment_index_selected) label = QLabel("Select or Edit!") verti_layout = QVBoxLayout() verti_layout.addWidget(sample_combobox) verti_layout.addWidget(label) widget = QWidget() widget.setLayout(verti_layout) self.ui.tableWidget.setCellWidget(row, col, widget) # new column - calibration col = 2 # first row label = QLabel("Run #:") cali_value = QLineEdit("") cali_value.returnPressed.connect( lambda entry=_name: self.run_entered(entry)) cali_browser_button = QPushButton("Browse...") cali_browser_button.setMinimumWidth(button_width) cali_browser_button.setMaximumWidth(button_width) cali_browser_button.clicked.connect( lambda state, entry=_name: self.calibration_browser_clicked(entry)) first_row = QHBoxLayout() first_row.addWidget(label) first_row.addWidget(cali_value) first_row.addWidget(cali_browser_button) first_row_widget = QWidget() first_row_widget.setLayout(first_row) # second row cali_browser_button_value = QLabel("N/A") verti_layout = QVBoxLayout() verti_layout.addWidget(first_row_widget) verti_layout.addWidget(cali_browser_button_value) col1_widget = QWidget() col1_widget.setLayout(verti_layout) self.ui.tableWidget.setCellWidget(row, col, col1_widget) # new column - Vanadium col = 3 # first row # first row label = QLabel("Run #:") vana_value = QLineEdit("") vana_value.returnPressed.connect( lambda entry=_name: self.run_entered(entry)) vana_browser_button = QPushButton("Browse...") vana_browser_button.setMinimumWidth(button_width) vana_browser_button.setMaximumWidth(button_width) vana_browser_button.clicked.connect( lambda state, entry=_name: self.vanadium_browser_clicked(entry)) first_row = QHBoxLayout() first_row.addWidget(label) first_row.addWidget(vana_value) first_row.addWidget(vana_browser_button) first_row_widget = QWidget() first_row_widget.setLayout(first_row) # second row vana_browser_button_value = QLabel("N/A") verti_layout = QVBoxLayout() verti_layout.addWidget(first_row_widget) verti_layout.addWidget(vana_browser_button_value) col1_widget = QWidget() col1_widget.setLayout(verti_layout) self.ui.tableWidget.setCellWidget(row, col, col1_widget) # new column - date col = 4 date = QDateEdit() date.setDate(self.master_date_value) self.ui.tableWidget.setCellWidget(row, col, date) # new column - output dir col = 5 browser_button = QPushButton("Browse...") browser_button.setMinimumWidth(button_width) browser_button.setMaximumWidth(button_width) browser_button.clicked.connect( lambda state, entry=_name: self.local_output_dir_clicked(entry)) browser_value = QLabel(self.master_folder) reset = QPushButton("Use Master") reset.setMinimumWidth(button_width) reset.setMaximumWidth(button_width) reset.clicked.connect( lambda state, entry=_name: self.local_reset_dir_clicked(entry)) hori_layout = QHBoxLayout() hori_layout.addWidget(browser_button) hori_layout.addWidget(browser_value) hori_layout.addWidget(reset) widget = QWidget() widget.setLayout(hori_layout) self.ui.tableWidget.setCellWidget(row, col, widget) list_local_ui = self.local_list_ui( sample_environment_value=sample_combobox, calibration_value=cali_value, calibration_browser=cali_browser_button, calibration_browser_value=cali_browser_button_value, vanadium_value=vana_value, vanadium_browser=vana_browser_button, vanadium_browser_value=vana_browser_button_value, date=date, output_dir_browser=browser_button, output_dir_value=browser_value, output_reset=reset) self.master_list_ui[_name] = list_local_ui list_local_name = dict(vanadium_run_number="", vanadium_browser="", calibration_run_number="", calibration_browser="") self.master_list_value[_name] = list_local_name
class HeaderWidget(ParameterWidget): def __init__(self, parent=None): ParameterWidget.__init__(self, Header, parent) def _init_ui(self): # Widgets self._txt_title = TextAttributeLineEdit(attribute=self.CLASS.title) self._txt_author = TextAttributeLineEdit(attribute=self.CLASS.author) self._txt_owner = TextAttributeLineEdit(attribute=self.CLASS.owner) self._txt_date = QDateEdit() self._txt_date.setDisplayFormat('yyyy-MM-dd') self._txt_time = QTimeEdit() self._txt_time.setDisplayFormat('hh:mm:ss') self._txt_timezone = TextAttributeLineEdit(attribute=self.CLASS.timezone) self._txt_checksum = TextAttributeLineEdit(attribute=self.CLASS.checksum) self._txt_checksum.setReadOnly(True) # Layouts layout = ParameterWidget._init_ui(self) layout.addRow('Title', self._txt_title) layout.addRow('Author', self._txt_author) layout.addRow('Owner', self._txt_owner) layout.addRow('Date', self._txt_date) layout.addRow('Time', self._txt_time) layout.addRow('Timezone', self._txt_timezone) layout.addRow('Checksum', self._txt_checksum) # Signals self._txt_title.textEdited.connect(self.edited) self._txt_author.textEdited.connect(self.edited) self._txt_owner.textEdited.connect(self.edited) self._txt_date.dateChanged.connect(self.edited) self._txt_time.timeChanged.connect(self.edited) self._txt_timezone.textEdited.connect(self.edited) self._txt_checksum.textEdited.connect(self.edited) return layout def parameter(self, parameter=None): parameter = ParameterWidget.parameter(self, parameter) parameter.title = self._txt_title.text() parameter.author = self._txt_author.text() parameter.owner = self._txt_owner.text() parameter.date = self._txt_date.date().toString('yyyy-MM-dd') parameter.time = self._txt_time.time().toString('hh:mm:ss') parameter.timezone = self._txt_timezone.text() return parameter def setParameter(self, header): ParameterWidget.setParameter(self, header) self._txt_title.setText(header.title) self._txt_author.setText(header.author) self._txt_owner.setText(header.owner) date = header.date if date is not None: self._txt_date.setDate(QDate(date.year, date.month, date.day)) time = header.time if time is not None: self._txt_time.setTime(QTime(time.hour, time.minute, time.second)) self._txt_timezone.setText(header.timezone) checksum = header.checksum if checksum is not None: self._txt_checksum.setText(checksum.value) def header(self, header=None): return self.parameter(header) def setHeader(self, header): self.setParameter(header) def setReadOnly(self, state): ParameterWidget.setReadOnly(self, state) self._txt_title.setReadOnly(state) self._txt_author.setReadOnly(state) self._txt_owner.setReadOnly(state) self._txt_date.setReadOnly(state) self._txt_time.setReadOnly(state) self._txt_timezone.setReadOnly(state) self._txt_checksum.setReadOnly(state) def isReadOnly(self): return ParameterWidget.isReadOnly(self) and \ self._txt_title.isReadOnly() and \ self._txt_author.isReadOnly() and \ self._txt_owner.isReadOnly() and \ self._txt_date.isReadOnly() and \ self._txt_time.isReadOnly() and \ self._txt_timezone.isReadOnly() and \ self._txt_checksum.isReadOnly() def hasAcceptableInput(self): return ParameterWidget.hasAcceptableInput(self) and \ self._txt_title.hasAcceptableInput() and \ self._txt_author.hasAcceptableInput() and \ self._txt_owner.hasAcceptableInput() and \ self._txt_date.hasAcceptableInput() and \ self._txt_time.hasAcceptableInput() and \ self._txt_timezone.hasAcceptableInput() and \ self._txt_checksum.hasAcceptableInput()