Skip to content

Commit 3ce1256

Browse files
author
dessant
committed
add TextInput.password_mask to customize the password placeholder
1 parent 5670cb8 commit 3ce1256

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

kivy/uix/textinput.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ def handle_readonly(instance, value):
516516
fbind('font_name', update_text_options)
517517
fbind('size', update_text_options)
518518
fbind('password', update_text_options)
519+
fbind('password_mask', update_text_options)
519520

520521
fbind('pos', self._trigger_update_graphics)
521522
fbind('readonly', handle_readonly)
@@ -1226,8 +1227,8 @@ def _update_selection(self, finished=False):
12261227
self._selection_finished = finished
12271228
_selection_text = self._get_text(encode=False)[a:b]
12281229
self.selection_text = ("" if not self.allow_copy else
1229-
(('*' * (b - a)) if self.password else
1230-
_selection_text))
1230+
((self.password_mask * (b - a)) if
1231+
self.password else _selection_text))
12311232
if not finished:
12321233
self._selection = True
12331234
else:
@@ -1709,7 +1710,8 @@ def _get_text_width(self, text, tab_width, _label_cached):
17091710
if not self.password:
17101711
width = _label_cached.get_extents(text)[0]
17111712
else:
1712-
width = _label_cached.get_extents('*' * len(text))[0]
1713+
width = _label_cached.get_extents(
1714+
self.password_mask * len(text))[0]
17131715
Cache_append('textinput.width', cid, width)
17141716
return width
17151717

@@ -2078,7 +2080,7 @@ def _create_line_label(self, text, hint=False):
20782080
# Create a label from a text, using line options
20792081
ntext = text.replace(u'\n', u'').replace(u'\t', u' ' * self.tab_width)
20802082
if self.password and not hint: # Don't replace hint_text with *
2081-
ntext = u'*' * len(ntext)
2083+
ntext = self.password_mask * len(ntext)
20822084
kw = self._get_line_options()
20832085
cid = '%s\0%s' % (ntext, str(kw))
20842086
texture = Cache_get('textinput.label', cid)
@@ -2430,14 +2432,24 @@ def _refresh_hint_text(self):
24302432
'''
24312433

24322434
password = BooleanProperty(False)
2433-
'''If True, the widget will display its characters as the character '*'.
2435+
'''If True, the widget will display its characters as the character
2436+
set in :attr:`password_mask`.
24342437
24352438
.. versionadded:: 1.2.0
24362439
24372440
:attr:`password` is a :class:`~kivy.properties.BooleanProperty` and
24382441
defaults to False.
24392442
'''
24402443

2444+
password_mask = StringProperty('*')
2445+
'''Sets the character used to mask the text when :attr:`password` is True.
2446+
2447+
.. versionadded:: 1.9.2
2448+
2449+
:attr:`password_mask` is a :class:`~kivy.properties.StringProperty` and
2450+
defaults to `'*'`.
2451+
'''
2452+
24412453
keyboard_suggestions = BooleanProperty(True)
24422454
'''If True provides auto suggestions on top of keyboard.
24432455
This will only work if :attr:`input_type` is set to `text`.

0 commit comments

Comments
 (0)