Refactor the window API a bit to make it more flexible.

This commit is contained in:
Marco Pesenti Gritti 2007-04-27 10:51:19 +02:00
parent 9dcfcf89e9
commit 9ccda70199
4 changed files with 56 additions and 55 deletions

View File

@ -19,7 +19,6 @@ import hippo
import cairo
from sugar.graphics.menushell import MenuShell
from sugar.graphics.window import Window
from sugar.graphics import units
import sugar
@ -33,13 +32,18 @@ _FRIENDS_PAGE = 1
_MESH_PAGE = 2
_TRANSITION_PAGE = 3
class HomeWindow(Window):
class HomeWindow(gtk.Window):
def __init__(self, shell):
Window.__init__(self)
gtk.Window.__init__(self)
self._shell = shell
self._active = False
self._level = sugar.ZOOM_HOME
self._canvas = hippo.Canvas()
self.add(self._canvas)
self._canvas.show()
self.set_default_size(gtk.gdk.screen_width(),
gtk.gdk.screen_height())
@ -54,7 +58,7 @@ class HomeWindow(Window):
self._mesh_box = MeshBox(shell, MenuShell(self))
self._transition_box = TransitionBox()
self.canvas.set_root(self._home_box)
self._canvas.set_root(self._home_box)
self._transition_box.connect('completed',
self._transition_completed_cb)
@ -81,7 +85,7 @@ class HomeWindow(Window):
def set_zoom_level(self, level):
self._level = level
self.canvas.set_root(self._transition_box)
self._canvas.set_root(self._transition_box)
if level == sugar.ZOOM_HOME:
scale = units.XLARGE_ICON_SCALE
@ -94,11 +98,11 @@ class HomeWindow(Window):
def _transition_completed_cb(self, transition_box):
if self._level == sugar.ZOOM_HOME:
self.canvas.set_root(self._home_box)
self._canvas.set_root(self._home_box)
elif self._level == sugar.ZOOM_FRIENDS:
self.canvas.set_root(self._friends_box)
self._canvas.set_root(self._friends_box)
elif self._level == sugar.ZOOM_MESH:
self.canvas.set_root(self._mesh_box)
self._canvas.set_root(self._mesh_box)
self._update_mesh_state()

View File

@ -28,7 +28,30 @@ import gtk
from sugar.presence import presenceservice
from sugar.activity.activityservice import ActivityService
from sugar.graphics.window import Window
from sugar.graphics.toolbox import ActivityToolbar
from sugar.graphics.toolbox import Toolbox
from sugar.graphics.toolbutton import ToolButton
class ActivityToolbar(gtk.Toolbar):
def __init__(self, activity):
gtk.Toolbar.__init__(self)
self._activity = activity
button = ToolButton('window-close')
button.connect('clicked', self._close_button_clicked_cb)
self.insert(button, -1)
button.show()
def _close_button_clicked_cb(self, button):
self._activity.destroy()
class ActivityToolbox(Toolbox):
def __init__(self, activity):
Toolbox.__init__(self)
activity_toolbar = ActivityToolbar(activity)
self.add_toolbar('Activity', activity_toolbar)
activity_toolbar.show()
class Activity(Window, gtk.Container):
"""Base Activity class that all other Activities derive from."""
@ -70,11 +93,6 @@ class Activity(Window, gtk.Container):
self._bus = ActivityService(self)
activity_toolbar = ActivityToolbar()
self.toolbox.add_toolbar('Activity', activity_toolbar)
activity_toolbar.connect('close', self._activity_toolbar_close_cb)
activity_toolbar.show()
def get_service_name(self):
"""Gets the activity service name."""
return os.environ['SUGAR_BUNDLE_SERVICE_NAME']
@ -94,9 +112,6 @@ class Activity(Window, gtk.Container):
self._service.join()
self.present()
def _activity_toolbar_close_cb(self, activity_toolbar):
self.destroy()
def _share_cb(self, ps, success, service, err):
self._pservice.disconnect(self._share_sigid)
self._share_sigid = None

View File

@ -33,20 +33,3 @@ class Toolbox(gtk.VBox):
def add_toolbar(self, name, toolbar):
self._notebook.append_page(toolbar, gtk.Label(name))
class ActivityToolbar(gtk.Toolbar):
__gsignals__ = {
'close': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([])),
}
def __init__(self):
gtk.Toolbar.__init__(self)
button = ToolButton('window-close')
button.connect('clicked', self._close_button_clicked_cb)
self.insert(button, -1)
button.show()
def _close_button_clicked_cb(self, button):
self.emit('close')

View File

@ -18,38 +18,37 @@
import gtk
import hippo
from sugar.graphics.toolbox import Toolbox
class Window(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
self.connect('realize', self._window_realize_cb)
vbox = gtk.VBox()
self.add(vbox)
self.toolbox = None
self.canvas = None
self.toolbox = Toolbox()
vbox.pack_start(self.toolbox, False)
self.toolbox.show()
self._canvas_box = gtk.VBox()
vbox.pack_start(self._canvas_box)
self._canvas_box.show()
self.canvas = hippo.Canvas()
self._canvas_box.pack_start(self.canvas)
self.canvas.show()
vbox.show()
self._vbox = gtk.VBox()
self.add(self._vbox)
self._vbox.show()
def set_canvas(self, canvas):
if self.canvas:
self._canvas_box.remove(self.canvas)
self._vbox.remove(self.canvas)
self._vbox.pack_start(canvas)
self._vbox.reorder_child(canvas, -1)
self._canvas_box.add(canvas)
self.canvas = canvas
def set_toolbox(self, toolbox):
if self.toolbox:
self._vbox.remove(self.toolbox)
self._vbox.pack_start(toolbox, False)
self._vbox.reorder_child(toolbox, 0)
self.toolbox = toolbox
def _window_realize_cb(self, window):
group = gtk.Window()
group.realize()