def dosectioninit(self, thisscreen, keysection, keyname): self.userstore = paramstore.ParamStore('Screen-' + thisscreen.name + '-' + keyname, dp=thisscreen.userstore, locname=keyname) TouchPoint.__init__(self, keyname, (0, 0), (0, 0)) screen.IncorporateParams( self, 'TouchArea', { 'KeyColor', 'KeyOffOutlineColor', 'KeyOnOutlineColor', 'KeyCharColorOn', 'KeyCharColorOff', 'KeyOutlineOffset', 'KeyColorOn', 'KeyColorOff', 'KeyLabelOn', 'KeyLabelOff' }, keysection) screen.AddUndefaultedParams(self, keysection, FastPress=0, Verify=False, Blink=0, label=['']) if self.Verify: screen.AddUndefaultedParams(thisscreen, keysection, GoMsg=['Proceed'], NoGoMsg=['Cancel']) self.Screen = thisscreen self.State = True
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)
def __init__(self, thisscreen, keysection, kn, keytype): keyname, self.Hub = _resolvekeyname(kn, thisscreen.DefaultHubObj) #self.ControlObj = None # object on which to make operation calls self.DisplayObj = None # object whose state is reflected in key debug.debugPrint('Screen', " New ", keytype, " Key Desc ", keyname) ManualKeyDesc.__init__(self, thisscreen, keysection, keyname) screen.AddUndefaultedParams(self, keysection, SceneProxy='', NodeName='') if keyname == '*Action*': keyname = self.NodeName # special case for alert screen action keys that always have same name todo - can nodename ever be explicitly set otherwise? self.ControlObj, self.DisplayObj = self.Hub.GetNode(keyname, self.SceneProxy) if self.ControlObjUndefined(): debug.debugPrint('Screen', "Screen", keyname, "unbound") logsupport.Logs.Log('Key Binding missing: ' + self.name, severity=ConsoleWarning) if self.Verify: self.VerifyScreen = supportscreens.VerifyScreen(self, self.GoMsg, self.NoGoMsg, self.Verified, None, thisscreen, self.KeyColorOff, thisscreen.BackgroundColor, thisscreen.CharColor, self.State, thisscreen.HubInterestList) self.Proc = self.VerifyScreen.Invoke # todo make this a goto key; make verify screen always do a pop and get rid of the switch screens below else: self.Proc = self.KeyPressAction self.ProcDblTap = self.KeyPressActionDbl if keytype == 'ONOFF': self.KeyAction = 'OnOff' elif keytype == 'ON': self.KeyAction = 'On' else: self.KeyAction = 'Off' utilities.register_example("OnOffKey", self)
def __init__(self, thisscreen, keysection, keyname): debug.debugPrint('Screen', " New SetVar Key Desc ", keyname) ManualKeyDesc.__init__(self, thisscreen, keysection, keyname) screen.AddUndefaultedParams(self, keysection, VarType='undef', Var='', Value=0) try: self.Proc = self.SetVarKeyPressed if self.VarType != 'undef': # deprecate if self.VarType == 'State': self.VarName = (hubs.hubs.defaulthub.name, 'State', self.Var) # use default hub for each of these 2 elif self.VarType == 'Int': self.VarName = (hubs.hubs.defaulthub.name, 'Int', self.Var) elif self.VarType == 'Local': self.VarName = ('LocalVars', self.Var) else: logsupport.Logs.Log('VarType not specified for key ', self.Var, ' on screen ', thisscreen.name, severity=ConsoleWarning) self.Proc = ErrorKey logsupport.Logs.Log('VarKey definition using depreacted VarKey ', self.VarType, ' change to ', valuestore.ExternalizeVarName(self.VarName), severity=ConsoleWarning) else: self.VarName = self.Var.split(':') except Exception as e: logsupport.Logs.Log('Var key error on screen: ' + thisscreen.name + ' Var: ' + self.Var, severity=ConsoleWarning) logsupport.Logs.Log('Excpt: ', str(e)) self.Proc = ErrorKey utilities.register_example("SetVarKey", self)
def __init__(self, thisscreen, keysection, keyname): debug.debugPrint('Screen', " New SetVarValue Key Desc ", keyname) self.Value = None ManualKeyDesc.__init__(self, thisscreen, keysection, keyname) screen.AddUndefaultedParams(self, keysection, Var='') self.Proc = self.SetVarValue utilities.register_example("SetVarValueKey", self)
def __init__(self, thisscreen, keysection, keyname): debug.debugPrint('Screen', " New GoTo Key ", keyname) ManualKeyDesc.__init__(self, thisscreen, keysection, keyname) screen.AddUndefaultedParams(self, keysection, ScreenName='**unspecified**') self.targetscreen = None GoToTargetList[self] = self.ScreenName self.Proc = self.GoToKeyPressed
def docodeinit(self, thisscreen, keyname, label, bcolor, charcoloron, charcoloroff, center=(0, 0), size=(0, 0), KOn=None, KOff=None, proc=None, procdbl=None, KCon='', KCoff='', KLon=('', ), KLoff=('', ), State=True, Blink=0, Verify=False, gaps=False): # NOTE: do not put defaults for KOn/KOff in signature - imports and arg parsing subtleties will cause error # because of when config is imported and what walues are at that time versus at call time self.userstore = paramstore.ParamStore('Screen-' + thisscreen.name + '-' + keyname, dp=thisscreen.userstore, locname=keyname) self.usekeygaps = gaps TouchPoint.__init__(self, keyname, center, size, proc=proc, procdbl=procdbl) self.Screen = thisscreen self.State = State self.Screen = thisscreen screen.IncorporateParams( self, 'TouchArea', { 'KeyColor': bcolor, 'KeyOffOutlineColor': KOff, 'KeyOnOutlineColor': KOn, 'KeyCharColorOn': charcoloron, 'KeyCharColorOff': charcoloroff, 'KeyColorOn': KCon, 'KeyColorOff': KCoff, 'KeyLabelOn': list(KLon), 'KeyLabelOff': list(KLoff) }, {}) screen.AddUndefaultedParams(self, {}, FastPress=False, Verify=False, Blink=Blink, label=label)
def __init__(self, screensection, screenname): debug.debugPrint('Screen', "New WeatherScreenDesc ", screenname) screen.ScreenDesc.__init__(self, screensection, screenname) self.fmt = WFormatter() butsize = self.ButSize(1, 1, 0) self.Keys = OrderedDict({ 'condorfcst': toucharea.TouchPoint('condorfcst', (self.HorizBorder + .5 * butsize[0], self.TopBorder + .5 * butsize[1]), butsize, proc=self.CondOrFcst) }) self.currentconditions = True # show conditions or forecast screen.AddUndefaultedParams(self, screensection, location='', LocationSize=40) self.SetScreenTitle(screen.FlatenScreenLabel(self.label), 50, self.CharColor) self.condformat = u"{d[0]} {d[1]}\u00B0F", u" Feels like: {d[2]}\u00B0", "Wind {d[3]}@{d[4]}" self.condfields = list( ((self.location, 'Cond', x) for x in ('Sky', 'Temp', 'Feels', 'WindDir', 'WindMPH'))) # self.dayformat = "Sunrise: {d[0]:02d}:{d[1]:02d}","Sunset: {d[2]:02d}:{d[3]:02d}","Moon rise: {d[4]} set: {d[5]}","{d[6]}% illuminated" # self.dayfields = list(((self.location, 'Cond', x) for x in ('SunriseH','SunriseM','SunsetH','SunsetM','Moonrise','Moonset','MoonPct'))) self.dayformat = "Sunrise: {d[0]}", "Sunset: {d[1]}", "Moon rise: {d[2]} set: {d[3]}" self.dayfields = list( ((self.location, 'Cond', x) for x in ('Sunrise', 'Sunset', 'Moonrise', 'Moonset'))) self.footformat = "Readings as of {d[0]}", self.footfields = ((self.location, 'Cond', 'Age'), ) self.fcstformat = u"{d[0]} {d[1]}\u00B0/{d[2]}\u00B0 {d[3]}", "Wind: {d[4]}" self.fcstfields = list( ((self.location, 'Fcst', x) for x in ('Day', 'High', 'Low', 'Sky', 'WindSpd'))) try: self.store = valuestore.ValueStores[self.location] except KeyError: logsupport.Logs.Log( "Weather screen {} using non-existent location {}".format( screenname, self.location), severity=logsupport.ConsoleWarning) raise ValueError utilities.register_example("WeatherScreenDesc", self)
def __init__(self, screensection, screenname): screen.ScreenDesc.__init__(self, screensection, screenname) debug.debugPrint('Screen', "Build Clock Screen") screen.AddUndefaultedParams(self, screensection, CharSize=[20], Font=fonts.monofont, OutFormat=[], ExtraFields=[], ExtraSize=[0], ExtraFormat=[]) for i in range(len(self.CharSize), len(self.OutFormat)): self.CharSize.append(self.CharSize[-1]) self.KeyList = None # no touch areas active on this screen utilities.register_example("ClockScreen", self) self.DecodedExtraFields = [] for f in self.ExtraFields: if ':' in f: self.DecodedExtraFields.append(f.split(':')) else: logsupport.Logs.Log("Incomplete field specified on clockscreen", severity=ConsoleWarning) self.poster = RepeatingPost(1.0, paused=True, name=self.name, proc=self.repaintClock) self.poster.start()
def __init__(self, thisscreen, keysection, keyname): debug.debugPrint('Screen', " New Var Key ", keyname) ManualKeyDesc.__init__(self, thisscreen, keysection, keyname) screen.AddUndefaultedParams(self, keysection, Var='', Appearance=[], ValueSeq=[]) valuestore.AddAlert(self.Var, (KeyWithVarChanged, (keyname, self.Var))) if self.ValueSeq: self.Proc = self.VarKeyPressed t = [] for n in self.ValueSeq: t.append(int(n)) self.ValueSeq = t self.displayoptions = [] self.oldval = None self.State = False for item in self.Appearance: desc = shlex.split(item) rng = desc[0].split(':') chooser = (int(rng[0]), int(rng[0])) if len(rng) == 1 else (int(rng[0]), int(rng[1])) clr = desc[1] lab = self.label if len(desc) < 3 else desc[2] self.displayoptions.append(self.DistOpt(chooser, clr, lab))
def __init__(self, thisscreen, keysection, keyname): debug.debugPrint('Screen', " New RunProgram Key ", keyname) ManualKeyDesc.__init__(self, thisscreen, keysection, keyname) screen.AddUndefaultedParams(self, keysection, ProgramName='') self.State = False pn, self.Hub = _resolvekeyname(self.ProgramName, thisscreen.DefaultHubObj) self.Program = self.Hub.GetProgram(pn) if self.Program is None: self.Program = DummyProgram(keyname, self.Hub.name, self.ProgramName) logsupport.Logs.Log( "Missing Prog binding Key: {} on screen {} Hub: {} Program: {}".format(keyname, thisscreen.name, self.Hub.name, self.ProgramName), severity=ConsoleWarning) if self.Verify: self.VerifyScreen = supportscreens.VerifyScreen(self, self.GoMsg, self.NoGoMsg, self.Verified, None, thisscreen, self.KeyColorOff, thisscreen.BackgroundColor, thisscreen.CharColor, self.State, thisscreen.HubInterestList) self.Proc = self.VerifyScreen.Invoke self.ProcDblTap = self.VerifyScreen.Invoke else: self.Proc = self.RunKeyPressed self.ProcDblTap = self.RunKeyDblPressed
def __init__(self, key, gomsg, nogomsg, procyes, procno, callingscreen, bcolor, keycoloroff, charcolor, state, interestlist): screen.BaseKeyScreenDesc.__init__(self, {}, key.name + '-Verify', parentscreen=key) debug.debugPrint('Screen', "Build Verify Screen") self.NavKeysShowing = False self.DefaultNavKeysShowing = False self.HubInterestList = interestlist self.DimTO = 20 self.PersistTO = 10 self.label = screen.FlatenScreenLabel(key.label) self.ClearScreenTitle() # don't use parent screen title self.CallingScreen = callingscreen screen.AddUndefaultedParams(self, None, TitleFontSize=40, SubFontSize=25) self.SetScreenTitle(self.label, 40, charcolor) self.Keys['yes'] = ManualKeyDesc(self, 'yes', gomsg, bcolor, keycoloroff, charcolor, State=state) self.Keys['yes'].Proc = procyes # functools.partial(proc, True) self.Keys['no'] = ManualKeyDesc(self, 'no', nogomsg, bcolor, keycoloroff, charcolor, State=state) self.Keys[ 'no'].Proc = procno if procno is not None else self.DefaultNo # functools.partial(proc, False) self.LayoutKeys(self.startvertspace, self.useablevertspace) utilities.register_example("VerifyScreen", self)
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)
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): screen.ScreenDesc.__init__(self, screensection, screenname) debug.debugPrint('Screen', "New TimeTempDesc ", screenname) screen.AddUndefaultedParams(self, screensection, location='', CharSize=[-1], ClockSize=-1, LocationSize=-1, CondSize=[20], FcstSize=[20], Font=fonts.monofont, FcstLayout='Block', FcstIcon=True, CondIcon=True, TimeFormat=[], ConditionFields=[], ConditionFormat=[], ForecastFields=[], ForecastFormat=[], ForecastDays=1, SkipDays=0, IconSizePct=100) if self.CharSize != [-1]: # old style logsupport.Logs.Log( "TimeTemp screen CharSize parameter deprecated, change to specific block size parameters", severity=ConsoleWarning) self.ClockSize = extref(self.CharSize, 0) self.LocationSize = extref(self.CharSize, 1) self.CondSize = extref(self.CharSize, 2) self.FcstSize = extref(self.CharSize, 3) if self.ForecastDays + self.SkipDays > 10: self.ForecastDays = 10 - self.SkipDays logsupport.Logs.Log("Long forecast requested; days reduced to: " + str(self.ForecastDays), severity=ConsoleWarning) if self.FcstLayout not in ('Block', 'BlockCentered', 'LineCentered', '2ColVert', '2ColHoriz'): logsupport.Logs.Log( 'FcstLayout Param not Block, BlockCentered, LineCentered, 2ColVert, or 2ColHoriz - using "Block" for ', screenname, severity=ConsoleWarning) self.FcstLayout = "Block" self.scrlabel = screen.FlatenScreenLabel(self.label) try: self.store = valuestore.ValueStores[self.location] except KeyError: logsupport.Logs.Log( "Timetemp screen {} using non-existent location {}".format( screenname, self.location), severity=ConsoleWarning) raise ValueError self.DecodedCondFields = [] for f in self.ConditionFields: if ':' in f: self.DecodedCondFields.append(f.split(':')) else: self.DecodedCondFields.append((self.location, 'Cond', f)) self.condicon = (self.location, 'Cond', 'Icon') if self.CondIcon else None self.DecodedFcstFields = [] for f in self.ForecastFields: if ':' in f: self.DecodedFcstFields.append(f.split(':')) else: self.DecodedFcstFields.append((self.location, 'Fcst', f)) self.fcsticon = (self.location, 'Fcst', 'Icon') if self.FcstIcon else None self.poster = RepeatingPost(1.0, paused=True, name=self.name, proc=self.repaintClock) self.poster.start() self.fmt = WFormatter()