/usr/share/games/tpclient-pywx/windows/winServerBrowser.py is in tpclient-pywx 0.3.1.1-3.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | # Python imports
import string
import os, os.path
import time
# wxPython Imports
import wx
# Local Imports
from winBase import winBaseXRC
from xrc.winServerBrowser import winServerBrowserBase
from requirements import graphicsdir
throbber = os.path.join(graphicsdir, "downloading.gif")
okay = os.path.join(graphicsdir, "finished.gif")
notokay = os.path.join(graphicsdir, "waiting.gif")
class winServerBrowser(winServerBrowserBase, winBaseXRC):
title = _("Updating")
ServersColumns = [_("Name"), _("Playing"), _("Server"), _("P"), _("C"), _("O"), _("Other")]
ServersColumns_Sizes = [
wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, 100,
wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE,
-1]
LocationsColumns = [_("Type"), _("DNS"), _("IP"), _("Port")]
LocationsColumns_Sizes = [
wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE, wx.LIST_AUTOSIZE]
def __init__(self, application):
winServerBrowserBase.__init__(self, None)
winBaseXRC.__init__(self, application)
self.Servers.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnServerSelect)
self.Locations.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnLocationSelect)
self.LocationsBox.Bind(wx.EVT_LEFT_DOWN, self.OnToggleLocation)
self.LocationsPanel.Bind(wx.EVT_LEFT_DOWN, self.OnToggleLocation)
self.OnToggleLocation(False)
self.application.gui.Binder(self.application.FinderClass.FoundLocalGameEvent, self.OnFoundLocalGame, self.IsShown)
self.application.gui.Binder(self.application.FinderClass.FoundRemoteGameEvent, self.OnFoundRemoteGame, self.IsShown)
# self.application.gui.Binder(self.application.FinderClass.LostLocalGameEvent, self.OnCacheUpdate)
# self.application.gui.Binder(self.application.FinderClass.LostRemoteGameEvent, self.OnCacheUpdate)
def AddGame(self, game=None, resize=True):
ctrl = self.Servers
Columns, Columns_Sizes = self.ServersColumns, self.ServersColumns_Sizes
if not game is None:
i = ctrl.GetItemCount()
ctrl.InsertStringItem(i, "")
ctrl.SetItemPyData(i, game)
ctrl.SetStringItem(i, Columns.index(_("Name")), game.name)
if game.where == "local":
ctrl.SetItemTextColour(i, wx.Color(0,0,255))
try:
ctrl.SetStringItem(i, Columns.index(_("Playing")), "%s (%s)" % (game.rule, game.rulever))
except AttributeError: pass
try:
ctrl.SetStringItem(i, Columns.index(_("Server")), "%s (%s)" % (game.sertype, game.server))
except AttributeError: pass
# try:
# ctrl.SetToolTipItem(i, game.cmt)
# except AttributeError: pass
try:
ctrl.SetStringItem(i, Columns.index(_("C")), unicode(game.cons))
except AttributeError: pass
try:
ctrl.SetStringItem(i, Columns.index(_("O")), unicode(game.objs))
except AttributeError: pass
try:
ctrl.SetStringItem(i, Columns.index(_("P")), unicode(game.plys))
except AttributeError: pass
try:
ctrl.SetStringItem(i, Columns.index(_("Other")), game.cmt)
except AttributeError: pass
if resize:
for i, name in enumerate(Columns):
ctrl.SetColumnWidth(i, Columns_Sizes[i])
def Setup(self):
ctrl = self.Servers
Columns, Columns_Sizes = self.ServersColumns, self.ServersColumns_Sizes
ctrl.ClearAll()
for i, name in enumerate(Columns):
ctrl.InsertColumn(i, name)
local, remote = self.application.finder.Games()
for games in (local, remote):
for game in games.values():
if game.name in local:
game.where = "local"
else:
game.where = "remote"
self.AddGame(game, False)
self.AddGame(None, True)
def OnFoundLocalGame(self, evt):
game = evt.game
game.where = "local"
self.AddGame(game)
def OnFoundRemoteGame(self, evt):
game = evt.game
game.where = "remote"
self.AddGame(game)
def OnServerSelect(self, evt):
ctrl = self.Locations
shown = ctrl.IsShown()
Columns, Columns_Sizes = self.LocationsColumns, self.LocationsColumns_Sizes
game = self.Servers.GetItemPyData(evt.GetIndex())
ctrl.ClearAll()
# Add the columns
for i, name in enumerate(Columns):
ctrl.InsertColumn(i, name)
# Populate the columns with data
for type, addrs in game.locations.items():
for dns, ip, port in addrs:
i = ctrl.GetItemCount()
ctrl.InsertStringItem(i, "")
ctrl.SetStringItem(i, Columns.index(_("Type")), type)
ctrl.SetStringItem(i, Columns.index(_("DNS")), dns)
ctrl.SetStringItem(i, Columns.index(_("IP")), ip)
ctrl.SetStringItem(i, Columns.index(_("Port")), unicode(port))
ctrl.SetItemPyData(i, (game, (type, dns, ip, port)))
# Set the column widths
for i, name in enumerate(Columns):
ctrl.SetColumnWidth(i, Columns_Sizes[i])
ctrl.Show()
# Set best location item selected and focused
type, addr = game.bestLocation()
slot = ctrl.FindItemByPyData((game, (type, addr[0], addr[1], addr[2])))
t = wx.LIST_STATE_FOCUSED|wx.LIST_STATE_SELECTED
ctrl.SetItemState(slot, t, t)
self.OnLocationSelect(slot)
self.OnToggleLocation(shown)
def OnToggleLocation(self, evt):
if not isinstance(evt, bool):
toggle = not self.Locations.IsShown()
else:
toggle = evt
if toggle:
self.Locations.Show()
self.LocationsBox.SetClientSize(self.Locations.GetBestSize())
else:
self.Locations.Hide()
self.LocationsBox.SetSize((-1, 1))
self.LocationsBox.Layout()
self.LocationsPanel.Layout()
if wx.Platform == "__WXMAC__":
self.Servers.SetSize((-1, 10))
self.Panel.Layout()
def OnLocationSelect(self, evt):
if isinstance(evt, int):
slot = evt
else:
slot = evt.GetIndex()
game, (type, dns, ip, port) = self.Locations.GetItemPyData(slot)
# We use the IP address for local games as mDNS's might not be resolvable to everyone
if game.where == "local":
dns = ip
# Set the copy box to the URL
self.URL.SetValue("%s://%s:%s/%s" % (type, dns, port, game.name))
def OnNewAccount(self, evt):
self.application.gui.Show(self.application.gui.account)
def OnConnectTo(self, evt):
pass
def Show(self, show=True):
if not show:
return self.Hide()
# Setup the ListCtrl
try:
self.Setup()
except Exception, e:
import traceback
traceback.print_exc()
print e
# Hide the Location Control
self.OnToggleLocation(False)
self.CenterOnScreen(wx.BOTH)
return winBaseXRC.Show(self)
def OnCancel(self, evt):
self.application.gui.Show(self.application.gui.connectto)
def OnRefresh(self, evt=None):
self.Progress.LoadFile(throbber)
self.Progress.Play()
self.application.finder.Call(self.application.finder.refresh)
# Disable the refresh button until the finder is done...
self.Refresh.Disable()
def OnRefreshFinished(self, worked, message=""):
# Renable the refresh button
self.Refresh.Enable()
if worked:
self.Progress.LoadFile(okay)
else:
self.Progress.LoadFile(notokay)
self.Progress.Play()
self.Progress.SetToolTip(message)
def OnFinderError(self, evt):
self.RefreshFinished(False, unicode(evt))
def OnFinderFinished(self, evt):
self.RefreshFinished(True)
# Config Functions -----------------------------------------------------------------------------
def ConfigDefault(self, config=None):
"""\
Fill out the config with defaults (if the options are not valid or nonexistant).
"""
return {}
def ConfigSave(self):
"""\
Returns the configuration of the Window (and it's children).
"""
return {}
def ConfigLoad(self, config={}):
"""\
Loads the configuration of the Window (and it's children).
"""
pass
def ConfigUpdate(self):
"""\
Updates the config details using external sources.
"""
pass
def ConfigDisplay(self, panel, sizer):
"""\
Display a config panel with all the config options.
"""
pass
def ConfigDisplayUpdate(self, evt):
"""\
Update the Display because it's changed externally.
"""
pass
|