[go: up one dir, main page]

Menu

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

Download this file

162 lines (132 with data), 5.1 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
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
161
#!/usr/bin/env python
# -*- coding: utf8 -*-
# This file is part of CatchX.
#
# CatchX is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CatchX is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CatchX. If not, see <http://www.gnu.org/licenses/>.
#Import stuff
import pygtk
pygtk.require('2.0')
import gtk
import function
import thread
import time
gtk.gdk.threads_init()
#Set a few needed variables
version = 0.15
name = "CatchX" #Just if we have to change the name for somewhat reason
threads = [] #The threads
port = 20211
#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): #DEPRECATED!
#print "button %s was pressed" % data
#thread.start_new_thread(server.server, (port,)) #The server runs in a new thread...
#thread = server.gserver()
#threads.append(thread)
#thread.start()
#thread.run()
#time.sleep(0) #Thanks Waldteufel :)
return True
def connect_server(widget, data):
def changebuttonstate(widget):
if adressentry.get_text() <> "" and passentry.get_text() <> "" and nameentry.get_text() <> "" and roomentry.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()
room = roomentry.get_text()
s = function.init_connection(server)
# if s == False:
# label.set_text("Couldn't connect to the server!")
## thread.start_new_thread(function.blink_window, (window,))
cliwindow.remove(loginbox)
infobox = gtk.VBox(False, 0)
cliwindow.add(infobox)
label = gtk.Label(str)
label.set_text("Loading game data...")
infobox.add(label)
cliwindow.show_all()
gdata = function.get_gamedata(s, password, nickname, room, cliwindow)
if gdata == "err_running":
label.set_text("Game is already running")
elif gdata == "err_login":
label.set_text("Wrong password or the room doesn't exist")
else:
cliwindow.remove(infobox)
kret = thread.start_new_thread(function.keepalive, (s,gdata[0]))
#kret = function.keepalive(s, gdata[0])
time.sleep(0)
#function.load_mappoints()
function.load_maingui(cliwindow, gdata[1], gdata[0], version, s)
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("Server")
roomframe = gtk.Frame("Room Name")
passframe = gtk.Frame("Password")
nameframe = gtk.Frame("Name")
adressentry = gtk.Entry()
roomentry = gtk.Entry()
passentry = gtk.Entry()
nameentry = gtk.Entry()
adressentry.set_text("cxmaster.netstyn.de")
#adressentry.set_sensitive(False)
adressframe.add(adressentry)
roomframe.add(roomentry)
passframe.add(passentry)
nameframe.add(nameentry)
adressentry.connect("changed", changebuttonstate)
roomentry.connect("changed", changebuttonstate)
passentry.connect("changed", changebuttonstate)
nameentry.connect("changed", changebuttonstate)
loginbox.add(adressframe)
loginbox.add(roomframe)
loginbox.add(passframe)
loginbox.add(nameframe)
connectbutton = gtk.Button("Connect")
connectbutton.set_sensitive(False)
connectbutton.connect("clicked", sendinit)
loginbox.add(connectbutton)
loginbox.show_all()
roomentry.grab_focus() #So you dont have to click first
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 room.")
hbox.add(label)
connect_button = gtk.Button("Join room")
start_button = gtk.Button("Open new Room")
connect_button.connect("clicked", connect_server, "cgame")
start_button.connect("clicked", start_server, "ngame")
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()