-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
rugby.py
executable file
·74 lines (63 loc) · 2.91 KB
/
rugby.py
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
#!/usr/bin/env python3
#
# This file is part of Mediary's Caspar Client.
# Copyright (C) 2018 Mediary Limited. All rights reserved.
#
import scorebug
import wx
import configurable
import lowerthird
import scoreextra
import timer
import lt_banner
ScoresByCode = {
# This table maps events to their scores. Occasionally the laws of rugby change, so this might have to be updated.
'Union': { 'try': 5, 'convertedtry': 7, 'penalty': 3, 'dropgoal': 3 },
'League': { 'try': 4, 'convertedtry': 6, 'penalty': 2, 'dropgoal': 1 },
}
RugbyCode = configurable.ListConfigItem('Code', 'Which rugby code\'s scoring rules', list(ScoresByCode.keys()))
class RugbyScoreBug(scorebug.ScoreBug):
config_section='rugby'
ui_label='Rugby score bug'
my_configurations=[scorebug.Template_bug, scorebug.Template_banner, configurable.Layer, RugbyCode]
my_default_config={'Bug Template': 'mediary/scorebug', 'Banner Template': 'mediary/score_lowerthird', 'Layer': 102, RugbyCode.label: 'Union'}
def createSecondLine(self,sizer):
'''
Our customised second line of the widget.
'''
line2 = wx.BoxSizer(wx.HORIZONTAL)
# Penalty and drop goal cannot be merged as league scores them differently...
# Conversion and penalty cannot be merged as union scores them differently...
self.addButton(line2, 'TRY', lambda e: self.score(1, 'try'), True)
line2.AddSpacer(10)
self.addButton(line2, 'TRY+CONV', lambda e: self.score(1, 'convertedtry'), True)
line2.AddSpacer(10)
self.addButton(line2, 'PEN', lambda e: self.score(1, 'penalty'), True)
line2.AddSpacer(10)
self.addButton(line2, 'DROP', lambda e: self.score(1, 'dropgoal'), True)
line2.AddStretchSpacer(1)
self.addButton(line2, 'TRY', lambda e: self.score(2, 'try'), True)
line2.AddSpacer(10)
self.addButton(line2, 'TRY+CONV', lambda e: self.score(2, 'convertedtry'), True)
line2.AddSpacer(10)
self.addButton(line2, 'PEN', lambda e: self.score(2, 'penalty'), True)
line2.AddSpacer(10)
self.addButton(line2, 'DROP', lambda e: self.score(2, 'dropgoal'), True)
sizer.AddStretchSpacer(1)
sizer.AddSpacer(10)
sizer.Add(line2, 0, wx.EXPAND)
def code(self):
'''
Looks up the rugby code (League or Union) selected in the config.
'''
return self.config.get(self.config_section, RugbyCode.label, RugbyScoreBug.my_default_config[RugbyCode.label])
def score(self,team,event):
'''
Looks up the score table to find out the score for the event,
then applies it to the correct team.
'''
delta = ScoresByCode[self.code()][event]
super(RugbyScoreBug, self).score(team, delta)
if __name__=='__main__':
import wxclient
wxclient.run_app([RugbyScoreBug, timer.Timer, scoreextra.ScoreExtra, lowerthird.LowerThird, lt_banner.LowerThirdBanner])