def _initInputUI(self, layout):
        self.setWindowTitle(self._title)
        messageLabel = QLabel(self._message, self)
        messageLabel.setWordWrap(True)
        layout.addWidget(messageLabel)

        inputWidget = QWidget(self)
        inputLayout = QHBoxLayout(inputWidget)
        inputLayout.setContentsMargins(0, 0, 0, 0)
                
        if type(self._initialBegin) != QTime:
            initialBegin = QTime.fromString(self._initialBegin, lunch_settings.LUNCH_TIME_FORMAT_QT)
        if type(self._initialEnd) != QTime:
            initialEnd = QTime.fromString(self._initialEnd, lunch_settings.LUNCH_TIME_FORMAT_QT)
                
        inputLayout.addWidget(QLabel("From", self))
        self.beginEdit = QTimeEdit(self)
        self.beginEdit.setDisplayFormat("HH:mm")
        self.beginEdit.setTime(initialBegin)
        inputLayout.addWidget(self.beginEdit)
        
        inputLayout.addWidget(QLabel("to", self))
        self.endEdit = QTimeEdit(self)
        self.endEdit.setDisplayFormat("HH:mm")
        self.endEdit.setTime(initialEnd)
        inputLayout.addWidget(self.endEdit)
        
        layout.addWidget(inputWidget, 0, Qt.AlignLeft)
class TimespanInputDialog(ErrorMessageDialog):
    def __init__(self, parent, title, message, initialBegin, initialEnd, checkBeforeNow=True):
        self._checkBeforeNow = checkBeforeNow
        self._title = title
        self._message = message
        self._initialBegin = initialBegin
        self._initialEnd = initialEnd
        
        super(TimespanInputDialog, self).__init__(parent)
        
    def _initInputUI(self, layout):
        self.setWindowTitle(self._title)
        messageLabel = QLabel(self._message, self)
        messageLabel.setWordWrap(True)
        layout.addWidget(messageLabel)

        inputWidget = QWidget(self)
        inputLayout = QHBoxLayout(inputWidget)
        inputLayout.setContentsMargins(0, 0, 0, 0)
                
        if type(self._initialBegin) != QTime:
            initialBegin = QTime.fromString(self._initialBegin, lunch_settings.LUNCH_TIME_FORMAT_QT)
        if type(self._initialEnd) != QTime:
            initialEnd = QTime.fromString(self._initialEnd, lunch_settings.LUNCH_TIME_FORMAT_QT)
                
        inputLayout.addWidget(QLabel("From", self))
        self.beginEdit = QTimeEdit(self)
        self.beginEdit.setDisplayFormat("HH:mm")
        self.beginEdit.setTime(initialBegin)
        inputLayout.addWidget(self.beginEdit)
        
        inputLayout.addWidget(QLabel("to", self))
        self.endEdit = QTimeEdit(self)
        self.endEdit.setDisplayFormat("HH:mm")
        self.endEdit.setTime(initialEnd)
        inputLayout.addWidget(self.endEdit)
        
        layout.addWidget(inputWidget, 0, Qt.AlignLeft)
        
    @loggingSlot()
    def _checkOK(self):
        if self.getEndTime() < self.getBeginTime():
            self._error(u"End time is before begin time.")
        elif self._checkBeforeNow and \
             getTimeDifference(self.getBeginTimeString(), self.getEndTimeString(), getCoreLogger()) == 0:
            self._error(u"The time span is already over.")
        else:
            self.accept()
        
    def getBeginTime(self):
        return self.beginEdit.time().toPyTime()
    def getBeginTimeString(self):
        return self.beginEdit.time().toPyTime().strftime(lunch_settings.LUNCH_TIME_FORMAT)
    
    def getEndTime(self):
        return self.endEdit.time().toPyTime()
    def getEndTimeString(self):
        return self.endEdit.time().toPyTime().strftime(lunch_settings.LUNCH_TIME_FORMAT)
示例#3
0
 def createEditor(self, parent, option, index):
     return QTimeEdit(parent)
示例#4
0
    def __init__(self, parent=None):
        super(TalkDetailsWidget, self).__init__(parent)

        self.layout = QGridLayout()
        self.setLayout(self.layout)

        self.buttonLayout = QHBoxLayout()

        saveIcon = QIcon.fromTheme("document-save")
        self.saveButton = QPushButton('Save Talk')
        self.saveButton.setIcon(saveIcon)
        self.buttonLayout.addWidget(self.saveButton)

        self.layout.addLayout(self.buttonLayout, 0, 1, 1, 1)

        self.titleLabel = QLabel('Title')
        self.titleLineEdit = QLineEdit()
        self.presenterLabel = QLabel('Presenter')
        self.presenterLineEdit = QLineEdit()
        self.layout.addWidget(self.titleLabel, 1, 0, 1, 1)
        self.layout.addWidget(self.titleLineEdit, 1, 1, 1, 1)
        self.layout.addWidget(self.presenterLabel, 1, 2, 1, 1)
        self.layout.addWidget(self.presenterLineEdit, 1, 3, 1, 1)

        self.eventLabel = QLabel('Event')
        self.eventLineEdit = QLineEdit()
        self.categoryLabel = QLabel('Category')
        self.categoryLineEdit = QLineEdit()

        self.layout.addWidget(self.eventLabel, 2, 0, 1, 1)
        self.layout.addWidget(self.eventLineEdit, 2, 1, 1, 1)
        self.layout.addWidget(self.categoryLabel, 2, 2, 1, 1)
        self.layout.addWidget(self.categoryLineEdit, 2, 3, 1, 1)

        self.roomLabel = QLabel('Room')
        self.roomLineEdit = QLineEdit()
        self.dateLayout = QHBoxLayout()
        self.dateLabel = QLabel('Date')
        self.dateEdit = QDateEdit()
        currentDate = QDate()
        self.dateEdit.setDate(currentDate.currentDate())
        self.dateEdit.setCalendarPopup(True)

        self.layout.addWidget(self.roomLabel, 3, 0, 1, 1)
        self.layout.addWidget(self.roomLineEdit, 3, 1, 1, 1)
        self.dateLayout.addWidget(self.dateEdit)
        self.layout.addWidget(self.dateLabel, 3, 2, 1, 1)
        self.layout.addLayout(self.dateLayout, 3, 3, 1, 1)

        self.startTimeLayout = QHBoxLayout()
        self.startTimeLabel = QLabel('Start Time')
        self.startTimeEdit = QTimeEdit()
        self.startTimeLayout.addWidget(self.startTimeEdit)
        self.endTimeLayout = QHBoxLayout()
        self.endTimeLabel = QLabel('End Time')
        self.endTimeEdit = QTimeEdit()
        self.endTimeLayout.addWidget(self.endTimeEdit)

        self.layout.addWidget(self.startTimeLabel, 4, 0, 1, 1)
        self.layout.addLayout(self.startTimeLayout, 4, 1, 1, 1)
        self.layout.addWidget(self.endTimeLabel, 4, 2, 1, 1)
        self.layout.addLayout(self.endTimeLayout, 4, 3, 1, 1)

        self.descriptionLabel = QLabel('Description')
        self.descriptionLabel.setAlignment(Qt.AlignTop)
        self.descriptionTextEdit = QPlainTextEdit()
        self.layout.addWidget(self.descriptionLabel, 5, 0, 1, 1)
        self.layout.addWidget(self.descriptionTextEdit, 5, 1, 1, 3)
示例#5
0
    def __init__(self, parent=None):
        '''
        Constructor
        '''
        QWidget.__init__(self, parent)
        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        self.addTalkGroupBox = QGroupBox("Add Talk")
        self.mainLayout.addWidget(self.addTalkGroupBox)

        self.addTalkLayout = QFormLayout()
        self.addTalkGroupBox.setLayout(self.addTalkLayout)

        # Title
        self.titleLabel = QLabel("Title")
        self.titleLineEdit = QLineEdit()
        if hasattr(QLineEdit(), 'setPlaceholderText'):
            self.titleLineEdit.setPlaceholderText("Title of the presentation")
        self.titleLabel.setBuddy(self.titleLineEdit)
        self.addTalkLayout.addRow(self.titleLabel, self.titleLineEdit)

        # Presenter
        self.presenterLabel = QLabel("Presenter")
        self.presenterLineEdit = QLineEdit()
        if hasattr(QLineEdit(), 'setPlaceholderText'):
            self.presenterLineEdit.setPlaceholderText("Name person or people presenting (comma separated)")
        self.presenterLabel.setBuddy(self.presenterLineEdit)
        self.addTalkLayout.addRow(self.presenterLabel, self.presenterLineEdit)

        # Event
        self.eventLabel = QLabel("Event")
        self.eventLineEdit = QLineEdit()
        if hasattr(QLineEdit(), 'setPlaceholderText'):
            self.eventLineEdit.setPlaceholderText("The name of the Event this talk is being presented at")
        self.eventLabel.setBuddy(self.eventLineEdit)
        self.addTalkLayout.addRow(self.eventLabel, self.eventLineEdit)

        # Room
        self.roomLabel = QLabel("Room")
        self.roomLineEdit = QLineEdit()
        if hasattr(QLineEdit(), 'setPlaceholderText'):
            self.roomLineEdit.setPlaceholderText("The Room in which the presentation is taking place")
        self.roomLabel.setBuddy(self.roomLineEdit)
        self.addTalkLayout.addRow(self.roomLabel, self.roomLineEdit)

        # Date
        current_date = QDate()
        self.dateLabel = QLabel("Date")
        self.dateEdit = QDateEdit()
        self.dateEdit.setDate(current_date.currentDate())
        self.dateLabel.setBuddy(self.dateEdit)
        self.addTalkLayout.addRow(self.dateLabel, self.dateEdit)

        self.dateEdit.setCalendarPopup(True)

        # Time
        current_time = QTime()
        self.timeLabel = QLabel("Time")
        self.timeEdit = QTimeEdit()
        self.timeEdit.setTime(current_time.currentTime())
        self.timeLabel.setBuddy(self.dateEdit)
        self.addTalkLayout.addRow(self.timeLabel, self.timeEdit)

        # Buttons
        addIcon = QIcon.fromTheme("list-add")
        cancelIcon = QIcon.fromTheme("edit-clear")

        self.buttonsWidget = QHBoxLayout()
        self.addButton = QPushButton("Add")
        self.addButton.setIcon(addIcon)
        self.cancelButton = QPushButton("Cancel")
        self.cancelButton.setIcon(cancelIcon)
        self.buttonsWidget.addWidget(self.addButton)
        self.buttonsWidget.addWidget(self.cancelButton)
        self.addTalkLayout.addRow(None, self.buttonsWidget)
示例#6
0
    def __init__(self, parent=None):
        super(TalkDetailsWidget, self).__init__(parent)

        self.layout = QGridLayout()
        self.setLayout(self.layout)

        self.buttonLayout = QHBoxLayout()

        addIcon = QIcon.fromTheme("list-add")
        self.addButton = QPushButton("Add New Talk")
        self.addButton.setIcon(addIcon)
        self.buttonLayout.addWidget(self.addButton)
        saveIcon = QIcon.fromTheme("document-save")
        self.saveButton = QPushButton("Save New Talk")
        self.saveButton.setIcon(saveIcon)
        self.buttonLayout.addWidget(self.saveButton)

        self.layout.addLayout(self.buttonLayout, 0, 1, 1, 1)

        self.titleLabel = QLabel("Title")
        self.titleLineEdit = QLineEdit()
        self.layout.addWidget(self.titleLabel, 1, 0, 1, 1)
        self.layout.addWidget(self.titleLineEdit, 1, 1, 1, 3)

        self.presenterLabel = QLabel("Presenter")
        self.presenterLineEdit = QLineEdit()

        self.categoryLabel = QLabel("Category")
        self.categoryLineEdit = QLineEdit()

        self.layout.addWidget(self.presenterLabel, 2, 0, 1, 1)
        self.layout.addWidget(self.presenterLineEdit, 2, 1, 1, 1)
        self.layout.addWidget(self.categoryLabel, 2, 2, 1, 1)
        self.layout.addWidget(self.categoryLineEdit, 2, 3, 1, 1)

        self.eventLabel = QLabel("Event")
        self.eventLineEdit = QLineEdit()
        self.roomLabel = QLabel("Room")
        self.roomLineEdit = QLineEdit()

        self.layout.addWidget(self.eventLabel, 3, 0, 1, 1)
        self.layout.addWidget(self.eventLineEdit, 3, 1, 1, 1)
        self.layout.addWidget(self.roomLabel, 3, 2, 1, 1)
        self.layout.addWidget(self.roomLineEdit, 3, 3, 1, 1)

        self.dateLayout = QHBoxLayout()
        self.timeLayout = QHBoxLayout()
        self.dateLabel = QLabel("Date")
        self.dateEdit = QDateEdit()
        currentDate = QDate()
        self.dateEdit.setDate(currentDate.currentDate())
        self.dateEdit.setCalendarPopup(True)
        self.timeLabel = QLabel("Time")
        self.timeEdit = QTimeEdit()

        self.dateLayout.addWidget(self.dateEdit)
        self.timeLayout.addWidget(self.timeEdit)
        self.layout.addWidget(self.dateLabel, 4, 0, 1, 1)
        self.layout.addLayout(self.dateLayout, 4, 1, 1, 1)
        self.layout.addWidget(self.timeLabel, 4, 2, 1, 1)
        self.layout.addLayout(self.timeLayout, 4, 3, 1, 1)

        self.descriptionLabel = QLabel("Description")
        self.descriptionLabel.setAlignment(Qt.AlignTop)
        self.descriptionTextEdit = QPlainTextEdit()
        self.layout.addWidget(self.descriptionLabel, 5, 0, 1, 1)
        self.layout.addWidget(self.descriptionTextEdit, 5, 1, 1, 3)
示例#7
0
    def __init__(self, parent=None):
        super(TalkDetailsWidget, self).__init__(parent)

        self.layout = QGridLayout()
        self.setLayout(self.layout)

        self.buttonLayout = QHBoxLayout()

        saveIcon = QIcon.fromTheme("document-save")
        self.saveButton = QPushButton('Save Talk')
        self.saveButton.setIcon(saveIcon)
        self.buttonLayout.addWidget(self.saveButton)

        self.layout.addLayout(self.buttonLayout, 0, 1, 1, 1)

        self.titleLabel = QLabel('Title')
        self.titleLineEdit = QLineEdit()
        self.presenterLabel = QLabel('Presenter')
        self.presenterLineEdit = QLineEdit()
        self.layout.addWidget(self.titleLabel, 1, 0, 1, 1)
        self.layout.addWidget(self.titleLineEdit, 1, 1, 1, 1)
        self.layout.addWidget(self.presenterLabel, 1, 2, 1, 1)
        self.layout.addWidget(self.presenterLineEdit, 1, 3, 1, 1)

        self.eventLabel = QLabel('Event')
        self.eventLineEdit = QLineEdit()
        self.categoryLabel = QLabel('Category')
        self.categoryLineEdit = QLineEdit()

        self.layout.addWidget(self.eventLabel, 2, 0, 1, 1)
        self.layout.addWidget(self.eventLineEdit, 2, 1, 1, 1)
        self.layout.addWidget(self.categoryLabel, 2, 2, 1, 1)
        self.layout.addWidget(self.categoryLineEdit, 2, 3, 1, 1)

        self.roomLabel = QLabel('Room')
        self.roomLineEdit = QLineEdit()
        self.dateLayout = QHBoxLayout()
        self.dateLabel = QLabel('Date')
        self.dateEdit = QDateEdit()
        currentDate = QDate()
        self.dateEdit.setDate(currentDate.currentDate())
        self.dateEdit.setCalendarPopup(True)

        self.layout.addWidget(self.roomLabel, 3, 0, 1, 1)
        self.layout.addWidget(self.roomLineEdit, 3, 1, 1, 1)
        self.dateLayout.addWidget(self.dateEdit)
        self.layout.addWidget(self.dateLabel, 3, 2, 1, 1)
        self.layout.addLayout(self.dateLayout, 3, 3, 1, 1)

        self.startTimeLayout = QHBoxLayout()
        self.startTimeLabel = QLabel('Start Time')
        self.startTimeEdit = QTimeEdit()
        self.startTimeLayout.addWidget(self.startTimeEdit)
        self.endTimeLayout = QHBoxLayout()
        self.endTimeLabel = QLabel('End Time')
        self.endTimeEdit = QTimeEdit()
        self.endTimeLayout.addWidget(self.endTimeEdit)

        self.layout.addWidget(self.startTimeLabel, 4, 0, 1, 1)
        self.layout.addLayout(self.startTimeLayout, 4, 1, 1, 1)
        self.layout.addWidget(self.endTimeLabel, 4, 2, 1, 1)
        self.layout.addLayout(self.endTimeLayout, 4, 3, 1, 1)

        self.descriptionLabel = QLabel('Description')
        self.descriptionLabel.setAlignment(Qt.AlignTop)
        self.descriptionTextEdit = QPlainTextEdit()
        self.layout.addWidget(self.descriptionLabel, 5, 0, 1, 1)
        self.layout.addWidget(self.descriptionTextEdit, 5, 1, 1, 3)
示例#8
0
    def create_widget(self):
        """ Create the QTimeEdit widget.

        """
        self.widget = QTimeEdit(self.parent_widget())
示例#9
0
class TalkDetailsWidget(QWidget):
    def __init__(self, parent=None):
        super(TalkDetailsWidget, self).__init__(parent)

        self.layout = QGridLayout()
        self.setLayout(self.layout)

        self.buttonLayout = QHBoxLayout()

        addIcon = QIcon.fromTheme("list-add")
        self.addButton = QPushButton('Add New Talk')
        self.addButton.setIcon(addIcon)
        self.buttonLayout.addWidget(self.addButton)
        saveIcon = QIcon.fromTheme("document-save")
        self.saveButton = QPushButton('Save New Talk')
        self.saveButton.setIcon(saveIcon)
        self.buttonLayout.addWidget(self.saveButton)

        self.layout.addLayout(self.buttonLayout, 0, 1, 1, 1)

        self.titleLabel = QLabel('Title')
        self.titleLineEdit = QLineEdit()
        self.layout.addWidget(self.titleLabel, 1, 0, 1, 1)
        self.layout.addWidget(self.titleLineEdit, 1, 1, 1, 3)

        self.presenterLabel = QLabel('Presenter')
        self.presenterLineEdit = QLineEdit()

        self.categoryLabel = QLabel('Category')
        self.categoryLineEdit = QLineEdit()

        self.layout.addWidget(self.presenterLabel, 2, 0, 1, 1)
        self.layout.addWidget(self.presenterLineEdit, 2, 1, 1, 1)
        self.layout.addWidget(self.categoryLabel, 2, 2, 1, 1)
        self.layout.addWidget(self.categoryLineEdit, 2, 3, 1, 1)

        self.eventLabel = QLabel('Event')
        self.eventLineEdit = QLineEdit()
        self.roomLabel = QLabel('Room')
        self.roomLineEdit = QLineEdit()

        self.layout.addWidget(self.eventLabel, 3, 0, 1, 1)
        self.layout.addWidget(self.eventLineEdit, 3, 1, 1, 1)
        self.layout.addWidget(self.roomLabel, 3, 2, 1, 1)
        self.layout.addWidget(self.roomLineEdit, 3, 3, 1, 1)

        self.dateLayout = QHBoxLayout()
        self.timeLayout = QHBoxLayout()
        self.dateLabel = QLabel('Date')
        self.dateEdit = QDateEdit()
        currentDate = QDate()
        self.dateEdit.setDate(currentDate.currentDate())
        self.dateEdit.setCalendarPopup(True)
        self.timeLabel = QLabel('Time')
        self.timeEdit = QTimeEdit()

        self.dateLayout.addWidget(self.dateEdit)
        self.timeLayout.addWidget(self.timeEdit)
        self.layout.addWidget(self.dateLabel, 4, 0, 1, 1)
        self.layout.addLayout(self.dateLayout, 4, 1, 1, 1)
        self.layout.addWidget(self.timeLabel, 4, 2, 1, 1)
        self.layout.addLayout(self.timeLayout, 4, 3, 1, 1)

        self.descriptionLabel = QLabel('Description')
        self.descriptionLabel.setAlignment(Qt.AlignTop)
        self.descriptionTextEdit = QPlainTextEdit()
        self.layout.addWidget(self.descriptionLabel, 5, 0, 1, 1)
        self.layout.addWidget(self.descriptionTextEdit, 5, 1, 1, 3)

    def enable_input_fields(self):
        self.titleLineEdit.setPlaceholderText("Enter Talk Title")
        self.presenterLineEdit.setPlaceholderText("Enter Presenter Name")
        self.categoryLineEdit.setPlaceholderText("Enter Category Type")
        self.eventLineEdit.setPlaceholderText("Enter Event Name")
        self.roomLineEdit.setPlaceholderText("Enter Room Location")
        self.titleLineEdit.setEnabled(True)
        self.presenterLineEdit.setEnabled(True)
        self.categoryLineEdit.setEnabled(True)
        self.eventLineEdit.setEnabled(True)
        self.roomLineEdit.setEnabled(True)
        self.dateEdit.setEnabled(True)
        self.timeEdit.setEnabled(True)
        self.descriptionTextEdit.setEnabled(True)

    def disable_input_fields(self):
        self.titleLineEdit.setPlaceholderText("")
        self.presenterLineEdit.setPlaceholderText("")
        self.categoryLineEdit.setPlaceholderText("")
        self.eventLineEdit.setPlaceholderText("")
        self.roomLineEdit.setPlaceholderText("")
        self.titleLineEdit.setEnabled(False)
        self.presenterLineEdit.setEnabled(False)
        self.categoryLineEdit.setEnabled(False)
        self.eventLineEdit.setEnabled(False)
        self.roomLineEdit.setEnabled(False)
        self.dateEdit.setEnabled(False)
        self.timeEdit.setEnabled(False)
        self.descriptionTextEdit.setEnabled(False)
示例#10
0
class QtTimeSelector(QtBoundedTime, ProxyTimeSelector):
    """ A Qt implementation of an Enaml ProxyTimeSelector.

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

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

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

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

        """
        super(QtTimeSelector, self).init_widget()
        d = self.declaration
        self.set_time_format(d.time_format)
        self.widget.timeChanged.connect(self.on_time_changed)

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

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

        """
        return self.widget.time().toPyTime()

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

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

        """
        self.widget.setMinimumTime(time)

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

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

        """
        self.widget.setMaximumTime(time)

    def set_time(self, time):
        """ Set the widget's current time.

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

        """
        self._guard |= CHANGED_GUARD
        try:
            self.widget.setTime(time)
        finally:
            self._guard &= ~CHANGED_GUARD

    def set_time_format(self, format):
        """ Set the widget's time 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 __init__(self,
                 from_min_date=None, from_min_time=None,
                 from_max_date=None, from_max_time=None,
                 to_min_date=None, to_min_time=None,
                 to_max_date=None, to_max_time=None,
                 title='Define time range',
                 from_label='From',
                 to_label='To',
                 object_name='', parent=None, flags=0):
        QGroupBox.__init__(self)

        #members
        self.from_time = None  # QTime
        self.from_date = None  # QDate
        self.to_time = None  # QTime
        self.to_date = None  # QDate
        self.from_min_date = from_min_date  # QDate
        self.from_min_time = from_min_time  # QTime
        self.from_max_date = from_max_date  # QDate
        self.from_max_time = from_max_time  # QTime
        self.to_min_date = to_min_date  # QDate
        self.to_min_time = to_min_time  # QTime
        self.to_max_date = to_max_date  # QDate
        self.to_max_time = to_max_time  # QTime

        #private gui elements
        self._from_label = QLabel(from_label)
        self._from_date_le = QLineEdit()
        self._from_date_cw = self._make_cw()
        self._from_date_cw_btn = self._make_cw_button()
        self._from_time_te = QTimeEdit()
        self._to_label = QLabel(to_label)
        self._to_date_le = QLineEdit()
        self._to_date_cw = self._make_cw()
        self._to_date_cw_btn = self._make_cw_button()
        self._to_time_te = QTimeEdit()

        self.setTitle(title)
        self._setup_ui()

        # from time ranges and default
        if self.from_min_time is None or not self.from_min_time.isValid():
            self.from_min_time = QTime(0, 0, 0, 0)
        if self.from_max_time is None or not self.from_max_time.isValid():
            self.from_max_time = QTime(23, 59, 59, 999)
        self.from_time = self.from_min_time

        # to time ranges and default
        if self.to_min_time is None or not self.to_min_time.isValid():
            self.to_min_time = QTime(0, 0, 0, 0)
        if self.to_max_time is None or not self.to_max_time.isValid():
            self.to_max_time = QTime(23, 59, 59, 999)
        self.to_time = self.to_max_time

        # from date ranges and default
        if self.from_min_date is None or not self.from_min_date.isValid():
            self.from_min_date = QDate.fromJulianDay(1)
        if self.from_max_date is None or not self.from_max_date.isValid():
            self.from_max_date = QDate.fromJulianDay(sys.maxint)
        self.from_date = self.from_min_date

        # to date ranges and default
        if self.to_min_date is None or not self.to_min_date.isValid():
            self.to_min_date = QDate.fromJulianDay(1)
        if self.to_max_date is None or not self.to_max_date.isValid():
            self.to_max_date = QDate.fromJulianDay(sys.maxint)
        self.to_date = self.to_max_date

        #setup the connections
        self._from_date_cw.clicked.connect(self.set_from_date)
        self._to_date_cw.clicked.connect(self.set_to_date)
        self._from_time_te.timeChanged.connect(self.set_from_time)
        self._to_time_te.timeChanged.connect(self.set_to_time)

        self._update_state()
class AntiqueDatesWidget(QGroupBox):
    """Widget to allow selection of dates back to 4714 BCE and to to sometime
     in the year 11 million CE. The widget allows to use the full range of
     QDate
    see: http://qt-project.org/doc/qt-4.8/qdate.html#range-of-valid-dates

    If no values are passed, the allowed range for both from and to is the
    full range allowed by QDate.

    You can setup ranges directly at init time or you can pass new ranges
    using the various setters (set_from_min_date, set_to_min_date,
    set_from_max_time,...). For convenience you can also use the datetime
    setters and getters (set_from_min_datetime, get_to_max_datetime, ...)

    This widget insures that from_time is always before to_time

    usage from code:
        self.myWidget = AntiqueDatesWidget()
        self.myLayout.insertWidget(1, self.myWidget)
    usage from designer:
        insert a QGroupBox in your UI file
        optionally give a title to the QGroupBox
        promote it to AntiqueDatesWidget

    Known issues: when opening the calendar widget the first time, the
    widget is not placed 100% correctly. This is because the widget has
    initially no position. This is merely a visual issue.
    """

    def __init__(self,
                 from_min_date=None, from_min_time=None,
                 from_max_date=None, from_max_time=None,
                 to_min_date=None, to_min_time=None,
                 to_max_date=None, to_max_time=None,
                 title='Define time range',
                 from_label='From',
                 to_label='To',
                 object_name='', parent=None, flags=0):
        QGroupBox.__init__(self)

        #members
        self.from_time = None  # QTime
        self.from_date = None  # QDate
        self.to_time = None  # QTime
        self.to_date = None  # QDate
        self.from_min_date = from_min_date  # QDate
        self.from_min_time = from_min_time  # QTime
        self.from_max_date = from_max_date  # QDate
        self.from_max_time = from_max_time  # QTime
        self.to_min_date = to_min_date  # QDate
        self.to_min_time = to_min_time  # QTime
        self.to_max_date = to_max_date  # QDate
        self.to_max_time = to_max_time  # QTime

        #private gui elements
        self._from_label = QLabel(from_label)
        self._from_date_le = QLineEdit()
        self._from_date_cw = self._make_cw()
        self._from_date_cw_btn = self._make_cw_button()
        self._from_time_te = QTimeEdit()
        self._to_label = QLabel(to_label)
        self._to_date_le = QLineEdit()
        self._to_date_cw = self._make_cw()
        self._to_date_cw_btn = self._make_cw_button()
        self._to_time_te = QTimeEdit()

        self.setTitle(title)
        self._setup_ui()

        # from time ranges and default
        if self.from_min_time is None or not self.from_min_time.isValid():
            self.from_min_time = QTime(0, 0, 0, 0)
        if self.from_max_time is None or not self.from_max_time.isValid():
            self.from_max_time = QTime(23, 59, 59, 999)
        self.from_time = self.from_min_time

        # to time ranges and default
        if self.to_min_time is None or not self.to_min_time.isValid():
            self.to_min_time = QTime(0, 0, 0, 0)
        if self.to_max_time is None or not self.to_max_time.isValid():
            self.to_max_time = QTime(23, 59, 59, 999)
        self.to_time = self.to_max_time

        # from date ranges and default
        if self.from_min_date is None or not self.from_min_date.isValid():
            self.from_min_date = QDate.fromJulianDay(1)
        if self.from_max_date is None or not self.from_max_date.isValid():
            self.from_max_date = QDate.fromJulianDay(sys.maxint)
        self.from_date = self.from_min_date

        # to date ranges and default
        if self.to_min_date is None or not self.to_min_date.isValid():
            self.to_min_date = QDate.fromJulianDay(1)
        if self.to_max_date is None or not self.to_max_date.isValid():
            self.to_max_date = QDate.fromJulianDay(sys.maxint)
        self.to_date = self.to_max_date

        #setup the connections
        self._from_date_cw.clicked.connect(self.set_from_date)
        self._to_date_cw.clicked.connect(self.set_to_date)
        self._from_time_te.timeChanged.connect(self.set_from_time)
        self._to_time_te.timeChanged.connect(self.set_to_time)

        self._update_state()

    def set_from_date(self, date):
        if date.isValid():
            self.from_date = date
            self._update_state()
        else:
            raise InvalidDatetimeError('date %s is invalid' % date)

    def set_to_date(self, date):
        if date.isValid():
            self.to_date = date
            self._update_state()
        else:
            raise InvalidDatetimeError('date %s is invalid' % date)

    def set_from_time(self, time):
        if time.isValid():
            self.from_time = time
            self._update_state()
        else:
            raise InvalidDatetimeError('time %s is invalid' % time)

    def set_to_time(self, time):
        if time.isValid():
            self.to_time = time
            self._update_state()
        else:
            raise InvalidDatetimeError('time %s is invalid' % time)

    def set_from_min_date(self, date):
        if date.isValid():
            self.from_min_date = date
            self._update_state()
        else:
            raise InvalidDatetimeError('date %s is invalid' % date)
        
    def set_from_min_time(self, time):
        if time.isValid():
            self.from_min_time = time
            self._update_state()
        else:
            raise InvalidDatetimeError('time %s is invalid' % time)

    def set_from_max_date(self, date):
        if date.isValid():
            self.from_max_date = date
            self._update_state()
        else:
            raise InvalidDatetimeError('date %s is invalid' % date)

    def set_from_max_time(self, time):
        if time.isValid():
            self.from_max_time = time
            self._update_state()
        else:
            raise InvalidDatetimeError('time %s is invalid' % time)

    def set_to_min_date(self, date):
        if date.isValid():
            self.to_min_date = date
            self._update_state()
        else:
            raise InvalidDatetimeError('date %s is invalid' % date)

    def set_to_min_time(self, time):
        if time.isValid():
            self.to_min_time = time
            self._update_state()
        else:
            raise InvalidDatetimeError('time %s is invalid' % time)

    def set_to_max_date(self, date):
        if date.isValid():
            self.to_max_date = date
            self._update_state()
        else:
            raise InvalidDatetimeError('date %s is invalid' % date)

    def set_to_max_time(self, time):
        if time.isValid():
            self.to_max_time = time
            self._update_state()
        else:
            raise InvalidDatetimeError('time %s is invalid' % time)

    def set_from_min_datetime(self, datetime):
        self.from_min_date = datetime.date()
        self.from_min_time = datetime.time()

    def set_from_max_datetime(self, datetime):
        self.from_max_date = datetime.date()
        self.from_max_time = datetime.time()

    def set_to_min_datetime(self, datetime):
        self.to_min_date = datetime.date()
        self.to_min_time = datetime.time()

    def set_to_max_datetime(self, datetime):
        self.to_max_date = datetime.date()
        self.to_max_time = datetime.time()

    def get_from_min_datetime(self):
        return QDateTime(self.from_min_date, self.from_min_time)

    def get_from_max_datetime(self):
        return QDateTime(self.from_max_date, self.from_max_time)

    def get_to_min_datetime(self):
        return QDateTime(self.to_min_date, self.to_min_time)

    def get_to_max_datetime(self):
        return QDateTime(self.to_max_date, self.to_max_time)

    def _update_ranges(self):
        """Guarantees that from_datetime is always <= to_datetime"""
        self.from_max_date = self.to_date
        self.to_min_date = self.from_date

        if self.from_date == self.to_date:
            # in the one day scenario we need to force self.from_max_time to
            # be smaller than self.to_min_time
            self.from_max_time = self.to_time
            self.to_min_time = self.from_time

        self._from_time_te.setTimeRange(self.from_min_time, self.from_max_time)
        self._to_time_te.setTimeRange(self.to_min_time, self.to_max_time)
        self._from_date_cw.setDateRange(self.from_min_date, self.from_max_date)
        self._to_date_cw.setDateRange(self.to_min_date, self.to_max_date)

    def _update_state(self):
        """Update the ranges and the reflect it in the GUI"""
        self._update_ranges()
        self._from_time_te.setTime(self.from_time)
        self._to_time_te.setTime(self.to_time)
        self._from_date_le.setText(self.from_date.toString())
        self._to_date_le.setText(self.to_date.toString())

    def _setup_ui(self):
        self._from_date_le.setEnabled(False)
        self._to_date_le.setEnabled(False)

        layout = QHBoxLayout(self)
        grid_layout = QGridLayout(self)
        grid_layout.addWidget(self._from_label, 0, 0)
        grid_layout.addWidget(self._from_date_le, 0, 1)
        grid_layout.addWidget(self._from_date_cw_btn, 0, 2)
        grid_layout.addWidget(self._from_time_te, 0, 3)
        grid_layout.addWidget(self._to_label, 1, 0)
        grid_layout.addWidget(self._to_date_le, 1, 1)
        grid_layout.addWidget(self._to_date_cw_btn, 1, 2)
        grid_layout.addWidget(self._to_time_te, 1, 3)

        layout.addLayout(grid_layout)
        self._retranslate_ui()

        self._from_date_cw_btn.toggled.connect(
            lambda checked: self._toggle_cw(checked, self._from_date_cw))
        self._to_date_cw_btn.toggled.connect(
            lambda checked: self._toggle_cw(checked, self._to_date_cw))

    def _retranslate_ui(self):
        self._from_time_te.setDisplayFormat(
            _translate("self", "hh:mm:ss", None))
        self._to_time_te.setDisplayFormat(
            _translate("self", "hh:mm:ss", None))
        self._from_label.setText(_translate("self", "From", None))
        self._to_label.setText(_translate("self", "To", None))

    def _toggle_cw(self, checked, cw):
        if checked:
            #disable the other calendar
            if cw == self._from_date_cw:
                self._to_date_cw_btn.setChecked(False)
                pos = self._from_date_cw_btn.pos()
            else:
                self._from_date_cw_btn.setChecked(False)
                pos = self._to_date_cw_btn.pos()

            pos = self.mapToGlobal(pos)
            margin = 20
            cw_width = cw.width() + margin
            #enable this calendar
            cw.show()
            cw.setFocus(Qt.PopupFocusReason)
            cw.move(pos.x() - cw_width, pos.y())
        else:
            cw.close()

    def _close_cw(self, cw):
        if cw == self._from_date_cw:
            self._from_date_cw_btn.setChecked(False)
        else:
            self._to_date_cw_btn.setChecked(False)
        cw.close()

    def _make_cw(self):
        cw = QCalendarWidget()
        cw.setWindowFlags(cw.windowFlags() |
                          Qt.Tool |
                          Qt.FramelessWindowHint |
                          Qt.WindowStaysOnTopHint)
        #geom = cw.geometry()
        #cw.setGeometry(20, 20, geom.width(), geom.height())
        cw.activated.connect(lambda: self._close_cw(cw))
        return cw

    @staticmethod
    def _make_cw_button():
        btn = QToolButton()
        btn.setIcon(QIcon.fromTheme('x-office-calendar'))
        btn.setCheckable(True)
        return btn
示例#13
0
    def __init__(self, parent=None):
        '''
        Constructor
        '''
        QWidget.__init__(self, parent)
        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        self.addTalkGroupBox = QGroupBox("Add Talk")
        self.mainLayout.addWidget(self.addTalkGroupBox)

        self.addTalkLayout = QFormLayout()
        self.addTalkGroupBox.setLayout(self.addTalkLayout)

        # Title
        self.titleLabel = QLabel("Title")
        self.titleLineEdit = QLineEdit()
        if hasattr(QLineEdit(), 'setPlaceholderText'):
            self.titleLineEdit.setPlaceholderText("Title of the presentation")
        self.titleLabel.setBuddy(self.titleLineEdit)
        self.addTalkLayout.addRow(self.titleLabel, self.titleLineEdit)

        # Presenter
        self.presenterLabel = QLabel("Presenter")
        self.presenterLineEdit = QLineEdit()
        if hasattr(QLineEdit(), 'setPlaceholderText'):
            self.presenterLineEdit.setPlaceholderText(
                "Name person or people presenting (comma separated)")
        self.presenterLabel.setBuddy(self.presenterLineEdit)
        self.addTalkLayout.addRow(self.presenterLabel, self.presenterLineEdit)

        # Event
        self.eventLabel = QLabel("Event")
        self.eventLineEdit = QLineEdit()
        if hasattr(QLineEdit(), 'setPlaceholderText'):
            self.eventLineEdit.setPlaceholderText(
                "The name of the Event this talk is being presented at")
        self.eventLabel.setBuddy(self.eventLineEdit)
        self.addTalkLayout.addRow(self.eventLabel, self.eventLineEdit)

        # Room
        self.roomLabel = QLabel("Room")
        self.roomLineEdit = QLineEdit()
        if hasattr(QLineEdit(), 'setPlaceholderText'):
            self.roomLineEdit.setPlaceholderText(
                "The Room in which the presentation is taking place")
        self.roomLabel.setBuddy(self.roomLineEdit)
        self.addTalkLayout.addRow(self.roomLabel, self.roomLineEdit)

        # Date
        current_date = QDate()
        self.dateLabel = QLabel("Date")
        self.dateEdit = QDateEdit()
        self.dateEdit.setDate(current_date.currentDate())
        self.dateLabel.setBuddy(self.dateEdit)
        self.addTalkLayout.addRow(self.dateLabel, self.dateEdit)

        self.dateEdit.setCalendarPopup(True)

        # Time
        current_time = QTime()
        self.timeLabel = QLabel("Time")
        self.timeEdit = QTimeEdit()
        self.timeEdit.setTime(current_time.currentTime())
        self.timeLabel.setBuddy(self.dateEdit)
        self.addTalkLayout.addRow(self.timeLabel, self.timeEdit)

        # Buttons
        addIcon = QIcon.fromTheme("list-add")
        cancelIcon = QIcon.fromTheme("edit-clear")

        self.buttonsWidget = QHBoxLayout()
        self.addButton = QPushButton("Add")
        self.addButton.setIcon(addIcon)
        self.cancelButton = QPushButton("Cancel")
        self.cancelButton.setIcon(cancelIcon)
        self.buttonsWidget.addWidget(self.addButton)
        self.buttonsWidget.addWidget(self.cancelButton)
        self.addTalkLayout.addRow(None, self.buttonsWidget)
示例#14
0
class TalkDetailsWidget(QWidget):

    def __init__(self, parent=None):
        super(TalkDetailsWidget, self).__init__(parent)

        self.layout = QGridLayout()
        self.setLayout(self.layout)

        self.buttonLayout = QHBoxLayout()

        saveIcon = QIcon.fromTheme("document-save")
        self.saveButton = QPushButton('Save Talk')
        self.saveButton.setIcon(saveIcon)
        self.buttonLayout.addWidget(self.saveButton)

        self.layout.addLayout(self.buttonLayout, 0, 1, 1, 1)

        self.titleLabel = QLabel('Title')
        self.titleLineEdit = QLineEdit()
        self.presenterLabel = QLabel('Presenter')
        self.presenterLineEdit = QLineEdit()
        self.layout.addWidget(self.titleLabel, 1, 0, 1, 1)
        self.layout.addWidget(self.titleLineEdit, 1, 1, 1, 1)
        self.layout.addWidget(self.presenterLabel, 1, 2, 1, 1)
        self.layout.addWidget(self.presenterLineEdit, 1, 3, 1, 1)

        self.eventLabel = QLabel('Event')
        self.eventLineEdit = QLineEdit()
        self.categoryLabel = QLabel('Category')
        self.categoryLineEdit = QLineEdit()

        self.layout.addWidget(self.eventLabel, 2, 0, 1, 1)
        self.layout.addWidget(self.eventLineEdit, 2, 1, 1, 1)
        self.layout.addWidget(self.categoryLabel, 2, 2, 1, 1)
        self.layout.addWidget(self.categoryLineEdit, 2, 3, 1, 1)

        self.roomLabel = QLabel('Room')
        self.roomLineEdit = QLineEdit()
        self.dateLayout = QHBoxLayout()
        self.dateLabel = QLabel('Date')
        self.dateEdit = QDateEdit()
        currentDate = QDate()
        self.dateEdit.setDate(currentDate.currentDate())
        self.dateEdit.setCalendarPopup(True)

        self.layout.addWidget(self.roomLabel, 3, 0, 1, 1)
        self.layout.addWidget(self.roomLineEdit, 3, 1, 1, 1)
        self.dateLayout.addWidget(self.dateEdit)
        self.layout.addWidget(self.dateLabel, 3, 2, 1, 1)
        self.layout.addLayout(self.dateLayout, 3, 3, 1, 1)

        self.startTimeLayout = QHBoxLayout()
        self.startTimeLabel = QLabel('Start Time')
        self.startTimeEdit = QTimeEdit()
        self.startTimeLayout.addWidget(self.startTimeEdit)
        self.endTimeLayout = QHBoxLayout()
        self.endTimeLabel = QLabel('End Time')
        self.endTimeEdit = QTimeEdit()
        self.endTimeLayout.addWidget(self.endTimeEdit)

        self.layout.addWidget(self.startTimeLabel, 4, 0, 1, 1)
        self.layout.addLayout(self.startTimeLayout, 4, 1, 1, 1)
        self.layout.addWidget(self.endTimeLabel, 4, 2, 1, 1)
        self.layout.addLayout(self.endTimeLayout, 4, 3, 1, 1)

        self.descriptionLabel = QLabel('Description')
        self.descriptionLabel.setAlignment(Qt.AlignTop)
        self.descriptionTextEdit = QPlainTextEdit()
        self.layout.addWidget(self.descriptionLabel, 5, 0, 1, 1)
        self.layout.addWidget(self.descriptionTextEdit, 5, 1, 1, 3)

    def enable_input_fields(self):
            self.titleLineEdit.setPlaceholderText("Enter Talk Title")
            self.presenterLineEdit.setPlaceholderText("Enter Presenter Name")
            self.categoryLineEdit.setPlaceholderText("Enter Category Type")
            self.eventLineEdit.setPlaceholderText("Enter Event Name")
            self.roomLineEdit.setPlaceholderText("Enter Room Location")
            self.titleLineEdit.setEnabled(True)
            self.presenterLineEdit.setEnabled(True)
            self.categoryLineEdit.setEnabled(True)
            self.eventLineEdit.setEnabled(True)
            self.roomLineEdit.setEnabled(True)
            self.dateEdit.setEnabled(True)
            self.startTimeEdit.setEnabled(True)
            self.endTimeEdit.setEnabled(True)
            self.descriptionTextEdit.setEnabled(True)

    def disable_input_fields(self):
            self.titleLineEdit.setPlaceholderText("")
            self.presenterLineEdit.setPlaceholderText("")
            self.categoryLineEdit.setPlaceholderText("")
            self.eventLineEdit.setPlaceholderText("")
            self.roomLineEdit.setPlaceholderText("")
            self.titleLineEdit.setEnabled(False)
            self.presenterLineEdit.setEnabled(False)
            self.categoryLineEdit.setEnabled(False)
            self.eventLineEdit.setEnabled(False)
            self.roomLineEdit.setEnabled(False)
            self.dateEdit.setEnabled(False)
            self.startTimeEdit.setEnabled(False)
            self.endTimeEdit.setEnabled(False)
            self.descriptionTextEdit.setEnabled(False)

    def clear_input_fields(self):
            self.titleLineEdit.clear()
            self.presenterLineEdit.clear()
            self.categoryLineEdit.clear()
            self.eventLineEdit.clear()
            self.roomLineEdit.clear()
            self.descriptionTextEdit.clear()