Fix review issues

This commit is contained in:
Aleksey Lim 2009-07-31 03:49:05 +00:00
parent 7bfb7704d7
commit 353564f12c
6 changed files with 119 additions and 98 deletions

View File

@ -46,7 +46,5 @@ tollbarbutton_4 = ToolbarButton(
icon_name='document-save')
toolbar.toolbar.insert(tollbarbutton_4, -1)
print [i.props.page for i in toolbar.subs]
window.show_all()
gtk.main()

View File

@ -806,10 +806,6 @@ class Activity(Window, gtk.Container):
def get_document_path(self, async_cb, async_err_cb):
async_err_cb(NotImplementedError())
def set_toolbar_box(self, toolbar_box):
# make more consistent using ToolbarBox instead of Toolbox
self.set_toolbox(toolbar_box)
# DEPRECATED
_shared_activity = property(lambda self: self.shared_activity, None)

View File

@ -50,10 +50,9 @@ class ActivityToolbarButton(ToolbarButton):
class StopButton(ToolButton):
def __init__(self, activity, **kwargs):
ToolButton.__init__(self, 'activity-stop',
tooltip=_('Stop'),
accelerator='<Ctrl>Q',
**kwargs)
ToolButton.__init__(self, 'activity-stop', **kwargs)
self.props.tooltip = _('Stop')
self.props.accelerator = '<Ctrl>Q'
self.connect('clicked', self.__stop_button_clicked_cb, activity)
def __stop_button_clicked_cb(self, button, activity):
@ -61,72 +60,68 @@ class StopButton(ToolButton):
class UndoButton(ToolButton):
def __init__(self, **kwargs):
ToolButton.__init__(self, 'edit-undo',
tooltip=_('Undo'),
accelerator='<Ctrl>Q',
**kwargs)
ToolButton.__init__(self, 'edit-undo', **kwargs)
self.props.tooltip = _('Undo')
self.props.accelerator = '<Ctrl>Q'
class RedoButton(ToolButton):
def __init__(self, **kwargs):
ToolButton.__init__(self, 'edit-redo',
tooltip=_('Redo'),
**kwargs)
ToolButton.__init__(self, 'edit-redo', **kwargs)
self.props.tooltip = _('Redo')
class CopyButton(ToolButton):
def __init__(self, **kwargs):
ToolButton.__init__(self, 'edit-copy',
tooltip=_('Copy'),
**kwargs)
ToolButton.__init__(self, 'edit-copy', **kwargs)
self.props.tooltip = _('Copy')
class PasteButton(ToolButton):
def __init__(self, **kwargs):
ToolButton.__init__(self, 'edit-paste',
tooltip=_('Paste'),
**kwargs)
ToolButton.__init__(self, 'edit-paste', **kwargs)
self.props.tooltip = _('Paste')
class ShareButton(RadioMenuButton):
def __init__(self, activity, **kwargs):
palette = RadioPalette()
self.__private = RadioToolButton(
self.private = RadioToolButton(
icon_name='zoom-home')
palette.append(self.__private, _('Private'))
palette.append(self.private, _('Private'))
self.__neighborhood = RadioToolButton(
self.neighborhood = RadioToolButton(
icon_name='zoom-neighborhood',
group=self.__private)
self.__neighborhood_handle = self.__neighborhood.connect(
group=self.private)
self.__neighborhood_handle = self.neighborhood.connect(
'clicked', self.__neighborhood_clicked_cb, activity)
palette.append(self.__neighborhood, _('My Neighborhood'))
palette.append(self.neighborhood, _('My Neighborhood'))
activity.connect('shared', self.__update_share)
activity.connect('joined', self.__update_share)
activity.connect('shared', self.__update_share_cb)
activity.connect('joined', self.__update_share_cb)
RadioMenuButton.__init__(self, palette=palette, **kwargs)
RadioMenuButton.__init__(self, **kwargs)
self.props.palette = palette
def __neighborhood_clicked_cb(self, button, activity):
activity.share()
def __update_share(self, activity):
self.__neighborhood.handler_block(self.__neighborhood_handle)
def __update_share_cb(self, activity):
self.neighborhood.handler_block(self.__neighborhood_handle)
try:
if activity.get_shared():
self.__private.props.sensitive = False
self.__neighborhood.props.sensitive = False
self.__neighborhood.props.active = True
self.private.props.sensitive = False
self.neighborhood.props.sensitive = False
self.neighborhood.props.active = True
else:
self.__private.props.sensitive = True
self.__neighborhood.props.sensitive = True
self.__private.props.active = True
self.private.props.sensitive = True
self.neighborhood.props.sensitive = True
self.private.props.active = True
finally:
self.__neighborhood.handler_unblock(self.__neighborhood_handle)
self.neighborhood.handler_unblock(self.__neighborhood_handle)
class KeepButton(ToolButton):
def __init__(self, activity, **kwargs):
ToolButton.__init__(self,
tooltip=_('Keep'),
accelerator='<Ctrl>S',
**kwargs)
ToolButton.__init__(self, **kwargs)
self.props.tooltip = _('Keep')
self.props.accelerator = '<Ctrl>S'
client = gconf.client_get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
@ -166,7 +161,7 @@ class TitleEntry(gtk.Entry):
activity.save()
shared_activity = activity.get_shared_activity()
if shared_activity:
if shared_activity is None:
shared_activity.props.name = title
self.__update_title_sid = None
@ -252,13 +247,11 @@ class EditToolbar(gtk.Toolbar):
def __init__(self):
gtk.Toolbar.__init__(self)
self.undo = ToolButton('edit-undo')
self.undo.set_tooltip(_('Undo'))
self.undo = UndoButton()
self.insert(self.undo, -1)
self.undo.show()
self.redo = ToolButton('edit-redo')
self.redo.set_tooltip(_('Redo'))
self.redo = RedoButton()
self.insert(self.redo, -1)
self.redo.show()
@ -267,13 +260,11 @@ class EditToolbar(gtk.Toolbar):
self.insert(self.separator, -1)
self.separator.show()
self.copy = ToolButton('edit-copy')
self.copy.set_tooltip(_('Copy'))
self.copy = CopyButton()
self.insert(self.copy, -1)
self.copy.show()
self.paste = ToolButton('edit-paste')
self.paste.set_tooltip(_('Paste'))
self.paste = PasteButton()
self.insert(self.paste, -1)
self.paste.show()

View File

@ -36,14 +36,14 @@ class RadioMenuButton(ToolButton):
self.connect('clicked', self.__clicked_cb)
def __clicked_cb(self, button):
self._clicked()
self.on_click()
def __palette_cb(self, widget, pspec):
if not isinstance(self.props.palette, RadioPalette):
return
self.props.palette.update_button()
def _clicked(self):
def on_click(self):
if not self.palette:
return
if self.palette.is_up() and \
@ -74,7 +74,7 @@ class RadioToolsButton(RadioMenuButton):
def __init__(self, **kwargs):
RadioMenuButton.__init__(self, **kwargs)
def _clicked(self):
def on_click(self):
if not self.selected_button:
return
self.selected_button.emit('clicked')
@ -96,7 +96,7 @@ class RadioPalette(Palette):
button.show()
button.connect('clicked', self.__clicked_cb)
self.button_box.pack_start(button, fill=False)
button.__palette_label = label
button.palette_label = label
if not children:
self.__clicked_cb(button, True)
@ -109,7 +109,7 @@ class RadioPalette(Palette):
if not button.get_active():
return
self.set_primary_text(button.__palette_label)
self.set_primary_text(button.palette_label)
if not quiet:
self.popdown(immediate=True)

View File

@ -22,9 +22,8 @@ from gobject import SIGNAL_RUN_FIRST, TYPE_NONE
from sugar.graphics import style
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.palette import _PopupAnimation, _PopdownAnimation
from sugar.graphics.palette import MouseSpeedDetector, Invoker
from sugar.graphics import animator
from sugar.graphics.animator import Animator, Animation
from sugar.graphics import palettegroup
class ToolbarButton(ToolButton):
@ -37,55 +36,56 @@ class ToolbarButton(ToolButton):
self.palette = _Palette(self)
self.connect('clicked',
lambda widget: self.set_expanded(not self.expanded))
lambda widget: self.set_expanded(not self.expanded_page))
def get_toolbar(self):
def get_toolbar_box(self):
if not hasattr(self.parent, 'owner'):
return None
return self.parent.owner
toolbar = property(get_toolbar)
toolbar_box = property(get_toolbar_box)
def get_page(self):
return self._page.child.child
def set_page(self, page):
self._page = _align(_Box, page)
self._page = _embody_page(_Box, page)
self._page._toolitem = self
page.show()
page = gobject.property(type=object, getter=get_page, setter=set_page)
def get_expanded(self):
return bool(self.toolbar) and bool(self._page) and \
self.toolbar._expanded_page() == self._page
return self.toolbar_box is not None and self._page is not None and \
self.toolbar_box._expanded_page() == self._page
def set_expanded(self, value):
if not self.toolbar or not self._page or self.get_expanded() == value:
if not self.toolbar_box or not self._page or \
self.get_expanded() == value:
return
if isinstance(self.palette, _Palette) and self.palette.is_up():
self.palette.popdown(immediate=True)
if not value:
self.toolbar._shrink_page(self._page)
self.toolbar_box.shrink_page(self._page)
return
expanded = self.toolbar._expanded_page()
expanded = self.toolbar_box._expanded_page()
if expanded and expanded._toolitem.window:
expanded._toolitem.window.invalidate_rect(None, True)
if self._page.parent:
self.palette.remove(self._page)
self.modify_bg(gtk.STATE_NORMAL, self.toolbar._bg)
self.modify_bg(gtk.STATE_NORMAL, self.toolbar_box._bg)
self.toolbar._expand_page(self._page)
self.toolbar_box._expand_page(self._page)
expanded = property(get_expanded, set_expanded)
expanded_page = property(get_expanded, set_expanded)
def do_expose_event(self, event):
if not self.expanded or self.palette and self.palette.is_up():
if not self.expanded_page or self.palette and self.palette.is_up():
ToolButton.do_expose_event(self, event)
if self.palette and self.palette.is_up():
_paint_arrow(self, event, gtk.ARROW_UP)
@ -116,7 +116,7 @@ class ToolbarBox(gtk.VBox):
self.__toolbar = gtk.Toolbar()
self.__toolbar.owner = self
top_widget = _align(gtk.EventBox, self.__toolbar)
top_widget = _embody_page(gtk.EventBox, self.__toolbar)
self.pack_start(top_widget)
self.props.padding = padding
@ -162,7 +162,7 @@ class ToolbarBox(gtk.VBox):
page_no = self.__notebook.get_current_page()
return self.__notebook.get_nth_page(page_no)
def _shrink_page(self, page):
def shrink_page(self, page):
page_no = self.__notebook.page_num(page)
if page_no == -1:
return
@ -211,10 +211,10 @@ class _Palette(gtk.Window):
self._invoker_hids = []
self.__focus = 0
self._popup_anim = animator.Animator(.5, 10)
self._popup_anim = Animator(.5, 10)
self._popup_anim.add(_PopupAnimation(self))
self._popdown_anim = animator.Animator(0.6, 10)
self._popdown_anim = Animator(0.6, 10)
self._popdown_anim.add(_PopdownAnimation(self))
accel_group = gtk.AccelGroup()
@ -270,8 +270,8 @@ class _Palette(gtk.Window):
def do_size_request(self, requisition):
gtk.Window.do_size_request(self, requisition)
if self._toolitem.toolbar:
requisition.width = self._toolitem.toolbar.allocation.width
if self._toolitem.toolbar_box:
requisition.width = self._toolitem.toolbar_box.allocation.width
def __realize_cb(self, widget):
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
@ -282,10 +282,10 @@ class _Palette(gtk.Window):
def popup(self, immediate=False):
self._popdown_anim.stop()
toolbar = self._toolitem.toolbar
toolbar = self._toolitem.toolbar_box
page = self._toolitem._page
if not self._invoker or self._toolitem.expanded or not toolbar:
if not self._invoker or self._toolitem.expanded_page or not toolbar:
return
_setup_page(page, style.COLOR_BLACK.get_gdk_color(),
@ -366,6 +366,24 @@ class _Palette(gtk.Window):
self._invoker.notify_popdown()
self._up = False
class _PopupAnimation(Animation):
def __init__(self, palette):
Animation.__init__(self, 0.0, 1.0)
self._palette = palette
def next_frame(self, current):
if current == 1.0:
self._palette.show()
class _PopdownAnimation(Animation):
def __init__(self, palette):
Animation.__init__(self, 0.0, 1.0)
self._palette = palette
def next_frame(self, current):
if current == 1.0:
self._palette.hide()
def _setup_page(page, color, hpad):
vpad = style._FOCUS_LINE_WIDTH
page.child.set_padding(vpad, vpad, hpad, hpad)
@ -373,7 +391,7 @@ def _setup_page(page, color, hpad):
page.modify_bg(gtk.STATE_NORMAL, color)
page.modify_bg(gtk.STATE_PRELIGHT, color)
def _align(box_class, widget):
def _embody_page(box_class, widget):
widget.show()
alignment = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
alignment.add(widget)

View File

@ -21,6 +21,8 @@ STABLE.
import gobject
import gtk
import logging
import warnings
from sugar.graphics.icon import Icon
@ -83,7 +85,7 @@ class Window(gtk.Window):
self.connect('window-state-event', self.__window_state_event_cb)
self.connect('key-press-event', self.__key_press_cb)
self.toolbox = None
self.__toolbar_box = None
self._alerts = []
self._canvas = None
self.tray = None
@ -120,14 +122,19 @@ class Window(gtk.Window):
canvas = property(get_canvas, set_canvas)
def set_toolbox(self, toolbox):
if self.toolbox:
self._vbox.remove(self.toolbox)
self._vbox.pack_start(toolbox, False)
self._vbox.reorder_child(toolbox, 0)
self.toolbox = toolbox
def get_toolbar_box(self):
return self.__toolbar_box
def set_toolbar_box(self, toolbar_box):
if self.__toolbar_box:
self._vbox.remove(self.__toolbar_box)
self._vbox.pack_start(toolbar_box, False)
self._vbox.reorder_child(toolbar_box, 0)
self.__toolbar_box = toolbar_box
toolbar_box = property(get_toolbar_box, set_toolbar_box)
def set_tray(self, tray, position):
if self.tray:
@ -147,7 +154,7 @@ class Window(gtk.Window):
self._alerts.append(alert)
if len(self._alerts) == 1:
self._vbox.pack_start(alert, False)
if self.toolbox is not None:
if self.__toolbar_box is not None:
self._vbox.reorder_child(alert, 1)
else:
self._vbox.reorder_child(alert, 0)
@ -160,7 +167,7 @@ class Window(gtk.Window):
self._vbox.remove(alert)
if len(self._alerts) >= 1:
self._vbox.pack_start(self._alerts[0], False)
if self.toolbox is not None:
if self.__toolbar_box is not None:
self._vbox.reorder_child(self._alerts[0], 1)
else:
self._vbox.reorder_child(self._alert[0], 0)
@ -175,8 +182,8 @@ class Window(gtk.Window):
return False
if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
if self.toolbox is not None:
self.toolbox.hide()
if self.__toolbar_box is not None:
self.__toolbar_box.hide()
if self.tray is not None:
self.tray.hide()
@ -185,8 +192,8 @@ class Window(gtk.Window):
self._unfullscreen_button.show()
else:
if self.toolbox is not None:
self.toolbox.show()
if self.__toolbar_box is not None:
self.__toolbar_box.show()
if self.tray is not None:
self.tray.show()
@ -219,3 +226,14 @@ class Window(gtk.Window):
setter=set_enable_fullscreen_mode,
getter=get_enable_fullscreen_mode)
# DEPRECATED
def set_toolbox(self, toolbar_box):
warnings.warn('use toolbar_box instead of toolbox', DeprecationWarning)
self.set_toolbar_box(toolbar_box)
def get_toolbox(self):
warnings.warn('use toolbar_box instead of toolbox', DeprecationWarning)
return self.__toolbar_box
toolbox = property(get_toolbox, set_toolbox)