/usr/share/tpclient-pywx/windows/main/panelMessage.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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | """\
This module contains the message window, it displays all the ingame messages and
lets the player filter out unimportant messages.
Messages are displayed using basic HTML.
"""
# Python Imports
from sets import Set
# wxPython Imports
import wx
import wx.html
# Config information
from requirements import graphicsdir
# Local Imports
from windows.winBase import ShiftMixIn
# Protocol Imports
from tp.netlib import GenericRS
from windows.xrc.panelMessage import panelMessageBase
class panelMessage(panelMessageBase, ShiftMixIn):
title = _("Messages")
def __init__(self, application, parent):
panelMessageBase.__init__(self, parent)
ShiftMixIn.__init__(self)
self.application = application
self.Message.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkEvent)
# The current message slot
self.node = None
self.application.gui.Binder(self.application.CacheClass.CacheUpdateEvent, self.OnCacheUpdate)
def OnLinkEvent(self, evt):
link = evt.GetLinkInfo().GetHref()
from extra.Opener import open
open(link)
html_filtered = """\
<html>
<body>
<center>
<table cols=1 width="100%%" background="%GRAPHICS/graphics/filtered.png">
<tr>
<td><b>Subject:</b> %(subject)s</td>
</tr>
<tr>
<td>%(body)s</td>
</tr>
</table>
</center>
</body>
</html>""".replace("%GRAPHICS", graphicsdir)
html_message = """\
<html>
<body>
<center>
<table cols=1 width="100%%">
<tr>
<td><b>Subject:</b> %(subject)s</td>
</tr>
<tr>
<td>%(body)s</td>
</tr>
</table>
</center>
</body>
</html>""".replace("%GRAPHICS", graphicsdir)
html_nomessage = """\
<html>
<body>
<center>
<table cols=1 width="100%">
<tr>
<td><b>Subject:</b> You are unloved!
</tr>
<tr>
<td>
You have received no messages this turn!<br><br>
Actually if you didn't receive any messages it most probably
means that your client couldn't load the results from the server.
Try reload/restart the client.
</td>
</tr>
</table>
</center>
</body>
</html>"""
html_allfiltered = """\
<html>
<body>
<center>
<table cols=1 width="100%" background="%GRAPHICS/graphics/filtered.png">
<tr>
<td><b>Subject:</b> All messages filtered
</tr>
<tr>
<td>All messages you have received this turn have been filtered.</td>
</tr>
</table>
</center>
</body>
</html>""".replace("%GRAPHICS", graphicsdir)
def GetPaneInfo(self):
info = wx.aui.AuiPaneInfo()
info.MinSize(self.GetBestSize())
info.Bottom()
info.Layer(1)
return info
def Show(self, show=True):
if show:
self.ShiftStart()
panelMessageBase.Show(self)
else:
self.Hide()
def Hide(self, hide=True):
if hide:
self.ShiftStop()
panelMessageBase.Hide(self)
else:
self.Show()
def OnShiftDown(self, evt):
self.ShowFL()
def OnShiftUp(self, evt):
self.ShowPN()
def ShowPN(self):
self.First.Hide()
self.Last.Hide()
self.Prev.Show()
self.Next.Show()
self.Layout()
def ShowFL(self):
self.Prev.Hide()
self.Next.Hide()
self.First.Show()
self.Last.Show()
self.Layout()
def OnCacheUpdate(self, evt=None):
"""\
Called when the cache is updated.
"""
# If it's a full cache update
if evt.what == None:
self.BoardSet(0)
return
# Only intrested in an order has been updated and we are currently looking at that
if evt.what != "messages" or evt.id != self.bid:
return
self.BoardSet(0, evt.node)
@property
def message(self):
"""\
Returns the currently displayed message.
"""
return self.node.CurrentOrder
@property
def messages(self):
"""\
Returns all the messages for the current board.
"""
if self.application.cache.messages.has_key(self.bid):
return self.application.cache.messages[self.bid]
else:
return []
def BoardSet(self, id, node=None):
"""\
Set the currently displayed board to id.
"""
self.bid = id
if not self.messages.first is None:
self.MessageSet(node=self.messages.first)
def MessageSet(self, direction=None, node=None):
"""\
Set the currently displayed message to the given node.
"""
# Are there any messages?
if len(self.messages) == 0:
message_subject = _("No messages")
message_counter = _("")
message_body = self.html_nomessage
message_filter = False
message_buttons = [False, False, False, False]
else:
if not direction is None:
if direction > 0 and not self.node.right is None:
self.node = self.node.right
elif direction < 0 and not self.node.left.left is None:
self.node = self.node.left
else:
raise SystemError("Need to give a direction or node")
elif not node is None:
assert node in self.messages
self.node = node
else:
raise SystemError("Need to give a direction or node")
message_subject = self.message.subject
message_body = self.html_message % self.message.__dict__
message_filter = False
message_buttons = [
not self.node.left.left is None,
GenericRS.Types["Object"] in self.message.references.types,
not self.node.right is None,
True
]
message_counter = _("%i of %i") % (self.messages.index(self.node)+1, len(self.messages))
self.Title.SetLabel(message_subject)
self.Counter.SetLabel(message_counter)
self.Message.SetPage(message_body)
self.Prev.Enable(message_buttons[0])
self.First.Enable(message_buttons[0])
self.Goto.Enable(message_buttons[1])
self.Last.Enable(message_buttons[2])
self.Next.Enable(message_buttons[2])
self.Delete.Enable(message_buttons[3])
def OnFirst(self, evt=None):
self.MessageSet(node=self.messages.first)
def OnNext(self, evt=None):
self.MessageSet(1)
def OnLast(self, evt=None):
self.MessageSet(node=self.messages.last)
def OnPrev(self, evt=None):
self.MessageSet(-1)
def OnDelete(self, evt=None):
# Tell everyone about the change
self.application.Post(self.application.cache.apply("messages", "remove", self.bid, self.node, None), source=self)
def OnGoto(self, slot):
# Select the object this message references
ids = []
for reference, id in self.message.references:
if reference == GenericRS.Types["Object"]:
try:
obj = self.application.cache.objects[id]
ids.append(id)
except KeyError:
pass
if len(ids) > 1:
menu = wx.Menu()
for id in ids:
try:
obj = self.application.cache.objects[id]
menu.Append(-1, "%s (%s)" % (obj.name, obj.id))
except KeyError:
pass
self.Bind(wx.EVT_MENU, self.MessageGotoMenu)
x, y = self.Goto.GetPosition()
self.PopupMenu(menu, (x,y+self.Goto.GetSize()[1]))
elif len(ids) == 1:
self.application.Post(self.application.gui.SelectObjectEvent(ids[0]), source=self)
def MessageGotoMenu(self, evt):
menu = evt.GetEventObject()
item = menu.FindItemById(evt.GetId())
id = int(item.GetLabel().split('(')[-1][:-1])
self.application.Post(self.application.gui.SelectObjectEvent(id), source=self)
def MessageNew(self, evt=None):
pass
def MessageFilter(self):
pass
|