一天看完python,一天wxpython,马上实践一下。
# -*- coding: utf-8 -*-
#Just for fuck jack!!!
#-----------------------------------
#author philsong songbohr@163.com
#V0.0.1 2012-8-14 initial version
#V0.0.2 2012-8-15 use mulplex select, wait for notification that an input or output channel is ready
#-----------------------------------
import wx
import socket
import thread
import sys
import select
import Queue
class chatdlg(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, 'chat window',
size=(600, 500))
self.DisplayText = wx.TextCtrl(self, -1, '',
size=(600, 350), style=wx.TE_MULTILINE)
self.InputText = wx.TextCtrl(self, -1, "Hi, jack! What the fuck are u doing now?",
pos=(5, 370), size=(500, -1))
self.sendButton = wx.Button(self, -1, "Send", pos=(510, 370))
self.Bind(wx.EVT_BUTTON, self.OnSendClick, self.sendButton)
self.sendButton.SetDefault()
wx.StaticText(self, -1, "IP", (5, 415))
self.IPText = wx.TextCtrl(self, -1, "219.147.23.114",
pos=(30, 415), size=(150, -1))
wx.StaticText(self, -1, "Port", (200, 415))
self.PortText = wx.TextCtrl(self, -1, "8001",
pos=(230, 415), size=(50, -1))
self.cButton = wx.Button(self, -1, "Connect as a client", pos=(280, 415))
self.Bind(wx.EVT_BUTTON, self.OnClientClick, self.cButton)
self.sButton = wx.Button(self, -1, "Connect as a Server", pos=(390, 415))
self.Bind(wx.EVT_BUTTON, self.OnSeverClick, self.sButton)
def OnSendClick(self, event):
#self.sendButton.SetLabel("Clicked")
self.send_data = self.InputText.GetValue()
try:
self.client.send(self.send_data)
self.DisplayText.AppendText('\nYour said: [')
self.DisplayText.AppendText(self.send_data)
self.DisplayText.AppendText(']\n')
except socket.error, e:
self.Disp