How to get Window ID with python?

Hello,
how do i get the window id of a specific window, eg. a movie played with mplayer in python? I can do s.th. like
xwininfo -name MPlayer
, but can't find a more pythonic way. Any ideas?
Thanks,
rich_o
Last edited by rich_o (2011-02-11 00:15:20)

This is actually sufficiently more complex that it would seem at first. Iterating over the QueryList of the root window isn't quite enough---since you're going to get a lot more results than you otherwise would. (There are many windows that usually make up each client.)
There are two approaches here. You can go with the QueryList idea, but you'll need to check that WM_STATE is defined for each particular window (this is how you tell whether it's a top-level window or not). Alternatively, if you're using any sort of standardized window manager, you could rely on the _NET_CLIENT_LIST property that is defined on the root window. (This is an EWMH standard.) In fact, in the former method, whether WM_STATE is set or not is also a standard, but an older one (the ICCCM standard).
I prefer using the _NET_CLIENT_LIST way. The property is maintained by the window manager and contains a list of all window IDs that the window manager is currently "managing."
While you can use python-xlib (and in my experience, it is perfectly suitable), you might also try xpyb, which is the Python version of XCB. The following should do the job you're looking for:
import struct
import xcb, xcb.xproto
winname = 'Geany'
def get_property_value(property_reply):
assert isinstance(property_reply, xcb.xproto.GetPropertyReply)
if property_reply.format == 8:
if 0 in property_reply.value:
ret = []
s = ''
for o in property_reply.value:
if o == 0:
ret.append(s)
s = ''
else:
s += chr(o)
else:
ret = str(property_reply.value.buf())
return ret
elif property_reply.format in (16, 32):
return list(struct.unpack('I' * property_reply.value_len,
property_reply.value.buf()))
return None
def contains(needle, haystack):
return haystack.lower().find(needle.lower()) > -1
c = xcb.connect()
root = c.get_setup().roots[0].root
_NET_CLIENT_LIST = c.core.InternAtom(True, len('_NET_CLIENT_LIST'),
'_NET_CLIENT_LIST').reply().atom
raw_clientlist = c.core.GetProperty(False, root, _NET_CLIENT_LIST,
xcb.xproto.GetPropertyType.Any,
0, 2 ** 32 - 1).reply()
clientlist = get_property_value(raw_clientlist)
cookies = {}
for ident in clientlist:
cookies[ident] = c.core.GetProperty(False, ident, xcb.xproto.Atom.WM_CLASS,
xcb.xproto.GetPropertyType.Any,
0, 2 ** 32 - 1)
for ident in cookies:
winclass = get_property_value(cookies[ident].reply())
if any([contains(winname, wncls) for wncls in winclass]):
print ident, winclass
Note: The above searches on WM_CLASS. You may also want to search on _NET_WM_NAME (or maybe even WM_NAME, if you're dealing with some legacy applications).
Finally, if you're going to do any more heavy lifting, may I suggest you check out my xpyb-util git repository? The above could be condensed into this with xpyb-util:
import struct
import xcb
import xcb.xproto
import util
import icccm
import ewmh
winname = 'Geany'
def contains(needle, haystack):
return haystack.lower().find(needle.lower()) > -1
c = xcb.connect()
root = c.get_setup().roots[0].root
clientlist = ewmh.get_client_list(c, root).reply()
cookies = {}
for ident in clientlist:
cookies[ident] = icccm.get_wm_class(c, ident)
for ident in cookies:
winclass = cookies[ident].reply()
if any([contains(winname, wncls) for wncls in winclass]):
print ident, winclass
My repo can be found here: https://github.com/BurntSushi/xpyb-util
(If you import the image module, you'll need PIL installed.)

Similar Messages

  • How to get Windows Server 2012 trial license key?

    How to get Windows Server 2012 trial license key? I'm trying to install WinServer 2012 Trial on a VMWare Workstation 9. I'm asked for the product key during set up. If I ignore putting in the key (since I don't have one) The install fails stating no valid
    key. I tried this with Oracle's Virtual Box and the same thing happens. I tried using Majic JellyBean to find the key, but that only works on pre-installed OS. A Technet article said to use aaaa-bbbbb-ccccc-ddddd etc. in the spaces. That doesn't work either.
    Articles all over the web seem to have other people in the same boat. Please help :)

    Download the trial version from here -
    http://www.microsoft.com/en-us/server-cloud/evaluate/trial-software.aspx  It does not require a key.  If the software is asking for a key, it is not the trial copy.  Where did you get your copy?
    .:|:.:|:. tim

  • How to get windows username printed on each page irrespective of application? we have cm6030f.

    How to get windows username printed on each page irrespective of application? we have HP CM6030F.

    Hi,
    Normally, you will receive a Windows Azure Pass from your local Windows Azure team. Please try to contact your local Windows Azure contact (http://support.microsoft.com/gp/customer-service-phone-numbers?wa=wsignin1.0
    Also, you could see this page
    http://www.windowsazurepass.com/AzureU/AcademicFAQ and apply the free trial azure via (http://www.windowsazurepass.com/AzureU/).
    Q: I am a student. Can I apply for a pass?                     
    A: Windows Azure Educator Grants are only for valid faculty. If your faculty has been awarded a Windows Azure Educator Grant, you will be able to get a pass through him/her for you coursework. If you are interested in learning more about Windows Azure,
    we encourage you to share these Educator Grants with your faculty or sign up for the FREE 3-month trial offer. 
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to get the itunes with those 3 colored buttons on top left corner ????ner ???

    Please help [humble request] ----
    I have 3 problems can u please help me out --
    1) How to get the itunes with the 3 colored buttons (i'm new to apple ,just 8 days so i dont know much stuff) on top left corner ,i've downloaded thrice from apple's site directly i everytime got the same sort of itunes with 'File' ,'Edit' ,'View' ,'Controls' ,'Store' ,'Adanced' ,'Help' on the top ,and also whenever i open the itunes store (in this itunes) only the app store opens ,now music albums ,movies ,tv shows nothing !!
    2) I dont know how to import video files from the computer to itunes
    3)i bought an app [fifa 11] ,n downloaded another 1 [contract killer] {ive deleted them and downloaded them thrice ,and they dont sync to my itouch it shows error (0xE800004C)
    Please please please help me im getting worried and frustrated
    please help me out with this

    but illaass
    i asked 2 of my frnds both of them have windows n not mac ,both of them are sayin dat they have the coloured buttons one , and i asked them dat how to access the itunes music store they said that when they kliked d itunes store option in the left side a screen appears where 6 -7 categories are there which are music store ,app store ,podcasts ,movies ,tv shows etc . bt when i open it it only shows d app store ,and on the bar only 4 options are ther the home icon , app store , podcasts and itunes u ,and when i klik movies ,tv shows on the left side ,there is an option "browse for movies in the itunes store" i klik it and only the app store opens and nothing else .
    and thanks now i know how to import videos
    and sigma 1337 ,
    ive downloaded the apps 4 -5 times now , still d same error mssg it comes like dis :-
    " Some of the apps in your iTunes library were not installed on the ipod "Shomik's ipod" because one or more errors occurred "
    please help me  im gettin frustrated

  • How to get window system user?

    Hi,
    How to get window system user use PL/SQL(form develope6i)?

    If you don't use Oracle database then you will have to do one of two things:
    (1) Now I'm back in the office I can check D2KWUTIL. The version I have comes with Forms6.0, so it is somewhat out of date, but it has a method called WIN_API_ENVIRONMENT.Get_Windows_Username - which works for NT/95 only, although I'm sure a later version will support more recent OS.
    (2) If that's no good then you'll have to use whatever facilities your database offers: I only know Oracle.
    I also repeat my suggestion that you try the Forms forum for additional help. This is the Database forum and so is focused on serverside Oracle PL/SQL. For your needs the Developer Suite forums are better.
    Cheers, APC

  • How to get spool along with e-mail or FAX

    Hi,
    I have a requirement where i have to produce a spool even i go for e-mail or FAX option when the script is triggered.
    I am using a standard program where it is coded to have either of the option. i.e. either we have to go for a printer or e-mail or FAX.
    Could any one suggest me how to get spool along with e-mail or FAX option.
    Thanks in advance.

    Hi,
    check this:-[http://help.sap.com/saphelp_nw04/helpdata/en/a5/28d3b9d26211d4b646006094192fe3/frameset.htm]
    hope u'll get some idea.
    Regards,
    Sneha.

  • I have a problem with mail.  the spelling and grammer check box before sending the messege is no longer there.  I did everything but cannot get it back.  is ther anyone who knows how to get the box with spelling and grammer checks before sending

    i have a problem with mail.  the spelling and grammer check box before sending the messege is no longer there.  I did everything but cannot get it back.  is ther anyone who knows how to get the box with spelling and grammer checks before sending the mail.
    Also the mail is acting very funny by not getting the rules work in a proper method.  Is ther a software to repair mail.

    i did both of them, but still the while sending the mail the diolog box is not showing up and also the spelling and grammer does not do the spelling check. 
    This problem just started for about 3 to 4 days now.  earlier it was working normally.

  • How to get the table with no. of records after filter in webdynpro

    Dear Gurus,
    How to get the table with no. of records after filter in webdynpro?
    Thanks in advance.
    Sankar

    Hello Sankar,
    Please explain your requirement clearly so that we can help you easily.
    To get the table records from your context node use method get_static_attributes_table()
    data lo_nd_mynode       type ref to if_wd_context_node. 
    data lt_atrributes_table  type wd_this->elements_mynode. 
    lo_nd_mynode = wd_context->get_child_node( name = wd_this->wdctx_mynode ). 
    lo_nd_mynode->get_static_attributes_table( importing table = lt_atrributes_table ). 
    Note: You should have already defined your context node as a Dictionary Structure.
    BR,
    RAM

  • I am just starting out in graphic design and I wanted to know how to get more involved with either adobe and or graphic design? I am really very interested in working with adobe and graphic design more and becoming more involved with both!!

    I am just starting out in graphic design and I wanted to know how to get more involved with either adobe and or graphic design? I am really very interested in working with adobe and graphic design more and becoming more involved with both!!

    I have now recently downloaded 10.0.2 which is confusing in itself, as, as far as I can ascertain that is actually version 11, but I'm not even sure about that.
    Version 10.0.2 is the newest version and the successor to GarageBand '11 (version 6.0.5).
    The '11 is referring to the iLife '11 suit of multimedia application - the older GarageBand was a part of this bundle.
    Have a look at Edgar's graphical enhanced manuals, the explain very detailed how things work and why. You can buy them as iBooks from the iBook store or directly from the page:
    http://DingDingMusic.com/Manuals/

  • How to get  Unapplied Amount with SQL or API in AR/ORACLE RECEIVABLES

    Hi ,
    how to get Unapplied Amount with SQL or API in AR/ORACLE RECEIVABLES.
    who can help me ? Thank you very much !

    i get it from private API.
    SELECT SUM(decode(ra.status, 'UNAPP', nvl(ra.amount_applied, 0), 0)) unapplied_amount
    FROM ar_receivable_applications ra
    WHERE ra.cash_receipt_id = 1820
    AND ra.status IN ('UNAPP', 'ACTIVITY')

  • How to get ALV Display with First column alone in sort

    How to get ALV Display with First column alone in sort

    HI,
    You can build Internal Table and send this to the parameter "IT_SORT".
    eg:
    "the sorting Internal Table structure is as whown below.
    DATA:  t_sort_info type slis_t_sortinfo_alv.
    "Build the Sort Internal Table
      t_sort_info-fieldname = 'CARRID'.
      t_sort_info-subtot = 'X'.
      append t_sort_info.
      t_sort_info-fieldname = 'FLDATE'.
      t_sort_info-subtot = 'X'.
      append t_sort_info.
    Then pass this "IT_SORT_INFO" table to the Function module "Reuse_alv_*". (Note send the body of the Internal table only like "<b>IT_SORT = IT_SORT_INFO[]</b>".
    Here i am making ALV output sorted on CARRID & FLDATE.
    You can specify only the First Column name for sorting.
    Regards,
    Manju
    Message was edited by:
            MANJUNATHA KS

  • How to get command history with timestamp ?

    how to get command history with timestamp ?

    If you are using bash:
    HISTTIMEFORMAT If this variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associated with each history entry displayed by the history builtin. If this variable is set, time stamps are written to the history file so they may be preserved across shell sessions.
    [SunOS 5.10/bash] [email protected]:/etc/ftpd
    # HISTTIMEFORMAT="%h/%m - %H:%M:%S ";export HISTTIMEFORMAT;history
        1  Aug/08 - 19:07:52 chmod a+rwx /root
        2  Aug/08 - 19:07:52 ll /
        3  Aug/08 - 19:07:52 tail -f /root/mylog.log
        4  Aug/08 - 19:07:52 vi /usr/dt/bin/Xsession
        5  Aug/08 - 19:07:52 cat /root/mylog.log
        6  Aug/08 - 19:07:52 ls /export/home/p661210/.dt
        7  Aug/08 - 19:07:52 ls -la  /export/home/p661210/.dt
        8  Aug/08 - 19:07:52 cat  /export/home/p661210/.dt/errorlog
        9  Aug/08 - 19:07:52 vi /usr/dt/config/C/sys.dtwmrc
       10  Aug/08 - 19:07:52 ls
       11  Aug/08 - 19:07:52 cat Xresources.jds
       12  Aug/08 - 19:07:52 vi /usr/dt
    [SunOS 5.10/bash] [email protected]:/etc/ftpd
    [SunOS 5.8/bash] root@wgls03:/root
    # HISTTIMEFORMAT="%h/%m - %H:%M:%S ";export HISTTIMEFORMAT;history
        1  Jul/07 - 09:02:21 vi /etc/vfstab
        2  Jul/07 - 09:02:21 mount /store
        3  Jul/07 - 09:02:21 cd /store/bnz
        4  Jul/07 - 09:02:21 ls
        5  Jul/07 - 09:02:21 ./BNZ_installBaseSoftware
        6  Jul/07 - 09:02:21 find /usr -name gunzipCheers,
    Andreas

  • How to get mpeg streamclip with mpeg 2 to work on Leopard and for fcp x?

    How to get mpeg streamclip with mpeg 2 to work on macbook with Leopard and VOB files?  Goal is to import into FCP X.
    mpeg used to download effectively and for free with fcp 7 but apparently not the case with fcp x.

    You need the MPEG-2 playback component. This is described in detail on the Squared5 web site.

  • How to get in touch with customer service?

    How to get in touch with customer service? Twice I had a chat and I would get an answer in a few days. Never heard a thing! I need an invoice for my book-keeping but I can't download it. It says: get in touch with the customer service. But I chatted for 2 times, tried to phone, They won't answer the phone. Where is the customer service!!!!!!!!!

    Hi Regine43b,
    Please refer to the following link for help with your monthly invoice: http://helpx.adobe.com/x-productkb/policy-pricing/print-creative-cloud-receipt.html
    If in case you still face issues, please contact support @ https://helpx.adobe.com/contact
    Regards,
    Sheena.

  • How to get QTP11 work with FF17. Unable to get Quicktest Proffessional11 plugin

    How to get QTP11 work with FF17. I have already installed Patch_090 and 0122.
    Unable to get Quicktest Proffessional11 plugin even after creating temp directory, into FF “extensions” directory.
    Please help

    If I may ask is there a recommended version of Firefox for the extension? [http://www.qatutorial.com/files/QTP_Install_Guide.pdf] is all I could find on how to install the software, is this the right add on?

Maybe you are looking for

  • Moving from a 4 to 4s

    hi all, just put old sim card from 4 into my new 4s. backed up from i cloud and transferred all data. noticed that my messages ..recieving and sending are showing up on my old phone will this stop when a new sim card goesin my old phone for my daught

  • How to put AVCHD and AVI formats in a timeline using Adobe production suite?

    I shot an event with two different types of cameras (AVCHD camera and tape camera with AVI output). I converted the video of avchd into 1080p first, then put it with the tape output together, the video was jittery. How can I put them together in a ti

  • Software under creation - what DOES that mean?

    Hi, I'm just curious, the belle availability information dated 7th Feb for my (fantastic) N8 shows that the software is "under Creation". What, exactly, does that mean?    How long does this process normally take?  Days, weeks, months?  Is the carrie

  • I can't download Lion in the app store

    It says in the app store that it is already installed. And obviously, I'm with snow leopard. Any idea how to show to the app store that I don't have Lion on my computer?

  • Retrieving Mail mailboxes from external drive

    I migrated my data from a Mac Pro running Mavericks to a new iMac running Yosemite. I did not export my Mail data from the Mavericks Mac Pro. Is there any way to access the mailboxes now? I have a copy of my Mac Pro (Mavericks) drive on an external d