Fix review issues

This commit is contained in:
Aleksey Lim 2009-07-29 15:33:02 +00:00
parent 0cf445eb0f
commit 872b18a103
5 changed files with 116 additions and 110 deletions

View File

@ -2,6 +2,7 @@ import gtk
from sugar.graphics.radiopalette import RadioPalette, RadioMenuButton, \ from sugar.graphics.radiopalette import RadioPalette, RadioMenuButton, \
RadioToolsButton RadioToolsButton
from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toolbutton import ToolButton
from sugar.graphics import style from sugar.graphics import style
@ -16,39 +17,61 @@ box.pack_start(toolbar, False)
text_view = gtk.TextView() text_view = gtk.TextView()
box.pack_start(text_view) box.pack_start(text_view)
def echo(text): def echo(button):
text_view.props.buffer.props.text += "\n" + text if not button.props.active:
return
text_view.props.buffer.props.text += "\n" + button.props.tooltip
# RadioMenuButton
palette = RadioPalette() palette = RadioPalette()
palette.append(
group = RadioToolButton(
icon_name='document-open', icon_name='document-open',
tooltip='menu.document-open', tooltip='menu.document-open')
toggled_cb=lambda: echo('menu.document-open')) group.connect('clicked', lambda button: echo(button))
palette.append( palette.append(group)
button = RadioToolButton(
icon_name='document-save', icon_name='document-save',
tooltip='menu.document-save', group=group,
toggled_cb=lambda: echo('menu.document-save')) tooltip='menu.document-save')
palette.append( button.connect('clicked', lambda button: echo(button))
palette.append(button)
button = RadioToolButton(
icon_name='document-send', icon_name='document-send',
tooltip='menu.document-send', group=group,
toggled_cb=lambda: echo('menu.document-send')) tooltip='menu.document-send')
button.connect('clicked', lambda button: echo(button))
palette.append(button)
button = RadioMenuButton(palette=palette) button = RadioMenuButton(palette=palette)
toolbar.insert(button, -1) toolbar.insert(button, -1)
# RadioToolsButton
palette = RadioPalette() palette = RadioPalette()
palette.append(
group = RadioToolButton(
icon_name='document-open', icon_name='document-open',
tooltip='tools.document-open', tooltip='menu.document-open')
toggled_cb=lambda: echo('tools.document-open')) group.connect('clicked', lambda button: echo(button))
palette.append( palette.append(group)
button = RadioToolButton(
icon_name='document-save', icon_name='document-save',
tooltip='tools.document-save', group=group,
toggled_cb=lambda: echo('tools.document-save')) tooltip='menu.document-save')
palette.append( button.connect('clicked', lambda button: echo(button))
palette.append(button)
button = RadioToolButton(
icon_name='document-send', icon_name='document-send',
tooltip='tools.document-send', group=group,
toggled_cb=lambda: echo('tools.document-send')) tooltip='menu.document-send')
button.connect('clicked', lambda button: echo(button))
palette.append(button)
button = RadioToolsButton(palette=palette) button = RadioToolsButton(palette=palette)
toolbar.insert(button, -1) toolbar.insert(button, -1)

View File

@ -75,6 +75,7 @@ from sugar.graphics.icon import Icon
from sugar.graphics.xocolor import XoColor from sugar.graphics.xocolor import XoColor
from sugar.graphics.toolbar import Toolbar, ToolbarButton from sugar.graphics.toolbar import Toolbar, ToolbarButton
from sugar.graphics.radiopalette import RadioPalette, RadioMenuButton from sugar.graphics.radiopalette import RadioPalette, RadioMenuButton
from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.datastore import datastore from sugar.datastore import datastore
from sugar.session import XSMPClient from sugar.session import XSMPClient
from sugar import wm from sugar import wm
@ -1054,25 +1055,26 @@ def paste_button(**kwargs):
return paste return paste
def share_button(activity, **kwargs): def share_button(activity, **kwargs):
quiet_trigger = [] def neighborhood_cb(button):
def neighborhood_cb():
if quiet_trigger:
return
activity.share() activity.share()
palette = RadioPalette() palette = RadioPalette()
private = palette.append(
private = RadioToolButton(
icon_name='zoom-home', icon_name='zoom-home',
tooltip=_('Private')) tooltip=_('Private'))
neighborhood = palette.append( palette.append(private)
neighborhood = RadioToolButton(
icon_name='zoom-neighborhood', icon_name='zoom-neighborhood',
tooltip=_('My Neighborhood'), group=private,
toggled_cb=neighborhood_cb) tooltip=_('My Neighborhood'))
neighborhood.connect('clicked', neighborhood_cb)
palette.append(neighborhood)
def update_share(): def update_share():
quiet_trigger.append(True) neighborhood.handler_block_by_func(neighborhood_cb)
try:
if activity.get_shared(): if activity.get_shared():
private.props.sensitive = False private.props.sensitive = False
neighborhood.props.sensitive = False neighborhood.props.sensitive = False
@ -1081,8 +1083,8 @@ def share_button(activity, **kwargs):
private.props.sensitive = True private.props.sensitive = True
neighborhood.props.sensitive = True neighborhood.props.sensitive = True
private.props.active = True private.props.active = True
finally:
quiet_trigger.pop() neighborhood.handler_unblock_by_func(neighborhood_cb)
activity.connect('shared', lambda activity: update_share()) activity.connect('shared', lambda activity: update_share())
activity.connect('joined', lambda activity: update_share()) activity.connect('joined', lambda activity: update_share())

View File

@ -1,29 +1,29 @@
sugardir = $(pythondir)/sugar/graphics sugardir = $(pythondir)/sugar/graphics
sugar_PYTHON = \ sugar_PYTHON = \
__init__.py \
alert.py \ alert.py \
animator.py \ animator.py \
canvastextview.py \ canvastextview.py \
combobox.py \
colorbutton.py \ colorbutton.py \
combobox.py \
entry.py \ entry.py \
icon.py \
iconentry.py \ iconentry.py \
icon.py \
__init__.py \
menuitem.py \ menuitem.py \
notebook.py \ notebook.py \
objectchooser.py \ objectchooser.py \
radiotoolbutton.py \
palette.py \
palettegroup.py \ palettegroup.py \
palette.py \
panel.py \ panel.py \
radiopalette.py \
radiotoolbutton.py \
roundbox.py \ roundbox.py \
style.py \ style.py \
toggletoolbutton.py \ toggletoolbutton.py \
toolbar.py \
toolbox.py \ toolbox.py \
toolbutton.py \ toolbutton.py \
toolcombobox.py \ toolcombobox.py \
tray.py \ tray.py \
window.py \ window.py \
xocolor.py \ xocolor.py \
toolbar.py \
radiopalette.py

View File

@ -18,21 +18,16 @@
import gtk import gtk
import gobject import gobject
import logging import logging
from gobject import SIGNAL_RUN_FIRST, TYPE_NONE from gobject import SIGNAL_RUN_FIRST, TYPE_NONE, TYPE_PYOBJECT
from sugar.graphics import style from sugar.graphics import style
from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.palette import Palette from sugar.graphics.palette import Palette
from sugar.graphics.radiotoolbutton import RadioToolButton
ARROW_SIZE = hasattr(style, 'TOOLBAR_ARROW_SIZE') and style.TOOLBAR_ARROW_SIZE \
or 8
class RadioPaletteButton(ToolButton): class RadioPaletteButton(ToolButton):
def __init__(self, **kwargs): def __init__(self, **kwargs):
ToolButton.__init__(self, **kwargs) ToolButton.__init__(self, **kwargs)
self.selected_button = None
self._button_cb = None
if self.props.palette: if self.props.palette:
self.__palette_cb(None, None) self.__palette_cb(None, None)
@ -44,10 +39,6 @@ class RadioPaletteButton(ToolButton):
return return
self.props.palette.update_button() self.props.palette.update_button()
def _set_current_button(self, button):
self.set_icon(button.rp_icon_name)
self._button_cb = button.rp_toggled_cb
class RadioMenuButton(RadioPaletteButton): class RadioMenuButton(RadioPaletteButton):
def __init__(self, **kwargs): def __init__(self, **kwargs):
RadioPaletteButton.__init__(self, **kwargs) RadioPaletteButton.__init__(self, **kwargs)
@ -75,18 +66,19 @@ class RadioMenuButton(RadioPaletteButton):
self.get_style().paint_arrow(event.window, self.get_style().paint_arrow(event.window,
gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, self, gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, self,
None, type, True, None, type, True,
a.x + a.width/2 - ARROW_SIZE/2, a.x + a.width/2 - style.TOOLBAR_ARROW_SIZE/2,
a.y + a.height - ARROW_SIZE - style._FOCUS_LINE_WIDTH, a.y + a.height - style.TOOLBAR_ARROW_SIZE - \
ARROW_SIZE, ARROW_SIZE) style._FOCUS_LINE_WIDTH,
style.TOOLBAR_ARROW_SIZE, style.TOOLBAR_ARROW_SIZE)
class RadioToolsButton(RadioPaletteButton): class RadioToolsButton(RadioPaletteButton):
def __init__(self, **kwargs): def __init__(self, **kwargs):
RadioPaletteButton.__init__(self, **kwargs) RadioPaletteButton.__init__(self, **kwargs)
def do_clicked(self): def do_clicked(self):
if not self._button_cb: if not self.selected_button:
return return
self._button_cb() self.selected_button.emit('clicked')
class RadioPalette(Palette): class RadioPalette(Palette):
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -96,39 +88,31 @@ class RadioPalette(Palette):
self.top.show() self.top.show()
self.set_content(self.top) self.set_content(self.top)
def append(self, icon_name, tooltip=None, toggled_cb=None): def append(self, button):
children = self.top.get_children() children = self.top.get_children()
button = RadioToolButton(icon_name=icon_name,
group=children and children[0] or None)
button.show() button.show()
button.connect('toggled', self.__toggled_cb) button.connect('clicked', self.__clicked_cb)
self.top.pack_start(button, fill=False) self.top.pack_start(button, fill=False)
button.rp_icon_name = icon_name
button.rp_tooltip = tooltip
button.rp_toggled_cb = toggled_cb
if not children: if not children:
self.__toggled_cb(button, True) self.__clicked_cb(button, True)
return button
def update_button(self): def update_button(self):
for i in self.top.get_children(): for i in self.top.get_children():
self.__toggled_cb(i, True) self.__clicked_cb(i, True)
def __toggled_cb(self, button, quiet=False): def __clicked_cb(self, button, quiet=False):
if not button.get_active(): if not button.get_active():
return return
self.set_primary_text(button.rp_tooltip) self.set_primary_text(button.props.tooltip)
if not quiet: if not quiet:
if button.rp_toggled_cb:
button.rp_toggled_cb()
self.popdown(immediate=True) self.popdown(immediate=True)
if not self.invoker or \ parent = self.invoker and self.invoker.parent
not isinstance(self.invoker.parent, RadioPaletteButton): if not isinstance(parent, RadioPaletteButton):
return return
self.invoker.parent._set_current_button(button) parent.set_icon(button.props.icon_name)
parent.selected_button = button

View File

@ -27,9 +27,6 @@ from sugar.graphics.palette import MouseSpeedDetector, Invoker
from sugar.graphics import animator from sugar.graphics import animator
from sugar.graphics import palettegroup from sugar.graphics import palettegroup
ARROW_SIZE = hasattr(style, 'TOOLBAR_ARROW_SIZE') and style.TOOLBAR_ARROW_SIZE \
or 8
class ToolbarButton(ToolButton): class ToolbarButton(ToolButton):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self._page = None self._page = None
@ -401,6 +398,6 @@ def _paint_arrow(widget, event, type):
widget.get_style().paint_arrow(event.window, widget.get_style().paint_arrow(event.window,
gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, widget, gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, widget,
None, type, True, None, type, True,
a.x + a.width/2 - ARROW_SIZE/2, a.x + a.width/2 - style.TOOLBAR_ARROW_SIZE/2,
a.y + a.height - ARROW_SIZE - style._FOCUS_LINE_WIDTH, a.y + a.height - style.TOOLBAR_ARROW_SIZE - style._FOCUS_LINE_WIDTH,
ARROW_SIZE, ARROW_SIZE) style.TOOLBAR_ARROW_SIZE, style.TOOLBAR_ARROW_SIZE)