def setUpgrade(self, upgradeType, player): self.player = player self.upgrade = upgradeType if player is None or upgradeType is None: self.elements = [self.coinsText] else: pos = Location(Screen(0.6, 0), 'midtop') image = self.app.theme.sprites.upgradeImage(upgradeType) area = Area( RelativePoint(Screen(0.6, 0), (0, 52)), ScaledSize(50, 10), 'midtop') self.elements = [ PictureElement(self.app, image, pos), self.coinsText, ] if upgradeType.enabled: self.elements.append( CoinGauge(self.app, area, player, upgradeType)) else: self.elements.append( TextElement(self.app, 'DISABLED', self.app.screenManager.fonts.ingameMenuFont, Location(CanvasX(620, 68), 'midbottom'), self.app.theme.colours.errorMessageColour))
def __init__(self, app): size = Canvas(384, 150) DialogBox.__init__(self, app, size, 'Host game?') self._deferred = None font = app.screenManager.fonts.defaultTextBoxFont btnColour = app.theme.colours.dialogButtonColour highlightColour = app.theme.colours.black labelColour = app.theme.colours.dialogBoxTextColour btnFont = app.screenManager.fonts.bigMenuFont self.elements = [ TextElement(app, 'No games found. Host a game?', font, Location(self.Relative(0.5, 0.4), 'center'), labelColour), TextButton(app, Location(self.Relative(0.3, 0.85), 'center'), 'Yes', btnFont, btnColour, highlightColour, onClick=self.yesClicked), TextButton(app, Location(self.Relative(0.7, 0.85), 'center'), 'No', btnFont, btnColour, highlightColour, onClick=self.noClicked), ]
def __init__(self, app, controller): super(JoiningDialog, self).__init__(app, ScaledSize(530, 180), 'Trosnoth') colours = app.theme.colours self.controller = controller fonts = self.app.screenManager.fonts self.text = elements.TextElement( self.app, '', fonts.menuFont, Location(DialogBoxAttachedPoint(self, ScaledSize(0, 40), 'midtop'), 'midtop'), colour=colours.joiningColour, ) self.elements = [ self.text, elements.TextButton( self.app, Location( DialogBoxAttachedPoint(self, ScaledSize(0, -10), 'midbottom'), 'midbottom'), 'Cancel', fonts.menuFont, colours.inGameButtonColour, colours.white, onClick=controller.cancelJoin, ), ] self.setColours(colours.joinGameBorderColour, colours.joinGameTitleColour, colours.joinGameBackgroundColour)
def __init__(self, app): Tab.__init__(self, app, 'Sign in') framework.TabFriendlyCompoundElement.__init__(self, app) font = app.screenManager.fonts.defaultTextBoxFont labelColour = app.theme.colours.dialogBoxTextColour inputColour = app.theme.colours.grey self.usernameField = prompt.InputBox(app, Region(topleft=self.Relative(0.1, 0.16), bottomright=self.Relative(0.9, 0.32)), font=font, colour=inputColour, validator=usernameValidator, onClick=self.setFocus, onTab=self.tabNext) self.passwordField = prompt.PasswordBox(app, Region(topleft=self.Relative(0.1, 0.48), bottomright=self.Relative(0.9, 0.64)), font=font, colour=inputColour, onClick=self.setFocus, onTab=self.tabNext) self.elements = [ TextElement(app, 'Username', font, Location(self.Relative(0.1, 0.11), 'midleft'), labelColour), self.usernameField, TextElement(app, 'Password', font, Location(self.Relative(0.1, 0.43), 'midleft'), labelColour), self.passwordField, ] self.tabOrder = [self.usernameField, self.passwordField]
def __init__(self, app, size, caption, message, buttons): DialogBox.__init__(self, app, size, caption) if hasattr(size, 'getSize'): size = size.getSize(app) textFont = app.screenManager.fonts.labelFont lines = wrapWords(app, message, textFont, size[0]) y = 5 for text in lines: textPos = Location(DialogBoxAttachedPoint(self, (0, y), 'midtop'), 'midtop') self.elements.append(TextElement(app, text, textFont, textPos)) y += textFont.getHeight(app) buttonFont = app.screenManager.fonts.captionFont for x in range(0, len(buttons)): dialogResult = buttons[x] location = Location( DialogBoxAttachedPoint(self, (0, -textFont.getHeight(self.app) / 2), 'midbottom'), 'midbottom') buttonFont = app.screenManager.fonts.captionFont for x in range(0, len(buttons)): dialogResult = buttons[x] location = Location( ((x + 1) * size[0] / (len(buttons) + 1), size[1] * 2 / 3), 'midtop') button = TextButton(app, location, DialogResult.text[dialogResult], buttonFont, (255, 0, 0), (255, 100, 200)) button._mbResult = dialogResult button.onClick.addListener(self._setResultAndClose) self.elements.append(button) self.result = None
def __init__(self, app): size = Canvas(512, 384) DialogBox.__init__(self, app, size, 'Please authenticate') self._deferred = None self._host = None font = app.screenManager.fonts.defaultTextBoxFont btnColour = app.theme.colours.dialogButtonColour highlightColour = app.theme.colours.black errorTextColour = app.theme.colours.errorColour self.tabContainer = TabContainer(app, Region(topleft=self.Relative(0, 0), size=self.Relative(1, 0.75)), font, app.theme.colours.tabContainerColour) self.tabContainer.addTab(LoginTab(app)) self.tabContainer.addTab(CreateAccountTab(app)) self.errorText = TextElement(app, '', font, Location(self.Relative(0.5, 0.8), 'center'), errorTextColour) font = app.screenManager.fonts.bigMenuFont self.elements = [ self.tabContainer, self.errorText, TextButton(app, Location(self.Relative(0.3, 0.9), 'center'), 'Ok', font, btnColour, highlightColour, onClick=self.okClicked), TextButton(app, Location(self.Relative(0.7, 0.9), 'center'), 'Cancel', font, btnColour, highlightColour, onClick=self.cancelClicked), ] self.cancelled = False
def __init__(self, app, nick, head): title = 'Player settings' DialogBox.__init__(self, app, Canvas(400, 290), title) labelFont = app.screenManager.fonts.bigMenuFont labelColour = app.theme.colours.dialogBoxTextColour btnFont = app.screenManager.fonts.bigMenuFont btnColour = app.theme.colours.dialogButtonColour highlightColour = app.theme.colours.black inputFont = app.screenManager.fonts.defaultTextBoxFont inputColour = app.theme.colours.grey self.inputBox = InputBox( app, Region(topleft=self.Relative(0.1, 0.25), bottomright=self.Relative(0.9, 0.45)), nick, font=inputFont, colour=inputColour, onClick=self.setFocus, onEnter=self.ok_clicked, onEsc=self.cancel_clicked, ) self.heads = HeadSelector( app, Region(topleft=self.Relative(0.1, 0.5), bottomright=self.Relative(0.9, 0.8))) self.heads.selected(head) self.elements = [ TextElement(app, 'Nickname:', labelFont, Location(self.Relative(0.1, 0.15), 'midleft'), labelColour), self.inputBox, self.heads, TextButton(app, Location(self.Relative(0.3, 0.9), 'center'), 'Ok', btnFont, btnColour, highlightColour, onClick=self.ok_clicked), TextButton(app, Location(self.Relative(0.7, 0.9), 'center'), 'Cancel', btnFont, btnColour, highlightColour, onClick=self.cancel_clicked), ] self.setFocus(self.inputBox)
def refresh(self): if not self.isOpen(): return self.elements = [self.sayToTeam, self.input] initialY = 470 count = 0 for text, nick, colour, firstLine in reversed(self.messageBuffer): currentY = initialY - count * self.MESSAGE_GAP if currentY < 200 or count >= 10: break if firstLine and nick is not None: person = TextElement( self.app, text=nick, font=self.font, pos=Location( FullScreenAttachedPoint((20, currentY), 'topleft'), 'topleft'), colour=colour, shadow=True, ) xOffset = person._getRect().width self.elements.append(person) text = text[len(nick):] else: xOffset = 0 if nick is None: colour = self.app.theme.colours.serverChat else: colour = self.textColour message = TextElement( self.app, text=text, font=self.font, pos=Location( FullScreenAttachedPoint((20 + xOffset, currentY), 'topleft'), 'topleft'), colour=colour, shadow=True, ) self.elements.append(message) count += 1
def __init__(self, app, tabContainer): super(CompoundElement, self).__init__(app) self.firstVisible = 0 self.skipOnMove = 3 self.numToDisplay = 0 self.arrowWidth = arrowWidth = 30 self.elements = [] self.headers = [] self.selectedIndex = -1 onLeft = lambda: self._moveDirection(True) onRight = lambda: self._moveDirection(False) canClickLeft = lambda: self.firstVisible > 0 canClickRight = lambda: (self.firstVisible + self.numToDisplay < len( self.headers)) self.tabContainer = tabContainer self._getHeight = _getHeight = tabContainer._getHeaderHeight class ArrowSize(object): def __init__(self, text): self.text = text def getSize(self, app): return (arrowWidth, _getHeight()) def __repr__(self): return "Arrow Size" self.leftArrow = TabHeaderArrow(app, tabContainer, "<", tabContainer.font, onLeft, canClickLeft) leftLocation = Location( AttachedPoint((0, 0), tabContainer._getRect, 'topleft'), 'topleft') leftSize = ArrowSize("<") self.leftArrow.setDimensions(leftLocation, leftSize) self.rightArrow = TabHeaderArrow(app, tabContainer, ">", tabContainer.font, onRight, canClickRight) rightLocation = Location( AttachedPoint((0, 0), tabContainer._getRect, 'topright'), 'topright') rightSize = ArrowSize(">") self.rightArrow.setDimensions(rightLocation, rightSize) self._getPt = self.tabContainer._getPt
def __init__(self, app, gameInterface): super(DetailsInterface, self).__init__(app) self.gameInterface = gameInterface # Maximum number of messages viewable at any one time maxView = 8 self.world = gameInterface.world self.player = None font = app.screenManager.fonts.messageFont self.currentMessages = MessageBank(self.app, maxView, 50, Location(FullScreenAttachedPoint(ScaledSize(-40,-40), 'bottomright'), 'bottomright'), 'right', 'bottom', font) # If we want to keep a record of all messages and their senders self.input = None self.inputText = None self.unobtrusiveGetter = None self.turretGauge = None self.reloadGauge = GunGauge(self.app, Area( FullScreenAttachedPoint(ScaledSize(0,-60), 'midbottom'), ScaledSize(100,30), 'midbottom')) self.respawnGauge = None self.itemGauge = ItemGauge(self.app, self.player) self.achievementBox = None self.currentUpgrade = None self.settingsMenu = SettingsMenu(app, onClose=self.hideSettings, showThemes=False) self.chatBox = ChatBox(app, self.world, self.gameInterface) menuloc = Location(FullScreenAttachedPoint((0,0), 'bottomleft'), 'bottomleft') self.menuManager = mainMenu.MainMenu(self.app, menuloc, self, self.gameInterface.keyMapping) self.upgradeDisplay = UpgradeDisplay(app) self.trajectoryOverlay = TrajectoryOverlay(app, gameInterface.gameViewer.viewManager, self.upgradeDisplay) self.gameVoteMenu = GameVoteMenu( app, self.world, onChange=self._castGameVote) self._gameVoteUpdateCounter = 0 self.elements = [ self.currentMessages, self.upgradeDisplay, self.reloadGauge, self.gameVoteMenu, self.chatBox, self.trajectoryOverlay, self.menuManager, self.itemGauge, ] self.upgradeMap = dict((upgradeClass.action, upgradeClass) for upgradeClass in allUpgrades)
def draw(self, screen): try: pos = pygame.mouse.get_pos() self.elements[0].setPos(Location(pos, 'center')) except Exception as e: log.exception(str(e)) super(Pointer, self).draw(screen)
def __init__(self, app, onClose=None, onStart=None): super(PractiseScreen, self).__init__(app) self.onClose = Event() if onClose is not None: self.onClose.addListener(onClose) self.onStart = Event() if onStart is not None: self.onStart.addListener(onStart) if app.displaySettings.alphaOverlays: alpha = 192 else: alpha = None bg = SolidRect(app, app.theme.colours.playMenu, alpha, Region(centre=Canvas(512, 384), size=Canvas(924, 500))) #colour = app.theme.colours.mainMenuColour #font = app.screenManager.fonts.consoleFont font = app.screenManager.fonts.bigMenuFont cancel = TextButton(app, Location(Canvas(512, 624), 'midbottom'), 'Cancel', font, app.theme.colours.secondMenuColour, app.theme.colours.white, onClick=self.cancel) self.elements = [bg, cancel]
def __init__(self, app, onSucceed=None, onFail=None): super(PlayAuthScreen, self).__init__(app) self.onSucceed = Event(listener=onSucceed) self.onFail = Event(listener=onFail) self.lobby = None self.badServers = set() if app.displaySettings.alphaOverlays: alpha = 192 else: alpha = None bg = SolidRect(app, app.theme.colours.playMenu, alpha, Region(centre=Canvas(512, 384), size=Canvas(924, 500))) colour = app.theme.colours.mainMenuColour font = app.screenManager.fonts.consoleFont self.logBox = LogBox( app, Region(size=Canvas(900, 425), midtop=Canvas(512, 146)), colour, font) font = app.screenManager.fonts.bigMenuFont cancel = TextButton(app, Location(Canvas(512, 624), 'midbottom'), 'Cancel', font, app.theme.colours.secondMenuColour, app.theme.colours.white, onClick=self.cancel) self.cancelled = False self.elements = [bg, self.logBox, cancel] self._passwordGetter = None self._gameSelectionBox = None
def __init__(self, app, game): super(GameTimer, self).__init__(app) self.world = game.world self.app = app # Change these constants to say where the box goes self.area = Area(FullScreenAttachedPoint(ScaledSize(0, -3), 'midtop'), ScaledSize(110, 35), 'midtop') self.lineWidth = max(int(3 * self.app.screenManager.scaleFactor), 1) # Anything more than width 2 looks way too thick if self.lineWidth > 2: self.lineWidth = 2 self.gameClock = clock.Clock( self.app, self.getTimeString, Location(FullScreenAttachedPoint(ScaledSize(0, 0), 'midtop'), 'midtop'), self.app.screenManager.fonts.timerFont, self.app.theme.colours.timerFontColour) self.elements = [self.gameClock] self.running = False # Seconds for half a flash self.flashCycle = 0.5 # Value the countdown has to get to before it starts to flash self.flashValue = 30
def update(self, loop=False): self._resetPlayers() if not self.world.uiOptions.showReadyStates: yPos = self.yPos else: yPos = self.yPos + int(50 * self.scale) self.playerTable.pos = Location( FullScreenAttachedPoint((self.xPos, yPos), 'topright'), 'topright') try: pi = self.gameViewer.interface.runningPlayerInterface self.friendlyTeam = pi.player.team self.spectator = False except (AttributeError, KeyError): # This will occur if the player is not yet on a team self.friendlyTeam = self.world.teamWithId['A'] self.spectator = True for player in self.world.players: # getDetailsForLeaderBoard() returns dict with pID, nick, team, dead, coins etc. details = player.getDetailsForLeaderBoard() self.players[details['team']].append(details) self._sortTeam('A') self._sortTeam('B') self._sortTeam(NEUTRAL_TEAM_ID) self._updateTable() if loop: self.callDef = WeakCallLater(UPDATE_DELAY, self, 'update', True)
def __init__(self, app, onCancel=None, onReplay=None): super(SavedGameMenu, self).__init__(app) area = ScaledArea(50, 140, 924, 570) bg = pygame.Surface((924, 500)) bg.fill(app.theme.colours.replayMenu) if app.displaySettings.alphaOverlays: bg.set_alpha(192) font = self.app.screenManager.fonts.ampleMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.replayTabBorder) bp = SizedPicture( app, bg, Location(AttachedPoint((0, 0), self.tabContainer._getTabRect)), TabSize(self.tabContainer)) self.replayTab = SavedGameTab(app, self.tabContainer, onCancel=onCancel, onReplay=onReplay) self.tabContainer.addTab(self.replayTab) self.elements = [bp, self.tabContainer]
def __init__(self, app, world, interface): super(ChatBox, self).__init__(app) self.world = world self.app = app self.interface = interface self.font = self.app.screenManager.fonts.newChatFont self.frameColour = self.app.theme.colours.chatFrameColour self.insideColour = self.app.theme.colours.chatInsideColour self.textColour = self.app.theme.colours.chatNormalColour self.sayToTeam = TextElement( self.app, text="Say to team:", font=self.font, pos=Location(FullScreenAttachedPoint((20, 501), 'topleft'), 'topleft'), colour=self.textColour, shadow=True, ) self.inputPosition = Area( FullScreenAttachedPoint((145, 500), 'topleft'), (370, 20), 'topleft') self.input = InputBox(self.app, self.inputPosition, font=self.font) self.input.onEnter.addListener( lambda sender: self.hitEnter(sender.value)) self.input.onEsc.addListener(lambda sender: self.close()) self.input.onClick.addListener(self.setFocus) self.messages = MessageBank( self.app, 10, 100, Location(FullScreenAttachedPoint((20, 470), 'topleft'), 'topleft'), 'left', 'bottom', self.font) self._chatOpen = False self.teamChat = True self.player = None self.messageBuffer = [] self.MESSAGE_GAP = self.font.getHeight(self.app) self.elements = [self.messages]
def __init__(self, app): size = Canvas(512, 384) DialogBox.__init__(self, app, size, 'Select arena') self._deferred = None self._games = None font = app.screenManager.fonts.defaultTextBoxFont btnColour = app.theme.colours.dialogButtonColour highlightColour = app.theme.colours.black labelColour = app.theme.colours.dialogBoxTextColour btnFont = app.screenManager.fonts.bigMenuFont listboxFont = app.screenManager.fonts.serverListFont listboxColour = app.theme.colours.mainMenuColour listboxHighlight = app.theme.colours.mainMenuHighlight self.gameList = ListBox( self.app, Region(topleft=self.Relative(0.05, 0.15), size=self.Relative(0.9, 0.65)), [], listboxFont, listboxColour, listboxHighlight, ) self.elements = [ TextElement(app, 'Please select:', font, Location(self.Relative(0.05, 0.05), 'topleft'), labelColour), self.gameList, TextButton(app, Location(self.Relative(0.3, 0.9), 'center'), 'Ok', btnFont, btnColour, highlightColour, onClick=self.okClicked), TextButton(app, Location(self.Relative(0.7, 0.9), 'center'), 'Cancel', btnFont, btnColour, highlightColour, onClick=self.cancelClicked), ]
def __init__(self, app, row, column): super(TextButtonCell, self).__init__(app, row, column) textAlign = self.styleGet('textAlign') pos = Location(CellAttachedPoint((0, 0), self, textAlign), textAlign) self.textButton = TextButton( self.app, pos, '', self.styleGet('font'), self.styleGet('foreColour'), self.styleGet('hoverColour')) self.elements = [self.textButton] self._oldText = ''
def __init__(self, app, row, column): super(TextCell, self).__init__(app, row, column) textAlign = self.styleGet('textAlign') self.textElement = TextElement( self.app, '', self.styleGet('font'), Location(CellAttachedPoint((0, 0), self, textAlign), textAlign), colour=self.styleGet('foreColour')) self.elements = [self.textElement] self._oldText = ''
def setupCanvas(self): position = Location( ScaledScreenAttachedPoint(ScaledPoint(100, 200), 'topleft'), 'topleft') maxSize = 325 * self.app.screenManager.scaleFactor size = self.serverTable._getSize() if size[1] > maxSize: # We will be using the scrollbars displaySize = (size[0] + scrollableCanvas.ScrollBar.defaultWidth, maxSize) else: displaySize = size self.canvas = scrollableCanvas.ScrollableCanvas( self.app, position, Size(*size), Size(*displaySize)) self.serverTable.pos = Location( scrollableCanvas.ScrollableCanvasAttachedPoint( self.canvas, (0, 0)), 'topleft') self.canvas.elements.append(self.serverTable)
def __init__(self, app): super(UpgradeDisplay, self).__init__(app) self.player = None self.upgrade = None self.coinsText = TextElement( self.app, '', self.app.screenManager.fonts.coinsDisplayFont, Location(Screen(0.65, 0.01), 'midtop'), self.app.theme.colours.coinsDisplayColour, shadow=True) self.elements = [self.coinsText]
def __init__(self, app): super(WinnerMsg, self).__init__(app) self.winnerMsg = TextElement(app, '', app.screenManager.fonts.winMessageFont, Location(Screen(0.5, 0.05), 'midtop'), (64, 64, 64)) self.background = SolidRect( app, (128, 128, 128), 150, PaddedRegion(self.winnerMsg, ScaledScalar(15))) self.elements = []
def __init__(self, app, title, label, validator=None): DialogBox.__init__(self, app, Canvas(400, 230), title) labelFont = app.screenManager.fonts.bigMenuFont labelColour = app.theme.colours.dialogBoxTextColour btnFont = app.screenManager.fonts.bigMenuFont btnColour = app.theme.colours.dialogButtonColour highlightColour = app.theme.colours.black inputFont = app.screenManager.fonts.defaultTextBoxFont inputColour = app.theme.colours.grey self.inputBox = InputBox(app, Region(topleft=self.Relative(0.1, 0.4), bottomright=self.Relative(0.9, 0.6)), font=inputFont, colour=inputColour, onClick=self.setFocus, onEnter=self.okClicked, onEsc=self.cancelClicked, validator=validator) self.elements = [ TextElement(app, label, labelFont, Location(self.Relative(0.1, 0.2), 'midleft'), labelColour), self.inputBox, TextButton(app, Location(self.Relative(0.3, 0.9), 'center'), 'Ok', btnFont, btnColour, highlightColour, onClick=self.okClicked), TextButton(app, Location(self.Relative(0.7, 0.9), 'center'), 'Cancel', btnFont, btnColour, highlightColour, onClick=self.cancelClicked), ] self.setFocus(self.inputBox)
def __init__(self, app, player, achievementId): super(AchievementBox, self).__init__(app) self.app = app self.player = player self.achievements = [achievementId] self.width = 453 self.height = 75 self._setColours() self.area = Area( FullScreenAttachedPoint(ScaledSize(0, -100), 'midbottom'), ScaledSize(self.width, self.height), 'midbottom') self.smlBox = Area( FullScreenAttachedPoint(ScaledSize(-self.width / 2 + 6, -104), 'midbottom'), ScaledSize(66, 66), 'bottomleft') self.titleText = TextElement( self.app, "ACHIEVEMENT UNLOCKED!", self.fonts.achievementTitleFont, Location( FullScreenAttachedPoint( ScaledSize(73 / 2, -100 - self.height + 10), 'midbottom'), 'midtop'), self.borderColour) self.nameText = TextElement( self.app, self.achievementDefs.getAchievementDetails(achievementId)[0], self.fonts.achievementNameFont, Location( FullScreenAttachedPoint(ScaledSize(73 / 2, -100 - 13), 'midbottom'), 'midbottom'), self.colours.black) self.elements = [self.titleText, self.nameText] self._updateImage() self.cycler = WeakLoopingCall(self, 'cycleAchievements') self.cycler.start(5.0, now=False)
def __init__(self, app, area, text, colour, fonts, bgColour=None, textAlign='left', loop=False, startOff=False, antiAlias=False): super(ScrollingText,self).__init__(app) self.area = area self.border = False self.shadowColour = None self.loop = loop self.startOff = startOff self.bgColour = bgColour self.speed = 50 self.offset = 0 self.colour = colour self.fonts = fonts self.text = text self.textAlign = textAlign self.antiAlias = antiAlias self.dirty = False # A test to see whether the size has changed self.lastSize = app.screenManager.size self._setImage() self.autoScroll = False # Create up and down buttons for if there's autoscroll. if 'buttons' in fonts: font = fonts['buttons'] else: font = app.fonts.scrollingButtonsFont pos = Location(AttachedPoint((0, 0), self._getRect, 'topright'), 'topleft') self.upBtn = TextButton(app, pos, ' up', font, colour, (255,255,255)) pos = Location(AttachedPoint((0,0), self._getRect, 'bottomright'), 'bottomleft') self.dnBtn = TextButton(app, pos, ' down', font, colour, (255,255,255)) self.onFinishedScrolling = Event()
def button(self, text, onClick, pos, anchor='topleft', hugeFont=False): pos = Location( ScaledScreenAttachedPoint(ScaledSize(pos[0], pos[1]), anchor), anchor) if hugeFont: font = self.app.screenManager.fonts.hugeMenuFont else: font = self.app.screenManager.fonts.bigMenuFont result = elements.TextButton(self.app, pos, text, font, self.colour, self.highlight) result.onClick.addListener(lambda sender: onClick()) return result
def __init__(self, app, reason): width = app.screenManager.scaleFactor * absoluteWidth font = app.fonts.connectionFailedFont boundary = app.screenManager.scaleFactor * 20 lines = wrapWords(app, reason, font, width - 2 * boundary) x = boundary elements = [] colours = app.theme.colours for text in lines: elements.append( TextElement(app, text, font, Location( DialogBoxAttachedPoint(self, (0, x), 'midtop'), 'midtop'), colour=colours.errorColour)) x += font.getHeight(app) # Boundary * 3 for top, bottom, and middle height = boundary * 3 + font.getHeight(app) * (len(lines) + 1) size = ScaledSize(absoluteWidth, height) super(ConnectionFailedDialog, self).__init__(app, size, 'Connection Failed') self.elements = elements self.elements.append( TextButton(app, Location( DialogBoxAttachedPoint(self, (0, -boundary), 'midbottom'), 'midbottom'), 'OK', font, colours.dialogButtonColour, colours.radioMouseover, onClick=lambda sender: self.close())) self.onEnter = Event() self.onEnter.addListener(self.close)
def addMenuItem(self, item, x, y, width, itemHeight): stdImage = pygame.Surface((self.rect.width, itemHeight)) hvrImage = pygame.Surface((self.rect.width, itemHeight)) stdImage.set_colorkey((0, 0, 0)) hvrImage.set_colorkey((0, 0, 0)) if item.enabled: stdColour = self.stdColour hvrColour = self.hvrColour else: stdColour = hvrColour = self.disabledColour if item.name == '---': # Separator. pygame.draw.line(stdImage, stdColour, (0, itemHeight // 2), (self.rect.width, itemHeight // 2)) pygame.draw.line(hvrImage, hvrColour, (0, itemHeight // 2), (self.rect.width, itemHeight // 2)) else: # Put caption on standard canvas. img = self.font.render(self.app, item.name, True, stdColour) r = img.get_rect() r.midleft = (2, itemHeight // 2) stdImage.blit(img, r) # Put caption on hover canvas. img = self.font.render(self.app, item.name, True, hvrColour) hvrImage.blit(img, r) if item.action is not None and self.keymapping is not None: try: hkStr = keyboard.shortcutName( self.keymapping.getkey(item.action)) except KeyError: pass else: # Put hotkey on standard canvas. img = self.font.render(self.app, hkStr, True, stdColour) r = img.get_rect() r.midright = (width - 2, itemHeight // 2) stdImage.blit(img, r) # Put hotkey on hover canvas. img = self.font.render(self.app, hkStr, True, hvrColour) hvrImage.blit(img, r) btn = elements.HoverButton(self.app, Location((x, y), 'center'), stdImage, hvrImage) if item.enabled: btn.onClick.addListener(lambda btn: item.execute()) self.elements.append(btn)
def __init__(self, app, text, area, image, value=None): super(ImageRadioButton, self).__init__(app) textLoc = Location(AttachedPoint((0, 0), self._getRect, 'midbottom'), 'midbottom') font = app.screenManager.fonts.smallNoteFont self.text = TextElement(app, text, font, textLoc, (0, 0, 0)) picLoc = Location(AttachedPoint((0, 0), self._getRect, 'midtop'), 'midtop') self.area = area self.value = value self._selected = False self.group = None self.bg = self.IRB_background(app, self) self.elements = [self.bg, self.text] if image is not None: self.image = PictureElement(app, image, picLoc) self.elements.insert(1, self.image)