def __init__(self, width, height): Surface.__init__(self, (width, height)) font.init() self.dir_path = path.dirname(path.realpath(__file__)) self.assets_path = path.join(self.dir_path, 'Assets') self.fonts_path = path.join(self.assets_path, 'Fonts') self.rssTree = None self.width = width self.height = height self.today = None self.fill((255, 255, 255)) self.titleBar_textOffset = (0, -2) self.titleBar_heightRatio = .4 self.titleBar_bgColor = (39,40,34) self.titleBar_textColor = (186, 111, 23) self.titleBar_font = ('OpenSans-Bold.ttf', int(height * .3067)) self.titleBar_text = 'Important Academic Deadlines' self.RenderTitleBar() self.scrollBarSpeed = 5 self.scrollBar_heightRatio = 1.0 - self.titleBar_heightRatio self.scrollBar_bgColor = (242,242,242) self.scrollBar_textColor = (0,0,0) self.scrollBar_textOffset = (0, 0) self.scrollBar_font = ('OpenSans-Regular.ttf', int(height * .33333)) self.scrollBar_textSeperator = ' | ' self.scrollBar = Surface((self.width, self.height * (1.0 - self.titleBar_heightRatio))) self.scrollBar.fill(self.scrollBar_bgColor) self.scrollX1 = 0 self.scrollX2 = 0 self.UpdateContents() self.scrollBar.convert()
def __init__(self): scrsize = self.w, self.h = display.get_surface().get_size() Surface.__init__(self, scrsize) self.foo = 0 self.l0 = [] self.l1 = [] self.l2 = []
def __init__(self, line, surf_w, justify): # renders a line (list of tokens) # accepts a line (list of tokens), width of line, and justification # returns Surface object with the tokens justified upon it given the # justify argument self.line = line self.links = defaultdict(list) links = self.links scale_token = _scale_token # get the line width, line height, whitespace used in the line, and # freespace remaining in the line line_w = sum(token.get_width() for token in line) line_h = max(token.get_height() for token in line) total_whitespace = sum(token.get_width() for token in line if token.iswhitespace) freespace = surf_w - line_w # the freespace available in the surface # initialize surface Surface.__init__(self, (surf_w, line_h)) self.set_colorkey(BLACK) # set x if justify == 'right': x = freespace elif justify == 'center': x = freespace / 2 else: x = 0 # if justified: modify whitespace widths if justify == 'justified': # the amount to stretch whitespace stretch = 1.0 + (freespace / total_whitespace) sub_w = 0 for i, token in enumerate(line): if token.iswhitespace: # replace token with a scaled token token_w = token.get_width() * stretch scale_w = int(token_w) sub_w += token_w % scale_w while sub_w > 1: sub_w -= 1 scale_w += 1 line[i] = scale_token(token, (scale_w, token.get_height())) for token in line: w, h = token.get_size() y = (line_h - h) # token y self.blit(token, (x, y)) for link in token.links: for rect in token.links[link]: # move rect to token's position in line and append to links links[link].append(rect.move(x, y)) x += w # update x with object width
def __init__(self, width, height, grid_size): Surface.__init__(self, (width, height)) self.fill(TRANSPARENT) xsize = self.get_width() / grid_size ysize = self.get_height() / grid_size for i in range(xsize): for j in range(ysize): rect = Rect(i * grid_size, j * grid_size, grid_size, grid_size) pygame.draw.rect(self, GRID_COLOR, rect, 1) self.set_colorkey(TRANSPARENT, RLEACCEL)
def __init__(self, position, size, passenger, resource_path): Surface.__init__(self, size) self.position = position self.size = size self.passenger = passenger self.text_font = font.Font(None, 15) self.passenger_surface = Surface(self.size).convert() self.rect = Rect(self.position, self.size) self.option_image = transform.scale(image.load(resource_path+"Images/option_icon.png"), (20, 20)) self.option_rect = self.option_image.get_rect()
def __init__(self, position, size, passenger, resourcePath): Surface.__init__(self, size) self.position = position self.size = size self.passenger = passenger self.textFont = font.Font(None, 15) self.passengerSurface = Surface(self.size).convert() self.rect = Rect(self.position, self.size) self.optionImage = transform.scale( image.load(resourcePath + "img/optionIcon.png"), (20, 20)) self.optionRect = self.optionImage.get_rect()
def draw_widgets(self): required_width = max([w.get_width() for w in self.widgets]) + self._padding[0] * 2 print(f'Required size: {required_width}') if required_width > self._size[0]: Surface.__init__(self, (required_width, self._size[1])) self.fill((0, 255, 0)) offset_height: int = 0 for i, widget in enumerate(self._widgets): self.blit(widget, (self._padding[0], (self._padding[1] * (i + 1)) + offset_height)) _, h = widget.get_size() offset_height += h
class _Token(Surface): # token object # links is a dictionary of link id strings keyed to the link rect on the # token # iswhitespace is a boolean indicating if the token is whitespace # str is a string representing the token content def __init__(self, (width, height), links, surfs, iswhitespace, token_str): # construct a token object # (width, height) is the width and height of the token # links is a dictionary of link id strings keyed to the link rect on the # token # surfs is a list of surfaces comprising the token # iswhitespace is a boolean indicating if the token is whitespace # token_str is a string representing the token self.links = links self.iswhitespace = iswhitespace self.str = token_str # construct Surface superclass Surface.__init__(self, (width, height)) # blit each token onto self x = 0 for surf in surfs: w, h = surf.get_size() y = height - h self.blit(surf, (x, y)) x += w
def __init__(self, width, height): Surface.__init__(self, (width, height)) self.width = width self.height = height self.fill((242, 242, 242)) # You need this if you intend to display any text font.init() self.dir_path = path.dirname(path.realpath(__file__)) self.assets_path = path.join(self.dir_path, 'Assets') # notice the 'Fonts' folder is located in the 'Assets' self.fonts_path = path.join(self.assets_path, 'Fonts') self.bcLogoFile = 'ButteCollegeLogo.png' self.welcomeTextFont = (path.join(self.fonts_path, 'OpenSans-Bold.ttf'), int(height * .3)) self.welcomeTextTop = 'Welcome to' self.welcomeTextBottom = 'the Media Center' self.Render()
def __init__(self, master=None, surface=None, **surf_kwargs): self.children = [] if not surface: self._build_surface(**surf_kwargs) else: surf_rect = surface.get_rect() Surface.__init__(surf_rect.size, masks=pygame.mask.from_surface(surface)) array = surfarray.array2d(surface) surfarray.blit_array(self, array) if not master: self.master = pygame.display.get_surface() else: self.master = master Events.__init__(self)
def __init__(self, width, height, bgColor): Surface.__init__(self, (width, height)) font.init() self.width = width self.height = height self.bgColor = bgColor self.dir_path = path.dirname(path.realpath(__file__)) self.assets_path = path.join(self.dir_path, 'Assets') self.fonts_path = path.join(self.assets_path, 'Fonts') self.fontFile = ('OpenSans-Regular.ttf', int(height * (35/125))) self.cloudFile = 'Cloud.png' self.rainFile = 'Rain.png' self.sunFile = 'Sun.png' self.black = (0,0,0) self.white = (255,255,255) self.fill(bgColor) self.w_list = [] self.Update()
def __init__(self, disp_res, fb_res, flags=HWSURFACE|DOUBLEBUF|RESIZABLE, fps=60, scale_type='pixelperfect', scale_smooth=False, bgcolor=(0,0,0)): screen = display.set_mode(disp_res, flags) Surface.__init__(self, fb_res, flags) self._scale_type = scale_type self._scale_function = transform.smoothscale if scale_smooth else transform.scale self.bgcolor = bgcolor self.compute_target_subsurf() self._update_rects = [] self._clock = time.Clock() self._fps = fps self._lag = 0 self._tdelta = 0 if FrameBuffer.instance is None: FrameBuffer.instance = self
def update_widget(self): if time.time() - self._last_refresh < self._last_refresh: return # Update data to be displayed data: str = self.refresh_data() self._last_refresh = time.time() if not isinstance(data, str): data = 'Error' bg_color = (255, 0, 0) else: bg_color = (0, 255, 0) lines = data.split('\n') render_objects = [ self._font_obj.render(line, self._font_antialias, self._font_color) for line in lines ] required_width = max(self._font_obj.size(line)[0] for line in lines) + self._padding[0] * 2 # Calculate anchor points for each line if self._align == Alignment.RIGHT: anchors = [ ( self.width - self._font_obj.size(line)[0] - self.h_padding, # x anchor self.v_padding * (i + 1) + i * self._font_size) # y anchor for i, line in enumerate(lines) ] else: anchors = [(self.h_padding, self.v_padding * (i + 1) + self._font_size) for i, line in enumerate(lines)] Surface.__init__(self, (required_width, anchors[-1][1] + self._font_size + self.v_padding)) self.fill((255, 0, 0)) self.blits(list(zip(render_objects, anchors)))
def __init__(self, piano_path, keys_path, screen_width, min_pitch: int): min_pitch //= 12 min_pitch *= 12 self.min_pitch = min_pitch keypad_octave = pg.image.load(piano_path) octave_width, octave_heigh = keypad_octave.get_width(), keypad_octave.get_height() self.octave_width = octave_width octaves = int(screen_width / octave_width) self.offset = int( (screen_width - (octave_width*octaves))/2 ) if self.offset > 0: octaves += 2 self.offset -= octave_width self.min_pitch -= 12 self.max_pitch = self.min_pitch + octaves*12 - 1 self.keypad_surface = Surface( (octaves*octave_width,octave_heigh) ) Surface.__init__(self, (octaves*octave_width,octave_heigh) ) for i in range(octaves): self.keypad_surface.blit( keypad_octave, (i*octave_width,0) ) self.blit( self.keypad_surface, (0,0) ) self.key_surfaces = [[],[]] self.key_info = [] inf = open(path.join(keys_path, 'key_info'), 'r') for i in range(12): self.key_surfaces[0].append( pg.image.load( path.join(keys_path, '0_'+ str(i)+'.png')) ) self.key_surfaces[1].append( pg.image.load( path.join(keys_path, '1_'+ str(i)+'.png')) ) line = inf.readline() self.key_info.append( literal_eval(line) ) self.rects = [] self.key_pressed = [] self.key_pressed.append({}) self.key_pressed.append({})
def __init__(self, width, height): Surface.__init__(self, (width, height)) font.init() self.dir_path = path.dirname(path.realpath(__file__)) self.assest_path = path.join(self.dir_path, 'Assets') self.fonts_path = path.join(self.assest_path, 'Fonts') self.bgColor = (15, 15, 15) self.weatherSurface = WeatherWidget(int(width * (250 / 1000)), int(height * (150 / 300)), self.bgColor) self.scheduler = BackgroundScheduler() self.scheduler.start() self.scheduler.add_job(self.weatherSurface.Update, 'interval', minutes=5) self.scheduler.add_job(self.blit, 'interval', minutes=5, seconds=2, args=(self.weatherSurface, (self.get_width() - self.weatherSurface.get_width(), 0))) # All values that can edit the sin wave clock self.sin_Length = self.get_width() # If zero it will just be a line self.sin_DotProximity = int(width * .02882882) # .5 is 1 second period self.sin_Period = .25 self.sin_Frequency = 4 self.sin_Amplitude = int(height * .166667) self.sin_YDisplacment = int(height * .25) self.sin_XDisplacment = int(width * .005) # Color for dots in the future self.sin_LnColorPrimary = (186, 111, 23) # Clolor for dots in the past self.sin_LnColorSecondary = (39, 40, 34) # Size of dots self.sin_LnRadius = int(height * (30 / 740)) self.sin_SecondsDotRadius = int(height * (30 / 740)) self.sin_SecondsYDisplacment = int(height * -.06667) self.sin_SecondsXDisplacment = int(width * -.055) self.fill(self.bgColor) # FONTS self.secondsFont = font.Font( path.join(self.fonts_path, '1979_dot_matrix.ttf'), int(height * .08)) self.dateFont = font.Font( path.join(self.fonts_path, 'OpenSans-Regular.ttf'), int(height * .25)) self.timeFont = font.Font( path.join(self.fonts_path, 'OpenSans-Regular.ttf'), int(height * .25)) self.fontColor = (242, 242, 242) self.previousSec = int(time.time() % 60) self.previousTime = time.strftime('%I:%M %p') self.previousDate = time.strftime('%a, %b %d') self.dateSurfaceXYOffset = (int(width * .01), int(height * -.05)) self.timeSurfaceXYOffset = (int(width * .008), int(height * .2)) self.secondsSurface = self.secondsFont.render(str(self.previousSec), True, self.fontColor) self.dateSurface = self.dateFont.render(str(self.previousDate), True, self.fontColor) self.timeSurface = self.timeFont.render(str(self.previousTime), True, self.fontColor) self.blit(self.weatherSurface, (self.get_width() - self.weatherSurface.get_width(), 0)) self.convert()
def __init__ (self, size): Surface.__init__(self, size) self.fill((50,50,50))
def __init__ (self, width, height, alpha=255): Surface.__init__ (self, (width, height), SRCALPHA, 32) self._alpha = 255 self._step = -1 self.set_alpha (alpha)
def __post_init__(self): Surface.__init__(self, (self._size))
def __post_init__(self): Surface.__init__(self, self._size) self._font_obj = font.SysFont(self._font, self._font_size)
def _build_surface(self, width, height, flags=pygame.SRCALPHA, depth=32): Surface.__init__(self, (width, height), flags, depth)
def __init__(self, width, height): Surface.__init__(self, (width, height)) self.width = width self.height = height # You need this if you intend to display any text font.init() self.scheduler = BackgroundScheduler() self.scheduler.start() # These are the folders we will use for images and fonts self.dir_path = path.dirname(path.realpath(__file__)) self.assets_path = path.join(self.dir_path, 'Assets') # notice the 'Fonts' folder is located in the 'Assets' self.fonts_path = path.join(self.assets_path, 'Fonts') # Change this when done testing ---- # Information specific to semester, building, and campus. # These are most often used by the BCScheduleCreator module to fill in web forms. # The same forms you would see if you went to http://searchclasses.butte.edu/ self.location = 'Main Campus' self.building = 'MC' self.term = '' # The relative location of the files containing the raw class data. self.scheduleFile = 'scheduleData.json' # This file is a compilation of Subjects in the 'MC' building. The greatly shortens # the amount of time required to update the json file. self.compiledSubjectsFile = 'subjectsIn_MC.txt' self.backgroundImageFile = 'MapBG.png' self.backgroundImage = image.load( path.join(self.assets_path, self.backgroundImageFile)) self.backgroundImage = transform.smoothscale(self.backgroundImage, (self.width, self.height)) self.backgroundImage.convert_alpha() # This defines the time after a class starts that it will still be displayed. # Ex: TimeSlot ends at 10:00, it will be visable until 10:00 + however miniutes. self.timeSlotDisplayBuffer = 8 # Holds All Surfaces that are displayed, and normally the very next one to be displayed after the # next update. self.classesSurfacesAndTimes = [] # Flag tells object to no longer update screen because nothing has changed. self.noMoreClassesFlag = False # Called by LoadTodaysClasses() self.todaysClasses = [] # Called by Load TodaysTimeSlots() self.todaysTimeSlots = [] self.timeSlotFont = (path.join(self.fonts_path, 'OpenSans-CondBold.ttf'), int(height * .03425)) # Max number of classes that should be displayed at once. self.scheduleDisplay_numberOfClasses = 20 # Shot letter-number phrase before the class title. self.classSurface_classCodeFont = (path.join(self.fonts_path, 'OpenSans-Bold.ttf'), int(height * .02877)) # Distance between classCode and roomNumber in pixels. self.classSurface_classCodeLeftBuffer = int(width * .01580) self.classSurface_classTitleFont = (path.join(self.fonts_path, 'OpenSans-Regular.ttf'), int(height * .02740)) # Distance between classTitle and classCode in pixels. self.classSurface_classTitleLeftBuffer = int(width * .18167) self.classSurface_classInstructorFont = (path.join( self.fonts_path, 'OpenSans-Regular.ttf'), int(height * .01370)) # These can be removed, then we can just put (int(width/height * 1111)) where ever they end up in the code. self.classSurface_widthBuffer = int(width * .0158) self.classSurface_heightBuffer = int(height * .00411) self.classSurface_bgColors = ((242, 242, 242), (255, 255, 255)) self.classSurface_roomNumberFont = (path.join(self.fonts_path, 'OpenSans-CondBold.ttf'), int(height * .04110)) self.classSurface_floorSurface_widthRatio = .15 self.classSurface_floorSurface_buffer = (0, 0) self.scheduler.add_job(CompileSubjectsInBuilding, 'cron', id='CompileSubjects01', day_of_week='mon-fri', hour=1, args=[ self.building, self.term, self.location, path.join(self.dir_path, self.compiledSubjectsFile) ]) self.scheduler.add_job(self.UpdateJson, 'cron', id='UpdateJson01', day_of_week='mon-fri', hour=2) self.scheduler.add_job(self.LoadTodaysClasses, 'cron', id='LoadTodaysClasses01', day_of_week='mon-fri', hour=2, minute=30) self.scheduler.add_job(self.LoadTodaysTimeSlots, 'cron', id='LoadTodaysTimeSlots01', day_of_week='mon-fri', hour=2, minute=35) self.InitializeJsonData() self.LoadTodaysClasses() self.LoadTodaysTimeSlots()
def __init__(self, size): Surface.__init__(self, size) self.image = image.load(resources.BGFILE) self.blit(self.image, (0, 0))
def __init__(self, width, height, alpha=255): Surface.__init__(self, (width, height), SRCALPHA, 32) self._alpha = 255 self._step = -1 self.set_alpha(alpha)
def __init__(self, dim, relXOff, relYOff): Surface.__init__(self, dim, SRCALPHA) self.xOff = glob.Screen.WIDTH * 0.5 + relXOff self.yOff = glob.Screen.HEIGHT * 0.5 + relYOff