Module Auto-GUI.auto_components.titled_input_field
Expand source code
from auto_components.grid import Grid
from auto_components.grid_items import GridItems
from auto_components.input_field import InputField
from miscellaneous.colors import *
class TitledInputField:
"""An input field that is titled"""
grid = None
title_field = None
input_field = None
error_message_function = None
def __init__(self, window_type, font, input_field_default_text, title_field_text, title_field_background_color=black,
title_field_text_color=white, input_field_background_color=white, input_field_text_color=black, error_message_function=lambda text: None):
"""Initializes the object"""
self.title_field = InputField(window_type, font, title_field_text, False, background_color=title_field_background_color, text_color=title_field_text_color)
self.input_field = InputField(window_type, font, input_field_default_text, True, background_color=input_field_background_color, text_color=input_field_text_color)
self.error_message_function = error_message_function
self.grid = GridItems.vertical_grid
def place(self, **kwargs):
"""Changes the position of the this object (x, y, width, height)"""
self.grid.set_dimensions(kwargs.get("x"), kwargs.get("y"), kwargs.get("width"), kwargs.get("height"))
self.grid.turn_into_grid([self.title_field, self.input_field], None, None)
def set_text(self, text):
"""Sets the text of the InputField to the value provided if the InputField is editable"""
self.input_field.set_text(text)
def set_title(self, title):
"""Sets the title of the title InputField"""
self.title_field.set_text(title)
def get_text(self):
return self.input_field.get()
def get_error_message(self):
"""
Returns:
str: the error message if the data is invalid"""
return self.error_message_function(self.get_text())
Classes
class TitledInputField (window_type, font, input_field_default_text, title_field_text, title_field_background_color='#000000', title_field_text_color='#ffffff', input_field_background_color='#ffffff', input_field_text_color='#000000', error_message_function=<function TitledInputField.<lambda>>)
-
An input field that is titled
Initializes the object
Expand source code
class TitledInputField: """An input field that is titled""" grid = None title_field = None input_field = None error_message_function = None def __init__(self, window_type, font, input_field_default_text, title_field_text, title_field_background_color=black, title_field_text_color=white, input_field_background_color=white, input_field_text_color=black, error_message_function=lambda text: None): """Initializes the object""" self.title_field = InputField(window_type, font, title_field_text, False, background_color=title_field_background_color, text_color=title_field_text_color) self.input_field = InputField(window_type, font, input_field_default_text, True, background_color=input_field_background_color, text_color=input_field_text_color) self.error_message_function = error_message_function self.grid = GridItems.vertical_grid def place(self, **kwargs): """Changes the position of the this object (x, y, width, height)""" self.grid.set_dimensions(kwargs.get("x"), kwargs.get("y"), kwargs.get("width"), kwargs.get("height")) self.grid.turn_into_grid([self.title_field, self.input_field], None, None) def set_text(self, text): """Sets the text of the InputField to the value provided if the InputField is editable""" self.input_field.set_text(text) def set_title(self, title): """Sets the title of the title InputField""" self.title_field.set_text(title) def get_text(self): return self.input_field.get() def get_error_message(self): """ Returns: str: the error message if the data is invalid""" return self.error_message_function(self.get_text())
Class variables
var error_message_function
var grid
var input_field
var title_field
Methods
def get_error_message(self)
-
Returns
str
- the error message if the data is invalid
Expand source code
def get_error_message(self): """ Returns: str: the error message if the data is invalid""" return self.error_message_function(self.get_text())
def get_text(self)
-
Expand source code
def get_text(self): return self.input_field.get()
def place(self, **kwargs)
-
Changes the position of the this object (x, y, width, height)
Expand source code
def place(self, **kwargs): """Changes the position of the this object (x, y, width, height)""" self.grid.set_dimensions(kwargs.get("x"), kwargs.get("y"), kwargs.get("width"), kwargs.get("height")) self.grid.turn_into_grid([self.title_field, self.input_field], None, None)
def set_text(self, text)
-
Sets the text of the InputField to the value provided if the InputField is editable
Expand source code
def set_text(self, text): """Sets the text of the InputField to the value provided if the InputField is editable""" self.input_field.set_text(text)
def set_title(self, title)
-
Sets the title of the title InputField
Expand source code
def set_title(self, title): """Sets the title of the title InputField""" self.title_field.set_text(title)