bad screen distance - linux

I'm trying to obtain an figure object (using matplotlib), inside a wxpython application. I don't need to plot (or see) the figure, because I would want only to save it in a png file.
When I do it using Windows XP, it is all okay, if I do it outside the wxpython application, for example inside sphinx documentation, it's all okay again.
But If I do it inside my wxpython application... something goes wrong and it raises this:
_tkinter.TclError: bad screen distance "320.0"
Has someone any idea about?

Since you're trying to use wxPython and getting tkinter errors, you probably haven't told matplotlib to use wx. This can either be done in the matplotlibrc file, or in the program. Instructions are here.

Related

matplotlib randomly shows no plot in figure window

I am using Python 3.8.16 on Ubuntu 18.04.6 LTS and work with matplotlib 3.6.2, but do not use Jupyter in this case. When I plot a graph with matplotlib, sometimes happens that I get the figure window, but without any content, except the window title "Figure 1". I cannot close the figure with "q", and usually cannot break the execution with ctrl C, however ctrl \ usually works. When I run the program again, usually everything is fine. I would say that the probability, that the plot will be shown properly is around 80-90%. I had the same behaviours with Python 3.7 and with previous versions of matplotlib - seems it is not version specific. The problem occures in diferent programs. The matplotlib.get_backend() command returns TkAgg, and the posts in discussion groups suggest it is ok in case of Ubuntu. I couldn't find any solutions on internet forums so would appreciate any hint.

Pyautogui image recognition returns None no matter what I do

I have been trying to get pyautogui to locate graphically a folder on my desktop but it fails no matter what I do:
This is my code (int_auto.py)
import pyautogui
button = pyautogui.locateCenterOnScreen('/Users/cadellteng/Desktop/Test-ground/randompy/pyxell2.png')
print(button)
I literally read through every SO thread I could find on this topic and some suggested that the photo needs to be lossless, so I used the cmd+shift+4 command on Mac to achieve this. A screenshot of my desktop and the reference image I used is attached here.
Note: This photo was converted to jpg because SO only allows photos up to 2MiB to be uploaded
Other things I tried are:
1. using locateAllOnScreen
2. grayscale = True
3. uninstall pyautogui and reinstalling pyautogui
But no matter what I did, I couldn't seems to be able to get the outcome I want. If it helps, I use a double screen and my code editor (VS Code) is on the secondary screen. What you see here as my desktop is my primary screen.
When the program is running nothing is blocking the folder.
There is also a warning on my terminal which I'm not sure if it's going to be useful:
/Users/cadellteng/Desktop/Test-ground/randompy/env/lib/python3.8/site-packages/rubicon/objc/ctypes_patch.py:21:
UserWarning: rubicon.objc.ctypes_patch has only been tested with Python 3.4 through 3.7.
You are using Python 3.8.2. Most likely things will work properly, but you may experience crashes if Python's internals have changed significantly. warnings.warn(
Do let me know if you require additional information.
EDIT June 01, 2020: So I thought that maybe pyautogui was not able to detect the folder because there are multiple folders and they all look the same and was not able to detect it. So I got this image off the web and tried to search it with it opened on my desktop with nothing else blocking it. But even then it was not able to find it.
I'm not sure if I am doing something wrong here but with each try, I am becoming more convinced that this API is broken.
The size of the picture might be a problem. When I use locateOnScreen to find an element in a browser and zoom out by, for example, 10%, then it will not locate it on screen even if is almost the same.
You have a Macbook so I think its because of the pixel density of the screen and the resolution pyautogui detects. You can check by:
image = pyautogui.LocateCenterOnScreen(‘image.png’)
print(image)
If you see coordinates above 2000 its probably because of the resolution. I suggest a workaround if you want to click the image like:
pyautogui.click(image.x/2, image.y/2, clicks=1, interval=10, button=‘left’) also try cropping the images as small as possible!

How can Pycharm (with matplotlib) show me my graphs in the same Py charm, next to my code?. Not in additional windows

i am using Matplotlib with Pycharm in a Mac osx. When I am making a graph, and I code plt.show() pycharm opens another window. And if there is 2 graphs, to see the 2nd one I have to close the first one. And I want to see both together.
There is a option to show the two graph in the same window, where my code is?
Thanks very much.
This link may help:
IPython magic commands
Using Jupyter notebooks you can achieve what you want by using %matplotlib inline. It seems from the link above that PyCharm may have some way to enable this same functionality.
See also: Inline plots in the scientific view

running a Program from vim that opens another window messes up the formating of my terminal

Im using vim inside a gnome-Terminal to edit a Python Program. Im also using a tiling Window manager calles awesome-wm.
Inside my Python program im plotting some data to a matplotlib graph (when executed that opens another window). When i want to test my Program i use the following comand to run the Program from inside of vim.
:!python3 %
when the Program runs it prints three messages to the shell and opens a matplotlib window to plot the data.
Sometimes i can only see the messed up linebreaks and have to scroll up to see the messages.
My question now is why is the formating inside the console messed up an how do i fix it?
My guess would be that the Terminal Window does not notice that it is beeing resized when the plot window is beeing opend, but i dont know how to refresh the terminal in that case.
using :!clear; python3 % does not help.
Thanks in advance.
(Well, it isn't a direct solution to your problem, but here it goes.)
Most terminal don't handle reflow in resize properly. There is no right ways to do it so most don't attempt to pull all the tricks in the book to make this better. After all, for classic floating window manger, resizing isn't something you do very often. LibVTE/Gnome-terminal isn't designed for tiling WMs and has not been patched over the years to make it better.
Urxvt is probably the most common terminal for AwesomeWM (the default is xterm because it is much more commonly installed by default). It has more advanced features like tabs and transparency you expect from modern terminals. Note that some of them (tabs) are disabled by default.
Sometime using software like tmux can be used to mitigate some of the limitations of any given terminal, but it comes with limitations of its own.

Screen capture doesn't work on MFC application in Vista

We've got some in-house applications built in MFC, with OpenGL drawing routines. They all use the same code to draw on the screen and either print the screen or save it to a JPEG file. Everything's been working fine in Windows XP, and I need to find a way to make them work on Vista.
In three of our applications, everything works. In the remaining one, I can get the window border, title bar, menus, and task bar, but the interior never shows up. As I said, these applications use the exact same code to write to the screen and capture the window image, and the only difference I see that looks like it might be relevant is that the problem application uses the MFC multiple document interface, while the ones that work use the single document interface.
Either the answer isn't on the net, or I'm worse at Googling than I thought. I asked on the MSDN forums, and the only practical suggestion I got was to use GDI+ rather than GDI, and that did nothing different. I have tried different things with every part of the code that captures and prints or save, given a pointer to the window, so apparently it's a matter of the window itself. I haven't rebuilt the offending application using SDI yet, and I really don't have any other ideas.
Has anybody seen anything like this?
What I've got is four applications. They use a lot of common code, and share the actual .h and .cpp files, so I know the drawing and screen capture code is identical.
There is a WindowtoDIB() routine that takes a *pWnd, and a source rectangle and destination size. It looks like very slightly adapted Microsoft code, and I've found other functions in this file on the Microsoft website. Of my four applications, three handle this just fine, but one doesn't. The most obvious difference is that the problem one is MDI.
It looks to me like the *pWnd is the problem. I'm not a MFC guru by a long shot, and it seems to me that the problem may be that we've got one window setup in the SDIs, and more than one in the MDI. I may be passing the wrong *pWnd to the function.
In the meantime, it has started working properly on the 64-bit Vista test machine, although it still doesn't work on the 32-bit Vista machine. I have no idea why. I haven't changed anything since the last tests, and I didn't think anybody else had. (On the 32-bit version, the Print Screen key works as expected, but it does not save the screen as a JPEG.)
Your question title mentions screen capture but your actual question doesn't. Please elaborate more clearly. Is the problem that you can do screen capture of three of your applications, but not the fourth one? You can use different screen capture software that can capture OpenGL/DirectX windows. Those surfaces are handled directly by the Window Manager and won't show up with a simple 'PrtScn'.
Switching to GDI+ won't solve it, nor will switching to SDI.
If it's the content of the CView that you want, then yes, that should be right one. If it's the content of the whole screen (at least the content, without the toolbar(s) and status bar), then you should pass it the CMainFrame (that's the default name which may have been changed, the one that is derived from CMDIFrameWnd).
Can you post the code of WindowToDIB()? I've just tried it and It Works For Me (TM), but without OpenGL code in the view. Try passing the following windows to your WindowToDIB() function:
CMainFrame* mainfrm = static_cast<CMainFrame*>(::AfxGetMainWnd());
- mainfrm
- mainfrm->MDIGetActive()
- mainfrm->MDIGetActive()->GetActiveView()
and see what you get.
The contents of each window are directX surfaces and are only assembled by the window manager in the graphics card. You'd not be able to capture this unless you switch off the new interface (DWM) or code specifically for screen capture from the DWM.
Wikipedia has a good description of the Desktop Window Manager (DWM)
Sorry, I still don't understand. You're trying to get the Print Screen key to work on all four applications? Or you're trying to get the WindowtoDIB() function to work, which takes a 'screenshot' (from within your own application) of the application itself, so that it can be saved as an image file?
Also, what do you mean with 'he Print Screen key works as expected, but it does not save the screen as a JPEG.'? Print Screen only copies to the clipboard, what happens when you paste in Paint?
If your WindowtoDIB() function only 'captures' the window you pass to it, then yes, your MDI child windows are not going to show up.
We eventually solved this by creating a different OpenGL context, and drawing everything to that. We gave up on the screen capture.

Resources