From 2b6ed52cd97a1e66a6b68f5ebebc490fdcf5b946 Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Mon, 23 Jun 2008 20:14:32 +0800 Subject: [PATCH] Add menu.py --- panel/Makefile.am | 1 + panel/languagebar.py | 4 ++-- panel/menu.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ panel/panel.py | 4 ++-- 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 panel/menu.py diff --git a/panel/Makefile.am b/panel/Makefile.am index 1418bd4..210ac6a 100644 --- a/panel/Makefile.am +++ b/panel/Makefile.am @@ -26,6 +26,7 @@ panel_PYTHON = \ lang.py \ languagebar.py \ main.py \ + menu.py \ panel.py \ $(NULL) diff --git a/panel/languagebar.py b/panel/languagebar.py index f1497e0..45fc404 100644 --- a/panel/languagebar.py +++ b/panel/languagebar.py @@ -25,7 +25,7 @@ import gobject import ibus from image import Image from handle import Handle -import menu +from menu import menu_position ICON_SIZE = gtk.ICON_SIZE_MENU @@ -209,7 +209,7 @@ class LanguageBar (gtk.Toolbar): self.emit ("property-activate", prop._name, prop._state) def _property_menu_clicked (self, widget, prop, menu): - menu.popup (None, None, menu.menu_position, + menu.popup (None, None, menu_position, 0, gtk.get_current_event_time (), widget) gobject.type_register (LanguageBar, "IBusLanguageBar") 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 +# +# 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) + diff --git a/panel/panel.py b/panel/panel.py index a7a6194..8f187e8 100644 --- a/panel/panel.py +++ b/panel/panel.py @@ -28,7 +28,7 @@ from lang import LANGUAGES from ibus import interface from languagebar import LanguageBar from candidatepanel import CandidatePanel -import menu +from menu import menu_position class Panel (ibus.Object): def __init__ (self, proxy, _ibus): @@ -135,7 +135,7 @@ class Panel (ibus.Object): def _im_menu_popup_cb (self, languagebar, button): menu = self._create_im_menu () menu.popup (None, None, - menu.menu_position, + menu_position, 0, gtk.get_current_event_time (), button) -- 2.7.4