def start(self, dummyResults='DIREKT'): """start the animation, returning its deferred""" if not isAlive(self): return fail() assert self.state() != QAbstractAnimation.Running for animation in self.animations: graphicsObject = animation.targetObject() if not isAlive(animation) or not isAlive(graphicsObject): return fail() graphicsObject.setActiveAnimation(animation) self.addAnimation(animation) propName = animation.pName() animation.setStartValue(graphicsObject.getValue(propName)) if propName == 'rotation': # change direction if that makes the difference smaller endValue = animation.endValue() currValue = graphicsObject.rotation if endValue - currValue > 180: animation.setStartValue(currValue + 360) if currValue - endValue > 180: animation.setStartValue(currValue - 360) for animation in self.animations: animation.targetObject().setDrawingOrder() self.finished.connect(self.allFinished) scene = Internal.scene scene.focusRect.hide() QParallelAnimationGroup.start( self, QAbstractAnimation.DeleteWhenStopped) if self.debug: logDebug('%s started with speed %d (%s)' % ( self, Internal.Preferences.animationSpeed, ','.join('A%s' % id4(x) for x in self.animations))) return succeed(None).addErrback(logException)
def ident(self): """the identifier to be used in debug messages""" pGroup = self.group() if isAlive(self) else 'notAlive' if pGroup or not isAlive(self): return '%s/A%s' % (pGroup, id4(self)) else: return 'A%s-%s' % (id4(self), self.targetObject().name())
def __hideGame(self): """remove all visible traces of the current game""" field = Internal.field if isAlive(field): field.setWindowTitle('Kajongg') if field: field.discardBoard.hide() field.selectorBoard.tiles = [] field.selectorBoard.allSelectorTiles = [] if isAlive(field.centralScene): field.centralScene.removeTiles() field.clientDialog = None for player in self.players: if player.handBoard: player.clearHand() player.handBoard.hide() if self.wall: self.wall.hide() self.wall = None self.lastDiscard = None if field: field.actionAutoPlay.setChecked(False) field.startingGame = False field.game = None field.updateGUI()
def hasFocus(self, value): """sets focus on this board""" if isAlive(self): scene = self.scene() if isAlive(scene): if scene.focusBoard == self or value: if self.focusTile: assert self.focusTile.board == self, '%s not in self %s' % ( self.focusTile, self) if value: scene.focusBoard = self
def updateGUI(self): """update some actions, all auxiliary windows and the statusbar""" if not isAlive(self): return self.setCaption('') for action in [self.actionScoreGame, self.actionPlayGame]: action.setEnabled(not bool(self.scene)) self.actionAbortGame.setEnabled(bool(self.scene)) scene = self.scene if isAlive(scene): scene.updateSceneGUI()
def __init__(self): parent = Internal.mainWindow # default # if we are (maybe indirectly) called from a method belonging to a QWidget, take that as parent # this does probably not work for classmethod or staticmethod but it is # good enough right now for frametuple in inspect.getouterframes(inspect.currentframe())[1:]: if 'self' in frametuple[0].f_locals: obj = frametuple[0].f_locals['self'] if isinstance(obj, QWidget) and not isinstance( obj, QDialog) and isAlive(obj): parent = obj break if not isAlive(parent): parent = None KDialogIgnoringEscape.__init__(self, parent)
def __init__(self): parent = Internal.mainWindow # default # if we are (maybe indirectly) called from a method belonging to a QWidget, take that as parent # this does probably not work for classmethod or staticmethod but it is # good enough right now for frametuple in inspect.getouterframes(inspect.currentframe())[1:]: if 'self' in frametuple[0].f_locals: obj = frametuple[0].f_locals['self'] if isinstance(obj, QWidget) and not isinstance(obj, QDialog) and isAlive(obj): parent = obj break if not isAlive(parent): parent = None KDialogIgnoringEscape.__init__(self, parent) self.chosen = None
def updateSceneGUI(self): """update some actions, all auxiliary windows and the statusbar""" if not isAlive(self): return GameScene.updateSceneGUI(self) game = self.game mainWindow = self.mainWindow if not game: connections = list( x.connection for x in HumanClient.humanClients if x.connection) title = u', '.join(u'{name}/{url}'.format(name=x.username, url=x.url) for x in connections) if title: decorateWindow(mainWindow, title) else: decorateWindow(mainWindow, str(game.seed)) for action in [mainWindow.actionScoreGame, mainWindow.actionPlayGame]: action.setEnabled(not bool(game)) mainWindow.actionAbortGame.setEnabled(bool(game)) self.discardBoard.setVisible(bool(game)) mainWindow.actionAutoPlay.setEnabled(not self.startingGame) mainWindow.actionChat.setEnabled(bool(game) and bool(game.client) and bool(game.client.connection) and not game.client.connection.url.isLocalGame and not self.startingGame) # chatting on tables before game started works with chat button per # table mainWindow.actionChat.setChecked( mainWindow.actionChat.isEnabled( ) and bool( game.client.table.chatWindow))
def updateGUI(self): """update some actions, all auxiliary windows and the statusbar""" if not isAlive(self): return title = '' connections = list(x.connection for x in HumanClient.humanClients if x.connection) game = self.game if not game: title = ', '.join('{name}/{url}'.format(name=x.username, url=x.url) for x in connections) if title: self.setWindowTitle('%s - Kajongg' % title) for action in [self.actionScoreGame, self.actionPlayGame]: action.setEnabled(not bool(game)) self.actionAbortGame.setEnabled(bool(game)) self.actionAngle.setEnabled(bool(game) and self.showShadows) scoring = bool(game and game.isScoringGame()) self.selectorBoard.setVisible(scoring) self.selectorBoard.setEnabled(scoring) self.discardBoard.setVisible(bool(game) and not scoring) self.actionScoring.setEnabled(scoring and not game.finished()) self.actionAutoPlay.setEnabled(not self.startingGame and not scoring) self.actionChat.setEnabled( bool(game) and bool(game.client) and not game.client.hasLocalServer() and not self.startingGame) # chatting on tables before game started works with chat button per table self.actionChat.setChecked(self.actionChat.isEnabled() and bool(game.client.table.chatWindow)) if self.actionScoring.isChecked(): self.actionScoring.setChecked(scoring and not game.finished()) for view in [self.scoringDialog, self.explainView, self.scoreTable]: if view: view.refresh(game) self.__showBalance()
def updateGUI(self): """update some actions, all auxiliary windows and the statusbar""" if not isAlive(self): return title = '' connections = list(x.connection for x in HumanClient.humanClients if x.connection) game = self.game if not game: title = ', '.join('{name}/{url}'.format(name=x.username, url=x.url) for x in connections) if title: self.setWindowTitle('%s - Kajongg' % title) for action in [self.actionScoreGame, self.actionPlayGame]: action.setEnabled(not bool(game)) self.actionAbortGame.setEnabled(bool(game)) self.actionAngle.setEnabled(bool(game) and self.showShadows) scoring = bool(game and game.isScoringGame()) self.selectorBoard.setVisible(scoring) self.selectorBoard.setEnabled(scoring) self.discardBoard.setVisible(bool(game) and not scoring) self.actionScoring.setEnabled(scoring and not game.finished()) self.actionAutoPlay.setEnabled(not self.startingGame and not scoring) self.actionChat.setEnabled(bool(game) and bool(game.client) and not game.client.hasLocalServer() and not self.startingGame) # chatting on tables before game started works with chat button per table self.actionChat.setChecked(self.actionChat.isEnabled() and bool(game.client.table.chatWindow)) if self.actionScoring.isChecked(): self.actionScoring.setChecked(scoring and not game.finished()) for view in [self.scoringDialog, self.explainView, self.scoreTable]: if view: view.refresh(game) self.__showBalance()
def setupAnimations(self): """move the item to its new place. This puts new Animation objects into the queue to be animated by calling animate()""" for pName, newValue in self.moveDict().items(): if self.scene() != Internal.scene: # not part of the playing scene, like tiles in tilesetselector setattr(self, pName, newValue) continue animation = self.queuedAnimation(pName) if animation: curValue = animation.endValue() if curValue != newValue: # change a queued animation if self.name() in Debug.animation: logDebug('setEndValue for {}: {}: {}->{}'.format( animation, pName, animation.formatValue(curValue), animation.formatValue(newValue))) animation.setEndValue(newValue) else: animation = self.activeAnimation.get(pName, None) if isAlive(animation): curValue = animation.endValue() else: curValue = self.getValue(pName) if pName != 'scale' or abs(curValue - newValue) > 0.00001: # ignore rounding differences for scale if curValue != newValue: Animation(self, pName, newValue)
def cancelAll(): """cancel all animations""" if Debug.quit: logDebug('Cancelling all animations') for group in ParallelAnimationGroup.running: if isAlive(group): group.clear()
def __str__(self): """for debug messages""" if isAlive(self) and isAlive(self.targetObject()): currentValue = getattr(self.targetObject(), self.pName()) endValue = self.endValue() targetObject = self.targetObject() else: currentValue = 'notAlive' endValue = 'notAlive' targetObject = 'notAlive' return '%s %s: %s->%s for %s duration=%dms' % ( self.ident(), self.pName(), self.formatValue(currentValue), self.formatValue(endValue), targetObject, self.duration())
def autoAnswer(self): """autoPlay gets autoAnswer""" result = self.dlg.returns() if Internal.field and isAlive(self.dlg): self.dlg.hide() self.dlg = None self.callback(result)
def _loginReallyFailed(self, failure): """login failed, not fixable by adding missing user""" msg = None if not isAlive(Internal.mainWindow): raise CancelledError if failure.check(CancelledError): pass elif failure.check(twisted.internet.error.TimeoutError): msg = i18n('Server %1 did not answer', self.url) elif failure.check(twisted.internet.error.ConnectionRefusedError): msg = i18n('Server %1 refused connection', self.url) elif failure.check(twisted.internet.error.ConnectionLost): msg = i18n('Server %1 does not run a kajongg server', self.url) elif failure.check(twisted.internet.error.DNSLookupError): msg = i18n('Address for server %1 cannot be found', self.url) elif failure.check(twisted.internet.error.ConnectError): msg = i18n( 'Login to server %1 failed: You have no network connection', self.url) else: msg = 'Login to server {} failed: {}/{} Callstack:{}'.format( self.url, failure.value.__class__.__name__, failure.getErrorMessage(), failure.getTraceback()) # Maybe the server is running but something is wrong with it if self.url and self.url.useSocket: if removeIfExists(socketName()): logInfo( i18n('removed stale socket <filename>%1</filename>', socketName())) msg += '\n\n\n' + i18n('Please try again') self.dlg = None if msg: logWarning(msg) raise CancelledError
def updateSceneGUI(self): """update some actions, all auxiliary windows and the statusbar""" if not isAlive(self): return GameScene.updateSceneGUI(self) game = self.game mainWindow = self.mainWindow if not game: connections = list(x.connection for x in HumanClient.humanClients if x.connection) title = ', '.join('{name}/{url}'.format(name=x.username, url=x.url) for x in connections) if title: decorateWindow(mainWindow, title) else: decorateWindow(mainWindow, str(game.seed)) for action in [mainWindow.actionScoreGame, mainWindow.actionPlayGame]: action.setEnabled(not bool(game)) mainWindow.actionAbortGame.setEnabled(bool(game)) self.discardBoard.setVisible(bool(game)) mainWindow.actionAutoPlay.setEnabled(not self.startingGame) mainWindow.actionChat.setEnabled( bool(game) and bool(game.client) and bool(game.client.connection) and not game.client.connection.url.isLocalGame and not self.startingGame) # chatting on tables before game started works with chat button per # table mainWindow.actionChat.setChecked( mainWindow.actionChat.isEnabled() and bool(game.client.table.chatWindow))
def showMoveHelper(self, visible=None): """show help text In empty HandBoards""" if visible is None: visible = not self.uiTiles if self.__moveHelper and not isAlive(self.__moveHelper): return if visible: if not self.__moveHelper: splitter = QGraphicsRectItem(self) hbCenter = self.rect().center() splitter.setRect(hbCenter.x() * 0.5, hbCenter.y(), hbCenter.x() * 1, 1) helpItems = [splitter] for name, yFactor in [(i18n('Move Exposed Tiles Here'), 0.5), (i18n('Move Concealed Tiles Here'), 1.5) ]: helper = QGraphicsSimpleTextItem(name, self) helper.setScale(3) nameRect = QRectF() nameRect.setSize( helper.mapToParent( helper.boundingRect()).boundingRect().size()) center = QPointF(hbCenter) center.setY(center.y() * yFactor) helper.setPos(center - nameRect.center()) if sceneRotation(self) == 180: rotateCenter(helper, 180) helpItems.append(helper) self.__moveHelper = self.scene().createItemGroup(helpItems) self.__moveHelper.setVisible(True) else: if self.__moveHelper: self.__moveHelper.setVisible(False)
def showMoveHelper(self, visible=None): """show help text In empty HandBoards""" if visible is None: visible = not self.uiTiles if self.__moveHelper and not isAlive(self.__moveHelper): return if visible: if not self.__moveHelper: splitter = QGraphicsRectItem(self) hbCenter = self.rect().center() splitter.setRect( hbCenter.x() * 0.5, hbCenter.y(), hbCenter.x() * 1, 1) helpItems = [splitter] for name, yFactor in [(m18n('Move Exposed Tiles Here'), 0.5), (m18n('Move Concealed Tiles Here'), 1.5)]: helper = QGraphicsSimpleTextItem(name, self) helper.setScale(3) nameRect = QRectF() nameRect.setSize( helper.mapToParent(helper.boundingRect()).boundingRect().size()) center = QPointF(hbCenter) center.setY(center.y() * yFactor) helper.setPos(center - nameRect.center()) if self.sceneRotation() == 180: rotateCenter(helper, 180) helpItems.append(helper) self.__moveHelper = self.scene().createItemGroup(helpItems) self.__moveHelper.setVisible(True) else: if self.__moveHelper: self.__moveHelper.setVisible(False)
def setActiveAnimation(self, animation): """the tile knows which of its properties are currently animated""" self.queuedAnimations = [] propName = animation.pName() assert propName not in self.activeAnimation or not isAlive(self.activeAnimation[propName]) self.activeAnimation[propName] = animation self.graphics.setCacheMode(QGraphicsItem.ItemCoordinateCache)
def setEnabled(self, enabled): """enable/disable this board""" if isAlive(self): # aborting a running game: the underlying C++ object might # already have been destroyed self.tileDragEnabled = (enabled and self.player == self.player.game.myself) QGraphicsRectItem.setEnabled(self, enabled)
def setActiveAnimation(self, animation): """the tile knows which of its properties are currently animated""" self.queuedAnimations = [] propName = animation.pName() assert propName not in self.activeAnimation or not isAlive( self.activeAnimation[propName]) self.activeAnimation[propName] = animation self.graphics.setCacheMode(QGraphicsItem.ItemCoordinateCache)
def setEnabled(self, enabled): """enable/disable this board""" if isAlive(self): # aborting a running game: the underlying C++ object might # already have been destroyed self.tileDragEnabled = enabled and \ (self.player.game.isScoringGame() or self.player == self.player.game.myself) QGraphicsRectItem.setEnabled(self, enabled)
def hide(self): """remove all uiTile references so they can be garbage collected""" for uiTile in self.uiTiles: uiTile.hide() self.uiTiles = [] self._focusTile = None if isAlive(self): self.setVisible(False)
def hide(self): """remove all tile references so they can be garbage collected""" for tile in self.tiles: tile.hide() self.tiles = [] self._focusTile = None if isAlive(self): QGraphicsRectItem.hide(self)
def close(self): """close the game""" scene = Internal.scene scene.discardBoard.hide() if isAlive(scene): scene.removeTiles() scene.clientDialog = None for player in self.players: player.hide() if self.wall: self.wall.hide() if isAlive(scene.mainWindow): scene.mainWindow.actionAutoPlay.setChecked(False) scene.startingGame = False scene.game = None scene.mainWindow.updateGUI() return PlayingGame.close(self)
def close(self): """close the game""" scene = Internal.scene scene.discardBoard.hide() if isAlive(scene): scene.removeTiles() scene.clientDialog = None for player in self.players: player.hide() if self.wall: self.wall.hide() if isAlive(scene.mainWindow): scene.mainWindow.actionAutoPlay.setChecked(False) scene.startingGame = False scene.game = None SideText.removeAll() scene.mainWindow.updateGUI() return PlayingGame.close(self)
def refresh(self, dummyDeferredResult=None): """show/hide on correct position after queued animations end""" board = self.board if not isAlive(board) or not isAlive(self): if isAlive(self): self.setVisible(False) return rect = board.tileFaceRect() rect.setWidth(rect.width() * board.focusRectWidth()) self.setRect(rect) self.setRotation(board.sceneRotation()) self.setScale(board.scale()) if board.focusTile: board.focusTile.setFocus() self.setPos(board.focusTile.pos) game = Internal.scene.game self.setVisible(board.isVisible() and bool(board.focusTile) and board.isEnabled() and board.hasFocus and bool(game) and not game.autoPlay)
def save(self): """writes the state into Preferences, but does not save""" for name, widget in self.widgets: if isAlive(widget): if isinstance(widget, (QSplitter, QHeaderView)): saveMethod = widget.saveState else: saveMethod = widget.saveGeometry Preferences[name] = QString(saveMethod().toHex())
def board(self, value): """assign and show/hide as needed""" if value and not isAlive(value): logDebug('assigning focusRect to a non-alive board %s/%s' % (type(value), value)) return if value: self._board = value self.refresh()
def adjustMainView(self): """adjust the view such that exactly the wanted things are displayed without having to scroll""" if not Internal.scaleScene or not isAlive(self): return view, scene = self.centralView, self.scene if scene: scene.adjustSceneView() view.fitInView(scene.itemsBoundingRect(), Qt.KeepAspectRatio)
def pName(self): """ Return self.propertyName() as a python string. @return: C{str} """ if isAlive(self): return bytes(self.propertyName()).decode() else: return 'notAlive'
def save(self): """writes the state into Preferences, but does not save""" for name, widget in self.widgets: if isAlive(widget): if hasattr(widget, 'saveState'): Internal.Preferences[name + 'State'] = self.stateStr( widget.saveState()) if hasattr(widget, 'saveGeometry'): Internal.Preferences[name + 'Geometry'] = self.stateStr( widget.saveGeometry())
def save(self): """writes the state into Preferences, but does not save""" for name, widget in self.widgets: if isAlive(widget): if hasattr(widget, 'saveState'): Internal.Preferences[name + 'State'] = QString( widget.saveState().toHex()) if hasattr(widget, 'saveGeometry'): Internal.Preferences[name + 'Geometry'] = QString( widget.saveGeometry().toHex())
def clearHand(self): """clears attributes related to current hand""" Player.clearHand(self) if self.game and self.game.wall: # is None while __del__ self.front = self.game.wall[self.idx] if isAlive(self.handBoard): self.handBoard.setEnabled(True) self.handBoard.showMoveHelper() self.manualRuleBoxes = []
def board(self, value): """assign and show/hide as needed""" if value and not isAlive(value): logDebug( u'assigning focusRect to a non-alive board %s/%s' % (type(value), value)) return if value: self._board = value self.refresh()
def refresh(self, dummyDeferredResult=None): """show/hide on correct position after queued animations end""" board = self.board if not isAlive(board) or not isAlive(self): if isAlive(self): self.setVisible(False) return rect = board.tileFaceRect() rect.setWidth(rect.width() * board.focusRectWidth()) self.setRect(rect) self.setRotation(sceneRotation(board)) self.setScale(board.scale()) if board.focusTile: board.focusTile.setFocus() self.setPos(board.focusTile.pos) game = Internal.scene.game self.setVisible(board.isVisible() and bool(board.focusTile) and board.isEnabled() and board.hasFocus and bool(game) and not game.autoPlay)
def timeout(self): """the progressboard wants an update""" pBar = self.progressBar if isAlive(pBar): pBar.setValue(pBar.value()+1) pBar.setVisible(True) if pBar.value() == pBar.maximum(): # timeout: we always return the original default answer, not the one with focus self.selectButton() pBar.setVisible(False)
def queryExit(self): """see queryClose""" def quitDebug(*args, **kwargs): """reducing branches in queryExit""" if Debug.quit: logDebug(*args, **kwargs) if self.exitReady: quitDebug( 'MainWindow.queryExit returns True because exitReady is set') return True if self.exitConfirmed: # now we can get serious self.exitReady = False for widget in chain( (x.tableList for x in HumanClient.humanClients), [self.confDialog, self.rulesetWindow, self.playerWindow]): if isAlive(widget): widget.hide() if self.exitWaitTime is None: self.exitWaitTime = 0 if Internal.reactor and Internal.reactor.running: self.exitWaitTime += 10 if self.exitWaitTime % 1000 == 0: logDebug('waiting since %d seconds for reactor to stop' % (self.exitWaitTime // 1000)) try: quitDebug('now stopping reactor') Internal.reactor.stop() assert isAlive(self) QTimer.singleShot(10, self.close) except ReactorNotRunning: self.exitReady = True quitDebug( 'MainWindow.queryExit returns True: It got exception ReactorNotRunning' ) else: self.exitReady = True quitDebug( 'MainWindow.queryExit returns True: Reactor is not running' ) return bool(self.exitReady)
def colorizeName(self): """set the color to be used for showing the player name on the wall""" if not isAlive(self.front.nameLabel): return if self == self.game.activePlayer and self.game.client: color = Qt.blue elif Internal.Preferences.tilesetName == 'jade': color = Qt.white else: color = Qt.black self.front.nameLabel.setBrush(QBrush(QColor(color)))
def colorizeName(self): """set the color to be used for showing the player name on the wall""" if not isAlive(self.sideText): return if self == self.game.activePlayer and self.game.client: color = Qt.blue elif Internal.Preferences.tilesetName == 'jade': color = Qt.white else: color = Qt.black self.sideText.color = color
def timeout(self): """the progressboard wants an update""" pBar = self.progressBar if isAlive(pBar): pBar.setValue(pBar.value() + 1) pBar.setVisible(True) if pBar.value() == pBar.maximum(): # timeout: we always return the original default answer, not # the one with focus self.selectButton() pBar.setVisible(False)
def updateSceneGUI(self): """update some actions, all auxiliary windows and the statusbar""" if not isAlive(self): return GameScene.updateSceneGUI(self) game = self.game mainWindow = self.mainWindow for action in [mainWindow.actionScoreGame, mainWindow.actionPlayGame]: action.setEnabled(not bool(game)) mainWindow.actionAbortGame.setEnabled(bool(game)) self.selectorBoard.setVisible(bool(game)) self.selectorBoard.setEnabled(bool(game))
def close(self): """log off from the server and return a Deferred""" scene = Internal.scene scene.selectorBoard.uiTiles = [] scene.selectorBoard.allSelectorTiles = [] if isAlive(scene): scene.removeTiles() for player in self.players: player.hide() if self.wall: self.wall.hide() return Game.close(self)
def cleanExit(*dummyArgs): """close sqlite3 files before quitting""" if isAlive(Internal.mainWindow): if Debug.quit: logDebug('cleanExit calling mainWindow.close') Internal.mainWindow.close() else: # this must be very early or very late if Debug.quit: logDebug('cleanExit calling sys.exit(0)') # sys.exit(0) MainWindow.aboutToQuit()
def updateCurrentTime(self, value): """count how many steps an animation does.""" self.steps += 1 if self.steps % 50 == 0: # periodically check if the board still exists. # if not (game end), we do not want to go on for animation in self.animations: uiTile = animation.targetObject() if not isAlive(uiTile.board): uiTile.clearActiveAnimation(animation) self.removeAnimation(animation) QParallelAnimationGroup.updateCurrentTime(self, value)
def updateCurrentTime(self, value): """count how many steps an animation does.""" self.steps += 1 if self.steps % 50 == 0: # periodically check if the board still exists. # if not (game end), we do not want to go on for animation in self.animations: tile = animation.targetObject() if not isAlive(tile.board): tile.clearActiveAnimation(animation) self.removeAnimation(animation) QParallelAnimationGroup.updateCurrentTime(self, value)
def cleanExit(*dummyArgs): """close sqlite3 files before quitting""" if isAlive(Internal.mainWindow): if Debug.quit: logDebug(u'cleanExit calling mainWindow.close') Internal.mainWindow.close() else: # this must be very early or very late if Debug.quit: logDebug(u'cleanExit calling sys.exit(0)') # sys.exit(0) MainWindow.aboutToQuit()
def queryExit(self): """see queryClose""" def quitDebug(*args, **kwargs): """reducing branches in queryExit""" if Debug.quit: logDebug(*args, **kwargs) if self.exitReady: quitDebug(u'MainWindow.queryExit returns True because exitReady is set') return True if self.exitConfirmed: # now we can get serious self.exitReady = False for widget in chain( (x.tableList for x in HumanClient.humanClients), [ self.confDialog, self.rulesetWindow, self.playerWindow]): if isAlive(widget): widget.hide() if self.exitWaitTime is None: self.exitWaitTime = 0 if Internal.reactor and Internal.reactor.running: self.exitWaitTime += 10 if self.exitWaitTime % 1000 == 0: logDebug( u'waiting since %d seconds for reactor to stop' % (self.exitWaitTime // 1000)) try: quitDebug(u'now stopping reactor') Internal.reactor.stop() assert isAlive(self) QTimer.singleShot(10, self.close) except ReactorNotRunning: self.exitReady = True quitDebug( u'MainWindow.queryExit returns True: It got exception ReactorNotRunning') else: self.exitReady = True quitDebug(u'MainWindow.queryExit returns True: Reactor is not running') return bool(self.exitReady)
def adjustView(self): """adjust the view such that exactly the wanted things are displayed without having to scroll""" if not Internal.scaleScene or not isAlive(self): return view, scene = self.centralView, self.scene if scene: scene.adjustView() oldRect = view.sceneRect() view.setSceneRect(scene.itemsBoundingRect()) newRect = view.sceneRect() if oldRect != newRect: view.fitInView(scene.itemsBoundingRect(), Qt.KeepAspectRatio)
def placeFocusRect(self): """show a blue rect around tile""" board = self._focusBoard if isAlive(board) and self.__focusRectVisible(): rect = board.tileFaceRect() rect.setWidth(rect.width()*board.focusRectWidth()) self.focusRect.setRect(rect) self.focusRect.setPos(board.focusTile.graphics.pos()) self.focusRect.setRotation(board.sceneRotation()) self.focusRect.setScale(board.scale()) self.focusRect.show() else: self.focusRect.hide()
def colorizeName(self): """set the color to be used for showing the player name on the wall""" if not isAlive(self.front.nameLabel): # TODO: should never happen logDebug('colirizeName: nameLabel is not alive') return if self == self.game.activePlayer and self.game.client: color = Qt.blue elif Internal.field.tilesetName == 'jade': color = Qt.white else: color = Qt.black self.front.nameLabel.setBrush(QBrush(QColor(color)))
def __init__(self, target, propName, endValue, parent=None): QPropertyAnimation.__init__(self, target, propName, parent) QPropertyAnimation.setEndValue(self, endValue) duration = Preferences.animationDuration() self.setDuration(duration) self.setEasingCurve(QEasingCurve.InOutQuad) target.queuedAnimations.append(self) Animation.nextAnimations.append(self) if target.element in Debug.animation: oldAnimation = target.activeAnimation.get(propName, None) if isAlive(oldAnimation): logDebug('new animation %s (after %s is done)' % (self, oldAnimation.ident())) else: logDebug('new animation %s' % self)
def confirmed(result): """quit if the active game has been aborted""" self.exitConfirmed = bool(result) if Debug.quit: if self.exitConfirmed: logDebug(u'mainWindow.queryClose confirmed') else: logDebug(u'mainWindow.queryClose not confirmed') # start closing again. This time no question will appear, the game # is already aborted if self.exitConfirmed: assert isAlive(self) self.close() else: self.exitConfirmed = None