Пример #1
0
 def minimum( self ):
     """
     Returns the minimum value for this ruler.  If the cached value is None,
     then a default value will be specified based on the ruler type.
     
     :return     <variant>
     """
     if ( self._minimum is not None ):
         return self._minimum
     
     rtype = self.rulerType()
     
     if ( rtype == XChartRuler.Type.Number ):
         self._minimum = 0
         
     elif ( rtype == XChartRuler.Type.Date ):
         self._minimum = QDate.currentDate()
     
     elif ( rtype == XChartRuler.Type.Datetime ):
         self._minimum = QDateTime.currentDateTime()
     
     elif ( rtype == XChartRuler.Type.Time ):
         self._minimum = QDateTime.currentDateTime().time()
     
     else:
         notches = self.notches()
         if ( notches ):
             self._minimum = notches[0]
     
     return self._minimum
Пример #2
0
 def datetimeXPos(self, dtime):
     """
     Returns the x-position for the inputed date time.
     
     :return     <float>
     """
     gantt = self.ganttWidget()
     scale = gantt.timescale()
     
     # calculate the distance for a minute
     if scale == gantt.Timescale.Minute:
         dstart = gantt.dateTimeStart()
         secs = dstart.secsTo(dtime)
         return secs
     
     # calculate the distance for an hour
     elif scale == gantt.Timescale.Hour:
        dstart = gantt.dateTimeStart()
        secs = dstart.secsTo(dtime)
        return secs / 2.0
     
     # calculate the distance for a day
     elif scale == gantt.Timescale.Day:
         dstart = QDateTime(gantt.dateStart(), QTime(0, 0, 0))
         secs = dstart.secsTo(dtime)
         return (secs / (60.0 * 2.0))
     
     # calculate the distance off the date only
     else:
         return self.dateXPos(dtime.date())
Пример #3
0
    def datetimeAt(self, x):
        """
        Returns the datetime at the inputed x position.
        
        :return     <QDateTime>
        """
        gantt = self.ganttWidget()
        dstart = gantt.dateTimeStart()
        distance = int(x / float(gantt.cellWidth()))
        
        # calculate the time for a minute
        if scale == gantt.Timescale.Minute:
            return dstart.addSecs(distance)
        
        # calculate the time for an hour
        elif scale == gantt.Timescale.Hour:
            return dstart.addSecs(distance * 2.0)

        # calculate the time for a day
        elif scale == gantt.Timescale.Day:
            dstart = QDateTime(gantt.dateStart(), QTime(0, 0, 0))
            return dstart.addSecs(distance * (60 * 2.0))
        
        # calculate the time off the date only
        else:
            date = self.dateAt(x)
            return QDateTime(date, QTime(0, 0, 0))
Пример #4
0
    def minimum(self):
        """
        Returns the minimum value for this ruler.  If the cached value is None,
        then a default value will be specified based on the ruler type.
        
        :return     <variant>
        """
        if (self._minimum is not None):
            return self._minimum

        rtype = self.rulerType()

        if (rtype == XChartRuler.Type.Number):
            self._minimum = 0

        elif (rtype == XChartRuler.Type.Date):
            self._minimum = QDate.currentDate()

        elif (rtype == XChartRuler.Type.Datetime):
            self._minimum = QDateTime.currentDateTime()

        elif (rtype == XChartRuler.Type.Time):
            self._minimum = QDateTime.currentDateTime().time()

        else:
            notches = self.notches()
            if (notches):
                self._minimum = notches[0]

        return self._minimum
Пример #5
0
 def dateTimeAt( self, point ):
     """
     Returns the date time at the inputed point.
     
     :param      point | <QPoint>
     """
     for dtime, data in self._dateTimeGrid.items():
         if ( data[1].contains(point) ):
             return QDateTime.fromTime_t(dtime)
     return QDateTime()
Пример #6
0
 def dateTimeStart(self):
     """
     Returns the start date time for this gantt chart.
     
     :return     <QDateTime>
     """
     return QDateTime(self.dateStart(), self.timeStart())
Пример #7
0
 def dateTimeEnd(self):
     """
     Returns the end date time for this gantt chart.
     
     :return     <QDateTime>
     """
     return QDateTime(self.dateEnd(), self.timeEnd())
Пример #8
0
 def dateTimeStart(self):
     """
     Returns a merging of data from the date end with the date start.
     
     :return     <QDateTime>
     """
     return QDateTime(self.dateStart(), self.timeStart())
Пример #9
0
 def dateTimeEnd(self):
     """
     Returns a merging of data from the date end with the time end.
     
     :return     <QDateTime>
     """
     return QDateTime(self.dateEnd(), self.timeEnd())
Пример #10
0
 def __init__( self ):
     super(XCalendarItem, self).__init__()
     
     curr_dtime = QDateTime.currentDateTime()
     curr_date  = curr_dtime.date()
     curr_time  = curr_dtime.time()
     
     self.setFlags(self.flags() | self.ItemIsSelectable)
     self.setAcceptHoverEvents(True)
     
     # round to the nearest 15 minute segment
     curr_time = QTime(curr_time.hour(),
                       curr_time.minute() - curr_time.minute() % 30,
                       0)
     
     self._rebuildBlocked = False
     self._textData   = []
     
     self._customData        = {}
     self._textColor         = QColor('white')
     self._fillColor         = QColor('blue')
     self._borderColor       = QColor('blue')
     self._highlightColor    = QColor('blue')
     
     self._title             = 'No Title'
     self._description       = ''
     self._dateStart         = curr_date
     self._dateEnd           = curr_date
     self._timeStart         = curr_time
     self._timeEnd           = curr_time.addSecs(60 * 60)
     self._allDay            = True
     self._rebuildRequired   = False
     
     if ( QTime(23, 0, 0) <= self._timeStart ):
         self._timeEnd       = QTime(23, 59, 0)
     
     self.setColor('blue')
Пример #11
0
    def __init__(self):
        super(XCalendarItem, self).__init__()

        curr_dtime = QDateTime.currentDateTime()
        curr_date = curr_dtime.date()
        curr_time = curr_dtime.time()

        self.setFlags(self.flags() | self.ItemIsSelectable)
        self.setAcceptHoverEvents(True)

        # round to the nearest 15 minute segment
        curr_time = QTime(curr_time.hour(),
                          curr_time.minute() - curr_time.minute() % 30, 0)

        self._rebuildBlocked = False
        self._textData = []

        self._customData = {}
        self._textColor = QColor('white')
        self._fillColor = QColor('blue')
        self._borderColor = QColor('blue')
        self._highlightColor = QColor('blue')

        self._title = 'No Title'
        self._description = ''
        self._dateStart = curr_date
        self._dateEnd = curr_date
        self._timeStart = curr_time
        self._timeEnd = curr_time.addSecs(60 * 60)
        self._allDay = True
        self._rebuildRequired = False

        if (QTime(23, 0, 0) <= self._timeStart):
            self._timeEnd = QTime(23, 59, 0)

        self.setColor('blue')
Пример #12
0
    def rebuildDay(self):
        """
        Rebuilds the current item in day mode.
        """
        scene = self.scene()
        if (not scene):
            return

        # calculate the base information
        start_date = self.dateStart()
        end_date = self.dateEnd()
        min_date = scene.minimumDate()
        max_date = scene.maximumDate()

        # make sure our item is visible
        if (not (min_date <= end_date and start_date <= max_date)):
            self.hide()
            self.setPath(QPainterPath())
            return

        # make sure we have valid range information
        if (start_date < min_date):
            start_date = min_date
            start_inrange = False
        else:
            start_inrange = True

        if (max_date < end_date):
            end_date = max_date
            end_inrange = False
        else:
            end_inrange = True

        # rebuild the path
        path = QPainterPath()
        self.setPos(0, 0)

        pad = 2
        offset = 18
        height = 16

        # rebuild a timed item
        if (not self.isAllDay()):
            start_dtime = QDateTime(self.dateStart(), self.timeStart())
            end_dtime = QDateTime(self.dateStart(),
                                  self.timeEnd().addSecs(-30 * 60))

            start_rect = scene.dateTimeRect(start_dtime)
            end_rect = scene.dateTimeRect(end_dtime)

            left = start_rect.left() + pad
            top = start_rect.top() + pad
            right = start_rect.right() - pad
            bottom = end_rect.bottom() - pad

            path.moveTo(left, top)
            path.lineTo(right, top)
            path.lineTo(right, bottom)
            path.lineTo(left, bottom)
            path.lineTo(left, top)

            data = (left + 6, top + 6, right - left - 12, bottom - top - 12,
                    Qt.AlignTop | Qt.AlignLeft, '%s - %s\n(%s)' %
                    (self.timeStart().toString('h:mmap')[:-1],
                     self.timeEnd().toString('h:mmap'), self.title()))

            self._textData.append(data)

        self.setPath(path)
        self.show()
Пример #13
0
 def setValue(self, value):
     self.setDateTime(QDateTime(value))
Пример #14
0
 def rebuildDays( self ):
     """
     Rebuilds the interface as a week display.
     """
     time = QTime(0, 0, 0)
     hour = True
     
     x = 6
     y = 6 + 24
     
     w = self.width() - 12 - 25
     
     dh         = 48
     indent     = 58
     text_data  = []
     
     vlines      = []
     hlines      = [QLine(x, y, w, y)]
     time_grids  = []
     
     for i in range(48):
         if ( hour ):
             hlines.append(QLine(x, y, w, y))
             text_data.append((x,
                               y + 6, 
                               indent - 6, 
                               dh, 
                               Qt.AlignRight | Qt.AlignTop,
                               time.toString('hap')))
         else:
             hlines.append(QLine(x + indent, y, w, y))
         
         time_grids.append((time, y, dh / 2))
         
         # move onto the next line
         hour = not hour
         time = time.addSecs(30 * 60)
         y += dh / 2
     
     hlines.append(QLine(x, y, w, y))
     
     h = y
     y = 6 + 24
     
     # load the grid
     vlines.append(QLine(x, y, x, h))
     vlines.append(QLine(x + indent, y, x + indent, h))
     vlines.append(QLine(w, y, w, h))
     
     today     = QDate.currentDate()
     curr_date = self.currentDate()
     
     # load the days
     if ( self.currentMode() == XCalendarScene.Mode.Week ):
         date = self.currentDate()
         day_of_week = date.dayOfWeek()
         if ( day_of_week == 7 ):
             day_of_week = 0
         
         min_date = date.addDays(-day_of_week)
         max_date = date.addDays(6-day_of_week)
         
         self._minimumDate = min_date
         self._maximumDate = max_date
         
         dw    = (w - (x + indent)) / 7.0
         vx    = x + indent
         date  = min_date
         
         for i in range(7):
             vlines.append(QLine(vx, y, vx, h))
             
             text_data.append((vx + 6,
                               6,
                               dw,
                               24,
                               Qt.AlignCenter,
                               date.toString('ddd MM/dd')))
             
             self._dateGrid[date.toJulianDay()] = ((0, i),
                                                   QRectF(vx, y, dw, h - y))
             
             # create the date grid for date time options
             for r, data in enumerate(time_grids):
                 time, ty, th = data
                 dtime = QDateTime(date, time)
                 key = dtime.toTime_t()
                 self._dateTimeGrid[key] = ((r, i), QRectF(vx, ty, dw, th))
             
             if ( date == curr_date ):
                 self._buildData['curr_date'] = QRectF(vx, y, dw, h - 29)
             elif ( date == today ):
                 self._buildData['today'] = QRectF(vx, y, dw, h - 29)
             
             date = date.addDays(1)
             vx += dw
     
     # load a single day
     else:
         date = self.currentDate()
         
         self._maximumDate = date
         self._minimumDate = date
         
         text_data.append((x + indent,
                           6,
                           w,
                           24,
                           Qt.AlignCenter,
                           date.toString('ddd MM/dd')))
         
         self._dateGrid[date.toJulianDay()] = ((0, 0), 
                                               QRectF(x, y, w - x, h - y))
         
         # create the date grid for date time options
         for r, data in enumerate(time_grids):
             time, ty, th = data
             dtime = QDateTime(date, time)
             key = dtime.toTime_t()
             rect = QRectF(x + indent, ty, w - (x + indent), th)
             self._dateTimeGrid[key] = ((r, 0), rect)
     
     self._buildData['grid'] = hlines + vlines
     self._buildData['regular_text'] = text_data
     
     rect = self.sceneRect()
     rect.setHeight(h + 6)
     
     super(XCalendarScene, self).setSceneRect(rect)
Пример #15
0
 def rebuildDay(self, opt):
     """
     Rebuilds the scale for the day mode.
     
     :param      opt | <XGanttRenderOptions>
     """
     self._labels            = []
     self._hlines            = []
     self._vlines            = []
     self._weekendRects      = []
     self._alternateRects    = []
     self._topLabels         = []
     
     top_format = 'dddd MMMM dd'
     label_format = 'ha'
     increment = 60 # hour
     
     # generate vertical lines
     x           = 0
     i           = 0
     half        = opt.header_height / 2.0
     curr        = QDateTime(opt.start, QTime(0, 0, 0))
     end         = QDateTime(opt.end, QTime(23, 0, 0))
     top_label   = opt.start.toString(top_format)
     top_rect    = QRect(0, 0, 0, half)
     alt_rect    = None
     
     while curr <= end:
         # update the top rect
         new_top_label = curr.toString(top_format)
         if new_top_label != top_label:
             top_rect.setRight(x)
             self._topLabels.append((top_rect, top_label))
             top_rect  = QRect(x, 0, 0, half)
             top_label = new_top_label
             
             if alt_rect is not None:
                 alt_rect.setRight(x)
                 self._alternateRects.append(alt_rect)
                 alt_rect = None
             else:
                 alt_rect = QRect(x, 0, 0, opt.height)
         
         # create the line
         self._hlines.append(QLine(x, 0, x, opt.height))
         
         # create the header label/rect
         label = nativestring(curr.toString(label_format))[:-1]
         rect  = QRect(x, half, opt.cell_width, half)
         self._labels.append((rect, label))
         
         # increment the dates
         curr = curr.addSecs(increment * 60)
         x += opt.cell_width
         i += 1
     
     # update the top rect
     top_rect.setRight(x)
     top_label = opt.end.toString(top_format)
     self._topLabels.append((top_rect, top_label))
     
     if alt_rect is not None:
         alt_rect.setRight(x)
         self._alternateRects.append(alt_rect)
     
     # resize the width to match the last date range
     new_width = x
     self.setSceneRect(0, 0, new_width, opt.height)
     
     # generate horizontal lines
     y       = 0
     h       = opt.height
     width   = new_width
     
     while y < h:
         self._vlines.append(QLine(0, y, width, y))
         y += opt.cell_height
     
     # clear the dirty flag
     self._dirty = False
Пример #16
0
 def __init__(self, parent=None):
     super(XDateTimeEdit, self).__init__(parent)
     
     # define custom properties
     self.setCalendarPopup(True)
     self.setDateTime(QDateTime.currentDateTime())
Пример #17
0
    def __init__(self, parent=None):
        super(XDateTimeEdit, self).__init__(parent)

        # define custom properties
        self.setCalendarPopup(True)
        self.setDateTime(QDateTime.currentDateTime())