Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import eg
- import urllib2
- import time
- eg.RegisterPlugin(
- name = "Foscam",
- author = "DaF",
- version = "1.0.2",
- canMultiLoad = True,
- kind = "external",
- createMacrosOnAdd = True,
- description = (
- "Plugin to control and add features to"
- '<br\n><br\n>'
- "FOSCAM FI8908W FI8918W"
- '<br\n>'
- "HEDEN VisionCam"
- '<br\n><br\n>'
- '<center><img src="foscam.png" /></center>'
- ),
- help = """
- <br/><b>Notice:</b>
- Check carefully every settings
- """,
- url = "http://forum.hardware.fr/hfr/HardwarePeripheriques/Webcam/fi8908w-fi8918w-visioncam-sujet_50586_1.htm",
- icon = (
- "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEA"
- "mpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iA"
- "lEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKO"
- "g6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEK"
- "JHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThL"
- "CIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCR"
- "ACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUp"
- "AAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2"
- "YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+r"
- "cEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+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fDt52+6/d/urueuCI/N2nWjzZ8e7ZU"
- "KqGkBAz7p6f4dwCIn0Irf0Ct0gAAAABJRU5ErkJggg=="
- ),
- )
- from threading import Event, Thread
- from os.path import basename, dirname, abspath
- #test
- import os, sys, time, string, select, re
- from socket import *
- from datetime import timedelta, datetime
- # Used for opening external app
- from eg.WinApi.Dynamic import (
- sizeof, byref, CreateProcess, WaitForSingleObject, FormatError,
- CloseHandle, create_unicode_buffer,
- STARTUPINFO, PROCESS_INFORMATION,
- CREATE_NEW_CONSOLE, STARTF_USESHOWWINDOW, INFINITE,
- GetExitCodeProcess, DWORD
- )
- WINSTATE_FLAGS = (
- 1, # SW_SHOWNORMAL
- 6, # SW_MINIMIZE | SW_HIDE
- 3, # SW_SHOWMAXIMIZED
- 0, # SW_HIDE
- )
- PRIORITY_FLAGS = (
- 64, # IDLE_PRIORITY_CLASS
- 16384, # BELOW_NORMAL_PRIORITY_CLASS
- 32, # NORMAL_PRIORITY_CLASS
- 32768, # ABOVE_NORMAL_PRIORITY_CLASS
- 256, # REALTIME_PRIORITY_CLASS
- )
- class Text:
- ipArea = "Foscam IP settings"
- textBoxIPCamCtrl = "IP"
- textBoxPortCtrl = "Port"
- textBoxLoginCtrl = "User"
- textBoxPwdCtrl = "Password"
- mediaArea = "External viewers settings"
- textBoxBrowserPathCtrl = "Jpeg viewer app path"
- textBoxcodecCtrl = "Codec (h264,mp4v,x264,mp1v,mp2v)"
- textBoxbitrateCtrl = "Bitrate"
- checkBoxStreamPlayerFullScreenCtrl = "Full screen video"
- checkBoxSafeHttpModeCtrl = "Solve the Error 10013 (urlopen)"
- checkBoxDebugCtrl = "Show debug in log"
- patrolSleepArea = "Patrol settings"
- patrolSleepCtrl = "Sleep time (in seconds)"
- patrolPos1 = "First preset"
- patrolPos2 = "Second preset"
- patrolLoopInfo = "Foscam : patrol every {0}s until {1}"
- patrolLoopEndInfo = "Foscam : stopped patrol"
- presetGotoArea = "Select a preset value"
- presetCtrl = "Preset number"
- presetRecordArea = "Select a preset value to record"
- switchIR = "Activate IR LEDs"
- commandNumber = "Command number"
- troubleShootArea = "Troubleshooting (only in case of troubles!)"
- alarmArea = "Alarm settings"
- alarmMotionCtrl = "Activate alarm yes/no = 1/0"
- alarmSensitivityCtrl = "Sensivity"
- alarmInputCtrl = "Input armed y/n"
- alarmIOCtrl = "IO linkage y/n"
- alarmMailCtrl = "Send email y/n"
- alarmIntervalCtrl = "Upload interval (seconds)"
- alarmMiscArea = "Miscellaneous"
- timerSnapshotInfo = "Foscam : Snapshots every {0}s until {1}"
- timerArea = "Select interval and folder path"
- intervalTimeCtrl = "Interval (second)"
- durationCtrl = "Duration (minute. 0 = unlimited)"
- folderCtrl = "Folder path"
- timerSnapshotEndInfo = "Foscam : stopped timed snapshots"
- videoArea = "Video features"
- checkBoxShowCtrl = "Display the video"
- checkBoxRecordCtrl = "Record video"
- checkBoxAudioRecordCtrl = "Record audio"
- durationVideoCtrl = "Duration (second)"
- protocolCtrl = "Protocol (rtsp,mmsh)"
- portCtrl = "Port"
- pageNameCtrl = "URL page name"
- class Foscam(eg.PluginBase):
- name = "FOSCAM FI8908W FI8918W / HEDEN VisionCam"
- description = "Take control of your ipcam, and get new features (patrolling, etc)."
- def __start__(self,ip="",port=8100, browserPath='C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe', login="admin",pwd="",safeHTTPMode = False, debug= False):
- self.debug = debug
- self.ip = ip
- self.port = port
- self.browserPath = browserPath
- self.login = login
- self.pwd = pwd
- self.safeHTTPMode = safeHTTPMode
- self.__SetFoscamMainCommands__()
- def __init__(self):
- self.AddAction(StartPatrolling)
- self.AddAction(SnapshotTimer)
- self.AddAction(StopPatrolling)
- self.AddAction(StopTimedSnapshot)
- self.AddAction(SaveSnapshot)
- self.AddAction(ShowSnapshot)
- self.AddAction(VideoStream)
- self.AddAction(GoToPreset)
- self.AddAction(RecordPreset)
- self.AddAction(SwitchIR)
- self.AddAction(SwitchAlarm)
- self.AddAction(SendRawCommand)
- self.AddAction(VideoBroadcast)
- def __stop__(self):
- if hasattr(self, "stopPatrolThreadEvent") :
- self.StopPatrolling()
- if hasattr(self, "stopSnapshotTimerThreadEvent") :
- self.StopTimedSnapshot()
- def __SetFoscamMainCommands__(self) :
- self.CMDS = {'IpCamURL': "http://{0}:{1}/".format(self.ip,self.port)}
- self.CMDS['UserLogin'] = "user={0}&pwd={1}".format(self.login,self.pwd)
- self.CMDS['SnapshotUrl'] = self.CMDS['IpCamURL'] + "snapshot.cgi?" + self.CMDS['UserLogin']
- self.CMDS['VideoStreamUrl'] = self.CMDS['IpCamURL'] + "videostream.asf?" + self.CMDS['UserLogin']
- self.CMDS['SetCommandUrl'] = self.CMDS['IpCamURL'] + "decoder_control.cgi?command={0}&" + self.CMDS['UserLogin']
- self.CMDS['SwitchAlarmUrl'] = self.CMDS['IpCamURL'] +"set_alarm.cgi?motion_armed={0}&motion_sensitivity={1}&input_armed={2}&iolinkage={3}&mail={4}&upload_interval={5}&schedule_enable=0&schedule_sun_0=0&schedule_sun_1=0&schedule_sun_2=0&schedule_mon_0=0&schedule_mon_1=0&schedule_mon_2=0&schedule_tue_0=0&schedule_tue_1=0&schedule_tue_2=0&schedule_wed_0=0&schedule_wed_1=0&schedule_wed_2=0&schedule_thu_0=0&schedule_thu_1=0&schedule_thu_2=0&schedule_fri_0=0&schedule_fri_1=0&schedule_fri_2=0&schedule_sat_0=0&schedule_sat_1=0&schedule_sat_2=0&" + self.CMDS['UserLogin']
- def SwitchAlarm(self, motion_armed=0,motion_sensitivity=10,input_armed=0,iolinkage=0,mail=0,upload_interval=10) :
- if(self.debug):
- print("Foscam debug : " + self.CMDS['SwitchAlarmUrl'].format(motion_armed,10-motion_sensitivity,input_armed,iolinkage,mail,upload_interval))
- self.SendHTTP(self.CMDS['SwitchAlarmUrl'].format(motion_armed,10-motion_sensitivity,input_armed,iolinkage,mail,upload_interval))
- def GotoPreset(self,preset):
- # Stopping patrol before any action
- if hasattr(self, "stopPatrolThreadEvent") :
- self.StopPatrolling()
- self.SendHTTP(self.CMDS['SetCommandUrl'].format(30 + preset * 2 -1))
- def RecordPreset(self,preset):
- # Stopping patrol before any action
- if hasattr(self, "stopPatrolThreadEvent") :
- self.StopPatrolling()
- self.SendHTTP(self.CMDS['SetCommandUrl'].format(30 + preset * 2 -2 ))
- def StopPatrolling(self):
- self.stopPatrolThreadEvent.set()
- def StopTimedSnapshot(self):
- self.stopSnapshotTimerThreadEvent.set()
- def SwitchIR(self,bSwitchIR) :
- if(bSwitchIR) :
- self.SendHTTP(self.CMDS['SetCommandUrl'].format(95))
- else :
- self.SendHTTP(self.CMDS['SetCommandUrl'].format(94))
- def SendRawCommand(self,command) :
- self.SendHTTP(self.CMDS['SetCommandUrl'].format(command))
- def SaveSnapshot(self, folder):
- # saving a snapshot
- opener1 = urllib2.build_opener()
- page1 = opener1.open(self.CMDS['SnapshotUrl'])
- my_picture = page1.read()
- now = datetime.now()
- filename = folder + "%i%i%i_%ih%i-%i.jpg" % (now.year,now.month, now.day, now.hour,now.minute,now.second)
- fout = open(filename, "wb")
- fout.write(my_picture)
- fout.close()
- print "Foscam : saved " + "%i%i%i_%ih%i-%i.jpg" % (now.year,now.month, now.day, now.hour,now.minute,now.second)
- def SnapshotTimer(self, stopSnapshotTimerThreadEvent, interval=None, duration=1440, folder = None):
- if duration <> 0 :
- self.timerEndTime = datetime.now() + timedelta( minutes = duration)
- Text.timerSnapshotInfo.format(interval, self.timerEndTime.isoformat(' '))
- while not stopSnapshotTimerThreadEvent.isSet():
- # saving snapshot
- opener1 = urllib2.build_opener()
- page1 = opener1.open(self.CMDS['SnapshotUrl'])
- my_picture = page1.read()
- now = datetime.now()
- filename = folder + "%i%i%i_%ih%i-%i.jpg" % (now.year,now.month, now.day, now.hour,now.minute,now.second)
- fout = open(filename, "wb")
- fout.write(my_picture)
- fout.close()
- print "Foscam : saved " + "%i%i%i_%ih%i-%i.jpg" % (now.year,now.month, now.day, now.hour,now.minute,now.second)
- # Let's stop the thread if necessary
- if duration <> 0 :
- if datetime.now() > self.timerEndTime :
- self.stopSnapshotTimerThreadEvent.set()
- print Text.timerSnapshotEndInfo
- # Wait n seconds before looping
- stopSnapshotTimerThreadEvent.wait(int(interval))
- def LoopPatrolling(self, stopPatrolThreadEvent, sleepTime, firstPosition, secondPosition,duration=1440):
- if duration <> 0 :
- self.patrolEndTime = datetime.now() + timedelta( minutes = duration)
- print Text.patrolLoopInfo.format(sleepTime, self.patrolEndTime.isoformat(' '))
- self.currentPosition = firstPosition
- while not stopPatrolThreadEvent.isSet():
- # Preset call
- self.SendHTTP(self.CMDS['SetCommandUrl'].format(30 + self.currentPosition * 2 -1 ))
- print "Foscam : patrolling to {0}".format(self.currentPosition)
- # Switch from one preset to the other
- if self.currentPosition == firstPosition :
- self.currentPosition = secondPosition
- else :
- self.currentPosition = firstPosition
- # Let's stop the thread if necessary
- if duration <> 0 :
- if datetime.now() > self.patrolEndTime :
- self.stopPatrolThreadEvent.set()
- # Going back to the first preset
- self.SendHTTP(self.CMDS['SetCommandUrl'].format(30 + firstPosition * 2 -1 ))
- print Text.patrolLoopEndInfo
- # Wait n seconds before looping
- stopPatrolThreadEvent.wait(int(sleepTime))
- # This method was taken from the Execute.py file that comes with eventghost
- def LaunchApp(
- self,
- application,
- argument=''
- ):
- returnValue = None
- winState=0
- waitForCompletion=False
- priority=2
- workingDir=""
- #pathname = eg.ParseString(pathname)
- pathname = eg.ParseString(application)
- if not workingDir:
- workingDir = dirname(abspath(pathname))
- argument = eg.ParseString(argument)
- commandLine = create_unicode_buffer('"%s" %s' % (pathname, argument))
- startupInfo = STARTUPINFO()
- startupInfo.cb = sizeof(STARTUPINFO)
- startupInfo.dwFlags = STARTF_USESHOWWINDOW
- startupInfo.wShowWindow = WINSTATE_FLAGS[winState]
- priorityFlag = PRIORITY_FLAGS[priority]
- processInformation = PROCESS_INFORMATION()
- if(self.debug) :
- print ("Foscam debug : launching " + application + " " + argument)
- res = CreateProcess(
- None, # lpApplicationName
- commandLine, # lpCommandLine
- None, # lpProcessAttributes
- None, # lpThreadAttributes
- False, # bInheritHandles
- priorityFlag|CREATE_NEW_CONSOLE, # dwCreationFlags
- None, # lpEnvironment
- workingDir, # lpCurrentDirectory
- startupInfo, # lpStartupInfo
- processInformation # lpProcessInformation
- )
- if res == 0:
- raise self.Exception(FormatError())
- if waitForCompletion:
- WaitForSingleObject(processInformation.hProcess, INFINITE)
- exitCode = DWORD()
- if not GetExitCodeProcess(
- processInformation.hProcess,
- byref(exitCode)
- ):
- raise self.Exception(FormatError())
- returnValue = exitCode.value
- CloseHandle(processInformation.hProcess)
- CloseHandle(processInformation.hThread)
- return returnValue
- def LaunchSnapshot(self):
- self.LaunchApp(self.browserPath , self.CMDS['SnapshotUrl'])
- def SendHTTP(self, url) :
- if(self.safeHTTPMode) :
- self.LaunchApp(self.browserPath , url)
- else :
- urllib2.urlopen(url)
- def LaunchVideoStream(self, bShow = True, bRecord = False, folder = "c:\\temp\\",vCodec="mp4v", bitrate = 2048, bAudioRecord = True, bFullScreenVideo = True, duration = 60 ):
- now = datetime.now()
- file = "%i%i%i_%ih%i-%i.avi" % (now.year,now.month, now.day, now.hour,now.minute,now.second)
- filename = folder + "\\" + file
- appArgument = " --extraintf=rc --rc-host=localhost:1234 --rc-quiet --rc-show-pos --run-time %i --stop-time=%i --no-qt-privacy-ask --no-qt-error-dialogs "%(duration,duration) # --extraintf logger --verbose=0 --logmode=text --file-logging --save-config --logfile=%s
- if(not bShow):
- appArgument = " -I" + appArgument
- if(bAudioRecord) :
- audioArgument = "acodec=mp3,ab=64,channels=1,samplerate=8000"
- else :
- audioArgument = "noaudio"
- appArgument += " --volume 0 "
- if(bShow and not bRecord):
- appArgument += self.CMDS['VideoStreamUrl']
- if bFullScreenVideo :
- appArgument += "--fullscreen"
- elif (bShow and bRecord):
- appArgument += "\"" + self.CMDS['VideoStreamUrl'] + "\" --sout=#transcode{{vcodec=" + vCodec + ",vb=%i"%bitrate + "," + audioArgument +"}:duplicate{{dst=display,dst=std{{access=file,mux=ts,dst='" + filename + "'}}'"
- if bFullScreenVideo :
- appArgument += " --fullscreen"
- elif (not bShow and bRecord):
- appArgument += "\"" + self.CMDS['VideoStreamUrl'] + "\" --sout=#transcode{{vcodec=" + vCodec + ",vb=%i"%bitrate + ',' + audioArgument +'}:std{{access=file,mux=ts,dst=' + filename
- appArgument += "}"
- if (bRecord) :
- self.lastVideoRecord = filename
- appArgument += " vlc://quit"
- if not hasattr(self, "videoRecordCount") :
- self.videoRecordCount = 1
- try :
- eg.plugins.VLC.Start(appArgument)
- except Exception as exc :
- print("Foscam Error : VLC's eventghost plugin is not installed. Please add the VLC plugin (and check that VLC is installed).")
- print(exc)
- pass
- else :
- # The following code detects and compensates a possible vlc/stream failure.
- time.sleep(5)
- try :
- os.remove(folder + "\\" + file)
- if(self.debug):
- print("Foscam debug : Getting camera stream failed, trying again (%i)"%self.videoRecordCount)
- self.videoRecordCount += 1
- if(self.videoRecordCount < 6):
- self.LaunchVideoStream(bShow, bRecord, folder,vCodec, bitrate, bAudioRecord, bFullScreenVideo, duration )
- except WindowsError as wError :
- print("Foscam : Recording " + file + " (%is)"%duration)
- self.videoRecordCount = 0
- pass
- except Exception as exc :
- print("Foscam error : ")
- print type(exc)
- print exc
- pass
- def BroadcastVideo(self, bShow = True, protocol = "rtsp", port = "5554", pageName="stream.sdp"):
- if not hasattr(self, "lastVideoRecord") :
- print ("Foscam : Broadcast can't start because there is no new record")
- return
- if(not bShow) :
- appArgument = " -I "
- else :
- appArgument = ""
- # In case of problems, add this to the argument : --extraintf logger --verbose=2 --logmode=text --file-logging --save-config --logfile=C:\\temp\\My_Broadcast_vlc_log.txt
- appArgument += "--sout=#transcode{soverlay,no-audio,vcodec=mp4v,width=160,height=90,vfilter=\"canvas{width=160,height=90,aspect=16:9}\",fps=15,vb=200,venc=x264{vbv-bufsize=500,partitions=all,level=12,no-cabac,subme=7,threads=4,ref=2,mixed-refs=1,bframes=0,min-keyint=1,keyint=50,trellis=2,direct=auto,qcomp=0.0,qpmax=51}}:gather:rtp{mp4a-latm,sdp=rtsp://0.0.0.0:%i/%s}' \"%s\" vlc://quit"%(port,pageName,self.lastVideoRecord)
- if(self.debug) :
- print("Foscam debug:argument:" + appArgument)
- eg.plugins.VLC.Start(appArgument)
- print("Foscam : Streaming to rtsp://localhost:%i/%s the file %s"%(port,pageName,self.lastVideoRecord) )
- def Configure(self, ip="",port=8100, browserPath="C:\\Program Files (x86)\\Mozilla Firefox\\Firefox.exe", login="admin",pwd="",bSafeHTTPMode = False, bDebug = False):
- panel = eg.ConfigPanel()
- IPCamCtrl = panel.TextCtrl(ip)
- PortCtrl = panel.SpinIntCtrl(port, max=65535)
- LoginCtrl = panel.TextCtrl(login)
- PwdCtrl = wx.TextCtrl(panel, 1, size=(150, -1), style=wx.TE_PASSWORD)
- PwdCtrl.SetValue(pwd)
- IPBox = panel.BoxedGroup(
- Text.ipArea,
- (Text.textBoxIPCamCtrl, IPCamCtrl),
- (Text.textBoxPortCtrl, PortCtrl),
- (Text.textBoxLoginCtrl, LoginCtrl),
- (Text.textBoxPwdCtrl, PwdCtrl),
- )
- eg.EqualizeWidths(IPBox.GetColumnItems(0))
- panel.sizer.Add(IPBox, 0, wx.EXPAND)
- BrowserPathCtrl = panel.TextCtrl(browserPath)
- MediaBox = panel.BoxedGroup(
- Text.mediaArea,
- (Text.textBoxBrowserPathCtrl, BrowserPathCtrl),
- )
- eg.EqualizeWidths(MediaBox.GetColumnItems(0))
- panel.sizer.Add(MediaBox,10,wx.EXPAND)
- checkBoxSafeHttpModeCtrl = wx.CheckBox(panel, -1, "")
- checkBoxSafeHttpModeCtrl.SetValue(bSafeHTTPMode)
- checkBoxDebugCtrl = wx.CheckBox(panel, -1, "")
- checkBoxDebugCtrl.SetValue(bDebug)
- TroubleShootingBox = panel.BoxedGroup(
- Text.troubleShootArea,
- (Text.checkBoxSafeHttpModeCtrl,checkBoxSafeHttpModeCtrl),
- (Text.checkBoxDebugCtrl,checkBoxDebugCtrl),
- )
- eg.EqualizeWidths(TroubleShootingBox.GetColumnItems(0))
- panel.sizer.Add(TroubleShootingBox,10,wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(IPCamCtrl.GetValue(),PortCtrl.GetValue(),BrowserPathCtrl.GetValue(),LoginCtrl.GetValue(),PwdCtrl.GetValue(),checkBoxSafeHttpModeCtrl.GetValue(),checkBoxDebugCtrl.GetValue())
- class StopPatrolling(eg.ActionBase):
- name = "Stop patrolling"
- description = "Camera won't patrol anymore."
- def __call__(self):
- self.plugin.StopPatrolling()
- class SwitchIR(eg.ActionBase):
- name = "IR (switch)"
- description = "Switch IR LEDs ON or OFF."
- iconFile = "ir"
- def __call__(self,bSwitchIR):
- self.plugin.SwitchIR(bSwitchIR)
- def Configure(self, bFullScreenVideo = True):
- panel = eg.ConfigPanel()
- checkBoxSwitchIRCtrl = wx.CheckBox(panel, -1, "")
- checkBoxSwitchIRCtrl.SetValue(bFullScreenVideo)
- IRBox = panel.BoxedGroup(
- Text.switchIR,
- (Text.switchIR,checkBoxSwitchIRCtrl),
- )
- eg.EqualizeWidths(IRBox.GetColumnItems(0))
- panel.sizer.Add(IRBox,10,wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(checkBoxSwitchIRCtrl.GetValue())
- class StartPatrolling(eg.ActionBase):
- name = "Start patrolling"
- description = "Camera will switch from one preset to the other every n seconds."
- iconFile = "patrol"
- def __call__(self, sleepTime=None, pos1 = 1, pos2 = 2, duration = 1440):
- self.plugin.stopPatrolThreadEvent = Event()
- self.plugin.threadPatrol = Thread(
- target=self.plugin.LoopPatrolling,
- args=(self.plugin.stopPatrolThreadEvent,sleepTime,pos1, pos2,duration )
- )
- self.plugin.threadPatrol.start()
- def Configure(self, sleepTime=120, pos1 = 1, pos2 = 2, duration = 1440):
- panel = eg.ConfigPanel()
- sleepCtrl = panel.SpinIntCtrl(sleepTime, max=65535)
- pos1Ctrl = panel.SpinIntCtrl(pos1, min=1, max=16)
- pos2Ctrl = panel.SpinIntCtrl(pos2, min=1, max=16)
- durationCtrl = panel.SpinIntCtrl(duration, min=0, max=65535)
- PatrolBox = panel.BoxedGroup(
- Text.patrolSleepArea,
- (Text.patrolSleepCtrl, sleepCtrl),
- (Text.patrolPos1, pos1Ctrl),
- (Text.patrolPos2, pos2Ctrl),
- (Text.durationCtrl, durationCtrl),
- )
- eg.EqualizeWidths(PatrolBox.GetColumnItems(0))
- panel.sizer.Add(PatrolBox, 1, wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(sleepCtrl.GetValue(),pos1Ctrl.GetValue(),pos2Ctrl.GetValue(), durationCtrl.GetValue())
- class GoToPreset(eg.ActionBase):
- name = "Go to preset"
- description = "Camera will move to a specific preset."
- iconFile = "preset"
- def __call__(self, preset=1):
- self.plugin.GotoPreset(preset)
- def Configure(self, preset=1):
- panel = eg.ConfigPanel()
- presetCtrl = panel.SpinIntCtrl(preset, min=1, max=16)
- presetBox = panel.BoxedGroup(
- Text.presetGotoArea,
- (Text.presetCtrl, presetCtrl),
- )
- panel.sizer.Add(presetBox, 1, wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(presetCtrl.GetValue())
- class RecordPreset(eg.ActionBase):
- name = "Set preset"
- description = "Selected preset will be replaced by the current camera position. Beware that you will lose the previous setting."
- def __call__(self, preset=1):
- self.plugin.RecordPreset(preset)
- def Configure(self, preset=1):
- panel = eg.ConfigPanel()
- presetCtrl = panel.SpinIntCtrl(preset, min=1, max=16)
- presetBox = panel.BoxedGroup(
- Text.presetRecordArea,
- (Text.presetCtrl, presetCtrl),
- )
- panel.sizer.Add(presetBox, 1, wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(presetCtrl.GetValue())
- class ShowSnapshot(eg.ActionBase):
- name = "Snapshot (show)"
- description = "Open a snapshot in the predefined browser."
- iconFile = "snapshot"
- def __call__(self):
- self.plugin.LaunchSnapshot()
- class VideoStream(eg.ActionBase):
- name = "Video (show/record)"
- description = "Open the media app and show or record the camera video stream. VLC is mandatory in order to record."
- iconFile = "video"
- def __call__(self, bShow = True, bRecord = False, folder = "c:\\temp\\",vCodec="mp4v", bitrate = 2048, bAudioRecord = True, bFullScreenVideo = True, duration = 60):
- self.plugin.LaunchVideoStream(bShow, bRecord, folder,vCodec, bitrate, bAudioRecord, bFullScreenVideo, duration)
- def Configure(self, bShow = True, bRecord = False, folder = "c:\\temp\\",vCodec="mp4v", bitrate = 2048, bAudioRecord = True, bFullScreenVideo = True, duration = 60):
- panel = eg.ConfigPanel()
- checkBoxShowCtrl = wx.CheckBox(panel, -1, "")
- checkBoxShowCtrl.SetValue(bShow)
- checkBoxRecordCtrl = wx.CheckBox(panel, -1, "")
- checkBoxRecordCtrl.SetValue(bRecord)
- folderCtrl = panel.TextCtrl(folder)
- codecCtrl = panel.TextCtrl(vCodec)
- bitrateCtrl = panel.SpinIntCtrl(bitrate)
- checkBoxAudioRecordCtrl = wx.CheckBox(panel, -1, "")
- checkBoxAudioRecordCtrl.SetValue(bAudioRecord)
- checkBoxStreamPlayerFullScreenCtrl = wx.CheckBox(panel, -1, "")
- checkBoxStreamPlayerFullScreenCtrl.SetValue(bFullScreenVideo)
- durationCtrl = panel.SpinIntCtrl(duration, min=5, max=65535)
- videoBox = panel.BoxedGroup(
- Text.videoArea,
- (Text.checkBoxShowCtrl, checkBoxShowCtrl),
- (Text.checkBoxRecordCtrl, checkBoxRecordCtrl),
- (Text.checkBoxAudioRecordCtrl,checkBoxAudioRecordCtrl),
- (Text.folderCtrl, folderCtrl),
- (Text.textBoxcodecCtrl, codecCtrl),
- (Text.textBoxbitrateCtrl, bitrateCtrl),
- (Text.checkBoxStreamPlayerFullScreenCtrl,checkBoxStreamPlayerFullScreenCtrl),
- (Text.durationVideoCtrl, durationCtrl),
- )
- eg.EqualizeWidths(videoBox.GetColumnItems(0))
- panel.sizer.Add(videoBox, 1, wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(checkBoxShowCtrl.GetValue(),checkBoxRecordCtrl.GetValue(),folderCtrl.GetValue(),codecCtrl.GetValue(),bitrateCtrl.GetValue(),checkBoxAudioRecordCtrl.GetValue(),checkBoxStreamPlayerFullScreenCtrl.GetValue(),durationCtrl.GetValue())
- class VideoBroadcast(eg.ActionBase):
- name = "Video (broadcast)"
- description = "Broadcast the last recorded file to a specific URL."
- iconFile = "video"
- def __call__(self, bShow = True, protocol = "rtsp", port = "5554", pageName="stream.sdp"):
- self.plugin.BroadcastVideo(bShow, protocol, port,pageName)
- def Configure(self, bShow = True, protocol = "rtsp", port = "5554", pageName="stream.sdp"):
- panel = eg.ConfigPanel()
- protocolCtrl = panel.TextCtrl(protocol)
- pageNameCtrl = panel.TextCtrl(pageName)
- portCtrl = panel.SpinIntCtrl(port)
- checkBoxShowCtrl = wx.CheckBox(panel, -1, "")
- checkBoxShowCtrl.SetValue(bShow)
- videoBox = panel.BoxedGroup(
- Text.videoArea,
- (Text.checkBoxShowCtrl, checkBoxShowCtrl),
- (Text.protocolCtrl, protocolCtrl),
- (Text.portCtrl, portCtrl),
- (Text.pageNameCtrl, pageNameCtrl)
- )
- eg.EqualizeWidths(videoBox.GetColumnItems(0))
- panel.sizer.Add(videoBox, 1, wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(checkBoxShowCtrl.GetValue(),protocolCtrl.GetValue(),portCtrl.GetValue(),pageNameCtrl.GetValue())
- class SendRawCommand(eg.ActionBase):
- name = "Custom command"
- description = "Any Foscam command using the 'decoder_control.cgi?command={commandNumber}' schema can be sent."
- def __call__(self, command=1):
- self.plugin.SendRawCommand(command)
- def Configure(self, command=1):
- panel = eg.ConfigPanel()
- presetCtrl = panel.SpinIntCtrl(command, min=0, max=65535)
- presetBox = panel.BoxedGroup(
- Text.commandNumber,
- (Text.commandNumber, presetCtrl),
- )
- panel.sizer.Add(presetBox, 1, wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(presetCtrl.GetValue())
- class SwitchAlarm(eg.ActionBase):
- name = "Alarm (switch)"
- description = "Switch ON/OFF the alarm with all parameters."
- iconFile = "alarm"
- def __call__(self, motion_armed=0,motion_sensitivity=10,input_armed=0,iolinkage=0,mail=0,upload_interval=10):
- self.plugin.SwitchAlarm(motion_armed,motion_sensitivity,input_armed,iolinkage,mail,upload_interval)
- def Configure(self, motion_armed=0,motion_sensitivity=10,input_armed=0,iolinkage=0,mail=0,upload_interval=10):
- panel = eg.ConfigPanel()
- MotionCtrl = panel.SpinIntCtrl(motion_armed,min=0, max=1)
- SensitivityCtrl = panel.SpinIntCtrl(motion_sensitivity,min=1, max=10)
- InputCtrl = panel.SpinIntCtrl(input_armed,min=0, max=1)
- IOCtrl = panel.SpinIntCtrl(iolinkage,min=0, max=1)
- MailCtrl = panel.SpinIntCtrl(mail,min=0, max=1)
- IntervalCtrl = panel.SpinIntCtrl(upload_interval,min=0, max=65535)
- AlarmBox = panel.BoxedGroup(
- Text.alarmArea,
- (Text.alarmMotionCtrl, MotionCtrl),
- (Text.alarmMailCtrl, MailCtrl),
- )
- eg.EqualizeWidths(AlarmBox.GetColumnItems(0))
- panel.sizer.Add(AlarmBox, 0, wx.EXPAND)
- AlarmMiscBox = panel.BoxedGroup(
- Text.alarmMiscArea,
- (Text.alarmSensitivityCtrl, SensitivityCtrl),
- (Text.alarmInputCtrl, InputCtrl),
- (Text.alarmIOCtrl, IOCtrl),
- (Text.alarmIntervalCtrl, IntervalCtrl),
- )
- eg.EqualizeWidths(AlarmMiscBox.GetColumnItems(0))
- panel.sizer.Add(AlarmMiscBox, 0, wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(MotionCtrl.GetValue(),SensitivityCtrl.GetValue(),InputCtrl.GetValue(),IOCtrl.GetValue(),MailCtrl.GetValue(),IntervalCtrl.GetValue())
- class SnapshotTimer(eg.ActionBase):
- name = "Snapshot (timer)"
- description = "Chose an interval (seconds) and multiple snapshots will be created in the save folder."
- iconFile = "snapshot"
- def __call__(self, interval=None, duration=1440, folder = None):
- self.plugin.stopSnapshotTimerThreadEvent = Event()
- self.plugin.threadTimer = Thread(
- target=self.plugin.SnapshotTimer,
- args=(self.plugin.stopSnapshotTimerThreadEvent,interval, duration,folder )
- )
- self.plugin.threadTimer.start()
- def Configure(self, interval=120, duration=1440, folder = "c:\\temp\\"):
- panel = eg.ConfigPanel()
- intervalTimeCtrl = panel.SpinIntCtrl(interval, min=1, max=65535)
- durationCtrl = panel.SpinIntCtrl(duration, min=0, max=65535)
- folderCtrl = panel.TextCtrl(folder)
- TimerBox = panel.BoxedGroup(
- Text.timerArea,
- (Text.intervalTimeCtrl, intervalTimeCtrl),
- (Text.durationCtrl, durationCtrl),
- (Text.folderCtrl, folderCtrl),
- )
- panel.sizer.Add(TimerBox, 1, wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(intervalTimeCtrl.GetValue(),durationCtrl.GetValue(),folderCtrl.GetValue())
- class StopTimedSnapshot(eg.ActionBase):
- name = "Stop timed snapshots"
- description = "Snapshots won't be saved anymore."
- def __call__(self):
- self.plugin.StopTimedSnapshot()
- class SaveSnapshot(eg.ActionBase):
- name = "Snapshot (save)"
- description = "Chose the save folder."
- iconFile = "snapshot"
- def __call__(self, folder = None):
- self.plugin.SaveSnapshot(folder)
- def Configure(self, folder = "c:\\temp\\"):
- panel = eg.ConfigPanel()
- folderCtrl = panel.TextCtrl(folder)
- SnapBox = panel.BoxedGroup(
- "",
- (Text.folderCtrl, folderCtrl),
- )
- panel.sizer.Add(SnapBox, 1, wx.EXPAND)
- while panel.Affirmed():
- panel.SetResult(folderCtrl.GetValue())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement