<commit_before># noinspection PyProtectedMember
import pygame
from configobj import Section

import debug
import keyspecs
import logsupport
import screen
import screens.__screens as screens
import utilities
from logsupport import ConsoleWarning


class KeyScreenDesc(screen.BaseKeyScreenDesc):
	def __init__(self, screensection, screenname, parentscreen=None, Clocked=0):
		super().__init__(screensection, screenname, parentscreen=parentscreen, Clocked=Clocked)
		debug.debugPrint('Screen', "New KeyScreenDesc ", screenname)

		# Build the Key objects
		for keyname in screensection:
			if isinstance(screensection[keyname], Section):
				self.Keys[keyname] = keyspecs.CreateKey(self, screensection[keyname], keyname)

		self.LayoutKeys()

		debug.debugPrint('Screen', "Active Subscription List for ", self.name, " will be:")
		for h, l in self.HubInterestList.items():
			for i, j in l.items():
				m1 = "  Subscribe on hub {} node: {} {}".format(h, i, j.name)
				m2 = ""
				try:
					m2 = ":{} via {}".format(j.ControlObj.name, j.DisplayObj.name)
				except:
					pass
				debug.debugPrint('Screen', m1 + m2)

		utilities.register_example("KeyScreenDesc", self)

	def __repr__(self):
		return screen.ScreenDesc.__repr__(self) + "\r\n     KeyScreenDesc:" + ":<" + str(self.Keys) + ">"

	def InitDisplay(self, nav):
		debug.debugPrint("Screen", "Keyscreen InitDisplay: ", self.name)
		for K in self.Keys.values():
			K.InitDisplay()
		super().InitDisplay(nav)
		pygame.display.update()

	def NodeEvent(self, evnt):
		# Watched node reported change event is ("Node", addr, value, seq)
		debug.debugPrint('Screen', evnt)

		if evnt.node is None:  # all keys for this hub
			for _, K in self.HubInterestList[evnt.hub].items():
				logsupport.Logs.Log('Node event to keyscreen with no node {}'.format(evnt), severity=ConsoleWarning)
				debug.debugPrint('Screen', 'KS Wildcard ISYEvent ', K.name, evnt)
				K.UnknownState = True
				K.PaintKey()
				pygame.display.update()
		elif evnt.node != 0:
			# noinspection PyBroadException
			try:
				K = self.HubInterestList[evnt.hub][evnt.node]
			except:
				debug.debugPrint('Screen', 'Bad key to KS - race?', self.name, str(evnt.node))
				return  # treat as noop
			debug.debugPrint('Screen', 'KS ISYEvent ', K.name, evnt, str(K.State))
			if hasattr(K, 'HandleNodeEvent'):  # todo make all handle event key specifig
				K.HandleNodeEvent(evnt)
			else:
				logsupport.Logs.Log('Generic node event??? {} {}'.format(K.name, evnt),
									severity=ConsoleWarning)
				if not isinstance(evnt.value, int):
					logsupport.Logs.Log("Node event with non integer state: " + evnt,
										severity=ConsoleWarning)
					evnt.value = int(evnt.value)
				K.State = not (evnt.value == 0)  # K is off (false) only if state is 0
				K.UnknownState = True if evnt.value == -1 else False
				K.PaintKey()
				pygame.display.update()
		else:
			# noinspection PyBroadException
			logsupport.Logs.Log('varchange via Node event? {} {}'.format(self.name, evnt), severity=ConsoleWarning)

	def VarEvent(self, evnt):
		print('Var event called {}'.format(evnt))
		try:
			K = self.Keys[evnt.varinfo[0]]
			K.PaintKey()
			pygame.display.update()
		except:<commit_msg>Update keyscreen to use clocked support for titles Clean up old screen update<commit_after># noinspection PyProtectedMember
import pygame
from configobj import Section

import debug
import keyspecs
import logsupport
import screen
import screens.__screens as screens
import utilities
from logsupport import ConsoleWarning


class KeyScreenDesc(screen.BaseKeyScreenDesc):
	def __init__(self, screensection, screenname, parentscreen=None, Clocked=0):
		super().__init__(screensection, screenname, parentscreen=parentscreen, Clocked=Clocked)
		debug.debugPrint('Screen', "New KeyScreenDesc ", screenname)

		# Build the Key objects
		for keyname in screensection:
			if isinstance(screensection[keyname], Section):
				self.Keys[keyname] = keyspecs.CreateKey(self, screensection[keyname], keyname)

		self.LayoutKeys()

		debug.debugPrint('Screen', "Active Subscription List for ", self.name, " will be:")
		for h, l in self.HubInterestList.items():
			for i, j in l.items():
				m1 = "  Subscribe on hub {} node: {} {}".format(h, i, j.name)
				m2 = ""
				try:
					m2 = ":{} via {}".format(j.ControlObj.name, j.DisplayObj.name)
				except:
					pass
				debug.debugPrint('Screen', m1 + m2)

		utilities.register_example("KeyScreenDesc", self)

	def __repr__(self):
		return screen.ScreenDesc.__repr__(self) + "\r\n     KeyScreenDesc:" + ":<" + str(self.Keys) + ">"

	def InitDisplay(self, nav, specificrepaint = None):
		debug.debugPrint("Screen", "Keyscreen InitDisplay: ", self.name)
		for K in self.Keys.values():
			K.InitDisplay()
		super().InitDisplay(nav)

	def NodeEvent(self, evnt):
		# Watched node reported change event is ("Node", addr, value, seq)
		debug.debugPrint('Screen', evnt)

		if evnt.node is None:  # all keys for this hub
			for _, K in self.HubInterestList[evnt.hub].items():
				logsupport.Logs.Log('Node event to keyscreen with no node {}'.format(evnt), severity=ConsoleWarning)
				debug.debugPrint('Screen', 'KS Wildcard ISYEvent ', K.name, evnt)
				K.UnknownState = True
				K.PaintKey()
				pygame.display.update()
		elif evnt.node != 0:
			try:
				K = self.HubInterestList[evnt.hub][evnt.node]
			except:
				debug.debugPrint('Screen', 'Bad key to KS - race?', self.name, str(evnt.node))
				return  # treat as noop
			debug.debugPrint('Screen', 'KS ISYEvent ', K.name, evnt, str(K.State))
			if hasattr(K, 'HandleNodeEvent'):  # todo make all handle event key specifig
				K.HandleNodeEvent(evnt)
			else:
				logsupport.Logs.Log('Generic node event??? {} {}'.format(K.name, evnt),
									severity=ConsoleWarning)
				if not isinstance(evnt.value, int):
					logsupport.Logs.Log("Node event with non integer state: " + evnt,
										severity=ConsoleWarning)
					evnt.value = int(evnt.value)
				K.State = not (evnt.value == 0)  # K is off (false) only if state is 0
				K.UnknownState = True if evnt.value == -1 else False
				K.PaintKey()
				pygame.display.update()
		else:
			logsupport.Logs.Log('varchange via Node event? {} {}'.format(self.name, evnt), severity=ConsoleWarning)

	def VarEvent(self, evnt):
		print('Var event called {}'.format(evnt))
		try:
			K = self.Keys[evnt.varinfo[0]]
			K.PaintKey()
			pygame.display.update()
		except:
{'fraction_non_alphanumeric': 0.13256032591664055, 'fraction_numerical': 0.0034471952366029457, 'mean_word_length': 4.01413982717989, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3353168', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2097, 'n_words': 548}