LLDB: is it possible to display graphics from lldb session? - debugging

I would like to display a plot from LLDB session, is that possible?
plt.figure()
plt.title('Test')
plt.imshow(array, cmap='gray')
plt.show()
Right now, when i do that through the "command script import ~/script.py"; the session is stuck!

This works correctly in command-line lldb (or at least it does for me...)
That it doesn't work when trying to share the connection to the Window Server with Xcode (since lldb is running in the Xcode app process) is not entirely surprising. Doing plt.figure() seems to stall, though it wasn't immediately clear to me what Python thought it was doing when you called this method. It was not stalled somewhere obvious.
I don't think lldb has anything to do with this one way or the other (especially since command-line lldb works.) You're more likely to figure out how to get this working by asking the MatPlotLib folks if they have any experience sharing GUI's when the python is an embedded interpreter, especially in something complex like Xcode.
You might also see if they have any way to call out to an out-of-process renderer. That might get around the complexities of living inside Xcode.

I had a similar issue while plotting custom objects in Xcode. The lldb session crashed when calling plt.plot().
I used matplotlib with the Agg backend and was able to plot and save the generated plots at a convenient location. However you won't be able to show them directly from lldb in Xcode with the Agg backend.
Here is how my code looked like:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
plt.plot([1,2,3,4,5])
plt.title("Title")
plt.savefig("your/path")
plt.close()
Hope this helps.

Related

How to fix blurry text in WxPython controls on Windows?

We have a Python-based application written with WxPython 4 that we build for multiple operating systems, including Windows. In Windows 10, at least in my environment (inside a VM on a high resolution monitor), the text elements in the interface are blurry:
I can improve the situation somewhat by setting the Windows DPI-scaling override on the application. This is indirect and suboptimal, and it seems like there should be a way to do it from WxPython more directly. However, I have not found a way to do it.
Is there any way to set DPI scaling from WxPython, or otherwise fix blurry text on Windows in WxPython 4 directly from within the application?
According to a message from Python Issue Tracker and what I tried in the wxPython official Hello World, Part 2 example (helloworld2.py), adding following code to your program should work:
import ctypes
try:
ctypes.windll.shcore.SetProcessDpiAwareness(True)
except:
pass

Programmatically choose correct backend for Matplotlib on Mac OS X

I have a program which integrates a tkinter GUI as well as a matplotlib plot (using pyplot). I'm running into endless troubles having this program work correctly across a variety of Mac platforms. The main problem seems to be the appropriate selection of the backend.
In some cases, the program runs fine no problem. In other cases, I run into a similar issue documented in this question. Implementing the solution outlined there solves that problem, but then other errors pop up for other systems. The solution to these other errors appears to be to use the Qt4Agg backend.
There has to be some standard way of getting a program using tkinter and matplotlib at the same time to play nice with Macs. How can I programmatically make sure the correct backend is being used such that the program won't crash for a Mac user?
Sorry if this is vague but it is a very broad problem.
See this answer: How to switch backends in matplotlib / Python
In essence, if you do not know which backend is available, the following code should load up the first backend that is available on the current machine. (I have only included 4 backends, there are quite a few others).
import matplotlib
gui_env = ['TKAgg','GTKAgg','Qt4Agg','WXAgg']
for gui in gui_env:
try:
print("testing", gui)
matplotlib.use(gui,warn=False, force=True)
from matplotlib import pyplot as plt
break
except:
continue
print("Using:",matplotlib.get_backend())
Using: GTKAgg
Update: I am lead to believe that there is a backend for OSX called MacOSX which could be added to that list, although I have no way of testing it myself.

Recommended GUI designing modules for beginning python coder

Do any of you guys know of a module for making a GUI that would be easier for someone like me, who learned python as his first programming language?
If it matters I don't plan on making anything really complex, just something that allows me to make a window with a menu bar and some buttons.
See GuiProgramming PythonInfo Wiki for a list of various choices of such modules and also of design tools that allow you design forms visually and have the resulting code partially or fully generated.
In terms of modules, the main Gui Programming modules for Python are wxPython, Tkinter, pyGTK, pyQT4 and PySlide.
In terms of which module to start with I guess that depends on your criteria (which haven't yet been clearly specified), but Tkinter is shipped with Python by default, so you could always start with that.
References for Tkinter are avaliable from here

Is there a terminal widget library compatible with Python 3?

I'm looking for a terminal UI library providing widgets like buttons, checkboxes and so on, that is compatible with python3.
I've tried:
pycdk (pyrex does not work with python3, and porting it is a mess)
urwid (does not work with python3, it has a port but not working well with new curses interface).
Does anyone know such a library?
Thanks!
Cython supports Python 3, and I was able to make Cython accept the pyx file by changing all __new__ to __cinit__.
Note that the examples still needs some porting to Python 3 at that point. I get "TypeError: expected bytes, str found" when trying to run the examples. Switching all the strings to bytes worked.
Possibly it would be better if the API accepted strings under Python 3 too, but that is definitely more work.

OpenMP with OpenCV on OS X

I'm having a problem getting OpenMP and OpenCV to play nicely with a new project in Xcode. The project in its current state does nothing but grab frames from the default camera and put them into a window. This functionality works. However, I would like to grab the frames in a separate thread, and I was hoping I could get some experience with OpenMP.
Merely checking the checkbox to enable OpenMP in Xcode wreaks havoc. The program, while it will compile, load and run just fine, will not respond to any events -- period. It just sits there, drawing grabbed frames. (I do get the OS X beachball, too, even though it's running fine.) I eventually have to force quit the app or kill it from Xcode. Keep in mind I get this behavior even without any OpenMP #pragmas -- I have only to enable the option in Xcode.
Any ideas on how to solve this?
I'm just guessing here. You might need to make sure that all OpenGL drawing commands are called from one thread.

Resources