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') icon_name='document-save')
toolbar.toolbar.insert(tollbarbutton_4, -1) toolbar.toolbar.insert(tollbarbutton_4, -1)
print [i.props.page for i in toolbar.subs]
window.show_all() window.show_all()
gtk.main() gtk.main()

View File

@ -806,10 +806,6 @@ class Activity(Window, gtk.Container):
def get_document_path(self, async_cb, async_err_cb): def get_document_path(self, async_cb, async_err_cb):
async_err_cb(NotImplementedError()) 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 # DEPRECATED
_shared_activity = property(lambda self: self.shared_activity, None) _shared_activity = property(lambda self: self.shared_activity, None)

View File

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

View File

@ -36,14 +36,14 @@ class RadioMenuButton(ToolButton):
self.connect('clicked', self.__clicked_cb) self.connect('clicked', self.__clicked_cb)
def __clicked_cb(self, button): def __clicked_cb(self, button):
self._clicked() self.on_click()
def __palette_cb(self, widget, pspec): def __palette_cb(self, widget, pspec):
if not isinstance(self.props.palette, RadioPalette): if not isinstance(self.props.palette, RadioPalette):
return return
self.props.palette.update_button() self.props.palette.update_button()
def _clicked(self): def on_click(self):
if not self.palette: if not self.palette:
return return
if self.palette.is_up() and \ if self.palette.is_up() and \
@ -74,7 +74,7 @@ class RadioToolsButton(RadioMenuButton):
def __init__(self, **kwargs): def __init__(self, **kwargs):
RadioMenuButton.__init__(self, **kwargs) RadioMenuButton.__init__(self, **kwargs)
def _clicked(self): def on_click(self):
if not self.selected_button: if not self.selected_button:
return return
self.selected_button.emit('clicked') self.selected_button.emit('clicked')
@ -96,7 +96,7 @@ class RadioPalette(Palette):
button.show() button.show()
button.connect('clicked', self.__clicked_cb) button.connect('clicked', self.__clicked_cb)
self.button_box.pack_start(button, fill=False) self.button_box.pack_start(button, fill=False)
button.__palette_label = label button.palette_label = label
if not children: if not children:
self.__clicked_cb(button, True) self.__clicked_cb(button, True)
@ -109,7 +109,7 @@ class RadioPalette(Palette):
if not button.get_active(): if not button.get_active():
return return
self.set_primary_text(button.__palette_label) self.set_primary_text(button.palette_label)
if not quiet: if not quiet:
self.popdown(immediate=True) 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 import style
from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.palette import _PopupAnimation, _PopdownAnimation
from sugar.graphics.palette import MouseSpeedDetector, Invoker from sugar.graphics.palette import MouseSpeedDetector, Invoker
from sugar.graphics import animator from sugar.graphics.animator import Animator, Animation
from sugar.graphics import palettegroup from sugar.graphics import palettegroup
class ToolbarButton(ToolButton): class ToolbarButton(ToolButton):
@ -37,55 +36,56 @@ class ToolbarButton(ToolButton):
self.palette = _Palette(self) self.palette = _Palette(self)
self.connect('clicked', 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'): if not hasattr(self.parent, 'owner'):
return None return None
return self.parent.owner return self.parent.owner
toolbar = property(get_toolbar) toolbar_box = property(get_toolbar_box)
def get_page(self): def get_page(self):
return self._page.child.child return self._page.child.child
def set_page(self, page): def set_page(self, page):
self._page = _align(_Box, page) self._page = _embody_page(_Box, page)
self._page._toolitem = self self._page._toolitem = self
page.show() page.show()
page = gobject.property(type=object, getter=get_page, setter=set_page) page = gobject.property(type=object, getter=get_page, setter=set_page)
def get_expanded(self): def get_expanded(self):
return bool(self.toolbar) and bool(self._page) and \ return self.toolbar_box is not None and self._page is not None and \
self.toolbar._expanded_page() == self._page self.toolbar_box._expanded_page() == self._page
def set_expanded(self, value): 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 return
if isinstance(self.palette, _Palette) and self.palette.is_up(): if isinstance(self.palette, _Palette) and self.palette.is_up():
self.palette.popdown(immediate=True) self.palette.popdown(immediate=True)
if not value: if not value:
self.toolbar._shrink_page(self._page) self.toolbar_box.shrink_page(self._page)
return return
expanded = self.toolbar._expanded_page() expanded = self.toolbar_box._expanded_page()
if expanded and expanded._toolitem.window: if expanded and expanded._toolitem.window:
expanded._toolitem.window.invalidate_rect(None, True) expanded._toolitem.window.invalidate_rect(None, True)
if self._page.parent: if self._page.parent:
self.palette.remove(self._page) 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): 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) ToolButton.do_expose_event(self, event)
if self.palette and self.palette.is_up(): if self.palette and self.palette.is_up():
_paint_arrow(self, event, gtk.ARROW_UP) _paint_arrow(self, event, gtk.ARROW_UP)
@ -116,7 +116,7 @@ class ToolbarBox(gtk.VBox):
self.__toolbar = gtk.Toolbar() self.__toolbar = gtk.Toolbar()
self.__toolbar.owner = self 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.pack_start(top_widget)
self.props.padding = padding self.props.padding = padding
@ -162,7 +162,7 @@ class ToolbarBox(gtk.VBox):
page_no = self.__notebook.get_current_page() page_no = self.__notebook.get_current_page()
return self.__notebook.get_nth_page(page_no) 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) page_no = self.__notebook.page_num(page)
if page_no == -1: if page_no == -1:
return return
@ -211,10 +211,10 @@ class _Palette(gtk.Window):
self._invoker_hids = [] self._invoker_hids = []
self.__focus = 0 self.__focus = 0
self._popup_anim = animator.Animator(.5, 10) self._popup_anim = Animator(.5, 10)
self._popup_anim.add(_PopupAnimation(self)) 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)) self._popdown_anim.add(_PopdownAnimation(self))
accel_group = gtk.AccelGroup() accel_group = gtk.AccelGroup()
@ -270,8 +270,8 @@ class _Palette(gtk.Window):
def do_size_request(self, requisition): def do_size_request(self, requisition):
gtk.Window.do_size_request(self, requisition) gtk.Window.do_size_request(self, requisition)
if self._toolitem.toolbar: if self._toolitem.toolbar_box:
requisition.width = self._toolitem.toolbar.allocation.width requisition.width = self._toolitem.toolbar_box.allocation.width
def __realize_cb(self, widget): def __realize_cb(self, widget):
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
@ -282,10 +282,10 @@ class _Palette(gtk.Window):
def popup(self, immediate=False): def popup(self, immediate=False):
self._popdown_anim.stop() self._popdown_anim.stop()
toolbar = self._toolitem.toolbar toolbar = self._toolitem.toolbar_box
page = self._toolitem._page 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 return
_setup_page(page, style.COLOR_BLACK.get_gdk_color(), _setup_page(page, style.COLOR_BLACK.get_gdk_color(),
@ -366,6 +366,24 @@ class _Palette(gtk.Window):
self._invoker.notify_popdown() self._invoker.notify_popdown()
self._up = False 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): def _setup_page(page, color, hpad):
vpad = style._FOCUS_LINE_WIDTH vpad = style._FOCUS_LINE_WIDTH
page.child.set_padding(vpad, vpad, hpad, hpad) 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_NORMAL, color)
page.modify_bg(gtk.STATE_PRELIGHT, color) page.modify_bg(gtk.STATE_PRELIGHT, color)
def _align(box_class, widget): def _embody_page(box_class, widget):
widget.show() widget.show()
alignment = gtk.Alignment(0.0, 0.0, 1.0, 1.0) alignment = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
alignment.add(widget) alignment.add(widget)

View File

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