Added some more ggsvm_e functionality and also a chat client

This commit is contained in:
Jonatan Pålsson 2011-02-20 01:41:40 +01:00
parent 883cf9e9d7
commit 67567fe263
15 changed files with 1058 additions and 45 deletions

317
games/GGSCalc/calc.glade Normal file
View file

@ -0,0 +1,317 @@
<?xml version="1.0" encoding="UTF-8"?>
<glade-interface>
<!-- interface-requires gtk+ 2.16 -->
<!-- interface-naming-policy project-wide -->
<widget class="GtkWindow" id="window1">
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<widget class="GtkEntry" id="txtCalc">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">5</property>
<property name="n_columns">4</property>
<child>
<widget class="GtkButton" id="button1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="btnDiv">
<property name="label" translatable="yes">/</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btnDiv_clicked"/>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btnMul">
<property name="label" translatable="yes">*</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btnMul_clicked"/>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btnMin">
<property name="label" translatable="yes">-</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btnMin_clicked"/>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn7">
<property name="label" translatable="yes">7</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn7_clicked"/>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn8">
<property name="label" translatable="yes">8</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn8_clicked"/>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn9">
<property name="label" translatable="yes">9</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn9_clicked"/>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btnPlus">
<property name="label" translatable="yes">+</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btnPlus_clicked"/>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn4">
<property name="label" translatable="yes">4</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn4_clicked"/>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn5">
<property name="label" translatable="yes">5</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn5_clicked"/>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn6">
<property name="label" translatable="yes">6</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn6_clicked"/>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btnDel">
<property name="label" translatable="yes">←</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btnDel_clicked"/>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn1">
<property name="label" translatable="yes">1</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn1_clicked"/>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn2">
<property name="label" translatable="yes">2</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn2_clicked"/>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn3">
<property name="label" translatable="yes">3</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn3_clicked"/>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btnEq">
<property name="label" translatable="yes">=</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btnEq_clicked"/>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btn0">
<property name="label" translatable="yes">0</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btn0_clicked"/>
</widget>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button18">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button19">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="btnConnect">
<property name="label" translatable="yes">☎</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btnConnect_clicked"/>
</widget>
<packing>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkStatusbar" id="statusbar">
<property name="visible">True</property>
<property name="spacing">2</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

101
games/GGSCalc/calc.py Normal file
View file

@ -0,0 +1,101 @@
#!/usr/bin/env python
import sys, socket
try:
import pygtk
pygtk.require("2.16")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
class GGSCalc:
def __init__(self):
#Set the Glade file
self.gladefile = "calc.glade"
self.wTree = gtk.glade.XML(self.gladefile, "window1")
#Create our dictionay and connect it
dic = {"on_mainWindow_destroy" : gtk.main_quit
, "on_btn0_clicked" : lambda x: self.OnBtnClick(0)
, "on_btn1_clicked" : lambda x: self.OnBtnClick(1)
, "on_btn2_clicked" : lambda x: self.OnBtnClick(2)
, "on_btn3_clicked" : lambda x: self.OnBtnClick(3)
, "on_btn4_clicked" : lambda x: self.OnBtnClick(4)
, "on_btn5_clicked" : lambda x: self.OnBtnClick(5)
, "on_btn6_clicked" : lambda x: self.OnBtnClick(6)
, "on_btn7_clicked" : lambda x: self.OnBtnClick(7)
, "on_btn8_clicked" : lambda x: self.OnBtnClick(8)
, "on_btn9_clicked" : lambda x: self.OnBtnClick(9)
, "on_btnDiv_clicked" : lambda x: self.OnBtnClick("/")
, "on_btnMul_clicked" : lambda x: self.OnBtnClick("*")
, "on_btnMin_clicked" : lambda x: self.OnBtnClick("-")
, "on_btnPlus_clicked" : lambda x: self.OnBtnClick("+")
, "on_btnEq_clicked" : lambda x: self.calc()
, "on_btnDel_clicked" : lambda x: self.OnBtnClick("Del")
, "on_btnConnect_clicked" : lambda x: self.connect()
}
for i in range(0,9):
dic
self.wTree.signal_autoconnect(dic)
self.wTree.get_widget("window1").show()
self.setStatus("Not connected")
def setStatus(self, msg):
self.wTree.get_widget("statusbar").push(0, msg)
def calc(self):
exp = self.wTree.get_widget("txtCalc").get_text()
self.s.send("Server-Command: call\n"+
"Token: %s\n" % self.token +
"Content-Type: text\n"+
"Content-Length: %s\n" % len(exp)+
"\n"+
exp)
fs = self.s.makefile()
self.wTree.get_widget("txtCalc").set_text(fs.readline().split(" ")[1])
def connect(self):
print "Connecting"
self.setStatus("Connecting")
HOST = 'localhost' # The remote host
PORT = 9000 # The same port as used by the server
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.connect((HOST, PORT))
self.s.send("Server-Command: hello\n"+
"Content-Type: text\n"+
"Content-Length: 0\n"+
"\n")
fs = self.s.makefile()
self.token = fs.readline().split(" ")[0]
self.setStatus("Connected!")
def OnBtnClick(self, btn):
calcTxt = self.wTree.get_widget("txtCalc")
t = calcTxt.get_text()
if btn == "+":
t += "+"
elif btn == "-":
t += "-"
elif btn == "/":
t += "/"
elif btn == "=":
t += "="
elif btn == "*":
t += "*"
elif btn == "Del":
t = t[:-1]
else:
t += str("\""+str(btn)+"\"")
calcTxt.set_text(t)
if __name__ == "__main__":
calc = GGSCalc()
gtk.main()