def _load_default_font(self): """ Load a default font. """ default_font_res = FontResource( font_id=self.default_font.idx, size=self.default_font.size, style={ 'bold': False, 'italic': False }, location=(PackageResource( package='pygame_gui.data', resource=self.default_font.regular_file_name), False)) error = default_font_res.load() if error is not None: warnings.warn(str(error)) self.loaded_fonts[self.default_font.idx] = default_font_res self.known_font_paths[self.default_font.name] = [ (PackageResource(package='pygame_gui.data', resource=self.default_font.regular_file_name), False), (PackageResource(package='pygame_gui.data', resource=self.default_font.bold_file_name), False), (PackageResource(package='pygame_gui.data', resource=self.default_font.italic_file_name), False), (PackageResource(package='pygame_gui.data', resource=self.default_font.bold_italic_file_name), False) ]
def _load_fonts(self): """ Loads all fonts specified in our loaded theme. """ for element_key in self.ui_element_fonts_info: font_info = self.ui_element_fonts_info[element_key] if 'regular_path' in font_info: regular_path = font_info['regular_path'] self.font_dictionary.add_font_path( font_info['name'], regular_path, font_info.get('bold_path', None), font_info.get('italic_path', None), font_info.get('bold_italic_path', None)) elif 'regular_resource' in font_info: bold_resource = None italic_resource = None bld_it_resource = None reg_res_data = font_info['regular_resource'] regular_resource = PackageResource( package=reg_res_data['package'], resource=reg_res_data['resource']) if 'bold_resource' in font_info: bold_res_data = font_info['bold_resource'] bold_resource = PackageResource( package=bold_res_data['package'], resource=bold_res_data['resource']) if 'italic_resource' in font_info: italic_res_data = font_info['italic_resource'] italic_resource = PackageResource( package=italic_res_data['package'], resource=italic_res_data['resource']) if 'bold_italic_resource' in font_info: bld_it_res_data = font_info['bold_italic_resource'] bld_it_resource = PackageResource( package=bld_it_res_data['package'], resource=bld_it_res_data['resource']) self.font_dictionary.add_font_path(font_info['name'], regular_resource, bold_resource, italic_resource, bld_it_resource) font_id = self.font_dictionary.create_font_id( font_info['size'], font_info['name'], font_info['bold'], font_info['italic']) if font_id not in self.font_dictionary.loaded_fonts: self.font_dictionary.preload_font(font_info['size'], font_info['name'], font_info['bold'], font_info['italic']) self.ele_font_res[ element_key] = self.font_dictionary.find_font_resource( font_info['size'], font_info['name'], font_info['bold'], font_info['italic'])
def _load_default_theme_file(self): """ Loads the default theme file, either from the file directly or from string data if we have been turned into an exe by a program like PyInstaller. """ if USE_IMPORT_LIB_RESOURCE: self.load_theme( PackageResource('pygame_gui.data', 'default_theme.json')) elif USE_FILE_PATH: self.load_theme(THEME_PATH) elif USE_STRINGIFIED_DATA: self.load_theme( io.StringIO( base64.standard_b64decode(default_theme).decode("utf-8")))
def _load_image_resource(self, res_data): resource_id = (str(res_data['package']) + '/' + str(res_data['resource'])) if resource_id in self.image_resources: image_resource = self.image_resources[resource_id] else: package_resource = PackageResource(res_data['package'], res_data['resource']) image_resource = ImageResource(resource_id, package_resource) if self._resource_loader.started(): error = image_resource.load() if error is not None: warnings.warn(str(error)) else: self._resource_loader.add_resource(image_resource) self.image_resources[resource_id] = image_resource return image_resource
def _load_images(self): """ Loads all images in our loaded theme. """ for element_key in self.ui_element_image_locs: image_ids_dict = self.ui_element_image_locs[element_key] if element_key not in self.ui_element_image_surfaces: self.ui_element_image_surfaces[element_key] = {} for image_id in image_ids_dict: image_resource_data = image_ids_dict[image_id] if image_resource_data['changed']: if 'package' in image_resource_data and 'resource' in image_resource_data: resource_id = (str(image_resource_data['package']) + '/' + str(image_resource_data['resource'])) if resource_id in self.image_resources: image_resource = self.image_resources[resource_id] else: package_resource = PackageResource( package=image_resource_data['package'], resource=image_resource_data['resource']) if USE_IMPORT_LIB_RESOURCE: image_resource = ImageResource( image_id=resource_id, location=package_resource) else: image_resource = ImageResource( image_id=resource_id, location=package_resource.to_path()) self._resource_loader.add_resource(image_resource) self.image_resources[resource_id] = image_resource elif 'path' in image_resource_data: resource_id = image_resource_data['path'] if resource_id in self.image_resources: image_resource = self.image_resources[resource_id] else: image_resource = ImageResource( image_id=resource_id, location=image_resource_data['path']) self._resource_loader.add_resource(image_resource) self.image_resources[resource_id] = image_resource else: raise warnings.warn('Unable to find image with id: ' + str(image_id)) if image_resource is not None: if 'sub_surface_rect' in image_resource_data: surface_id = ( image_resource.image_id + str(image_resource_data['sub_surface_rect'])) if surface_id in self.surface_resources: surf_resource = self.surface_resources[ surface_id] else: surf_resource = SurfaceResource( image_resource=image_resource, sub_surface_rect=image_resource_data[ 'sub_surface_rect']) self.surface_resources[ surface_id] = surf_resource self._resource_loader.add_resource( surf_resource) else: surface_id = image_resource.image_id if surface_id in self.surface_resources: surf_resource = self.surface_resources[ surface_id] else: surf_resource = SurfaceResource( image_resource=image_resource) self.surface_resources[ surface_id] = surf_resource surf_resource.surface = surf_resource.image_resource.loaded_surface self.ui_element_image_surfaces[element_key][ image_id] = surf_resource
def _load_default_theme_file(self): """ Loads the default theme file. """ self.load_theme( PackageResource('pygame_gui.data', 'default_theme.json'))