53 lines
1.0 KiB
Python
53 lines
1.0 KiB
Python
# Bryan Schumaker (11/13/2010)
|
|
|
|
import gtk
|
|
import socket
|
|
|
|
win = None
|
|
|
|
def send(text):
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
#s.connect( ("localhost", 4242) )
|
|
s.connect( ("192.168.1.100", 4242) )
|
|
total_sent = 0
|
|
length = len(text)
|
|
while total_sent < length:
|
|
sent = s.send(text[total_sent:])
|
|
if sent == 0:
|
|
print "Socket connection broken :("
|
|
return
|
|
total_sent += sent
|
|
|
|
def encode(func):
|
|
op, args = func.split('(', 1)
|
|
args = args[:len(args)-1]
|
|
args = args.split(',')
|
|
msg = "%s %s" % (len(op), op)
|
|
msg_args = ""
|
|
n_args = 0
|
|
for arg in args:
|
|
arg = arg.strip()
|
|
if len(arg) > 0:
|
|
msg_args += " %s %s" % (len(arg), arg)
|
|
n_args += 1
|
|
msg = msg.strip()
|
|
args = msg_args.strip()
|
|
msg = "%s %s %s" % (msg, n_args, args)
|
|
msg = msg.strip()
|
|
return "%s %s" % (len(msg), msg)
|
|
# msg_len op_len op n_args arg1_len arg1 arg2_len arg2
|
|
|
|
|
|
def start():
|
|
gtk.main()
|
|
|
|
def quit(*args):
|
|
gtk.main_quit()
|
|
|
|
def window():
|
|
global win
|
|
if win == None:
|
|
from gui import window
|
|
win = window.get_window()
|
|
return win
|