MCPcopy Index your code
hub / github.com/rawpython/remi / TextInput

Class TextInput

remi/gui.py:2220–2335  ·  view source on GitHub ↗

Editable multiline/single_line text area widget. You can set the content by means of the function set_text or retrieve its content with get_text.

Source from the content-addressed store, hash-verified

2218
2219
2220class TextInput(Widget, _MixinTextualWidget):
2221 """Editable multiline/single_line text area widget. You can set the content by means of the function set_text or
2222 retrieve its content with get_text.
2223 """
2224
2225 @property
2226 @editor_attribute_decorator("WidgetSpecific",'''Defines the maximum text content length.''', int, {'possible_values': '', 'min': 0, 'max': 10000, 'default': 0, 'step': 1})
2227 def attr_maxlength(self): return self.attributes.get('maxlength', '0')
2228 @attr_maxlength.setter
2229 def attr_maxlength(self, value): self.attributes['maxlength'] = str(value)
2230 @attr_maxlength.deleter
2231 def attr_maxlength(self): del self.attributes['maxlength']
2232
2233 def __init__(self, single_line=True, hint='', *args, **kwargs):
2234 """
2235 Args:
2236 single_line (bool): Determines if the TextInput have to be single_line. A multiline TextInput have a gripper
2237 that allows the resize.
2238 hint (str): Sets a hint using the html placeholder attribute.
2239 kwargs: See Widget.__init__()
2240 """
2241 super(TextInput, self).__init__(*args, **kwargs)
2242 self.type = 'textarea'
2243
2244 self.single_line = single_line
2245 if single_line:
2246 self.style['resize'] = 'none'
2247 self.attributes['rows'] = '1'
2248 self.attributes[self.EVENT_ONINPUT] = """
2249 var elem = document.getElementById('%(emitter_identifier)s');
2250 var enter_pressed = (elem.value.indexOf('\\n') > -1);
2251 if(enter_pressed){
2252 elem.value = elem.value.split('\\n').join('');
2253 var params={};params['new_value']=elem.value;
2254 remi.sendCallbackParam('%(emitter_identifier)s','%(event_name)s',params);
2255 }""" % {'emitter_identifier': str(self.identifier), 'event_name': Widget.EVENT_ONCHANGE}
2256 #else:
2257 # self.attributes[self.EVENT_ONINPUT] = """
2258 # var elem = document.getElementById('%(emitter_identifier)s');
2259 # var params={};params['new_value']=elem.value;
2260 # remi.sendCallbackParam('%(emitter_identifier)s','%(event_name)s',params);
2261 # """ % {'emitter_identifier': str(self.identifier), 'event_name': Widget.EVENT_ONCHANGE}
2262
2263 self.set_value('')
2264
2265 if hint:
2266 self.attributes['placeholder'] = hint
2267
2268 self.attributes['autocomplete'] = 'off'
2269
2270 self.attributes[Widget.EVENT_ONCHANGE] = \
2271 "var params={};params['new_value']=document.getElementById('%(emitter_identifier)s').value;" \
2272 "remi.sendCallbackParam('%(emitter_identifier)s','%(event_name)s',params);"% \
2273 {'emitter_identifier': str(self.identifier), 'event_name': Widget.EVENT_ONCHANGE}
2274
2275 def set_value(self, text):
2276 """Sets the text content.
2277

Callers 5

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected