def FinishKey(self, center, size, firstfont=0, shrink=True):
        if size[0] <> 0:  # if size is not zero then set the pos/size of the key; otherwise it was previously set in manual creation
            self.Center = center
            self.Size = size

        buttonsmaller = (self.Size[0] - scaleW(6), self.Size[1] - scaleH(6))

        # create image of ON key
        self.KeyOnImage = pygame.Surface(self.Size)
        pygame.draw.rect(self.KeyOnImage, wc(self.KeyColor),
                         ((0, 0), self.Size), 0)
        bord = 3  # todo pixel - probably should use same scaling in both dimensions since this is a line width
        pygame.draw.rect(self.KeyOnImage, wc(self.KeyOnOutlineColor),
                         ((scaleW(bord), scaleH(bord)), buttonsmaller), bord)

        # create image of OFF key
        self.KeyOffImage = pygame.Surface(self.Size)
        pygame.draw.rect(self.KeyOffImage, wc(self.KeyColor),
                         ((0, 0), self.Size), 0)
        bord = self.KeyOutlineOffset
        pygame.draw.rect(self.KeyOffImage, wc(self.KeyOffOutlineColor),
                         ((scaleW(bord), scaleH(bord)), buttonsmaller), bord)
        s = pygame.Surface(self.Size)
        s.set_alpha(150)
        s.fill(wc("white"))
        self.KeyOffImage.blit(s, (0, 0))

        # if a non-blank label then add in the label - otherwise it is a late bound label that will get set at paint time
        if not self.DynamicLabel:
            fontchoice = self.FindFontSize(self.label, firstfont, shrink)
            self.AddTitle(self.KeyOnImage, self.label, fontchoice,
                          self.KeyCharColorOn)
            self.AddTitle(self.KeyOffImage, self.label, fontchoice,
                          self.KeyCharColorOff)
Exemple #2
0
	def FinishKey(self,center,size,firstfont=0,shrink=True):
		if size[0] <> 0: # if size is not zero then set the pos/size of the key; otherwise it was previously set in manual creation
			self.Center = center
			self.Size = size

		buttonsmaller = (self.Size[0] - scaleW(6), self.Size[1] - scaleH(6))

		# create image of ON key
		self.KeyOnImage = pygame.Surface(self.Size)
		pygame.draw.rect(self.KeyOnImage, wc(self.KeyColorOn), ((0, 0), self.Size), 0)
		bord = 3  # todo pixel - probably should use same scaling in both dimensions since this is a line width
		pygame.draw.rect(self.KeyOnImage, wc(self.KeyOnOutlineColor), ((scaleW(bord),scaleH(bord)), buttonsmaller), bord)

		# create image of OFF key
		self.KeyOffImage = pygame.Surface(self.Size)
		pygame.draw.rect(self.KeyOffImage, wc(self.KeyColorOff), ((0, 0), self.Size), 0)
		bord = self.KeyOutlineOffset
		pygame.draw.rect(self.KeyOffImage, wc(self.KeyOffOutlineColor), ((scaleW(bord),scaleH(bord)), buttonsmaller), bord)
		s = pygame.Surface(self.Size)
		s.set_alpha(150)
		s.fill(wc("white"))
		self.KeyOffImage.blit(s, (0,0))

		# if a non-blank label then add in the label - otherwise it is a late bound label that will get set at paint time
		if self.KeyLabelOn[0] <> '':  # static label supplied
			fontchoice = self.FindFontSize(self.KeyLabelOn, firstfont, shrink)
			self.AddTitle(self.KeyOnImage, self.KeyLabelOn, fontchoice, self.KeyCharColorOn)
		if self.KeyLabelOff[0] <> '':
			fontchoice = self.FindFontSize(self.KeyLabelOff, firstfont,
										   shrink)  # todo add Onlabel and OffLabel - they will need separate fontchoiices default to label
			self.AddTitle(self.KeyOffImage, self.KeyLabelOff, fontchoice, self.KeyCharColorOff)
Exemple #3
0
	def FindFontSize(self,lab,firstfont,shrink):
		lines = len(lab)
		buttonsmaller = (self.Size[0] - scaleW(6), self.Size[1] - scaleH(6))
		# compute writeable area for text
		textarea = (buttonsmaller[0] - 2, buttonsmaller[1] - 2)
		fontchoice = self.ButtonFontSizes[firstfont]
		if shrink:
			for l in range(lines):
				for i in range(firstfont, len(self.ButtonFontSizes) - 1):
					txtsize = config.fonts.Font(self.ButtonFontSizes[i]).size(lab[l])
					if lines*txtsize[1] >= textarea[1] or txtsize[0] >= textarea[0]:
						fontchoice = self.ButtonFontSizes[i + 1]
		return fontchoice
 def FindFontSize(self, lab, firstfont, shrink):
     lines = len(lab)
     buttonsmaller = (self.Size[0] - scaleW(6), self.Size[1] - scaleH(6))
     # compute writeable area for text
     textarea = (buttonsmaller[0] - 2, buttonsmaller[1] - 2)
     fontchoice = self.ButtonFontSizes[firstfont]
     if shrink:
         for l in range(lines):
             for i in range(firstfont, len(self.ButtonFontSizes) - 1):
                 txtsize = config.fonts.Font(self.ButtonFontSizes[i]).size(
                     lab[l])
                 if lines * txtsize[1] >= textarea[1] or txtsize[
                         0] >= textarea[0]:
                     fontchoice = self.ButtonFontSizes[i + 1]
     return fontchoice
Exemple #5
0
	def __init__(self, screensection, screenname):
		debugprint(config.dbgscreenbuild, "New ThermostatScreenDesc ", screenname)
		screen.BaseKeyScreenDesc.__init__(self, screensection, screenname)
		utilities.LocalizeParams(self, screensection, 'KeyColor', 'KeyOffOutlineColor', 'KeyOnOutlineColor')
		self.info = {}
		self.fsize = (30, 50, 80, 160)

		if screenname in config.ISY.NodesByName:
			self.RealObj = config.ISY.NodesByName[screenname]
		else:
			self.RealObj = None
			config.Logs.Log("No Thermostat: " + screenname, severity=logsupport.ConsoleWarning)

		self.TitleRen = config.fonts.Font(self.fsize[1]).render(screen.FlatenScreenLabel(self.label), 0,
																wc(self.CharColor))
		self.TitlePos = ((config.screenwidth - self.TitleRen.get_width())/2, config.topborder)
		self.TempPos = config.topborder + self.TitleRen.get_height()
		self.StatePos = self.TempPos + config.fonts.Font(self.fsize[3]).get_linesize() - scaleH(20)
		self.SPPos = self.StatePos + scaleH(25)
		self.AdjButSurf = pygame.Surface((config.screenwidth, scaleH(40)))
		self.AdjButTops = self.SPPos + config.fonts.Font(self.fsize[2]).get_linesize() - scaleH(5)
		centerspacing = config.screenwidth/5
		self.AdjButSurf.fill(wc(self.BackgroundColor))
		arrowsize = scaleH(40)  # pixel

		for i in range(4):
			gfxdraw.filled_trigon(self.AdjButSurf, *trifromtop(centerspacing, arrowsize/2, i + 1, arrowsize,
															   wc(("red", "blue", "red", "blue")[i]), i%2 <> 0))
			self.keysbyord.append(toucharea.TouchPoint((centerspacing*(i + 1), self.AdjButTops + arrowsize/2),
													   (arrowsize*1.2, arrowsize*1.2)))
		self.ModeButPos = self.AdjButTops + scaleH(85)  # pixel

		bsize = (scaleW(100), scaleH(50))  # pixel
		self.keysbyord.append(toucharea.ManualKeyDesc("Mode", ["Mode"],
													  self.KeyColor, self.CharColor, self.CharColor,
													  center=(config.screenwidth/4, self.ModeButPos), size=bsize,
													  KOn=config.KeyOffOutlineColor))  # todo clean up
		self.keysbyord.append(toucharea.ManualKeyDesc("Fan", ["Fan"],
													  self.KeyColor, self.CharColor, self.CharColor,
													  center=(3*config.screenwidth/4, self.ModeButPos), size=bsize,
													  KOn=config.KeyOffOutlineColor))
		self.keysbyord[4].FinishKey((0,0),(0,0))
		self.keysbyord[5].FinishKey((0,0),(0,0))
		self.ModesPos = self.ModeButPos + bsize[1]/2 + scaleH(5)
		utilities.register_example("ThermostatScreenDesc", self)
	def __init__(self, screensection, screenname):
		debugPrint('BuildScreen', "New ThermostatScreenDesc ", screenname)
		screen.BaseKeyScreenDesc.__init__(self, screensection, screenname)
		utilities.LocalizeParams(self, screensection, 'KeyColor', 'KeyOffOutlineColor', 'KeyOnOutlineColor')
		self.info = {}
		self.fsize = (30, 50, 80, 160)

		if screenname in config.ISY.NodesByName:
			self.RealObj = config.ISY.NodesByName[screenname]
		else:
			self.RealObj = None
			config.Logs.Log("No Thermostat: " + screenname, severity=logsupport.ConsoleWarning)

		self.TitleRen = config.fonts.Font(self.fsize[1]).render(screen.FlatenScreenLabel(self.label), 0,
																wc(self.CharColor))
		self.TitlePos = ((config.screenwidth - self.TitleRen.get_width())/2, config.topborder)
		self.TempPos = config.topborder + self.TitleRen.get_height()
		self.StatePos = self.TempPos + config.fonts.Font(self.fsize[3]).get_linesize() - scaleH(20)
		self.SPPos = self.StatePos + scaleH(25)
		self.AdjButSurf = pygame.Surface((config.screenwidth, scaleH(40)))
		self.AdjButTops = self.SPPos + config.fonts.Font(self.fsize[2]).get_linesize() - scaleH(5)
		centerspacing = config.screenwidth/5
		self.AdjButSurf.fill(wc(self.BackgroundColor))
		arrowsize = scaleH(40)  # pixel

		for i in range(4):
			gfxdraw.filled_trigon(self.AdjButSurf, *trifromtop(centerspacing, arrowsize/2, i + 1, arrowsize,
															   wc(("red", "blue", "red", "blue")[i]), i%2 <> 0))
			self.keysbyord.append(toucharea.TouchPoint((centerspacing*(i + 1), self.AdjButTops + arrowsize/2),
													   (arrowsize*1.2, arrowsize*1.2)))
		self.ModeButPos = self.AdjButTops + scaleH(85)  # pixel

		bsize = (scaleW(100), scaleH(50))  # pixel
		self.keysbyord.append(toucharea.ManualKeyDesc("Mode", ["Mode"],
													  self.KeyColor, self.CharColor, self.CharColor,
													  center=(config.screenwidth/4, self.ModeButPos), size=bsize,
													  KOn=config.KeyOffOutlineColor))  # todo clean up
		self.keysbyord.append(toucharea.ManualKeyDesc("Fan", ["Fan"],
													  self.KeyColor, self.CharColor, self.CharColor,
													  center=(3*config.screenwidth/4, self.ModeButPos), size=bsize,
													  KOn=config.KeyOffOutlineColor))
		self.keysbyord[4].FinishKey((0,0),(0,0))
		self.keysbyord[5].FinishKey((0,0),(0,0))
		self.ModesPos = self.ModeButPos + bsize[1]/2 + scaleH(5)
		utilities.register_example("ThermostatScreenDesc", self)