-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerGUI.py
160 lines (127 loc) · 5.11 KB
/
ServerGUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#Implementation of chat server using wxpython and socket library.
#Implemented by Aditya Kaushik(www.github.com/FuriousFlash) and Puja Kumari(www.github.com/PujaLuciX)
#Further additions and improvements in progress.
import wx
import socket
import time
import thread
import wx.richtext as rt
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# get local machine name
host = '192.168.1.100'
port = 9999
# bind to the port
serversocket.bind((host, port))
# queue up to 5 requests
serversocket.listen(5)
clientsocket=''
class Example(wx.Frame):
global clientsocket
def __init__(self, parent, title):
super(Example, self).__init__(parent, title=title,
size=(390, 350))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
#font = wx.Font(PointSize, family, style, weight, underline=False, faceName="", encoding=wx.FONTENCODING_DEFAULT)
"""
text = wx.StaticText(panel, -1, 'my text', (20, 100))
font = wx.Font(18, wx.DECORATIVE, wx.ITALIC, wx.NORMAL)
text.SetFont(font)
"""
"""
family = wx.DECORATIVE, wx.DEFAULT,wx.MODERN, wx.ROMAN, wx.SCRIPT or wx.SWISS
style = wx.NORMAL, wx.SLANT or wx.ITALIC.
weight = wx.NORMAL, wx.LIGHT, or wx.BOLD.
"""
font = wx.Font(18, wx.MODERN, wx.ITALIC, wx.NORMAL, underline=False, faceName="", encoding=wx.FONTENCODING_DEFAULT)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
st2 = wx.StaticText(panel, label='Chat ROM')
st2.SetFont(font)
hbox2.Add(st2)
vbox.Add(hbox2, flag=wx.LEFT | wx.TOP, border=10)
vbox.Add((-1, 10))
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
self.tc2 = rt.RichTextCtrl(panel, style=wx.TE_MULTILINE|wx.TE_RICH | wx.TE_READONLY)
font2 = wx.Font(10, wx.MODERN, wx.ITALIC, wx.NORMAL)
self.tc2.SetFont(font2)
hbox3.Add(self.tc2, proportion=1, flag=wx.EXPAND)
self.tc2.GetCaret().Hide()
vbox.Add(hbox3, proportion=3, flag=wx.LEFT|wx.RIGHT|wx.EXPAND,
border=10)
vbox.Add((-1, 10))
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
st1 = wx.StaticText(panel, label='Message')
st1.SetFont(font)
hbox1.Add(st1, flag=wx.RIGHT, border=8)
self.tc = wx.TextCtrl(panel, style=wx.TE_MULTILINE|wx.TE_RICH)
hbox1.Add(self.tc, proportion=1, flag=wx.EXPAND)
vbox.Add(hbox1, proportion=1, flag=wx.EXPAND|wx.LEFT|wx.RIGHT , border=10)
vbox.Add((-1, 25))
"""hbox4 = wx.BoxSizer(wx.HORIZONTAL)
cb1 = wx.CheckBox(panel, label='Case Sensitive')
cb1.SetFont(font)
hbox4.Add(cb1)
cb2 = wx.CheckBox(panel, label='Nested Classes')
cb2.SetFont(font)
hbox4.Add(cb2, flag=wx.LEFT, border=10)
cb3 = wx.CheckBox(panel, label='Non-Project classes')
cb3.SetFont(font)
hbox4.Add(cb3, flag=wx.LEFT, border=10)
vbox.Add(hbox4, flag=wx.LEFT, border=10)
vbox.Add((-1, 25))
"""
hbox5 = wx.BoxSizer(wx.HORIZONTAL)
btn1 = wx.Button(panel, label='Ok', size=(70, 30))
hbox5.Add(btn1)
btn1.Bind(wx.EVT_BUTTON,self.insert)
btn2 = wx.Button(panel, label='Close', size=(70, 30))
hbox5.Add(btn2, flag=wx.LEFT|wx.BOTTOM, border=5)
vbox.Add(hbox5, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=10)
panel.SetSizer(vbox)
def insert(self,e):
self.tc2.BeginBold()
r.tc2.BeginTextColour((0,255,0))
self.tc2.WriteText("Server:")
r.tc2.EndTextColour()
self.tc2.EndBold()
l=self.tc.GetValue()
self.tc2.WriteText(l)
self.tc2.Newline()
clientsocket.sendall(l)
self.tc.Clear()
if __name__ == '__main__':
app = wx.App()
r=Example(None, title='Chat App')
# queue up to 5 requests
def GetConnected():
serversocket.listen(5)
global clientsocket
# establish a connection
clientsocket,addr = serversocket.accept()
font3 = wx.Font(18, wx.ROMAN, wx.ITALIC, wx.NORMAL, underline=False, faceName="", encoding=wx.FONTENCODING_DEFAULT)
u="Got a connection from "+ str(addr)+"\n"
r.tc2.WriteText(u)
r.tc2.BeginAlignment(rt.TEXT_ALIGNMENT_RIGHT)
r.tc2.BeginLineSpacing(rt.TEXT_ATTR_LINE_SPACING_HALF)
r.tc2.EndLineSpacing()
r.tc2.EndAlignment()
while True:
try:
d=clientsocket.recv(1024)
r.tc2.BeginBold()
r.tc2.BeginTextColour((255,0,0))
r.tc2.WriteText("Client:")
r.tc2.EndTextColour()
r.tc2.EndBold()
r.tc2.WriteText(d.decode('ascii'))
r.tc2.Newline()
except:
r.tc2.WriteText("DCED\n")
GetConnected()
clientsocket.close()
thread.start_new_thread(GetConnected,())
app.MainLoop()