summaryrefslogtreecommitdiffstats
path: root/panel/menu.py
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2008-06-23 20:14:32 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2008-06-23 20:14:32 +0800
commit2b6ed52cd97a1e66a6b68f5ebebc490fdcf5b946 (patch)
treee98a7cc510765bd3525ad9d7eba3780573ace9aa /panel/menu.py
parent57877ac31e28b94cacb5c4b45974bed1b1381f7b (diff)
downloadibus-2b6ed52cd97a1e66a6b68f5ebebc490fdcf5b946.tar.gz
ibus-2b6ed52cd97a1e66a6b68f5ebebc490fdcf5b946.tar.xz
ibus-2b6ed52cd97a1e66a6b68f5ebebc490fdcf5b946.zip
Add menu.py
Diffstat (limited to 'panel/menu.py')
-rw-r--r--panel/menu.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/panel/menu.py b/panel/menu.py
new file mode 100644
index 0000000..f57cc95
--- /dev/null
+++ b/panel/menu.py
@@ -0,0 +1,54 @@
+# vim:set noet ts=4:
+#
+# ibus - The Input Bus
+#
+# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+# Boston, MA 02111-1307 USA
+
+def menu_position (menu, button):
+ screen = button.get_screen ()
+ monitor = screen.get_monitor_at_window (button.window)
+ monitor_allocation = screen.get_monitor_geometry (monitor)
+
+ x, y = button.window.get_origin ()
+ x += button.allocation.x
+ y += button.allocation.y
+
+ menu_width, menu_height = menu.size_request ()
+
+ if x + menu_width >= monitor_allocation.width:
+ x -= menu_width - button.allocation.width
+ elif x - menu_width <= 0:
+ pass
+ else:
+ if x <= monitor_allocation.width * 3 / 4:
+ pass
+ else:
+ x -= menu_width - button.allocation.width
+
+ if y + button.allocation.height + menu_height >= monitor_allocation.height:
+ y -= menu_height
+ elif y - menu_height <= 0:
+ y += button.allocation.height
+ else:
+ if y <= monitor_allocation.height * 3 / 4:
+ y += button.allocation.height
+ else:
+ y -= menu_height
+
+ return (x, y, False)
+