-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrigdj_util.py
More file actions
87 lines (77 loc) · 2.57 KB
/
rigdj_util.py
File metadata and controls
87 lines (77 loc) · 2.57 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
from tkinter import *
import tkinter.font
# thanks to https://stackoverflow.com/a/21831742 for this method
def setMaxWidth(stringList, element):
"""
Sets a tkinter element to have width matching the largest string in stringlist.
"""
f = tkinter.font.nametofont(element.cget("font"))
zerowidth=f.measure("0")
w=int(max([f.measure(i) for i in stringList])/zerowidth)+1
element.config(width=w)
def uiName (player):
uiNames = {
"anthem" : "Anthem",
"goal" : "Goalhorn",
"victory" : "Victory Anthem",
}
if player in uiNames:
return uiNames[player]
else:
return player
def outName (player):
outNames = {
"Anthem" : "anthem",
"Goalhorn" : "goal",
"Victory Anthem" : "victory",
}
if player in outNames:
return outNames[player]
else:
return player
def uiConvert (players):
"""
Converts a players dictionary read from a 4ccm file from keyword names to human-readable names.
Note that this does NOT change the pname values inside the condition lists themselves.
"""
for key in players.keys():
temp = uiName(key)
if temp != key:
players[temp] = players[key]
players.pop(key)
def outConvert (players):
"""
Converts a players dictionary created in rigDJ from human-readable names to keyword names.
"""
uiNames = {
"Anthem" : "anthem",
"Goalhorn" : "goal",
"Victory Anthem" : "victory",
}
for key in players.keys():
if key in uiNames:
players[uiNames[key]] = players[key]
players.pop(key)
class ScrollingListbox (Listbox):
"""
Simple class that combines a Listbox and Scrollbar.
"""
def __init__ (self, master, *args, bd=2, **kwargs):
# we need yscrollcommand to sync to the scroll bar
if "yscrollcommand" in kwargs:
raise ValueError("Cannot create ScrollingListbox with yscrollcommand or bd set.")
# create a frame
self.frame = Frame(master, bd=bd, relief=SUNKEN)
self.scrollbar = Scrollbar(self.frame)
self.scrollbar.pack(side=RIGHT, fill=Y)
# initialise self inside own frame, and set yscrollcommand
super().__init__(self.frame, *args, bd=0, yscrollcommand=self.scrollbar.set, **kwargs)
super().pack(fill=BOTH, expand=1)
# tell scrollbar to control yview
self.scrollbar.config(command=self.yview)
def pack (self, *args, **kwargs):
# let the frame handle all the actual geometry
self.frame.pack(*args, **kwargs)
def grid (self, *args, **kwargs):
# as above
self.frame.grid(*args, **kwargs)