question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

widget.Text param:validator using a function not takes the current value.

See original GitHub issue

https://github.com/peterbrittain/asciimatics/blob/4d8279a4d1fc095c6ce26b0c4fb5702992f2e268/asciimatics/widgets.py#L1592

#works
#self.text_count = Text(label="Count", validator=lambda x: True if x.isdigit() else False)

#not works
self.text_count = Text(label="Count", validator=self._valid_char)
#_valid_char, not takes any value
@staticmethod
def _valid_char(self, char):
     ...

whitout staticmethod raise an exception: TypeError: first argument must be string or compiled pattern

Is it a error?

Using: C9 IDE Python 3.5.3 (default, Apr 22 2017, 00:00:00) [GCC 4.8.4]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
peterbrittaincommented, May 4, 2018

OK! In that case, this is fixed. I’ll close the issue.

Note that your sample code for the instance method will hit a recursion error with this fix because you are setting a new value inside the validator. You don’t need to do this as the value is already set by the widget. The validator should simply check whether the current value is syntactically correct and return True/False accordingly.

1reaction
peterbrittaincommented, May 4, 2018

Hold on a sec… Do you mean that you can’t use instance methods as your validator function?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Capture the Value of a Text Widget after the Tab ...
If you want the text to be shown before the tab space and the text to be shown with the tab space after,...
Read more >
Simple ways to pass to and share data with widgets/pages
This article is going to be more practical than theoretical, I just wanted to show in a simple way, various methods to share...
Read more >
Databricks widgets | Databricks on AWS
Learn how to use input widgets that allow you to add parameters to your notebooks and dashboards.
Read more >
Interactivity in the custom widget - Amazon CloudWatch
action— Valid values are call , which calls a Lambda function, and html , which displays any HTML contained within <cwdb-action> . The...
Read more >
24.8. Methods on Text widgets
To retrieve the current value of an option set on an embedded image, call this method with an index pointing to the image...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found