Skip to content

Commit aca0a05

Browse files
committed
Add sample chat skeleton
1 parent 21ece72 commit aca0a05

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

samples/chat/chat.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
"Minimal gui2py CHAT application (to be used as skeleton)"
5+
6+
from __future__ import with_statement # for python 2.5 compatibility
7+
8+
__author__ = "Mariano Reingart ([email protected])"
9+
__copyright__ = "Copyright (C) 2016 Mariano Reingart"
10+
__license__ = "LGPL 3.0"
11+
12+
import gui
13+
14+
# --- here goes your event handlers ---
15+
16+
def send(evt):
17+
"Process an outgoing communication"
18+
# get the text written by the user (input textbox control)
19+
msg = ctrl_input.value
20+
# send the message (replace with socket/queue/etc.)
21+
gui.alert(msg, "Message")
22+
# record the message (update the UI)
23+
log(msg)
24+
ctrl_input.value = ""
25+
ctrl_input.set_focus()
26+
27+
def recv(evt=None):
28+
"Process an incoming communication"
29+
# receive the message (replace with socket/queue/etc.)
30+
msg = ""
31+
# record the message (update the UI)
32+
log(msg)
33+
34+
def log(msg):
35+
"Append the message to the output text box control"
36+
ctrl_output.value += msg + "\n"
37+
38+
# --- gui2py designer generated code starts ---
39+
40+
with gui.Window(name='mywin', title=u'gui2py chat', resizable=True,
41+
height='461px', left='168', top='79', width='400px', ):
42+
gui.TextBox(name=u'output', multiline=True, height='403', left='8',
43+
top='10', width='379')
44+
gui.TextBox(name=u'input', height='30', left='11', top='417', width='323')
45+
gui.Button(label=u'\u2192', name=u'send', left='348', top='419',
46+
width='40', default=True, )
47+
48+
# --- gui2py designer generated code ends ---
49+
50+
mywin = gui.get("mywin")
51+
ctrl_input = mywin["input"]
52+
ctrl_output = mywin["output"]
53+
54+
# assign your event handlers:
55+
56+
mywin['send'].onclick = send
57+
58+
if __name__ == "__main__":
59+
# example to call a GUI function (i.e. from other thread):
60+
gui.call_after(log, "Welcome!")
61+
# basic startup: show windows, activate control and start GUI
62+
mywin.show()
63+
ctrl_input.set_focus()
64+
gui.main_loop()
65+

0 commit comments

Comments
 (0)