示例#1
0
 def __init__(self,
              screensection,
              screenname,
              ExtraCmdButs=(),
              withnav=True):
     self.name = screenname
     self.keysbyord = []
     utilities.LocalizeParams(self,
                              screensection,
                              'CharColor',
                              'DimTO',
                              'BackgroundColor',
                              'CmdKeyCol',
                              'CmdCharCol',
                              label=[screenname])
     self.WithNav = withnav
     self.PrevScreen = self.NextScreen = None
     cbutwidth = (config.screenwidth -
                  2 * config.horizborder) / (2 + len(ExtraCmdButs))
     cvertcenter = config.screenheight - config.botborder / 2
     cbutheight = config.botborder - config.cmdvertspace * 2
     # todo condition on withnav?  if False then None? if change then also fix FinishScreen not to fail on none
     self.PrevScreenKey = toucharea.ManualKeyDesc(
         '**prev**', ['**prev**'],
         self.CmdKeyCol,
         self.CmdCharCol,
         self.CmdCharCol,
         center=(config.horizborder + .5 * cbutwidth, cvertcenter),
         size=(cbutwidth, cbutheight))
     self.NextScreenKey = toucharea.ManualKeyDesc(
         '**next**', ['**next**'],
         self.CmdKeyCol,
         self.CmdCharCol,
         self.CmdCharCol,
         center=(config.horizborder +
                 (1 + len(ExtraCmdButs) + .5) * cbutwidth, cvertcenter),
         size=(cbutwidth, cbutheight))
     self.ExtraCmdKeys = []
     for i in range(len(ExtraCmdButs)):
         hcenter = config.horizborder + (i + 1.5) * cbutwidth
         self.ExtraCmdKeys.append(
             toucharea.ManualKeyDesc(ExtraCmdButs[i][0],
                                     ExtraCmdButs[i][1],
                                     self.CmdKeyCol,
                                     self.CmdCharCol,
                                     self.CmdCharCol,
                                     center=(hcenter, cvertcenter),
                                     size=(cbutwidth, cbutheight)))
         self.ExtraCmdKeys[-1].FinishKey((0, 0), (0, 0))
     utilities.register_example('ScreenDesc', self)
示例#2
0
 def __init__(self, name, keys, overrides=fixedoverrides):
     screen.BaseKeyScreenDesc.__init__(self, overrides, name)
     debug.debugPrint('Screen', "Build Maintenance Screen")
     self.NavKeysShowing = False
     self.DefaultNavKeysShowing = False
     screen.AddUndefaultedParams(self,
                                 None,
                                 TitleFontSize=40,
                                 SubFontSize=25)
     for k, kt in keys.items():
         NK = toucharea.ManualKeyDesc(self,
                                      k, [kt[0]],
                                      'gold',
                                      'black',
                                      'red',
                                      KOn='black',
                                      KOff='red')
         if kt[1] is not None:
             if len(
                     kt
             ) == 3:  # need to add key reference to the proc for this key
                 NK.Proc = functools.partial(kt[1], NK)
             else:
                 NK.Proc = kt[1]
         self.Keys[k] = NK
     topoff = self.TitleFontSize + self.SubFontSize
     self.LayoutKeys(topoff, self.useablevertspacesansnav - topoff)
     self.DimTO = 60
     self.PersistTO = 1  # setting to 0 would turn off timer and stick us here
     utilities.register_example("MaintScreenDesc", self)
示例#3
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)
示例#4
0
	def CreateNavKeys(self, prevk, nextk):
		cvertcenter = hw.screenheight - self.BotBorder / 2
		self.prevkey = toucharea.ManualKeyDesc(self, 'Nav<' + prevk.name,
											   prevk.label,
											   prevk.CmdKeyCol, prevk.CmdCharCol,
											   prevk.CmdCharCol,
											   proc=functools.partial(GoToScreen, prevk),
											   center=(
												   self.starthorizspace + .5 * (
													   self.NavKeyWidth),
												   cvertcenter),
											   size=(self.NavKeyWidth, self.NavKeyHeight), gaps=True)
		self.nextkey = toucharea.ManualKeyDesc(self, 'Nav>' + nextk.name,
											   nextk.label,
											   nextk.CmdKeyCol, nextk.CmdCharCol,
											   nextk.CmdCharCol,
											   proc=functools.partial(GoToScreen, nextk),
											   center=(
												   self.starthorizspace + 1.5 * (
													   self.NavKeyWidth),
												   cvertcenter),
											   size=(self.NavKeyWidth, self.NavKeyHeight), gaps=True)
示例#5
0
 def __init__(self, keys):
     debugprint(config.dbgscreenbuild, "Build Maintenance Screen")
     screen.BaseKeyScreenDesc.__init__(self,
                                       fixedoverrides,
                                       'Maint',
                                       withnav=False)
     utilities.LocalizeParams(self, None, TitleFontSize=40, SubFontSize=25)
     self.keysbyord = []
     for k, kt in keys.iteritems():
         self.keysbyord.append(
             toucharea.ManualKeyDesc(k, [kt[0]],
                                     'gold',
                                     'black',
                                     'black',
                                     KOn='black',
                                     KOff='black',
                                     proc=kt[1]))
     topoff = self.TitleFontSize + self.SubFontSize
     self.LayoutKeys(topoff,
                     config.screenheight - 2 * config.topborder - topoff)
     utilities.register_example("MaintScreenDesc", self)
示例#6
0
	def __init__(self, screensection, screenname):
		global alertscreens
		screen.ScreenDesc.__init__(self, screensection, screenname)
		debug.debugPrint('Screen', "Build Alerts Screen")
		self.NavKeysShowing = False
		self.DefaultNavKeysShowing = False
		screen.IncorporateParams(self, screenname, {'KeyColor', 'KeyCharColorOn', 'KeyCharColorOff'}, screensection)
		screen.AddUndefaultedParams(self, screensection, CharSize=[20], Font=fonts.monofont, MessageBack='',
									Message=[], DeferTime="2 minutes", BlinkTime=0)
		if self.MessageBack == '':
			self.MessageBack = self.BackgroundColor
		self.DimTO = 0  # alert screens don't dim or yield voluntarily
		self.PersistTO = 0
		self.BlinkTimer = None
		self.TimerName = 0
		self.DeferTimer = None

		self.Msg = True

		messageareapart = .7
		messageareaheight = (
									hw.screenheight - 2 * self.TopBorder) * messageareapart  # no Nav keys todo switch to new screen sizing
		alertbutheight = (hw.screenheight - messageareaheight - 2 * self.TopBorder) / 2
		self.upperleft = (self.HorizBorder, self.TopBorder)

		self.Defer = utilities.get_timedelta(self.DeferTime)

		self.Keys = {'defer': toucharea.ManualKeyDesc(self, 'defer', ['Defer'], self.KeyColor, self.KeyCharColorOn,
													  self.KeyCharColorOff,
													  center=(hw.screenwidth / 2,
															  self.TopBorder + messageareaheight + 0.5 * alertbutheight),
													  size=(
														  hw.screenwidth - 2 * self.HorizBorder, alertbutheight),
													  proc=self.DeferAction)}

		if 'Action' in screensection:
			action = screensection['Action']
			self.Keys['action'] = keyspecs.CreateKey(self, action, '*Action*')
			# this is only case so far that is a user descibed key that gets explicit positioning so just do it here
			self.Keys['action'].Center = (
				hw.screenwidth / 2, self.TopBorder + messageareaheight + 1.5 * alertbutheight)
			self.Keys['action'].Size = (hw.screenwidth - 2 * self.HorizBorder, alertbutheight)
			self.Keys['action'].State = True  # for appearance only
			self.Keys['action'].FinishKey((0, 0), (0, 0))
		else:
			pass
		# no key created - just a blank spot on the alert screen

		#

		for i in range(len(self.CharSize), len(self.Message)):
			self.CharSize.append(self.CharSize[-1])

		h = 0
		l = []

		for i, ln in enumerate(self.Message):
			l.append(
				fonts.fonts.Font(self.CharSize[i], self.Font).render(ln, 0, wc(self.KeyCharColorOn)))
			h = h + l[i].get_height()
		s = (messageareaheight - h) / (len(l))

		self.messageimage = pygame.Surface((hw.screenwidth - 2 * self.HorizBorder, messageareaheight))
		self.messageblank = pygame.Surface((hw.screenwidth - 2 * self.HorizBorder, messageareaheight))
		self.messageimage.fill(wc(self.MessageBack))
		self.messageblank.fill(wc(self.BackgroundColor))

		vert_off = s / 2
		for i in range(len(l)):
			horiz_off = (hw.screenwidth - l[i].get_width()) / 2 - self.HorizBorder
			self.messageimage.blit(l[i], (horiz_off, vert_off))
			vert_off = vert_off + s + l[i].get_height()

		self.Alert = None  # gets filled in by code that parses/defines an alert that invokes the screen
		alertscreens[screenname] = self
		self.DimTO = 0
		self.PersistTO = 0
		utilities.register_example("AlertsScreen", self)
示例#7
0
	def __init__(self, screensection, screenname, parentscreen=None):
		self.userstore = paramstore.ParamStore('Screen-' + screenname,
											   dp=screenStore if parentscreen is None else parentscreen.userstore,
											   locname=screenname)
		# todo add routine to update allowable mods per screen - but rationalize with incorp parameters from hight level guys

		self.markradius = int(min(hw.screenwidth, hw.screenheight) * .025)

		self.name = screenname
		self.Active = False  # true if actually on screen
		self.ScreenTimers = []
		self.DefaultNavKeysShowing = True
		self.NavKeysShowing = True
		self.NavKeys = collections.OrderedDict()
		self.Keys = collections.OrderedDict()
		self.WithNav = True
		self.useablevertspace = hw.screenheight - self.TopBorder - self.BotBorder
		self.useablevertspacesansnav = hw.screenheight - self.TopBorder - self.BotBorderWONav
		self.useablehorizspace = hw.screenwidth - 2 * self.HorizBorder
		self.startvertspace = self.TopBorder
		self.starthorizspace = self.HorizBorder
		self.titleoffset = 0
		self.HubInterestList = {}  # one entry per hub, each entry is a dict mapping addr to Node
		self.ScreenTitleBlk = None
		self.prevkey = None
		self.nextkey = None
		self.NavKeyWidth = (hw.screenwidth - 2 * self.HorizBorder) // 2

		cvertcenter = hw.screenheight - self.BotBorder / 2
		# print("NKW {} {} {} {}".format(self.NavKeyWidth, self.HorizBorder, self.HorizButGap, cvertcenter))

		self.homekey = toucharea.ManualKeyDesc(self, 'Back<' + 'Home', ('Home',),
											   self.CmdKeyCol, self.CmdCharCol, self.CmdCharCol,
											   proc=functools.partial(GoToScreen, HOMETOKEN),
											   center=(
												   self.starthorizspace + .5 * (self.NavKeyWidth),
												   cvertcenter),
											   size=(self.NavKeyWidth, self.NavKeyHeight), gaps=True)
		self.backkey = toucharea.ManualKeyDesc(self, 'Nav>' + 'Back', ('Back',),
											   self.CmdKeyCol, self.CmdCharCol, self.CmdCharCol,
											   proc=functools.partial(GoToScreen, BACKTOKEN),
											   center=(
												   self.starthorizspace + 1.5 * (self.NavKeyWidth),
												   cvertcenter),
											   size=(self.NavKeyWidth, self.NavKeyHeight), gaps=True)

		IncorporateParams(self, 'Screen',
						  {'CharColor', 'DimTO', 'PersistTO', 'BackgroundColor', 'CmdKeyCol', 'CmdCharCol',
						   'DefaultHub', 'ScreenTitle', 'ScreenTitleColor', 'ScreenTitleSize'}, screensection)
		AddUndefaultedParams(self, screensection, label=[screenname])

		try:
			self.DefaultHubObj = hubs.hubs.Hubs[self.DefaultHub]
		except KeyError:
			self.DefaultHubObj = None  # todo test what happens later or force this to be an exiting error
			logsupport.Logs.Log("Bad default hub name for screen: ", screenname, severity=ConsoleError)

		if self.ScreenTitle != '':
			# adjust space for a title
			self.ScreenTitleBlk = fonts.fonts.Font(self.ScreenTitleSize, bold=True).render(self.ScreenTitle, 0,
																						   wc(self.ScreenTitleColor))
			h = self.ScreenTitleBlk.get_height()
			w = self.ScreenTitleBlk.get_width()
			titlegap = h // 10  # todo is this the best way to space?
			self.startvertspace = self.startvertspace + h + titlegap
			self.useablevertspace = self.useablevertspace - h - titlegap
			self.titleoffset = self.starthorizspace + (self.useablehorizspace - w) // 2

		utilities.register_example('ScreenDesc', self)
示例#8
0
    def SetScreenContents(self):
        self.numplayers = 0  # if 0 then Sonos didn't get set up correctly
        self.numgroups = 0
        self.nms = []
        self.gpingrms = []
        self.PlayerInputs = []
        self.SourceSet = None
        self.SonosNodes = {}
        self.NodeVPos = []
        self.KeysSum = {}
        self.GCVPos = []
        self.KeysGC = {}
        self.KeysGpCtl = {}
        self.GPCtlVPos = []
        self.SrcSlotsVPos = []
        self.KeysSrc = {}
        self.ButLocSize = []
        self.SonosGroups = {}
        self.RoomNames = {}
        self.SlotToGp = []
        self.Subscreen = -1
        self.SourceItem = 0
        self.SourceSelection = ''
        self.ExtraSource = {}
        self.HubInterestList[self.HA.name] = {}
        for n, p in self.HA.DomainEntityReg['media_player'].items(
        ):  # todo can simplify if sonos becomes a separate module from media player
            if p.Sonos:
                self.SonosNodes[p.entity_id] = p
                self.SlotToGp.append('')
                self.HubInterestList[self.HA.name][p.entity_id] = p.entity_id
        self.numplayers = len(self.SonosNodes)

        for i in range(self.numplayers + 1):
            self.GCVPos.append(self.startvertspace + i * 50)

        # set up the control screen for a group
        self.ctlhgt = self.useablevertspace // (2 * self.numplayers + 2)
        for i in range(self.numplayers + 1):
            self.GPCtlVPos.append(self.startvertspace + i * 2 * self.ctlhgt)

        # set up the main summary screen
        vpos = self.startvertspace
        if self.numplayers != 0:
            self.roomheight = self.useablevertspace // self.numplayers
        else:
            self.roomheight = self.useablevertspace  # dummy value to avoid div by 0 in error case
        self.roomdisplayinfo = (1.5, 1, 1, 1)
        for n, p in self.SonosNodes.items():
            self.NodeVPos.append(vpos)
            vpos += self.roomheight
            lineheight = self.roomheight / (sum(self.roomdisplayinfo) /
                                            self.roomdisplayinfo[0])
            self.RoomNames[p.entity_id] = screenutil.CreateTextBlock(
                p.FriendlyName, lineheight, self.CharColor, True, FitLine=True)
        self.NodeVPos.append(vpos)

        for i in range(self.numplayers):
            self.KeysSum['Slot' + str(i)] = toucharea.TouchPoint(
                'Slot' + str(i),
                (hw.screenwidth // 2,
                 (self.NodeVPos[i] + self.NodeVPos[i + 1]) // 2),
                (hw.screenwidth, self.roomheight),
                proc=functools.partial(self.RoomSelect, i),
                procdbl=functools.partial(self.RoomSelectDbl, i))
            self.KeysGC['SlotGC' + str(i)] = toucharea.TouchPoint(
                'SlotGC' + str(i),
                (hw.screenwidth // 2,
                 (self.GCVPos[i] + self.GCVPos[i + 1]) // 2),
                (hw.screenwidth, 50),
                proc=functools.partial(self.GroupMemberToggle, i))
            butvert = self.GPCtlVPos[i] + self.ctlhgt * 1.5
            butsz = (self.ctlhgt, self.ctlhgt)
            self.ButLocSize.append(
                {'Dn': ((hw.screenwidth // 4, butvert), butsz)})
            self.KeysGpCtl['Dn' + str(i)] = toucharea.TouchPoint(
                'Dn' + str(i), (hw.screenwidth // 4, butvert),
                butsz,
                proc=functools.partial(self.VolChange, i, -1))

            self.ButLocSize[i]['Up'] = ((hw.screenwidth // 2, butvert), butsz)
            self.KeysGpCtl['Up' + str(i)] = toucharea.TouchPoint(
                'Up' + str(i), (hw.screenwidth // 2, butvert),
                butsz,
                proc=functools.partial(self.VolChange, i, 1))

            self.ButLocSize[i]['Mute'] = ((3 * hw.screenwidth // 4, butvert),
                                          butsz)
            self.KeysGpCtl['Mute' + str(i)] = toucharea.TouchPoint(
                'Mute' + str(i), (3 * hw.screenwidth // 4, butvert),
                butsz,
                proc=functools.partial(self.VolChange, i, 0))

        self.KeysGpCtl['Source'] = toucharea.ManualKeyDesc(
            self,
            'Source', ['Source'],
            self.BackgroundColor,
            self.CharColor,
            self.CharColor,
            center=(3 * hw.screenwidth // 4, self.GPCtlVPos[-1] + self.ctlhgt),
            size=(hw.screenwidth // 3, self.ctlhgt),
            KOn='',
            KOff='',
            proc=self.SetSource)

        self.KeysGpCtl['OKCtl'] = toucharea.ManualKeyDesc(
            self,
            'OKCtl', ['OK'],
            self.BackgroundColor,
            self.CharColor,
            self.CharColor,
            center=(hw.screenwidth // 4, self.GPCtlVPos[-1] + self.ctlhgt),
            size=(hw.screenwidth // 3, self.ctlhgt),
            KOn='',
            KOff='',
            proc=self.GpCtlOK)

        self.KeysGC['OK'] = toucharea.ManualKeyDesc(
            self,
            'OK', ['OK'],
            self.BackgroundColor,
            self.CharColor,
            self.CharColor,
            center=(hw.screenwidth // 2, self.GCVPos[-1] + 30),
            size=(hw.screenwidth // 4, self.ctlhgt),
            KOn='',
            KOff='',
            proc=self.GroupMemberOK)

        self.Keys = self.KeysSum
示例#9
0
    def __init__(self, screensection, screenname):
        config.SonosScreen = self  # todo hack to handle late appearing players
        debug.debugPrint('Screen', "New SonosScreenDesc ", screenname)
        screen.BaseKeyScreenDesc.__init__(self, screensection, screenname)
        screen.IncorporateParams(self, 'SonosScreen', {'KeyColor'},
                                 screensection)
        self.DullKeyColor = wc(self.KeyColor, .5, self.BackgroundColor)
        self.HA = self.DefaultHubObj
        self.Subscreen = -1

        self.SetScreenTitle(
            'Sonos', hw.screenheight / 12, self.CharColor
        )  # todo correct the fontsize and maybe the color choice and change to useable vert
        if not isinstance(self.DefaultHubObj, hasshub.HA):
            logsupport.Logs.Log("Sonos Default Hub is not HA hub",
                                severity=ConsoleError,
                                tb=False)
            return

        self.SetScreenContents()

        if self.numplayers == 0:
            logsupport.Logs.Log("No Sonos Players reported - check network",
                                severity=ConsoleWarning)
            return

        # set up source selection screen
        self.SourceSlot = []
        vpos = self.startvertspace  # todo add buffer?
        self.sourceslots = 8
        self.sourceheight = self.useablevertspace // (
            self.sourceslots + 1)  # allow space at bottom right for arrow

        for i in range(self.sourceslots):
            self.SrcSlotsVPos.append(vpos)
            self.KeysSrc['Src' + str(i)] = toucharea.TouchPoint(
                'Scr' + str(i),
                (hw.screenwidth // 2, vpos + self.sourceheight // 2),
                (hw.screenwidth, self.sourceheight),
                proc=functools.partial(self.PickSource, i))
            vpos += self.sourceheight
            self.SourceSlot.append('')
        self.SrcPrev = (
            hw.screenwidth - self.sourceheight - self.HorizBorder,
            self.startvertspace - self.sourceheight // 2
        )  # todo change to horizstart + useablehoriz - sourceheight
        self.SrcNext = (hw.screenwidth - self.sourceheight - self.HorizBorder,
                        vpos + self.sourceheight // 2 + 10)  # for appearance
        self.KeysSrc['Prev'] = toucharea.TouchPoint(
            'Prev',
            self.SrcPrev, (self.sourceheight, self.sourceheight),
            proc=functools.partial(self.PrevNext, False))
        self.KeysSrc['Next'] = toucharea.TouchPoint(
            'Next',
            self.SrcNext, (self.sourceheight, self.sourceheight),
            proc=functools.partial(self.PrevNext, True))
        self.KeysSrc['OKSrc'] = toucharea.ManualKeyDesc(
            self,
            'OKSrc', ['OK'],
            self.BackgroundColor,
            self.CharColor,
            self.CharColor,
            center=(self.SrcNext[0] - 2.5 * self.sourceheight,
                    self.SrcNext[1]),
            size=(2 * self.sourceheight, self.sourceheight),
            KOn='',
            KOff='',
            proc=functools.partial(self.PickSourceOK, True))
        self.KeysSrc['CnclSrc'] = toucharea.ManualKeyDesc(
            self,
            'CnclSrc', ['Back'],
            self.BackgroundColor,
            self.CharColor,
            self.CharColor,
            center=(self.SrcNext[0] - 5 * self.sourceheight, self.SrcNext[1]),
            size=(2 * self.sourceheight, self.sourceheight),
            KOn='',
            KOff='',
            proc=functools.partial(self.PickSourceOK, False))

        utilities.register_example("SonosScreenDesc", self)
示例#10
0
    def __init__(self, masterscreen, choosername, slots, screenhgt, voffset,
                 proc):
        """
		Create subscreen(s) that allow choosing from a list
		:param masterscreen: the real screen for which this operates
		:param slots: number of slots to create per selection screen
		:param screenhgt: height of the area to be used for the list
		:param voffset: vertical offset for start of area to be used
		:param proc: function called with resultant selection index or -1 if cancelled
		"""
        screen.ScreenDesc.__init__(self, {},
                                   masterscreen.name + '-' + choosername +
                                   '-Chooser',
                                   parentscreen=masterscreen)
        self.Result = proc
        self.masterscreen = masterscreen
        self.selection = -1
        self.itemlist = []
        self.firstitem = 0
        self.NumSlots = slots
        self.ListKeySlots = {}
        self.SlotsVPos = []
        self.SlotItem = []
        vpos = voffset
        self.BackgroundColor = self.masterscreen.BackgroundColor
        self.DullKeyColor = wc(self.masterscreen.KeyColor, .5,
                               self.BackgroundColor)
        self.CharColor = self.masterscreen.CharColor
        self.sourceheight = screenhgt // (self.NumSlots + 1)

        for i in range(self.NumSlots):
            self.SlotsVPos.append(vpos)
            self.ListKeySlots['Src' + str(i)] = toucharea.TouchPoint(
                'Slot' + str(i),
                (hw.screenwidth // 2, vpos + self.sourceheight // 2),
                (hw.screenwidth, self.sourceheight),
                proc=functools.partial(self.PickItem, i))
            vpos += self.sourceheight
            self.SlotItem.append('')
        self.SrcPrev = (hw.screenwidth - self.sourceheight - self.HorizBorder,
                        voffset - self.sourceheight // 2)
        self.SrcNext = (hw.screenwidth - self.sourceheight - self.HorizBorder,
                        vpos + self.sourceheight // 2 + 10)  # for appearance
        self.ListKeySlots['Prev'] = toucharea.TouchPoint(
            'Prev',
            self.SrcPrev, (self.sourceheight, self.sourceheight),
            proc=functools.partial(self.PrevNext, False))
        self.ListKeySlots['Next'] = toucharea.TouchPoint(
            'Next',
            self.SrcNext, (self.sourceheight, self.sourceheight),
            proc=functools.partial(self.PrevNext, True))
        self.ListKeySlots['OKSrc'] = toucharea.ManualKeyDesc(
            self,
            'OKSrc', ['OK'],
            self.BackgroundColor,
            self.CharColor,
            self.CharColor,
            center=(self.SrcNext[0] - 2.5 * self.sourceheight,
                    self.SrcNext[1]),
            size=(2 * self.sourceheight, self.sourceheight),
            KOn='',
            KOff='',
            proc=functools.partial(self.PickItemOK, True))
        '''
示例#11
0
    def __init__(self, screensection, screenname):
        screen.ScreenDesc.__init__(self, screensection, screenname)
        debug.debugPrint('Screen', "New OctoPrintScreenDesc ", screenname)
        self.JobKeys = {}
        self.files = []
        self.filepaths = []
        self.PowerKeys = {}

        # status of printer
        self.OPstate = 'unknown'
        self.OPfile = ''
        self.OPcomppct = 'unknown'
        self.OPtimeleft = 'unknown'
        self.OPtemp1 = 'unknown'
        self.OPbed = 'unknown'
        self.ValidState = False

        self.PollTimer = timers.RepeatingPost(5.0,
                                              paused=True,
                                              start=True,
                                              name=self.name + '-Poll',
                                              proc=self.RefreshOctoStatus)

        screen.IncorporateParams(self, 'OctoPrint', {'KeyColor'},
                                 screensection)
        screen.AddUndefaultedParams(self, screensection, address='', apikey='')
        self.title, th, self.tw = screenutil.CreateTextBlock(
            self.name, hw.screenheight / 12, self.CharColor,
            True)  # todo switch to new screen sizing for title

        self.errornotice, th, self.errwid = screenutil.CreateTextBlock(
            'Access Error', hw.screenheight / 12, self.CharColor,
            True)  # todo fix for new vertspace
        self.titlespace = th + hw.screenheight / 32
        useablescreenheight = hw.screenheight - self.TopBorder - self.BotBorder - self.titlespace
        ctlpos = useablescreenheight / 5
        ctlhgt = int(ctlpos * .9)
        self.head = {"X-Api-Key": self.apikey}
        self.url = 'http://' + self.address + ':5000'
        retp = self.OctoGet('connection')
        if retp.status_code != 200:
            logsupport.Logs.Log('Access to OctoPrint denied: ',
                                retp.text,
                                severity=logsupport.ConsoleWarning)

        self.PowerKeys['printeron'] = toucharea.ManualKeyDesc(
            self,
            'PowerOn',
            ['Power On'],
            self.KeyColor,
            'white',
            'black',
            #															  self.CharColor, self.CharColor,
            center=(hw.screenwidth // 4, ctlpos * 4),
            size=(hw.screenwidth // 3, ctlhgt),
            KOn='',
            KOff='',
            proc=functools.partial(self.Power, 'printeron'))
        self.PowerKeys['printeroff'] = toucharea.ManualKeyDesc(
            self,
            'PowerOff',
            ['Power Off'],
            self.KeyColor,
            'white',
            'black',
            #															   self.CharColor, self.CharColor,
            center=(3 * hw.screenwidth // 4, ctlpos * 4),
            size=(hw.screenwidth // 3, ctlhgt),
            KOn='',
            KOff='',
            proc=functools.partial(self.Power, 'printeroff'))
        self.PowerKeys['connect'] = toucharea.ManualKeyDesc(
            self,
            'Connect',
            ['Connect'],
            self.KeyColor,
            'white',
            'black',
            #															self.CharColor, self.CharColor,
            center=(hw.screenwidth // 4, ctlpos * 5),
            size=(hw.screenwidth // 3, ctlhgt),
            KOn='',
            KOff='',
            proc=functools.partial(self.Connect, 'connect'))
        self.PowerKeys['disconnect'] = toucharea.ManualKeyDesc(
            self,
            'Disconnect',
            ['Disconnect'],
            self.KeyColor,
            'white',
            'black',
            #															   self.CharColor, self.CharColor,
            center=(3 * hw.screenwidth // 4, ctlpos * 5),
            size=(hw.screenwidth // 3, ctlhgt),
            KOn='',
            KOff='',
            proc=functools.partial(self.Connect, 'disconnect'))
        self.PowerPlusKeys = self.PowerKeys.copy()
        self.PowerPlusKeys['Print'] = toucharea.ManualKeyDesc(
            self,
            'Print', ['Print'],
            self.KeyColor,
            self.CharColor,
            self.CharColor,
            center=(hw.screenwidth // 2, ctlpos * 6),
            size=(hw.screenwidth // 3, ctlhgt),
            KOn='',
            KOff='',
            proc=self.SelectFile)

        self.JobKeys['Cancel'] = toucharea.ManualKeyDesc(
            self,
            'Cancel', ['Cancel'],
            self.KeyColor,
            self.CharColor,
            self.CharColor,
            center=(hw.screenwidth // 4, ctlpos * 5),
            size=(hw.screenwidth // 3, ctlhgt),
            KOn='',
            KOff='',
            proc=self.PreDoCancel,
            Verify=True)
        self.JobKeys['Pause'] = toucharea.ManualKeyDesc(
            self,
            'Pause', ['Pause'],
            self.KeyColor,
            self.CharColor,
            self.CharColor,
            center=(3 * hw.screenwidth // 4, ctlpos * 5),
            size=(hw.screenwidth // 3, ctlhgt),
            KOn='',
            KOff='',
            proc=self.PreDoPause,
            Verify=True)
        self.VerifyScreenCancel = supportscreens.VerifyScreen(
            self.JobKeys['Cancel'], ('Cancel', 'Job'), ('Back', ),
            self.DoCancel, None, screen, self.KeyColor, self.CharColor,
            self.CharColor, True, None)
        self.VerifyScreenPause = supportscreens.VerifyScreen(
            self.JobKeys['Pause'], ('Pause', 'Job'), ('Back', ), self.DoCancel,
            None, screen, self.KeyColor, self.CharColor, self.CharColor, True,
            None)
        self.FileSubscreen = supportscreens.ListChooserSubScreen(
            self, 'FileList', 8, useablescreenheight, self.titlespace,
            self.FilePick)
    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)
示例#13
0
    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)