# Created by Leo from: C:\Python23\Tom\leo\pyro.leo # << Cameratest declarations >> import Image import urllib2 import ImageChops import image_view import ImageStat import ImageEnhance import rserve #import ArgImagePlugin,BmpImagePlugin,BufrStubImagePlugin,CurImagePlugin,DcxImagePlugin,EpsImagePlugin,FitsStubImagePlugin,FliImagePlugin,FpxImagePlugin,GbrImagePlugin,GifImagePlugin,GribStubImagePlugin,Hdf5StubImagePlugin,IcoImagePlugin,ImImagePlugin,ImtImagePlugin,IptcImagePlugin,JpegImagePlugin,McIdasImagePlugin,MicImagePlugin,MpegImagePlugin,MspImagePlugin,PalmImagePlugin,PcdImagePlugin,PcxImagePlugin,PdfImagePlugin,PixarImagePlugin,PngImagePlugin,PpmImagePlugin,PsdImagePlugin,SgiImagePlugin,SunImagePlugin,TgaImagePlugin,TiffImagePlugin,WmfImagePlugin,XbmImagePlugin,XpmImagePlugin,XVThumbImagePlugin ##for py2exe import wx import time, string from Pyro.EventService.Clients import Publisher, Subscriber from server import CHAT_SERVER_NAME from threading import Thread import Pyro.core from Pyro.errors import NamingError, ConnectionClosedError import wx.lib.evtmgr as EventManager # -- end -- << Cameratest declarations >> # << Cameratest methods >> (1 of 3) class MyFrame(wx.Frame): # << class MyFrame methods >> (1 of 8) def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.DefaultSize) tb = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_HORIZONTAL| wx.NO_BORDER| wx.TB_FLAT) self.cam = dictofpyro['Camera'] self.Bind(wx.EVT_CLOSE, self.OnCloseWindow, id = self.GetId()) maintimerID = wx.NewId() self.maintimer = wx.Timer(self, maintimerID) self.Bind(wx.EVT_TIMER, self.OnTimer, id=maintimerID)#EVT_TIMER(self, maintimerID, self.OnTimer) self.chatter=Chatter(self,-1) self.glob_thing = image_view.ImageView(self, -1) #self.splitter.SetMinimumPaneSize(20) #self.splitter.SplitHorizontally(self.glob_thing, self.text_thing, 0) StartButtonID = wx.NewId() self.StartButton = wx.Button(tb, StartButtonID, "Go", wx.Point(20, 20)) #EVT_BUTTON(self, StartButtonID, self.OnGoClick) self.StartButton.SetBackgroundColour(wx.BLUE) self.StartButton.SetForegroundColour(wx.WHITE) self.StartButton.SetDefault() StopButtonID = wx.NewId() self.StopButton = wx.Button(tb, StopButtonID, "Stop", wx.Point(260, 20)) #EVT_BUTTON(self, StopButtonID, self.OnStopClick) self.StopButton.SetBackgroundColour(wx.RED) self.StopButton.SetForegroundColour(wx.WHITE) #cbID = wx.NewId() tb.AddControl(self.StartButton) self.Bind(wx.EVT_BUTTON, self.OnGoClick, id=StartButtonID) tb.AddSeparator() #cbID = wx.NewId() tb.AddControl(self.StopButton) self.Bind(wx.EVT_BUTTON, self.OnStopClick, id=StopButtonID) tb.AddSeparator() tb.AddSeparator() self.SetToolBar(tb) tb.Realize() self.main_sizer = wx.BoxSizer(wx.VERTICAL) self.main_sizer.Add(self.glob_thing, 5, wx.EXPAND) self.main_sizer.Add(self.chatter, 5, wx.EXPAND) self.SetSizer(self.main_sizer) self.SetAutoLayout(1) self.main_sizer.Fit(self) self.chatter.chooseChannel() # << class MyFrame methods >> (2 of 8) def OnTimer(self, event): img = self.cam.tostring() im2 = Image.fromstring('RGB',(160, 120),img) self.glob_thing.set_image(im2) # << class MyFrame methods >> (3 of 8) def OnCombo(self, event): #print event.GetInt() self.cyclenum = event.GetInt() # << class MyFrame methods >> (4 of 8) def OnSavedir(self, event): #print event.GetInt() self.OnSavedir = event.GetString() # << class MyFrame methods >> (5 of 8) def OnDiffdir(self, event): #print event.GetInt() self.diffsavedir = event.GetString() # << class MyFrame methods >> (6 of 8) def OnCloseWindow(self, event): self.chatter.chatbox.leave(self.chatter.channel, self.chatter.nick) self.chatter.abort() rserve.close() self.Destroy() # << class MyFrame methods >> (7 of 8) def OnGoClick(self, event): self.maintimer.Start(25) # << class MyFrame methods >> (8 of 8) def OnStopClick(self, event): self.maintimer.Stop() # -- end -- << class MyFrame methods >> # << Cameratest methods >> (2 of 3) class Chatter(wx.Panel,Publisher, Subscriber): # << class Chatter methods >> (1 of 4) def __init__(self, parent, ID): wx.Panel.__init__(self, parent, ID) self.display = wx.TextCtrl(self, -1,'', size=(200, 100), style=wx.TE_MULTILINE) self.entry = wx.TextCtrl(self, -1, '', size=(125, -1),style=wx.TE_PROCESS_ENTER ) #self.bind(wx.EVT_TEXT_ENTER, self.OnTxtEnter, id=self.entry.GetId()) EventManager.eventManager.Register(self.OnTxtEnter, wx.EVT_TEXT_ENTER, self.entry) self.StartButton = wx.Button(self, -1, "OK", wx.Point(20, 20)) EventManager.eventManager.Register(self.OnTxtEnter, wx.EVT_BUTTON, self.StartButton) self.StartButton.SetBackgroundColour(wx.GREEN) self.StartButton.SetForegroundColour(wx.WHITE) self.entry_sizer = wx.BoxSizer(wx.HORIZONTAL) self.entry_sizer.Add(self.entry, 10, wx.EXPAND) self.entry_sizer.Add(self.StartButton, 2, wx.EXPAND) self.main_sizer = wx.BoxSizer(wx.VERTICAL) self.main_sizer.Add(self.display, 10, wx.EXPAND) self.main_sizer.Add(self.entry_sizer, 1, wx.EXPAND) self.SetSizer(self.main_sizer) self.SetAutoLayout(1) self.main_sizer.Fit(self) Publisher.__init__(self) Subscriber.__init__(self) self.chatbox = Pyro.core.getProxyForURI('PYRONAME://'+CHAT_SERVER_NAME) #print conntxt,CHAT_SERVER_NAME #uri = Pyro.core.PyroURI(conntxt + CHAT_SERVER_NAME) #self.chatbox = Pyro.core.getProxyForURI('PYRONAME://216.19.27.24:9090/' + CHAT_SERVER_NAME) #'PYROLOC://216.19.27.24:9090/' # << class Chatter methods >> (2 of 4) def event(self, event): (nick,line)=event.msg if nick!=self.nick: self.display.SetValue(self.display.GetValue() + '['+nick+'] '+line + chr(10)) #print '['+nick+'] '+line # << class Chatter methods >> (3 of 4) def chooseChannel(self): nicks=self.chatbox.getNicks() if nicks: str1 = 'The following people are on the server: ' for i in nicks: str1 = str1 +', ' + str(i) str1 = str1 + chr(10) self.display.SetValue(self.display.GetValue() + str1 + chr(10)) #print 'The following people are on the server: ',', '.join(nicks) channels=self.chatbox.getChannels() channels.sort() self.channel="tomchanel" #if channels: # str1 = 'The following channels already exist: ' # for i in channels: # str1 = str1 +', ' + str(i) # str1 = str1 + chr(10) # #print 'The following channels already exist: ',', '.join(channels) # #print # self.display.SetValue(self.display.GetValue() + str1 + chr(10)) # #self.channel=raw_input('Choose a channel or create a new one: ') # dlg = wx.TextEntryDialog(self, 'Choose a channel or create a new one: ','Channel Name', '') # dlg.SetValue("tomchanel") # if dlg.ShowModal() == wx.ID_OK: # self.channel=dlg.GetValue() # # dlg.Destroy() #else: # self.display.SetValue(self.display.GetValue() + 'The server has no active channels.' + chr(10)) # #print 'The server has no active channels.' # dlg = wx.TextEntryDialog(self, 'Name for new channel: ','Channel Name', '') # dlg.SetValue("tomchanel") # if dlg.ShowModal() == wx.ID_OK: # self.channel=dlg.GetValue() # dlg.Destroy() # #self.channel=raw_input('Name for new channel: ') #self.nick=raw_input('Choose a nickname: ') dlg = wx.TextEntryDialog(self, 'Choose a nickname: ','Nickname', '') dlg.SetValue("Forign Entity") if dlg.ShowModal() == wx.ID_OK: self.nick=dlg.GetValue() dlg.Destroy() (self.eventTopic, people)=self.chatbox.join(self.channel,self.nick) self.subscribe(self.eventTopic) str1 = 'Joined as ' + str(self.nick) str2 = 'People on this chat:' for i in people: str2 = str2 +', ' + str(i) str2 = str2 + chr(10) self.display.SetValue(self.display.GetValue() + str1 + chr(10)) self.display.SetValue(self.display.GetValue() + str2 + chr(10)) #self.inputThread=Thread(target=self.handleInput) #self.inputThread.start() try: #self.listen() self.inputThread=Thread(target=self.listen) self.inputThread.start() except KeyboardInterrupt: self.display.SetValue(self.display.GetValue() + 'Shutting down... (press enter)' + chr(10)) #print 'Shutting down... (press enter)' self.abort() self.inputThread.join() # << class Chatter methods >> (4 of 4) def OnTxtEnter(self,event): try: if not self.abortListen: line = self.entry.GetValue() if line: self.publish(self.eventTopic,(self.nick,line)) except EOFError: pass self.display.SetValue(self.display.GetValue() + '[me] '+line + chr(10)) self.entry.SetValue('') # -- end -- << class Chatter methods >> # << Cameratest methods >> (3 of 3) class MyApp(wx.App): # << class MyApp methods >> def OnInit(self): # Create an instance of our customized Frame class frame = MyFrame(None, -1, "Tom Chat") frame.Show(True) # Tell wxWindows that this is our main window self.SetTopWindow(frame) # Return a success flag return True # -- end -- << class MyApp methods >> # -- end -- << Cameratest methods >> #flnm = urllib2.urlopen('http://some.com.rainbow/Pyro_NS_URI') #connect from url #conntxt = flnm.readline() #flnm.close() #dictofpyro = rserve.connect(conntxt) dictofpyro = rserve.connect(None)#brodcast connect dictofpyro.log("connection from Camera") app = MyApp(0) # Create an instance of the application class app.MainLoop() # Tell it to start processing events