I'm currently updating a legacy application from Python 2.7.15 to Python 3.8.10. At the same time, I'm updating from wxPython version 2.8.12.1 to wxPython version 4.2.0.
I've used the 2to3 tool as well as done a lot of manual changes and the application is mostly running properly now. I have one major issue however, and it has to do with double-buffered drawing.
Specifically, in my onPaint() event handler, that has been bound to the EVT_PAINT event, I have the following code:
def onPaint(self,event):
drawPanelSize = self.drawPanel.GetSize()
self.bg_img = wx.Image('/background.png', wx.BITMAP_TYPE_ANY).Scale(drawPanelSize[0],
drawPanelSize[1])
bmp = wx.bitmap(self.bg_img)
dc = wx.BufferedPaintDC(self.drawPanel, bmp, wx.BUFFER_VIRTUAL_AREA)
There is more code above and below the code shown above, but this is the important area.
The problem that I am seeing is the following:
Traceback (most recent call last):
File "./TestBench.py", line 1553, in onPaint
dc = wx.BufferedPaintDC(self.drawPanel, bmp, wx.BUFFER_VIRTUAL_AREA)
wx._core.wxAssertionError: C++ assertion ""IsOk()"" failed at /tmp/pip-install-ewiqr929/wxPython/ext/wxWidgets/src/gtk/dc.cpp(238) in DoStretchBlit(): invalid DC
Does anyone have any insight into what may be going wrong here? Like I said this code worked fine using and older version of Python and an older version of wxPython. I would also accept any advice on how to appropriately debug this.
Please let me know if more information is required. I've already verified that the arguments to the function are valid. (i.e. self.drawPanel, and bmp are created properly and are valid arguments to the BufferedPaintDC method)
Also keep in mind most of the application (including the UI widgets, which are relying on gtk) is working at this point.
Things to note about my environment:
ubuntu (20:04)
gtk-3 (3.24.2)
Python (3.8.10)
wxPython (4.2.0)
Related
I'm trying to automate the mmc (snap in console) type desktop app. Where I need to expand the tree.
Try 1 -
But when I do use expand() function it generates error popup which says that "the child nodes does not exists". After this script simply stops with no error message on console unless ok button is clicked on error popup. This I suspect because when tree node expanded it triggers some event which brings child nodes under it and somehow pywinauto is not getting Childs of this node. Please note that this error popup does not come up when the step is done manually.
Try 2 -
When I tried with select() then too same behavior observed as above. It generated same error popup.
Try 3 -
I tried click() and click_input() functions and it clicks on random tree node but not on the tree node on which it is called.
The all above trials are of my application which is not public.
For reproducing this issue I have tried it on common application available on windows OS. And we can see that the 3rd is still reproducible.
Reference code -
import time
from pywinauto.application import Application
from pywinauto import Desktop
app = Application().start(r'cmd.exe /c "C:\Windows\system32\perfmon.msc"', wait_for_idle=False)
app = Application(backend="win32").connect(title='Performance Monitor', timeout=10)
main_wind = app.window(best_match='MMCMainFrame', top_level_only=False)
console_wind = main_wind.child_window(best_match="MDIClients").child_window(best_match='MMCChildFrm').child_window(class_name="MMCViewWindow")
tree = console_wind.TreeView # print_control_identifiers()
children = tree.get_item(["Performance","Data Collector Sets"]).expand().get_child("System").expand().get_child('System Diagnostics')
print(children.text())
# below line will select the System Diagnostics
children.select()
time.sleep(4)
# Below line should click on System Diagnostics but it does NOT and same happens for click() function
children.click_input()
Any help will be really helpful in knowing why this click() and click_input() clicks on random tree node and Why expand() and select() method generates the non functional error popup?
Please mention if there is concrete workaround to this.
versions -
Windows OS 10, build 20H2
Python 3.10.4
comtypes 1.1.11
pip 22.0.4
pywin32 303
pywinauto 0.6.8
setuptools 61.2.0
six 1.16.0
wheel 0.37.1
TIA..
I have referenced some stack overflow and github issue tracker as for this problem as below but nothing works.
Treeview problem
select() for TreeView items (and similar) leads error if this selection calls other dialogs etc
Python: Click by coordinate inside a window
This was all because of incorrect backend API used for snap in control application. Unfortunately my POC I did on win32 API where it worked because I was doing some initial steps manually hence the problem I was facing(explained in try1) was not there and everything was working perfectly fine.
As soon as I switched the backend to UIA it gave me different identifiers for the controls that I used previously. Now I used this identifiers and started using UIA documentation and everything started working smoothly.
Also in my investigation there is no proper way to identify the backend API for the desktop application unless you try both and figure out which works for you.
Suggestion to readers - If you are using win32 API as backend there are different api methods available for that in the documentation. and for UIA backend different. read documentation carefully.
You can try the uispy tool and find that perfmon.msc can be automated with uia
I am new to python, trying to automate powerpoint using win32com. I am unable to import or use constants in my scripts. I have ran makepy to create libraries. below is the error messages & script. Can someone tell me how to import constants ?
Script :
import win32com.client
Application =win32com.client.gencache.EnsureDispatch("PowerPoint.Application")
Presentation = Application.Presentations.Add()
Base = Presentation.Slides.Add(1, ppLayoutBlank)
Error messages :
Traceback (most recent call last):
File "ppt.py", line 14, in
Base = Presentation.Slides.Add(1, ppLayoutBlank)
NameError: name 'ppLayoutBlank' is not defined
The INTEROP method you have chosen depends on the application interface to which you are connecting.
Not defined usually means that there is no such variable, but Python more often raises NameError in such cases. So what is exactly happening here is a little unclear.
So, depends on the version of PPoint on how to communicate with it.
I advise you to use pywinauto instead and go for "brute_force", i.e. emulate key presses and/or clicks etc. on right buttons, menues etc.
Because the names of thous is little less likely to change trough out the versions than a COM interface.
Microsoft has a nasty habit of changing just a little bit the interface, and then a program stops working.
If you want to insist on win32com, you will have to read PPoint's documentation for a specific version (or Office version), and for win32com for your Python version.
You should see whether you should start a COM Client or is there some other MS tweak you need to employ.
I'm under Linux now and cannot test here, but try to
import win32com.client.constants
... and then look for the constants defined in that module.
See also How to use win32com.client.constants with MS Word?.
enter image description hereWhy does the fuction Utf8Helper::setCollatorLanguage in arangodb sdk always return false?
It is at fault ERROR ERROR in the Collator: : createInstance < > : U_FILE_ACCESS_ERRORï¼›And It's lead to failed to initialise ICU; ICU_DATA= "F:\\work_lc\\arangodb-2.6\\Build32\\bin\\..\\\\share\\arangodb\\";This project where to copy from others, it can be used, but i'm not,I just wonder what configuration file not produced
You need to make shure, ICU is able to load its locale database.
See our cookbook regarding windows compilation how to achieve this.
Please note that ArangoDB 2.6 is way out of date, and you should work with a more recent version.
More recent versions will also provide better error messages in such situations via the windows event log.
I'm trying to use Pygsr, what I'm doing wrong?
from pygsr import Pygsr
speech = Pygsr()
speech.record(3)
phrase, complete_response = speech.speech_to_text('es_ES')
print (phrase)
but I got error:
Traceback (most recent call last):
File "D:/VIV/PyCharm_project/0_WORKFILE_2.py", line 1, in <module>
from pygsr import Pygsr
File "C:\Users\User\AppData\Roaming\Python\Python35\site-packages\pygsr\__init__.py", line 30
print "REC: "
^
SyntaxError: Missing parentheses in call to 'print'
Process finished with exit code 1
The issue is that the Pygsr library seems to be written with some version of Python 2 in mind.
In Python 2, print is a statement and as such allows "softspace" in between the statement itself and the string to be printed. As of Python 3.0, print is a function and as such, requires opening and closing parentheses around the function arguments. Because Pygsr is written with some version of Python 2, it still uses the statement form of print, which is invalid in Python 3. This can be seen in the line that the SyntaxError is pointing to, which is a statement and not a function (print "REC: " vs print("REC: ")).
You've got a few options for fixing this issue:
The first option is to switch back down to using the latest version of Python 2 (which is 2.7.11 at time of writing). This will mean that anything that's not backwards compatible in 3 (but still works in 2) will function, but I don't recommend switching versions just to get a library working, especially because it will affect the code you write. As well as that, the general consensus (to the best of my knowledge) seems to be that new scripts built on 2 should use the function form of print, which is available from 2.6 onwards but can be imported from __future__ for versions before 2.6.
The second option is to use the automatic tool 2to3 to convert the scripts in the library to be compatible with 3. This won't always work 100% due to the complexity and potential edge cases that a Python script may have, but it's usually a good way to get a lot of the simpler changes out of the way quickly.
The third option is to make the changes yourself. This should be as simple as manually going through the library and fixing any references to print, but you could also find the issues by running your script, seeing which file and line number is referenced in the error and then making the required edits.
I've been trying for hours, but can't build and use Light Table. Every time I try to run deploy/LightTable, it hangs on a screen that simply says "Light Table". I receive this error*:
[14381:0519/204037:INFO:CONSOLE(27860)] "Uncaught TypeError: Cannot read property 'thread_STAR_' of undefined", source: file:///home/zaz/Desktop/LightTable/builds/lighttable-0.8.0-linux/resources/app/core/node_modules/lighttable/bootstrap.js (27860)
Here's what I've tried:
git clone https://github.com/LightTable/LightTable.git
cd LightTable
bash linux_deps.sh
./deploy/LightTable # creates frozen window, throws the error above
cd deploy
./LightTable # creates frozen window, throws the error above
./ltbin # creates frozen window, throws the error above
I also tried similar things after checking out the atom-shell branch and the 0.7.2 tag (and cleaning up all the files from the previous build). Each time, I received the error above.
Does anyone know what's going on here?
Has Light Table been completely abandoned? It seems the last commit was in March.
* Depending on the version I was trying to run, I also received other errors, but I don't think they're relevant (the error above was the only one that appeared for all versions):
[18593:0519/222845:INFO:gpu_info_collector_x11.cc(80)] NVCtrl extension does not exist.
[18593:0519/222845:ERROR:browser_main_loop.cc(226)] Gdk: gdk_window_set_icon_list: icons too large
Fontconfig warning: FcPattern object size does not accept value 11(i)
[14413:0519/204035:INFO:renderer_main.cc(212)] Renderer process started
A year later (question was written in May 2015, now is June 2016), LightTable 0.8.1 is out, and I tried both Linux binary and cloned it from git, and it works fine.
For complete info, I'm using also Atom, and although I had not problems with "Cannot read property 'something' of undefined"" in Atom core, I met such problems in two or three Atom packages.
Both editors are based on same electron platform, LightTable is beautiful eye candy with quite revolutionary REPL integration, but it needs more polish to be usable to same extent as Atom.
For example, LightTable does not have workspace saving by default, that is done via plugin. That's ridiculous.
But although Atom looks so nice and powerful compared to simple editors, with realy huuuge number of available packages/plugins, LightTable is more elegant.
As I don't want to start new semi-religious war Atom vs LightTable resembling vi-vs-emacs, I'll stop here. :)
I can't replicate your problems in LightTable v0.8.1, so I think that answers this question. If not, please add errors you get with v0.8.1.
For info about releases, please check: https://github.com/LightTable/LightTable/releases