PyGTK and visual-python - python

I'm developing an application with PyGTK that will make use of visual-python's 3d drawings and animations, but I can't get both libraries to work together: they either hung up when I close the Gtk window or they get stuck when I run the application.
I've tried with threads and they run side-by-side, but when I close visual-python's window this kills python's interpreter, raising a Segmentation Fault.
Has anyone been able to use visual-python from a PyGtk app?

This is a non-trivial problem given the way that VPython wants to work, but there is an example in the contributed programs section of the VPython web site that shows how to embed VPython into a wxPython application, so perhaps you can look over that code and determine what you would need to do to perform the same magic in PyGTK.

Related

Python curses window flickering when resizing terminal

This is my first post on stack overflow so I hope I'm doing it properly.
I am currently working on a Terminal User Interface for python applications. I know that there are many ready-to-use libraries such as npyscreen out there, but I wantend to create one as programming excercice. In particular, I wanted to to play with some architectural patterns to learn them.
All that said, I'm currently facing several problems with python curses library, that I'm using as low level interface to the terminal.
The problems arise when I try to resize my terminal. As you can see from the code (see below), I handle the terminal resizing in the main loop, invoking the getmaxyx()() method of my curses window and redrawing what is on the screen accordingly.
The problem is that the screen seems to flicker when I try to resize the terminal.
Moreover, my "curses application" works fine on MacOS but totally crashes on windows (even after installing windows curses).
To handle that I tried to re-write the low-level interfice by using the blessed library. It solved the windows crashing problem, but the flickering still remains.
I can not figure out what the problem is.
Fore those wishing to help me, here follows the github page of the project: Terminal GUI on GitHub
Thank you in advance.
With curses, there's (at least) 3 things to look for:
ncurses can handle SIGWINCH (PDCurses may not)
some Python configurations interfere with ncurses receiving SIGWINCH. If your program never receives KEY_RESIZE (which it's not checking for...), then it's time to file a bug report for Python to get that fixed.
some programs don't actively read keyboard input (and if KEY_RESIZE isn't read, ncurses won't update the screensize. That would make the program crash.

Is there a way to get the labels of running GTK applications?

I am trying to extract labels of widgets of running GTK applications. I tried using GtkParasite but I have no idea how to get it working in my python program.
I want to be able to get the widgets and their labels of a gtk application that is running on my computer. It means that if I run gedit on my system then i want to get the labels of the widgets at run time. I hope this makes sense.
Is there a way to use the C library of GTK to get an instance of a running GTK application?
Thanks in advance.
You probably should use accessibility libraries - those are tools that allow eg. screen readers to read GUI labels for visually impaired users. On Linux, at-spi2 seems to be the de-facto standard.
For Python, take look at at-spi examples:
https://github.com/infapi00/at-spi2-examples

Python custom GUI

I googled and search stackoverflow before asking this question
Answers that I don't expect:
wxWidgets is the best Python GUIUse TkInter (BIM) for GUI development.
Q. How to make a GUI without using any module/library? i.e make a GUI from scratch. Modules like tkinter not allowed.
I've made several GUIs from scratch using SDL which is a low level drawing library. The advantage of doing that is that it will look exactly the same on any platform down to the pixel and you can get it to work on embedded systems. Full screen GUIs are really easy too. Disadvantages are that it is a lot of work.
In python the pygame library wraps SDL so you would use that, and in fact that is how I made the GUI for a lab instrument which had a large colour LCD screen. The controller ran linux, but not X-windows.
pygame is an extra library, yes, but I can't think of a way of making a GUI with only what python provides.
The easiest GUI to make without "module/library" is a web-based one. I.e. generate HTML with Javascript from your Python code, and let the Javascript interact via AJAX with your Python app. This can be implemented without too much effort with just the standard Python library (and some JS code, of course), or with modules that don't require "heavy" installation of platform-specific extensions.

Python PyQT gestures

I want to enable use of PyQT gestures in my application. Anybody has an example or some short code that could demonstrate use of gesture control in PyQT application?
I tried googling around but could find only one post about customizing the gesture... I am not that far yet at all, I just want to see how to bind the gesture and callback in Python QT app.
thanks
I'm working the same problem. No reason why it shouldn't work, by simply translating some of the C++ examples, but its bleeding edge.
For example, won't work on Linux desktop (just Windows) without Qt 5 or a lot of work. See http://qt-project.org/forums/viewthread/12664. If I get Qt 5 installed, I hope to post a Python example.
I am using PySide, and the QtGraphicsFramework and have a small test program. Another more sophisticated test, of custom gestures, is crashing, not just throwing exceptions, and I'm suspecting the Python binding.
There are plenty of nuances. If any platform is good for learning, it should be Qt and Python. Go figure why there are no examples yet.

Detecting active windows in python with KDE

I'm writing a small python script that tracks how I'm dividing my time between programs. It needs to detect the currently active window (ideally, the application controlling that window, but I can make do with just the window title), as well as idle time.
At the moment, I'm using KIdleTime to determine how long I've been not touching my computer, which works fine by itself.
I also try to use wnck to determine which windows are active, and again, this works fine by itself.
It's when I try to combine the two into one program that I run into troubles. Since wnck is a gnome library and KIdleTime is a KDE library, they need to be run on their own threads for the window change and idle timeout signals to fire.
I'm having trouble finding a way to do this in python - if I use the threading module to try to run one of them on a separate thread, the KDE library complains that it's not on the main thread, or the Gnome library has an impressive meltdown and eats all the memory it can get (incidentally, ulimit was very useful in this case, I can recommend it).
So, I have four options:
Find a KDE library that can detect
when the window is changed - I would
have thought that dbus would expose
this in kwin, but it doesn't seem
to.
Find a way of running both the kde and gnome libraries at the same
time.
Find an equivalent of KIdleTime that runs on the Gnome event thread.
Use timers to poll KIdleTime from within the Gnome thread (which is
what I'm doing now, but is far from ideal, it leads to imprecision in
determining idle times).
Can anyone offer me a solution?
One can use the wxPython GUI toolkit for this purpose.
It has a method for getting the active window.
It has a timer class, althou there are multiple ways you could use.
Of course, you can forget about QT, Gnome, and all other graphical libraries.
Here is what wx can do.

Categories