Full python

This commit is contained in:
Dandaedre 2018-11-06 13:14:48 +01:00
parent 5439d350f7
commit c9e8ab3334
2 changed files with 72 additions and 6 deletions

39
gui.py Normal file
View File

@ -0,0 +1,39 @@
try:
from tkinter import *
except:
from Tkinter import *
import request
def shon(event):
request.openURL(request.shutter_on)
def shoff(event):
request.openURL(request.shutter_off)
def stat():
lbstat.text='Shutter: {} / OSD: {} / INPUT: {}'.format(*request.openSTATUS(request.status))
window = Tk()
window.title("Panasonic Remote GUI")
window.geometry('350x200')
lbsh = Label(window, text="SHUTTER")
lbst = Label(window, text="STATUS")
lbstat=Label(window, text="")
btno = Button(window, text="OFF",command=lambda: shoff(None))
btnf = Button(window, text="ON",command=lambda: shon(None))
btstat=Button(window, text="Refresh",command=stat)
btno.grid(column=2, row=0)
btnf.grid(column=1, row=0)
btstat.grid(column=1,row=1)
lbsh.grid(column=0, row=0)
lbst.grid(column=0,row=1)
lbstat.grid(column=0,row=2)
window.bind("a", shon)
window.bind("z", shoff)
window.mainloop()

View File

@ -1,11 +1,23 @@
import urllib2,sys
import re
try:
import Tkinter as tk
except:
import tkinter as tk
def makeURL(cmd):
url = 'http://192.168.0.8/cgi-bin/proj_ctl.cgi?key={}&lang=e&osd=on'.format(cmd)
reinp=re.compile('INPUT&nbsp;(?P<np>\w+)')
def makeURL(ip,cmd):
url = 'http://{}/cgi-bin/proj_ctl.cgi?key={}&lang=e&osd=off'.format(ip,cmd)
username = 'admin1'
password = 'panasonic'
p = urllib2.HTTPPasswordMgrWithDefaultRealm()
p.add_password(None, url, username, password)
return p,url
def makeSTATUS(ip):
url='http://{}/cgi-bin/get_osd.cgi?lang=e'.format(ip)
username = 'admin1'
password = 'panasonic'
p = urllib2.HTTPPasswordMgrWithDefaultRealm()
@ -19,22 +31,37 @@ def openURL(cmd):
handler = urllib2.HTTPBasicAuthHandler(p)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
page = urllib2.urlopen(url).read()
page = urllib2.urlopen(url,timeout=2).read()
return page
except Exception as e:
print(e)
return None
def openSTATUS(cmd):
text=openURL(cmd)
sh,osd,inp="Off","Off",""
if text==None:
return None
if text.find("SHUTTER ON")>=0:
sh="On"
if text.find("ON SCREEN ON")>=0:
osf="On"
inp=reinp.search(text).groups()[0]
return sh,osd,inp
ip="192.168.0.8"
shutter_on=makeURL(ip,"shutter_on")
shutter_off=makeURL(ip,"shutter_off")
status=makeSTATUS(ip)
shutter_on=makeURL("shutter_on")
shutter_off=makeURL("shutter_off")
if __name__ == '__main__':
try:
cmd=sys.argv[1]
print(cmd)
if cmd=="on":
openURL(shutter_on)
elif cmd=="off":
openURL(shutter_off)
elif cmd=="status":
print('Shutter: {}\nOSD: {}\nINPUT: {}'.format(*openSTATUS(status)))
except:
openURL(shutter_off)