예제 #1
0
	def draw(self, cr):
		if self.center:
			w, h = self.layout.get_pixel_size()
			cr.move_to(self.x - w/2.0, self.y - h/2.0)
		else:
			cr.move_to(self.x, self.y)
		fillColor(cr, self.color)
		show_layout(cr, self.layout)
예제 #2
0
파일: timeline.py 프로젝트: ilius/starcal
	def drawTick(self, cr, tick, maxTickHeight):
		tickH = tick.height
		tickW = tick.width
		tickH = min(tickH, maxTickHeight)
		###
		tickX = tick.pos - tickW / 2.0
		tickY = 1
		cr.rectangle(tickX, tickY, tickW, tickH)
		try:
			fillColor(cr, tick.color)
		except:
			print(
				"error in fill" +
				", x=%.2f, y=%.2f" % (tickX, tickY) +
				", w=%.2f, h=%.2f" % (tickW, tickH)
			)
		###
		font = [
			fontFamily,
			False,
			False,
			tick.fontSize,
		]
		#layout = newLimitedWidthTextLayout(
		#	self,
		#	tick.label,
		#	tick.maxLabelWidth,
		#	font=font,
		#	truncate=truncateTickLabel,
		#)  # FIXME
		layout = newTextLayout(
			self,
			text=tick.label,
			font=font,
			maxSize=(tick.maxLabelWidth, 0),
			maximizeScale=1.0,
			truncate=truncateTickLabel,
		)  # FIXME
		if layout:
			#layout.set_auto_dir(0)  # FIXME
			#print("layout.get_auto_dir() = %s"%layout.get_auto_dir())
			layoutW, layoutH = layout.get_pixel_size()
			layoutX = tick.pos - layoutW / 2.0
			layoutY = tickH * labelYRatio
			try:
				cr.move_to(layoutX, layoutY)
			except:
				print("error in move_to, x=%.2f, y=%.2f" % (layoutX, layoutY))
			else:
				show_layout(cr, layout)## with the same tick.color
예제 #3
0
 def drawTick(self, cr, tick, maxTickHeight):
     tickH = tick.height
     tickW = tick.width
     tickH = min(tickH, maxTickHeight)
     ###
     tickX = tick.pos - tickW / 2.0
     tickY = 1
     cr.rectangle(tickX, tickY, tickW, tickH)
     try:
         fillColor(cr, tick.color)
     except:
         print('error in fill, x=%.2f, y=%.2f, w=%.2f, h=%.2f' %
               (tickX, tickY, tickW, tickH))
     ###
     font = [
         fontFamily,
         False,
         False,
         tick.fontSize,
     ]
     #layout = newLimitedWidthTextLayout(
     #    self,
     #    tick.label,
     #    tick.maxLabelWidth,
     #    font=font,
     #    truncate=truncateTickLabel,
     #)## FIXME
     layout = newTextLayout(
         self,
         text=tick.label,
         font=font,
         maxSize=(tick.maxLabelWidth, 0),
         maximizeScale=1.0,
         truncate=truncateTickLabel,
     )  ## FIXME
     if layout:
         #layout.set_auto_dir(0)## FIXME
         #print('layout.get_auto_dir() = %s'%layout.get_auto_dir())
         layoutW, layoutH = layout.get_pixel_size()
         layoutX = tick.pos - layoutW / 2.0
         layoutY = tickH * labelYRatio
         try:
             cr.move_to(layoutX, layoutY)
         except:
             print('error in move_to, x=%.2f, y=%.2f' % (layoutX, layoutY))
         else:
             show_layout(cr, layout)  ## with the same tick.color
예제 #4
0
	def drawAll(self, cr):
		width = self.get_allocation().width
		height = self.get_allocation().height
		pixelPerSec = self.pixelPerSec
		dayPixel = dayLen * pixelPerSec ## pixel
		maxTickHeight = maxTickHeightRatio * height
		#####
		cr.rectangle(0, 0, width, height)
		fillColor(cr, bgColor)
		#####
		setColor(cr, holidayBgBolor)
		for x in self.data['holidays']:
			cr.rectangle(x, 0, dayPixel, height)
			cr.fill()
		#####
		for tick in self.data['ticks']:
			self.drawTick(cr, tick, maxTickHeight)
		######
		beforeBoxH = maxTickHeight ## FIXME
		maxBoxH = height - beforeBoxH
		for box in self.data['boxes']:
			box.setPixelValues(self.timeStart, pixelPerSec, beforeBoxH, maxBoxH)
			self.drawBox(cr, box)
		self.drawBoxEditingHelperLines(cr)
		###### Draw Current Time Marker
		dt = self.currentTime - self.timeStart
		if 0 <= dt <= self.timeWidth:
			setColor(cr, currentTimeMarkerColor)
			cr.rectangle(
				dt*pixelPerSec - currentTimeMarkerWidth/2.0,
				0,
				currentTimeMarkerWidth,
				currentTimeMarkerHeightRatio * self.get_allocation().height
			)
			cr.fill()
		######
		for button in self.buttons:
			button.draw(cr, width, height)
예제 #5
0
 def drawAll(self, cr):
     width = self.get_allocation().width
     height = self.get_allocation().height
     pixelPerSec = self.pixelPerSec
     dayPixel = dayLen * pixelPerSec  ## pixel
     maxTickHeight = maxTickHeightRatio * height
     #####
     cr.rectangle(0, 0, width, height)
     fillColor(cr, bgColor)
     #####
     setColor(cr, holidayBgBolor)
     for x in self.data['holidays']:
         cr.rectangle(x, 0, dayPixel, height)
         cr.fill()
     #####
     for tick in self.data['ticks']:
         self.drawTick(cr, tick, maxTickHeight)
     ######
     beforeBoxH = maxTickHeight  ## FIXME
     maxBoxH = height - beforeBoxH
     for box in self.data['boxes']:
         box.setPixelValues(self.timeStart, pixelPerSec, beforeBoxH,
                            maxBoxH)
         self.drawBox(cr, box)
     self.drawBoxEditingHelperLines(cr)
     ###### Draw Current Time Marker
     dt = self.currentTime - self.timeStart
     if 0 <= dt <= self.timeWidth:
         setColor(cr, currentTimeMarkerColor)
         cr.rectangle(
             dt * pixelPerSec - currentTimeMarkerWidth / 2.0, 0,
             currentTimeMarkerWidth,
             currentTimeMarkerHeightRatio * self.get_allocation().height)
         cr.fill()
     ######
     for button in self.buttons:
         button.draw(cr, width, height)
예제 #6
0
파일: timeline.py 프로젝트: ilius/starcal
	def drawAll(self, cr):
		timeStart = self.timeStart
		timeWidth = self.timeWidth
		timeEnd = timeStart + timeWidth
		####
		width = self.get_allocation().width
		height = self.get_allocation().height
		pixelPerSec = self.pixelPerSec
		dayPixel = dayLen * pixelPerSec ## pixel
		maxTickHeight = maxTickHeightRatio * height
		#####
		cr.rectangle(0, 0, width, height)
		fillColor(cr, bgColor)
		#####
		setColor(cr, holidayBgBolor)
		for x in self.data["holidays"]:
			cr.rectangle(x, 0, dayPixel, height)
			cr.fill()
		#####
		for tick in self.data["ticks"]:
			self.drawTick(cr, tick, maxTickHeight)
		######
		beforeBoxH = maxTickHeight ## FIXME
		maxBoxH = height - beforeBoxH
		for box in self.data["boxes"]:
			box.setPixelValues(timeStart, pixelPerSec, beforeBoxH, maxBoxH)
			self.drawBox(cr, box)
		self.drawBoxEditingHelperLines(cr)
		###### Show (possible) Daylight Saving change
		if timeStart > 0 and 2 * 3600 < timeWidth < 30 * dayLen:
			if getUtcOffsetByEpoch(timeStart) != getUtcOffsetByEpoch(timeEnd):
				startJd = getJdFromEpoch(timeStart)
				endJd = getJdFromEpoch(timeEnd)
				lastOffset = getUtcOffsetByJd(startJd, localTz)
				dstChangeJd = None
				deltaSec = 0
				for jd in range(startJd + 1, endJd + 1):
					offset = getUtcOffsetByJd(jd, localTz)
					deltaSec = offset - lastOffset
					if deltaSec != 0:
						dstChangeJd = jd
						break
				if dstChangeJd is not None:
					deltaHour = deltaSec / 3600.0
					dstChangeEpoch = getEpochFromJd(dstChangeJd)
					#print("dstChangeEpoch = %s" % dstChangeEpoch)
				else:
					print("dstChangeEpoch not found")

		###### Draw Current Time Marker
		dt = self.currentTime - timeStart
		if 0 <= dt <= timeWidth:
			setColor(cr, currentTimeMarkerColor)
			cr.rectangle(
				dt * pixelPerSec - currentTimeMarkerWidth / 2.0,
				0,
				currentTimeMarkerWidth,
				currentTimeMarkerHeightRatio * self.get_allocation().height
			)
			cr.fill()
		######
		for button in self.buttons:
			button.draw(cr, width, height)
예제 #7
0
    def drawAll(self, cr):
        timeStart = self.timeStart
        timeWidth = self.timeWidth
        timeEnd = timeStart + timeWidth
        ####
        width = self.get_allocation().width
        height = self.get_allocation().height
        pixelPerSec = self.pixelPerSec
        dayPixel = dayLen * pixelPerSec  ## pixel
        maxTickHeight = maxTickHeightRatio * height
        #####
        cr.rectangle(0, 0, width, height)
        fillColor(cr, bgColor)
        #####
        setColor(cr, holidayBgBolor)
        for x in self.data["holidays"]:
            cr.rectangle(x, 0, dayPixel, height)
            cr.fill()
        #####
        for tick in self.data["ticks"]:
            self.drawTick(cr, tick, maxTickHeight)
        ######
        beforeBoxH = maxTickHeight  ## FIXME
        maxBoxH = height - beforeBoxH
        for box in self.data["boxes"]:
            box.setPixelValues(timeStart, pixelPerSec, beforeBoxH, maxBoxH)
            self.drawBox(cr, box)
        self.drawBoxEditingHelperLines(cr)
        ###### Show (possible) Daylight Saving change
        if timeStart > 0 and 2 * 3600 < timeWidth < 30 * dayLen:
            if getUtcOffsetByEpoch(timeStart) != getUtcOffsetByEpoch(timeEnd):
                startJd = getJdFromEpoch(timeStart)
                endJd = getJdFromEpoch(timeEnd)
                lastOffset = getUtcOffsetByJd(startJd, localTz)
                dstChangeJd = None
                deltaSec = 0
                for jd in range(startJd + 1, endJd + 1):
                    offset = getUtcOffsetByJd(jd, localTz)
                    deltaSec = offset - lastOffset
                    if deltaSec != 0:
                        dstChangeJd = jd
                        break
                if dstChangeJd is not None:
                    deltaHour = deltaSec / 3600.0
                    dstChangeEpoch = getEpochFromJd(dstChangeJd)
                    #print("dstChangeEpoch = %s" % dstChangeEpoch)
                else:
                    print("dstChangeEpoch not found")

        ###### Draw Current Time Marker
        dt = self.currentTime - timeStart
        if 0 <= dt <= timeWidth:
            setColor(cr, currentTimeMarkerColor)
            cr.rectangle(
                dt * pixelPerSec - currentTimeMarkerWidth / 2.0, 0,
                currentTimeMarkerWidth,
                currentTimeMarkerHeightRatio * self.get_allocation().height)
            cr.fill()
        ######
        for button in self.buttons:
            button.draw(cr, width, height)