Exemplo n.º 1
0
def main():
    current_isp_index = 0

    try:
        lcd = Server("localhost", debug=False)
        lcd.start_session()

        sc = lcd.add_screen("home")
        sc.set_heartbeat("off")
        sc.set_duration(10)

        line1 = sc.add_string_widget("Line1Widget", text="Init...", x=1, y=1)
        line2 = sc.add_scroller_widget("Line2Widget",
                                       text="",
                                       speed=6,
                                       top=2,
                                       right=16)

        last_calibration = get_calibration()

        update_display(line1, line2, current_isp_index)
        update_shaping(last_calibration, current_isp_index)

        lcd.add_key("Down")
        lcd.add_key("Up")

        last_update_time = time.time()
        while (True):
            key = lcd.poll()
            if key is not None:
                favorites = get_favorites()
                if key == "key Down\n":
                    current_isp_index += 1
                    if current_isp_index == len(favorites):
                        current_isp_index = 0
                elif key == "key Up\n":
                    current_isp_index -= 1
                    if current_isp_index < 0:
                        current_isp_index = len(favorites) - 1
                else:
                    print(("Unknown key: ", key))
                update_display(line1, line2, current_isp_index)
                # reload the calibration, in case it has updated
                last_calibration = get_calibration()
                update_shaping(last_calibration, current_isp_index)
                last_update_time = time.time()
            # watch for file changes on LASTDISPLAY_FULLPATH
            elif os.path.isfile(LASTDISPLAY_FULLPATH) and os.stat(
                    LASTDISPLAY_FULLPATH).st_mtime > last_update_time:
                last_update_time = time.time()
                with open(LASTDISPLAY_FULLPATH) as f:
                    line1.set_text(f.readline().split("\n")[0])
                    line2.set_text(f.readline().split("\n")[0])

            time.sleep(0.2)
    except ConnectionRefusedError:
        print("display: problem connecting to lcdproc, shutting down")
Exemplo n.º 2
0
def main():
    logInfo("Starting up...")
    while True:
        try:
            lcd = Server("localhost", debug=False)
            lcd.start_session()
            logInfo("Connected to LCDd")

            lcd.add_key("Up")
            lcd.add_key("Down")

            screen1 = lcd.add_screen("Screen1")
            screen1.set_heartbeat("off")

            line1_widget = screen1.add_scroller_widget("line1",
                                                       left=1,
                                                       top=1,
                                                       right=20,
                                                       bottom=1,
                                                       speed=10,
                                                       text="")
            line2_widget = screen1.add_scroller_widget("line2",
                                                       left=1,
                                                       top=2,
                                                       right=20,
                                                       bottom=2,
                                                       speed=10,
                                                       text="")

            currentIndex = 0

            logInfo("Entering endless loop...")
            while True:

                interfaceNames = sorted(netifaces.interfaces())

                interfaceNames = filter(lambda name: not name in ["lo"],
                                        interfaceNames)

                currentIndex = max(0, min(currentIndex,
                                          len(interfaceNames) - 1))
                currentInterfaceName = interfaceNames[currentIndex]

                line1 = currentInterfaceName + ": "
                line2 = ""
                addresses = netifaces.ifaddresses(currentInterfaceName)

                if netifaces.AF_INET in addresses:
                    line1 += addresses[netifaces.AF_INET][0]['addr']

                if netifaces.AF_INET6 in addresses:
                    line2 += addresses[netifaces.AF_INET6][0]['addr']

                line1_widget.set_text(line1)
                line2_widget.set_text(line2)

                time.sleep(0.1)

                while True:
                    event = lcd.poll()
                    if not event:
                        break
                    event = string.strip(event)
                    if event == "key Up":
                        currentIndex = currentIndex + 1
                    elif event == "key Down":
                        currentIndex = currentIndex - 1
        # probably it's better to just quit together with LCDd, therefore it's commented out...
        #except socket.error, EOFError:
        #    logWarn("Error connecting to LCDd, retrying in 30 seconds...")
        #    time.sleep(30)
        except Exception as e:
            logError(e, "Error reached toplevel, exiting with exit code 42")
            sys.exit(42)
def main():
    logInfo("Starting up...")
    while True:
        try:
            lcd = Server("localhost", debug=False)
            lcd.start_session()
            logInfo("Connected to LCDd")

            lcd.add_key("Up")
            lcd.add_key("Down")

            screen1 = lcd.add_screen("Screen1")
            screen1.set_heartbeat("off")

            line1_widget = screen1.add_scroller_widget("line1", left=1, top=1, right=20, bottom=1, speed=10, text="")
            line2_widget = screen1.add_scroller_widget("line2", left=1, top=2, right=20, bottom=2, speed=10, text="")

            currentIndex = 0

            logInfo("Entering endless loop...")
            while True:

                interfaceNames = sorted(netifaces.interfaces())

                interfaceNames = filter (lambda name:
                                             not name in ["lo"],
                                         interfaceNames)

                currentIndex = max(0, min(currentIndex, len(interfaceNames) - 1))
                currentInterfaceName = interfaceNames[currentIndex]

                line1 = currentInterfaceName + ": "
                line2 = ""
                addresses = netifaces.ifaddresses(currentInterfaceName)

                if netifaces.AF_INET in addresses:
                    line1 += addresses[netifaces.AF_INET][0]['addr']

                if netifaces.AF_INET6 in addresses:
                    line2 += addresses[netifaces.AF_INET6][0]['addr']

                line1_widget.set_text(line1)
                line2_widget.set_text(line2)

                time.sleep(0.1)

                while True:
                    event = lcd.poll()
                    if not event:
                        break
                    event = string.strip(event)
                    if event == "key Up":
                        currentIndex = currentIndex + 1
                    elif event == "key Down":
                        currentIndex = currentIndex - 1
        # probably it's better to just quit together with LCDd, therefore it's commented out...
        #except socket.error, EOFError:
        #    logWarn("Error connecting to LCDd, retrying in 30 seconds...")
        #    time.sleep(30)
        except Exception as e:
            logError(e, "Error reached toplevel, exiting with exit code 42")
            sys.exit(42)
Exemplo n.º 4
0
class DmxUi():
    def __init__(self,color_list):
        self.color_list=color_list
        self.lcd = Server("127.0.0.1", debug=False)
        self.lcd.start_session()
        self.lcd.add_key("Up",mode="exclusively")
        self.lcd.add_key("Down",mode="exclusively")
        self.lcd.add_key("Enter",mode="exclusively")

        #Allocate the screen
        self.screen = self.lcd.add_screen("DMX")
        self.screen.set_heartbeat("off")

        #Add a widget for the label
        self.label_widget = self.screen.add_string_widget("label_widget",
                                                          text="",x=1,y=1)
        #Add a widget for the color
        self.color_widget = self.screen.add_string_widget("color_widget",
                                                          text="",x=7,y=1)
        #Add a widget to display the "selected" status
        self.not_set_widget = self.screen.add_string_widget("not_set_widget",
                                                            text="",x=16,y=1)
        #Set the label text
        self.label_widget.set_text("Color:")

        self.color_idx=0
        self.current_color_idx=0
        self.color_widget.set_text(self.color_list[self.color_idx][0])    
        self.num_colors = len(self.color_list)

    # Get a key from LCDproc
    def get_key(self):
        resp = self.lcd.poll()
        if (resp == None):
            return None

        return resp[4:-1]

    # UI processing
    # -get keyinput
    # -update display
    # -return the current selection
    def ui_process(self):

        key_press = self.get_key()

        if (key_press==None):
            return None
        
        if (key_press == "Up"):
            self.color_idx -= 1

        if (key_press == "Down"):
            self.color_idx += 1

        self.color_idx %= self.num_colors

        if (key_press == "Enter"):
            self.current_color_idx = self.color_idx

        if (self.color_idx != self.current_color_idx):
            self.not_set_widget.set_text("*")
        else:
            self.not_set_widget.set_text("")

        self.color_widget.set_text(self.color_list[self.color_idx][0])

        return self.current_color_idx
Exemplo n.º 5
0
def main():

    signal.signal(signal.SIGALRM, handler)

    # Initialize the LCD object instance
    lcd = Server(debug=False)
    lcd.start_session()
    lcd.add_key("Up")
    lcd.add_key("Down")
    lcd.add_key("Right")
    lcd.add_key("Left")
    lcd.add_key("Enter")

    # Initialize root/initial cfaScreen instance
    cfaScreen = home_screen.get()

    # Append Screens to base cfaInstance
    cfaScreen.pushDownScreen(sys_screens.get())
    cfaScreen.pushDownScreen(IntelHDA_screens.get())

    # Spawn the initial screen
    screen = genScreen(lcd, cfaScreen)

    # Loop logic... (read events and react)
    try:
        while True:
            signal.alarm(1)
            try:
                event = lcd.poll()
            except:
                event = None
            finally:
                signal.alarm(0)
            if not event == None:
                lines = event.splitlines()
                if lines[0] == 'key Enter':
                    cfaScreen.handleEnter(screen)
                elif lines[0] == 'key Up':
                    if cfaScreen.upScreen == None and cfaScreen.downScreen == None:
                        cfaScreen.handleUp(screen)
                    elif not cfaScreen.upScreen == None:
                        clearScreen(lcd, cfaScreen)
                        cfaScreen = cfaScreen.upScreen
                        screen = genScreen(lcd, cfaScreen)
                    else:
                        pass
                elif lines[0] == 'key Down':
                    if cfaScreen.downScreen == None and cfaScreen.upScreen == None:
                        cfaScreen.handleDown(screen)
                    elif not cfaScreen.downScreen == None:
                        clearScreen(lcd, cfaScreen)
                        cfaScreen = cfaScreen.downScreen
                        screen = genScreen(lcd, cfaScreen)
                    else:
                        pass
                elif lines[0] == 'key Right':
                    if not cfaScreen.nextScreen == None:
                        clearScreen(lcd, cfaScreen)
                        cfaScreen = cfaScreen.nextScreen
                        screen = genScreen(lcd, cfaScreen)
                    else:
                        pass
                elif lines[0] == 'key Left':
                    if not cfaScreen.prevScreen == None:
                        clearScreen(lcd, cfaScreen)
                        cfaScreen = cfaScreen.prevScreen
                        screen = genScreen(lcd, cfaScreen)
                    else:
                        pass
            else:
                # Here the update functions are called
                if cfaScreen.ready():
                    cfaScreen.updateWidgets(screen)
        time.sleep(0.100)
    # LCD Cleanup on exit
    finally:
        # Execute closing code before clearing screen
        clearScreen(lcd, cfaScreen)
Exemplo n.º 6
0
class LCDProcPlugin (GObject.Object, Peas.Activatable):
    object = GObject.property(type=GObject.Object)
 
    def __init__(self):
        super(LCDProcPlugin, self).__init__()
 
    def do_activate(self):
        print "Activating Plugin"
         
        self.entry = None
        self.duration = 0
        self.artist = " "
        self.title = " "
        self.album = " "
 
        # Initialise LCD
        try:
            self.lcd = Server(LCDPROC_HOST, debug=True)
        except SocketError:
            print "Failed to connect to LCDd"
            return False
        self.lcd.start_session()
        self.screen1 = self.lcd.add_screen("Rhythmbox")
        self.title1_widget = self.screen1.add_title_widget("Title", "Rhythmbox")
        self.label1_widget = self.screen1.add_string_widget("Label", KEY_LABELS, 1, 2)
        self.screen2 = self.lcd.add_screen("Rhythmbox-info")
        self.screen2.set_heartbeat("off")
        self.lcd.output("on")
        width = self.lcd.server_info["screen_width"]
        self.album_widget = self.screen2.add_scroller_widget("AlbumWidget", top = ALBUM_LINE, bottom = ALBUM_LINE, right = width, text = "Album")
        self.artist_widget = self.screen2.add_scroller_widget("ArtistWidget", top = ARTIST_LINE, bottom = ARTIST_LINE, right = width, text = "Artist")
        self.title_widget = self.screen2.add_scroller_widget("TitleWidget", top = TITLE_LINE, bottom = TITLE_LINE, right = width, text = "Title")
        self.progress_bar = self.screen2.add_hbar_widget("HBarWidget", x=1, y=TIME_LINE, length=0)
        self.time_widget = self.screen2.add_string_widget("TimeWidget", "", 1, TIME_LINE)
        self.displayed_lines = 4
        if SHOW_LABELS:
            self.label_widget = self.screen2.add_string_widget("LabelWidget", KEY_LABELS, 1, LABEL_LINE)
            self.displayed_lines += 1
 
        self.bounce_roll_length = width + BOUNCE_ROLL_THRESHOLD
        self.screen_width_pxl = width * self.lcd.server_info["cell_width"]
         
        for key in keyUse.keys():
            self.lcd.add_key(key)
 
        # Connect call-back functions to interesting events.
        sp = self.object.props.shell_player
        self.pc_id = sp.connect('playing-changed', self.playing_changed)
        self.psc_id = sp.connect('playing-song-changed', self.playing_song_changed)
        self.pspc_id = sp.connect('playing-song-property-changed', self.playing_song_property_changed)
        self.ec_id = sp.connect('elapsed-changed', self.elapsed_changed)
        # LCDd processes key input at 32Hz.
        self.pollcbtag = GObject.timeout_add(1000 / 32, self.poll_cb)
        
        print sp.get_playback_state()
        if sp.get_playing():
            print "Activating: playing"
            self.set_entry(sp.get_playing_entry())
            self.screen1.set_priority("background")
            self.screen2.set_priority("foreground")
        else:
            print "Activating: stopped"
            self.screen1.set_priority("info")
            self.screen2.set_priority("background")
        print "Plugin Activated"
 
    def do_deactivate(self):
        print "Deactivating Plugin"
        if not hasattr(self, 'pc_id'):
            return
        sp = self.object.props.shell_player
        sp.disconnect(self.pc_id)
        sp.disconnect(self.psc_id)
        sp.disconnect(self.pspc_id)
        sp.disconnect(self.ec_id)
        GObject.source_remove(self.pollcbtag)
 
        # Disconnect LCD
        del self.title1_widget
        del self.label1_widget
        del self.artist_widget
        del self.album_widget
        del self.title_widget
        del self.progress_bar
        del self.time_widget
        if SHOW_LABELS:
            del self.label_widget
        del self.screen1
        del self.screen2
        self.lcd.tn.close()
        del self.lcd
        print "Plugin Deactivated"
 
    def poll_cb(self):
        response = self.lcd.poll()
        if response:
            print "Poll Response: %s" % (response[:-1])
            bits = (response[:-1]).split(" ")
            if bits[0] == "key":
                action = keyUse[bits[1]]
                sp = self.object.props.shell_player    # Used by some actions.
                print action
                try:
                    exec action
                except GError as e:
                    if e.args[0] in ('Not currently playing', 'No previous song'):
                        print "%s safe to ignore." % e.args[0]
                    else:
                        print "%s unexpected." % e.args
                        raise
                except:
                    print "Blast! Unexpected error:", sys.exc_info()[0]
                    raise
        return True
 
    def playing_changed(self, player, playing):
        if playing:
            print "Playing"
            self.set_entry(player.get_playing_entry())
            self.screen1.set_priority("background")
            self.screen2.set_priority("foreground")
        else:
            print "Not playing"
            self.entry = None
            self.screen1.set_priority("info")
            self.screen2.set_priority("background")
 
    def playing_song_changed(self, player, entry):
        print "Playing song changed %s" % (entry)
        if player.get_playing():
            self.set_entry(entry)
 
    def playing_song_property_changed(self, player, uri, song_property, old, new):
        print "Playing song %s property (%s) changed (%s to %s)" % (uri, song_property, old, new)
        if player.get_playing():
            if song_property in (NORMAL_ALBUM, STREAM_ALBUM):
                self.album = new
            elif song_property in (NORMAL_ARTIST, STREAM_ARTIST):
                self.artist = new
            elif song_property in (NORMAL_TITLE):
                self.title = new
            elif song_property in (STREAM_TITLE):
                if new.count(" - ") >= 1:
                    # contains "Artist - Title"
                    fields = new.split(" - ",1)
                    self.artist = fields[0]
                    self.title = fields[1]
                else:
                    # only title
                    self.title = new
                    self.artist = ""
                self.album = uri
                self.duration = 0
            else:
                return
        else:
            return
        self.set_display()
 
    def elapsed_changed(self, player, time):
#         print "Elapsed changed %d" % time
        if (time >= 0 and self.duration > 0):
            progress = self.screen_width_pxl * time / self.duration
            self.progress_bar.set_length(progress)
            progress_str  = "%d:%02d" % (time/60, time%60)
            if (time < self.duration / 2):
                self.time_widget.set_x(self.lcd.server_info["screen_width"] - len(progress_str) + 1)
            else:
                self.time_widget.set_x(1)
            self.time_widget.set_text(progress_str)
        else:
            self.progress_bar.set_length(0)
            self.time_widget.set_text("")

    def set_entry(self, entry):
        if rb.entry_equal(entry, self.entry):
            return
        self.entry = entry
        if entry is None:
            return
        self.album = entry.get_string(RB.RhythmDBPropType.ALBUM)
        self.artist = entry.get_string(RB.RhythmDBPropType.ARTIST)
        self.title = entry.get_string(RB.RhythmDBPropType.TITLE)
        self.duration = entry.get_ulong(RB.RhythmDBPropType.DURATION)
#         sp = self.object.props.shell_player
#         self.duration = sp.get_playing_song_duration()
        self.rating = entry.get_double(RB.RhythmDBPropType.RATING)
        print "Song rating %g" % self.rating
        db = self.object.get_property("db")
        if entry.get_entry_type().props.category == RB.RhythmDBEntryCategory.STREAM:
            if not self.album:
                self.album = db.entry_request_extra_metadata(entry, STREAM_ALBUM)
            if not self.artist:
                self.artist = db.entry_request_extra_metadata(entry, STREAM_ARTIST)
            if not self.title:
                self.title = db.entry_request_extra_metadata(entry, STREAM_TITLE)
        self.set_display()
 
    def set_display(self):
        album_text = self.album
        if DONT_SCROLL:
            album_text = album_text[0:self.lcd.server_info["screen_width"]]
        elif len(album_text) < self.bounce_roll_length:
            self.album_widget.set_direction("h")    # Bounce text to show characters that don't fit
        else:
            self.album_widget.set_direction("m")    # Roll text to show characters that don't fit
            album_text += " * "
        self.album_widget.set_text(album_text)
 
        artist_text = self.artist
        if DONT_SCROLL:
            artist_text = artist_text[0:self.lcd.server_info["screen_width"]]
        elif len(artist_text) < self.bounce_roll_length:
            self.artist_widget.set_direction("h")
        else:
            self.artist_widget.set_direction("m")
            artist_text += " * "
        self.artist_widget.set_text(artist_text)
 
        title_text = self.title
        if DONT_SCROLL:
            title_text = title_text[0:self.lcd.server_info["screen_width"]]
        elif len(title_text) < self.bounce_roll_length:
            self.title_widget.set_direction("h")
        else:
            self.title_widget.set_direction("m")
            title_text += " * "
        self.title_widget.set_text(title_text)

    def new_line(self, current, step):
        print "newline %d,%d" % (current, step)
        current += step
        if current > self.displayed_lines:
            return 1
        if current == 0:
            current = self.displayed_lines
        return current
 
    def scroll(self, step):
        self.album_widget.set_top(self.new_line(self.album_widget.top, step))
        self.album_widget.set_bottom(self.new_line(self.album_widget.bottom, step))
        self.artist_widget.set_top(self.new_line(self.artist_widget.top, step))
        self.artist_widget.set_bottom(self.new_line(self.artist_widget.bottom, step))
        self.title_widget.set_top(self.new_line(self.title_widget.top, step))
        self.title_widget.set_bottom(self.new_line(self.title_widget.bottom, step))
        self.progress_bar.set_y(self.new_line(self.progress_bar.y, step))
        self.time_widget.set_y(self.new_line(self.time_widget.y, step))
        if SHOW_LABELS:
            self.label_widget.set_y(self.new_line(self.label_widget.y, step))