From b8f3be093b6d55ff73545b532becedf85238773c Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 08 Oct 2008 14:58:55 +0000 Subject: Fix crash when pressing keys and cleanup frame instantiation a bit. --- diff --git a/bin/sugar-session b/bin/sugar-session index 9d7af69..ca1c02e 100644 --- a/bin/sugar-session +++ b/bin/sugar-session @@ -43,12 +43,10 @@ def uisetup_completed_cb(): def uisetup_delayed_cb(home_window): from jarabe.journal import journalactivity - from jarabe.view.keyhandler import KeyHandler - from jarabe.frame import frame + from jarabe.view import keyhandler + from jarabe import frame - frame = frame.get_instance() - - key_handler = KeyHandler(frame) + keyhandler.setup(frame.get_view()) journalactivity.start() diff --git a/src/jarabe/frame/__init__.py b/src/jarabe/frame/__init__.py index a9dd95a..d7aec3d 100644 --- a/src/jarabe/frame/__init__.py +++ b/src/jarabe/frame/__init__.py @@ -14,3 +14,12 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +from jarabe.frame.frame import Frame + +_view = None + +def get_view(): + global _view + if not _view: + _view = Frame() + return _view diff --git a/src/jarabe/frame/activitiestray.py b/src/jarabe/frame/activitiestray.py index 63dd327..157d73e 100644 --- a/src/jarabe/frame/activitiestray.py +++ b/src/jarabe/frame/activitiestray.py @@ -39,7 +39,7 @@ from jarabe.view.palettes import JournalPalette, CurrentActivityPalette from jarabe.view.pulsingicon import PulsingIcon from jarabe.frame.frameinvoker import FrameWidgetInvoker from jarabe.frame.notification import NotificationIcon -import jarabe.frame.frame +import jarabe.frame class ActivityButton(RadioToolButton): def __init__(self, home_activity, group): @@ -98,7 +98,7 @@ class BaseInviteButton(ToolButton): def __clicked_cb(self, button): if self._notif_icon is not None: - frame = jarabe.frame.frame.get_instance() + frame = jarabe.frame.get_view() frame.remove_notification(self._notif_icon) self._notif_icon = None self._launch() @@ -108,7 +108,7 @@ class BaseInviteButton(ToolButton): raise NotImplementedError def __destroy_cb(self, button): - frame = jarabe.frame.frame.get_instance() + frame = jarabe.frame.get_view() frame.remove_notification(self._notif_icon) class ActivityInviteButton(BaseInviteButton): @@ -145,9 +145,9 @@ class ActivityInviteButton(BaseInviteButton): palette.set_group_id('frame') self._notif_icon.palette = palette - frame = jarabe.frame.frame.get_instance() + frame = jarabe.frame.get_view() frame.add_notification(self._notif_icon, - jarabe.frame.frame.TOP_LEFT) + gtk.CORNER_TOP_LEFT) def _launch(self): """Join the activity in the invite.""" @@ -192,9 +192,9 @@ class PrivateInviteButton(BaseInviteButton): palette.set_group_id('frame') self._notif_icon.palette = palette - frame = jarabe.frame.frame.get_instance() + frame = jarabe.frame.get_view() frame.add_notification(self._notif_icon, - jarabe.frame.frame.TOP_LEFT) + gtk.CORNER_TOP_LEFT) def _launch(self): """Start the activity with private channel.""" diff --git a/src/jarabe/frame/clipboardicon.py b/src/jarabe/frame/clipboardicon.py index 266e9a8..6c744ca 100644 --- a/src/jarabe/frame/clipboardicon.py +++ b/src/jarabe/frame/clipboardicon.py @@ -27,7 +27,7 @@ from jarabe.frame import clipboard from jarabe.frame.clipboardmenu import ClipboardMenu from jarabe.frame.frameinvoker import FrameWidgetInvoker from jarabe.frame.notification import NotificationIcon -import jarabe.frame.frame +import jarabe.frame class ClipboardIcon(RadioToolButton): __gtype_name__ = 'SugarClipboardIcon' @@ -123,9 +123,9 @@ class ClipboardIcon(RadioToolButton): self._notif_icon.props.xo_color = \ XoColor('%s,%s' % (self._icon.props.stroke_color, self._icon.props.fill_color)) - frame = jarabe.frame.frame.get_instance() + frame = jarabe.frame.get_view() frame.add_notification(self._notif_icon, - jarabe.frame.frame.BOTTOM_LEFT) + gtk.CORNER_BOTTOM_LEFT) self._current_percent = cb_object.get_percent() def _notify_active_cb(self, widget, pspec): diff --git a/src/jarabe/frame/frame.py b/src/jarabe/frame/frame.py index 7a60ba4..49574f8 100644 --- a/src/jarabe/frame/frame.py +++ b/src/jarabe/frame/frame.py @@ -275,20 +275,20 @@ class Frame(object): def notify_key_press(self): self._key_listener.key_press() - def add_notification(self, icon, corner=TOP_LEFT): + def add_notification(self, icon, corner=gtk.CORNER_TOP_LEFT): if not isinstance(icon, NotificationIcon): raise TypeError('icon must be a NotificationIcon.') window = NotificationWindow() screen = gtk.gdk.screen_get_default() - if corner == TOP_LEFT: + if corner == gtk.CORNER_TOP_LEFT: window.move(0, 0) - elif corner == TOP_RIGHT: + elif corner == gtk.CORNER_TOP_RIGHT: window.move(screen.get_width() - style.GRID_CELL_SIZE, 0) - elif corner == BOTTOM_LEFT: + elif corner == gtk.CORNER_BOTTOM_LEFT: window.move(0, screen.get_height() - style.GRID_CELL_SIZE) - elif corner == BOTTOM_RIGHT: + elif corner == gtk.CORNER_BOTTOM_RIGHT: window.move(screen.get_width() - style.GRID_CELL_SIZE, screen.get_height() - style.GRID_CELL_SIZE) else: @@ -316,12 +316,3 @@ class Frame(object): del self._notif_by_icon[icon] visible = property(is_visible, None) - -_instance = None - -def get_instance(): - global _instance - if not _instance: - _instance = Frame() - return _instance - diff --git a/src/jarabe/view/keyhandler.py b/src/jarabe/view/keyhandler.py index 48c7696..1c33f44 100644 --- a/src/jarabe/view/keyhandler.py +++ b/src/jarabe/view/keyhandler.py @@ -94,7 +94,7 @@ class KeyHandler(object): self._key_grabber.connect('key-released', self._key_released_cb) - self._tabbing_handler = TabbingHandler(_TABBING_MODIFIER) + self._tabbing_handler = TabbingHandler(self._frame, _TABBING_MODIFIER) self._key_grabber.grab_keys(_actions_table.keys()) @@ -322,3 +322,12 @@ class KeyHandler(object): return True return False +_instance = None + +def setup(frame): + global _instance + + if _instance: + del _instance + + _instance = KeyHandler(frame) diff --git a/src/jarabe/view/tabbinghandler.py b/src/jarabe/view/tabbinghandler.py index e86d0de..87a36a1 100644 --- a/src/jarabe/view/tabbinghandler.py +++ b/src/jarabe/view/tabbinghandler.py @@ -18,17 +18,16 @@ import logging import gtk import gobject -from jarabe.frame import frame from jarabe.model import shell _RAISE_DELAY = 250 class TabbingHandler(object): - def __init__(self, modifier): + def __init__(self, frame, modifier): + self._frame = frame self._tabbing = False self._modifier = modifier self._timeout = None - self._frame = frame.get_instance() def _start_tabbing(self): if not self._tabbing: -- cgit v0.9.1