MPRIS integration with Python or VLC-Python - python

Does anybody know of an easy module to interact with MPRIS and write metadata to it?
I'm trying to get a music player working with the OS, and I'm using VLC [python-vlc] as it's backend. If you can help me out find any module that allows me to easily write metadata, thanks.
Modules I've tried:
playerdo - Only reads metadata
playerctl - Only reads metadata
modipy-mpris - Doesn't work
mpris-server - Breaks constantly and generally a pain to set up
vidify - Not what I've wanted
VLC docs: https://www.olivieraubert.net/vlc/python-ctypes/doc/index.html
NOTE: This is not what my player looks like, this is KDE's Applet allowing me to see what is playing. I'm sure windows has something similar, but the most important thing is I need to be able to play and pause music from anywhere in the OS with the play/pause button on my keyboard or bluetooth device
Example of output: KDE Plasma Applet

Use MPRIS-SERVER but read the issues.
Still a pain to set up but at least it works properly.

Related

pywinaudio doesn't recognize all of the controls in Audacity

Hello I'm once again looking for help. While trying to automate Audacity I came to a problem with what I could find being that it doesn't recognize the sub menu Audacity uses. Whenever I run this code:
app = Application(backend= 'uia').start(r'C:\Program Files (x86)\Audacity\audacity.exe')
app.Audacity.menu_select('File->Import')
app.Audacity.menu_select('Import->Audio... Ctrl+Shift+I')
It can't select the audio part (The whole submenu of Import is this way) but tries to find the nearest name to that, which apparently is somewhere in the transport menu. Also when I try to run print_control_identifiers() it doesn't show the submenu or any submenu in fact, even when trying to control the depth, it doesn't find the submenu.
you can use 'inspect.exe' to identify the control on your application, you can try UIA or MSAA to see which automation tech is feasible for the application.
or you can use other tools AccessBridgeExplorer or clicknium recorder to check whether the control can be recognized.

Is there any way to make python act like a game controller?

I want to control games with python. I need python to act like a game controller and do what i code.
I couldn't find things about this. I'm waiting for your help. Thanks.
edit : I pretty much did it with using PyvJoy library and vJoy software. Its now possible python to act like game controller and press keys. This can be useful while developing machine learning apps.
Here's an example code I used a while ago in order to read inputs from an xbox controller hooked-up via the USB port and use them inside Python:
my GitHub
It relies on the pyGame module:
https://www.pygame.org/news

pyqt embed in photoshop

This is complex to explain, I hope this will not end up being a vague question getting vague answers.
If this is not the right place to ask this, you may help me to find the proper one.
I have a plugin for Photoshop based on the Listener, so it captures any input from the user.
The plugin creates a python module (called here "ps") containing basically the hInstance and the hwnd of the photoshop window.
Then this plugin, using plain python commands in the plugin for the module like those
PyRun_SimpleString("import Photoshop");
PyRun_SimpleString("Photoshop.showTools()");
will load a special module (here called "Photoshop") that will initialize pyqt and using the QtWinMigrate and the ps module to get the hInstance like this: QMfcApp.pluginInstance(ps.GetPluginInstance()), will start pyqt in photoshop. Here an example code of the Photoshop module using the ps module:
from PyQt4.QtWinMigrate import QMfcApp
from PyQt4.QtGui import QPushButton
import ps #this is implemented in the photoshop plugin (based on the Listener plugin)
#create the plugin instance here
app=QMfcApp.pluginInstance(ps.GetPluginInstance())
def showTools():
box = QPushButton()
box.show()
app.exec_()
Again then, the sequence is like this:
When the plugin starts in photoshop "ps" module is created, then it will load the "Photoshop" module that will load and bind properly pyqt. In the "Photoshop" module I can load any python module, widgets are properly working and everything works really well inside Photoshop.
But now the problem is: using Wacom tablets in Photoshop loose stroke sensitivity, the driver works and everything else works but the pressure sensitivity.
Apparently QMfcApp.pluginInstance will install an event filter to drive the Qt event loop while photoshop still owns the event loop. ( http://doc.qt.digia.com/solutions/4/qtwinmigrate/qmfcapp.html )
and on the paper looks fine to me.. but I could not manage to solve this by myself and I tried, more or less carefully, different approaches:
the listener plugin is not the problem. If Listener plugin runs but python is not initialized sensitivity works fine.
python itself is not a problem. If the listener starts python without gui nor pyqt, then works fine.
as soon as I call pluginInstance which should create the QApplication the issue starts and pressure is lost from the tablet. Even with the small code I wrote before.
Someone may have put pyqt as a plugin somewhere else, since the only purpose of QMfcApp is apparently this one. There is something I can configure to make it work? Is a known issue?
I would rather keep the approach (instead of connecting to photoshop externally like with COM)
I am not able to post the entire code here but let me know if you need something.. I probably can show more.
Thanks a lot for your help

Python Image processing screenshots

I'm trying to write a program than will detect when my mouse pointer will change icon and automatically send out a mouse click. Is there a better way to do this than to take screenshots and parse the image for the mouse icon?
EDIT:
I'm running my program on windows 7.
I'm trying to learn some image processing and make a simple flash game i made automated.
Rules: when the curses changes shape, click to get a point.
Also what imaging modules for python will allow you to take a specific size screenshot not just the whole screen? This question has moved to a new thread: "Taking Screen shots of specific size"
The way to do this in Windows is to install either a global message hook with SetWindowsHookEx or SetWinEventHook. (Alternatively, you could build a DLL that embeds Python and hooks into the browser or its Flash wrapper app and do it less intrusively from within the app, but that's much more work.)
The message you want is WM_SETCURSOR. Note that this is the message sent by Windows to the app to ask whether it wants to change the cursor, not a message sent when the cursor changes. So, IIRC, you will want to put a WH_CALLWNDPROC and a WH_CALLWNDPROCRET and check GetCursorInfo before and after to see if the app has done so.
So, how do you do this from Python? Honestly, if you don't already know both win32api and friends from the pywin32 package, and how to write Windows message procs in some language, you probably don't want to. If you do want to, I'd start off with the (abandoned) pyHook project from UNC Assist. Even if you can't get it working, it's full of useful source code.
You should also search SO for [python] SetWinEventHook and [python] SetWindowsHookEx, and google around a bit; there are some examples out there (I even wrote one here somewhere…)
You can look at higher-level wrapper frameworks like pywinauto and winGuiAuto, but as far as I know, none of them has much help for capturing events.
I believe there are other tools, maybe AutoIt, that have all the functionality you need, but not in Python module. (AutoIt, for example, has its own VB-like scripting language instead.)

convert ahk to python

I am learning both autohotkey and python. I wrote this script in ahk (and it works!) that automatically joins tables (using tableninja) in the pokerstars client--
^q::
Loop
{
Send q
Sleep 500
Send {PgUp}
Sleep 500
Send w
Sleep 60000
}
return
I'd like to convert this into python--could you give me an idea as to which modules I can use to accomplish this?
What the python script needs to do is to (while looping) type in a letter (on a notepad that's already open), go down two lines, type in another letter, then wait one minute before starting over.
I am thinking--
import module to auto-type letters
import module that works as timer
def function
type letter q
enter
enter
def function
type letter w
def function
sleep
while True
function
function
function
I am teaching myself how to code. I haven't reached that part about python modules just yet. Thanks!
Assuming you work on windows(don't think AHK runs on anything else), you should check out sendkeys. It will make sending keystrokes a piece of cake. If you want somthing a little more robust, take a look at pywinauto
For the shortcut part, take a look at pyhook
I suggest these modules:
SendKeysCtypes for any sending of keystrokes and sending shortcuts to a window.
SendKeysCtypes is a new and more stable version of SendKeys. I have had issues with SendKeys in the past.
PYHK to deal with global hotkeys - receive hotkeys and trigger functions.
PYHK is based on pyHook and makes hotkey registration very simple. I wrote it because I had the exact same idea as you - I wanted to to do AHK functionality in python.
win32gui for window handling such as moving resizing.
I personally prefer win32gui for short, simple tasks. I use pywinauto for more complex tasks. An example would be if I had to access a menu within a program (like File-New).
mouse.py to control the mouse. This is the most robust way I have found so far. The version I use is an extension of a module I found here at stackoverflow - ctypes mouse_events.
I have personally done several programs for poker with python. I have released source code of my smaller programs. You can find them with source on my website schurpf.com/poker-software.
there's also AutoPy, a cross-platform library for this purpose.

Categories