def dateAt( self, point ): """ Returns the date at the given point. :param point | <QPoint> """ for date, data in self._dateGrid.items(): if ( data[1].contains(point) ): return QDate.fromJulianDay(date) return QDate()
def __init__( self, parent = None ): super(XCalendarScene, self).__init__( parent ) # define custom properties self._currentDate = QDate.currentDate() self._currentMode = XCalendarScene.Mode.Month self._timelineScale = XCalendarScene.TimelineScale.Week self._minimumDate = QDate() self._maximumDate = QDate() self._dateGrid = {} self._dateTimeGrid = {} self._buildData = {} self._rebuildRequired = False
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
def setDateStart( self, dateStart ): """ Sets the start date for this item. This will automatically push the end date to match the duration for this item. So if the item starts on 1/1/12 and ends on 1/2/12, and the start date is changed to 2/1/12, the end date will change to 2/2/12. To affect the duration of the item, use either setDuration, or setDateEnd. :param dateStart | <QDate> """ dateStart = QDate(dateStart) duration = self.duration() self._dateStart = dateStart self._dateEnd = dateStart.addDays(duration - 1) self.markForRebuild()
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
def setDateStart(self, dateStart): """ Sets the start date for this item. This will automatically push the end date to match the duration for this item. So if the item starts on 1/1/12 and ends on 1/2/12, and the start date is changed to 2/1/12, the end date will change to 2/2/12. To affect the duration of the item, use either setDuration, or setDateEnd. :param dateStart | <QDate> """ dateStart = QDate(dateStart) duration = self.duration() self._dateStart = dateStart self._dateEnd = dateStart.addDays(duration - 1) self.markForRebuild()
def setTimescale( self, timescale ): """ Sets the timescale value for this widget to the inputed value. :param timescale | <XGanttWidget.Timescale> """ self._timescale = timescale # show hour/minute scale if timescale == XGanttWidget.Timescale.Minute: self._cellWidth = 60 # (60 seconds) self._dateStart = QDate.currentDate() self._timeStart = QTime(0, 0, 0) self._dateEnd = QDate.currentDate() self._timeEnd = QTime(23, 59, 59) elif timescale == XGanttWidget.Timescale.Hour: self._cellWidth = 30 # (60 seconds / 2.0) self._dateStart = QDate.currentDate() self._timeStart = QTime(0, 0, 0) self._dateEnd = QDate.currentDate() self._timeEnd = QTime(23, 59, 59) # show day/hour scale elif timescale == XGanttWidget.Timescale.Day: self._cellWidth = 30 # (60 minutes / 2.0) self._dateStart = QDate.currentDate().addDays(-7) self._timeStart = QTime(0, 0, 0) self._dateEnd = QDate.currentDate().addDays(7) self._timeEnd = QTime(23, 59, 59)
def setTimescale(self, timescale): """ Sets the timescale value for this widget to the inputed value. :param timescale | <XGanttWidget.Timescale> """ self._timescale = timescale # show hour/minute scale if timescale == XGanttWidget.Timescale.Minute: self._cellWidth = 60 # (60 seconds) self._dateStart = QDate.currentDate() self._timeStart = QTime(0, 0, 0) self._dateEnd = QDate.currentDate() self._timeEnd = QTime(23, 59, 59) elif timescale == XGanttWidget.Timescale.Hour: self._cellWidth = 30 # (60 seconds / 2.0) self._dateStart = QDate.currentDate() self._timeStart = QTime(0, 0, 0) self._dateEnd = QDate.currentDate() self._timeEnd = QTime(23, 59, 59) # show day/hour scale elif timescale == XGanttWidget.Timescale.Day: self._cellWidth = 30 # (60 minutes / 2.0) self._dateStart = QDate.currentDate().addDays(-7) self._timeStart = QTime(0, 0, 0) self._dateEnd = QDate.currentDate().addDays(7) self._timeEnd = QTime(23, 59, 59)
def __init__(self, ganttWidget): super(XGanttWidgetItem, self).__init__() # set default properties self.setFixedHeight(ganttWidget.cellHeight()) for i in range(1, 20): self.setTextAlignment(i, Qt.AlignCenter) # define custom properties self._blockedAdjustments = {} self._viewItem = self.createViewItem() self._dateStart = QDate.currentDate() self._dateEnd = QDate.currentDate() self._allDay = True self._timeStart = QTime(0, 0, 0) self._timeEnd = QTime(23, 59, 59) self._name = '' self._properties = {} self._itemStyle = XGanttWidgetItem.ItemStyle.Normal self._useGroupStyleWithChildren = True self._dependencies = {} self._reverseDependencies = {}
def rebuild( self ): """ Rebuilds the information for this scene. """ self._buildData.clear() self._dateGrid.clear() self._dateTimeGrid.clear() curr_min = self._minimumDate curr_max = self._maximumDate self._maximumDate = QDate() self._minimumDate = QDate() self.markForRebuild(False) # rebuilds the month view if ( self.currentMode() == XCalendarScene.Mode.Month ): self.rebuildMonth() elif ( self.currentMode() in (XCalendarScene.Mode.Week, XCalendarScene.Mode.Day)): self.rebuildDays() # rebuild the items in the scene items = sorted(self.items()) for item in items: item.setPos(0, 0) item.hide() for item in items: if ( isinstance(item, XCalendarItem) ): item.rebuild() if ( curr_min != self._minimumDate or curr_max != self._maximumDate ): parent = self.parent() if ( parent and not parent.signalsBlocked() ): parent.dateRangeChanged.emit(self._minimumDate, self._maximumDate)
def setDateEnd(self, dateEnd): """ Sets the end date for this item. This method will only affect the start date if the end date is set to occur before its start, in which case it will set the start date as the same date. (1 day duration) Otherwise, this method will scale the duration of the event. :param dateEnd | <QDate> """ dateEnd = QDate(dateEnd) if (dateEnd < self._dateStart): self._dateStart = dateEnd self._dateEnd = dateEnd self.markForRebuild()
def gotoToday( self ): """ Goes to today as the current date. """ self.scene().setCurrentDate(QDate.currentDate())
def gotoToday(self): """ Goes to today as the current date. """ self.scene().setCurrentDate(QDate.currentDate())
def __init__(self, parent=None): super(XGanttWidget, self).__init__(parent) # load the user interface projexui.loadUi(__file__, self) # define custom properties self._backend = None self._dateStart = QDate.currentDate().addMonths(-2) self._dateEnd = QDate.currentDate().addMonths(2) self._timeStart = QTime(0, 0, 0) self._timeEnd = QTime(23, 59, 59) self._alternatingRowColors = False self._cellWidth = 20 self._cellHeight = 20 self._first = True self._dateFormat = 'M/d/yy' self._timescale = XGanttWidget.Timescale.Month self._scrolling = False self._dirty = False # setup the palette colors palette = self.palette() color = palette.color(palette.Base) self._gridPen = QPen(color.darker(115)) self._brush = QBrush(color) self._alternateBrush = QBrush(color.darker(105)) weekendColor = color.darker(108) self._weekendBrush = QBrush(weekendColor) # setup the columns for the tree self.setColumns(['Name', 'Start', 'End', 'Calendar Days', 'Work Days']) header = self.uiGanttTREE.header() header.setFixedHeight(self._cellHeight * 2) headerItem = self.uiGanttTREE.headerItem() headerItem.setSizeHint(0, QSize(80, header.height())) # initialize the tree widget self.uiGanttTREE.setShowGrid(False) self.uiGanttTREE.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.uiGanttTREE.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.uiGanttTREE.setVerticalScrollMode(self.uiGanttTREE.ScrollPerPixel) self.uiGanttTREE.setResizeToContentsInteractive(True) self.uiGanttTREE.setEditable(True) self.uiGanttTREE.resize(500, 20) self.uiGanttTREE.setContextMenuPolicy(Qt.CustomContextMenu) # initialize the view widget self.uiGanttVIEW.setDragMode(self.uiGanttVIEW.RubberBandDrag) self.uiGanttVIEW.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.uiGanttVIEW.setAlignment(Qt.AlignTop | Qt.AlignLeft) self.uiGanttVIEW.setScene(XGanttScene(self)) self.uiGanttVIEW.installEventFilter(self) self.uiGanttVIEW.horizontalScrollBar().setValue(50) self.uiGanttVIEW.setContextMenuPolicy(Qt.CustomContextMenu) # create connections self.uiGanttTREE.itemExpanded.connect(self.syncView) self.uiGanttTREE.itemCollapsed.connect(self.syncView) # connect scrollbars tree_bar = self.uiGanttTREE.verticalScrollBar() view_bar = self.uiGanttVIEW.verticalScrollBar() tree_bar.rangeChanged.connect(self._updateViewRect) tree_bar.valueChanged.connect(self._scrollView) view_bar.valueChanged.connect(self._scrollTree) # connect selection self.uiGanttTREE.itemSelectionChanged.connect(self._selectView) self.uiGanttVIEW.scene().selectionChanged.connect(self._selectTree) self.uiGanttTREE.itemChanged.connect(self.updateItemData) self.uiGanttTREE.customContextMenuRequested.connect( self.requestTreeMenu) self.uiGanttVIEW.customContextMenuRequested.connect( self.requestViewMenu)
def __init__(self, parent=None): super(XDateEdit, self).__init__(parent) # define custom properties self.setCalendarPopup(True) self.setDate(QDate.currentDate())
def rebuildMonth( self ): """ Rebuilds the month for this scene. """ # make sure we start at 0 for sunday vs. 7 for sunday day_map = dict([(i+1, i+1) for i in range(7)]) day_map[7] = 0 today = QDate.currentDate() curr = self.currentDate() first = QDate(curr.year(), curr.month(), 1) last = QDate(curr.year(), curr.month(), curr.daysInMonth()) first = first.addDays(-day_map[first.dayOfWeek()]) last = last.addDays(6-day_map[last.dayOfWeek()]) cols = 7 rows = (first.daysTo(last) + 1) / cols hlines = [] vlines = [] padx = 6 pady = 6 header = 24 w = self.width() - (2 * padx) h = self.height() - (2 * pady) dw = (w / cols) - 1 dh = ((h - header) / rows) - 1 x0 = padx y0 = pady + header x = x0 y = y0 for row in range(rows + 1): hlines.append(QLine(x0, y, w, y)) y += dh for col in range(cols + 1): vlines.append(QLine(x, y0, x, h)) x += dw self._buildData['grid'] = hlines + vlines # draw the date fields date = first row = 0 col = 0 # draw the headers x = x0 y = pady regular_text = [] mid_text = [] self._buildData['regular_text'] = regular_text self._buildData['mid_text'] = mid_text for day in ('Sun', 'Mon','Tue','Wed','Thu','Fri','Sat'): regular_text.append((x + 5, y, dw, y0, Qt.AlignLeft | Qt.AlignVCenter, day)) x += dw for i in range(first.daysTo(last) + 1): top = (y0 + (row * dh)) left = (x0 + (col * dw)) rect = QRectF(left - 1, top, dw, dh) # mark the current date on the calendar if ( date == curr ): self._buildData['curr_date'] = rect # mark today's date on the calendar elif ( date == today ): self._buildData['today'] = rect # determine how to draw the calendar format = 'd' if ( date.day() == 1 ): format = 'MMM d' # determine the color to draw the text if ( date.month() == curr.month() ): text = regular_text else: text = mid_text # draw the text text.append((left + 2, top + 2, dw - 4, dh - 4, Qt.AlignTop | Qt.AlignLeft, date.toString(format))) # update the limits if ( not i ): self._minimumDate = date self._maximumDate = date self._dateGrid[date.toJulianDay()] = ((row, col), rect) if ( col == (cols - 1) ): row += 1 col = 0 else: col += 1 date = date.addDays(1)
def __init__( self, parent = None ): super(XGanttWidget, self).__init__( parent ) # load the user interface projexui.loadUi(__file__, self) # define custom properties self._backend = None self._dateStart = QDate.currentDate().addMonths(-2) self._dateEnd = QDate.currentDate().addMonths(2) self._timeStart = QTime(0, 0, 0) self._timeEnd = QTime(23, 59, 59) self._alternatingRowColors = False self._cellWidth = 20 self._cellHeight = 20 self._first = True self._dateFormat = 'M/d/yy' self._timescale = XGanttWidget.Timescale.Month self._scrolling = False self._dirty = False # setup the palette colors palette = self.palette() color = palette.color(palette.Base) self._gridPen = QPen(color.darker(115)) self._brush = QBrush(color) self._alternateBrush = QBrush(color.darker(105)) weekendColor = color.darker(108) self._weekendBrush = QBrush(weekendColor) # setup the columns for the tree self.setColumns(['Name', 'Start', 'End', 'Calendar Days', 'Work Days']) header = self.uiGanttTREE.header() header.setFixedHeight(self._cellHeight * 2) headerItem = self.uiGanttTREE.headerItem() headerItem.setSizeHint(0, QSize(80, header.height())) # initialize the tree widget self.uiGanttTREE.setShowGrid(False) self.uiGanttTREE.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.uiGanttTREE.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.uiGanttTREE.setVerticalScrollMode(self.uiGanttTREE.ScrollPerPixel) self.uiGanttTREE.setResizeToContentsInteractive(True) self.uiGanttTREE.setEditable(True) self.uiGanttTREE.resize(500, 20) self.uiGanttTREE.setContextMenuPolicy(Qt.CustomContextMenu) # initialize the view widget self.uiGanttVIEW.setDragMode( self.uiGanttVIEW.RubberBandDrag ) self.uiGanttVIEW.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.uiGanttVIEW.setAlignment(Qt.AlignTop | Qt.AlignLeft) self.uiGanttVIEW.setScene(XGanttScene(self)) self.uiGanttVIEW.installEventFilter(self) self.uiGanttVIEW.horizontalScrollBar().setValue(50) self.uiGanttVIEW.setContextMenuPolicy(Qt.CustomContextMenu) # create connections self.uiGanttTREE.itemExpanded.connect(self.syncView) self.uiGanttTREE.itemCollapsed.connect(self.syncView) # connect scrollbars tree_bar = self.uiGanttTREE.verticalScrollBar() view_bar = self.uiGanttVIEW.verticalScrollBar() tree_bar.rangeChanged.connect(self._updateViewRect) tree_bar.valueChanged.connect(self._scrollView) view_bar.valueChanged.connect(self._scrollTree) # connect selection self.uiGanttTREE.itemSelectionChanged.connect(self._selectView) self.uiGanttVIEW.scene().selectionChanged.connect(self._selectTree) self.uiGanttTREE.itemChanged.connect(self.updateItemData) self.uiGanttTREE.customContextMenuRequested.connect(self.requestTreeMenu) self.uiGanttVIEW.customContextMenuRequested.connect(self.requestViewMenu)
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)
def setValue(self, value): self.setDate(QDate(value))