def setUp(self, frame: Frame, window): self._frame = frame self._window = window self._screen = pygame.surface.Surface(frame.size(), pygame.SRCALPHA) self._runner = EventRunner(self) self._backgroundImage = Images(File(self._screenDir), self._frame).setUp(None) self._screen.blit(self._backgroundImage.getImage('background'), self._backgroundImage.getFrame().getCoord()) for _, surface in self: surface.setUp(self._screenDir, self)
class Screen(Container): def __init__(self, name): super().__init__() self._name = name self._screenDir = os.path.join("./surfaces/", self._name + "/") def start(self): pass def run(self): self._runner.run() def end(self): pass def setUp(self, frame: Frame, window): self._frame = frame self._window = window self._screen = pygame.surface.Surface(frame.size(), pygame.SRCALPHA) self._runner = EventRunner(self) self._backgroundImage = Images(File(self._screenDir), self._frame).setUp(None) self._screen.blit(self._backgroundImage.getImage('background'), self._backgroundImage.getFrame().getCoord()) for _, surface in self: surface.setUp(self._screenDir, self) def display(self): self._window.triggerUpdate() def switchScreen(self, type_: str, screen: str = None): self._window.changeStack(type_, screen) def addSurface(self, surface): self.addObject(surface.getName(), surface) return self def getSurface(self, name: str) -> Surface: return self.getObject(name) def getScreen(self): return self._screen def getName(self): return self._name def getFrame(self): return self._frame
def __init__(self, screen, name, frame: Frame, selectable: bool = True, bg_colour: tuple = None, directDisplay: bool = False, alpha: bool = False, **items): self.screen = screen self.name = name self.frame = frame self.selectable = selectable self.bg_colour = bg_colour self.directDisplay = directDisplay self.alpha = alpha # Create surface if self.alpha: self.Surface = pygame.surface.Surface(self.frame.size(), pygame.SRCALPHA) else: self.Surface = pygame.surface.Surface(self.frame.size()) # Get background image self.bg_image = Images([self.screen.name, self.name], frame=self.frame, alpha=alpha) self.loadBackground() # Store items self.loaded = False self.containerList = [] for name, itemData in items.items(): self.addItem(name, itemData)
def __init__(self, spritePage:list, size:tuple, alpha:bool = True): # Get sprite images images = Images(frame=Frame(x=0,y=0,w=size[0],h=size[1]), imagePage=spritePage, scale=True, alpha=alpha) self.containerList = images.containerList # Load them to attributes for image in images.containerList: setattr(self, image, images[image])
def __init__(self, name: str, main: any, surfaces: dict = None, keyboard: dict = None, bg_colour: tuple = None, seperateBackground: bool = False, selectable: bool = True, firstLoad: list = 'all', alpha: bool = False): self.name = name self.main = main self.bg_colour = bg_colour self.selectable = selectable self.frame = Frame(x=window.x, y=window.y, w=window.width, h=window.height) self.alpha = alpha # Event setup self.events = Events(self) # Keyboard actions self.keyboard = keyboardActions(self, keyboard) # Setting up screen if self.alpha: self.Screen = pygame.surface.Surface(window.size(), pygame.SRCALPHA) else: self.Screen = pygame.surface.Surface(window.size()) # Get background image self.seperateBackground = seperateBackground self.bg_image = Images([self.name], (0, 0)) self.loadBackground() # Load surfaces self.loaded = [] self.containerList = [] if surfaces != None: for name, surfaceData in surfaces.items(): self.addSurface(name, surfaceData) self.load(withSurfaces=firstLoad, refresh=True) # Adding to data of all screen screens.add(self.name, self)
def __init__(self, surface: Surface, name: str, type: str, frame: Frame, imageData: dict = None, overlayDataFrame: bool = False, data: dict = None, selectable: bool = True, state: str = '', action: any = None, lock_state: bool = False, clickSound: sound = sound.button_click): self.surface = surface self.name = name self.selectable = selectable self.type = str(type) self.frame = frame self.state = state self.action = action self.lock_state = lock_state self.overlayDataFrame = overlayDataFrame self.clickSound = clickSound # Get images if imageData != None: self.images = Images(**imageData, imagePage=[ surface.screen.name, surface.name, name ]) # If no image loaded if self.images.containerList == []: logger.warn('[{}] No image found for {} item.'.format( self.surface.name, self.name)) # No image defined for item else: self.images = None # Store data self.loaded = False self.containerList = [] if data != None: for name, dataData in data.items(): self.addData(name, dataData)
def __init__(self): super().__init__(name="sort") self\ .addSurface( Surface( name="back", type_="button", frame=Frame(x=71, y=41, w=112, h=61), actions=[Runclass(self.switchScreen, "back")] ) .addData("image", Images(None, Frame(x=71, y=41, w=112, h=61))) )\ .addSurface( Surface( name="info", type_="button", frame=Frame(x=841, y=41, w=112, h=61), actions=[] ) .addData("image", Images(None, Frame(x=841, y=41, w=112, h=61))) )\ .addSurface( Surface( name="stats", type_="container", frame=Frame(x=223, y=606, w=752, h=133), selectable=False, actions=[] ) .addData("image", Images(None, Frame(x=223, y=606, w=752, h=133))) .addData("speed", Text( frame=Frame(x=349, y=630, w=254, h=40), text="0", suffix=" swaps per sec", format_=TextFormat(fontSize=28, pos="center", warpText=48) )) .addData("moves", Text( frame=Frame(x=436, y=677, w=167, h=40), text="0", format_=TextFormat(fontSize=28, pos="center", warpText=48) )) .addData("time", Text( frame=Frame(x=768, y=630, w=177, h=40), text="0.00", suffix=" sec", format_=TextFormat(fontSize=28, pos="center", warpText=48) )) .addData("length", Text( frame=Frame(x=759, y=677, w=186, h=40), text="0", format_=TextFormat(fontSize=28, pos="center", warpText=48) )) )\ .addSurface( Surface( name="sortbox", type_="container", frame=Frame(x=52, y=145, w=922, h=430), selectable=False, actions=[] ) .addData("image", Images(None, Frame(x=52, y=145, w=922, h=430))) .addChild( Surface( name="rerun", type_="button", frame=Frame(x=906, y=521, w=68, h=55), selectable=False, actions=[] ) .addData("image", Images(None, Frame(x=906, y=521, w=68, h=55))) ) )
def __init__(self): super().__init__(name="home") self\ .addSurface( Surface( name="type", type_="button", frame=Frame(x=246, y=149, w=729, h=70), actions=[] ) .addData("image", Images(None, Frame(x=246, y=149, w=729, h=70))) .addData("text", Text( frame=Frame(x=271, y=159, w=628, h=53), text="Insertion sort", format_=TextFormat(fontSize=38, pos="center") )) )\ .addSurface( Surface( name="info", type_="button", frame=Frame(x=225, y=242, w=751, h=211), actions=[] ) .addData("image", Images(None, Frame(x=225, y=242, w=751, h=211))) .addData("text", Text( frame=Frame(x=252, y=260, w=695, h=168), text="Bubble sort, is one of the most simplest sorting algorithm that repeatedly steps through the list, compares adjacent pairs and swaps them if they are in the wrong order.", format_=TextFormat(fontSize=31, pos="center", warpText=48) )) )\ .addSurface( Surface( name="speed", type_="button", frame=Frame(x=271, y=480, w=704, h=70), actions=[] ) .addData("image", Images(None, Frame(x=271, y=480, w=704, h=70))) .addData("text", Text( frame=Frame(x=296, y=490, w=654, h=53), text="100.0", suffix=" swaps per sec", format_=TextFormat(fontSize=38, pos="center") )) )\ .addSurface( Surface( name="length", type_="button", frame=Frame(x=403, y=575, w=572, h=70), actions=[] ) .addData("image", Images(None, Frame(x=403, y=575, w=572, h=70))) .addData("text", Text( frame=Frame(x=428, y=585, w=522, h=53), text="10", suffix=" bars", format_=TextFormat(fontSize=38, pos="center") )) )\ .addSurface( Surface( name="run", type_="button", frame=Frame(x=781, y=671, w=194, h=70), actions=[Runclass(self.switchScreen, "load", "sort")] ) .addData("image", Images(None, Frame(x=781, y=671, w=194, h=70))) )