Esempio n. 1
0
    def Assign(alert):
        """
		params: Var Var, . . .
		"""
        params = (alert.param, ) if isinstance(alert.param,
                                               str) else alert.param
        val = -99999
        for p in params:
            item = p.split('=')
            # noinspection PyBroadException
            try:
                val = float(item[1].strip())
            except:
                try:
                    val = valuestore.GetVal(item[1].strip())
                except BaseException as e:
                    logsupport.Logs.Log(
                        "Error setting var in AssignVar alert: ",
                        str(item[1]),
                        ' to ',
                        repr(val),
                        severity=ConsoleWarning)
                    logsupport.Logs.Log("Exception was: ",
                                        repr(e),
                                        severity=ConsoleWarning)
            valuestore.SetVal(item[0].strip(), val)
            logsupport.Logs.Log("Var ",
                                item[0],
                                ' set to value of ',
                                item[1],
                                ' (',
                                val,
                                ')',
                                severity=ConsoleDetail)
Esempio n. 2
0
    def Command(alert):
        if not isinstance(alert.trigger, alerttasks.VarChangeTrigger):
            logsupport.Logs.Log('Net Command not triggered by variable',
                                severity=ConsoleWarning)
        varval = valuestore.GetVal(alert.trigger.var)
        valuestore.SetVal(alert.trigger.var, 0)
        if varval == 1:
            logsupport.Logs.Log('Remote restart')
            exitutils.Exit_Screen_Message('Remote restart requested',
                                          'Remote Restart')
            config.terminationreason = 'remote restart'
            exitutils.Exit(exitutils.REMOTERESTART)
        elif varval == 2:
            logsupport.Logs.Log('Remote reboot')
            exitutils.Exit_Screen_Message('Remote reboot requested',
                                          'Remote Reboot')
            config.terminationreason = 'remote reboot'
            exitutils.Exit(exitutils.REMOTEREBOOT)
        elif varval == 3:
            logsupport.Logs.Log('Remote download stable')
            maintscreen.fetch_stable()
        elif varval == 4:
            logsupport.Logs.Log('Remote download beta')
            maintscreen.fetch_beta()
        elif varval == 5:
            logsupport.Logs.Log('Remote set stable')
            subprocess.Popen('sudo rm /home/pi/usebeta', shell=True)
        elif varval == 6:
            logsupport.Logs.Log('Remote set beta')
            subprocess.Popen('sudo touch /home/pi/usebeta', shell=True)
        elif varval == 7:
            logsupport.Logs.Log('Remote history buffer dump')
            entrytime = time.strftime('%m-%d-%y %H:%M:%S')
            historybuffer.DumpAll('Command Dump', entrytime)
        elif varval == 8:
            logsupport.Logs.Log('Remote error indicator cleared')
            config.sysStore.ErrorNotice = -1
        elif varval in range(100, 100 + len(debug.DbgFlags)):
            flg = debug.DbgFlags[varval - 100]
            valuestore.SetVal(('Debug', flg), True)
            logsupport.Logs.Log('Remote set debug ', flg)
        elif varval in range(200, 200 + len(debug.DbgFlags)):
            flg = debug.DbgFlags[varval - 200]
            valuestore.SetVal(('Debug', flg), False)
            logsupport.Logs.Log('Remote clear debug ', flg)
        elif varval in range(300, 310):
            valuestore.SetVal(('Debug', 'LogLevel'), varval - 300)
            logsupport.Logs.Log('Remote set LogLevel to ', varval - 300)

        else:
            logsupport.Logs.Log('Unknown remote command: ', varval)
Esempio n. 3
0
 def IsTrue(self):
     val = -99999
     try:
         val = valuestore.GetVal(self.var)
         if self.test == 'EQ':
             return int(val) == int(self.value)
         elif self.test == 'NE':
             return int(val) != int(self.value)
         else:
             logsupport.Logs.Log('Bad test in IsTrue',
                                 self.test,
                                 severity=ConsoleError)
             return False  # shouldn't happen
     except Exception as E:
         logsupport.Logs.Log(
             'Exception in IsTrue: {} Test: {} Val: {} Compare Val: {}'.
             format(repr(E), self.test, val, self.value),
             severity=ConsoleError)
         return False
Esempio n. 4
0
	def PaintKey(self, ForceDisplay=False, DisplayState=True):
		# create the images here dynamically then let lower methods do display, blink etc.
		val = valuestore.GetVal(self.Var)
		if self.oldval != val:
			self.oldval = val
			oncolor = wc(self.KeyColorOn)
			offcolor = wc(self.KeyColorOff)
			lab = []
			for i in self.displayoptions:
				if i.Chooser[0] <= val <= i.Chooser[1]:
					lab = i.Label[:]

					oncolor = tint(i.Color)
					offcolor = wc(i.Color)
					break
			if not lab: lab = self.KeyLabelOn[:]
			lab2 = []
			for line in lab:
				lab2.append(line.replace('$', str(val)))
			self.BuildKey(oncolor, offcolor)
			self.SetKeyImages(lab2, lab2, 0, True)
			self.ScheduleBlinkKey(self.Blink)
		super(VarKey, self).PaintKey(ForceDisplay, DisplayState)
Esempio n. 5
0
	def InitDisplay(self):
		debug.debugPrint("Screen", "SetVarValue Key.InitDisplay ", self.Screen.name, self.name)
		self.Value = valuestore.GetVal(self.Var)
		super(SetVarValueKey, self).InitDisplay()
Esempio n. 6
0
	def VarKeyPressed(self):
		try:
			i = self.ValueSeq.index(valuestore.GetVal(self.Var))
		except ValueError:
			i = len(self.ValueSeq) - 1
		valuestore.SetVal(self.Var, self.ValueSeq[(i + 1) % len(self.ValueSeq)])
Esempio n. 7
0
    def ShowScreen(self, conditions):
        # todo given the useable vert space change should check for overflow or auto size font

        self.store.BlockRefresh()

        vert_off = self.startvertspace

        if not self.store.ValidWeather:
            renderedlines = [
                fonts.fonts.Font(45, "").render(x, 0, wc(self.CharColor))
                for x in self.store.Status
            ]
            for l in renderedlines:
                hw.screen.blit(
                    l, ((hw.screenwidth - l.get_width()) / 2, vert_off))
                vert_off = vert_off + 60  # todo use useable space stuff and vert start
        else:
            renderedlines = []

            if self.LocationSize != 0:
                locblk = fonts.fonts.Font(self.LocationSize, "").render(
                    self.fmt.format("{d}",
                                    d=self.store.GetVal(('Cond', 'Location'))),
                    0, wc(self.CharColor))
                hw.screen.blit(
                    locblk,
                    ((hw.screenwidth - locblk.get_width()) / 2, vert_off))
                vert_off = vert_off + locblk.get_height(
                ) + 10  # todo gap of 10 pixels is arbitrary

            h = vert_off
            if conditions:
                renderedlines.append(
                    CreateWeathBlock(self.condformat, self.condfields, "",
                                     [45, 25, 35], self.CharColor,
                                     (self.location, 'Cond', 'Icon'), False))
                h = h + renderedlines[-1].get_height()
                renderedlines.append(
                    CreateWeathBlock(self.dayformat, self.dayfields, "", [30],
                                     self.CharColor, None, True))
                h = h + renderedlines[-1].get_height()
                renderedlines.append(
                    CreateWeathBlock(self.footformat, self.footfields, "",
                                     [25], self.CharColor, None, True))
                h = h + renderedlines[-1].get_height()
                s = (self.useablevertspace - h) / (
                    len(renderedlines) - 1) if len(renderedlines) > 1 else 0
                for l in renderedlines:
                    hw.screen.blit(
                        l, ((hw.screenwidth - l.get_width()) / 2, vert_off))
                    vert_off = vert_off + l.get_height() + s

            else:
                fcstlines = 0
                fcstdays = valuestore.GetVal((self.location, 'FcstDays'))
                maxfcstwidth = 0
                if fcstdays > 0:
                    for i in range(fcstdays):
                        renderedlines.append(
                            CreateWeathBlock(
                                self.fcstformat,
                                self.fcstfields,
                                "",
                                [25],
                                self.CharColor,
                                # todo compute font size based on useable
                                (self.location, 'Fcst', 'Icon'),
                                False,
                                day=i))
                        if renderedlines[-1].get_width() > maxfcstwidth:
                            maxfcstwidth = renderedlines[-1].get_width()
                        fcstlines += 1
                else:
                    renderedlines.append(
                        fonts.fonts.Font(35,
                                         "").render("No Forecast Available", 0,
                                                    wc(self.CharColor)))

                if hw.screenwidth > 350:
                    h = h + renderedlines[-1].get_height() * 5
                    fcstlines = 2 + (fcstlines + 1) / 2
                    usewidth = hw.screenwidth / 2
                else:
                    h = h + renderedlines[-1].get_height() * 5
                    fcstlines = 5
                    usewidth = hw.screenwidth
                s = (self.useablevertspace - h) / (fcstlines + 1)

                startvert = vert_off
                horiz_off = (usewidth - maxfcstwidth) / 2
                for dy, fcst in enumerate(renderedlines):
                    hw.screen.blit(fcst, (horiz_off, vert_off))
                    vert_off = vert_off + s + fcst.get_height()
                    if (dy == 4) and (hw.screenwidth > 350):
                        horiz_off = horiz_off + usewidth
                        vert_off = startvert

        pygame.display.update()
Esempio n. 8
0
"""
maintscreen.SetUpMaintScreens()
logsupport.Logs.Log("Built Maintenance Screen")

LogBadParams(ParsedConfigFile, "Globals")
LogBadParams(alertspec, "Alerts")
"""
Dump documentation if development version
"""
# if config.sysStore.versionname == 'development':
#	utilities.DumpDocumentation()
"""
Run the main console loop
"""
for n in alerttasks.monitoredvars:  # make sure vars used in alerts are updated to starting values
    valuestore.GetVal(n)
config.sysStore.ErrorNotice = -1
gui = threading.Thread(name='GUI',
                       target=screens.DS.MainControlLoop,
                       args=(screens.HomeScreen, ))
config.ecode = 99
gui.start()

gui.join()
logsupport.Logs.Log("Main line exit: ", config.ecode)
timers.ShutTimers(config.terminationreason)
logsupport.Logs.Log('Console exiting')
hw.GoBright(100)
pygame.quit()
logsupport.DevPrint('Exit handling done')
Esempio n. 9
0
def CreateWeathBlock(Format, Fields, WeathFont, FontSize, WeathColor, icon, centered, day=-1, useicon=True,
					 maxiconsize=0):
	rf = []
	fh = 0
	fw = 0
	FS = FontSize[:] if isinstance(FontSize, list) else [FontSize]
	fsize = int(FS.pop(0))
	usefont = fonts.fonts.Font(fsize, WeathFont)
	fcstdays = 0

	fld = ''
	vals = []
	try:
		for fld in Fields:
			if day == -1:
				t = valuestore.GetVal(fld)
				if callable(t):
					vals.append(t())
				else:
					vals.append(t)
			else:
				fcstdays = valuestore.GetVal((fld[0], 'FcstDays'))
				if day < fcstdays:
					t = valuestore.GetVal(fld + (day,))
					if callable(t):
						vals.append(t())
					else:
						vals.append(t)
				else:
					vals.append(None)
					logsupport.Logs.Log(
						"Attempt to forecast(day " + str(day) + ") beyond " + str(fcstdays) + " returned",
						severity=ConsoleDetailHigh)
	except Exception as e:
		logsupport.Logs.Log('Weather Block field access error: ' + str(fld) + ' Exc: ' + str(e))

	try:
		for f in Format:
			rf.append(usefont.render(WFormatter().format(f, d=vals), 0, wc(WeathColor)))
			fh += rf[-1].get_height()
			if rf[-1].get_width() > fw: fw = rf[-1].get_width()
			if FS:
				fsize = int(FS.pop(0))
				usefont = fonts.fonts.Font(fsize, WeathFont)
	except Exception as e:
		logsupport.Logs.Log('TimeTemp Weather Formatting Error: ', repr(e), severity=ConsoleWarning)
		if isinstance(e, KeyError):
			logsupport.Logs.Log(' No such weather field: ', e.args, severity=ConsoleWarning)
		rf.append(usefont.render('Weather N/A', 0, wc(WeathColor)))
		fh = rf[-1].get_height() * len(Format)  # force the height to always be equal even if error
		if rf[-1].get_width() > fw: fw = rf[-1].get_width()
	if icon is not None:
		iconsize = fh if maxiconsize == 0 else min(fh, maxiconsize)
		totw = fw + iconsize + ICONSPACE
		hoff = iconsize + ICONSPACE
		if day == -1:
			iconref = icon[1:]
		else:
			if day < fcstdays:
				iconref = icon[1:] + (day,)
			else:
				iconref = None
				logsupport.Logs.Log(
					"Attempt to forecast(day " + str(day) + ") beyond " + str(fcstdays) + " returned by provider",
					severity=ConsoleDetailHigh)
	else:
		iconref = None
		iconsize = 0
		totw = fw
		hoff = 0
	fsfc = pygame.Surface((totw, fh))
	fsfc.set_colorkey(wc('black'))
	v = 0
	# noinspection PyBroadException
	try:
		if iconref is not None:
			tmp = pygame.transform.smoothscale(valuestore.ValueStores[icon[0]].GetVal(iconref), (iconsize, iconsize))
			# R = pygame.Rect((0, 0), (tmp.get_height(), tmp.get_width()))
			# pygame.draw.rect(fsfc, (128, 128, 128), R, 3)
			# print('Scale: '+str(tmp.get_height())+ ' ' + str(valuestore.ValueStores[icon[0]].GetVal(iconref)) )
			fsfc.blit(tmp, (0, (fh - iconsize) // 2))
	except:
		if useicon:
			logsupport.Logs.Log("Internal error - missing icon for: ", str(icon[0]), str(iconref),
								severity=ConsoleWarning)
	# logsupport.Logs.Log("Temp msg: ", valuestore.ValueStores([icon[0], ('Cond', 'IconURL')]))
	for l in rf:
		if centered:
			fsfc.blit(l, (hoff + (fw - l.get_width()) / 2, v))
		else:
			fsfc.blit(l, (hoff, v))
		v += l.get_height()
	return fsfc