Difference between revisions of "Features/GTK3/Shell"
Line 57: | Line 57: | ||
style.COLOR_SELECTION_GREY.get_gdk_color()) | style.COLOR_SELECTION_GREY.get_gdk_color()) | ||
</pre> | </pre> | ||
+ | |||
+ | === Palettes can't include menu and widgets at the same time === | ||
+ | |||
+ | We can use anything like this: | ||
+ | |||
+ | <pre> | ||
+ | |||
+ | class SugarMenuItem(gtk.EventBox): | ||
+ | |||
+ | __gsignals__ = { | ||
+ | 'clicked': (gobject.SIGNAL_RUN_FIRST, None, []) | ||
+ | } | ||
+ | |||
+ | def __init__(self, icon_name, label_text): | ||
+ | gtk.EventBox.__init__(self) | ||
+ | self._sensitive = True | ||
+ | vbox = gtk.VBox() | ||
+ | hbox = gtk.HBox() | ||
+ | vbox.set_border_width(style.DEFAULT_PADDING) | ||
+ | self.icon = Icon() | ||
+ | self.icon.props.icon_name = icon_name | ||
+ | hbox.pack_start(self.icon, expand=False, fill=False, | ||
+ | padding=style.DEFAULT_PADDING) | ||
+ | align = gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0) | ||
+ | text = '<span foreground="%s">' % style.COLOR_WHITE.get_html() + \ | ||
+ | label_text + '</span>' | ||
+ | self.label = gtk.Label() | ||
+ | self.label.set_use_markup(True) | ||
+ | self.label.set_markup(text) | ||
+ | align.add(self.label) | ||
+ | hbox.pack_start(align, expand=True, fill=True, | ||
+ | padding=style.DEFAULT_PADDING) | ||
+ | vbox.pack_start(hbox, expand=False, fill=False, | ||
+ | padding=style.DEFAULT_PADDING) | ||
+ | self.add(vbox) | ||
+ | self.id_bt_release_cb = self.connect('button-release-event', | ||
+ | self.__button_release_cb) | ||
+ | self.id_enter_notify_cb = self.connect('enter-notify-event', | ||
+ | self.__enter_notify_cb) | ||
+ | self.id_leave_notify_cb = self.connect('leave-notify-event', | ||
+ | self.__leave_notify_cb) | ||
+ | self.modify_bg(gtk.STATE_NORMAL, style.COLOR_BLACK.get_gdk_color()) | ||
+ | self.show_all() | ||
+ | self.set_above_child(True) | ||
+ | |||
+ | def __button_release_cb(self, widget, event): | ||
+ | self.emit('clicked') | ||
+ | |||
+ | def __enter_notify_cb(self, widget, event): | ||
+ | self.modify_bg(gtk.STATE_NORMAL, | ||
+ | style.COLOR_BUTTON_GREY.get_gdk_color()) | ||
+ | |||
+ | def __leave_notify_cb(self, widget, event): | ||
+ | self.modify_bg(gtk.STATE_NORMAL, style.COLOR_BLACK.get_gdk_color()) | ||
+ | |||
+ | def set_icon(self, icon_name): | ||
+ | self.icon.props.icon_name = icon_name | ||
+ | |||
+ | def set_label(self, label_text): | ||
+ | text = '<span foreground="%s">' % style.COLOR_WHITE.get_html() + \ | ||
+ | label_text + '</span>' | ||
+ | self.label.set_markup(text) | ||
+ | |||
+ | def set_sensitive(self, sensitive): | ||
+ | if self._sensitive == sensitive: | ||
+ | return | ||
+ | |||
+ | self._sensitive = sensitive | ||
+ | if sensitive: | ||
+ | self.handler_unblock(self.id_bt_release_cb) | ||
+ | self.handler_unblock(self.id_enter_notify_cb) | ||
+ | self.handler_unblock(self.id_leave_notify_cb) | ||
+ | else: | ||
+ | self.handler_block(self.id_bt_release_cb) | ||
+ | self.handler_block(self.id_enter_notify_cb) | ||
+ | self.handler_block(self.id_leave_notify_cb) | ||
+ | self.modify_bg(gtk.STATE_NORMAL, style.COLOR_BLACK.get_gdk_color()) | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | And add them to a vbox: | ||
+ | |||
+ | <pre> | ||
+ | |||
+ | # TODO: private!!! | ||
+ | self._content.set_border_width(0) | ||
+ | |||
+ | self._play_pause_button = SugarMenuItem('player_play', | ||
+ | _('Say selected text')) | ||
+ | self._play_pause_button.connect('clicked', self.__play_clicked_cb) | ||
+ | vbox_menu.add(self._play_pause_button) | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | To do the SegurMenuItem take all the width in the palette, we need set the border_width in _content to zero, | ||
+ | but that is a private member. Then we need to look if we add a method to set the it, | ||
+ | or change the api to make the first container (where is the menu today) useful for other type of widgets. |
Revision as of 12:28, 31 January 2012
Daniel Drake started an effort to port the shell to the GTK3 sugar-toolkit. These are the biggest issues identified so far:
Custom tree model for journal
Having trouble reimplementing this. See http://mail.gnome.org/archives/python-hackers-list/2011-December/msg00010.html
Custom Icon cell renderer
sugar3.graphics.icon.CellRendererIcon is based on pygtks GenericCellRenderer - needs to be ported
do_forall not working in pygobject
Needs:
- https://bugzilla.gnome.org/show_bug.cgi?id=663052 gobject-introspection not yet merged
- https://bugzilla.gnome.org/show_bug.cgi?id=644926 pygobject missing header file in patch. not yet merged
cant call gdkwindow.raise()
raise is reserved word in Python. Workaround: getattr(win, 'raise')()
See http://mail.gnome.org/archives/python-hackers-list/2011-December/msg00011.html
xklavier
python-xklavier is based on pygtk codegen, we can probably just drop the link to pygtk, but failing that, we will need introspection bindings.
gdk_property_get
Not working:
def _property_get_trapped(window, prop, prop_type): Gdk.error_trap_push() prop_atom = Gdk.Atom.intern(prop, False) type_atom = Gdk.Atom.intern(prop_type, False) logging.warning("get prop %s %s %s", window, prop_atom, type_atom) prop_info = Gdk.property_get(window, prop_atom, type_atom, 0, 9999, False)
TypeError: Could not caller allocate argument 6 of callable property_get
ActivityIcon.do_draw never called
see http://mail.gnome.org/archives/python-hackers-list/2011-December/msg00013.html
Port hardcoded styles to the CSS stylesheet
For example in sugar/extensions/cpsection/network/view.py we have things like:
label_server = gtk.Label(_('Server:')) label_server.set_alignment(1, 0.5) label_server.modify_fg(gtk.STATE_NORMAL, style.COLOR_SELECTION_GREY.get_gdk_color())
We can use anything like this:
class SugarMenuItem(gtk.EventBox): __gsignals__ = { 'clicked': (gobject.SIGNAL_RUN_FIRST, None, []) } def __init__(self, icon_name, label_text): gtk.EventBox.__init__(self) self._sensitive = True vbox = gtk.VBox() hbox = gtk.HBox() vbox.set_border_width(style.DEFAULT_PADDING) self.icon = Icon() self.icon.props.icon_name = icon_name hbox.pack_start(self.icon, expand=False, fill=False, padding=style.DEFAULT_PADDING) align = gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0) text = '<span foreground="%s">' % style.COLOR_WHITE.get_html() + \ label_text + '</span>' self.label = gtk.Label() self.label.set_use_markup(True) self.label.set_markup(text) align.add(self.label) hbox.pack_start(align, expand=True, fill=True, padding=style.DEFAULT_PADDING) vbox.pack_start(hbox, expand=False, fill=False, padding=style.DEFAULT_PADDING) self.add(vbox) self.id_bt_release_cb = self.connect('button-release-event', self.__button_release_cb) self.id_enter_notify_cb = self.connect('enter-notify-event', self.__enter_notify_cb) self.id_leave_notify_cb = self.connect('leave-notify-event', self.__leave_notify_cb) self.modify_bg(gtk.STATE_NORMAL, style.COLOR_BLACK.get_gdk_color()) self.show_all() self.set_above_child(True) def __button_release_cb(self, widget, event): self.emit('clicked') def __enter_notify_cb(self, widget, event): self.modify_bg(gtk.STATE_NORMAL, style.COLOR_BUTTON_GREY.get_gdk_color()) def __leave_notify_cb(self, widget, event): self.modify_bg(gtk.STATE_NORMAL, style.COLOR_BLACK.get_gdk_color()) def set_icon(self, icon_name): self.icon.props.icon_name = icon_name def set_label(self, label_text): text = '<span foreground="%s">' % style.COLOR_WHITE.get_html() + \ label_text + '</span>' self.label.set_markup(text) def set_sensitive(self, sensitive): if self._sensitive == sensitive: return self._sensitive = sensitive if sensitive: self.handler_unblock(self.id_bt_release_cb) self.handler_unblock(self.id_enter_notify_cb) self.handler_unblock(self.id_leave_notify_cb) else: self.handler_block(self.id_bt_release_cb) self.handler_block(self.id_enter_notify_cb) self.handler_block(self.id_leave_notify_cb) self.modify_bg(gtk.STATE_NORMAL, style.COLOR_BLACK.get_gdk_color())
And add them to a vbox:
# TODO: private!!! self._content.set_border_width(0) self._play_pause_button = SugarMenuItem('player_play', _('Say selected text')) self._play_pause_button.connect('clicked', self.__play_clicked_cb) vbox_menu.add(self._play_pause_button)
To do the SegurMenuItem take all the width in the palette, we need set the border_width in _content to zero, but that is a private member. Then we need to look if we add a method to set the it, or change the api to make the first container (where is the menu today) useful for other type of widgets.