def BuildKey(self, coloron, coloroff): if self.usekeygaps: self.GappedSize = (self.Size[0] - self.Screen.HorizButGap, self.Size[1] - self.Screen.VertButGap) else: self.GappedSize = self.Size buttonsmaller = (self.GappedSize[0] - scaleW(6), self.GappedSize[1] - scaleH(6)) # create image of ON key self.KeyOnImageBase = pygame.Surface(self.GappedSize) pygame.draw.rect(self.KeyOnImageBase, coloron, ((0, 0), self.Size), 0) bord = self.KeyOutlineOffset pygame.draw.rect(self.KeyOnImageBase, wc(self.KeyOnOutlineColor), ((scaleW(bord), scaleH(bord)), buttonsmaller), bord) # create image of OFF key self.KeyOffImageBase = pygame.Surface(self.GappedSize) pygame.draw.rect(self.KeyOffImageBase, coloroff, ((0, 0), self.Size), 0) bord = self.KeyOutlineOffset pygame.draw.rect(self.KeyOffImageBase, wc(self.KeyOffOutlineColor), ((scaleW(bord), scaleH(bord)), buttonsmaller), bord) self.KeyUnknownOverlay = pygame.Surface(self.Size) pygame.draw.line(self.KeyUnknownOverlay, wc(self.KeyCharColorOn), (0, 0), self.Size, bord) pygame.draw.line(self.KeyUnknownOverlay, wc(self.KeyCharColorOn), (0, self.Size[1]), (self.Size[0], 0), bord) self.KeyUnknownOverlay.set_alpha(128)
def __init__(self): global monofont pygame.font.init() f = pygame.font.get_fonts() if not monofont in f: # pre stretch system doesn't have noto mono monofont = "droidsansmono" self.fontcache = {"": {40: {True: {True: pygame.font.SysFont("", hw.scaleH(40), True, True)}}}}
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 = fonts.fonts.Font(self.ButtonFontSizes[i], bold=True).size(lab[l]) if lines * txtsize[1] >= textarea[1] or txtsize[ 0] >= textarea[0]: fontchoice = self.ButtonFontSizes[i + 1] return fontchoice
def gennewfont(gname, gsize, gbold, gitalic): # logsupport.Logs.Log('Generated Font: ', repr(name), str(size), str(utilities.scaleH(size)), str(bold), # str(italic)) return pygame.font.SysFont(gname, hw.scaleH(gsize), gbold, gitalic)
def __init__(self, screensection, screenname): debug.debugPrint('Screen', "New Nest ThermostatScreenDesc ", screenname) screen.BaseKeyScreenDesc.__init__(self, screensection, screenname) screen.IncorporateParams( self, 'NestThermostatScreen', {'KeyColor', 'KeyOffOutlineColor', 'KeyOnOutlineColor'}, screensection) nominalfontsz = (30, 50, 80, 160) nominalspacers = (5, 20, 25, 40, 50, 85) self.fsize = [] self.spacer = [] self.HA = self.DefaultHubObj self.ThermNode = self.HA.GetNode(screenname)[0] # use ControlObj (0) if self.ThermNode is None: logsupport.Logs.Log("No Thermostat: " + screenname, severity=ConsoleWarning) raise ValueError # if isinstance(self.DefaultHub,hasshub.HA): # self.HA = self.DefaultHub # self.ThermNode = self.HA.GetNode(screenname)[0] # use ControlObj (0) # if self.ThermNode is None: # logsupport.Logs.Log("No Thermostat: " + screenname, severity=ConsoleWarning) # raise ValueError # else: # logsupport.Logs.Log("Nest Thermostat screen only works with HA hub", severity=ConsoleError) # self.self.ThermNode = None # raise ValueError self.SetScreenTitle(screen.FlatenScreenLabel(self.label), nominalfontsz[1], self.CharColor) self.TempPos = self.startvertspace ''' Size and positions based on nominal 480 vertical screen less top/bottom borders less default title size of 50 Compute other fonts sizes based on what is left after that given user ability to set actual title size ''' tempsurf = fonts.fonts.Font(50).render('Temp', 0, wc(self.CharColor)) useable = self.useablevertspace / (self.useablevertspace - tempsurf.get_height()) for fs in nominalfontsz: self.fsize.append(int(fs * useable)) for fs in nominalspacers: self.spacer.append(int(fs * useable)) self.StatePos = self.TempPos + fonts.fonts.Font( self.fsize[3]).get_linesize() - scaleH(self.spacer[1]) self.SPVPos = self.StatePos + scaleH(self.spacer[2]) sp = fonts.fonts.Font(self.fsize[2]).render("{:2d}".format(99), 0, wc(self.CharColor)) self.SPHgt = sp.get_height() self.SPWdt = sp.get_width() self.SetPointSurf = pygame.Surface((self.SPWdt, self.SPHgt)) self.SetPointSurf.fill(wc(self.BackgroundColor)) self.AdjButSurf = pygame.Surface( (hw.screenwidth, scaleH(self.spacer[3]))) self.AdjButTops = self.SPVPos + fonts.fonts.Font( self.fsize[2]).get_linesize() - scaleH(self.spacer[0]) centerspacing = hw.screenwidth // 5 self.SPHPosL = int(1.5 * centerspacing) self.SPHPosR = int(3.5 * centerspacing) self.AdjButSurf.fill(wc(self.BackgroundColor)) self.LocalOnly = [0.0, 0.0 ] # Heat setpoint, Cool setpoint: 0 is normal color self.ModeLocal = 0.0 self.FanLocal = 0.0 arrowsize = scaleH( 40) # pixel todo should this be other than a constant? self.t_low = 0 self.t_high = 99 self.t_cur = 0 self.t_state = "Unknown" self.mode = 'auto' self.fan = 'auto' self.modes, self.fanstates = self.ThermNode.GetModeInfo() self.TimeBumpSP = None self.TimeBumpModes = None self.TimeBumpFan = None self.TimerName = 0 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.Keys['temp' + str(i)] = toucharea.TouchPoint( 'temp' + str(i), (centerspacing * (i + 1), self.AdjButTops + arrowsize // 2), (arrowsize * 1.2, arrowsize * 1.2), proc=functools.partial(self.BumpTemp, (True, True, False, False)[i], (1, -1, 1, -1)[i])) self.ModeButPos = self.AdjButTops + scaleH(self.spacer[5]) # pixel bsize = (scaleW(100), scaleH(self.spacer[4])) # pixel self.Keys['Mode'] = toucharea.ManualKeyDesc( self, "Mode", ["Mode"], self.KeyColor, self.CharColor, self.CharColor, center=(self.SPHPosL, self.ModeButPos), size=bsize, KOn=self.KeyOffOutlineColor, proc=self.BumpMode) self.Keys['Fan'] = toucharea.ManualKeyDesc(self, "Fan", ["Fan"], self.KeyColor, self.CharColor, self.CharColor, center=(self.SPHPosR, self.ModeButPos), size=bsize, KOn=self.KeyOffOutlineColor, proc=self.BumpFan) self.ModesPos = self.ModeButPos + bsize[1] // 2 + scaleH( self.spacer[0]) if self.ThermNode is not None: self.HubInterestList[self.HA.name] = { self.ThermNode.address: self.Keys['Mode'] } # placeholder for thermostat node utilities.register_example("NestThermostatScreenDesc", self)
def __init__(self, screensection, screenname): debug.debugPrint('Screen', "New ThermostatScreenDesc ", screenname) screen.BaseKeyScreenDesc.__init__(self, screensection, screenname) screen.IncorporateParams( self, 'ThermostatScreen', {'KeyColor', 'KeyOffOutlineColor', 'KeyOnOutlineColor'}, screensection) self.info = {} self.oldinfo = {} nominalfontsz = (30, 50, 80, 160) nominalspacers = (5, 20, 25, 40, 50, 85) self.fsize = [] self.spacer = [] if isinstance(self.DefaultHubObj, isy.ISY): self.isy = self.DefaultHubObj self.ISYObj = self.isy.GetNode(screenname)[0] # use ControlObj (0) if self.ISYObj is None: logsupport.Logs.Log("No Thermostat: " + screenname, severity=ConsoleWarning) else: logsupport.Logs.Log("Thermostat screen only works with ISY hub", severity=ConsoleError) self.ISYObj = None self.SetScreenTitle(screen.FlatenScreenLabel(self.label), nominalfontsz[1], self.CharColor) self.TempPos = self.startvertspace ''' Size and positions based on vertical screen space less top/bottom borders less default title size of 50 Compute other fonts sizes based on what is left after that given user ability to set actual title size ''' tempsurf = fonts.fonts.Font(50).render('Temp', 0, wc( self.CharColor)) # todo should the 50 be scaled now? sizingratio = self.useablevertspace / (self.useablevertspace - tempsurf.get_height()) for fs in nominalfontsz: self.fsize.append(int(fs * sizingratio)) for fs in nominalspacers: self.spacer.append(int(fs * sizingratio)) self.StatePos = self.TempPos + fonts.fonts.Font( self.fsize[3]).get_linesize() - scaleH(self.spacer[1]) self.SPPos = self.StatePos + scaleH(self.spacer[2]) self.AdjButSurf = pygame.Surface( (hw.screenwidth, scaleH(self.spacer[3]))) self.AdjButTops = self.SPPos + fonts.fonts.Font( self.fsize[2]).get_linesize() - scaleH(self.spacer[0]) centerspacing = hw.screenwidth // 5 self.SPHPosL = int(1.5 * centerspacing) self.SPHPosR = int(3.5 * centerspacing) self.AdjButSurf.fill(wc(self.BackgroundColor)) arrowsize = scaleH(self.spacer[3]) # 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.Keys['temp' + str(i)] = toucharea.TouchPoint( 'temp' + str(i), (centerspacing * (i + 1), self.AdjButTops + arrowsize // 2), (arrowsize * 1.2, arrowsize * 1.2), proc=functools.partial(self.BumpTemp, ('CLISPH', 'CLISPH', 'CLISPC', 'CLISPC')[i], (2, -2, 2, -2)[i])) self.ModeButPos = self.AdjButTops + scaleH(self.spacer[5]) # pixel bsize = (scaleW(100), scaleH(self.spacer[4])) # pixel self.Keys['Mode'] = toucharea.ManualKeyDesc( self, "Mode", ["Mode"], self.KeyColor, self.CharColor, self.CharColor, center=(self.SPHPosL, self.ModeButPos), size=bsize, KOn=self.KeyOffOutlineColor, proc=functools.partial(self.BumpMode, 'CLIMD', range(8))) self.Keys['Fan'] = toucharea.ManualKeyDesc( self, "Fan", ["Fan"], self.KeyColor, self.CharColor, self.CharColor, center=(self.SPHPosR, self.ModeButPos), size=bsize, KOn=self.KeyOffOutlineColor, proc=functools.partial(self.BumpMode, 'CLIFS', (7, 8))) self.ModesPos = self.ModeButPos + bsize[1] // 2 + scaleH( self.spacer[0]) if self.ISYObj is not None: self.HubInterestList[self.isy.name] = { self.ISYObj.address: self.Keys['Mode'] } # placeholder for thermostat node utilities.register_example("ThermostatScreenDesc", self)
def ScaleScreensInfo(): # Compute all values in base screen size case screenStore.SetVal('BotBorder', scaleH(screenStore.BotBorderWONav + screenStore.NavKeyHeight)) screenStore.SetVal('NavKeyHeight', scaleH(screenStore.NavKeyHeight)) screenStore.SetVal('TopBorder', scaleH(screenStore.TopBorder)) screenStore.SetVal('HorizBorder', scaleW(screenStore.HorizBorder))