[go: up one dir, main page]

Menu

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

Download this file

151 lines (125 with data), 4.7 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
#!/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 server
import time
gtk.gdk.threads_init()
#Set a few needed variables
version = 0.012
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):
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 :)
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)
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("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()
adressentry.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 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()