예제 #1
0
    def ShowControlScreen(self):

        toblit = []
        if self.ValidState:
            statusblock, h, statusw = screenutil.CreateTextBlock(
                [self.OPstate, self.OPfile, self.OPcomppct + self.OPtimeleft],
                25, self.CharColor, True)

            vpos = self.titlespace + h

            if self.OPstate in ['Printing', 'Paused', 'Operational']:
                tool1, h, w = screenutil.CreateTextBlock(
                    [self.OPtemp1, self.OPbed], 25, self.CharColor, True)
                toblit.append((tool1, ((hw.screenwidth - w) // 2, vpos)))
                # config.screen.blit(tool1, ((config.screenwidth - w) // 2, vpos))
                vpos = vpos + h

        else:
            statusblock, h, statusw = screenutil.CreateTextBlock([
                'Not Available',
            ], 25, self.CharColor, True)

        for i in toblit:
            hw.screen.blit(i[0], i[1])
        hw.screen.blit(statusblock,
                       ((hw.screenwidth - statusw) // 2, self.titlespace))
예제 #2
0
 def SourceSelectScreen(self):
     # show a list of sources starting with startsource item last item is either next or return
     # compute sources per screen as usable vertical height div item pixel height
     self.Keys = self.KeysSrc
     self.ReInitDisplay()
     for i in range(
             self.SourceItem,
             min(len(self.SourceSet), self.SourceItem + self.sourceslots)):
         slot = i - self.SourceItem
         clr = self.DullKeyColor if self.SourceSet[
             i] == self.SourceSelection else self.CharColor
         rs, h, w = screenutil.CreateTextBlock(self.SourceSet[i],
                                               self.sourceheight,
                                               clr,
                                               False,
                                               FitLine=True,
                                               MaxWidth=hw.screenwidth -
                                               self.HorizBorder * 2)
         self.SourceSlot[slot] = self.SourceSet[i]
         voff = self.SrcSlotsVPos[slot] + (self.sourceheight - h) // 2
         hw.screen.blit(rs, (self.HorizBorder, voff))
     pygame.draw.polygon(
         hw.screen, wc(self.CharColor),
         supportscreens._TriangleCorners(self.SrcPrev, self.sourceheight,
                                         False), 3)
     pygame.draw.polygon(
         hw.screen, wc(self.CharColor),
         supportscreens._TriangleCorners(self.SrcNext, self.sourceheight,
                                         True), 3)
예제 #3
0
 def DisplayListSelect(self):
     for i in range(self.firstitem,
                    min(len(self.itemlist),
                        self.firstitem + self.NumSlots)):
         slot = i - self.firstitem
         clr = self.DullKeyColor if i == self.selection else self.CharColor
         rs, h, w = screenutil.CreateTextBlock(self.itemlist[i],
                                               self.sourceheight,
                                               clr,
                                               False,
                                               FitLine=True,
                                               MaxWidth=hw.screenwidth -
                                               self.HorizBorder * 2)
         voff = self.SlotsVPos[slot] + (self.sourceheight - h) // 2
         hw.screen.blit(rs, (self.HorizBorder, voff))
     upcolor = wc(
         self.CharColor) if self.firstitem != 0 else self.DullKeyColor
     dncolor = wc(self.CharColor) if self.firstitem + self.NumSlots < len(
         self.itemlist) else self.DullKeyColor
     pygame.draw.polygon(
         hw.screen, upcolor,
         _TriangleCorners(self.SrcPrev, self.sourceheight, False), 3)
     pygame.draw.polygon(
         hw.screen, dncolor,
         _TriangleCorners(self.SrcNext, self.sourceheight, True), 3)
     pygame.display.update()
예제 #4
0
    def GroupScreen(self, gpentity):

        self.nms = []
        self.Keys = self.KeysGpCtl
        self.ReInitDisplay()
        i = 0
        for p in self.SonosGroups[gpentity]:
            self.nms.append(self.SonosNodes[p])
            rn = screenutil.CreateTextBlock(self.nms[-1].FriendlyName,
                                            self.ctlhgt,
                                            self.CharColor,
                                            True,
                                            FitLine=True,
                                            MaxWidth=hw.screenwidth -
                                            2 * self.HorizBorder + 10)
            vol = self.nms[-1].volume * 100
            volrndr, h, w = screenutil.CreateTextBlock(str(int(vol)),
                                                       .8 * self.ctlhgt,
                                                       self.CharColor,
                                                       True,
                                                       FitLine=True)
            volx = (self.ButLocSize[i]['Dn'][0][0] +
                    self.ButLocSize[i]['Up'][0][0] - w) // 2
            hw.screen.blit(volrndr,
                           (volx, self.ButLocSize[i]['Dn'][0][1] - h // 2))
            hw.screen.blit(rn[0], (20, self.GPCtlVPos[i]))
            pygame.draw.polygon(
                hw.screen, wc(self.CharColor),
                supportscreens._TriangleCorners(self.ButLocSize[i]['Dn'][0],
                                                self.ButLocSize[i]['Dn'][1][0],
                                                True), 2)
            pygame.draw.polygon(
                hw.screen, wc(self.CharColor),
                supportscreens._TriangleCorners(self.ButLocSize[i]['Up'][0],
                                                self.ButLocSize[i]['Up'][1][0],
                                                False), 2)
            spkr, diagbar = self._Speaker(self.ButLocSize[i]['Mute'][0],
                                          self.ButLocSize[i]['Mute'][1][0])
            pygame.draw.polygon(hw.screen, wc(self.CharColor), spkr, 2)
            if self.nms[-1].muted:
                pygame.draw.line(hw.screen, wc(self.CharColor), diagbar[0],
                                 diagbar[1], 4)
            i += 1
예제 #5
0
 def ChangeGroupingScreen(self, gpentity):
     self.Keys = self.KeysGC
     self.ReInitDisplay()
     self.gpingrms = [[self.SonosNodes[gpentity], True]]
     for n, r in self.SonosNodes.items():
         if n != gpentity:
             ingp = n in self.SonosNodes[gpentity].sonos_group
             self.gpingrms.append([r, ingp])
     for rm, i in zip(self.gpingrms, range(self.numplayers)):
         hw.screen.blit(
             screenutil.CreateTextBlock(
                 rm[0].FriendlyName,
                 40, (self.DullKeyColor, self.CharColor)[rm[1]],
                 False,
                 FitLine=True,
                 MaxWidth=hw.screenwidth - self.HorizBorder)[0],
             (20, self.GCVPos[i]))
예제 #6
0
 def SummaryScreen(self):
     if self.numplayers == 0:
         errmsg, _, _ = screenutil.CreateTextBlock(
             [' ', 'No Players', 'Found', 'Check', 'Configuration', ' '],
             30, 'white', True)
         hw.screen.blit(errmsg, (self.HorizBorder + 15, 40))
         pygame.display.update()
         return
     self.Keys = self.KeysSum
     self.ReInitDisplay()
     slot = 0
     pygame.draw.line(hw.screen, wc(self.CharColor),
                      (self.HorizBorder, self.NodeVPos[0]),
                      (hw.screenwidth - self.HorizBorder, self.NodeVPos[0]),
                      3)
     for e, g in self.SonosGroups.items():
         ginfo = self.SonosNodes[g[0]]
         if ginfo.internalstate == -1:
             unav, ht, wd = screenutil.CreateTextBlock(
                 '<player info unavailable>',
                 self.roomheight //
                 (sum(self.roomdisplayinfo) / self.roomdisplayinfo[1]),
                 self.CharColor,
                 False,
                 FitLine=True,
                 MaxWidth=hw.screenwidth - 2 * self.HorizBorder - 15)
             hw.screen.blit(
                 unav,
                 (self.HorizBorder + 15,
                  self.NodeVPos[slot] + self.roomheight //
                  (sum(self.roomdisplayinfo) / self.roomdisplayinfo[0])))
         else:
             song, ht, wd = screenutil.CreateTextBlock(
                 [ginfo.song, ginfo.artist, ginfo.album],
                 self.roomheight //
                 (sum(self.roomdisplayinfo) / self.roomdisplayinfo[1]),
                 self.CharColor,
                 False,
                 FitLine=True,
                 MaxWidth=hw.screenwidth - 2 * self.HorizBorder - 15)
             hw.screen.blit(
                 song,
                 (self.HorizBorder + 15,
                  self.NodeVPos[slot] + self.roomheight //
                  (sum(self.roomdisplayinfo) / self.roomdisplayinfo[0])))
         for n in g:
             hw.screen.blit(self.RoomNames[n][0],
                            (self.HorizBorder + 5, self.NodeVPos[slot]))
             self.SlotToGp[slot] = e
             slot += 1
             lineoff = self.NodeVPos[slot]
         # noinspection PyUnboundLocalVariable
         pygame.draw.line(hw.screen, wc(self.CharColor),
                          (self.HorizBorder, lineoff),
                          (hw.screenwidth - self.HorizBorder, lineoff), 3)
     pygame.draw.line(hw.screen, wc(self.CharColor),
                      (self.HorizBorder, self.NodeVPos[0]),
                      (self.HorizBorder, lineoff), 3)
     pygame.draw.line(hw.screen, wc(self.CharColor),
                      (hw.screenwidth - self.HorizBorder, self.NodeVPos[0]),
                      (hw.screenwidth - self.HorizBorder, lineoff), 3)
예제 #7
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
예제 #8
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)