Fix review issues
This commit is contained in:
parent
0cf445eb0f
commit
872b18a103
@ -2,6 +2,7 @@ import gtk
|
||||
|
||||
from sugar.graphics.radiopalette import RadioPalette, RadioMenuButton, \
|
||||
RadioToolsButton
|
||||
from sugar.graphics.radiotoolbutton import RadioToolButton
|
||||
from sugar.graphics.toolbutton import ToolButton
|
||||
from sugar.graphics import style
|
||||
|
||||
@ -16,39 +17,61 @@ box.pack_start(toolbar, False)
|
||||
text_view = gtk.TextView()
|
||||
box.pack_start(text_view)
|
||||
|
||||
def echo(text):
|
||||
text_view.props.buffer.props.text += "\n" + text
|
||||
def echo(button):
|
||||
if not button.props.active:
|
||||
return
|
||||
text_view.props.buffer.props.text += "\n" + button.props.tooltip
|
||||
|
||||
# RadioMenuButton
|
||||
|
||||
palette = RadioPalette()
|
||||
palette.append(
|
||||
|
||||
group = RadioToolButton(
|
||||
icon_name='document-open',
|
||||
tooltip='menu.document-open',
|
||||
toggled_cb=lambda: echo('menu.document-open'))
|
||||
palette.append(
|
||||
tooltip='menu.document-open')
|
||||
group.connect('clicked', lambda button: echo(button))
|
||||
palette.append(group)
|
||||
|
||||
button = RadioToolButton(
|
||||
icon_name='document-save',
|
||||
tooltip='menu.document-save',
|
||||
toggled_cb=lambda: echo('menu.document-save'))
|
||||
palette.append(
|
||||
group=group,
|
||||
tooltip='menu.document-save')
|
||||
button.connect('clicked', lambda button: echo(button))
|
||||
palette.append(button)
|
||||
|
||||
button = RadioToolButton(
|
||||
icon_name='document-send',
|
||||
tooltip='menu.document-send',
|
||||
toggled_cb=lambda: echo('menu.document-send'))
|
||||
group=group,
|
||||
tooltip='menu.document-send')
|
||||
button.connect('clicked', lambda button: echo(button))
|
||||
palette.append(button)
|
||||
|
||||
button = RadioMenuButton(palette=palette)
|
||||
toolbar.insert(button, -1)
|
||||
|
||||
# RadioToolsButton
|
||||
|
||||
palette = RadioPalette()
|
||||
palette.append(
|
||||
|
||||
group = RadioToolButton(
|
||||
icon_name='document-open',
|
||||
tooltip='tools.document-open',
|
||||
toggled_cb=lambda: echo('tools.document-open'))
|
||||
palette.append(
|
||||
tooltip='menu.document-open')
|
||||
group.connect('clicked', lambda button: echo(button))
|
||||
palette.append(group)
|
||||
|
||||
button = RadioToolButton(
|
||||
icon_name='document-save',
|
||||
tooltip='tools.document-save',
|
||||
toggled_cb=lambda: echo('tools.document-save'))
|
||||
palette.append(
|
||||
group=group,
|
||||
tooltip='menu.document-save')
|
||||
button.connect('clicked', lambda button: echo(button))
|
||||
palette.append(button)
|
||||
|
||||
button = RadioToolButton(
|
||||
icon_name='document-send',
|
||||
tooltip='tools.document-send',
|
||||
toggled_cb=lambda: echo('tools.document-send'))
|
||||
group=group,
|
||||
tooltip='menu.document-send')
|
||||
button.connect('clicked', lambda button: echo(button))
|
||||
palette.append(button)
|
||||
|
||||
button = RadioToolsButton(palette=palette)
|
||||
toolbar.insert(button, -1)
|
||||
|
@ -75,6 +75,7 @@ from sugar.graphics.icon import Icon
|
||||
from sugar.graphics.xocolor import XoColor
|
||||
from sugar.graphics.toolbar import Toolbar, ToolbarButton
|
||||
from sugar.graphics.radiopalette import RadioPalette, RadioMenuButton
|
||||
from sugar.graphics.radiotoolbutton import RadioToolButton
|
||||
from sugar.datastore import datastore
|
||||
from sugar.session import XSMPClient
|
||||
from sugar import wm
|
||||
@ -1054,25 +1055,26 @@ def paste_button(**kwargs):
|
||||
return paste
|
||||
|
||||
def share_button(activity, **kwargs):
|
||||
quiet_trigger = []
|
||||
|
||||
def neighborhood_cb():
|
||||
if quiet_trigger:
|
||||
return
|
||||
def neighborhood_cb(button):
|
||||
activity.share()
|
||||
|
||||
palette = RadioPalette()
|
||||
private = palette.append(
|
||||
|
||||
private = RadioToolButton(
|
||||
icon_name='zoom-home',
|
||||
tooltip=_('Private'))
|
||||
neighborhood = palette.append(
|
||||
palette.append(private)
|
||||
|
||||
neighborhood = RadioToolButton(
|
||||
icon_name='zoom-neighborhood',
|
||||
tooltip=_('My Neighborhood'),
|
||||
toggled_cb=neighborhood_cb)
|
||||
group=private,
|
||||
tooltip=_('My Neighborhood'))
|
||||
neighborhood.connect('clicked', neighborhood_cb)
|
||||
palette.append(neighborhood)
|
||||
|
||||
def update_share():
|
||||
quiet_trigger.append(True)
|
||||
|
||||
neighborhood.handler_block_by_func(neighborhood_cb)
|
||||
try:
|
||||
if activity.get_shared():
|
||||
private.props.sensitive = False
|
||||
neighborhood.props.sensitive = False
|
||||
@ -1081,8 +1083,8 @@ def share_button(activity, **kwargs):
|
||||
private.props.sensitive = True
|
||||
neighborhood.props.sensitive = True
|
||||
private.props.active = True
|
||||
|
||||
quiet_trigger.pop()
|
||||
finally:
|
||||
neighborhood.handler_unblock_by_func(neighborhood_cb)
|
||||
|
||||
activity.connect('shared', lambda activity: update_share())
|
||||
activity.connect('joined', lambda activity: update_share())
|
||||
|
@ -1,29 +1,29 @@
|
||||
sugardir = $(pythondir)/sugar/graphics
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
alert.py \
|
||||
animator.py \
|
||||
canvastextview.py \
|
||||
combobox.py \
|
||||
colorbutton.py \
|
||||
combobox.py \
|
||||
entry.py \
|
||||
icon.py \
|
||||
iconentry.py \
|
||||
icon.py \
|
||||
__init__.py \
|
||||
menuitem.py \
|
||||
notebook.py \
|
||||
objectchooser.py \
|
||||
radiotoolbutton.py \
|
||||
palette.py \
|
||||
palettegroup.py \
|
||||
palette.py \
|
||||
panel.py \
|
||||
radiopalette.py \
|
||||
radiotoolbutton.py \
|
||||
roundbox.py \
|
||||
style.py \
|
||||
toggletoolbutton.py \
|
||||
toolbar.py \
|
||||
toolbox.py \
|
||||
toolbutton.py \
|
||||
toolcombobox.py \
|
||||
tray.py \
|
||||
window.py \
|
||||
xocolor.py \
|
||||
toolbar.py \
|
||||
radiopalette.py
|
||||
|
@ -18,21 +18,16 @@
|
||||
import gtk
|
||||
import gobject
|
||||
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.toolbutton import ToolButton
|
||||
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):
|
||||
def __init__(self, **kwargs):
|
||||
ToolButton.__init__(self, **kwargs)
|
||||
|
||||
self._button_cb = None
|
||||
self.selected_button = None
|
||||
|
||||
if self.props.palette:
|
||||
self.__palette_cb(None, None)
|
||||
@ -44,10 +39,6 @@ class RadioPaletteButton(ToolButton):
|
||||
return
|
||||
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):
|
||||
def __init__(self, **kwargs):
|
||||
RadioPaletteButton.__init__(self, **kwargs)
|
||||
@ -75,18 +66,19 @@ class RadioMenuButton(RadioPaletteButton):
|
||||
self.get_style().paint_arrow(event.window,
|
||||
gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, self,
|
||||
None, type, True,
|
||||
a.x + a.width/2 - ARROW_SIZE/2,
|
||||
a.y + a.height - ARROW_SIZE - style._FOCUS_LINE_WIDTH,
|
||||
ARROW_SIZE, ARROW_SIZE)
|
||||
a.x + a.width/2 - style.TOOLBAR_ARROW_SIZE/2,
|
||||
a.y + a.height - style.TOOLBAR_ARROW_SIZE - \
|
||||
style._FOCUS_LINE_WIDTH,
|
||||
style.TOOLBAR_ARROW_SIZE, style.TOOLBAR_ARROW_SIZE)
|
||||
|
||||
class RadioToolsButton(RadioPaletteButton):
|
||||
def __init__(self, **kwargs):
|
||||
RadioPaletteButton.__init__(self, **kwargs)
|
||||
|
||||
def do_clicked(self):
|
||||
if not self._button_cb:
|
||||
if not self.selected_button:
|
||||
return
|
||||
self._button_cb()
|
||||
self.selected_button.emit('clicked')
|
||||
|
||||
class RadioPalette(Palette):
|
||||
def __init__(self, **kwargs):
|
||||
@ -96,39 +88,31 @@ class RadioPalette(Palette):
|
||||
self.top.show()
|
||||
self.set_content(self.top)
|
||||
|
||||
def append(self, icon_name, tooltip=None, toggled_cb=None):
|
||||
def append(self, button):
|
||||
children = self.top.get_children()
|
||||
button = RadioToolButton(icon_name=icon_name,
|
||||
group=children and children[0] or None)
|
||||
|
||||
button.show()
|
||||
button.connect('toggled', self.__toggled_cb)
|
||||
button.connect('clicked', self.__clicked_cb)
|
||||
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:
|
||||
self.__toggled_cb(button, True)
|
||||
|
||||
return button
|
||||
self.__clicked_cb(button, True)
|
||||
|
||||
def update_button(self):
|
||||
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():
|
||||
return
|
||||
|
||||
self.set_primary_text(button.rp_tooltip)
|
||||
self.set_primary_text(button.props.tooltip)
|
||||
if not quiet:
|
||||
if button.rp_toggled_cb:
|
||||
button.rp_toggled_cb()
|
||||
self.popdown(immediate=True)
|
||||
|
||||
if not self.invoker or \
|
||||
not isinstance(self.invoker.parent, RadioPaletteButton):
|
||||
parent = self.invoker and self.invoker.parent
|
||||
if not isinstance(parent, RadioPaletteButton):
|
||||
return
|
||||
|
||||
self.invoker.parent._set_current_button(button)
|
||||
parent.set_icon(button.props.icon_name)
|
||||
parent.selected_button = button
|
||||
|
@ -27,9 +27,6 @@ from sugar.graphics.palette import MouseSpeedDetector, Invoker
|
||||
from sugar.graphics import animator
|
||||
from sugar.graphics import palettegroup
|
||||
|
||||
ARROW_SIZE = hasattr(style, 'TOOLBAR_ARROW_SIZE') and style.TOOLBAR_ARROW_SIZE \
|
||||
or 8
|
||||
|
||||
class ToolbarButton(ToolButton):
|
||||
def __init__(self, **kwargs):
|
||||
self._page = None
|
||||
@ -401,6 +398,6 @@ def _paint_arrow(widget, event, type):
|
||||
widget.get_style().paint_arrow(event.window,
|
||||
gtk.STATE_NORMAL, gtk.SHADOW_IN, event.area, widget,
|
||||
None, type, True,
|
||||
a.x + a.width/2 - ARROW_SIZE/2,
|
||||
a.y + a.height - ARROW_SIZE - style._FOCUS_LINE_WIDTH,
|
||||
ARROW_SIZE, ARROW_SIZE)
|
||||
a.x + a.width/2 - style.TOOLBAR_ARROW_SIZE/2,
|
||||
a.y + a.height - style.TOOLBAR_ARROW_SIZE - style._FOCUS_LINE_WIDTH,
|
||||
style.TOOLBAR_ARROW_SIZE, style.TOOLBAR_ARROW_SIZE)
|
||||
|
Loading…
Reference in New Issue
Block a user