Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import socket
- import wx
- # import thread module
- from _thread import *
- import threading
- #-------------------------------------------------------------------------------------------------
- class MainWindow(wx.Frame):
- def __init__(self, parent, title):
- wx.Frame.__init__(self, parent, title=title, size=(300, 400))
- self.control = wx.TextCtrl(self, size = (200, 25))
- self.control2 = wx.TextCtrl(self, size = (200, 25), pos = (0, 25), style = wx.TE_READONLY)
- self.CreateStatusBar() # A StatusBar in the bottom of the window
- # Setting up the menu.
- filemenu= wx.Menu()
- # wx.ID_ABOUT and wx.ID_EXIT are standard ids provided by wxWidgets.
- menuAbout = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
- menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
- # Creating the menubar.
- menuBar = wx.MenuBar()
- menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
- self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
- bSendButton = wx.Button(self, 10, "Send", (0, 200))
- bSendButton.SetDefault()
- bSendButton.SetSize(bSendButton.GetBestSize())
- # Set events.
- self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
- self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
- self.Bind(wx.EVT_BUTTON, self.OnClick, bSendButton)
- self.Show(True)
- self.buttons = { bSendButton : 'Test String'}
- def OnAbout(self,e):
- # A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets.
- dlg = wx.MessageDialog( self, "A small text editor", "About Sample Editor", wx.OK)
- dlg.ShowModal() # Show it
- dlg.Destroy() # finally destroy it when finished.
- def OnExit(self,e):
- self.Close(True) # Close the frame.
- def OnClick(self, event):
- #self.log.write("Click! (%d)\n" % event.GetId())
- self.control2.Clear()
- testVar = self.control.GetValue()
- print(str(self.control.GetInsertionPoint()))
- self.control2.write(testVar)
- #-------------------------------------------------------------------------------------------------
- print_lock = threading.Lock()
- lastdata=''
- def threaded(conn, lastdata):
- try:
- while True:
- data = conn.recv(1024)
- if data!= lastdata:
- print(data)
- conn.sendall(data+b'>')
- lastdata=data
- except:
- conn.close()
- print_lock.release()
- #-------------------------------------------------------------------------------------------------
- def listenThread():
- lastdata=b''
- HOST = '' # Symbolic name meaning the local host
- PORT = 25000 # Arbitrary non-privileged port
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.bind((HOST, PORT))
- s.listen(1)
- while True:
- conn, addr = s.accept()
- print_lock.acquire()
- print ('Connected by', addr[0], ':', addr[1])
- start_new_thread(threaded, (conn, lastdata))
- start_new_thread(listenThread, ())
- app = wx.App(False)
- frame = MainWindow(None, "Sample editor")
- frame2 = MainWindow(None, "Sample editor 2")
- app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement