Welcome, guest | Sign In | My Account | Store | Cart

In Windows explorer the user can choose to have the taskbar field on any of the for sides of the screen (i.e top, bottom, left or right). This means that code that needs to display windows relative to this selection has to know where the taskbar is placed.

This little procedure finds the position of the taskbar field and returns "top", "bottom", "left" or "right" depending on the choice of the user.

Python, 13 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import wx

def getTaskbarPos():
    d_w, d_h = wx.DisplaySize()
    c_x, c_y, c_w, c_h = wx.ClientDisplayRect()
                        
    l = [(c_y, "top"), (d_h - c_y - c_h, "bottom"), (c_x, "left"), (d_w - c_x - c_w, "right")]
    def sorter(a,b):
        if a[0]<b[0] : return 1
        if a[0]>b[0] : return -1
        return 0
    l.sort(sorter)
    return l[0][1]

In my specific case I needed to know where the taskbar was placed so that I could display a borderless information window just above my application's TaskBarIcon. It took me some time to find out how to do it and that is why I'm writing this recipe.

I have tested this in Python 2.4.1 with wxPython 2.6.1.0 on Windows XP SP2, but the same technique will probably work with the X window managers as well.

2 comments

Stephen McDonald 14 years, 11 months ago  # | flag

Unfortunately this works for Windows only. On Linux, gnome-panel is ignored by wx.ClientDisplayRect() and 0,0 coordinates along with the full resolution is returned regardless of its position.

This is rather unfortunate as it's exactly what I've been looking for over the past few hours.

Also on both Linux and Windows, the above code fails if wx.App() has not been instantiated.

wxPython 2.8.0.1

Python 2.4.3 (#2, Oct 6 2006, 07:52:30)

[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2

Stephen McDonald 14 years, 11 months ago  # | flag

The closet I've come so far is calling frame.Maximize() and frame.GetRect() which gives the desired output, but this requires the frame being shown in its maximized state which obviously isn't desirable.

Created by Jan Persson on Tue, 5 Jul 2005 (PSF)
Python recipes (4591)
Jan Persson's recipes (1)

Required Modules

Other Information and Tasks