Pidgin script with Python/ Get Focus Signal - python

I am creating a script in Python to integrate Pidgin with Unity (Ubuntu 12.04), I've managed to do the counting notifications system using the Unity API, but i dont know what event or signal that is activated when the conversation window gains focus(To clear the message counter)...
I've tried some of the signals available on the documentation of Pidgin (https://developer.pidgin.im/wiki/DbusHowto) but none of them worked, is there any GTK(or anything) event that is triggered when the window chat gets focus?

Conversation UI signals are listed here those might be more helpful for what you are trying to do.
Though I don't know that I understand what you meant by your comment about the counter being wiped instantly when you tried some of the other signals. That sounds like it might be a coding error to me.

Related

Is there a way to display a loading icon on an inline button for telegram bot?

I'm developing a simple bot for myself.
I prompt the user with some inline buttons, which execute some functions on the backend. Since some functions take a little longer to execute, may I graphically show that the button tap was recorded, perhaps with a loading icon? Otherwise, the user might think something went wrong and keep on tapping.
I'm working on Python with python-telegram-bot v20.0a2.
the official TG clients will display a loading icon by default until you call answer_callback_query. So you can just delay calling that method until after your backend is done. IIRC after some timeout the icon will vanish on it's own, too, though, if your computation takes too long.

NSWindow drag regions should only be invalidated on the Main Thread! This will throw an exception in the future

I am writing a Python program with two threads. One displays a GUI and the other gets input from a scanner and saves data in an online database. The code works fine on my raspberry pi but if I try it on my MacBook Pro (Catalina 10.15.2), I get the above mentioned warning followed by my code crashing.
Does anyone have an idea how to get it working or what causes the problem?
You might want to call:
matplotlib.pyplot.switch_backend('Agg')
so that your server does not try to create (and then destroy) GUI windows that will never be seen.
You likely use different Python versions. Your Python on your Raspberry PI still allows invalidating NSWindow drag regions outside the Main thread, while your Python in your MacBook Pro already stopped supporting this. You will likely need to refactor your code so that NSWindow drag regions will only be invalidated on the Main thread.
You need to localize where NSWindow drag regions are invalidated and make sure that those happen in the Main thread.
EDIT
The asker explained that according to his/her findings, NSWindow drag regions only apply to Mac.

Uncomplicated window interface for displaying status in python

I am trying to create a window in python where I will be displaying the status of a large system, a bunch of numbers or some LEDs. The idea is that the system sends messages to the display thread and the thread updates different parts of the window, like displaying a number or turning the color of a field. More importantly, the user interacts with system via command line of python interpreter, e.g. executing commands or updating variables.
One may simply suggest that I need to use one of the GUI packages, like pyqt or xwpython. But these modules are designed to build GUIs, that means they have plenty of resources to handle events moues clicks and so on, which I don't need. Also, these modules run a event loop which is a waste of resources as well as in many cases they block the python shell.
I tried to use pyqt without running the main loop. But when I do this windows thinks my application is not responding, and I get a bunch of problems. For example the close button on the window does not work, and any effort on closing it crashes my python session.
Any ideas on how I can implement my application?
Maybe you should consider to use the Apache's Superset dashboard.
Check this up:
https://superset.incubator.apache.org/installation.html
It makes amazing dashboards incredibly easy and useful.

Writing an active program with wxPython. Where to start?

I spent the last hours trying to get to know wxPython, because I want to write a GUI program. I found some tutorials on that (not too many), but all of them just explain how to add yet another kind of widget, down to fancy things like LED number outputs and mouse gestures (this one e.g. takes it quite far: Another Tutorial). But everything I could find so far does nothing more than create a static GUI, waiting for the user to do something, then execute some handlers and wait again. It took me a while to even find out that wx.App takes a part in all of that, and that you can subclass it.
I want to write a program, that does things without input! The GUI is supposed to be a client that logs in on a server, and when the server sends something, I want the GUI to show what happened. I could not find a single tutorial even mentioning, that such programs exist. How can I write such a thing? How do they integrate with wxpython?
Do I need to span another thread? Is there a way to hook into the MainLoop and have some code executed periodically, that checks for change and then updates some of those fancy GUI things? And is there any page that teaches you, how to do this?
First of all, you should figure out how to do what you want WITHOUT a GUI. In this case, you'll need to figure out how to login to a server. You'll probably need to use something like paramiko for that. See http://www.lag.net/paramiko/
Once you've got that figured out, then you can add it to your GUI. Probably in a button handler so when the user presses a button, it pops up a dialog asking for a user name and password to pass to paramiko to login to the server.
If the server query takes a long time to execute (like say you're querying a database for a huge set of data), then you'll want to run the query in a separate thread. Why? Because that query will block the GUI's main loop and make your app freeze until it finishes. See the following articles for information on wxPython and threads:
http://wiki.wxpython.org/LongRunningTasks
http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/
I wrote up a tutorial on making wxPython talk to a socket server, so you might find that useful: http://www.blog.pythonlibrary.org/2013/06/27/wxpython-how-to-communicate-with-your-gui-via-sockets/
I also have an article on how to make an image viewer, and do CRUD ops to a database on there.

Finding when the ActiveApplication changes in OSX through Python

Is there a way to find when the activeApplication changes in OSX through Python and AppKit? I know how to find out launchedApplication and activeApplication ( please refer to my other question here: Finding the Current Active Window in Mac OS X using Python )
I've got an OS X app that does this by polling with an NSTimer. I tried searching for distributed notifications to see if I could find a better way to do it, but I couldn't see anything terribly useful.
I did get notifications when application were launched or quit. which is at least a little helpful. You can see the registration of these where my controller wakes up.
This application has been immensely helpful to me and even polling once a second uses nearly no CPU. If I could make it more event driven, I would, though. :)
I'm not aware of an 'official'/good way to do this, but one hackish way to go about this is to listen for any distributed notifications and see which ones are always fired when the frontmost app changes, so you can listen for that one:
You can set something like this up:
def awakeFromNib(self):
NSDistributedNotificationCenter.defaultCenter().addObserver_selector_name_object_(
self, 'someNotification:', None, None)
def someNotification_(self, notification):
NSLog(notification.name())
After you've found a notification that always fires when apps are switched, you can replace the first 'None' in the addObserver_etc_ call with the name of that notification and check for the frontmost app in your 'someNotification_' method.
In my case I noticed that the 'AppleSelectedInputSourcesChangedNotification' fired everytime I switched apps, so I would listen to that..
Keep in mind that this can break any moment and you'll prolly be checking for a change in the frontmost app more often than needed.
There must be a better way though.. hopefully :)

Categories