[Sugar-devel] [sugar-toolkit-gtk3] Set getter an setter in icon_name property - SL #3849

Gonzalo Odiard godiard at sugarlabs.org
Wed Sep 19 15:13:27 EDT 2012


Today we explored with Simon different alternatives:

- override the icon-name property and fallback to what we do in
set_named_icon
- override the icon-name property and print a warning to use 'named_icon'
- override the icon-name property, do what we do in set_named_icon and
remove the named_icon property (there is not a better moment to do the last
one than now, if we think this is the right thing to do)

In toolbutton, we are using the icon_name property:

    def __init__(self, icon_name=None, **kwargs):
        .....
        if icon_name:
            self.set_icon(icon_name)

    def set_icon(self, icon_name):
        icon = Icon(icon_name=icon_name)
        self.set_icon_widget(icon)
        icon.show()

    icon_name = GObject.property(type=str, setter=set_icon)

In toogletoolbutton we are using named_icon and can be set as a parameter
when created,
there are a set_named_icon but there are not a property:

    def __init__(self, named_icon=None):
        ....
        self.set_named_icon(named_icon)

    def set_named_icon(self, named_icon):
        icon = Icon(icon_name=named_icon)
        self.set_icon_widget(icon)
        icon.show()

And in radiotoolbutton there are a property and a method named_icon, but
can't be set at creation time:

    def __init__(self, **kwargs):

    def set_named_icon(self, named_icon):
        icon = Icon(icon_name=named_icon,
                    xo_color=self._xo_color,
                    icon_size=Gtk.IconSize.LARGE_TOOLBAR)
        self.set_icon_widget(icon)
        icon.show()

    def get_named_icon(self):
        if self.props.icon_widget is not None:
            return self.props.icon_widget.props.icon_name
        else:
            return None

    named_icon = GObject.property(type=str, setter=set_named_icon,
                                  getter=get_named_icon)

(icon_name is a property of Gtk.Gtk.RadioToolButton, but is not set in the
same way,
and the button looks bigger)

I think we should have a consistent API, doing the same than in toolbutton.

Questions:

1) Do you agree with have a consistent API and do the change now in gtk3
toolkit?
2) What should we do with the old named_icon properties? Remove it?
Mark as deprecated?
How?

For reference, this is the use of named_icon in activities, remember this
is a change for gtk3 only, gtk2 activities don't need to do changes:

[gonzalo at nautilus honey]$ grep -rn named_icon * --include=*.py
abacus/mainline/toolbar_utils.py:90:    button.set_named_icon(button_name)
abacus/abacus-gtk3/toolbar_utils.py:45:    button.set_named_icon(icon_name)
calculate/mainline/toolbars.py:66:
 self.set_named_icon(items[0]['icon'])
calculate/mainline/toolbars.py:79:
 self.set_named_icon(but['icon'])
clock/mainline/clock.py:262:        button1 =
RadioToolButton(named_icon="simple-clock")
clock/mainline/clock.py:267:        button2 =
RadioToolButton(named_icon="nice-clock",
clock/mainline/clock.py:273:        button3 =
RadioToolButton(named_icon="digital-clock",
implode/mainline/implodeactivity.py:175:                button =
RadioToolButton(named_icon=icon_name,
implode/mainline/implodeactivity.py:178:                button =
RadioToolButton(named_icon=icon_name)
labyrinth/mainline/labyrinthactivity.py:353:        self._parent.mods[1] =
RadioToolButton(named_icon='text-mode')
labyrinth/mainline/labyrinthactivity.py:361:        self._parent.mods[2] =
RadioToolButton(named_icon='image-mode')
labyrinth/mainline/labyrinthactivity.py:369:        self._parent.mods[3] =
RadioToolButton(named_icon='draw-mode')
labyrinth/mainline/labyrinthactivity.py:377:        self._parent.mods[5] =
RadioToolButton(named_icon='label-mode')
measure/mainline/sensor_toolbar.py:88:
 self.time.set_named_icon('media-audio')
measure/mainline/sensor_toolbar.py:96:
 self.resistance.set_named_icon('resistance')
measure/mainline/sensor_toolbar.py:107:
 self.voltage.set_named_icon('voltage')
memorize/mainline/createtoolbar.py:101:
 self._equal_pairs.set_named_icon('pair-equals')
memorize/mainline/createtoolbar.py:105:
 self._equal_pairs.set_named_icon('pair-non-equals')
memorize/mainline/createtoolbar.py:114:
 self._grouped.set_named_icon('grouped_game2')
memorize/mainline/createtoolbar.py:118:
 self._grouped.set_named_icon('grouped_game1')
memorize/mainline/createcardpanel.py:332:
 named_icon='speak')
memorize/mainline/activity.py:215:
 button.set_named_icon('player_play')
memorize/mainline/activity.py:219:
 button.set_named_icon('view-source')
paint/mainline/toolbox.py:232:        RadioToolButton.__init__(self,
named_icon=icon_name)
physics/mainline/activity.py:151:            button =
RadioToolButton(named_icon=c.icon)
portfolio/portfolio/toolbar_utils.py:90:
 button.set_named_icon(button_name)
read/mainline/speechtoolbar.py:132:
 self.play_btn.set_named_icon('media-playback-start')
read/mainline/speechtoolbar.py:138:
 self.play_btn.set_named_icon('media-playback-pause')
read/mainline/speechtoolbar.py:142:
 self.play_btn.set_named_icon('media-playback-start')
read/mainline/speechtoolbar.py:147:
 self.play_btn.set_named_icon('media-playback-start')
speak/mainline/activity.py:134:                named_icon='mode-type',
speak/mainline/activity.py:140:                named_icon='mode-robot',
speak/mainline/activity.py:148:                named_icon='mode-chat',
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:121:
     self.preset1Button.set_named_icon('preset1')
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:128:
     self.preset2Button.set_named_icon('preset2')
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:135:
     self.preset3Button.set_named_icon('preset3')
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:142:
     self.preset4Button.set_named_icon('preset4')
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:149:
     self.preset5Button.set_named_icon('preset5')
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:156:
     self.preset6Button.set_named_icon('preset6')
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:163:
     self.preset7Button.set_named_icon('preset7')
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:170:
     self.preset8Button.set_named_icon('preset8')
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:177:
     self.preset9Button.set_named_icon('preset9')
tamtam/mainline/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:184:
     self.preset10Button.set_named_icon('preset10')
tamtam/mainline/TamTamJam.activity/Jam/Toolbars.py:161:
 btn.set_named_icon('beats')
tamtam/mainline/TamTamJam.activity/Jam/Toolbars.py:169:
 btn.set_named_icon('beats')
tamtam/mainline/TamTamJam.activity/Jam/Toolbars.py:271:
 btn.set_named_icon('preset1')
tamtam/mainline/TamTamJam.activity/Jam/Toolbars.py:279:
 btn.set_named_icon('preset%d'%i)
tamtam/mainline/TamTamEdit.activity/Edit/EditToolbars.py:89:
 self.pointerButton.set_named_icon('edit-pointer')
tamtam/mainline/TamTamEdit.activity/Edit/EditToolbars.py:98:
 self.drawButton.set_named_icon('edit-pencil')
tamtam/mainline/TamTamEdit.activity/Edit/EditToolbars.py:107:
 self.paintButton.set_named_icon('edit-brush')
tamtam/tamtam/Edit/EditToolbars.py:73:
 toolbar.pointerButton.set_named_icon('edit-pointer')
tamtam/tamtam/Edit/EditToolbars.py:82:
 toolbar.drawButton.set_named_icon('edit-pencil')
tamtam/tamtam/Edit/EditToolbars.py:91:
 toolbar.paintButton.set_named_icon('edit-brush')
tamtam/tamtam/Jam/Toolbars.py:188:        btn.set_named_icon('beats')
tamtam/tamtam/Jam/Toolbars.py:196:            btn.set_named_icon('beats')
tamtam/tamtam/Jam/Toolbars.py:282:        btn.set_named_icon('jam-preset1')
tamtam/tamtam/Jam/Toolbars.py:290:
 btn.set_named_icon('jam-preset%d' % i)
tamtam/tamtam/SynthLab/SynthLabToolbars.py:165:
 button.set_named_icon(name)
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:120:
       self.preset1Button.set_named_icon('preset1')
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:127:
       self.preset2Button.set_named_icon('preset2')
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:134:
       self.preset3Button.set_named_icon('preset3')
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:141:
       self.preset4Button.set_named_icon('preset4')
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:148:
       self.preset5Button.set_named_icon('preset5')
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:155:
       self.preset6Button.set_named_icon('preset6')
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:162:
       self.preset7Button.set_named_icon('preset7')
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:169:
       self.preset8Button.set_named_icon('preset8')
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:176:
       self.preset9Button.set_named_icon('preset9')
tamtam/tamtam.olpc/TamTamSynthLab.activity/SynthLab/SynthLabToolbars.py:183:
       self.preset10Button.set_named_icon('preset10')
tamtam/tamtam.olpc/TamTamJam.activity/Jam/Toolbars.py:160:
 btn.set_named_icon('beats')
tamtam/tamtam.olpc/TamTamJam.activity/Jam/Toolbars.py:168:
 btn.set_named_icon('beats')
tamtam/tamtam.olpc/TamTamJam.activity/Jam/Toolbars.py:270:
 btn.set_named_icon('preset1')
tamtam/tamtam.olpc/TamTamJam.activity/Jam/Toolbars.py:278:
 btn.set_named_icon('preset%d'%i)
tamtam/tamtam.olpc/TamTamEdit.activity/Edit/EditToolbars.py:90:
 self.pointerButton.set_named_icon('edit-pointer')
tamtam/tamtam.olpc/TamTamEdit.activity/Edit/EditToolbars.py:99:
 self.drawButton.set_named_icon('edit-pencil')
tamtam/tamtam.olpc/TamTamEdit.activity/Edit/EditToolbars.py:108:
 self.paintButton.set_named_icon('edit-brush')
turtleart/mainline/TurtleArtActivity.py:1244:
 button.set_named_icon(button_name)
write/mainline/speechtoolbar.py:158:
 self.play_btn.set_named_icon('media-playback-start')
write/mainline/speechtoolbar.py:166:
 self.play_btn.set_named_icon('media-playback-pause')
write/mainline/speechtoolbar.py:185:
 self.play_btn.set_named_icon('media-playback-start')
write/mainline/speechtoolbar.py:191:
 self.play_btn.set_named_icon('media-playback-start')

Gonzalo


On Tue, Sep 18, 2012 at 1:35 PM, Manuel Quiñones <manuq at laptop.org> wrote:

> Oh wait I overlooked this.  What's the benefit of having two
> properties exactly the same? I would vote to use named_icon as in the
> constructor, and change Paint.
>
> 2012/9/18 Manuel Quiñones <manuq at laptop.org>:
> > Thanks Gonzalo.  Yes this fixes the regression, which was affecting
> > Paint, and may affect other ports so I vote for adding this instead of
> > deprecating the API.  So now both:
> >
> > radial_button = RadioToolButton(named_icon='view-radial')
> >
> > and:
> >
> > radial_button = RadioToolButton()
> > radial_button.props.icon_name = 'view-radial'
> >
> > works.  Great.
> >
> > 2012/9/18  <godiard at sugarlabs.org>:
> >> From: Gonzalo Odiard <godiard at gmail.com>
> >>
> >> With g-i bindings, setting the property don't change the size
> >> and the button is bigger than should be.
> >> Now we have two properties for the same, icon_name and named_icon,
> >> maybe one should be deprecated.
> >>
> >> Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>
> >
> > Acked-by: Manuel Quiñones <manuq at laptop.org>
> >
> >> ---
> >>  src/sugar3/graphics/radiotoolbutton.py | 3 +++
> >>  1 file changed, 3 insertions(+)
> >>
> >> diff --git a/src/sugar3/graphics/radiotoolbutton.py
> b/src/sugar3/graphics/radiotoolbutton.py
> >> index 006d167..0c44347 100644
> >> --- a/src/sugar3/graphics/radiotoolbutton.py
> >> +++ b/src/sugar3/graphics/radiotoolbutton.py
> >> @@ -131,6 +131,9 @@ class RadioToolButton(Gtk.RadioToolButton):
> >>      named_icon = GObject.property(type=str, setter=set_named_icon,
> >>                                    getter=get_named_icon)
> >>
> >> +    icon_name = GObject.property(type=str, setter=set_named_icon,
> >> +                                  getter=get_named_icon)
> >
> > I will take care of the indentation here before pushing.
> >
> >> +
> >>      def set_xo_color(self, xo_color):
> >>          if self._xo_color != xo_color:
> >>              self._xo_color = xo_color
> >> --
> >> 1.7.11.4
> >>
> >> _______________________________________________
> >> Sugar-devel mailing list
> >> Sugar-devel at lists.sugarlabs.org
> >> http://lists.sugarlabs.org/listinfo/sugar-devel
> >
> >
> >
> > --
> > .. manuq ..
>
>
>
> --
> .. manuq ..
>



-- 
Gonzalo Odiard
SugarLabs Argentina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20120919/9694af0b/attachment-0001.html>


More information about the Sugar-devel mailing list