def set_title(self, title): # lgtm [py/inheritance/incorrect-overridden-signature] """ Update the widget title. :param title: New title :type title: str :return: None """ self._title = to_string(title) self._apply_font() self._render() self._check_render_size_changed()
def set_title( self, title): # lgtm [py/inheritance/incorrect-overridden-signature] """ Update the widget title. :param title: New title :type title: str :return: None """ self._title = to_string(title) self._apply_font() self._last_render_hash = 0 # Force widget render self._render()
def set_title(self, title, offsetx=0, offsety=0): """ Set the Menu title. :param title: Menu title :type title: str :param offsetx: Offset x-position of title (px) :type offsetx: int, float :param offsety: Offset y-position of title (px) :type offsety: int, float :return: None """ assert isinstance(offsetx, (int, float)) assert isinstance(offsety, (int, float)) self._title = to_string(title) self._offsety = offsety self._offsetx = offsetx
def set_value(self, color): _color = '' if self._color_type == TYPE_RGB: if color == '': super(ColorInput, self).set_value('') return assert isinstance( color, tuple), 'Color in rgb format must be a tuple in (r,g,b) format' assert len(color) == 3, 'Tuple must contain only 3 colors, R,G,B' r, g, b = color assert isinstance(r, int), 'Red color must be an integer' assert isinstance(g, int), 'Blue color must be an integer' assert isinstance(b, int), 'Green color must be an integer' assert 0 <= r <= 255, 'Red color must be between 0 and 255' assert 0 <= g <= 255, 'Blue color must be between 0 and 255' assert 0 <= b <= 255, 'Green color must be between 0 and 255' _color = '{0}{3}{1}{3}{2}'.format(r, g, b, self._separator) self._auto_separator_pos = [0, 1] elif self._color_type == TYPE_HEX: text = to_string(color).strip() if text == '': _color = '#' else: # Remove all invalid chars _valid_text = '' for ch in text: if ch in self._valid_chars: _valid_text += ch text = _valid_text # Check if the color is valid count_hash = 0 for ch in text: if ch == '#': count_hash += 1 if count_hash == 1: assert text[0] == '#', 'color format must be "#RRGGBB"' if count_hash == 0: text = '#' + text assert len( text ) == 7, 'invalid color, only formats "#RRGGBB" and "RRGGBB" are allowed' _color = text super(ColorInput, self).set_value(_color)
def __init__(self, title, elements, selector_id='', default=0, onchange=None, onreturn=None, *args, **kwargs): assert isinstance(elements, list) assert isinstance(selector_id, str) assert isinstance(default, int) # Check element list _check_elements(elements) assert default >= 0, 'default position must be equal or greater than zero' assert default < len( elements), 'default position should be lower than number of values' assert isinstance(selector_id, str), 'id must be a string' assert isinstance(default, int), 'default must be an integer' super(Selector, self).__init__( title=to_string( title, strict=True ), # Cannot use unicode in py2 as selector use format widget_id=selector_id, onchange=onchange, onreturn=onreturn, args=args, kwargs=kwargs) self._elements = elements self._index = 0 # type: int self._sformat = '{0}< {1} >' # type: str self._title_size = 0.0 # type: float # Apply default item default %= len(self._elements) for k in range(0, default): self.right()
def __init__(self, title='', widget_id='', onchange=None, onreturn=None, args=None, kwargs=None): assert isinstance(widget_id, str), 'widget id must be a string' if onchange: assert is_callable(onchange), 'onchange must be callable or None' if onreturn: assert is_callable(onreturn), 'onreturn must be callable or None' # Store id, if None or empty create new ID based on UUID if widget_id is None or len(widget_id) == 0: widget_id = uuid4() self._alignment = _locals.ALIGN_CENTER self._attributes = {} # Stores widget attributes self._background_color = None self._background_inflate = (0, 0) self._events = [] # type: list self._id = str(widget_id) self._margin = (0.0, 0.0) # type: tuple self._max_width = None # type: (int,float) self._padding = (0, 0, 0, 0) # top, right, bottom, left self._selection_time = 0 # type: float self._title = to_string(title) # Widget transforms self._angle = 0 # Rotation angle (degrees) self._flip = (False, False) # x, y self._scale = [False, 1, 1, False, False] # do_scale, x, y, smooth, use_same_xy self._translate = (0.0, 0.0) # type: tuple # Widget rect. This object does not contain padding. For getting the widget+padding # use .get_rect() Widget method instead self._rect = pygame.Rect(0, 0, 0, 0) # type: pygame.Rect # Callbacks self._draw_callbacks = {} # type: dict self._update_callbacks = {} # type: dict self._args = args or [] # type: list self._kwargs = kwargs or {} # type: dict self._on_change = onchange # type: callable self._on_return = onreturn # type: callable # Surface of the widget self._surface = None # type: (pygame.Surface,None) # Menu reference self._menu = None # If this is True then the widget forces the Menu to update because the # widget render has changed self._menu_surface_needs_update = False # Modified in set_font() method self._font = None # type: (pygame.font.Font,None) self._font_antialias = True # type: bool self._font_background_color = None # type: (tuple, None) self._font_color = (0, 0, 0) # type: tuple self._font_name = '' # type: str self._font_selected_color = (255, 255, 255) # type: tuple self._font_size = 0 # type: int # Text shadow self._shadow = False # type: bool self._shadow_color = (0, 0, 0) # type: tuple self._shadow_offset = 2.0 # type: float self._shadow_position = _locals.POSITION_NORTHWEST self._shadow_tuple = None # (x px offset, y px offset) self._create_shadow_tuple() # Rendering, this variable may be used by render() method # If the hash of the variables change respect to the last render hash # (hash computed using self._hash_variables() method) # then the widget should render and update the hash self._last_render_hash = 0 # type: int # Selection effect, for avoiding exception while getting object rect, NullSelection # was created. Initially it was None self._selection_effect = _NullSelection() # type: Selection # Public attributes self.active = False # Widget requests focus self.is_selectable = True # Some widgets cannot be selected like labels self.joystick_enabled = True self.lock_position = False # If True, locks position after first call to .set_position(x,y) method self.mouse_enabled = True self.selected = False self.selection_effect_enabled = True # Some widgets cannot have selection effect self.selection_expand_background = False # If True, the widget background will inflate to match selection margin if selected self.sound = Sound() # type: Sound self.touchscreen_enabled = True self.visible = True # Use .show() or .hide() to modify this status
def __init__(self, title='', widget_id='', onchange=None, onreturn=None, args=None, kwargs=None): assert isinstance(widget_id, str) if onchange: assert callable(onchange), 'onchange must be callable or None' if onreturn: assert callable(onreturn), 'onreturn must be callable or None' # Store id, if None or empty create new ID based on UUID if widget_id is None or len(widget_id) == 0: widget_id = uuid4() self._attributes = {} # Stores widget attributes self._alignment = _locals.ALIGN_CENTER self._background_color = None self._background_inflate = (0, 0) self._events = [] # type: list self._id = str(widget_id) self._margin = (0.0, 0.0) # type: tuple self._max_width = None # type: (int,float) self._rect = pygame.Rect(0, 0, 0, 0) # type: (pygame.Rect,None) self._selected_rect = None # type: (pygame.rect.Rect,None) self._selection_time = 0 # type: float self._title = to_string(title) self._args = args or [] # type: list self._kwargs = kwargs or {} # type: dict self._on_change = onchange # type: callable self._on_return = onreturn # type: callable # Surface of the widget self._surface = None # type: (pygame.Surface,None) # Menu reference self._menu = None # If this is True then the widget forces the Menu to update because the # widget render has changed self._menu_surface_needs_update = False # Modified in set_font() method self._font = None # type: (pygame.font.Font,None) self._font_antialias = True # type: bool self._font_background_color = None # type: (tuple, None) self._font_color = (0, 0, 0) # type: tuple self._font_name = '' # type: str self._font_selected_color = (255, 255, 255) # type: tuple self._font_size = 0 # type: int # Text shadow self._shadow = False # type: bool self._shadow_color = (0, 0, 0) # type: tuple self._shadow_offset = 2.0 # type: float self._shadow_position = _locals.POSITION_NORTHWEST self._shadow_tuple = None # (x px offset, y px offset) self._create_shadow_tuple() # Rendering, this variable may be used by render() method # If the hash of the variables change respect to the last render hash # (hash computed using self._hash_variables() method) # then the widget should render and update the hash self._last_render_hash = 0 # type: int # Stores the last render surface size, updated by _check_render_size_changed() self._last_render_surface_size = (0, 0) self._selection_effect = None # type: Selection # Public attributes self.active = False # Widget requests focus self.is_selectable = True # Some widgets cannot be selected like labels self.joystick_enabled = True self.mouse_enabled = True self.selected = False self.selection_effect_enabled = True # Some widgets cannot have selection effect self.sound = Sound() # type: Sound