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 mainButton(app, text, onClick, pos, anchor='topleft', hugeFont=False, smallFont=False): pos = Location(ScaledScreenAttachedPoint(ScaledSize(pos[0], pos[1]), 'topleft'), anchor) if hugeFont: font = app.screenManager.fonts.hugeMenuFont elif smallFont: font = app.screenManager.fonts.menuFont else: font = app.screenManager.fonts.mainMenuFont result = TextButton(app, pos, text, font, app.theme.colours.mainMenuColour, app.theme.colours.mainMenuHighlight) result.onClick.addListener(lambda sender: onClick()) return result
def button(app, text, onClick, pos, anchor='topleft', hugeFont=False, smallFont=False, firstColour=None, secondColour=None): if firstColour is None: firstColour = app.theme.colours.secondMenuColour if secondColour is None: secondColour = app.theme.colours.mainMenuHighlight pos = Location(ScaledScreenAttachedPoint(ScaledSize(pos[0], pos[1]), anchor), anchor) if hugeFont: font = app.screenManager.fonts.hugeMenuFont elif smallFont: font = app.screenManager.fonts.menuFont else: font = app.screenManager.fonts.mainMenuFont result = TextButton(app, pos, text, font, firstColour, secondColour) result.onClick.addListener(lambda sender: onClick()) return result
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, serverName='server', onCancel=None): super(ConnectingScreen, self).__init__(app) colours = app.theme.colours self.text = TextElement(self.app, 'Connecting to %s...' % serverName, self.app.screenManager.fonts.bigMenuFont, ScaledLocation(512, 384, 'center'), colour=colours.connectingColour) button = TextButton( self.app, Location(ScaledScreenAttachedPoint(ScaledSize(0, 300), 'center'), 'center'), 'cancel', self.app.screenManager.fonts.bigMenuFont, colours.mainMenuColour, colours.white, onClick=onCancel) self.onCancel = button.onClick self.elements = [button, self.text]
def __init__(self, app, host, onClose, onSave): super(ChangePasswordTab, self).__init__(app, 'Password') self.onClose = onClose self.onSave = onSave self.host = host font = app.screenManager.fonts.defaultTextBoxFont labelColour = app.theme.colours.dialogBoxTextColour inputColour = app.theme.colours.white label = TextElement( self.app, 'Use this form to change your password for %s' % (self.host, ), font=self.app.screenManager.fonts.smallMenuFont, pos=Location( ScaledScreenAttachedPoint(ScaledPoint(100, 200), 'topleft'), 'topleft'), colour=self.app.theme.colours.mainMenuColour, ) self.passwordField = 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.passwordField2 = PasswordBox( app, Region(topleft=self.Relative(0.1, 0.8), bottomright=self.Relative(0.9, 0.96)), font=font, colour=inputColour, onClick=self.setFocus, onTab=self.tabNext) self.elements = [ label, TextElement(app, 'New password', font, Location(self.Relative(0.1, 0.43), 'midleft'), labelColour), self.passwordField, TextElement(app, 'Retype new password', font, Location(self.Relative(0.1, 0.75), 'midleft'), labelColour), self.passwordField2, button(app, 'save', self.onSave, (-100, -75), 'midbottom', secondColour=app.theme.colours.white), button(app, 'cancel', self.cancel, (100, -75), 'midbottom', secondColour=app.theme.colours.white), ] self.tabOrder = [self.passwordField, self.passwordField2]
def setupTable(self): position = Location( ScaledScreenAttachedPoint(ScaledPoint(100, 200), 'topleft'), 'topleft') # position is merely temporary self.serverTable = table.Table(self.app, position) hostColumn = table.TextBoxColumn(self.app, self.serverTable, ScaledScalar(290)) portColumn = table.TextBoxColumn(self.app, self.serverTable, ScaledScalar(70)) connectButtonColumn = table.TextButtonColumn(self.app, self.serverTable, ScaledScalar(80)) accountButtonColumn = table.TextButtonColumn(self.app, self.serverTable, ScaledScalar(100)) upButtonColumn = table.TextButtonColumn(self.app, self.serverTable, ScaledScalar(40)) downButtonColumn = table.TextButtonColumn(self.app, self.serverTable, ScaledScalar(40)) deleteButtonColumn = table.TextButtonColumn(self.app, self.serverTable, ScaledScalar(40)) self.serverTable.addColumns([ hostColumn, portColumn, connectButtonColumn, accountButtonColumn, upButtonColumn, downButtonColumn, deleteButtonColumn, ]) self.serverTable.setBorderWidth(4) self.serverTable.setBorderColour((0, 0, 0)) with self.serverTable.style as s: s.backColour = (255, 255, 255) s.foreColour = self.app.theme.colours.mainMenuColour s.font = self.app.screenManager.fonts.smallMenuFont s.padding = (4, 1) s.hasShadow = True s.shadowColour = (0, 0, 0) hostColumn.style.textAlign = 'midright' portColumn.style.textAlign = 'center' for column in (connectButtonColumn, accountButtonColumn, upButtonColumn, downButtonColumn): with column.style as s: s.textAlign = 'center' s.foreColour = self.app.theme.colours.mainMenuHighlight s.hoverColour = self.app.theme.colours.black with deleteButtonColumn.style as s: s.foreColour = self.app.theme.colours.red s.backColour = self.app.theme.colours.black s.hoverColour = self.app.theme.colours.white s.textAlign = 'center' self.serverTable.setDefaultHeight(ScaledScalar(40)) # Title row row = self.serverTable.addRow() row[HOSTNAME_COLUMN].setText('Host Name') row[HOSTNAME_COLUMN].style.foreColour = self.app.theme.colours.black row[HOSTNAME_COLUMN].setReadOnly(True) row[PORT_COLUMN].setText('Port') row[PORT_COLUMN].style.foreColour = self.app.theme.colours.black row[PORT_COLUMN].setReadOnly(True) self.serverTable.getRow(0).style.backColour = ( self.app.theme.colours.grey)
def setupButtons(self): lanButtonPos = Location( ScaledScreenAttachedPoint(ScaledPoint(100, 550), 'topleft')) self.lanButton = CheckBox( self.app, lanButtonPos, 'LAN Discovery', self.app.screenManager.fonts.serverSelectionCheckboxesFont, self.app.theme.colours.mainMenuColour, initValue=self.app.connectionSettings.lanGames, style='circle', fillColour=self.app.theme.colours.mainMenuColour) self.lanButton.onValueChanged.addListener(lambda sender: self.save()) lanSearchButtonPos = Location( ScaledScreenAttachedPoint(ScaledPoint(380, 550), 'topleft')) self.lanSearchButton = TextButton( self.app, lanSearchButtonPos, 'Search LAN for Game', self.app.screenManager.fonts.serverSelectionCheckboxesFont, self.app.theme.colours.mainMenuHighlight, self.app.theme.colours.white, onClick=lambda sender: self.joinLan()) createButtonPos = Location( ScaledScreenAttachedPoint(ScaledPoint(100, 600), 'topleft')) self.createButton = CheckBox( self.app, createButtonPos, 'Create games on remote servers', self.app.screenManager.fonts.serverSelectionCheckboxesFont, self.app.theme.colours.mainMenuColour, initValue=self.app.connectionSettings.createGames, style='circle', fillColour=self.app.theme.colours.mainMenuColour) self.createButton.onValueChanged.addListener( lambda sender: self.save()) otherButtonPos = Location( ScaledScreenAttachedPoint(ScaledPoint(100, 650), 'topleft')) self.otherButton = CheckBox( self.app, otherButtonPos, 'Ask servers about other games', self.app.screenManager.fonts.serverSelectionCheckboxesFont, self.app.theme.colours.mainMenuColour, initValue=self.app.connectionSettings.otherGames, style='circle', fillColour=self.app.theme.colours.mainMenuColour) self.otherButton.onValueChanged.addListener(lambda sender: self.save()) newButtonPos = Location( ScaledScreenAttachedPoint(ScaledPoint(850, 285), 'topleft')) self.newButton = TextButton( self.app, newButtonPos, '+ Server', self.app.screenManager.fonts.serverSelectionCheckboxesFont, self.app.theme.colours.serverSelectionNewItem, self.app.theme.colours.white, onClick=lambda sender: self.newServer()) self.closeButton = elements.TextButton( self.app, Location( ScaledScreenAttachedPoint(ScaledSize(-70, 650), 'topright'), 'topright'), 'done', self.app.screenManager.fonts.bigMenuFont, self.app.theme.colours.mainMenuHighlight, self.app.theme.colours.white, onClick=lambda sender: self.onClose(), )