logo
down
shadow

Passing line-edits to a contextmanager to set validators


Passing line-edits to a contextmanager to set validators

Content Index :

Passing line-edits to a contextmanager to set validators
Tag : python , By : Comfly
Date : January 11 2021, 03:34 PM

this will help A context-manager isn't the right tool for this job. Once you have the list of line-edits, all you need to do is iterate over them using a for-loop. An efficient way to generate the list is to use findChildren with a regexp. This can then be wrapped up in a local function like this:
def __init__(self, ...):
    ...
    def set_validators(pattern):
        widgets = self.findChidren(QtGui.QLineEdit, QtCore.QRegExp(pattern))    
        for widget in widgets:
            validator = QtGui.QDoubleValidator()
            validator.setDecimals(2)
            widget.setValidator(validator)

    set_validators('.*PriceLineEdit$')
    set_validators('.*OtherLineEdit$')
    ...
    def set_validators(widgets):
        for widget in widgets:
            validator = QtGui.QDoubleValidator()
            validator.setDecimals(2)
            widget.setValidator(validator)

    my_widgets = [self.ui.retailPriceLineEdit, self.ui.discountPriceLineEdit sellf.ui.onlinePriceLineEdit]

    set_validators(my_widgets)
    set_validators(other_widgets)
    ...

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Wordpress plugin to SAVE post-publish edits, without actually PUBLISHING those edits


Tag : wordpress , By : kangfoo2
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have done a lot of RnD and can conclude that Revisionary along with Role Scoper can be used for the exact purpose.

Why does my contextmanager-function not work like my contextmanager class in python?


Tag : python , By : n1ckless_id
Date : March 29 2020, 07:55 AM
I hope this helps you . The example in the documentation for contextmanager is somewhat misleading. The portion of the function after yield does not really correspond to the __exit__ of the context manager protocol. The key point in the documentation is this:
@contextlib.contextmanager
def cm():
    print "before"
    exc = None
    try:
        yield
    except Exception, exc:
        print "Exception was caught"
    print "after"
    if exc is not None:
        raise exc

>>> with cm():
...     print "Hi!"
before
Hi!
after

>>> with cm():
...     print "Hi!"
...     1/0
before
Hi!
Exception was caught
after

Wikipedia API call specifies anonymous edits only, but I get back lots of non-anon edits


Tag : json , By : ralph okochu
Date : March 29 2020, 07:55 AM
I wish this help you First of all, it “doesn't work” in the API sandbox either, you just need to use the sandbox on the English Wikipedia, not mediawiki.org.
If you look at the results closely, you'll notice that all of the non-anonymous entries have type external. That means those are edits to the Wikidata page for that article, which show as anonymous (I assume that's because the Wikidata user who made the change may not exist on the local wiki). To get rid of those edits, set rctype in your query to filter out external:

Form fields edits by Javascript fail when user edits field


Tag : javascript , By : B3CFT
Date : March 29 2020, 07:55 AM
it should still fix some issue Once you've edited a