Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Drake <dsd@laptop.org>2011-10-30 15:23:57 (GMT)
committer Daniel Drake <dsd@laptop.org>2011-10-30 15:23:57 (GMT)
commit13dc438894b74606c358c369472a7988fe500b82 (patch)
tree76cfd4689454b2e8210fdb7b204c0f9356797ce1
parent49af0f023ef7c5c1bcfbd99f989070d4a981a33f (diff)
parentfdb0daa01d20535a7b87cfd2c9c3be019cb20e9f (diff)
Merge branch 'master' of git.sugarlabs.org:~erikos/sugar-toolkit/sugar-toolkit-gtk3
-rw-r--r--src/sugar3/graphics/alert.py2
-rw-r--r--src/sugar3/graphics/palette.py65
-rw-r--r--src/sugar3/graphics/palettewindow.py175
-rw-r--r--src/sugar3/graphics/toolbarbox.py2
4 files changed, 127 insertions, 117 deletions
diff --git a/src/sugar3/graphics/alert.py b/src/sugar3/graphics/alert.py
index f72a2bd..239afc2 100644
--- a/src/sugar3/graphics/alert.py
+++ b/src/sugar3/graphics/alert.py
@@ -342,7 +342,7 @@ class _TimeoutIcon(Gtk.Alignment):
__gtype_name__ = 'SugarTimeoutIcon'
def __init__(self):
- GObject.GObject.__init__(self, 0, 0, 1, 1)
+ Gtk.Alignment.__init__(self, xalign=0, yalign=0, xscale=1, yscale=1)
self.set_app_paintable(True)
self._text = Gtk.Label()
self._text.set_alignment(0.5, 0.5)
diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py
index 4e9ee71..7a2dcc7 100644
--- a/src/sugar3/graphics/palette.py
+++ b/src/sugar3/graphics/palette.py
@@ -29,7 +29,7 @@ from sugar3.graphics import palettegroup
from sugar3.graphics import animator
from sugar3.graphics import style
from sugar3.graphics.icon import Icon
-from sugar3.graphics.palettewindow import PaletteWindow
+from sugar3.graphics import palettewindow
# DEPRECATED
# Import these for backwards compatibility
@@ -37,10 +37,14 @@ from sugar3.graphics.palettewindow import MouseSpeedDetector, Invoker, \
WidgetInvoker, CanvasInvoker, ToolInvoker, CellRendererInvoker
-class Palette(PaletteWindow):
+class Palette(palettewindow.PaletteWindow):
PRIMARY = 0
SECONDARY = 1
+ __gsignals__ = {
+ 'activate': (GObject.SignalFlags.RUN_FIRST, None, ([])),
+ }
+
__gtype_name__ = 'SugarPalette'
def __init__(self, label=None, accel_path=None,
@@ -48,6 +52,9 @@ class Palette(PaletteWindow):
# DEPRECATED: label is passed with the primary-text property,
# accel_path is set via the invoker property
+ self.widget = palettewindow._PaletteWindowWidget()
+
+
self._primary_text = None
self._secondary_text = None
self._icon = None
@@ -100,10 +107,7 @@ class Palette(PaletteWindow):
self._secondary_anim.add(_SecondaryAnimation(self))
# we init after initializing all of our containers
- PaletteWindow.__init__(self, **kwargs)
-
- primary_box.set_size_request(-1, style.GRID_CELL_SIZE
- - 2 * self.get_border_width())
+ palettewindow.PaletteWindow.__init__(self, **kwargs)
self._full_request = [0, 0]
self._content = None
@@ -118,23 +122,17 @@ class Palette(PaletteWindow):
self._secondary_box.pack_start(self.action_bar, True, True, 0)
self.action_bar.show()
- self.add(palette_box)
+ self.widget.add(palette_box)
palette_box.show()
- self.connect('realize', self.__realize_cb)
- self.connect('hide', self.__hide_cb)
self.connect('notify::invoker', self.__notify_invoker_cb)
- self.connect('destroy', self.__destroy_cb)
+ self.widget.connect('realize', self.__realize_cb)
+ self.widget.connect('hide', self.__hide_cb)
+ self.widget.connect('destroy', self.__destroy_cb)
def _invoker_right_click_cb(self, invoker):
self.popup(immediate=True, state=self.SECONDARY)
- def do_style_set(self, previous_style):
- # Prevent a warning from pygtk
- if previous_style is not None:
- Gtk.Window.do_style_set(self, previous_style)
- self.set_border_width(self.get_style().xthickness)
-
def __destroy_cb(self, palette):
self._secondary_anim.stop()
self.popdown(immediate=True)
@@ -159,7 +157,7 @@ class Palette(PaletteWindow):
if self._invoker is not None:
self._update_full_request()
- PaletteWindow.popup(self, immediate)
+ palettewindow.PaletteWindow.popup(self, immediate)
if state is None:
state = self.PRIMARY
@@ -175,10 +173,10 @@ class Palette(PaletteWindow):
self._secondary_anim.stop()
# to suppress glitches while later re-opening
self.set_palette_state(self.PRIMARY)
- PaletteWindow.popdown(self, immediate)
+ palettewindow.PaletteWindow.popdown(self, immediate)
def on_enter(self, event):
- PaletteWindow.on_enter(self, event)
+ palettewindow.PaletteWindow.on_enter(self, event)
self._secondary_anim.start()
def _add_content(self):
@@ -288,17 +286,18 @@ class Palette(PaletteWindow):
self._update_accept_focus()
self._update_separators()
- def do_size_request(self, requisition):
- PaletteWindow.do_size_request(self, requisition)
+ # We need to figure out how to do the size request with GTK+ 3.
+# def do_size_request(self, requisition):
+# palettewindow.PaletteWindow.do_size_request(self, requisition)
- # Gtk.AccelLabel request doesn't include the accelerator.
- label_width = self._label_alignment.size_request()[0] + \
- self._label.get_accel_width() + \
- 2 * self.get_border_width()
+# # Gtk.AccelLabel request doesn't include the accelerator.
+# label_width = self._label_alignment.size_request()[0] + \
+# self._label.get_accel_width() + \
+# 2 * self.get_border_width()
- requisition.width = max(requisition.width,
- label_width,
- self._full_request[0])
+# requisition.width = max(requisition.width,
+# label_width,
+# self._full_request[0])
def _update_separators(self):
visible = self._content.get_children()
@@ -306,9 +305,7 @@ class Palette(PaletteWindow):
def _update_accept_focus(self):
accept_focus = len(self._content.get_children())
- win = self.get_window()
- if win:
- win.set_accept_focus(accept_focus)
+ self.widget.set_accept_focus(accept_focus)
def __realize_cb(self, widget):
self._update_accept_focus()
@@ -317,7 +314,7 @@ class Palette(PaletteWindow):
if self._palette_state == self.PRIMARY:
self._secondary_box.show()
- self._full_request = self.size_request()
+ self._full_request = self.widget.size_request()
if self._palette_state == self.PRIMARY:
self._secondary_box.hide()
@@ -357,3 +354,7 @@ class _SecondaryAnimation(animator.Animation):
def next_frame(self, current):
if current == 1.0:
self._palette.set_palette_state(Palette.SECONDARY)
+
+
+
+
diff --git a/src/sugar3/graphics/palettewindow.py b/src/sugar3/graphics/palettewindow.py
index f500d12..3406a10 100644
--- a/src/sugar3/graphics/palettewindow.py
+++ b/src/sugar3/graphics/palettewindow.py
@@ -65,6 +65,77 @@ def _calculate_gap(a, b):
return False
+class _PaletteWindowWidget(Gtk.Window):
+
+ def __init__(self):
+ Gtk.Window.__init__(self)
+
+ self.set_decorated(False)
+ self.set_resizable(False)
+ self.set_position(Gtk.WindowPosition.NONE)
+
+ # TODO: How to implement this with GtkStyle/the theme
+ # Do not forget theme changes.
+ #self.set_border_width(self.get_style().xthickness)
+
+ accel_group = Gtk.AccelGroup()
+ self.set_data('sugar-accel-group', accel_group)
+ self.add_accel_group(accel_group)
+
+ self._old_alloc = None
+
+ self._should_accept_focus = True
+
+ def set_accept_focus(self, focus):
+ self._should_accept_focus = focus
+ if self.get_window() != None:
+ self.get_window().set_accept_focus(focus)
+
+ def do_realize(self):
+ Gtk.Window.do_realize(self)
+
+ self.get_window().set_accept_focus(self._should_accept_focus)
+
+ def get_origin(self):
+ res, x, y = self.get_window().get_origin()
+ return x, y
+
+ def do_realize(self):
+ Gtk.Window.do_realize(self)
+ self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
+
+ def do_size_request(self, requisition):
+ Gtk.Window.do_size_request(self, requisition)
+ requisition.width = max(requisition.width, style.GRID_CELL_SIZE * 2)
+
+ def do_size_allocate(self, allocation):
+ Gtk.Window.do_size_allocate(self, allocation)
+
+ if self._old_alloc is None or \
+ self._old_alloc.x != allocation.x or \
+ self._old_alloc.y != allocation.y or \
+ self._old_alloc.width != allocation.width or \
+ self._old_alloc.height != allocation.height:
+ self.queue_draw()
+
+ # We need to store old allocation because when size_allocate
+ # is called widget.allocation is already updated.
+ # Gtk.Window resizing is different from normal containers:
+ # the X window is resized, widget.allocation is updated from
+ # the configure request handler and finally size_allocate is called.
+ self._old_alloc = allocation
+
+ def do_draw(self, cr):
+
+ # TODO: Draw the border with gap here.
+ cr.set_source_rgb(0.5, 0.5, 0.5)
+ cr.paint()
+
+ # Fall trough to the container expose handler.
+ # (Leaving out the window expose handler which redraws everything)
+ Gtk.Bin.do_draw(self, cr)
+
+
class MouseSpeedDetector(GObject.GObject):
__gsignals__ = {
@@ -131,14 +202,11 @@ class MouseSpeedDetector(GObject.GObject):
return True
-class PaletteWindow(Gtk.Window):
-
- __gtype_name__ = 'SugarPaletteWindow'
+class PaletteWindow(GObject.GObject):
__gsignals__ = {
'popup': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'popdown': (GObject.SignalFlags.RUN_FIRST, None, ([])),
- 'activate': (GObject.SignalFlags.RUN_FIRST, None, ([])),
}
def __init__(self, **kwargs):
@@ -149,7 +217,6 @@ class PaletteWindow(Gtk.Window):
self._cursor_y = 0
self._alignment = None
self._up = False
- self._old_alloc = None
self._palette_state = None
self._popup_anim = animator.Animator(.5, 10)
@@ -160,26 +227,15 @@ class PaletteWindow(Gtk.Window):
GObject.GObject.__init__(self, **kwargs)
- self.set_decorated(False)
- self.set_resizable(False)
- self.set_position(Gtk.WindowPosition.NONE)
- # Just assume xthickness and ythickness are the same
- self.set_border_width(self.get_style().xthickness)
-
- accel_group = Gtk.AccelGroup()
- self.set_data('sugar-accel-group', accel_group)
- self.add_accel_group(accel_group)
-
self.set_group_id('default')
- self.connect('show', self.__show_cb)
- self.connect('hide', self.__hide_cb)
- self.connect('realize', self.__realize_cb)
- self.connect('destroy', self.__destroy_cb)
- self.connect('enter-notify-event', self.__enter_notify_event_cb)
- self.connect('leave-notify-event', self.__leave_notify_event_cb)
+ self.widget.connect('show', self.__show_cb)
+ self.widget.connect('hide', self.__hide_cb)
+ self.widget.connect('destroy', self.__destroy_cb)
+ self.widget.connect('enter-notify-event', self.__enter_notify_event_cb)
+ self.widget.connect('leave-notify-event', self.__leave_notify_event_cb)
- self._mouse_detector = MouseSpeedDetector(self, 200, 5)
+ self._mouse_detector = MouseSpeedDetector(self.widget, 200, 5)
self._mouse_detector.connect('motion-slow', self._mouse_slow_cb)
def __destroy_cb(self, palette):
@@ -207,9 +263,6 @@ class PaletteWindow(Gtk.Window):
getter=get_invoker,
setter=set_invoker)
- def __realize_cb(self, widget):
- self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
-
def _mouse_slow_cb(self, widget):
self._mouse_detector.stop()
self._palette_do_popup()
@@ -248,69 +301,21 @@ class PaletteWindow(Gtk.Window):
getter=get_group_id,
setter=set_group_id)
- def do_size_request(self, requisition):
- Gtk.Window.do_size_request(self, requisition)
- requisition.width = max(requisition.width, style.GRID_CELL_SIZE * 2)
-
- def do_size_allocate(self, allocation):
- Gtk.Window.do_size_allocate(self, allocation)
-
- if self._old_alloc is None or \
- self._old_alloc.x != allocation.x or \
- self._old_alloc.y != allocation.y or \
- self._old_alloc.width != allocation.width or \
- self._old_alloc.height != allocation.height:
- self.queue_draw()
-
- # We need to store old allocation because when size_allocate
- # is called widget.allocation is already updated.
- # Gtk.Window resizing is different from normal containers:
- # the X window is resized, widget.allocation is updated from
- # the configure request handler and finally size_allocate is called.
- self._old_alloc = allocation
-
- def do_expose_event(self, event):
- # We want to draw a border with a beautiful gap
- if self._invoker is not None and self._invoker.has_rectangle_gap():
- invoker = self._invoker.get_rect()
- palette = self.get_rect()
-
- gap = _calculate_gap(palette, invoker)
- else:
- gap = False
-
- allocation = self.get_allocation()
- wstyle = self.get_style()
-
- if gap:
- wstyle.paint_box_gap(event.window, Gtk.StateType.PRELIGHT,
- Gtk.ShadowType.IN, event.area, self, 'palette',
- 0, 0, allocation.width, allocation.height,
- gap[0], gap[1], gap[2])
- else:
- wstyle.paint_box(event.window, Gtk.StateType.PRELIGHT,
- Gtk.ShadowType.IN, event.area, self, 'palette',
- 0, 0, allocation.width, allocation.height)
-
- # Fall trough to the container expose handler.
- # (Leaving out the window expose handler which redraws everything)
- Gtk.Bin.do_expose_event(self, event)
-
def update_position(self):
invoker = self._invoker
if invoker is None or self._alignment is None:
logging.error('Cannot update the palette position.')
return
- rect = self.size_request()
+ rect = self.widget.size_request()
position = invoker.get_position_for_alignment(self._alignment, rect)
if position is None:
position = invoker.get_position(rect)
- self.move(position.x, position.y)
+ self.widget.move(position.x, position.y)
def get_full_size_request(self):
- return self.size_request()
+ return self.widget.size_request()
def popup(self, immediate=False):
if self._invoker is not None:
@@ -318,7 +323,7 @@ class PaletteWindow(Gtk.Window):
self._alignment = self._invoker.get_alignment(full_size_request)
self.update_position()
- self.set_transient_for(self._invoker.get_toplevel())
+ self.widget.set_transient_for(self._invoker.get_toplevel())
self._popdown_anim.stop()
@@ -326,7 +331,7 @@ class PaletteWindow(Gtk.Window):
self._popup_anim.start()
else:
self._popup_anim.stop()
- self.show()
+ self.widget.show()
# we have to invoke update_position() twice
# since WM could ignore first move() request
self.update_position()
@@ -339,8 +344,9 @@ class PaletteWindow(Gtk.Window):
self._popdown_anim.start()
else:
self._popdown_anim.stop()
- self.size_request()
- self.hide()
+ # XXX: Please, someone remove or explain this :-)
+ self.widget.size_request()
+ self.widget.hide()
def on_invoker_enter(self):
self._popdown_anim.stop()
@@ -386,14 +392,17 @@ class PaletteWindow(Gtk.Window):
self.emit('popdown')
def get_rect(self):
- res, win_x, win_y = self.get_window().get_origin()
+ win_x, win_y = self.widget.get_origin()
rectangle = self.get_allocation()
x = win_x + rectangle.x
y = win_y + rectangle.y
- width, height = self.size_request()
+ requisition = self.widget.size_request()
- return (x, y, width, height)
+ rect = Gdk.Rectangle()
+ rect.x, rect.y, rect.width, rect.height = (x, y, requisition.width, requisition.height)
+
+ return rect
def get_palette_state(self):
return self._palette_state
diff --git a/src/sugar3/graphics/toolbarbox.py b/src/sugar3/graphics/toolbarbox.py
index b88208f..df48c2b 100644
--- a/src/sugar3/graphics/toolbarbox.py
+++ b/src/sugar3/graphics/toolbarbox.py
@@ -18,7 +18,7 @@
from gi.repository import Gtk, GObject, Gdk
from sugar3.graphics import style
-from sugar3.graphics.palette import PaletteWindow, ToolInvoker
+from sugar3.graphics.palettewindow import PaletteWindow, ToolInvoker
from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics import palettegroup