Skip to content

Commit 690f65c

Browse files
committed
Nested all callbacks into 'cb' subfunctions so they're grouped. If only they could go UNDER their addCallback calls so the code was in a line...
1 parent 72e1fe6 commit 690f65c

7 files changed

+208
-101
lines changed

pinggraph.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,20 @@ def __init__(self, dic, darea):
3232

3333
self.data = None
3434

35+
3536
def set_data(self, data):
3637
'''Set or switch the source of the data (owned by each Gameserver)'''
3738
self.data = data
3839

40+
3941
def queue_draw(self):
4042
'''Called when the graph should be redrawn--sets it visible and tells Gtk
4143
to fire on_draw'''
4244
rect = self.darea.get_allocation()
4345
self.darea.queue_draw_area(0, 0, rect.width, rect.height)
4446
self.darea.set_visible(True)
4547

48+
4649
def on_ping_graph_draw(self, ping_graph, cx):
4750
'''Actually draw the graph with Cairo'''
4851
ping_graph.set_visible(self.data != None)
@@ -61,7 +64,6 @@ def on_ping_graph_draw(self, ping_graph, cx):
6164
g.add_color_stop_rgb(1.0, 0.2, 1.0, 0.2)
6265
cx.set_source(g)
6366

64-
6567
x = 0
6668
for i in range(len(self.data)):
6769
x = i * rect.width / (PING_LIMIT - 1)

rcongui.py

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __init__(self):
5959

6060
self.win.show()
6161

62+
6263
def setup_toolbar(self):
6364
'''Manually create a toolbar since Glade doesn't properly support
6465
PRIMARY_TOOLBAR style'''
@@ -89,6 +90,7 @@ def setup_toolbar(self):
8990
slot.set_property("expand", False)
9091
slot.pack_start(toolbar, False, True, 0)
9192

93+
9294
def on_server_list_button_press_event(self, treeview, event):
9395
# If the user right clicks, show them a menu
9496
if event.button == 3:
@@ -111,27 +113,33 @@ def on_cancel_add_server_clicked(self, cancel_add_server):
111113
# get_window doesn't work here--next time it tries to show it fails. not sure why...
112114
self.servermanager.close_server_dialog(cancel_add_server.get_toplevel())
113115

116+
114117
def on_add_server_dialog_delete_event(self, add_server_dialog, event):
115118
self.servermanager.close_server_dialog(add_server_dialog)
116119
return True
117120

121+
118122
def on_about_dialog_delete_event(self, about_dialog, event):
119123
about_dialog.hide()
120124
return True
121125

126+
122127
def on_about_menuitem_activate(self, about_menuitem):
123128
self.bd.get_object("about_dialog").show()
124129

130+
125131
def on_about_dialog_response(self, about_dialog, response_id):
126132
about_dialog.hide()
127133

128134

129135
def on_main_window_destroy(self, main_window):
130136
self.quit()
131137

138+
132139
def on_act_quit_activate(self, act_quit):
133140
self.quit()
134141

142+
135143
def quit(self):
136144
self.servermanager.quit()
137145
print("stopping reactor")

rcontool.glade

+54-3
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ Uses SourceLib Python RCON library.</property>
955955
<child>
956956
<object class="GtkFrame" id="frame4">
957957
<property name="visible">True</property>
958+
<property name="sensitive">False</property>
958959
<property name="can_focus">False</property>
959960
<property name="border_width">5</property>
960961
<property name="label_xalign">0</property>
@@ -967,7 +968,6 @@ Uses SourceLib Python RCON library.</property>
967968
<property name="spacing">5</property>
968969
<child>
969970
<object class="GtkBox" id="box9">
970-
<property name="visible">True</property>
971971
<property name="can_focus">False</property>
972972
<property name="spacing">5</property>
973973
<child>
@@ -1010,23 +1010,74 @@ Uses SourceLib Python RCON library.</property>
10101010
<child>
10111011
<object class="GtkEntry" id="entry1">
10121012
<property name="visible">True</property>
1013+
<property name="sensitive">False</property>
10131014
<property name="can_focus">True</property>
1015+
<property name="tooltip_markup" translatable="yes">Pop up a notification when this word is said in chat.
1016+
Note:&lt;i&gt; Must be connected to server log&lt;/i&gt;</property>
10141017
<property name="invisible_char">•</property>
1015-
<property name="placeholder_text">Enter a notify command...</property>
1018+
<property name="placeholder_text">Enter a chat notification...</property>
10161019
</object>
10171020
<packing>
10181021
<property name="expand">False</property>
10191022
<property name="fill">True</property>
10201023
<property name="position">1</property>
10211024
</packing>
10221025
</child>
1026+
<child>
1027+
<object class="GtkBox" id="box1">
1028+
<property name="visible">True</property>
1029+
<property name="can_focus">False</property>
1030+
<property name="spacing">5</property>
1031+
<child>
1032+
<object class="GtkCheckButton" id="server_down_notify">
1033+
<property name="label" translatable="yes">Server down</property>
1034+
<property name="use_action_appearance">False</property>
1035+
<property name="visible">True</property>
1036+
<property name="can_focus">True</property>
1037+
<property name="receives_default">False</property>
1038+
<property name="tooltip_text" translatable="yes">Notify if server is down for more than 5 seconds</property>
1039+
<property name="use_action_appearance">False</property>
1040+
<property name="xalign">0</property>
1041+
<property name="draw_indicator">True</property>
1042+
</object>
1043+
<packing>
1044+
<property name="expand">True</property>
1045+
<property name="fill">True</property>
1046+
<property name="position">0</property>
1047+
</packing>
1048+
</child>
1049+
<child>
1050+
<object class="GtkCheckButton" id="map_change_notify">
1051+
<property name="label" translatable="yes">Map Change</property>
1052+
<property name="use_action_appearance">False</property>
1053+
<property name="visible">True</property>
1054+
<property name="can_focus">True</property>
1055+
<property name="receives_default">False</property>
1056+
<property name="tooltip_text" translatable="yes">Notify on map change</property>
1057+
<property name="use_action_appearance">False</property>
1058+
<property name="xalign">0</property>
1059+
<property name="draw_indicator">True</property>
1060+
</object>
1061+
<packing>
1062+
<property name="expand">True</property>
1063+
<property name="fill">True</property>
1064+
<property name="position">1</property>
1065+
</packing>
1066+
</child>
1067+
</object>
1068+
<packing>
1069+
<property name="expand">False</property>
1070+
<property name="fill">True</property>
1071+
<property name="position">2</property>
1072+
</packing>
1073+
</child>
10231074
</object>
10241075
</child>
10251076
<child type="label">
10261077
<object class="GtkLabel" id="label4">
10271078
<property name="visible">True</property>
10281079
<property name="can_focus">False</property>
1029-
<property name="label" translatable="yes">&lt;b&gt;Settings&lt;/b&gt;</property>
1080+
<property name="label" translatable="yes">&lt;b&gt;Notifications&lt;/b&gt;</property>
10301081
<property name="use_markup">True</property>
10311082
</object>
10321083
</child>

recentcommands.py

+3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ def __init__(self, store):
4040
except:
4141
pass
4242

43+
4344
def add_to_store(self, cmd):
4445
self.store.append([cmd])
4546

47+
4648
def addcmd(self, command):
4749
command = command.strip()
4850

@@ -52,6 +54,7 @@ def addcmd(self, command):
5254
else:
5355
self.commands[command] += 1
5456

57+
5558
def quit(self):
5659
fcmds = open("recentcommands.pkl", "w")
5760

server.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def get_default_info():
2929
return { 'ip' : '', 'port' : -1, 'hostname' : '???', 'numplayers' : 0, 'maxplayers' : 0, 'ping' : 1000, 'map' : 'Unknown', 'gamedesc' : 'Unknown'}
3030

3131
class Gameserver(object):
32+
'''Stores data about a server and handles rcon and querying'''
3233
def __init__(self, ip, port, rcon_visible=False, rcon_password=None, save_rcon=True):
3334
self.ip = ip
3435
self.port = port
@@ -48,25 +49,31 @@ def __init__(self, ip, port, rcon_visible=False, rcon_password=None, save_rcon=T
4849

4950
self.save_rcon = save_rcon
5051

52+
5153
def __reduce__(self):
5254
'''Magical pickle packer, creates a new "gameserver" instance with the following args'''
5355
return Gameserver, (self.ip,self.port,self.rcon_visible, self.rcon_password if self.save_rcon else None, self.save_rcon)
5456

57+
5558
def __key(self):
5659
return (self.ip, self.port)
5760

61+
5862
def __hash__(self):
5963
'''Servers should be unique by IP'''
6064
return self.__key().__hash__()
6165

66+
6267
def __cmp__(self, other):
6368
return self.__hash__() < other.__hash__()
6469

70+
6571
def add_ping_history(self):
6672
self.pings.append(self.info['ping'])
6773
if len(self.pings) > pinggraph.PING_LIMIT:
6874
self.pings.pop(0)
6975

76+
7077
def rcon_cmd(self, command):
7178
if not self.rcon_connected():
7279
return False, "Password not set, ignoring"
@@ -80,6 +87,7 @@ def rcon_cmd(self, command):
8087
self.rcon = None
8188
return False, str(e)
8289

90+
8391
def query(self):
8492
try:
8593
q = SourceLib.SourceQuery.SourceQuery(self.ip, self.port)
@@ -96,7 +104,7 @@ def query(self):
96104
if 'ping' in self.info:
97105
self.info['ping'] = int(self.info['ping'] * 1000)
98106
else:
99-
self.info['ping'] = 9001
107+
self.info['ping'] = 9001 # There's no way that can be right
100108

101109
return True, ""
102110
except (SourceLib.SourceQuery.SourceQueryError, socket.gaierror) as e:
@@ -109,6 +117,7 @@ def query(self):
109117
self.info['ping'] = 9001
110118
return False, error
111119

120+
112121
def cleanup(self):
113122
if self.rcon_connected():
114123
self.rcon.disconnect()
@@ -117,9 +126,11 @@ def cleanup(self):
117126
def set_rcon_visibility(self, enabled):
118127
self.rcon_visible = enabled
119128

129+
120130
def rcon_connected(self):
121131
return self.rcon != None
122132

133+
123134
def set_rcon(self, newpass):
124135
if not newpass:
125136
return

0 commit comments

Comments
 (0)