[go: up one dir, main page]

Menu

[r39]: / main / function.py  Maximize  Restore  History

Download this file

156 lines (126 with data), 4.0 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
import pygtk
import gtk
import os
import xmlrpclib
import time
punkte = {411 : 392, 641 : 553, 943 : 537, 853 : 655, 664 : 796, 638 : 795}
def create_window(window_name):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title(window_name)
window.set_border_width(5)
return window
def init_connection(server):
print("Trying to connect to " + server)
s = xmlrpclib.ServerProxy('http://' + server + ':20211')
ping = s.ping()
if ping != "pong":
print("Error - Couldn't establish a connecting to the server.")
return False
else:
print("Connected to " + server + ':20211')
return s
def get_gamedata(s, password, name):
runs = s.running()
if runs == True:
print "Game is already running"
return "err_running"
playerid = s.connect()
print("Got assigned playerid #" + str(playerid))
auth = s.auth(playerid, password, name)
if auth == False:
print "Wrong password"
return "err_login"
players = s.get_players(playerid)
#print "Players on the server: " + str(players)
return (playerid,players)
def load_maingui(cliwindow, players, playerid): #This is the most complex GUI, the maingui...
cliwindow.maximize() #We need the complete space
size = cliwindow.get_size() #Now get the size of the maximized window
print "WSize = " + str(size)
uppersize = int(((size[0] / 95) *100) + 100)
print uppersize
clibox = gtk.VBox(False, 0)
cliwindow.add(clibox)
mapbox = gtk.VBox(False, 0)
#clibox.add(mapbox)
toolbox = gtk.HBox(False, 0)
#clibox.add(toolbox)
leftdnbox = gtk.VBox(False, 0)
#toolbox.add(leftdnbox)
rightdnbox = gtk.VBox(False, 0)
#toolbox.add(rightdnbox)
image = gtk.Image()
image.set_from_file("map.png")
pixelsize = image.get_pixbuf() # get the size of the picture to adjust the Layout size
pixelwidth = pixelsize.get_width()
pixelheight = pixelsize.get_height()
#Layout and Scrollbar settings
layout = gtk.Layout()
vadjust = layout.get_vadjustment()
hadjust = layout.get_hadjustment()
vadjust.step_increment = 10
hadjust.step_increment = 10
layout.set_size(pixelwidth, pixelheight)
vscrollbar = gtk.VScrollbar(vadjust)
hscrollbar = gtk.HScrollbar(hadjust)
vscrollbar.show()
hscrollbar.show()
layout.set_events(gtk.gdk.BUTTON_PRESS_MASK)
layout.connect("button_press_event", button_press)
layout.put(image, 0, 0)
#packing the layout and the scrollbars in the Table
table = gtk.Table(2, 2, 0)
table.attach(layout, 0, 1, 0, 1, gtk.EXPAND|gtk.FILL, gtk.EXPAND|gtk.FILL, 0, 0)
table.attach(vscrollbar, 1, 2, 0, 1, 0, gtk.EXPAND|gtk.FILL, 0, 0)
table.attach(hscrollbar, 0, 1, 1, 2, gtk.EXPAND|gtk.FILL, 0, 0, 0)
mapbox.add(table)
label3 = gtk.Label(str)
label3.set_text("Right Toolbox")
rightdnbox.add(label3)
#The user-list
liststore = gtk.ListStore(str, str)
treeview = gtk.TreeView(liststore)
tvcolumn = gtk.TreeViewColumn('Id')
tvcolumn1 = gtk.TreeViewColumn('Name')
treeview.append_column(tvcolumn)
treeview.append_column(tvcolumn1)
#print players
for name in players:
liststore.append([name[1], name[0]])
cell = gtk.CellRendererText()
cell1 = gtk.CellRendererText()
#tvcolumn.pack_start(cellpb, False)
tvcolumn.pack_start(cell, True)
tvcolumn1.pack_start(cell1, True)
tvcolumn.set_attributes(cell, text=0)
tvcolumn1.set_attributes(cell1, text=1)
treeview.set_search_column(0)
tvcolumn.set_sort_column_id(0)
leftdnbox.add(treeview)
#
vpan = gtk.VPaned()
vpan.add1(mapbox)
vpan.add2(toolbox)
clibox.add(vpan)
hpan = gtk.HPaned()
hpan.add1(leftdnbox)
hpan.add2(rightdnbox)
toolbox.add(hpan)
vpan.set_position(uppersize)
hpan.set_position(150)
cliwindow.show_all()
def button_press(widget, event):
correct = 0
print event.x, event.y
for xwert, ywert in punkte.items():
if (-10 < (event.x - xwert) < 10) and (-10 < (event.y - ywert)):
correct = 1
if correct == 1:
print "True"
else:
print "False"
return True
def keepalive(s,pid): # To be improved :D
s.keepalive(pid)
time.sleep(1)
self.keepalive(s, pid)