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 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 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 __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 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 __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 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 gotoToday(self): """ Goes to today as the current date. """ self.scene().setCurrentDate(QDate.currentDate())