Ejemplo n.º 1
1
 def create_dateedit(self, text, option, tip=None):
     label = QLabel(text)
     dateedit = QDateEdit()
     dateedit.setDisplayFormat('dd MMM yyyy')
     dateedit.setMaximumDate(QDate(2010,12,31))
     dateedit.setMinimumDate(QDate(2002,01,01))
     if tip is not None: dateedit.setToolTip(tip)
     self.dateedits[dateedit] = option
     layout = QHBoxLayout()
     for subwidget in (label, dateedit):
         layout.addWidget(subwidget)
     layout.addStretch(1)
     layout.setContentsMargins(0, 0, 0, 0)
     widget = QWidget(self)
     widget.setLayout(layout)
     return widget
Ejemplo n.º 2
0
    def _create_widget(cls, c, parent, host=None):
        dt = QDateEdit(parent)
        dt.setObjectName(u'{0}_{1}'.format(cls._TYPE_PREFIX, c.name))
        dt.setCalendarPopup(True)

        # Set ranges
        if c.min_use_current_date:
            dt.setMinimumDate(date.today())
        else:
            dt.setMinimumDate(c.minimum)

        if c.max_use_current_date:
            dt.setMaximumDate(date.today())
        else:
            dt.setMaximumDate(c.maximum)

        # Set maximum date as current date
        dt.setDate(date.today())

        return dt
Ejemplo n.º 3
0
 def create_dateedit(self,
                     text,
                     option,
                     tip=None,
                     min_date=None,
                     max_date=None):
     label = QLabel(text)
     dateedit = QDateEdit()
     dateedit.setDisplayFormat('dd MMM yyyy')
     if min_date: dateedit.setMinimumDate(min_date)
     if max_date: dateedit.setMaximumDate(max_date)
     if tip: dateedit.setToolTip(tip)
     self.dateedits[dateedit] = option
     layout = QHBoxLayout()
     for subwidget in (label, dateedit):
         layout.addWidget(subwidget)
     layout.addStretch(1)
     layout.setContentsMargins(0, 0, 0, 0)
     widget = QWidget(self)
     widget.setLayout(layout)
     return widget
Ejemplo n.º 4
0
        def initGui():
            def setData():
                buttonPath.setText(self.data["path"])
                radioVisual.setChecked(self.data["isVisual"])
                radioAnalytic.setChecked(not self.data["isVisual"])
                chkBoxSquare.setChecked(self.data["isSquare"])
                d1 = self.data["date1"]
                d2 = self.data["date2"]
                date1.setDate(d1)
                date2.setDate(d2)
                date1.setMaximumDate(d2.addDays(-1))
                date2.setMinimumDate(d1.addDays(+1))
                spinDay.setValue(d1.daysTo(d2))

            def connect():
                buttonOK.clicked.connect(self.onOK)
                buttonPath.clicked.connect(self.onPath)
                date1.dateChanged.connect(self.onDateChanged1)
                date2.dateChanged.connect(self.onDateChanged2)
                spinDay.valueChanged.connect(self.onValueChanged)

            windowTitle = "Setting download images Planet Labs"
            self.setWindowTitle(windowTitle)
            self.setWindowIcon(icon)

            grpImage = QGroupBox("Images", self)
            radioVisual = QRadioButton("Visual", grpImage)
            radioVisual.setObjectName("rbVisual")
            radioAnalytic = QRadioButton("Analytic", grpImage)
            chkBoxSquare = QCheckBox("Square thumbnail", grpImage)
            chkBoxSquare.setObjectName("cbBoxSquare")
            buttonPath = QPushButton(self.titleSelectDirectory, grpImage)
            buttonPath.setObjectName("pbPath")

            layoutRadioButtons = QHBoxLayout()
            for item in (radioVisual, radioAnalytic):
                layoutRadioButtons.addWidget(item)

            layoutImage = QVBoxLayout(grpImage)
            layoutImage.addLayout(layoutRadioButtons)
            layoutImage.addWidget(chkBoxSquare)
            layoutImage.addWidget(buttonPath)

            grpDateSearch = QGroupBox("Dates for search", self)
            date1 = QDateEdit(grpDateSearch)
            date1.setObjectName("deDate1")
            date2 = QDateEdit(grpDateSearch)
            date2.setObjectName("deDate2")
            for item in [date1, date2]:
                item.setCalendarPopup(True)
                format = item.displayFormat().replace("yy", "yyyy")
                item.setDisplayFormat(format)
            spinDay = QSpinBox(grpDateSearch)
            spinDay.setObjectName("sbDay")
            spinDay.setSingleStep(1)
            spinDay.setSuffix(" Days")
            spinDay.setRange(1, 1000 * 360)

            layoutDate = QHBoxLayout(grpDateSearch)
            layoutDate.addWidget(QLabel("From", grpDateSearch))
            layoutDate.addWidget(date1)
            layoutDate.addWidget(QLabel("To", grpDateSearch))
            layoutDate.addWidget(date2)
            layoutDate.addWidget(spinDay)

            buttonOK = QPushButton("OK", self)

            layout = QVBoxLayout(self)
            layout.addWidget(grpImage)
            layout.addWidget(grpDateSearch)
            layout.addWidget(buttonOK)

            self.resize(5 * len(windowTitle) + 200, 30)

            if not self.data is None:
                setData()
            else:
                radioVisual.setChecked(True)
                radioAnalytic.setChecked(False)
                chkBoxSquare.setChecked(False)
                d2 = QDate.currentDate()
                d1 = d2.addMonths(-1)
                date1.setDate(d1)
                date2.setDate(d2)
                date1.setMaximumDate(d2.addDays(-1))
                date2.setMinimumDate(d1.addDays(+1))
                spinDay.setValue(d1.daysTo(d2))

            connect()
Ejemplo n.º 5
0
class QtDateSelector(QtBoundedDate, ProxyDateSelector):
    """ A Qt implementation of an Enaml ProxyDateSelector.

    """
    #: A reference to the widget created by the proxy.
    widget = Typed(QDateEdit)

    #--------------------------------------------------------------------------
    # Initialization API
    #--------------------------------------------------------------------------
    def create_widget(self):
        """ Create the QDateEdit widget.

        """
        self.widget = QDateEdit(self.parent_widget())

    def init_widget(self):
        """ Initialize the widget.

        """
        super(QtDateSelector, self).init_widget()
        d = self.declaration
        self.set_date_format(d.date_format)
        self.set_calendar_popup(d.calendar_popup)
        self.widget.dateChanged.connect(self.on_date_changed)

    #--------------------------------------------------------------------------
    # Abstract API Implementation
    #--------------------------------------------------------------------------
    def get_date(self):
        """ Return the current date in the control.

        Returns
        -------
        result : date
            The current control date as a date object.

        """
        return self.widget.date().toPyDate()

    def set_minimum(self, date):
        """ Set the widget's minimum date.

        Parameters
        ----------
        date : date
            The date object to use for setting the minimum date.

        """
        self.widget.setMinimumDate(date)

    def set_maximum(self, date):
        """ Set the widget's maximum date.

        Parameters
        ----------
        date : date
            The date object to use for setting the maximum date.

        """
        self.widget.setMaximumDate(date)

    def set_date(self, date):
        """ Set the widget's current date.

        Parameters
        ----------
        date : date
            The date object to use for setting the date.

        """
        self._guard |= CHANGED_GUARD
        try:
            self.widget.setDate(date)
        finally:
            self._guard &= ~CHANGED_GUARD

    def set_date_format(self, format):
        """ Set the widget's date format.

        Parameters
        ----------
        format : str
            A Python time formatting string.

        """
        # XXX make sure Python's and Qt's format strings are the
        # same, or convert between the two.
        self.widget.setDisplayFormat(format)

    def set_calendar_popup(self, popup):
        """ Set whether a calendar popup is available on the widget.

        Parameters
        ----------
        popup : bool
            Whether the calendar popup is enabled.

        """
        self.widget.setCalendarPopup(popup)
Ejemplo n.º 6
0
class QtDateSelector(QtBoundedDate, ProxyDateSelector):
    """ A Qt implementation of an Enaml ProxyDateSelector.

    """

    #: A reference to the widget created by the proxy.
    widget = Typed(QDateEdit)

    # --------------------------------------------------------------------------
    # Initialization API
    # --------------------------------------------------------------------------
    def create_widget(self):
        """ Create the QDateEdit widget.

        """
        self.widget = QDateEdit(self.parent_widget())

    def init_widget(self):
        """ Initialize the widget.

        """
        super(QtDateSelector, self).init_widget()
        d = self.declaration
        self.set_date_format(d.date_format)
        self.set_calendar_popup(d.calendar_popup)
        self.widget.dateChanged.connect(self.on_date_changed)

    # --------------------------------------------------------------------------
    # Abstract API Implementation
    # --------------------------------------------------------------------------
    def get_date(self):
        """ Return the current date in the control.

        Returns
        -------
        result : date
            The current control date as a date object.

        """
        return self.widget.date().toPyDate()

    def set_minimum(self, date):
        """ Set the widget's minimum date.

        Parameters
        ----------
        date : date
            The date object to use for setting the minimum date.

        """
        self.widget.setMinimumDate(date)

    def set_maximum(self, date):
        """ Set the widget's maximum date.

        Parameters
        ----------
        date : date
            The date object to use for setting the maximum date.

        """
        self.widget.setMaximumDate(date)

    def set_date(self, date):
        """ Set the widget's current date.

        Parameters
        ----------
        date : date
            The date object to use for setting the date.

        """
        self._guard |= CHANGED_GUARD
        try:
            self.widget.setDate(date)
        finally:
            self._guard &= ~CHANGED_GUARD

    def set_date_format(self, format):
        """ Set the widget's date format.

        Parameters
        ----------
        format : str
            A Python time formatting string.

        """
        # XXX make sure Python's and Qt's format strings are the
        # same, or convert between the two.
        self.widget.setDisplayFormat(format)

    def set_calendar_popup(self, popup):
        """ Set whether a calendar popup is available on the widget.

        Parameters
        ----------
        popup : bool
            Whether the calendar popup is enabled.

        """
        self.widget.setCalendarPopup(popup)