sugar-toolkit-gtk3/shell/view/frame/Frame.py

169 lines
4.3 KiB
Python
Raw Normal View History

2006-08-23 11:52:18 +02:00
import gtk
import gobject
2006-09-07 15:11:51 +02:00
import goocanvas
import wnck
2006-08-23 11:52:18 +02:00
2006-09-15 13:23:21 +02:00
from view.frame.BottomPanel import BottomPanel
from view.frame.RightPanel import RightPanel
from view.frame.TopPanel import TopPanel
from view.frame.PanelWindow import PanelWindow
from sugar.canvas.Grid import Grid
from sugar.canvas.MenuShell import MenuShell
2006-08-23 11:52:18 +02:00
class EventFrame(gobject.GObject):
__gsignals__ = {
'hover': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([])),
}
def __init__(self):
gobject.GObject.__init__(self)
self._windows = []
invisible = self._create_invisible(0, 0, gtk.gdk.screen_width(), 1)
self._windows.append(invisible)
invisible = self._create_invisible(0, 0, 1, gtk.gdk.screen_height())
self._windows.append(invisible)
invisible = self._create_invisible(gtk.gdk.screen_width() - 1, 0,
gtk.gdk.screen_width(),
gtk.gdk.screen_height())
self._windows.append(invisible)
invisible = self._create_invisible(0, gtk.gdk.screen_height() - 1,
gtk.gdk.screen_width(),
gtk.gdk.screen_height())
self._windows.append(invisible)
screen = wnck.screen_get_default()
screen.connect('active-window-changed',
self._active_window_changed_cb)
def _create_invisible(self, x, y, width, height):
invisible = gtk.Invisible()
invisible.connect('enter-notify-event', self._enter_notify_cb)
invisible.realize()
invisible.window.set_events(gtk.gdk.ENTER_NOTIFY_MASK)
invisible.window.move_resize(x, y, width, height)
return invisible
def _enter_notify_cb(self, widget, event):
self.emit('hover')
def show(self):
for window in self._windows:
window.show()
def hide(self):
for window in self._windows:
window.hide()
def _active_window_changed_cb(self, screen):
for window in self._windows:
window.window.raise_()
2006-09-01 15:11:52 +02:00
class Frame:
def __init__(self, shell):
2006-09-07 15:11:51 +02:00
self._windows = []
self._shell = shell
self._hide_timeout = 0
2006-09-07 15:11:51 +02:00
model = goocanvas.CanvasModelSimple()
root = model.get_root_item()
2006-09-07 15:11:51 +02:00
grid = shell.get_grid()
self._menu_shell = MenuShell(grid)
self._menu_shell.connect('activated', self._menu_shell_activated_cb)
self._menu_shell.connect('deactivated', self._menu_shell_deactivated_cb)
2006-08-23 11:52:18 +02:00
2006-09-14 15:07:22 +02:00
bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0)
grid.set_constraints(bg, 0, 0, 80, 60)
root.add_child(bg)
2006-09-01 15:33:55 +02:00
panel = BottomPanel(shell)
grid.set_constraints(panel, 5, 55)
root.add_child(panel)
2006-09-07 15:11:51 +02:00
self._add_panel(model, 0, 55, 80, 5)
2006-09-08 01:13:42 +02:00
panel = TopPanel(shell, self._menu_shell)
root.add_child(panel)
2006-09-08 01:13:42 +02:00
self._add_panel(model, 0, 0, 80, 5)
panel = RightPanel(shell, self._menu_shell)
grid.set_constraints(panel, 75, 5)
root.add_child(panel)
2006-09-07 15:11:51 +02:00
self._add_panel(model, 75, 5, 5, 50)
self._add_panel(model, 0, 5, 5, 50)
self._event_frame = EventFrame()
self._event_frame.connect('hover', self._event_frame_hover_cb)
self._event_frame.show()
def _add_panel(self, model, x, y, width, height):
grid = self._shell.get_grid()
panel_window = PanelWindow(grid, model, x, y, width, height)
panel_window.connect('enter-notify-event', self._enter_notify_cb)
panel_window.connect('leave-notify-event', self._leave_notify_cb)
2006-09-08 00:51:45 +02:00
self._windows.append(panel_window)
2006-08-28 16:53:29 +02:00
def _menu_shell_activated_cb(self, menu_shell):
self._cancel_hide()
def _menu_shell_deactivated_cb(self, menu_shell):
self._hide_after(500)
def _enter_notify_cb(self, window, event):
self._cancel_hide()
def _leave_notify_cb(self, window, event):
# FIXME for some reason every click cause also a leave-notify
if event.state == gtk.gdk.BUTTON1_MASK:
return
if not self._menu_shell.is_active():
self._hide_after(500)
def _event_frame_hover_cb(self, event_frame):
self.show()
def _hide_timeout_cb(self):
self.hide()
return False
def _cancel_hide(self):
if self._hide_timeout > 0:
gobject.source_remove(self._hide_timeout)
def _hide_after(self, ms):
self._cancel_hide()
self._hide_timeout = gobject.timeout_add(ms, self._hide_timeout_cb)
def show_and_hide(self, seconds):
self.show()
self._hide_after(seconds * 1000)
2006-08-28 16:53:29 +02:00
def show(self):
2006-09-07 15:11:51 +02:00
for panel in self._windows:
2006-09-01 15:33:55 +02:00
panel.show()
self._event_frame.hide()
2006-08-28 16:53:29 +02:00
def hide(self):
2006-09-07 15:11:51 +02:00
for panel in self._windows:
2006-09-01 15:33:55 +02:00
panel.hide()
self._event_frame.show()
2006-08-23 11:52:18 +02:00
2006-08-28 16:53:29 +02:00
def toggle_visibility(self):
if self._windows[0].props.visible:
self.hide()
else:
self.show()