Hmm, Firefox didn't upload my file...trying again.
On Mon, Mar 31, 2008 at 3:46 PM, Eben Eliason <[EMAIL PROTECTED]> wrote:
> Here is my attempt at consolidating the changes to palette.py. The
> layout is tested with respect to primary text, secondary text, and
> icons, but I have not visually tested the accel labels. All of the
>
> other changes applicable have been merged.
>
> - Eben
>
> On Mon, Mar 31, 2008 at 1:48 PM, Marco Pesenti Gritti
>
>
> <[EMAIL PROTECTED]> wrote:
> > Looks good. Now that the logic is much simpler I don't think the
> > helper is worth...
> >
> > Marco
> >
> >
> >
> > On Mon, Mar 31, 2008 at 7:18 PM, Tomeu Vizoso <[EMAIL PROTECTED]> wrote:
> > > On Fri, Mar 28, 2008 at 10:55 PM, Marco Pesenti Gritti
> > >
> > >
> > > <[EMAIL PROTECTED]> wrote:
> > > > On Fri, Mar 28, 2008 at 9:52 PM, Marco Pesenti Gritti
> > > > <[EMAIL PROTECTED]> wrote:
> > > > > On Fri, Mar 28, 2008 at 8:13 PM, Tomeu Vizoso <[EMAIL PROTECTED]>
> wrote:
> > > >
> > > > > > > + def set_tooltip(self, tooltip):
> > > > > > > + if self._tooltip != tooltip:
> > > > > > > + self._tooltip = tooltip
> > > > > > > + if tooltip and self.palette is None:
> > > > > > > + self.palette = Palette(tooltip)
> > > > > > > + elif self.palette:
> > > > > > > + self.palette.set_primary_text(tooltip)
> > > > > > >
> > > > > > > Is the if at the top really necessary? I can't think of
> use cases
> > > > > > > where we would be hitting it.
> > > > > > > Also I'd replace the palette if you set_tooltip and a
> Palette already exist.
> > > > > >
> > > > > > How so?
> > > > >
> > > > > Are you trying to optimize the change tooltip use case there?
> > > > >
> > > > > What about this logic:
> > > > >
> > > > > * palette != None and tooltip == None -> replace the palette
> > > > > * palette != None and tooltip != None -> replace primary text
> > > > >
> > > > > (It would require to set tooltip to None on set_palette, but
> that make sense)
> > > > >
> > > > > The semantic is going to be a bit unclear there in any case and
> we
> > > > > should document it. But if I
> set_palette(fancy_dialog_like_palette)
> > > > > and then set_tooltip, I'd expect a tooltip to appear, not the
> primary
> > > > > text of my fancy palette to be changed.
> > > >
> > > > Btw it seem like it would be fairly easy to factor out this logic to
> > > > toolbutton.setup_tooltip()
> > >
> > > Looks good?
> > >
> > >
> > > def set_tooltip(self, tooltip):
> > > """ Set a simple palette with just a single label.
> > > """
> > > if self.palette is None or self._tooltip is None:
> > > self.palette = Palette(tooltip)
> > > elif self.palette is not None:
> > >
> > > self.palette.set_primary_text(tooltip)
> > >
> > > self._tooltip = tooltip
> > >
> > > # Set label, shows up when toolbar overflows
> > > gtk.ToolButton.set_label(self, tooltip)
> > >
> > > Do you think it is worth to put into a toolbutton.setup_tooltip() func?
> > >
> > > Thanks,
> > >
> > > Tomeu
> > >
> > _______________________________________________
> > Sugar mailing list
> > [email protected]
> > http://lists.laptop.org/listinfo/sugar
> >
>
diff --git a/sugar/graphics/palette.py b/sugar/graphics/palette.py
index 4430b96..6fb8fc3 100644
--- a/sugar/graphics/palette.py
+++ b/sugar/graphics/palette.py
@@ -131,8 +131,21 @@ class Palette(gtk.Window):
__gtype_name__ = 'SugarPalette'
__gproperties__ = {
- 'invoker' : (object, None, None,
- gobject.PARAM_READWRITE)
+ 'invoker' : (object, None, None,
+ gobject.PARAM_READWRITE),
+ 'primary-text' : (str, None, None, None,
+ gobject.PARAM_READWRITE),
+ 'secondary-text' : (str, None, None, None,
+ gobject.PARAM_READWRITE),
+ 'icon' : (object, None, None,
+ gobject.PARAM_READWRITE),
+ 'icon-visible' : (bool, None, None, True,
+ gobject.PARAM_READWRITE),
+ 'group-id' : (str, None, None, None,
+ gobject.PARAM_READWRITE),
+
+ 'menu-after-content' : (bool, None, None, False,
+ gobject.PARAM_CONSTRUCT_ONLY)
}
__gsignals__ = {
@@ -143,61 +156,105 @@ class Palette(gtk.Window):
}
def __init__(self, label, accel_path=None, menu_after_content=False,
- text_maxlen=0):
- gtk.Window.__init__(self)
-
- self.set_decorated(False)
- self.set_resizable(False)
- # Just assume xthickness and ythickness are the same
- self.set_border_width(self.style.xthickness)
- self.connect('realize', self._realize_cb)
- self.connect('destroy', self.__destroy_cb)
- self.connect('map-event', self.__map_event_cb)
+ text_maxlen=0, **kwargs):
self.palette_state = self.PRIMARY
- self._alignment = None
- self._old_alloc = None
- self._full_request = [0, 0]
- self._cursor_x = 0
- self._cursor_y = 0
- self._invoker = None
+ self._primary_text = None
+ self._secondary_text = None
+ self._icon = None
+ self._icon_visible = True
self._group_id = None
- self._up = False
- self._palette_popup_sid = None
+ self._menu_after_content = False
- self._popup_anim = animator.Animator(0.3, 10)
- self._popup_anim.add(_PopupAnimation(self))
+ palette_box = gtk.VBox()
- self._secondary_anim = animator.Animator(1.0, 10)
- self._secondary_anim.add(_SecondaryAnimation(self))
+ primary_box = gtk.HBox()
+ palette_box.pack_start(primary_box, expand=False)
+ primary_box.show()
- self._popdown_anim = animator.Animator(0.6, 10)
- self._popdown_anim.add(_PopdownAnimation(self))
+ self._icon_box = gtk.HBox()
+ self._icon_box.set_size_request(style.zoom(style.GRID_CELL_SIZE), -1)
+ primary_box.pack_start(self._icon_box, expand=False)
- vbox = gtk.VBox()
+ labels_box = gtk.VBox()
+ self._label_alignment = gtk.Alignment(xalign=0, yalign=0.5,
+ xscale=0, yscale=0.33)
+ self._label_alignment.set_padding(0, 0, style.DEFAULT_SPACING,
+ style.DEFAULT_SPACING)
+ self._label_alignment.add(labels_box)
+ self._label_alignment.show()
+ primary_box.pack_start(self._label_alignment, expand=True)
+ labels_box.show()
self._label = gtk.AccelLabel('')
- self._label.set_size_request(-1, style.zoom(style.GRID_CELL_SIZE) -
- 2 * self.get_border_width())
self._label.set_alignment(0, 0.5)
- self._label.set_padding(style.DEFAULT_SPACING, 0)
if text_maxlen > 0:
self._label.set_max_width_chars(text_maxlen)
self._label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
- vbox.pack_start(self._label)
+ labels_box.pack_start(self._label, expand=True)
+
+ self._secondary_label = gtk.Label()
+ self._secondary_label.set_alignment(0, 0.5)
+
+ if text_maxlen > 0:
+ self._secondary_label.set_max_width_chars(text_maxlen)
+ self._secondary_label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
+
+ labels_box.pack_start(self._secondary_label, expand=True)
+ #self._secondary_label.show()
self._secondary_box = gtk.VBox()
- vbox.pack_start(self._secondary_box)
+ palette_box.pack_start(self._secondary_box)
self._separator = gtk.HSeparator()
self._secondary_box.pack_start(self._separator)
self._menu_content_separator = gtk.HSeparator()
- if menu_after_content:
+ self._popup_anim = animator.Animator(0.3, 10)
+ self._popup_anim.add(_PopupAnimation(self))
+
+ self._secondary_anim = animator.Animator(1.0, 10)
+ self._secondary_anim.add(_SecondaryAnimation(self))
+
+ self._popdown_anim = animator.Animator(0.6, 10)
+ self._popdown_anim.add(_PopdownAnimation(self))
+
+ # we init after initializing all of our containers
+ gobject.GObject.__init__(self, **kwargs)
+
+ self.set_decorated(False)
+ self.set_resizable(False)
+ # Just assume xthickness and ythickness are the same
+ self.set_border_width(self.style.xthickness)
+
+ primary_box.set_size_request(-1, style.zoom(style.GRID_CELL_SIZE)
+ - 2 * self.get_border_width())
+
+ self.connect('realize', self._realize_cb)
+ self.connect('destroy', self.__destroy_cb)
+ self.connect('map-event', self.__map_event_cb)
+
+ self._alignment = None
+ self._old_alloc = None
+ self._full_request = [0, 0]
+ self._cursor_x = 0
+ self._cursor_y = 0
+ self._invoker = None
+ self._group_id = None
+ self._up = False
+ self._palette_popup_sid = None
+
+ # we set these for backward compatibility
+ if label is not None:
+ self.props.primary_text = label
+ if menu_after_content is not None:
+ self._menu_after_content = menu_after_content
+
+ if self._menu_after_content:
self._add_content()
self._secondary_box.pack_start(self._menu_content_separator)
self._add_menu()
@@ -210,8 +267,8 @@ class Palette(gtk.Window):
self._secondary_box.pack_start(self.action_bar)
self.action_bar.show()
- self.add(vbox)
- vbox.show()
+ self.add(palette_box)
+ palette_box.show()
# The menu is not shown here until an item is added
self.menu = _Menu(self)
@@ -221,8 +278,8 @@ class Palette(gtk.Window):
self.connect('leave-notify-event',
self._leave_notify_event_cb)
- self.set_primary_text(label)
- self.set_group_id('default')
+ #self.set_primary_text(self._primary_text)
+ #self.set_group_id('default')
self._mouse_detector = MouseSpeedDetector(self, 200, 5)
self._mouse_detector.connect('motion-slow', self._mouse_slow_cb)
@@ -264,11 +321,66 @@ class Palette(gtk.Window):
return gtk.gdk.Rectangle(x, y, width, height)
- def set_primary_text(self, label):
+ def _set_invoker(self, invoker):
+ if self._invoker is not None:
+ self._invoker.disconnect(self._enter_invoker_hid)
+ self._invoker.disconnect(self._leave_invoker_hid)
+
+ self._invoker = invoker
+ if invoker is not None:
+ self._enter_invoker_hid = self._invoker.connect(
+ 'mouse-enter', self._invoker_mouse_enter_cb)
+ self._leave_invoker_hid = self._invoker.connect(
+ 'mouse-leave', self._invoker_mouse_leave_cb)
+ if hasattr(invoker.props, 'widget'):
+ self._label.props.accel_widget = invoker.props.widget
+
+ def set_primary_text(self, label, accel_path=None):
+ self._primary_text = label
+
if label is not None:
self._label.set_markup('<b>%s</b>' % label)
self._label.show()
+ def _set_secondary_text(self, label):
+ self._secondary_text = label
+
+ if label is None:
+ self._secondary_label.hide()
+ else:
+ self._secondary_label.set_text(label)
+ self._secondary_label.show()
+
+ def _show_icon(self):
+ self._label_alignment.set_padding(0, 0, 0, style.DEFAULT_SPACING)
+ self._icon_box.show()
+
+ def _hide_icon(self):
+ self._icon_box.hide()
+ self._label_alignment.set_padding(0, 0, style.DEFAULT_SPACING,
+ style.DEFAULT_SPACING)
+
+ def _set_icon(self, icon):
+ if icon is None:
+ self._icon = None
+ self._hide_icon()
+ else:
+ if self._icon:
+ self._icon_box.remove(self._icon)
+
+ self._icon = icon
+ self._icon_box.pack_start(self._icon)
+ self._icon.show()
+ self._show_icon()
+
+ def _set_icon_visible(self, visible):
+ self._icon_visible = visible
+
+ if visible and self._icon is not None:
+ self._show_icon()
+ else:
+ self._hide_icon()
+
def set_content(self, widget):
if len(self._content.get_children()) > 0:
self._content.remove(self._content.get_children()[0])
@@ -293,24 +405,35 @@ class Palette(gtk.Window):
def do_set_property(self, pspec, value):
if pspec.name == 'invoker':
- if self._invoker is not None:
- self._invoker.disconnect(self._enter_invoker_hid)
- self._invoker.disconnect(self._leave_invoker_hid)
-
- self._invoker = value
- if value is not None:
- self._enter_invoker_hid = self._invoker.connect(
- 'mouse-enter', self._invoker_mouse_enter_cb)
- self._leave_invoker_hid = self._invoker.connect(
- 'mouse-leave', self._invoker_mouse_leave_cb)
- if hasattr(value.props, 'widget'):
- self._label.props.accel_widget = value.props.widget
+ self._set_invoker(value)
+ elif pspec.name == 'primary-text':
+ self.set_primary_text(value, None)
+ elif pspec.name == 'secondary-text':
+ self._set_secondary_text(value)
+ elif pspec.name == 'icon':
+ self._set_icon(value)
+ elif pspec.name == 'icon-visible':
+ self._set_icon_visible(value)
+ elif pspec.name == 'group-id':
+ self.set_group_id(value)
else:
raise AssertionError
def do_get_property(self, pspec):
if pspec.name == 'invoker':
return self._invoker
+ elif pspec.name == 'primary-text':
+ return self._primary_text
+ elif pspec.name == 'secondary-text':
+ return self._secondary_text
+ elif pspec.name == 'icon':
+ return self._icon
+ elif pspec.name == 'icon-visible':
+ return self._icon_visible
+ elif pspec.name == 'group-id':
+ return self._group_id
+ elif pspec.name == 'menu-after-content':
+ return self._menu_after_content
else:
raise AssertionError
_______________________________________________
Sugar mailing list
[email protected]
http://lists.laptop.org/listinfo/sugar