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 __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 _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 createEditor(self, parent, option, index, object_explorer=False): """Overriding method createEditor""" val_type = index.sibling(index.row(), 1).data() self.sig_open_editor.emit() if index.column() < 3: return None if self.show_warning(index): answer = QMessageBox.warning( self.parent(), _("Warning"), _("Opening this variable can be slow\n\n" "Do you want to continue anyway?"), QMessageBox.Yes | QMessageBox.No) if answer == QMessageBox.No: return None try: value = self.get_value(index) if value is None: return None except ImportError as msg: self.sig_editor_shown.emit() module = str(msg).split("'")[1] if module in ['pandas', 'numpy']: if module == 'numpy': val_type = 'array' else: val_type = 'dataframe, series' QMessageBox.critical( self.parent(), _("Error"), _("Spyder is unable to show the {val_type} or object " "you're trying to view because <tt>{module}</tt> was " "not installed alongside Spyder. Please install " "this package in your Spyder environment." "<br>").format(val_type=val_type, module=module)) return else: QMessageBox.critical( self.parent(), _("Error"), _("Spyder is unable to show the variable you're " "trying to view because the module " "<tt>{module}</tt> was not found in your " "Spyder environment. Please install " "this package in your Spyder environment." "<br>").format(module=module)) return except Exception as msg: QMessageBox.critical( self.parent(), _("Error"), _("Spyder was unable to retrieve the value of " "this variable from the console.<br><br>" "The error message was:<br>" "%s") % to_text_string(msg)) return key = index.model().get_key(index) readonly = (isinstance(value, (tuple, set)) or self.parent().readonly or not is_known_type(value)) # CollectionsEditor for a list, tuple, dict, etc. if isinstance(value, (list, set, tuple, dict)) and not object_explorer: from spyder.widgets.collectionseditor import CollectionsEditor editor = CollectionsEditor(parent=parent) editor.setup(value, key, icon=self.parent().windowIcon(), readonly=readonly) self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # ArrayEditor for a Numpy array elif (isinstance(value, (ndarray, MaskedArray)) and ndarray is not FakeObject and not object_explorer): editor = ArrayEditor(parent=parent) if not editor.setup_and_check(value, title=key, readonly=readonly): return self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # ArrayEditor for an images elif (isinstance(value, Image) and ndarray is not FakeObject and Image is not FakeObject and not object_explorer): arr = array(value) editor = ArrayEditor(parent=parent) if not editor.setup_and_check(arr, title=key, readonly=readonly): return conv_func = lambda arr: Image.fromarray(arr, mode=value.mode) self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly, conv=conv_func)) return None # DataFrameEditor for a pandas dataframe, series or index elif (isinstance(value, (DataFrame, Index, Series)) and DataFrame is not FakeObject and not object_explorer): editor = DataFrameEditor(parent=parent) if not editor.setup_and_check(value, title=key): return editor.dataModel.set_format(index.model().dataframe_format) editor.sig_option_changed.connect(self.change_option) self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # QDateEdit and QDateTimeEdit for a dates or datetime respectively elif isinstance(value, datetime.date) and not object_explorer: # Needed to handle NaT values # See spyder-ide/spyder#8329 try: value.time() except ValueError: self.sig_editor_shown.emit() return None if readonly: self.sig_editor_shown.emit() return None else: if isinstance(value, datetime.datetime): editor = QDateTimeEdit(value, parent=parent) else: editor = QDateEdit(value, parent=parent) editor.setCalendarPopup(True) editor.setFont(get_font(font_size_delta=DEFAULT_SMALL_DELTA)) self.sig_editor_shown.emit() return editor # TextEditor for a long string elif is_text_string(value) and len(value) > 40 and not object_explorer: te = TextEditor(None, parent=parent) if te.setup_and_check(value): editor = TextEditor(value, key, readonly=readonly, parent=parent) self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # QLineEdit for an individual value (int, float, short string, etc) elif is_editable_type(value) and not object_explorer: if readonly: self.sig_editor_shown.emit() return None else: editor = QLineEdit(parent=parent) editor.setFont(get_font(font_size_delta=DEFAULT_SMALL_DELTA)) editor.setAlignment(Qt.AlignLeft) # This is making Spyder crash because the QLineEdit that it's # been modified is removed and a new one is created after # evaluation. So the object on which this method is trying to # act doesn't exist anymore. # editor.returnPressed.connect(self.commitAndCloseEditor) self.sig_editor_shown.emit() return editor # ObjectExplorer for an arbitrary Python object else: show_callable_attributes = index.model().show_callable_attributes show_special_attributes = index.model().show_special_attributes dataframe_format = index.model().dataframe_format if show_callable_attributes is None: show_callable_attributes = False if show_special_attributes is None: show_special_attributes = False from spyder.plugins.variableexplorer.widgets.objectexplorer \ import ObjectExplorer editor = ObjectExplorer( value, name=key, parent=parent, show_callable_attributes=show_callable_attributes, show_special_attributes=show_special_attributes, dataframe_format=dataframe_format, readonly=readonly) editor.sig_option_changed.connect(self.change_option) self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None
def createEditor(self, parent, option, index): """Overriding method createEditor""" if self.show_warning(index): answer = QMessageBox.warning( self.parent(), _("Warning"), _("Opening this variable can be slow\n\n" "Do you want to continue anyway?"), QMessageBox.Yes | QMessageBox.No) if answer == QMessageBox.No: return None try: value = self.get_value(index) try: self.old_obj = value.copy() except AttributeError: self.old_obj = copy.deepcopy(value) if value is None: return None except Exception as msg: QMessageBox.critical( self.parent(), _("Error"), _("Spyder was unable to retrieve the value of " "this variable from the console.<br><br>" "The error message was:<br>" "<i>%s</i>") % to_text_string(msg)) return self.current_index = index key = index.model().get_key(index).obj_name readonly = (isinstance(value, (tuple, set)) or self.parent().readonly or not is_known_type(value)) # CollectionsEditor for a list, tuple, dict, etc. if isinstance(value, (list, set, tuple, dict)): from spyder.widgets.collectionseditor import CollectionsEditor editor = CollectionsEditor(parent=parent) editor.setup(value, key, icon=self.parent().windowIcon(), readonly=readonly) self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # ArrayEditor for a Numpy array elif (isinstance(value, (ndarray, MaskedArray)) and ndarray is not FakeObject): editor = ArrayEditor(parent=parent) if not editor.setup_and_check(value, title=key, readonly=readonly): return self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # ArrayEditor for an images elif (isinstance(value, Image) and ndarray is not FakeObject and Image is not FakeObject): arr = array(value) editor = ArrayEditor(parent=parent) if not editor.setup_and_check(arr, title=key, readonly=readonly): return conv_func = lambda arr: Image.fromarray(arr, mode=value.mode) self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly, conv=conv_func)) return None # DataFrameEditor for a pandas dataframe, series or index elif (isinstance(value, (DataFrame, Index, Series)) and DataFrame is not FakeObject): editor = DataFrameEditor(parent=parent) if not editor.setup_and_check(value, title=key): return editor.dataModel.set_format(index.model().dataframe_format) editor.sig_option_changed.connect(self.change_option) self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # QDateEdit and QDateTimeEdit for a dates or datetime respectively elif isinstance(value, datetime.date): if readonly: return None else: if isinstance(value, datetime.datetime): editor = QDateTimeEdit(value, parent=parent) else: editor = QDateEdit(value, parent=parent) editor.setCalendarPopup(True) editor.setFont(get_font(font_size_delta=DEFAULT_SMALL_DELTA)) return editor # TextEditor for a long string elif is_text_string(value) and len(value) > 40: te = TextEditor(None, parent=parent) if te.setup_and_check(value): editor = TextEditor(value, key, readonly=readonly, parent=parent) self.create_dialog( editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # QLineEdit for an individual value (int, float, short string, etc) elif is_editable_type(value): if readonly: return None else: editor = QLineEdit(parent=parent) editor.setFont(get_font(font_size_delta=DEFAULT_SMALL_DELTA)) editor.setAlignment(Qt.AlignLeft) # This is making Spyder crash because the QLineEdit that it's # been modified is removed and a new one is created after # evaluation. So the object on which this method is trying to # act doesn't exist anymore. # editor.returnPressed.connect(self.commitAndCloseEditor) return editor # An arbitrary Python object. # Since we are already in the Object Explorer no editor is needed else: return None
def __init__(self, item, parent_layout): super(DateWidget, self).__init__(item, parent_layout) self.dateedit = self.group = QDateEdit() self.dateedit.setToolTip(item.get_help())
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
def setup(self): for label, value in self.data: if DEBUG_FORMLAYOUT: print("value:", value) # trex: test-skip if label is None and value is None: # Separator: (None, None) self.formlayout.addRow(QLabel(" "), QLabel(" ")) self.widgets.append(None) continue elif label is None: # Comment self.formlayout.addRow(QLabel(value)) self.widgets.append(None) continue elif tuple_to_qfont(value) is not None: field = FontLayout(value, self) elif text_to_qcolor(value).isValid(): field = ColorLayout(QColor(value), self) elif is_text_string(value): if '\n' in value: for linesep in (os.linesep, '\n'): if linesep in value: value = value.replace(linesep, u"\u2029") field = QTextEdit(value, self) else: field = QLineEdit(value, self) elif isinstance(value, (list, tuple)): value = list(value) # in case this is a tuple selindex = value.pop(0) field = QComboBox(self) if isinstance(value[0], (list, tuple)): keys = [key for key, _val in value] value = [val for _key, val in value] else: keys = value field.addItems(value) if selindex in value: selindex = value.index(selindex) elif selindex in keys: selindex = keys.index(selindex) elif not isinstance(selindex, int): print("Warning: '%s' index is invalid (label: "\ "%s, value: %s)" % (selindex, label, value), file=STDERR) selindex = 0 field.setCurrentIndex(selindex) elif isinstance(value, bool): field = QCheckBox(self) field.setCheckState(Qt.Checked if value else Qt.Unchecked) elif isinstance(value, float): field = QLineEdit(repr(value), self) field.setValidator(QDoubleValidator(field)) dialog = self.get_dialog() dialog.register_float_field(field) field.textChanged.connect(lambda text: dialog.update_buttons()) elif isinstance(value, int): field = QSpinBox(self) field.setRange(-1e9, 1e9) field.setValue(value) elif isinstance(value, datetime.datetime): field = QDateTimeEdit(self) field.setDateTime(value) elif isinstance(value, datetime.date): field = QDateEdit(self) field.setDate(value) else: field = QLineEdit(repr(value), self) self.formlayout.addRow(label, field) self.widgets.append(field)
def createEditor(self, parent, option, index, object_explorer=False): """Overriding method createEditor""" val_type = index.sibling(index.row(), 1).data() self.sig_editor_creation_started.emit() if index.column() < 3: return None if self.show_warning(index): answer = QMessageBox.warning( self.parent(), _("Warning"), _("Opening this variable can be slow\n\n" "Do you want to continue anyway?"), QMessageBox.Yes | QMessageBox.No) if answer == QMessageBox.No: self.sig_editor_shown.emit() return None try: value = self.get_value(index) if value is None: return None except ImportError as msg: self.sig_editor_shown.emit() module = str(msg).split("'")[1] if module in ['pandas', 'numpy']: if module == 'numpy': val_type = 'array' else: val_type = 'dataframe, series' message = _("Spyder is unable to show the {val_type} or object" " you're trying to view because <tt>{module}</tt>" " is not installed. ") if running_in_mac_app(): message += _("Please consider using the full version of " "the Spyder MacOS application.<br>") else: message += _("Please install this package in your Spyder " "environment.<br>") QMessageBox.critical( self.parent(), _("Error"), message.format(val_type=val_type, module=module)) return else: if running_in_mac_app() or is_pynsist(): message = _("Spyder is unable to show the variable you're" " trying to view because the module " "<tt>{module}</tt> is not supported in the " "Spyder Lite application.<br>") else: message = _("Spyder is unable to show the variable you're" " trying to view because the module " "<tt>{module}</tt> is not found in your " "Spyder environment. Please install this " "package in this environment.<br>") QMessageBox.critical(self.parent(), _("Error"), message.format(module=module)) return except Exception as msg: QMessageBox.critical( self.parent(), _("Error"), _("Spyder was unable to retrieve the value of " "this variable from the console.<br><br>" "The error message was:<br>" "%s") % to_text_string(msg)) return key = index.model().get_key(index) readonly = (isinstance(value, (tuple, set)) or self.parent().readonly or not is_known_type(value)) # We can't edit Numpy void objects because they could be anything, so # this might cause a crash. # Fixes spyder-ide/spyder#10603 if isinstance(value, np.void): self.sig_editor_shown.emit() return None # CollectionsEditor for a list, tuple, dict, etc. elif isinstance(value, (list, set, tuple, dict)) and not object_explorer: from spyder.widgets.collectionseditor import CollectionsEditor editor = CollectionsEditor(parent=parent) editor.setup(value, key, icon=self.parent().windowIcon(), readonly=readonly) self.create_dialog(editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # ArrayEditor for a Numpy array elif (isinstance(value, (np.ndarray, np.ma.MaskedArray)) and np.ndarray is not FakeObject and not object_explorer): # We need to leave this import here for tests to pass. from .arrayeditor import ArrayEditor editor = ArrayEditor(parent=parent) if not editor.setup_and_check(value, title=key, readonly=readonly): return self.create_dialog(editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # ArrayEditor for an images elif (isinstance(value, PIL.Image.Image) and np.ndarray is not FakeObject and PIL.Image is not FakeObject and not object_explorer): # Sometimes the ArrayEditor import above is not seen (don't know # why), so we need to reimport it here. # Fixes spyder-ide/spyder#16731 from .arrayeditor import ArrayEditor arr = np.array(value) editor = ArrayEditor(parent=parent) if not editor.setup_and_check(arr, title=key, readonly=readonly): return conv_func = lambda arr: PIL.Image.fromarray(arr, mode=value.mode) self.create_dialog(editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly, conv=conv_func)) return None # DataFrameEditor for a pandas dataframe, series or index elif (isinstance(value, (pd.DataFrame, pd.Index, pd.Series)) and pd.DataFrame is not FakeObject and not object_explorer): # We need to leave this import here for tests to pass. from .dataframeeditor import DataFrameEditor editor = DataFrameEditor(parent=parent) if not editor.setup_and_check(value, title=key): self.sig_editor_shown.emit() return self.create_dialog(editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # QDateEdit and QDateTimeEdit for a dates or datetime respectively elif isinstance(value, datetime.date) and not object_explorer: if readonly: self.sig_editor_shown.emit() return None else: if isinstance(value, datetime.datetime): editor = QDateTimeEdit(value, parent=parent) # Needed to handle NaT values # See spyder-ide/spyder#8329 try: value.time() except ValueError: self.sig_editor_shown.emit() return None else: editor = QDateEdit(value, parent=parent) editor.setCalendarPopup(True) editor.setFont(get_font(font_size_delta=DEFAULT_SMALL_DELTA)) self.sig_editor_shown.emit() return editor # TextEditor for a long string elif is_text_string(value) and len(value) > 40 and not object_explorer: te = TextEditor(None, parent=parent) if te.setup_and_check(value): editor = TextEditor(value, key, readonly=readonly, parent=parent) self.create_dialog(editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None # QLineEdit for an individual value (int, float, short string, etc) elif is_editable_type(value) and not object_explorer: if readonly: self.sig_editor_shown.emit() return None else: editor = QLineEdit(parent=parent) editor.setFont(get_font(font_size_delta=DEFAULT_SMALL_DELTA)) editor.setAlignment(Qt.AlignLeft) # This is making Spyder crash because the QLineEdit that it's # been modified is removed and a new one is created after # evaluation. So the object on which this method is trying to # act doesn't exist anymore. # editor.returnPressed.connect(self.commitAndCloseEditor) self.sig_editor_shown.emit() return editor # ObjectExplorer for an arbitrary Python object else: from spyder.plugins.variableexplorer.widgets.objectexplorer \ import ObjectExplorer editor = ObjectExplorer( value, name=key, parent=parent, readonly=readonly) self.create_dialog(editor, dict(model=index.model(), editor=editor, key=key, readonly=readonly)) return None
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()