1
# -*- coding: utf-8 -*-
5
__author__ = 'Robert Ancell <bob27@users.sourceforge.net>'
6
__license__ = 'GNU General Public License Version 2'
7
__copyright__ = 'Copyright 2005-2006 Robert Ancell'
13
# The AI type or '' for human
16
# The AI difficulty level
26
allowSpectators = False
33
class NetworkFeedback:
34
"""Template class for feedback from a network game selector"""
36
def addProfile(self, profile):
39
def setProfile(self, profile):
42
def joinRoom(self, room):
45
def joinTable(self, table):
48
class NetworkController:
51
def setVisible(self, isVisible):
54
def addProfile(self, profile, name):
57
def setBusy(self, isBusy):
60
def addChat(self, user, channel, text):
65
def addRoom(self, index, name, description, room, protocol):
69
'name' is the name of the room (string).
70
'description' is a description of the room (string).
71
'room' is the room to add (user-defined)
76
def removeRoom(self, room):
82
def addTable(self, name, table):
85
def removeTable(self, table):
88
def clearTables(self):
91
def addPlayer(self, player, name, icon):
94
def removePlayer(self, player):
97
def clearPlayers(self):
100
def addAdvert(self, title, rating, advert):
101
"""Add a game advert.
103
'title' is the title of the advert (string).
104
'rating' is the rating for this game (string).
105
'advert' is an object to key this advert with (user-defined).
109
def removeAdvert(self, advert):
110
"""Remove a game advert.
112
'advert' is an object that was passed into addAdvert().
116
def requestGame(self, gameName):
117
"""Request this player joins a game.
119
'gameName' is the name of the game this player requested to join (string).
124
"""Template class for feedback from a view object"""
126
def showMoveHints(self, showHints):
127
"""Configure move hinting.
129
'showHints' sets if move hints should be shown (boolean).
133
def showSmooth(self, doNumbering):
136
def saveGame(self, path):
137
"""Called when the user requests the game in this view to be saved.
139
'path' is the path to the file to save to (string).
141
Returns the error that occurred (string) or None if successful.
145
def renderGL(self, background_color = (0, 0, 0)):
146
"""Render the scene using OpenGL"""
149
def renderCairoStatic(self, context, background_color = (0, 0, 0)):
150
"""Render the static elements of the scene.
152
'context' is the cairo context to modify.
154
Return False if the static elements have not changed otherwise True.
158
def renderCairoDynamic(self, context):
159
"""Render the dynamic elements of the scene.
161
'context' is the cairo context to modify.
165
def reshape(self, width, height):
166
"""This method is called when the UI resizes the scene.
168
'width' is the new width of the scene in pixels (integer).
169
'height' is the new height of the scene in pixels (integer).
173
def select(self, x, y):
174
"""This method is called when the UI selects a position on the scene.
176
'x' is the horizontal pixel location when the user has selected (integer, 0 = left pixel).
177
'y' is the vertical pixel location when the user has selected (integer, 0 = top pixel).
181
def deselect(self, x, y):
182
"""This method is called when the UI deselects a position on the scene.
184
'x' is the horizontal pixel location when the user has selected (integer, 0 = left pixel).
185
'y' is the vertical pixel location when the user has selected (integer, 0 = top pixel).
189
def setMoveNumber(self, moveNumber):
190
"""This method is called when the UI changes the move to render.
192
'moveNumber' is the moveNumber to watch (integer, negative numbers index from latest move).
196
def getFileName(self):
197
"""Get the file name to save to.
199
Returns the file name (string) or None if game is not saved.
203
def save(self, filename = None):
204
"""Save the game using this view.
206
'filename' is the file to save to (string or None to save to last filename).
211
"""Indicates the human player wants to undo their last move"""
215
"""Indicates the human player wants to resign"""
219
"""Indicates the human player wants to claim a draw"""
222
class ViewController:
223
"""Template class for methods to control a view"""
225
def setTitle(self, title):
226
"""Set the title for this view.
228
'title' is the title to use (string).
232
def setNeedsSaving(self, needsSaving):
233
"""Mark if this view needs saving.
235
'needsSaving' True if this view needs saving.
239
def addMove(self, move):
240
"""Register a move with this view.
242
'move' is the move made (string).
247
"""Remove the last move from this view"""
251
"""Request this view is redrawn"""
254
def setWhiteTimer(self, total, remaining):
255
"""Set the time remaining for the white player.
258
'remaining' FIXME TODO
262
def setBlackTimer(self, total, remaining):
263
"""Set the time remaining for the black player.
266
'remaining' FIXME TODO
270
def setAttention(self, requiresAttention):
271
"""Get the users attention for this view.
273
'requiresAttention' is a flag to show if this view requires attention.
278
"""Template class for feedback from a UI"""
280
def onAnimate(self, timeStep):
281
"""Called when an animation tick occurs.
283
'timeStep' is the time between the last call to this method in seconds (float).
285
Return True if animation should continue otherwise False
289
def onReadFileDescriptor(self, fd):
290
"""Called when a file descriptor is able to be read.
292
'fd' is the file descriptor with available data to read (integer).
294
Return False when finished otherwise True.
298
def onWriteFileDescriptor(self, fd):
299
"""Called when a file descriptor can be written to.
301
'fd' is the file descriptor that can be written to (integer).
303
Return False if writing is completed otherwise True
307
def onGameStart(self, game):
308
"""Called when a local game is started.
310
'game' is the game propertied (Game).
314
def loadGame(self, path):
315
"""Called when a game is loaded.
317
'path' is the path to the game to load (string).
319
Returns the error that occurred (string) or None if successful.
323
def onNewNetworkGame(self):
329
"""Called when the user quits the program"""
336
def onTick(self, time):
337
"""Called when the timer hits a one second boundary.
339
'time' is the boundary time in seconds.
344
"""Called when this timer expires"""
351
def getRemaining(self):
352
"""Get the amount of time remaining on this clock.
354
returns the amount of time in milliseconds (int)
359
"""Stop this timer from counting down"""
363
"""Continue counting down"""
367
"""Delete this timer"""
374
def addBinary(self, data, style = None):
379
def addText(self, text, style = None):
384
def addLine(self, text, style = None):
394
SAVE_YES = 'SAVE_YES'
396
SAVE_ABORT = 'SAVE_ABORT'
399
"""Template class for a glChess UI.
402
def __init__(self, feedback):
405
'feedback' is the feedback object for this UI to report with (extends UIFeedback).
409
def addLogWindow(self, title, executable, description):
412
def startAnimation(self):
413
"""Start the animation callback"""
416
def watchFileDescriptor(self, fd):
417
"""Notify when a file descriptor is able to be read.
419
'fd' is the file descriptor to watch (integer).
421
When data is available onReadFileDescriptor() is called.
425
def unwatchFileDescriptor(self, fd):
428
def writeFileDescriptor(self, fd):
429
"""Notify when a file descriptor can be written to.
431
'fd' is the file descriptor to write (integer).
433
When data can be written onWriteFileDescriptor is called.
437
def addTimer(self, feedback, duration):
440
'feedback' is an object containing methods to call for feedback (extends TimerFeedback).
441
'duration' is the period to call this method at in seconds (integer).
443
returns a timer object to control this timer (extends Timer).
447
def setView(self, title, feedback, isPlayable = True):
448
"""Set the view to display.
450
'title' is the title for the view (string).
451
'feedback' is a object to report view events with (extends ViewFeedback).
452
'isPlayable' is True if this view can be played.
454
Returns a view controller object (extends ViewController).
458
def addNetworkDialog(self, feedback):
460
'feedback' is a object to report view events with (extends NetworkFeedback).
462
Returns a network controller object (excends NetworkController).
466
def reportGameLoaded(self, game):
467
"""Report a loaded game as required by onGameLoad().
469
'game' is the game properties (Game).
473
def addNetworkGame(self, name, game):
474
"""Report a detected network game.
476
'name' is the name of the network game (string).
477
'game' is the game detected (user-defined).
481
def removeNetworkGame(self, game):
482
"""Report a network game as terminated.
484
'game' is the game that has removed (as registered with addNetworkGame()).
488
def requestSave(self, title):
489
"""Request a game is saved.
491
'title' is the request to make to the user.
493
Returns SAVE_YES, SAVE_NO or SAVE_ABORT.
498
"""Report the application has ended"""