Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.34 KB | None | 0 0
  1. import os
  2. import socket
  3. import wx
  4. # import thread module
  5. from _thread import *
  6. import threading
  7. #-------------------------------------------------------------------------------------------------
  8.  
  9. class MainWindow(wx.Frame):
  10.     def __init__(self, parent, title):
  11.         wx.Frame.__init__(self, parent, title=title, size=(300, 400))
  12.         self.control = wx.TextCtrl(self, size = (200, 25))
  13.         self.control2 = wx.TextCtrl(self, size = (200, 25), pos = (0, 25), style = wx.TE_READONLY)
  14.         self.CreateStatusBar() # A StatusBar in the bottom of the window
  15.        
  16.         # Setting up the menu.
  17.         filemenu= wx.Menu()
  18.  
  19.         # wx.ID_ABOUT and wx.ID_EXIT are standard ids provided by wxWidgets.
  20.         menuAbout = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
  21.         menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
  22.  
  23.         # Creating the menubar.
  24.         menuBar = wx.MenuBar()
  25.         menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
  26.         self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
  27.  
  28.         bSendButton = wx.Button(self, 10, "Send", (0, 200))
  29.         bSendButton.SetDefault()
  30.         bSendButton.SetSize(bSendButton.GetBestSize())
  31.  
  32.  
  33.         # Set events.
  34.         self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
  35.         self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
  36.         self.Bind(wx.EVT_BUTTON, self.OnClick, bSendButton)
  37.  
  38.         self.Show(True)
  39.  
  40.         self.buttons = { bSendButton : 'Test String'}
  41.  
  42.     def OnAbout(self,e):
  43.         # A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets.
  44.         dlg = wx.MessageDialog( self, "A small text editor", "About Sample Editor", wx.OK)
  45.         dlg.ShowModal() # Show it
  46.         dlg.Destroy() # finally destroy it when finished.
  47.  
  48.     def OnExit(self,e):
  49.         self.Close(True)  # Close the frame.
  50.  
  51.     def OnClick(self, event):
  52.         #self.log.write("Click! (%d)\n" % event.GetId())
  53.         self.control2.Clear()
  54.         testVar = self.control.GetValue()
  55.         print(str(self.control.GetInsertionPoint()))
  56.         self.control2.write(testVar)
  57.  
  58. #-------------------------------------------------------------------------------------------------        
  59. print_lock = threading.Lock()
  60. lastdata=''
  61. def threaded(conn, lastdata):
  62.     try:
  63.         while True:
  64.             data = conn.recv(1024)
  65.             if data!= lastdata:
  66.                     print(data)
  67.                     conn.sendall(data+b'>')
  68.                     lastdata=data
  69.     except:
  70.         conn.close()
  71.         print_lock.release()
  72.            
  73. #-------------------------------------------------------------------------------------------------        
  74. def listenThread():
  75.     lastdata=b''
  76.     HOST = ''                 # Symbolic name meaning the local host
  77.     PORT = 25000              # Arbitrary non-privileged port
  78.     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  79.     s.bind((HOST, PORT))
  80.     s.listen(1)
  81.        
  82.     while True:
  83.         conn, addr = s.accept()
  84.         print_lock.acquire()
  85.         print ('Connected by', addr[0], ':', addr[1])
  86.         start_new_thread(threaded, (conn, lastdata))
  87.  
  88.  
  89. start_new_thread(listenThread, ())
  90. app = wx.App(False)
  91. frame = MainWindow(None, "Sample editor")
  92. frame2 = MainWindow(None, "Sample editor 2")
  93. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement