File: aligned_window.py

package info (click to toggle)
gnome-blog 0.8-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,172 kB
  • ctags: 144
  • sloc: sh: 3,172; python: 1,144; makefile: 131; xml: 8
file content (51 lines) | stat: -rw-r--r-- 1,679 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gtk

class AlignedWindow(gtk.Window):

    def __init__(self, widgetToAlignWith):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.set_decorated(gtk.FALSE)
        
        self.widgetToAlignWith = widgetToAlignWith

    def positionWindow(self):
        # Get our own dimensions & position
        self.realize()
        gtk.gdk.flush()
        ourWidth  = (self.window.get_geometry())[2]
        ourHeight = (self.window.get_geometry())[3]

	# Skip the taskbar, and the pager, stick and stay on top
	self.stick()
	# not wrapped self.set_skip_taskbar_hint(gtk.TRUE)
	# not wrapped self.set_skip_pager_hint(gtk.TRUE)
	self.set_type_hint (gtk.gdk.WINDOW_TYPE_HINT_DOCK)

        # Get the dimensions/position of the widgetToAlignWith
        self.widgetToAlignWith.realize()
	entryX, entryY = self.widgetToAlignWith.window.get_origin()
        entryWidth  = (self.widgetToAlignWith.window.get_geometry())[2]
        entryHeight = (self.widgetToAlignWith.window.get_geometry())[3]

        # Get the screen dimensions
        screenHeight = gtk.gdk.screen_height()
        screenWidth = gtk.gdk.screen_width()

        if entryX + ourWidth < screenWidth:
            # Align to the left of the entry
            newX = entryX
        else:
            # Align to the right of the entry
            newX = (entryX + entryWidth) - ourWidth

        if entryY + entryHeight + ourHeight < screenHeight:
            # Align to the bottom of the entry
            newY = entryY + entryHeight
        else:
            newY = entryY - ourHeight

        # -"Coordinates locked in captain."
        # -"Engage."
        self.move(newX, newY)
        self.show()