When i use below pywinauto code, i am getting error saying
from pywinauto.controls.win32_controls import ButtonWrapper
checkbox = ButtonWrapper(app.Dialog.child_window(title='Has Balance',auto_id='HasBalanceCheckEdit',control_type='CheckBox').TCheckBox.WrapperObject())
print(checkbox.GetCheckState())
Error:
raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find 'TCheckBox' in 'dict_keys(['Has Balance', 'Has BalanceStatic', 'Static'])'
Based on the output you provided, next level spec TCheckBox is not needed. Just use this code:
checkbox = app.Dialog.child_window(title='Has Balance', auto_id='HasBalanceCheckEdit', control_type='CheckBox').wrapper_object()
Explicit ButtonWrapper instantiation is also not necessary because the control type is already auto detected by .wrapper_object(). That's why control_type='CheckBox' in your child_window can find the control.
used import pywinauto.controls.uia_controls to resolve the above code.
Related
I am currently writing a web-application and need to "refresh the page" by clearing the cache. So the user should be able to refresh the page. For this reason I created a button with the following statement in it st.legacy_caching.caching.clear_cache(). However, even I have the most updated version (1.12.0) I get the following error "module 'streamlit' has no attribute 'legacy_caching'"
my code looks like this
#st.cache(allow_output_mutation=True, suppress_st_warning=True)
def load_General():
engine = sa.create_engine("mssql+pyodbc:///?odbc_connect={}".format(params))
con=engine.connect()
general_query_raw='''string'''
General_raw=pd.read_sql(general_query_raw,con)
general_query_cleansed='''string'''
General_cleansed=pd.read_sql(general_query_cleansed,con)
return General_raw, General_cleansed
#st.cache(allow_output_mutation=True,suppress_st_warning=True)
def load_Role():
engine = sa.create_engine("mssql+pyodbc:///?odbc_connect={}".format(params))
con=engine.connect()
role_query_raw='''string'''
Role_raw=pd.read_sql(role_query_raw,con)
role_query_cleansed='''string'''
Role_cleansed=pd.read_sql(role_query_cleansed,con)
return Role_raw,Role_cleansed
With the following line(s) I try to clean the cache in order to be able to get the latest data from the DB
def clear_cache():
st.legacy_caching.caching.clear_cache()
st.sidebar.button("Refresh Program",on_click=clear_cache)
Any Idea what could help me here?
I had come across a similar issue recently, instead of creating a button to clear the cache you can use the st.empty() function that should clear the cache.
Just call as below before calling your defined functions:
load_general = st.empty()
load_role = st.empty()
load_general = load_General()
load_role = load_Role()
https://docs.streamlit.io/library/api-reference/layout/st.empty
Okay so I'm programming a Wolfram Alpha API and I added a res string with query and its giving me this error: AttributeError: 'str' object has no attribute 'query'
Here's the PyDa.py:
import PySimpleGUI as sg
sg.theme('Dark Blue')
app_id = ('API_key')
client = (app_id)
layout = [ [sg.Text("Hello, my name's Ted. What's your question?")],
[sg.Input()],
[sg.Button('Ok'), sg.Button('Cancel')] ]
window = sg.Window('Ted', layout)
while True:
event, values = window.read()
if event in (None, 'Cancel'):
break
res = client.query(values[0])
print(next(res.results).text)
window.close()
where values[0] is what the user enters. I've tried completely deleting query and it doesn't work. I thing I need to install something but when I try pip install wolframalpha api it does install but that's not whats missing/ is wrong. I should be getting pods but its not sending those because of the error.
Hmm, I don't know exactly what happens before the client.query call, but the AtrributeError says client is of type str. I don't think there is a problem with dependencies, because then the error would be different. The client is according to the docs defined with client = Client(getfixture('API_key')). If you have this in your code, then I have no idea what's wrong.
In pywinauto I am trying to access a nested submenue item that contains.
The Path is Datei->Importieren->Vorlagen->comdirect Musterdepot (attached screenshot)
Any idea how I can get this running?
The code I use:
app = Application(backend = 'uia').connect(path = "PortfolioPerformance.exe")
app.Dialog.Anwendungsmenü.item_by_path('Datei->Importieren->Vorlagen->comdirect Musterdepot').click_input()
The error I receive:
AttributeError: 'NoneType' object has no attribute 'is_active'
Screenshot of Menu:
After spending some time I figured out the following behaviour:
Once I expanded the Datei Menu, the print_control_identifiers updated to include the submenues.
The following code will click the correct, but maybe there are nicer solutions out there:
app = Application(backend = 'uia').connect(path = PROCNAME)
dialog = app.dialog
#first open the Importieren submenu:
dialog.Anwendungsmenü.item_by_path('Datei->Importieren')
# then the submenue appears on top level menues, open the importieren menu:
dialog["Importieren"].item_by_path('Vorlagen->comdirect Musterdepot').select()
I am using Odoo 11 and I want to display a Warning popup in a #api.constraint method. The warning popup that I want to display has two buttons, the first is an OK button used to ignore the warning and the other one is a Cancel button used to attempt the saving operation, it' s similar to the warning popup that odoo uses like on the picture below :
I searched a lot on the web and I found different proposed solutions like using Wizard, exception.Warning() and osv.except_osv(), but unfortunately no one of this solution gives me exactly what I want.
Any help please?
You can raise warning message by different ways. I have created message related to stock quantity by this way:
if self.qty > new_qty:
message = _('You plan to sell %s quantity but you only have %s available in %s warehouse.') % \
(self.qty, self.product_id.virtual_available, self.order_id.warehouse_id.name)
mess= {
'title': _('Not enough inventory!'),
'message' : message
}
return {'warning': mess}
This return same wizard of warning as you want and as shown given image.
The basic odoo Warning that you can use is called from the odoo.exception class.
For example:
from odoo.exceptions import AccessError, UserError, RedirectWarning, ValidationError, Warning
#api.constrains('age')
def _check_something(self):
for record in self:
if record.age > 20:
raise Warning(_("Your record is too old: %s" % record.age))
This should work for your issue.
I write a (draft) module to open Dialog box see:
https://github.com/Micronaet/micronaet-sales/tree/master/confirm_dialog_wizard
In your button you can write this code to open, for ex. to hide a product:
#api.multi
def hide_product_pricelist(self):
""" Hide product
"""
return self.env['dialog.box.wizard'].open_dialog(
message='The product will be hided, <b>you cannot use again</b> '
'but remain in sale order where yet present, <br/>'
'confirm?',
action='self.env["product.product"].browse(%s).write('
'{"active": False})' % self.id,
title='Confirm request:',
mode='cancel_confirm',
)
The program will pop up a window to confirm (as in tree you cannot use "confirm" message parameter), I'm try to do better but ... its a begin ... :)
It is similar to the warning shown when we use the confirm attribute on a button.
<button confirm="Reset to draft!"/>
Raising a validation error or returning a warning as dictionary did not show the Cancel button.
I'm using Plone with dexterity and I'm validating 2 related fields using the invariant decorator. Everything works but... I'd like to move the generic error message on one specific field.
How can I do this? I've found a three years old suggestion by Martin Aspeli about how it would be cool doing it:
http://plone.293351.n2.nabble.com/plone-app-form-does-not-display-invariant-errors-td348710.html
but they dont came out with a solution.
I've also found a way to do it but it's ugly: placing on the update method of the form this code:
for widget in widgets:
name = widget.context.getName()
if errors:
for error in errors:
if isinstance(error, Invalid) and name in error.args[1:]:
if widget._error is None:
widget._error = error
Isn't there a lower level implementation that allows to pass the names of the fields to the raised Invalid and does not need to loop trough all the fields and all the errors for each field?!?
You can do this by doing your extra validation in the form's action handler, and raise WidgetActionExecutionError specifying the widget for which the error should be shown.
This looks as follows (taken from http://plone.org/products/dexterity/documentation/manual/schema-driven-forms/customising-form-behaviour/validation):
from five import grok
from plone.directives import form
from zope.interface import invariant, Invalid
from zope import schema
from z3c.form import button
from z3c.form.interfaces import ActionExecutionError, WidgetActionExecutionError
from Products.CMFCore.interfaces import ISiteRoot
from Products.statusmessages.interfaces import IStatusMessage
from example.dexterityforms.interfaces import MessageFactory as _
...
class OrderForm(form.SchemaForm):
...
#button.buttonAndHandler(_(u'Order'))
def handleApply(self, action):
data, errors = self.extractData()
# Some additional validation
if 'address1' in data and 'address2' in data:
if len(data['address1']) < 2 and len(data['address2']) < 2:
raise ActionExecutionError(Invalid(_(u"Please provide a valid address")))
elif len(data['address1']) < 2 and len(data['address2']) > 10:
raise WidgetActionExecutionError('address2', Invalid(u"Please put the main part of the address in the first field"))
if errors:
self.status = self.formErrorsMessage
return
I think it may also be possible to raise WidgetActionExecutionError from your invariant, but then it might not do what you want if the invariant is getting checked at some other time than while processing a z3c.form form.