In APL, you can trivially bring up a window that shows the contents of a variable whilst your program is running and watch it update live.
This is illustrated by the classic Game of Life video at 5 minutes in.
Is there any similar 'inspector' for Python with support for numpy arrays so I can see step through my array code and see what its doing live?
(Ideally using TK or something portable)
Have you looked at the python debugger? (pdb)
It's not graphical but it is completely portable. Depending what IDE you're using, there might be a visual debugger built in.
(original poster)
I could not find one, so I made one. You can get it here.
Related
I am trying to take a pixbuf image and drop it into the user's clipboard for pasting into any program that accepts images. If I don't run Gtk.main(), nothing happens. If I do run Gtk.main(), it works, but the program never exits (I don't want to open a window).
# pixbuf is a pixbuf image
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clipboard.set_image(pixbuf)
clipboard.store()
Gtk.main()
I have bad news, and I suggest you use something other than gtk to set the clipboard. I recommend trying something like wl-clipboard, xsel, or xclip. I am sure you know how to chose one or two of these and call it from a python script.
If you are looking for a gtk-only solution, I have spent quite some time on this and given up though I am not yet an expert in any of this.
The traditional solution is documented here:
https://github.com/bstpierre/gtk-examples/blob/master/c/clipboard_simple.c.
For reasons beyond my knowledge it doesn't currently work, but the comments at the bottom would be important in creating a gtk-only solution. The problem could be for a number of reasons including a bug in gtk or glibc. Or it might be part of a poorly explained migration to wayland.
Another potential solution is documented here: https://docs.gtk.org/gtk3/func.events_pending.html. This also doesn't work for unknown reasons.
The next avenues for testing are to test historical versions of linux distributions, and once the library version is found try to pinpoint the exact commit to the exact library and make a change. I made a decent effort to debug gtk, but it is not yet my area of expertise.
Even if the the change could be maid to facilitate one of the above solutions, it would be to much to ask for a version that works on wayland. Although xwayland may offer residual support and wl-clipboard offers a hack, any clipboard read or write requires a window and for your window to be focused as mentioned here: https://gitlab.gnome.org/GNOME/gtk/-/issues/1874. There seams to be some exeption for non-gnome wayland implied in this discussion: https://github.com/bugaevc/wl-clipboard/issues/90. Although I never found the offending part of the wayland standard, I expect that it is present.
I'm currently at a crossroads. I'm somewhat versed in Python (2.7) and would really like to start getting into GUI to give my (although mini) projects some more depth and versibility.
For the most part, my scripts don't use anything graphical so this is the first time I'm dipping my toes in this water.
That said, I've tried using pygame and tkinter but seem to fail at every turn to get something up and running (although I had some slight success with pygame)
Am I correct to understand that for both I need X started in order to generate any type of interface, and with that, so I need X to get any type of input (touchscreen presses)?
Thanks in advance!
In order to use tkinter, you must have a graphics system running. For Windows and OSX that simply means you need to be logged in (ie: can't run as a service). For linux and other unix-like systems that means that you must have X running.
Neither tkinter nor any of the other common GUI toolkits will write directly to the screen.
I'm gonna give an alternative answer. If you know HTML, CSS and Javascript (or have time to give it a try) I would recommend using Flask, http://flask.pocoo.org/.
With flask you can create websites but you can also (as I am using it) let it be your GUI. It will work on any device and looks really good :).
I've been searching everywhere for an answer to this but to no avail. I want to be able to run my code and have the variables stored in memory so that I can perhaps set a "checkpoint" which I can run from in the future. The reason is that I have a fairly expensive function that takes some time to compute (as well as user input) and it would be nice if I didn't have to wait for it to finish every time I run after I change something downstream.
I'm sure a feature like this exists in PyCharm but I have no idea what it's called and the documentation isn't very clear to me at my level of experience. It would save me a lot of time if someone could point me in the right direction.
Turns out this is (more or less) possible by using the PyCharm console. I guess I should have realized this earlier because it seems so simple now (though I've never used a console in my life so I guess I should learn).
Anyway, the console lets you run blocks of your code presuming the required variables, functions, libraries, etc... have been specified beforehand. You can actually highlight a block of your code in the PyCharm editor, right click and select "Run in console" to execute it.
This feature is not implement in Pycharm (see pycharm forum) but seems implemented in Spyder.
I'm exploring 2D interpolations for the purpose of writing a script in Python. I've been using the PIL (Pillow) modules to quickly display the results of the algorithms - this is best for cases when interactive input isn't necessary (i.e. testing on a random set of points).
For interactive testing I've found jsfiddle to be the most lightweight solution, but I admit it isn't ideal to rewrite functions in another language merely to be able to move points around, and input specific shapes of quads.
simple example, 4 verts drawn at random (JavaScript in JS fiddle; would like to do the same in Python)
What would be a fastest way to play around with a Python script graphically? Is there a Python counterpart of jsfiddle? I googled 'Python fiddle', of course, but it's not what I'm looking for. What I need is a simple canvas implementation and click events support.
Thanks in advance,
Well, there is Python Fiddle, but I think this question is going to be closed by admins as being off-topic on Stack Overflow; see this thread here.
I'd also come to think of Jupyter and Anaconda. The latter includes the former. These will harness matplotlib, amongst others, and Jupyter gives you a Matlab-like interpreter that shows you variable values for each line and you're able to step by step look at those variables and any graphs you are making.
As mentioned in previous answer, there is Jupyter notebook – a software for interactive Python programming including graphical output.
You can run Jupyter locally or on your own server, but there are free cloud versions:
https://colab.research.google.com/
https://notebooks.azure.com/
In python 3.3.2, how you adjust the time it takes for the suggestion box to appear just after typing a '.'. For example, say I import wxPython and type wx. after 3 seconds a list box would appear showing the available options. Is there any way to set this to appear instantly or in a very short time? Sort of like Visual Studio's intellisense feature which appears instantly.
Thanks in advance :)
I think you are referring to your IDE, the editor you are using to write your code. If this is the case, that would depend on your editor, which one are you using?
If you are using the built-in editor IDLE, then what you are looking to do is not an available option.
If you are trying to do this within your own code using wxPython (as
SexySaxMan suggested), please provide an example of your code so we can get a better idea of what you are trying to do.
I believe what you're looking for is something like time.sleep
http://docs.python.org/2/library/time.html#time.sleep
EDIT: I haven't really used wxPython, but I have used Tkinter and Tkinter.after does exactly what you're asking for. Try looking for a parallel in wxPython.