def draw_drop_down(self): if self.__is_drop_down_pressed: self.__size_content.clear() for pos in range(self.__size_counter, len(DisplaySettings.SCREEN_SIZES), 1): if (pos - self.__size_counter) < 3: rect = pg.Rect( (self.size_select.x, int(self.size_select.y + self.size_select.height * ((pos - self.__size_counter) + 1))), self.size_select.size) font = pg.font.Font( Themes.DEFAULT_THEME.get("text_font_style"), int(self.size_select.height * 0.6)) txt = font.render( DisplaySettings.get_size_name( DisplaySettings.get_size_by_id(pos)), True, Themes.DEFAULT_THEME.get("text_area_text")) rect_txt = txt.get_rect() rect_txt.center = rect.center self.__size_content.append([rect, txt, rect_txt]) for i in range(0, len(self.__size_content), 1): pg.draw.rect(self.display, Themes.DEFAULT_THEME.get("text_area_background"), self.__size_content[i][0], 0) self.display.blit(self.__size_content[i][1], self.__size_content[i][2])
def set_configurations(cls): cfgs = dict() if not os.path.exists(ConfigManager.CONFIG_PATH): ConfigManager.LOGGER.error("Configuration file not found...") ConfigManager.LOGGER.info( "Generating default configuration file...") ConfigManager.generate_default_configuration() with open(ConfigManager.CONFIG_PATH, 'r') as json_cfg: cfg = json.load(json_cfg) # LOADING CONFIGURATIONS # TRY to find custom settings try: ConfigManager.LOGGER.info( "Loading custom configuration settings...") cfgs["screen"] = [ cfg["CUSTOM"]["SIZE"]["WIDTH"], cfg["CUSTOM"]["SIZE"]["HEIGHT"] ] cfgs["lang"] = cfg["CUSTOM"]["LANGUAGE"] cfgs["theme"] = cfg["CUSTOM"]["THEME"] except KeyError as ex: ConfigManager.LOGGER.error("Custom configurations not found") ConfigManager.LOGGER.info("Loading default configurations...") cfgs["screen"] = [ cfg["DEFAULT"]["SIZE"]["WIDTH"], cfg["DEFAULT"]["SIZE"]["HEIGHT"] ] cfgs["lang"] = cfg["DEFAULT"]["LANGUAGE"] cfgs["theme"] = cfg["DEFAULT"]["THEME"] DisplaySettings.set_size_by_key( DisplaySettings.get_size_name(cfgs.get("screen"))) StringUtils.set_language(cfgs.get("lang")) # LANGUAGE Themes.set_theme(cfgs.get("theme")) # THEME
def check_menu_pressed(self, pos): if self.__is_drop_down_pressed: for i in range(0, len(self.__size_content), 1): if self.__size_content[i][0].collidepoint(pos) == 1: self.__size = DisplaySettings.get_size_name( DisplaySettings.get_size_by_id(i + self.__size_counter)) self.__is_drop_down_pressed = False self.__selected = True
def __init__(self, display, coords=None, size=None): Form.__init__(self, display, coords, size) self.size_select = None self.btn_drop_down = None self.__size = DisplaySettings.get_size_name() self.__size_content = list() self.__size_counter = 0 self.__is_drop_down_pressed = False self.__selected = False
def check_form_events(self, event): super().check_form_events(event) if event.type == MOUSEBUTTONUP: if event.button != 4 and event.button != 5: pos = pg.mouse.get_pos() self.check_menu_pressed(pos) if self.btn_drop_down.collidepoint(pos) == 1: if self.__is_drop_down_pressed: self.__is_drop_down_pressed = False else: self.__is_drop_down_pressed = True self.__size_counter = 0 elif self.btn_apply.get_rect().collidepoint(pos) == 1: for i in range(0, len(DisplaySettings.SCREEN_SIZES), 1): if self.__size == DisplaySettings.get_size_name( DisplaySettings.get_size_by_id(i)): DisplaySettings.set_size_by_key( DisplaySettings.get_size_name( DisplaySettings.get_size_by_id(i))) self.display = pg.display.set_mode( DisplaySettings.DEFAULT_SCREEN_SIZE) else: self.__is_drop_down_pressed = False elif event.type == MOUSEBUTTONDOWN: if self.__is_drop_down_pressed: if event.button == 4: self.__size_counter -= 1 elif event.button == 5 and len( DisplaySettings.SCREEN_SIZES) > 3: self.__size_counter += 1 if self.__size_counter < 0: self.__size_counter = 0 elif (len(DisplaySettings.SCREEN_SIZES) > 3) and (self.__size_counter > len(DisplaySettings.SCREEN_SIZES) - 3): self.__size_counter = (len(DisplaySettings.SCREEN_SIZES) - 3)