PK 0SQ2rcc SharedMLB.pyUT {B}BUximport os import sys import logging import sys import getopt from string import split, join try: from tempfile import mkdtemp except: from tempfile import mktemp import wx from AccessGrid.SharedAppClient import SharedAppClient from AccessGrid.Platform.Config import UserConfig from AccessGrid.ClientProfile import ClientProfile from AccessGrid import icons from AccessGrid.Toolkit import WXGUIApplication from AccessGrid.NetworkAddressAllocator import NetworkAddressAllocator from AccessGrid.Platform.ProcessManager import ProcessManager from AccessGrid.Platform import IsWindows, IsOSX, Config from AccessGrid.UIUtilities import AboutDialog, MessageDialog, ErrorDialog from AccessGrid.MulticastAddressAllocator import MulticastAddressAllocator ID_START = wx.NewId() ID_TEXT = wx.NewId() ID_EXIT = wx.NewId() ID_SELECT = wx.NewId() ID_AUTOADDR = wx.NewId() ID_CANCEL = wx.NewId() ID_OK = wx.NewId() class MCGAddress: def __init__(self, group=None, ttl="127"): mcaa = MulticastAddressAllocator() self.ipAddressConverter = IpAddressConverter() self.ttl = ttl if group == None: self.group = "%s/%s" % (mcaa.AllocateAddress(), mcaa.AllocatePort()) else: self.group = group print "ADDR: %s" % self.group def getAddress(self): return "%s-%d" % (self.group, self.ttl) def getGroupAddr(self): return self.group def getTTL(self): return self.ttl # ipasList = self.ipAddressConverter.StringToIp(addr) # self.data[0] = ipasList[0] # self.data[1] = ipasList[1] # self.data[2] = ipasList[2] # self.data[3] = ipasList[3] class MLBControl(wx.Panel): """ MLBControl runs agui for the instigator of the session, enabling selection of the multicast group for the session """ def __init__(self, parent, id, log, parentobj=None, mcaddr=None, ttl="127"): wx.Panel.__init__(self, parent, id) self.selectButton = wx.Button(parent, ID_SELECT, "New") self.startButton = wx.Button(parent, ID_START, "Start MLB") self.exitButton = wx.Button(parent, ID_EXIT, "Exit session") self.txt_address = wx.TextCtrl(parent, ID_TEXT, mcaddr, wx.DefaultPosition, (150,18), wx.TE_PROCESS_ENTER) mcs = wx.BoxSizer(wx.HORIZONTAL) mcs.Add(self.txt_address, 0, wx.ALIGN_CENTER) mcs.Add(self.selectButton, 0, wx.ALIGN_CENTER) frameSizer = wx.BoxSizer(wx.VERTICAL) parent.SetSizer(frameSizer) frameSizer.Add(mcs, 0, wx.ALL) frameSizer.Add(self.startButton, 0, wx.ALIGN_CENTER) frameSizer.Add(self.exitButton, 0, wx.ALIGN_CENTER|wx.BOTTOM) log.info("MLBControl") try: parent.Bind(wx.EVT_TEXT_ENTER, parentobj.OnSend, id=ID_TEXT) parent.Bind(wx.EVT_BUTTON, parentobj.OnMCAddrSelect, id=ID_SELECT) except: wx.EVT_TEXT_ENTER(parent, ID_TEXT, parentobj.OnSend) wx.EVT_BUTTON(parent, ID_SELECT, parentobj.OnMCAddrSelect) class MLBSession(wx.Panel): """ MLBSession runs a gui for participants joining a session (no manipulation of multicast group) """ def __init__(self, parent, id, log, parentobj=None, mcaddr=None, ttl="127"): wx.Panel.__init__(self, parent, id) self.txt_address = wx.TextCtrl(parent, ID_TEXT, mcaddr, wx.DefaultPosition, (150,18), wx.TE_READONLY) self.startButton = wx.Button(parent, ID_START, "Start MLB") self.exitButton = wx.Button(parent, ID_EXIT, "Exit session") frameSizer = wx.BoxSizer(wx.VERTICAL) parent.SetSizer(frameSizer) frameSizer.Add(self.txt_address, 0, wx.ALIGN_CENTER) frameSizer.Add(self.startButton, 0, wx.ALIGN_CENTER) frameSizer.Add(self.exitButton, 0, wx.ALIGN_CENTER|wx.BOTTOM) log.info("MLBSession") class StaticAddressingPanel(wx.Dialog, wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) self.ipAddressConverter = IpAddressConverter() # self.staticAddressingButton = wx.CheckBox(self, 5, "Use Static Addressing") self.panel = wx.Panel(self, -1) self.videoTitleText = wx.StaticText(self.panel, -1, "Media Lecture Board", size = wx.Size(100,20)) if IsOSX: self.videoTitleText.SetFont(wx.Font(12, wx.NORMAL, wx.NORMAL, wx.BOLD)) else: self.videoTitleText.SetFont(wx.Font(wx.DEFAULT, wx.NORMAL, wx.NORMAL, wx.BOLD)) self.videoAddressText = wx.StaticText(self.panel, -1, "Address: ", size = wx.Size(60,-1), style = wx.ALIGN_RIGHT) self.videoPortText = wx.StaticText(self.panel, -1, " Port: ", size = wx.Size(45,-1), style = wx.ALIGN_RIGHT) self.videoTtlText = wx.StaticText(self.panel, -1, " TTL:", size = wx.Size(40,-1), style = wx.ALIGN_RIGHT) self.videoIp1 = wx.TextCtrl(self.panel, -1, "", size = wx.Size(30,-1)) self.videoIp2 = wx.TextCtrl(self.panel, -1, "", size = wx.Size(30,-1)) self.videoIp3 = wx.TextCtrl(self.panel, -1, "", size = wx.Size(30,-1)) self.videoIp4 = wx.TextCtrl(self.panel, -1, "", size = wx.Size(30,-1)) self.videoPort = wx.TextCtrl(self.panel, -1, "", size = wx.Size(50,-1)) self.videoTtl = wx.TextCtrl(self.panel, -1, "", size = wx.Size(30,-1)) # if self.staticAddressingButton.GetValue(): # self.panel.Enable(True) # else: # self.panel.Enable(False) self.panel.Enable(True) self.SetValidator(StaticAddressingValidator()) self.cancelButton = wx.Button(self.panel, ID_CANCEL, "Cancel") self.okButton = wx.Button(self.panel, ID_OK, "OK") try: self.panel.Bind(wx.EVT_BUTTON, self.OnMCAddrCancel, id=ID_CANCEL) self.panel.Bind(wx.EVT_BUTTON, self.OnMCAddrOK, id=ID_OK) except: wx.EVT_BUTTON(self.panel, ID_CANCEL, self.OnMCAddrCancel) wx.EVT_BUTTON(self.panel, ID_OK, self.OnMCAddrOK) self.__doLayout() self.__setEvents() def OnMCAddrOK(self, event): self.Validate() pass def OnMCAddrCancel(self, event): pass def __doLayout(self): self.staticAddressingSizer = wx.BoxSizer(wx.VERTICAL) self.staticAddressingSizer.Add(wx.Size(10,10)) # self.staticAddressingSizer.Add(self.staticAddressingButton, 0, wx.EXPAND|wx.ALL, 5) panelSizer = wx.BoxSizer(wx.VERTICAL) videoIpSizer = wx.BoxSizer(wx.HORIZONTAL) videoIpSizer.Add(self.videoIp1, 1 , wx.EXPAND) videoIpSizer.Add(self.videoIp2, 1 , wx.EXPAND) videoIpSizer.Add(self.videoIp3, 1 , wx.EXPAND) videoIpSizer.Add(self.videoIp4, 1 , wx.EXPAND) videoTitleSizer = wx.BoxSizer(wx.HORIZONTAL) videoTitleSizer.Add(self.videoTitleText, 0, wx.ALIGN_CENTER) videoTitleSizer.Add(wx.StaticLine(self.panel, -1), 1, wx.ALIGN_CENTER) panelSizer.Add(videoTitleSizer, 1 , wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 10) vidSizer=wx.BoxSizer(wx.HORIZONTAL) vidSizer.Add(self.videoAddressText,0,wx.EXPAND|wx.LEFT,10) vidSizer.Add(videoIpSizer,5,wx.EXPAND) vidSizer.Add(self.videoPortText,0,wx.EXPAND) vidSizer.Add(self.videoPort,2,wx.EXPAND) vidSizer.Add(self.videoTtlText,0,wx.EXPAND) vidSizer.Add(self.videoTtl,1,wx.EXPAND) panelSizer.Add(vidSizer, 0 , wx.EXPAND|wx.ALL, 5) actionSizer=wx.BoxSizer(wx.HORIZONTAL) actionSizer.Add(self.cancelButton, 0, wx.EXPAND) actionSizer.Add(self.okButton, 0, wx.EXPAND) panelSizer.Add(actionSizer, 0 , wx.EXPAND|wx.ALL, 5) panelSizer.Add(wx.Size(10,10)) self.panel.SetSizer(panelSizer) panelSizer.Fit(self.panel) self.staticAddressingSizer.Add(self.panel, 0 , wx.EXPAND) self.SetSizer(self.staticAddressingSizer) self.staticAddressingSizer.Fit(self) self.SetAutoLayout(1) def __setEvents(self): # EVT_CHECKBOX(self, 5, self.ClickStaticButton) pass def SetStaticVideo(self, videoIp, videoPort, videoTtl): videoList = self.ipAddressConverter.StringToIp(videoIp) self.videoPort.SetValue(str(videoPort)) self.videoIp1.SetValue(str(videoList[0])) self.videoIp2.SetValue(str(videoList[1])) self.videoIp3.SetValue(str(videoList[2])) self.videoIp4.SetValue(str(videoList[3])) self.videoTtl.SetValue(str(videoTtl)) def GetVideoAddress(self): return self.ipAddressConverter.IpToString(self.videoIp1.GetValue(), \ self.videoIp2.GetValue(), \ self.videoIp3.GetValue(), \ self.videoIp4.GetValue()) def GetVideoPort(self): return self.videoPort.GetValue() def GetVideoTtl(self): return self.videoTtl.GetValue() def ClickStaticButton(self, event): if event.Checked(): self.panel.Enable(True) else: self.panel.Enable(False) def Validate(self): # if(self.staticAddressingButton.GetValue()): # return self.GetValidator().Validate(self) # else: # return True return self.GetValidator().Validate(self) class StaticAddressingValidator(wx.PyValidator): ''' Validator used to ensure correctness of parameters entered in StaticAddressingPanel. ''' def __init__(self): wx.PyValidator.__init__(self) def Clone(self): ''' Returns a new StaticAddressingValidator. Note: Overrides super class method. ''' return StaticAddressingValidator() def __CheckIP(self, ip1, ip2, ip3, ip4): try: i1 = int(ip1.GetValue()) i2 = int(ip2.GetValue()) i3 = int(ip3.GetValue()) i4 = int(ip4.GetValue()) except ValueError: MessageDialog(None,"Please, fill in all IP Address fields in 'Addressing' tab.", "Notification") return False if (i1 in range(224, 240) and i2 in range(0,256) and i3 in range(0,256) and i4 in range(0,256)): return True else: MessageDialog(None, "Allowed values for IP Address are between 224.0.0.0 - 239.255.255.255 in 'Addressing' tab", "Notification") return False def __CheckPort(self, port): try: int(port.GetValue()) return True except ValueError: MessageDialog(None,"%s is not a valid port in 'Addressing' tab."%(port.GetValue()), "Notification") return False def __CheckTTL(self, ttl): try: ttl = int(ttl.GetValue()) except ValueError: MessageDialog(None,"%s is not a valid time to live (TTL) value in 'Addressing' tab."%(ttl.GetValue()), "Notification") return False if not ttl in range(0,128): MessageDialog(None, "Time to live (TTL) should be a value between 0 - 127 in 'Addressing' tab.", "Notification") return False else: return True def Validate(self, win): ''' Checks if win has correct parameters. ''' return (self.__CheckIP(win.videoIp1, win.videoIp2, win.videoIp3, win.videoIp4) and self.__CheckPort(win.videoPort) and self.__CheckTTL(win.videoTtl)) def TransferToWindow(self): return True # Prevent wxDialog from complaining. def TransferFromWindow(self): return True # Prevent wxDialog from complaining. class IpAddressConverter: def __init__(self): self.ipString = "" self.ipIntList = [] def StringToIp(self, ipString): ipStringList = string.split(ipString, '.') self.ipIntList = map(string.atoi, ipStringList) return self.ipIntList def IpToString(self, ip1, ip2, ip3, ip4): self.ipString = str(ip1)+'.'+str(ip2)+'.'+str(ip3)+'.'+str(ip4) return self.ipString ############################################################## # # Global functions # ############################################################## class multicastDialog(wx.Dialog): def __init__(self, parent, group="", ttl="127"): wx.Dialog.__init__(self, parent, -1, "Multicast Address Selector") self.parent = parent self.videoTitleText = wx.StaticText(self, -1, "Media Lecture Board", size = wx.Size(100,20)) if IsOSX: self.videoTitleText.SetFont(wx.Font(12, wx.NORMAL, wx.NORMAL, wx.BOLD)) else: self.videoTitleText.SetFont(wx.Font(wx.DEFAULT, wx.NORMAL, wx.NORMAL, wx.BOLD)) self.videoAddressText = wx.StaticText(self, -1, "Address: ", size = wx.Size(60,-1), style = wx.ALIGN_RIGHT) self.videoPortText = wx.StaticText(self, -1, " Port: ", size = wx.Size(45,-1), style = wx.ALIGN_RIGHT) self.videoTtlText = wx.StaticText(self, -1, " TTL:", size = wx.Size(40,-1), style = wx.ALIGN_RIGHT) self.videoIp1 = wx.TextCtrl(self, -1, "", size = wx.Size(30,-1)) self.videoIp2 = wx.TextCtrl(self, -1, "", size = wx.Size(30,-1)) self.videoIp3 = wx.TextCtrl(self, -1, "", size = wx.Size(30,-1)) self.videoIp4 = wx.TextCtrl(self, -1, "", size = wx.Size(30,-1)) self.videoPort = wx.TextCtrl(self, -1, "", size = wx.Size(50,-1)) self.videoTtl = wx.TextCtrl(self, -1, "", size = wx.Size(30,-1)) self.videoSpace = wx.StaticText(self, -1, " ", size = wx.Size(10,-1), style = wx.ALIGN_RIGHT) self.autoAddrButton = wx.Button(self, ID_AUTOADDR, "Auto Address") self.cancelButton = wx.Button(self, ID_CANCEL, "Cancel") self.okButton = wx.Button(self, ID_OK, "OK") try: self.Bind(wx.EVT_BUTTON, self.OnAutoAddress, id=ID_AUTOADDR) self.Bind(wx.EVT_BUTTON, self.OnMCDialogCancel, id=ID_CANCEL) self.Bind(wx.EVT_BUTTON, self.OnMCDialogOK, id=ID_OK) except: wx.EVT_BUTTON(self, ID_AUTOADDR, self.OnAutoAddress) wx.EVT_BUTTON(self, ID_CANCEL, self.OnMCDialogCancel) wx.EVT_BUTTON(self, ID_OK, self.OnMCDialogOK) self.videoTtl.SetValue(ttl) if len(group) > 0: self.grp = split(group, "/") self.videoPort.SetValue(self.grp[-1]) self.grpIP = split(self.grp[0], ".") self.videoIp1.SetValue(self.grpIP[0]) self.videoIp2.SetValue(self.grpIP[1]) self.videoIp3.SetValue(self.grpIP[2]) self.videoIp4.SetValue(self.grpIP[3]) self.SetValidator(StaticAddressingValidator()) self.__doLayout() def __doLayout(self): panelSizer = wx.BoxSizer(wx.VERTICAL) panelSizer.Add(self.videoIp1, 1 , wx.EXPAND) videoIpSizer = wx.BoxSizer(wx.HORIZONTAL) videoIpSizer.Add(self.videoIp1, 1 , wx.EXPAND) videoIpSizer.Add(self.videoIp2, 1 , wx.EXPAND) videoIpSizer.Add(self.videoIp3, 1 , wx.EXPAND) videoIpSizer.Add(self.videoIp4, 1 , wx.EXPAND) videoTitleSizer = wx.BoxSizer(wx.HORIZONTAL) videoTitleSizer.Add(self.videoTitleText, 0, wx.ALIGN_CENTER) # videoTitleSizer.Add(wx.StaticLine(self.panel, -1), 1, wx.ALIGN_CENTER) videoTitleSizer.Add(wx.StaticLine(self, -1), 1, wx.ALIGN_CENTER) panelSizer.Add(videoTitleSizer, 1 , wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 10) vidSizer=wx.BoxSizer(wx.HORIZONTAL) vidSizer.Add(self.videoAddressText,0,wx.EXPAND|wx.LEFT,10) vidSizer.Add(videoIpSizer,5,wx.EXPAND) vidSizer.Add(self.videoPortText,0,wx.EXPAND) vidSizer.Add(self.videoPort,2,wx.EXPAND) vidSizer.Add(self.videoTtlText,0,wx.EXPAND) vidSizer.Add(self.videoTtl,1,wx.EXPAND) vidSizer.Add(self.videoSpace,0,wx.EXPAND) vidSizer.Add(self.autoAddrButton, 0, wx.EXPAND) panelSizer.Add(vidSizer, 0 , wx.EXPAND|wx.ALL, 5) actionSizer=wx.BoxSizer(wx.HORIZONTAL) actionSizer.Add(self.cancelButton, 0, wx.EXPAND) actionSizer.Add(self.okButton, 0, wx.EXPAND) panelSizer.Add(actionSizer, 0 , wx.EXPAND|wx.ALL, 5) panelSizer.Add(wx.Size(10,10)) self.SetSizer(panelSizer) panelSizer.Fit(self) self.SetAutoLayout(1) def Validate(self): return self.GetValidator().Validate(self) def OnAutoAddress(self, event): print "AUTO ADDRESS" mcAddr = MCGAddress() group = mcAddr.getGroupAddr() if len(group) > 0: self.grp = split(group, "/") self.videoPort.SetValue(self.grp[-1]) self.grpIP = split(self.grp[0], ".") self.videoIp1.SetValue(self.grpIP[0]) self.videoIp2.SetValue(self.grpIP[1]) self.videoIp3.SetValue(self.grpIP[2]) self.videoIp4.SetValue(self.grpIP[3]) def OnMCDialogCancel(self, event): self.EndModal(wx.ID_CANCEL) def OnMCDialogOK(self, event): if self.Validate(): self.newaddr = "%s.%s.%s.%s/%s" % \ (self.videoIp1.GetValue(), self.videoIp2.GetValue(), self.videoIp3.GetValue(), self.videoIp4.GetValue(), self.videoPort.GetValue()) self.parent.mcGroup = self.newaddr self.parent.mcTTL = self.videoTtl.GetValue() self.EndModal(wx.ID_OK) class SharedMLB( wx.App ): """ SharedMLB wraps MLB as an Access Grid Shared Session """ def OnInit(self): return 1 def OnExit(self, event): ''' Shut down shared browser. ''' self.sharedAppClient.Shutdown() self.frame.Close(True) for p in self.pids: pid = self.processManager.TerminateProcess(p) # Delete temporary storage directory & contents dfiles = os.listdir(self.tmpStorageArea) for f in dfiles: self.log.info("Removing: %s" % f) os.remove(os.path.join(self.tmpStorageArea, f)) os.removedirs(self.tmpStorageArea) os._exit(1) def __init__( self, appUrl, venueUrl, name): ''' Creates the shared application client, used for application service interaction, and opens a web browser for UI display. ''' wx.App.__init__(self, False) # Create shared application client self.sharedAppClient = SharedAppClient(name) self.log = self.sharedAppClient.InitLogging() # Do everything in our own special place, if possible try: self.tmpStorageArea = mkdtemp(prefix=name) except: self.log.exception("failed to create temporary storage area") self.tmpStorageArea = os.tempnam() os.mkdir(self.tmpStorageArea) else: os.chdir(self.tmpStorageArea) self.processManager = ProcessManager() self.pids = [] # Get client profile try: clientProfileFile = os.path.join(UserConfig.instance().GetConfigDir(), "profile") clientProfile = ClientProfile(clientProfileFile) except: self.log.info("SharedAppClient.Connect: Could not load client profile, set clientProfile = None") clientProfile = None else: self.log.info("SharedAppClient.Connect: Loaded ClientProfile") self.log.info("XXX My profile.name: %s" % clientProfile.name) # Join the application session. self.sharedAppClient.Join(appUrl, clientProfile) self.publicId = self.sharedAppClient.GetPublicId() self.log.info("SharedAppClient.Connect: Joined session") # Am I the user who created the shared session? appState = self.sharedAppClient.GetApplicationState() self.iamowner = self.nameIsDescribedName(clientProfile.name, appState.description) self.log.debug("XXX appState.name: %s" % appState.name) self.log.debug("XXX appState.description: %s" % appState.description) self.log.debug("XXX appState.id: %s" % appState.id) self.log.debug("XXX appState.mimeType: %s" % appState.mimeType) self.log.debug("XXX appState.uri: %s" % appState.uri) self.log.debug("XXX appState.data: %s" % appState.data) group = self.sharedAppClient.GetData("group_MLB") if len(group) > 0: self.log.info("Already have group addr: %s" % group) self.mcGroup = group self.mcTTL = "%s" % self.sharedAppClient.GetData("ttl_MLB") if self.iamowner: # Create MLBControl Window self.frame = wx.Frame(None, -1, "MLB Controller", size=(381,100)) self.videocontrol = MLBControl(self.frame, -1, self.log, self, self.mcGroup, self.mcTTL) else: # Create MLBSession Window self.frame = wx.Frame(None, -1, "MLB Session", size=(381,100)) self.videocontrol = MLBSession(self.frame, -1, self.log, self, self.mcGroup, self.mcTTL) else: if self.iamowner: self.log.info("XXX I own this Shared app!") mcAddr = MCGAddress() self.mcGroup = mcAddr.getGroupAddr() self.mcTTL = mcAddr.getTTL() self.sharedAppClient.SetData("group_MLB", self.mcGroup) self.sharedAppClient.SetData("ttl_MLB", self.mcTTL) self.log.info("GetGroupAddr: %s, ttl: %s" % (self.mcGroup, self.mcTTL)) # Create MLBControl Window self.frame = wx.Frame(None, -1, "MLB Controller", size=(381,100)) self.videocontrol = MLBControl(self.frame, -1, self.log, self, self.mcGroup, self.mcTTL) else: # We're not the owner and there's no group set up yet # have to set up a callback or something to continue # For now, just exit self.OnExit(None) try: self.frame.Bind(wx.EVT_BUTTON, self.OnExit, id=ID_EXIT) self.frame.Bind(wx.EVT_BUTTON, self.OnStart, id=ID_START) except: wx.EVT_BUTTON( self.frame, ID_EXIT, self.OnExit) wx.EVT_BUTTON(self.frame, ID_START, self.OnStart) # Register browse event callback self.sharedAppClient.RegisterEventCallback("browse", self.BrowseCallback ) # Register new group event callback self.sharedAppClient.RegisterEventCallback("new_group_MLB", self.NewGroupCallback ) self.frame.Show(1) self.SetTopWindow(self.frame) def NewGroupCallback(self, event): """ """ self.log.debug("XXX NewGroupCallback") # Determine if the sender of the event is this component or not. (senderId, newgroup, newttl) = event.data if senderId == self.sharedAppClient.GetPublicId(): self.log.debug("Sender processing newGroup: %s, newTTL: %s" % (newgroup, newttl)) # As sender, other values already set (prior to sending event to others) else: self.log.debug("Receiver processing newGroup: %s, newTTL: %s" % (newgroup, newttl)) self.mcGroup = newgroup self.mcTTL = newttl self.videocontrol.txt_address.SetValue(newgroup) def BrowseCallback(self, event): """ Callback invoked when incoming browse events arrive. Events can include this component's browse events, so these need to be filtered out. """ pass def nameIsDescribedName(self, name, desc): """ Determine whether name matches the name component within desc (where desc is the desciption field of a SharedApplication's State). Return True or False """ nameList = desc.split() dname = join(nameList[2:-6]) self.log.debug("XXX name component of app description: %s", dname) return name == dname def OnSend(self, event): ''' What to do when send button is pressed ''' if event.GetId() == ID_TEXT: self.log.debug("XXX TEXT was returned") def OnStart(self, event): ''' What to do when start button is pressed - start the video stream ''' self.log.debug("XXX START was returned") print "XXX START was returned" # Possible options are: # maddr/mport # -t ttl # -f file print "MLB group: %s" % self.sharedAppClient.GetData("group_MLB") options = [] options.append(self.sharedAppClient.GetData("group_MLB")) # options.append("234.56.78.90/19019") opts = split("-t 64") for o in opts: options.append(o) exeFile = os.path.join(os.path.expanduser("~"), "mlb", "mlb") if not os.path.exists(exeFile): self.log.debug("XXX %s not available" % exeFile) self.log.debug("XXX Video executable: %s", exeFile) executable = exeFile pid = self.processManager.StartProcess(executable, options) self.pids.append(pid) def OnMCAddrSelect(self, event): ''' What to do when "Set multicast address" button is pressed ''' dlg = multicastDialog(parent=self.frame, group=self.mcGroup, ttl=self.mcTTL) if dlg.ShowModal() == wx.ID_OK: # Replace existing multicast details print ("new addr: %s" % self.frame.mcGroup) self.mcGroup = self.frame.mcGroup self.mcTTL = self.frame.mcTTL self.sharedAppClient.SetData("group_MLB", self.mcGroup) self.sharedAppClient.SetData("ttl_MLB", self.mcTTL) publicId = self.sharedAppClient.GetPublicId() self.sharedAppClient.SendEvent("new_group_MLB", ( publicId, self.sharedAppClient.GetData("group_MLB"), self.sharedAppClient.GetData("ttl_MLB") ) ) else: # Retain existing multicast details print ("YYYYYYYYYYYYYYYYYYYYYYYYYYYY") dlg.Destroy() class ArgumentManager: def __init__(self): self.arguments = {} self.arguments['applicationUrl'] = None self.arguments['venueUrl'] = None self.arguments['debug'] = 0 def GetArguments(self): return self.arguments def Usage(self): """ How to use the program. """ print "%s:" % sys.argv[0] print " -a|--applicationURL : " print " -v|--venueUrl : " print " -d|--debug : " print " -h|--help : " def ProcessArgs(self): """ Handle any arguments we're interested in. """ try: opts, args = getopt.getopt(sys.argv[1:], "a:v:d:h", ["applicationURL=", "venueURL=", "debug", "help"]) except getopt.GetoptError: self.Usage() sys.exit(2) for o, a in opts: if o in ("-a", "--applicationURL"): self.arguments["applicationUrl"] = a elif o in ("-v", "--venueURL"): self.arguments["venueUrl"] = a elif o in ("-d", "--debug"): self.arguments["debug"] = 1 elif o in ("-h", "--help"): self.Usage() sys.exit(0) if __name__ == "__main__": app = WXGUIApplication() name = "SharedMLB" # Parse command line options am = ArgumentManager() am.ProcessArgs() aDict = am.GetArguments() appUrl = aDict['applicationUrl'] venueUrl = aDict['venueUrl'] debugMode = aDict['debug'] init_args = [] if "--debug" in sys.argv or "-d" in sys.argv: init_args.append("--debug") app.Initialize(name, args=init_args) if not appUrl: am.Usage() elif not venueUrl: am.Usage() else: wx.InitAllImageHandlers() sb = SharedMLB( appUrl, venueUrl, name) sb.MainLoop() PK kP2d SharedMLB.appUT ۼBVBUx[application] name = Shared MLB mimetype = application/x-ag-shared-mlb extension = sharedmlb files = SharedMLB.py [commands] Open = %(python)s SharedMLB.py -a %(appUrl)s -v %(venueUrl)s PK 0SQ2rcc SharedMLB.pyUT{BUxPK kP2d cSharedMLB.appUTۼBUxPKd