anthonyeden / ProPresenter-Stage-Display-Python

A Python implementation of the ProPresenter Stage Display - for Raspberry Pi
https://mediarealm.com.au/propresenter-pi/
GNU General Public License v3.0
27 stars 4 forks source link

Connection Status #12

Open thejame opened 5 years ago

thejame commented 5 years ago

Had an idea about putting a connection status in the top right of the display, so if the app disconnects from the ProPresenter service or cannot reach it, you get an error instead of a blank screen. Then when the connection is good again, the message disappears. Check it out - not much modification was needed.

` def connected(self, data): print "ProPresenter Connected"
self.updateStatus("")

def connectFailed(self, error):
    self.tryReconnect = True

    if self.disconnectTime == 0:
        self.disconnectTime = time.time()

    print "ProPresenter Connect Failed", error        
    self.updateStatus("NO CONNECTION")

def disconnected(self, error):
    self.tryReconnect = True

    if self.disconnectTime == 0:
        self.disconnectTime = time.time()

    print "ProPresenter Disconnected", error        
    self.updateStatus("DISCONNECTED")`

and then the object: self.labelStatus = tk.Label( self, text = "", font = (self.fontName, self.fontSizeClock, self.fontStyle), background = self.backgroundColour, foreground = self.errorColour, wraplength = self.wordWrapLength, anchor = tk.SE, justify = tk.LEFT ) self.labelStatus.grid( column = 1, row = 0, sticky = tk.E+tk.N+tk.S, padx = self.padX, pady = self.padY )

and the function: ` def updateStatus(self, data): if self.labelStatus is None: return False

    self.labelTimer.config(text = "")
    self.labelStatus.config(text = data)`

It doesn't need a new column or row since it shares it with the Timer status. Just needs a parameter in the JSON file like so:

"TextColourError": "#FF0000",

thejame commented 5 years ago

Actually took this a little further and added the ability to show the server IP address and the machine's local IP address if can't connect to the ProPresenter host.

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) print "Stage display:", s.getsockname()[0] self.IP_Addr=s.getsockname()[0] s.close()

and show it in the connectFailed() definition-

self.nextText="DISPLAY: "+self.IP_Addr+"\nSERVER: "+self.ProP_IPAddress