def __init__(self, crop, context_menu, date0=0, parent=None): super().__init__(parent) self.date0 = date0 self.crop = crop self.text = crop.plant.name self.context_menu = context_menu self.create_rect(crop.planned_start_date, crop.planned_end_date, planned=True) self.create_rect(crop.start_date, crop.end_date, planned=False) text = QtGui.QGraphicsSimpleTextItem(self.text) text_align(text, self.boundingRect) text.setParentItem(self) rect = QtGui.QGraphicsRectItem(self.boundingRect()) self.addToGroup(rect)
def __init__(self, date0, parent=None): super().__init__(parent) #months on the top first_year = date0.year last_year = datetime.date.today().year for year in range(first_year, last_year + 1): for month in range(1, 12 + 1): firstday = datetime.date(year=year, month=month, day=1) if month == 12: lastday = datetime.date(year=year + 1, month=1, day=1) else: lastday = datetime.date(year=year, month=month + 1, day=1) x0 = date_to_pos(firstday, date0) x1 = date_to_pos(lastday, date0) rect = QtGui.QGraphicsRectItem(x0, - 30, x1 - x0, 20) rect.setParentItem(self) text = QtGui.QGraphicsSimpleTextItem(firstday.strftime("%B")) text_align(text, rect.rect) text.setParentItem(self)
def update(self, crop): self.setRect(self.subd_rect.posx, - self.subd_rect.posy - self.subd_rect.height, self.subd_rect.width, self.subd_rect.height) self.crop = crop if self.crop: plant = crop.plant text = plant.name text = re.sub("\s+", "\n", text) textw = QtGui.QGraphicsSimpleTextItem(text) font = textw.font() font.setPointSize(6) font.setWeight(25) textw.setFont(font) text_align(textw, self.boundingRect) textw.setParentItem(self) color = QtGui.QColor(plant.color) if self.planned: self.setBrush(QtGui.QBrush(color, QtCore.Qt.BDiagPattern)) else: self.setBrush(QtGui.QBrush(color))