-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowManager.py
More file actions
233 lines (215 loc) · 7.68 KB
/
WindowManager.py
File metadata and controls
233 lines (215 loc) · 7.68 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
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
from PluginInterface import *
from Manialink import *
from WindowElements import *
"""
\file WindowManager.py
\brief Contains the WindowManager
"""
class WindowManager(PluginInterface):
"""
\brief WindowManager class to abstract the Manialink interface
"""
def __init__(self, pipes, args):
"""
\brief Construct the WindowManager
\param pipes The communication pipes to the PluginManager
\param args Additional startup arguments
"""
self.displays = {} #The display of each player
super(WindowManager, self).__init__(pipes)#initialize the PluginInterface
def initialize(self, args):
"""
\brief Initialize the WindowManager
\param args Should be empty
Nothing to do
"""
pass
def displayMl(self, *args):
"""
\brief Display a manialink via ManialinkManager
\param args the arguments that would be passed to the ManialinkManager
"""
self.callMethod(('ManialinkManager', 'displayManialinkToLogin'), *args)
def hideMl(self, *args):
"""
\brief Hide a manialink from the dipslay of a player
\param args The args to hide a special manialink from the player
"""
self.callMethod(('ManialinkManager', 'hideManialinkToLogin'), *args)
def windowFrame(self, width, height, posx, posy, posz = 0):
"""
\brief ???
"""
pass
def closeWindow(self, entries, login, name):
"""
\brief Callback for closing a window
\param entries The entries in the window's manialink
\param login The login of the player
\param name The name of the window to close
"""
try:
display = self.displays[login]
try:
del display[name]
self.hideMl(name, login)
except KeyError:
self.log('error: ' + str(login) + ' has no window named "' + str(name) + '" to close')
except KeyError:
self.log('error: login ' + str(login) + ' has no windows to be closed')
def __addWindow(self, login, name, window, useOldState = False):
"""
\brief Add a window to manage
\param login The player to display the window to
\param name The name of the window to display
\param window The window instance to display
\param useOldState Should the state of the replaced window be used
"""
if not (login in self.displays):
self.displays[login] = {}
if useOldState:
try:
oldWindow = self.displays[login][name]
window.setState(oldWindow.getState())
except KeyError:
pass
self.displays[login][name] = window
def displayWindow(self, login, name, window, useOldState = False):
"""
\brief Display the given window
\param login The player to display the window to
\param name The name of the window to display
\param window The window instance to display
\param useOldState Should be tried to use the state of the old window if there is one?
"""
window.setName(name)
window.setUser(login)
window.setWindowManager(self)
self.__addWindow(login, name, window, useOldState)
ml = window.getManialink()
self.displayMl(ml, name, login)
def displayPagedWindow(self, login, name, title, size, pos, pages, useOldState = False):
"""
\brief Display a paged window
\param login The player to display tdhe window to
\param name The name of the window
\param title The title of the window
\param size The size of the window
\param pos The upper left corner of the window
\param pages A list of pages (manialinks)
\param useOldState Should be tried to use the state of the old window if there is one?
"""
window = PagedWindow(title, pages)
window.setName(name)
window.setSize(size)
window.setPos(pos)
self.displayWindow(login, name, window, useOldState)
def displayLinesWindow(self, login, name, title, size, pos, rows, rowsPerPage, useOldState = False):
"""
\brief Display lines in a window
\param login The login of the player to display to
\param name The name of the window
\param size The size of the window
\param pos The upper left corner of the window
\param rows The rows to display
\param rowsPerPage The number of rows to display per page
\param useOldState Should be tried to use the state of the old window if there is one?
"""
window = LinesWindow(title)
window.setName(name)
window.setSize(size)
window.setPos(pos)
window.setLines(rows, rowsPerPage)
self.displayWindow(login, name, window, useOldState)
def displayTableWindow(self, login, name, title, size, pos, rows, rowsPerPage,
columnWidths, headLine = None, useOldState = False):
"""
\brief Display manialink elements in a table
\param login The player to display to
\param name The windows name
\param title The title of the window
\param size The size of the window
\param pos The upper left corner of the window
\param rows The rows to display (each is an iterable of columns)
\param rowsPerPage The number of rows to display per page
\param columntWidths The widths of each column
\param headLine The headlines of each column
\param useOldState Should be tried to use the state of the old window if there is one?
"""
window = TableWindow(title)
window.setName(name)
window.setSize(size)
window.setPos(pos)
window.setTable(rows, rowsPerPage, columnWidths, headLine)
self.displayWindow(login, name, window, useOldState)
def displayTableStringsWindow(self, login, name, title, size, pos, rows,
rowsPerPage, columnWidths, headLine = None, useOldState = False):
"""
\brief Display strings in a table
\param login The player to display to
\param name The windows name
\param title The title of the window
\param size The size of the window
\param pos The upper left corner of the window
\param rows The rows to display (each is an iterable of columns)
\param rowsPerPage The number of rows to display per page
\param columntWidths The widths of each column
\param headLine The headlines of each column
\param useOldState Should be tried to use the state of the old window if there is one?
"""
window = TableStringsWindow(title)
window.setName(name)
window.setSize(size)
window.setPos(pos)
window.setTableStrings(rows, rowsPerPage, columnWidths, headLine)
self.displayWindow(login, name, window, useOldState)
#args = (windowName, pageNumber)
def changePage(self, entries, login, name, pageNumber):
"""
\brief Change the page of a multiPage window
\param entries The entries of the manialink
\param login The login of the calling player
\param name The name of the window
\param pageNumber The number of the page to change to
"""
try:
display = self.displays[login]
try:
window = display[name]
try:
window.setCurrentPage(pageNumber)
self.displayMl(window.getManialink(), name, login)
except AttributeError:
self.log('error: ' + str(name) + ' does not seem to be a paged window')
except KeyError:
self.log('error: ' + str(login) + ' has no window "' + str(name) + '" to change page on')
except KeyError:
self.log('error: ' + str(login) + ' has no windows to change page')
def getCallbackAddress(self, login, windowName, functionName):
"""
\brief A method that will
\param login The login of the player that will see the window
\param windowName The name of the window
\param functionName The function of the window to call
"""
return ('WindowManager', (login, windowName, functionName))
def _getTarget(self, name):
"""
\brief Get the target of the calls from other plugins
\param name The name of the target
"""
if isinstance(name, str):
return super(WindowManager, self)._getTarget(name)
else:
try:
#get the display
display = self.displays[name[0]]
try:
#get the window on the display
window = display[name[1]]
#return the function
return getattr(window, name[2])
except KeyError:
self.log('Unknown window ' + name[0] + ' for user ' + name[1])
except KeyError:
self.log('Unknown user ' + name[0])