Merge branch 'master' of git.sugarlabs.org:sugar-toolkit-gtk3/sugar-toolkit-gtk3

This commit is contained in:
Pootle daemon 2012-03-16 00:30:55 -04:00
commit 06f4e92372
3 changed files with 102 additions and 69 deletions

View File

@ -98,16 +98,15 @@ class _PaletteMenuWidget(Gtk.Menu):
res_, x, y = self.get_toplevel().get_window().get_origin() res_, x, y = self.get_toplevel().get_window().get_origin()
return x, y return x, y
def do_size_request(self, requisition):
Gtk.Window.do_size_request(self, requisition)
requisition.width = max(requisition.width, style.GRID_CELL_SIZE * 2)
def move(self, x, y): def move(self, x, y):
self._popup_position = (x, y) self._popup_position = (x, y)
def set_transient_for(self, window): def set_transient_for(self, window):
pass pass
def set_invoker(self, invoker):
pass
def _position(self, widget, data): def _position(self, widget, data):
return self._popup_position[0], self._popup_position[1], False return self._popup_position[0], self._popup_position[1], False
@ -252,7 +251,7 @@ class _PaletteWindowWidget(Gtk.Window):
self.add_accel_group(accel_group) self.add_accel_group(accel_group)
self._old_alloc = None self._old_alloc = None
self._invoker = None
self._should_accept_focus = True self._should_accept_focus = True
def set_accept_focus(self, focus): def set_accept_focus(self, focus):
@ -270,9 +269,13 @@ class _PaletteWindowWidget(Gtk.Window):
self.get_window().set_accept_focus(self._should_accept_focus) self.get_window().set_accept_focus(self._should_accept_focus)
self.set_type_hint(Gdk.WindowTypeHint.DIALOG) self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
def do_size_request(self, requisition): def do_get_preferred_width(self):
Gtk.Window.do_size_request(self, requisition) size = 0
requisition.width = max(requisition.width, style.GRID_CELL_SIZE * 2) child = self.get_child()
if child:
minimum_size, natural_size = child.get_preferred_width()
size = max(minimum_size, natural_size, style.GRID_CELL_SIZE * 2)
return size, size
def do_size_allocate(self, allocation): def do_size_allocate(self, allocation):
Gtk.Window.do_size_allocate(self, allocation) Gtk.Window.do_size_allocate(self, allocation)
@ -291,6 +294,46 @@ class _PaletteWindowWidget(Gtk.Window):
# the configure request handler and finally size_allocate is called. # the configure request handler and finally size_allocate is called.
self._old_alloc = allocation self._old_alloc = allocation
def set_invoker(self, invoker):
self._invoker = invoker
def get_rect(self):
win_x, win_y = self.get_origin()
rectangle = self.get_allocation()
x = win_x + rectangle.x
y = win_y + rectangle.y
minimum, natural = self.get_preferred_size()
rect = Gdk.Rectangle()
rect.x = x
rect.y = y
rect.width = minimum.width
rect.height = natural.height
return rect
def do_draw(self, cr):
# Fall trough to the container expose handler.
# (Leaving out the window expose handler which redraws everything)
Gtk.Window.do_draw(self, cr)
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()
context = self.get_style_context()
context.add_class('toolitem')
if gap:
Gtk.render_frame_gap(context, cr, 0, 0, allocation.width, allocation.height,
gap[0], gap[1], gap[2])
else:
Gtk.render_frame(context, cr, 0, 0, allocation.width, allocation.height)
return False
def __enter_notify_event_cb(self, widget, event): def __enter_notify_event_cb(self, widget, event):
if event.mode == Gdk.CrossingMode.NORMAL and \ if event.mode == Gdk.CrossingMode.NORMAL and \
event.detail != Gdk.NotifyType.INFERIOR: event.detail != Gdk.NotifyType.INFERIOR:
@ -427,6 +470,7 @@ class PaletteWindow(GObject.GObject):
self._widget.connect('leave-notify', self.__leave_notify_cb) self._widget.connect('leave-notify', self.__leave_notify_cb)
self._set_effective_group_id(self._group_id) self._set_effective_group_id(self._group_id)
self._widget.set_invoker(self._invoker)
self._mouse_detector.connect('motion-slow', self._mouse_slow_cb) self._mouse_detector.connect('motion-slow', self._mouse_slow_cb)
self._mouse_detector.parent = self._widget self._mouse_detector.parent = self._widget
@ -452,6 +496,7 @@ class PaletteWindow(GObject.GObject):
self._invoker_hids.remove(hid) self._invoker_hids.remove(hid)
self._invoker = invoker self._invoker = invoker
self._widget.set_invoker(self._invoker)
if invoker is not None: if invoker is not None:
self._invoker_hids.append(self._invoker.connect( self._invoker_hids.append(self._invoker.connect(
'mouse-enter', self._invoker_mouse_enter_cb)) 'mouse-enter', self._invoker_mouse_enter_cb))
@ -599,17 +644,17 @@ class PaletteWindow(GObject.GObject):
def get_rect(self): def get_rect(self):
win_x, win_y = self._widget.get_origin() win_x, win_y = self._widget.get_origin()
rectangle = self.get_allocation() rectangle = self._widget.get_allocation()
x = win_x + rectangle.x x = win_x + rectangle.x
y = win_y + rectangle.y y = win_y + rectangle.y
requisition = self._widget.size_request() minimum, natural_ = self._widget.get_preferred_size()
rect = Gdk.Rectangle() rect = Gdk.Rectangle()
rect.x = x rect.x = x
rect.y = y rect.y = y
rect.width = requisition.width rect.width = minimum.width
rect.height = requisition.height rect.height = minimum.height
return rect return rect
@ -967,25 +1012,18 @@ class WidgetInvoker(Invoker):
def has_rectangle_gap(self): def has_rectangle_gap(self):
return True return True
def draw_rectangle(self, event, palette): def draw_rectangle(self, cr, palette):
x, y = self._widget.allocation.x, self._widget.allocation.y allocation = self.parent.get_allocation()
context = self.parent.get_style_context()
context.add_class('toolitem')
wstyle = self._widget.get_style()
gap = _calculate_gap(self.get_rect(), palette.get_rect()) gap = _calculate_gap(self.get_rect(), palette.get_rect())
if gap: if gap:
wstyle.paint_box_gap(event.window, Gtk.StateType.PRELIGHT, Gtk.render_frame_gap(context, cr, 0, 0,
Gtk.ShadowType.IN, event.area, self._widget, allocation.width,
'palette-invoker', x, y, allocation.height,
self._widget.allocation.width,
self._widget.allocation.height,
gap[0], gap[1], gap[2]) gap[0], gap[1], gap[2])
else:
wstyle.paint_box(event.window, Gtk.StateType.PRELIGHT,
Gtk.ShadowType.IN, event.area, self._widget,
'palette-invoker', x, y,
self._widget.allocation.width,
self._widget.allocation.height)
def __enter_notify_event_cb(self, widget, event): def __enter_notify_event_cb(self, widget, event):
self.notify_mouse_enter() self.notify_mouse_enter()

View File

@ -38,7 +38,7 @@ class ToolbarButton(ToolButton):
self.connect('clicked', self.connect('clicked',
lambda widget: self.set_expanded(not self.is_expanded())) lambda widget: self.set_expanded(not self.is_expanded()))
self.connect_after('draw', self.__drawing_cb)
self.connect('hierarchy-changed', self.__hierarchy_changed_cb) self.connect('hierarchy-changed', self.__hierarchy_changed_cb)
def __hierarchy_changed_cb(self, tool_button, previous_toplevel): def __hierarchy_changed_cb(self, tool_button, previous_toplevel):
@ -66,7 +66,7 @@ class ToolbarButton(ToolButton):
if page is None: if page is None:
self.page_widget = None self.page_widget = None
return return
self.page_widget, alignment_ = _embed_page(_Box, page) self.page_widget, alignment_ = _embed_page(_Box(self), page)
self.page_widget.set_size_request(-1, style.GRID_CELL_SIZE) self.page_widget.set_size_request(-1, style.GRID_CELL_SIZE)
page.show() page.show()
if self.props.palette is None: if self.props.palette is None:
@ -125,22 +125,19 @@ class ToolbarButton(ToolButton):
return return
page_parent.remove(self.page_widget) page_parent.remove(self.page_widget)
def do_draw(self, cr): def __drawing_cb(self, button, cr):
if not self.is_expanded() or self.props.palette is not None and \
self.props.palette.is_up():
Gtk.ToolButton.do_draw(self, cr)
_paint_arrow(self, cr, math.pi)
return
alloc = self.get_allocation() alloc = self.get_allocation()
context = self.get_style_context() context = self.get_style_context()
context.add_class('toolitem') context.add_class('toolitem')
if not self.is_expanded() or self.props.palette is not None and \
self.props.palette.is_up():
ToolButton.do_draw(self, cr)
_paint_arrow(self, cr, math.pi)
return False
Gtk.render_frame_gap(context, cr, 0, 0, alloc.width, alloc.height, Gtk.render_frame_gap(context, cr, 0, 0, alloc.width, alloc.height,
Gtk.PositionType.BOTTOM, 0, alloc.width) Gtk.PositionType.BOTTOM, 0, alloc.width)
Gtk.ToolButton.do_draw(self, cr)
_paint_arrow(self, cr, 0) _paint_arrow(self, cr, 0)
return False
class ToolbarBox(Gtk.VBox): class ToolbarBox(Gtk.VBox):
@ -155,7 +152,7 @@ class ToolbarBox(Gtk.VBox):
self._toolbar.connect('remove', self.__remove_cb) self._toolbar.connect('remove', self.__remove_cb)
self._toolbar_widget, self._toolbar_alignment = \ self._toolbar_widget, self._toolbar_alignment = \
_embed_page(Gtk.EventBox, self._toolbar) _embed_page(Gtk.EventBox(), self._toolbar)
self.pack_start(self._toolbar_widget, True, True, 0) self.pack_start(self._toolbar_widget, True, True, 0)
self.props.padding = padding self.props.padding = padding
@ -269,26 +266,23 @@ class _ToolbarPalette(PaletteWindow):
class _Box(Gtk.EventBox): class _Box(Gtk.EventBox):
def __init__(self): def __init__(self, toolbar_button):
GObject.GObject.__init__(self) GObject.GObject.__init__(self)
self.set_app_paintable(True) self.set_app_paintable(True)
self._toolbar_button = toolbar_button
def do_expose_event(self, widget, event): def do_draw(self, cr):
# TODO: reimplement this in the theme button_alloc = self._toolbar_button.get_allocation()
expanded_button = self.get_parent().expanded_button
if expanded_button is None: cr.set_line_width(style.FOCUS_LINE_WIDTH * 2)
return cr.set_source_rgba(*style.COLOR_BUTTON_GREY.get_rgba())
alloc = expanded_button.allocation cr.move_to(0, 0)
self.get_style().paint_box(event.window, cr.line_to(button_alloc.x + style.FOCUS_LINE_WIDTH, 0)
Gtk.StateType.NORMAL, Gtk.ShadowType.IN, event.area, self, cr.move_to(button_alloc.x + button_alloc.width - style.FOCUS_LINE_WIDTH, 0)
'palette-invoker', -style.FOCUS_LINE_WIDTH, 0, cr.line_to(self.get_allocation().width, 0)
self.allocation.width + style.FOCUS_LINE_WIDTH * 2, cr.stroke()
self.allocation.height + style.FOCUS_LINE_WIDTH)
self.get_style().paint_box(event.window, Gtk.EventBox.do_draw(self, cr)
Gtk.StateType.NORMAL, Gtk.ShadowType.NONE, event.area, self, None,
alloc.x + style.FOCUS_LINE_WIDTH, 0,
alloc.width - style.FOCUS_LINE_WIDTH * 2,
style.FOCUS_LINE_WIDTH)
def _setup_page(page_widget, color, hpad): def _setup_page(page_widget, color, hpad):
@ -305,14 +299,13 @@ def _setup_page(page_widget, color, hpad):
page_widget.modify_bg(Gtk.StateType.PRELIGHT, color) page_widget.modify_bg(Gtk.StateType.PRELIGHT, color)
def _embed_page(box_class, page): def _embed_page(page_widget, page):
page.show() page.show()
alignment = Gtk.Alignment(xscale=1.0, yscale=1.0) alignment = Gtk.Alignment(xscale=1.0, yscale=1.0)
alignment.add(page) alignment.add(page)
alignment.show() alignment.show()
page_widget = box_class()
page_widget.modify_bg(Gtk.StateType.ACTIVE, page_widget.modify_bg(Gtk.StateType.ACTIVE,
style.COLOR_BUTTON_GREY.get_gdk_color()) style.COLOR_BUTTON_GREY.get_gdk_color())
page_widget.add(alignment) page_widget.add(alignment)

View File

@ -142,20 +142,22 @@ class ToolButton(Gtk.ToolButton):
palette_invoker = GObject.property( palette_invoker = GObject.property(
type=object, setter=set_palette_invoker, getter=get_palette_invoker) type=object, setter=set_palette_invoker, getter=get_palette_invoker)
def do_expose_event(self, event): def do_draw(self, cr):
child = self.get_child() child = self.get_child()
allocation = self.get_allocation() if self.palette and self.palette.is_up():
allocation = self.get_allocation()
# draw a black background, has been done by the engine before
cr.set_source_rgb(0, 0, 0)
cr.rectangle(0, 0, allocation.width, allocation.height)
cr.paint()
Gtk.ToolButton.do_draw(self, cr)
if self.palette and self.palette.is_up(): if self.palette and self.palette.is_up():
invoker = self.palette.props.invoker invoker = self.palette.props.invoker
invoker.draw_rectangle(event, self.palette) invoker.draw_rectangle(cr, self.palette)
elif child.state == Gtk.StateType.PRELIGHT:
child.style.paint_box(event.window, Gtk.StateType.PRELIGHT,
Gtk.ShadowType.NONE, event.area,
child, 'toolbutton-prelight',
allocation.x, allocation.y,
allocation.width, allocation.height)
Gtk.ToolButton.do_expose_event(self, event) return False
def do_clicked(self): def do_clicked(self):
if self.palette: if self.palette: