[go: up one dir, main page]

Menu

[r29]: / main / start.py  Maximize  Restore  History

Download this file

127 lines (105 with data), 3.8 kB

  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
#!/usr/bin/env python
# -*- coding: utf8 -*-
# (For umlaut support)
#Import stuff
import pygtk
pygtk.require('2.0')
import gtk
import function
import thread
import server
import time
#Set a few needed variables
version = 0.012
name = "CatchX" #Just if we have to change the name for somewhat reason
threads = [] #The threads
#The code
print "Starting " + name + " v" + str(version)
#Now we ask the user whether he wants to connect to an exisiting server or if he wants to create one
class catchx:
def __init__(self):
def start_server(widget, data=None):
print "button %s was pressed" % data
#thread.start_new_thread(server.open_server, (str(port),)) #The server runs in a new thread...
thread = server.gserver()
threads.append(thread)
thread.start()
thread.run()
#time.sleep(0) #Thanks Waldteufel :)
def connect_server(widget, data):
def changebuttonstate(widget):
if adressentry.get_text() <> "" and passentry.get_text() <> "" and nameentry.get_text() <> "":
connectbutton.set_sensitive(True)
else:
connectbutton.set_sensitive(False)
def sendinit(widget):
server = adressentry.get_text()
password = passentry.get_text()
nickname = nameentry.get_text()
s = function.init_connection(server)
cliwindow.remove(loginbox)
infobox = gtk.VBox(False, 0)
cliwindow.add(infobox)
label = gtk.Label(str)
#if s == False:
# label.set_text("Couldn't establish a connection to the server.")
#else:
label.set_text("Loading game data...")
infobox.add(label)
cliwindow.show_all()
gdata = function.get_gamedata(s, password, nickname)
if gdata == "err_running":
label.set_text("Game is already running")
elif gdata == "err_login":
label.set_text("Wrong password")
else:
cliwindow.remove(infobox)
function.load_maingui(cliwindow, gdata[0], gdata[1])
print "button %s was pressed" % data
cliwindow.remove(hbox)
loginbox = gtk.VBox(False, 0)
cliwindow.add(loginbox)
label = gtk.Label(str)
label.set_text("Please enter the address and the password of the server you want to connect to.\nYou should also choose a name that will be seen by the other players.")
loginbox.add(label)
adressframe = gtk.Frame("Address")
passframe = gtk.Frame("Password")
nameframe = gtk.Frame("Name")
adressentry = gtk.Entry()
passentry = gtk.Entry()
nameentry = gtk.Entry()
adressframe.add(adressentry)
passframe.add(passentry)
nameframe.add(nameentry)
adressentry.connect("changed", changebuttonstate)
passentry.connect("changed", changebuttonstate)
nameentry.connect("changed", changebuttonstate)
loginbox.add(adressframe)
loginbox.add(passframe)
loginbox.add(nameframe)
connectbutton = gtk.Button("Connect")
connectbutton.set_sensitive(False)
connectbutton.connect("clicked", sendinit)
loginbox.add(connectbutton)
loginbox.show_all()
cliwindow = function.create_window(name)
hbox = gtk.VBox(False, 0)
cliwindow.add(hbox)
label = gtk.Label(str)
label.set_text("Please choose whether you want to participate in an existing game or if you want to create a new one.")
hbox.add(label)
connect_button = gtk.Button("Connect to existing game")
start_button = gtk.Button("Start new game")
connect_button.connect("clicked", connect_server, "cgame")
start_button.connect("clicked", start_server, "ngame")
start_button.set_sensitive(False) #Not implemented yet ;)
hbox.pack_start(connect_button, True, True, 0)
hbox.pack_start(start_button, True, True, 0)
cliwindow.show_all()
cliwindow.connect("destroy", lambda wid: gtk.main_quit())
def main():
gtk.main()
return 0
if __name__ == "__main__":
catchx()
main()