Skip to content

Commit

Permalink
Merge branch 'master' into add_optionscontainer_abilities
Browse files Browse the repository at this point in the history
  • Loading branch information
saroad2 committed Nov 29, 2020
2 parents 55dc1d9 + caa0e10 commit d0c3974
Show file tree
Hide file tree
Showing 11 changed files with 951 additions and 71 deletions.
11 changes: 10 additions & 1 deletion examples/multilinetextinput/multilinetextinput/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def enable_toggle_pressed(self, widget, **kwargs):
def readonly_toggle_pressed(self, widget, **kwargs):
self.multiline_input.readonly = not self.multiline_input.readonly

def add_content_pressed(self, widget, **kwargs):
self.multiline_input.value = "All work and no play makes Jack a dull boy... " * 100

def clear_pressed(self, widget, **kwargs):
self.multiline_input.clear()

Expand Down Expand Up @@ -41,6 +44,11 @@ def startup(self):
on_press=self.readonly_toggle_pressed,
style=Pack(flex=1)
)
button_add_content = toga.Button(
'Add content',
on_press=self.add_content_pressed,
style=Pack(flex=1)
)
button_clear = toga.Button(
'Clear',
on_press=self.clear_pressed,
Expand All @@ -50,7 +58,8 @@ def startup(self):
children=[
button_toggle_enabled,
button_toggle_readonly,
button_clear
button_add_content,
button_clear,
],
style=Pack(
direction=ROW,
Expand Down
32 changes: 11 additions & 21 deletions examples/textinput/textinput/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import re
from string import ascii_lowercase, ascii_uppercase, digits

import toga
from toga.constants import COLUMN
from toga.style import Pack
from toga import validators

EMPTY_PASSWORD = 'Empty password'

Expand Down Expand Up @@ -71,18 +71,25 @@ def startup(self):
self.password_input = toga.PasswordInput(
placeholder='Password...',
style=Pack(padding=10),
on_change=self.on_password_change
on_change=self.on_password_change,
validators=[
validators.MinLength(10),
validators.ContainsUppercase(),
validators.ContainsLowercase(),
validators.ContainsSpecial(),
validators.ContainsDigit()
]
)
self.email_input = toga.TextInput(
placeholder='Email...',
style=Pack(padding=10),
validator=self.validate_email
validators=[validators.Email()]
)
self.number_input = toga.NumberInput(style=Pack(padding=10))
btn_extract = toga.Button(
'Extract values',
on_press=self.do_extract_values,
style=Pack(flex=1)
style=Pack(flex=1),
)

# Outermost box
Expand Down Expand Up @@ -131,23 +138,6 @@ def get_password_content_label(self, content):
contains.add("special characters")
return "Password contains: {}".format(', '.join(contains))

@classmethod
def validate_email(cls, value):
if value == "":
return
split_email = value.split("@")
email_parts = len(split_email)
if email_parts == 1:
return 'No "@" in address'
if email_parts >= 3:
return 'Too many "@" symbols in address'
name, domain = split_email
if not re.match(r"[A-Za-z][A-Za-z0-9\-.]*", name):
return 'Email name is invalid'
if not re.match(r"[A-Za-z][A-Za-z0-9\-.]*", domain):
return 'Email domain is invalid'
return


def main():
return TextInputApp('TextInput', 'org.beeware.widgets.textinput')
Expand Down
4 changes: 4 additions & 0 deletions src/cocoa/toga_cocoa/widgets/passwordinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def textDidChange_(self, notification) -> None:
if self.interface.on_change:
self.interface.on_change(self.interface)

@objc_method
def textShouldEndEditing_(self, textObject) -> bool:
return self.interface.validate()


class PasswordInput(TextInput):
def create(self):
Expand Down
Loading

0 comments on commit d0c3974

Please sign in to comment.