def update_maximum_datetime(self, event=None): # sanity checking of values if (self.minimum_datetime is not None and self.maximum_datetime is not None and self.minimum_datetime > self.maximum_datetime): self.minimum_datetime = self.maximum_datetime if self.control is not None: if self.maximum_datetime is not None: self.control.setMaximumDateTime( QDateTime(self.maximum_datetime)) else: self.control.clearMaximumDateTime()
def update_editor(self): """Updates the editor when the object trait changes externally to the editor. """ value = self.value if value: if self.minimum_datetime and self.minimum_datetime > value: value = self.minimum_datetime elif self.maximum_datetime and self.value > self.maximum_datetime: value = self.maximum_datetime try: q_datetime = QDateTime(value) except Exception: pass self.control.setDateTime(q_datetime) self.value = value
def test_datetime_editor_qt_datetime_out_of_bound(self): # The maximum datetime supported by Qt is larger than the maximum # datetime supported by Python editor_factory = DatetimeEditor() view = get_date_time_simple_view(editor_factory) init_datetime = datetime.datetime(1900, 1, 1) instance = InstanceWithDatetime(date_time=init_datetime) with self.launch_editor(instance, view) as editor: # the user set the datetime on the Qt widget to a value # too large for Python from pyface.qt.QtCore import QDateTime, QDate q_datetime = QDateTime(QDate(datetime.MAXYEAR + 1, 1, 1)) editor.control.setDateTime(q_datetime) # Get the displayed value back. displayed_value = to_datetime(editor.control.dateTime()) self.assertEqual(instance.date_time, displayed_value)