diff --git a/sugar/shell/WindowManager.py b/sugar/shell/WindowManager.py new file mode 100644 index 00000000..8b8720ee --- /dev/null +++ b/sugar/shell/WindowManager.py @@ -0,0 +1,83 @@ +import pygtk +pygtk.require('2.0') +import gtk + +class WindowManager: + __managers_list = [] + + CENTER = 0 + LEFT = 1 + RIGHT = 2 + BOTTOM = 3 + + ABSOLUTE = 0 + SCREEN_RELATIVE = 1 + + def __init__(self, window): + self._window = window + + WindowManager.__managers_list.append(self) + + window.connect("key-press-event", self.__key_press_event_cb) + + def __key_press_event_cb(self, window, event): + manager = None + + if event.keyval == gtk.keysyms.Left and \ + event.state & gtk.gdk.CONTROL_MASK: + for wm in WindowManager.__managers_list: + if wm._position == WindowManager.LEFT: + manager = wm + + if manager and manager._window.get_property('visible'): + manager.slide_window_out() + elif manager: + manager.slide_window_in() + + def set_width(self, width, width_type): + self._width = width + self._width_type = width_type + + def set_height(self, height, height_type): + self._height = height + self._height_type = height_type + + def set_position(self, position): + self._position = position + + def _update_size_and_position(self): + screen_width = self._window.get_screen().get_width() + screen_height = self._window.get_screen().get_height() + + if self._width_type is WindowManager.ABSOLUTE: + width = self._width + elif self._width_type is WindowManager.SCREEN_RELATIVE: + width = screen_width * self._width + + if self._height_type is WindowManager.ABSOLUTE: + height = self._height + elif self._height_type is WindowManager.SCREEN_RELATIVE: + height = screen_height * self._height + + if self._position is WindowManager.CENTER: + x = (screen_width - width) / 2 + y = (screen_height - height) / 2 + elif self._position is WindowManager.LEFT: + x = 0 + y = (screen_height - height) / 2 + + self._window.move(x, y) + self._window.resize(width, height) + + def slide_window_in(self): + self._window.show() + + def slide_window_out(self): + self._window.hide() + + def show_window(self): + self._update_size_and_position() + self._window.show() + + def hide_window(self): + self._window.hide() diff --git a/sugar/shell/shell.py b/sugar/shell/shell.py index 12a3396d..da1031a1 100755 --- a/sugar/shell/shell.py +++ b/sugar/shell/shell.py @@ -11,6 +11,7 @@ import sugar.util from sugar.shell.PresenceWindow import PresenceWindow from sugar.shell.Owner import ShellOwner from sugar.shell.StartPage import StartPage +from sugar.shell.WindowManager import WindowManager class ActivityHost(dbus.service.Object): @@ -223,8 +224,6 @@ class ActivityContainer(dbus.service.Object): self.window = gtk.Window() self.window.set_title("OLPC Sugar") - self.window.resize(640, 480) - self.window.set_geometry_hints(min_width = 640, max_width = 640, min_height = 480, max_height = 480) self.notebook = gtk.Notebook() tab_label = gtk.Label("Everyone") @@ -375,7 +374,18 @@ def main(): activity_container.show() presence_window = PresenceWindow(activity_container) - presence_window.show() + + wm = WindowManager(presence_window) + wm.set_width(0.15, WindowManager.SCREEN_RELATIVE) + wm.set_height(1.0, WindowManager.SCREEN_RELATIVE) + wm.set_position(WindowManager.LEFT) + wm.show_window() + + wm = WindowManager(activity_container.window) + wm.set_width(640, WindowManager.ABSOLUTE) + wm.set_height(480, WindowManager.ABSOLUTE) + wm.set_position(WindowManager.CENTER) + wm.show_window() console.set_parent_window(activity_container.window)