Beispiel #1
0
	def updateTypeParamsWidget(self):
		try:
			vbox = self.typeParamsVbox
		except AttributeError:
			return
		for child in vbox.get_children():
			child.destroy()
		###
		n = len(calTypes.active)
		while len(ui.dcalTypeParams) < n:
			ui.dcalTypeParams.append({
				"pos": (0, 0),
				"font": ui.getFont(3.0),
				"color": ui.textColor,
			})
		sgroupLabel = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
		sgroupFont = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
		for i, mode in enumerate(calTypes.active):
			#try:
			params = ui.dcalTypeParams[i]
			#except IndexError:
			##
			hbox = DayCalTypeParamBox(self, i, mode, params, sgroupLabel, sgroupFont)
			pack(vbox, hbox)
		###
		vbox.show_all()
Beispiel #2
0
 def statusIconUpdateIcon(self, ddate):## FIXME
     from scal3.utils import toBytes
     imagePath = ui.statusIconImageHoli if ui.todayCell.holiday else ui.statusIconImage
     ext = os.path.splitext(imagePath)[1][1:].lower()
     loader = GdkPixbuf.PixbufLoader.new_with_type(ext)
     if ui.statusIconFixedSizeEnable:
         try:
             width, height = ui.statusIconFixedSizeWH
             loader.set_size(width, height)
         except:
             myRaise()
     data = open(imagePath).read()
     if ext == 'svg':
         dayNum = _(ddate[2])
         if ui.statusIconFontFamilyEnable:
             if ui.statusIconFontFamily:
                 family = ui.statusIconFontFamily
             else:
                 family = ui.getFont()[0]
             dayNum = '<tspan style="font-family:%s">%s</tspan>'%(family, dayNum)
         data = data.replace(
             'TX',
             dayNum,
         )
     data = toBytes(data)
     loader.write(data)
     loader.close()
     pixbuf = loader.get_pixbuf()
     self.sicon.set_from_pixbuf(pixbuf)
Beispiel #3
0
	def statusIconUpdateIcon(self, ddate):## FIXME
		from scal3.utils import toBytes
		imagePath = ui.statusIconImageHoli if ui.todayCell.holiday else ui.statusIconImage
		ext = os.path.splitext(imagePath)[1][1:].lower()
		loader = GdkPixbuf.PixbufLoader.new_with_type(ext)
		if ui.statusIconFixedSizeEnable:
			try:
				width, height = ui.statusIconFixedSizeWH
				loader.set_size(width, height)
			except:
				myRaise()
		data = open(imagePath, 'rb').read()
		if ext == 'svg':
			dayNum = locale_man.numEncode(
				ddate[2],
				mode=calTypes.primary,  # FIXME
			)
			if ui.statusIconFontFamilyEnable:
				if ui.statusIconFontFamily:
					family = ui.statusIconFontFamily
				else:
					family = ui.getFont()[0]
				dayNum = '<tspan style="font-family:%s">%s</tspan>'%(family, dayNum)
			data = data.replace(
				b'TX',
				toBytes(dayNum),
			)
		loader.write(data)
		loader.close()
		pixbuf = loader.get_pixbuf()
		self.sicon.set_from_pixbuf(pixbuf)
Beispiel #4
0
 def updateTypeParamsWidget(self):
     try:
         vbox = self.typeParamsVbox
     except AttributeError:
         return
     for child in vbox.get_children():
         child.destroy()
     ###
     n = len(calTypes.active)
     while len(ui.dcalTypeParams) < n:
         ui.dcalTypeParams.append({
             "pos": (0, 0),
             "font": ui.getFont(3.0),
             "color": ui.textColor,
         })
     sgroupLabel = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
     sgroupFont = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
     for i, mode in enumerate(calTypes.active):
         #try:
         params = ui.dcalTypeParams[i]
         #except IndexError:
         ##
         hbox = DayCalTypeParamBox(self, i, mode, params, sgroupLabel,
                                   sgroupFont)
         pack(vbox, hbox)
     ###
     vbox.show_all()
Beispiel #5
0
def newTextLayout(
	widget,
	text='',
	font=None,
	maxSize=None,
	maximizeScale=0.6,
	truncate=False,
):
	'''
		None return value should be expected and handled, only if maxSize is given
	'''
	layout = widget.create_pango_layout('') ## a Pango.Layout object
	if font:
		font = list(font)
	else:
		font = ui.getFont()
	layout.set_font_description(pfontEncode(font))
	if text:
		layout.set_markup(text)
		if maxSize:
			layoutW, layoutH = layout.get_pixel_size()
			##
			maxW, maxH = maxSize
			maxW = float(maxW)
			maxH = float(maxH)
			if maxW <= 0:
				return
			if maxH <= 0:
				minRat = 1.0
			else:
				minRat = 1.01 * layoutH/maxH ## FIXME
			if truncate:
				if minRat > 1:
					font[3] = int(font[3]/minRat)
				layout.set_font_description(pfontEncode(font))
				layoutW, layoutH = layout.get_pixel_size()
				if layoutW > 0:
					char_w = float(layoutW)/len(text)
					char_num = int(maxW//char_w)
					while layoutW > maxW:
						text = cutText(text, char_num)
						if not text:
							break
						layout = widget.create_pango_layout(text)
						layout.set_font_description(pfontEncode(font))
						layoutW, layoutH = layout.get_pixel_size()
						char_num -= max(int((layoutW-maxW)//char_w), 1)
						if char_num<0:
							layout = None
							break
			else:
				if maximizeScale > 0:
					minRat = minRat/maximizeScale
				if minRat < layoutW/maxW:
					minRat = layoutW/maxW
				if minRat > 1:
					font[3] = int(font[3]/minRat)
				layout.set_font_description(pfontEncode(font))
	return layout
Beispiel #6
0
def drawBoxText(cr, box, x, y, w, h, widget):
    ## now draw the text
    ## how to find the best font size based in the box's width and height,
    ## and font family? FIXME
    ## possibly write in many lines? or just in one line and wrap if needed?
    if box.text:
        #print(box.text)
        textW = 0.9 * w
        textH = 0.9 * h
        textLen = len(toStr(box.text))
        #print('textLen=%s'%textLen)
        avgCharW = float(textW if rotateBoxLabel ==
                         0 else max(textW, textH)) / textLen
        if avgCharW > 3:  ## FIXME
            font = list(ui.getFont())
            layout = widget.create_pango_layout(
                box.text)  ## a Pango.Layout object
            layout.set_font_description(pfontEncode(font))
            layoutW, layoutH = layout.get_pixel_size()
            #print('orig font size: %s'%font[3])
            normRatio = min(
                float(textW) / layoutW,
                float(textH) / layoutH,
            )
            rotateRatio = min(
                float(textW) / layoutH,
                float(textH) / layoutW,
            )
            if rotateBoxLabel != 0 and rotateRatio > normRatio:
                font[3] *= max(normRatio, rotateRatio)
                layout.set_font_description(pfontEncode(font))
                layoutW, layoutH = layout.get_pixel_size()
                fillColor(cr, fgColor)  ## before cr.move_to
                #print('x=%s, y=%s, w=%s, h=%s, layoutW=%s, layoutH=%s'\)
                #   %(x,y,w,h,layoutW,layoutH)
                cr.move_to(
                    x + (w - rotateBoxLabel * layoutH) / 2.0,
                    y + (h + rotateBoxLabel * layoutW) / 2.0,
                )
                cr.rotate(-rotateBoxLabel * pi / 2)
                show_layout(cr, layout)
                try:
                    cr.rotate(rotateBoxLabel * pi / 2)
                except:
                    print('counld not rotate by %s*pi/2 = %s' % (
                        rotateBoxLabel,
                        rotateBoxLabel * pi / 2,
                    ))
            else:
                font[3] *= normRatio
                layout.set_font_description(pfontEncode(font))
                layoutW, layoutH = layout.get_pixel_size()
                fillColor(cr, fgColor)  ## before cr.move_to
                cr.move_to(
                    x + (w - layoutW) / 2.0,
                    y + (h - layoutH) / 2.0,
                )
                show_layout(cr, layout)
Beispiel #7
0
	def onConfigChange(self, *a, **ka):
		ui.cellCache.clear()
		settings.set_property(
			'gtk-font-name',
			pfontEncode(ui.getFont()).to_string(),
		)
		####
		BaseCalObj.onConfigChange(self, *a, **ka)
		self.onDateChange()
Beispiel #8
0
 def onConfigChange(self, *a, **ka):
     ui.cellCache.clear()
     settings.set_property(
         "gtk-font-name",
         pfontEncode(ui.getFont()).to_string(),
     )
     ####
     BaseCalObj.onConfigChange(self, *a, **ka)
     self.onDateChange()
Beispiel #9
0
def drawBoxText(cr, box, x, y, w, h, widget):
	## now draw the text
	## how to find the best font size based in the box's width and height,
	## and font family? FIXME
	## possibly write in many lines? or just in one line and wrap if needed?
	if box.text:
		#print(box.text)
		textW = 0.9 * w
		textH = 0.9 * h
		textLen = len(toStr(box.text))
		#print('textLen=%s'%textLen)
		avgCharW = float(textW if rotateBoxLabel == 0 else max(textW, textH)) / textLen
		if avgCharW > 3:## FIXME
			font = list(ui.getFont())
			layout = widget.create_pango_layout(box.text) ## a Pango.Layout object
			layout.set_font_description(pfontEncode(font))
			layoutW, layoutH = layout.get_pixel_size()
			#print('orig font size: %s'%font[3])
			normRatio = min(
				float(textW)/layoutW,
				float(textH)/layoutH,
			)
			rotateRatio = min(
				float(textW)/layoutH,
				float(textH)/layoutW,
			)
			if rotateBoxLabel != 0 and rotateRatio > normRatio:
				font[3] *= max(normRatio, rotateRatio)
				layout.set_font_description(pfontEncode(font))
				layoutW, layoutH = layout.get_pixel_size()
				fillColor(cr, fgColor)## before cr.move_to
				#print('x=%s, y=%s, w=%s, h=%s, layoutW=%s, layoutH=%s'\)
				#	%(x,y,w,h,layoutW,layoutH)
				cr.move_to(
					x + (w - rotateBoxLabel*layoutH)/2.0,
					y + (h + rotateBoxLabel*layoutW)/2.0,
				)
				cr.rotate(-rotateBoxLabel*pi/2)
				show_layout(cr, layout)
				try:
					cr.rotate(rotateBoxLabel*pi/2)
				except:
					print('counld not rotate by %s*pi/2 = %s'%(
						rotateBoxLabel,
						rotateBoxLabel*pi/2,
					))
			else:
				font[3] *= normRatio
				layout.set_font_description(pfontEncode(font))
				layoutW, layoutH = layout.get_pixel_size()
				fillColor(cr, fgColor)## before cr.move_to
				cr.move_to(
					x + (w-layoutW)/2.0,
					y + (h-layoutH)/2.0,
				)
				show_layout(cr, layout)
Beispiel #10
0
 def drawTextList(self, cr, textData, font=None):
     alloc = self.get_allocation()
     w = alloc.width
     h = alloc.height
     ###
     rowH = h / 7
     itemW = w - ui.wcalPadding
     if font is None:
         fontName = self.getFontValue()
         fontSize = ui.getFont()[-1]  # FIXME
         font = [fontName, False, False, fontSize] if fontName else None
     for i in range(7):
         data = textData[i]
         if data:
             linesN = len(data)
             lineH = rowH / linesN
             lineI = 0
             if len(data[0]) < 2:
                 print(self._name)
             for line, color in data:
                 layout = newTextLayout(
                     self,
                     text=line,
                     font=font,
                     maxSize=(itemW, lineH),
                     maximizeScale=ui.wcalTextSizeScale,
                     truncate=self.truncateText,
                 )
                 if not layout:
                     continue
                 layoutW, layoutH = layout.get_pixel_size()
                 layoutX = (w - layoutW) / 2
                 layoutY = i * rowH + (lineI + 0.5) * lineH - layoutH / 2
                 cr.move_to(layoutX, layoutY)
                 if self.colorizeHolidayText and self.wcal.status[i].holiday:
                     color = ui.holidayColor
                 if not color:
                     color = ui.textColor
                 setColor(cr, color)
                 show_layout(cr, layout)
                 lineI += 1
Beispiel #11
0
	def drawTextList(self, cr, textData, font=None):
		alloc = self.get_allocation()
		w = alloc.width
		h = alloc.height
		###
		rowH = h / 7
		itemW = w - ui.wcalPadding
		if font is None:
			fontName = self.getFontValue()
			fontSize = ui.getFont()[-1]  # FIXME
			font = [fontName, False, False, fontSize] if fontName else None
		for i in range(7):
			data = textData[i]
			if data:
				linesN = len(data)
				lineH = rowH / linesN
				lineI = 0
				if len(data[0]) < 2:
					print(self._name)
				for line, color in data:
					layout = newTextLayout(
						self,
						text=line,
						font=font,
						maxSize=(itemW, lineH),
						maximizeScale=ui.wcalTextSizeScale,
						truncate=self.truncateText,
					)
					if not layout:
						continue
					layoutW, layoutH = layout.get_pixel_size()
					layoutX = (w - layoutW) / 2
					layoutY = i * rowH + (lineI + 0.5) * lineH - layoutH / 2
					cr.move_to(layoutX, layoutY)
					if self.colorizeHolidayText and self.wcal.status[i].holiday:
						color = ui.holidayColor
					if not color:
						color = ui.textColor
					setColor(cr, color)
					show_layout(cr, layout)
					lineI += 1
Beispiel #12
0
	def statusIconUpdateIcon(self, ddate):  # FIXME
		from scal3.utils import toBytes
		imagePath = (
			ui.statusIconImageHoli if ui.todayCell.holiday
			else ui.statusIconImage
		)
		ext = os.path.splitext(imagePath)[1][1:].lower()
		loader = GdkPixbuf.PixbufLoader.new_with_type(ext)
		if ui.statusIconFixedSizeEnable:
			try:
				width, height = ui.statusIconFixedSizeWH
				loader.set_size(width, height)
			except:
				myRaise()
		data = open(imagePath, "rb").read()
		if ext == "svg":
			dayNum = locale_man.numEncode(
				ddate[2],
				mode=calTypes.primary,  # FIXME
			)
			if ui.statusIconFontFamilyEnable:
				if ui.statusIconFontFamily:
					family = ui.statusIconFontFamily
				else:
					family = ui.getFont()[0]
				dayNum = "<tspan style=\"font-family:%s\">%s</tspan>" % (
					family,
					dayNum,
				)
			data = data.replace(
				b"TX",
				toBytes(dayNum),
			)
		loader.write(data)
		loader.close()
		pixbuf = loader.get_pixbuf()
		self.sicon.set_from_pixbuf(pixbuf)
Beispiel #13
0
	def set(self, data):
		font = data['font']
		self.fontCheck.set_active(bool(font))
		if not font:
			font = ui.getFont()
		self.fontb.set_font_name(font)
Beispiel #14
0


movingKeyTimeoutFirst = 0.5
movingKeyTimeout = 0.1 ## seconds ## continiouse keyPress delay is about 0.05 sec

#############################################
truncateTickLabel = False

## 0: no rotation
## 1: 90 deg CCW (if needed)
## -1: 90 deg CW (if needed)

####################################################

fontFamily = ui.getFont()[0]

dayLen = 24 * 3600
minYearLenSec = 365 * dayLen
avgMonthLen = 30 * dayLen

unitSteps = (
    (3600, 12),
    (3600, 6),
    (3600, 3),
    (3600, 1),
    (60, 30),
    (60, 15),
    (60, 5),
    (60, 1),
    (1, 30),
Beispiel #15
0
	def update_font(self):
		self.override_font(pfontEncode(ui.getFont()))
Beispiel #16
0
	def set(self, data):
		font = data["font"]
		self.fontCheck.set_active(bool(font))
		if not font:
			font = ui.getFont()
		self.fontb.set_font_name(font)
Beispiel #17
0
## movingMaxSpeed = movingAccel * 4
## reach to maximum speed in 4 seconds

movingKeyTimeoutFirst = 0.5
movingKeyTimeout = 0.1  ## seconds ## continiouse keyPress delay is about 0.05 sec

#############################################
truncateTickLabel = False

## 0: no rotation
## 1: 90 deg CCW (if needed)
## -1: 90 deg CW (if needed)

####################################################

fontFamily = ui.getFont()[0]

dayLen = 24 * 3600
minYearLenSec = 365 * dayLen
avgMonthLen = 30 * dayLen

unitSteps = (
    (3600, 12),
    (3600, 6),
    (3600, 3),
    (3600, 1),
    (60, 30),
    (60, 15),
    (60, 5),
    (60, 1),
    (1, 30),
Beispiel #18
0
 def update_font(self):
     self.override_font(pfontEncode(ui.getFont()))