Пример #1
0
    def doRead(self):
        """ Input is ready! """
        curses.noecho()
        c = self.stdscr.getch() # read a character

        if c == curses.KEY_BACKSPACE:
            self.searchText = self.searchText[:-1]
            #self.updateDisplay()

        elif c == curses.KEY_ENTER or c == 10:
            line = self.searchText
            self.searchText = ''
            
            if line == "pause":
                pause()
                
            elif line == "resume":
                resume()
                
            elif line == "skip":
                skip()
                
            else:
                initiateSearch(SearchContext(self), line)

        elif c <= 256:
            if len(self.searchText) == self.cols-2: return
            self.searchText = self.searchText + chr(c)
            #self.updateDisplay()
        
        self.stdscr.addstr(self.rows-1, 0, 
                           self.searchText + (' ' * (
                           self.cols-len(self.searchText)-2)))
        self.stdscr.move(self.rows-1, len(self.searchText))
        self.stdscr.refresh()
Пример #2
0
    def cmd(self, responder, user, channel, command, msg):
        if command == PAUSE:
            pause()
            responder("ok")

        elif command == RESUME:
            resume()
            responder("ok")

        elif command == SKIP:
            skip()
            responder("ok")

        elif command == STATUS:
            queueObj, statusLookup = getStatus()
            if queueObj:
                title = str(queueObj.media_object)
            else:
                title = ""

            if statusLookup:
                status, stat_text = statusLookup
            else:
                status = "IDLE"
                stat_text = "Waiting for Activity"

            responder(("%s %s: %s" % (status, stat_text, title)).encode("UTF-8"))

        elif command == DUMP:
            qitems = [x for x in getQueuedItems()]
            if qitems:
                responder("%d item(s) in the queue" % len(qitems))
                for item in qitems:
                    msg = "%i: %s" % (item.media_object.id, item.media_object)
                    responder(msg.encode("UTF-8"))

        elif command == REMOVE:
            if remQueuedItem(int(msg)):
                responder("ok")
            else:
                responder("Failed to remove")

        elif command == SEARCH:
            s = SearchContext(self)
            s.responder = responder
            initiateSearch(s, msg)

        elif command == ADD:
            try:
                dbId = int(msg)
            except:
                responder("Expecting Resource Id")
                return

            item = Session().query(MediaObject).filter(MediaObject.id == dbId).first()
            if item:
                if queue(item):
                    responder("ok")
                else:
                    responder("Already in Queue")
            else:
                responder("Not found")