Fix review issues
This commit is contained in:
parent
e03fd4ddde
commit
a2f20f39ff
@ -17,33 +17,30 @@ 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(button):
|
def echo(button, label):
|
||||||
if not button.props.active:
|
if not button.props.active:
|
||||||
return
|
return
|
||||||
text_view.props.buffer.props.text += "\n" + button.props.tooltip
|
text_view.props.buffer.props.text += "\n" + label
|
||||||
|
|
||||||
# RadioMenuButton
|
# RadioMenuButton
|
||||||
|
|
||||||
palette = RadioPalette()
|
palette = RadioPalette()
|
||||||
|
|
||||||
group = RadioToolButton(
|
group = RadioToolButton(
|
||||||
icon_name='document-open',
|
icon_name='document-open')
|
||||||
tooltip='menu.document-open')
|
group.connect('clicked', lambda button: echo(button, 'document-open'))
|
||||||
group.connect('clicked', lambda button: echo(button))
|
|
||||||
palette.append(group, 'menu.document-open')
|
palette.append(group, 'menu.document-open')
|
||||||
|
|
||||||
button = RadioToolButton(
|
button = RadioToolButton(
|
||||||
icon_name='document-save',
|
icon_name='document-save',
|
||||||
group=group,
|
group=group)
|
||||||
tooltip='menu.document-save')
|
button.connect('clicked', lambda button: echo(button, 'document-save'))
|
||||||
button.connect('clicked', lambda button: echo(button))
|
|
||||||
palette.append(button, 'menu.document-save')
|
palette.append(button, 'menu.document-save')
|
||||||
|
|
||||||
button = RadioToolButton(
|
button = RadioToolButton(
|
||||||
icon_name='document-send',
|
icon_name='document-send',
|
||||||
group=group,
|
group=group)
|
||||||
tooltip='menu.document-send')
|
button.connect('clicked', lambda button: echo(button, 'document-send'))
|
||||||
button.connect('clicked', lambda button: echo(button))
|
|
||||||
palette.append(button, 'menu.document-send')
|
palette.append(button, 'menu.document-send')
|
||||||
|
|
||||||
button = RadioMenuButton(palette=palette)
|
button = RadioMenuButton(palette=palette)
|
||||||
@ -54,23 +51,20 @@ toolbar.insert(button, -1)
|
|||||||
palette = RadioPalette()
|
palette = RadioPalette()
|
||||||
|
|
||||||
group = RadioToolButton(
|
group = RadioToolButton(
|
||||||
icon_name='document-open',
|
icon_name='document-open')
|
||||||
tooltip='menu.document-open')
|
group.connect('clicked', lambda button: echo(button, 'document-open'))
|
||||||
group.connect('clicked', lambda button: echo(button))
|
|
||||||
palette.append(group, 'menu.document-open')
|
palette.append(group, 'menu.document-open')
|
||||||
|
|
||||||
button = RadioToolButton(
|
button = RadioToolButton(
|
||||||
icon_name='document-save',
|
icon_name='document-save',
|
||||||
group=group,
|
group=group)
|
||||||
tooltip='menu.document-save')
|
button.connect('clicked', lambda button: echo(button, 'document-save'))
|
||||||
button.connect('clicked', lambda button: echo(button))
|
|
||||||
palette.append(button, 'menu.document-save')
|
palette.append(button, 'menu.document-save')
|
||||||
|
|
||||||
button = RadioToolButton(
|
button = RadioToolButton(
|
||||||
icon_name='document-send',
|
icon_name='document-send',
|
||||||
group=group,
|
group=group)
|
||||||
tooltip='menu.document-send')
|
button.connect('clicked', lambda button: echo(button, 'document-send'))
|
||||||
button.connect('clicked', lambda button: echo(button))
|
|
||||||
palette.append(button, 'menu.document-send')
|
palette.append(button, 'menu.document-send')
|
||||||
|
|
||||||
button = RadioToolsButton(palette=palette)
|
button = RadioToolsButton(palette=palette)
|
||||||
|
@ -61,7 +61,7 @@ import dbus
|
|||||||
import dbus.service
|
import dbus.service
|
||||||
import cjson
|
import cjson
|
||||||
|
|
||||||
from sugar import util
|
from sugar import util
|
||||||
from sugar.presence import presenceservice
|
from sugar.presence import presenceservice
|
||||||
from sugar.activity.activityservice import ActivityService
|
from sugar.activity.activityservice import ActivityService
|
||||||
from sugar.activity.namingalert import NamingAlert
|
from sugar.activity.namingalert import NamingAlert
|
||||||
@ -101,6 +101,12 @@ class ActivityToolbar(gtk.Toolbar):
|
|||||||
gtk.Toolbar.__init__(self)
|
gtk.Toolbar.__init__(self)
|
||||||
|
|
||||||
self._activity = activity
|
self._activity = activity
|
||||||
|
self._updating_share = False
|
||||||
|
|
||||||
|
activity.connect('shared', self.__activity_shared_cb)
|
||||||
|
activity.connect('joined', self.__activity_shared_cb)
|
||||||
|
activity.connect('notify::max_participants',
|
||||||
|
self.__max_participants_changed_cb)
|
||||||
|
|
||||||
if activity.metadata:
|
if activity.metadata:
|
||||||
self.title = gtk.Entry()
|
self.title = gtk.Entry()
|
||||||
@ -117,17 +123,66 @@ class ActivityToolbar(gtk.Toolbar):
|
|||||||
self.insert(separator, -1)
|
self.insert(separator, -1)
|
||||||
separator.show()
|
separator.show()
|
||||||
|
|
||||||
self.share = share_button(activity)
|
self.share = ToolComboBox(label_text=_('Share with:'))
|
||||||
|
self.share.combo.connect('changed', self.__share_changed_cb)
|
||||||
|
self.share.combo.append_item(SCOPE_PRIVATE, _('Private'), 'zoom-home')
|
||||||
|
self.share.combo.append_item(SCOPE_NEIGHBORHOOD, _('My Neighborhood'),
|
||||||
|
'zoom-neighborhood')
|
||||||
self.insert(self.share, -1)
|
self.insert(self.share, -1)
|
||||||
|
self.share.show()
|
||||||
|
|
||||||
self.keep = keep_button(activity)
|
self._update_share()
|
||||||
|
|
||||||
|
self.keep = ToolButton(tooltip=_('Keep'))
|
||||||
|
client = gconf.client_get_default()
|
||||||
|
color = XoColor(client.get_string('/desktop/sugar/user/color'))
|
||||||
|
keep_icon = Icon(icon_name='document-save', xo_color=color)
|
||||||
|
self.keep.set_icon_widget(keep_icon)
|
||||||
|
keep_icon.show()
|
||||||
|
self.keep.props.accelerator = '<Ctrl>S'
|
||||||
|
self.keep.connect('clicked', self.__keep_clicked_cb)
|
||||||
self.insert(self.keep, -1)
|
self.insert(self.keep, -1)
|
||||||
|
self.keep.show()
|
||||||
|
|
||||||
self.stop = stop_button(activity)
|
self.stop = ToolButton('activity-stop', tooltip=_('Stop'))
|
||||||
|
self.stop.props.accelerator = '<Ctrl>Q'
|
||||||
|
self.stop.connect('clicked', self.__stop_clicked_cb)
|
||||||
self.insert(self.stop, -1)
|
self.insert(self.stop, -1)
|
||||||
|
self.stop.show()
|
||||||
|
|
||||||
self._update_title_sid = None
|
self._update_title_sid = None
|
||||||
|
|
||||||
|
def _update_share(self):
|
||||||
|
self._updating_share = True
|
||||||
|
|
||||||
|
if self._activity.props.max_participants == 1:
|
||||||
|
self.share.hide()
|
||||||
|
|
||||||
|
if self._activity.get_shared():
|
||||||
|
self.share.set_sensitive(False)
|
||||||
|
self.share.combo.set_active(1)
|
||||||
|
else:
|
||||||
|
self.share.set_sensitive(True)
|
||||||
|
self.share.combo.set_active(0)
|
||||||
|
|
||||||
|
self._updating_share = False
|
||||||
|
|
||||||
|
def __share_changed_cb(self, combo):
|
||||||
|
if self._updating_share:
|
||||||
|
return
|
||||||
|
|
||||||
|
model = self.share.combo.get_model()
|
||||||
|
it = self.share.combo.get_active_iter()
|
||||||
|
(scope, ) = model.get(it, 0)
|
||||||
|
if scope == SCOPE_NEIGHBORHOOD:
|
||||||
|
self._activity.share()
|
||||||
|
|
||||||
|
def __keep_clicked_cb(self, button):
|
||||||
|
self._activity.copy()
|
||||||
|
|
||||||
|
def __stop_clicked_cb(self, button):
|
||||||
|
self._activity.close()
|
||||||
|
|
||||||
def __jobject_updated_cb(self, jobject):
|
def __jobject_updated_cb(self, jobject):
|
||||||
self.title.set_text(jobject['title'])
|
self.title.set_text(jobject['title'])
|
||||||
|
|
||||||
@ -160,9 +215,15 @@ class ActivityToolbar(gtk.Toolbar):
|
|||||||
self.insert(tool_item, -1)
|
self.insert(tool_item, -1)
|
||||||
tool_item.show()
|
tool_item.show()
|
||||||
|
|
||||||
|
def __activity_shared_cb(self, activity):
|
||||||
|
self._update_share()
|
||||||
|
|
||||||
|
def __max_participants_changed_cb(self, activity, pspec):
|
||||||
|
self._update_share()
|
||||||
|
|
||||||
class EditToolbar(gtk.Toolbar):
|
class EditToolbar(gtk.Toolbar):
|
||||||
"""Provides the standard edit toolbar for Activities.
|
"""Provides the standard edit toolbar for Activities.
|
||||||
|
|
||||||
Members:
|
Members:
|
||||||
undo -- the undo button
|
undo -- the undo button
|
||||||
redo -- the redo button
|
redo -- the redo button
|
||||||
@ -196,20 +257,30 @@ class EditToolbar(gtk.Toolbar):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
gtk.Toolbar.__init__(self)
|
gtk.Toolbar.__init__(self)
|
||||||
|
|
||||||
self.undo = undo_button()
|
self.undo = ToolButton('edit-undo')
|
||||||
|
self.undo.set_tooltip(_('Undo'))
|
||||||
self.insert(self.undo, -1)
|
self.insert(self.undo, -1)
|
||||||
|
self.undo.show()
|
||||||
|
|
||||||
self.redo = redo_button()
|
self.redo = ToolButton('edit-redo')
|
||||||
|
self.redo.set_tooltip(_('Redo'))
|
||||||
self.insert(self.redo, -1)
|
self.insert(self.redo, -1)
|
||||||
|
self.redo.show()
|
||||||
|
|
||||||
self.separator = separator()
|
self.separator = gtk.SeparatorToolItem()
|
||||||
|
self.separator.set_draw(True)
|
||||||
self.insert(self.separator, -1)
|
self.insert(self.separator, -1)
|
||||||
|
self.separator.show()
|
||||||
|
|
||||||
self.copy = copy_button()
|
self.copy = ToolButton('edit-copy')
|
||||||
|
self.copy.set_tooltip(_('Copy'))
|
||||||
self.insert(self.copy, -1)
|
self.insert(self.copy, -1)
|
||||||
|
self.copy.show()
|
||||||
|
|
||||||
self.paste = paste_button()
|
self.paste = ToolButton('edit-paste')
|
||||||
|
self.paste.set_tooltip(_('Paste'))
|
||||||
self.insert(self.paste, -1)
|
self.insert(self.paste, -1)
|
||||||
|
self.paste.show()
|
||||||
|
|
||||||
class ActivityToolbox(Toolbox):
|
class ActivityToolbox(Toolbox):
|
||||||
"""Creates the Toolbox for the Activity
|
"""Creates the Toolbox for the Activity
|
||||||
@ -962,6 +1033,126 @@ class Activity(Window, gtk.Container):
|
|||||||
# DEPRECATED
|
# DEPRECATED
|
||||||
_shared_activity = property(lambda self: self.shared_activity, None)
|
_shared_activity = property(lambda self: self.shared_activity, None)
|
||||||
|
|
||||||
|
class ActivityToolbarButton(ToolbarButton):
|
||||||
|
def __init__(self, activity, **kwargs):
|
||||||
|
from jarabe.journal.misc import get_icon_name
|
||||||
|
|
||||||
|
toolbar = ActivityToolbar(activity)
|
||||||
|
toolbar.stop.hide()
|
||||||
|
|
||||||
|
ToolbarButton.__init__(self, page=toolbar, **kwargs)
|
||||||
|
|
||||||
|
self.activity = activity
|
||||||
|
|
||||||
|
client = gconf.client_get_default()
|
||||||
|
color = XoColor(client.get_string('/desktop/sugar/user/color'))
|
||||||
|
icon = Icon(file=get_icon_name(activity.metadata), xo_color=color)
|
||||||
|
icon.show()
|
||||||
|
self.set_icon_widget(icon)
|
||||||
|
|
||||||
|
def expander(self):
|
||||||
|
separator = gtk.SeparatorToolItem()
|
||||||
|
separator.props.draw = False
|
||||||
|
separator.set_expand(True)
|
||||||
|
separator.show()
|
||||||
|
return separator
|
||||||
|
|
||||||
|
def stop_button(self, **kwargs):
|
||||||
|
stop = ToolButton('activity-stop', tooltip=_('Stop'), **kwargs)
|
||||||
|
stop.props.accelerator = '<Ctrl>Q'
|
||||||
|
stop.connect('clicked', self.__stop_button_clicked_cb)
|
||||||
|
stop.show()
|
||||||
|
return stop
|
||||||
|
|
||||||
|
def __stop_button_clicked_cb(self, button):
|
||||||
|
self.activity.close()
|
||||||
|
|
||||||
|
def undo_button(self, **kwargs):
|
||||||
|
undo = ToolButton('edit-undo', **kwargs)
|
||||||
|
undo.set_tooltip(_('Undo'))
|
||||||
|
undo.show()
|
||||||
|
return undo
|
||||||
|
|
||||||
|
def redo_button(self, **kwargs):
|
||||||
|
redo = ToolButton('edit-redo', **kwargs)
|
||||||
|
redo.set_tooltip(_('Redo'))
|
||||||
|
redo.show()
|
||||||
|
return redo
|
||||||
|
|
||||||
|
def separator(self, **kwargs):
|
||||||
|
separator = gtk.SeparatorToolItem(**kwargs)
|
||||||
|
separator.set_draw(True)
|
||||||
|
separator.show()
|
||||||
|
return separator
|
||||||
|
|
||||||
|
def copy_button(self, **kwargs):
|
||||||
|
copy = ToolButton('edit-copy', **kwargs)
|
||||||
|
copy.set_tooltip(_('Copy'))
|
||||||
|
copy.show()
|
||||||
|
return copy
|
||||||
|
|
||||||
|
def paste_button(self, **kwargs):
|
||||||
|
paste = ToolButton('edit-paste', **kwargs)
|
||||||
|
paste.set_tooltip(_('Paste'))
|
||||||
|
paste.show()
|
||||||
|
return paste
|
||||||
|
|
||||||
|
def share_button(self):
|
||||||
|
palette = RadioPalette()
|
||||||
|
|
||||||
|
private = RadioToolButton(
|
||||||
|
icon_name='zoom-home')
|
||||||
|
palette.append(private, _('Private'))
|
||||||
|
|
||||||
|
neighborhood = RadioToolButton(
|
||||||
|
icon_name='zoom-neighborhood',
|
||||||
|
group=private)
|
||||||
|
neighborhood_handle = neighborhood.connect('clicked',
|
||||||
|
self.__neighborhood_clicked_cb)
|
||||||
|
palette.append(neighborhood, _('My Neighborhood'))
|
||||||
|
|
||||||
|
self.activity.connect('shared', self.__update_share)
|
||||||
|
self.activity.connect('joined', self.__update_share)
|
||||||
|
|
||||||
|
share = RadioMenuButton(palette=palette)
|
||||||
|
share.show()
|
||||||
|
|
||||||
|
return share
|
||||||
|
|
||||||
|
def __neighborhood_clicked_cb(self, button):
|
||||||
|
self.activity.share()
|
||||||
|
|
||||||
|
def __update_share(self, activity):
|
||||||
|
neighborhood.handler_block(neighborhood_handle)
|
||||||
|
try:
|
||||||
|
if self.activity.get_shared():
|
||||||
|
private.props.sensitive = False
|
||||||
|
neighborhood.props.sensitive = False
|
||||||
|
neighborhood.props.active = True
|
||||||
|
else:
|
||||||
|
private.props.sensitive = True
|
||||||
|
neighborhood.props.sensitive = True
|
||||||
|
private.props.active = True
|
||||||
|
finally:
|
||||||
|
neighborhood.handler_unblock(neighborhood_handle)
|
||||||
|
|
||||||
|
def keep_button(self, **kwargs):
|
||||||
|
client = gconf.client_get_default()
|
||||||
|
color = XoColor(client.get_string('/desktop/sugar/user/color'))
|
||||||
|
keep_icon = Icon(icon_name='document-save', xo_color=color)
|
||||||
|
keep_icon.show()
|
||||||
|
|
||||||
|
keep = ToolButton(tooltip=_('Keep'), **kwargs)
|
||||||
|
keep.set_icon_widget(keep_icon)
|
||||||
|
keep.props.accelerator = '<Ctrl>S'
|
||||||
|
keep.connect('clicked', self.__keep_button_clicked)
|
||||||
|
keep.show()
|
||||||
|
|
||||||
|
return keep
|
||||||
|
|
||||||
|
def __keep_button_clicked(self, button):
|
||||||
|
self.activity.copy()
|
||||||
|
|
||||||
_session = None
|
_session = None
|
||||||
|
|
||||||
def _get_session():
|
def _get_session():
|
||||||
@ -975,7 +1166,7 @@ def _get_session():
|
|||||||
def get_bundle_name():
|
def get_bundle_name():
|
||||||
"""Return the bundle name for the current process' bundle"""
|
"""Return the bundle name for the current process' bundle"""
|
||||||
return os.environ['SUGAR_BUNDLE_NAME']
|
return os.environ['SUGAR_BUNDLE_NAME']
|
||||||
|
|
||||||
def get_bundle_path():
|
def get_bundle_path():
|
||||||
"""Return the bundle path for the current process' bundle"""
|
"""Return the bundle path for the current process' bundle"""
|
||||||
return os.environ['SUGAR_BUNDLE_PATH']
|
return os.environ['SUGAR_BUNDLE_PATH']
|
||||||
@ -993,113 +1184,3 @@ def show_object_in_journal(object_id):
|
|||||||
obj = bus.get_object(J_DBUS_SERVICE, J_DBUS_PATH)
|
obj = bus.get_object(J_DBUS_SERVICE, J_DBUS_PATH)
|
||||||
journal = dbus.Interface(obj, J_DBUS_INTERFACE)
|
journal = dbus.Interface(obj, J_DBUS_INTERFACE)
|
||||||
journal.ShowObject(object_id)
|
journal.ShowObject(object_id)
|
||||||
|
|
||||||
def toolbar(activity):
|
|
||||||
from jarabe.journal.misc import get_icon_name
|
|
||||||
|
|
||||||
toolbar = ActivityToolbar(activity)
|
|
||||||
toolbar.stop.hide()
|
|
||||||
activity_button = ToolbarButton(page=toolbar)
|
|
||||||
activity_button.show()
|
|
||||||
|
|
||||||
client = gconf.client_get_default()
|
|
||||||
color = XoColor(client.get_string('/desktop/sugar/user/color'))
|
|
||||||
icon = Icon(file=get_icon_name(activity.metadata), xo_color=color)
|
|
||||||
icon.show()
|
|
||||||
activity_button.set_icon_widget(icon)
|
|
||||||
|
|
||||||
return activity_button
|
|
||||||
|
|
||||||
def expander():
|
|
||||||
separator = gtk.SeparatorToolItem()
|
|
||||||
separator.props.draw = False
|
|
||||||
separator.set_expand(True)
|
|
||||||
separator.show()
|
|
||||||
return separator
|
|
||||||
|
|
||||||
def stop_button(activity, **kwargs):
|
|
||||||
stop = ToolButton('activity-stop', tooltip=_('Stop'), **kwargs)
|
|
||||||
stop.props.accelerator = '<Ctrl>Q'
|
|
||||||
stop.connect('clicked', lambda button: activity.close())
|
|
||||||
stop.show()
|
|
||||||
return stop
|
|
||||||
|
|
||||||
def undo_button(**kwargs):
|
|
||||||
undo = ToolButton('edit-undo', **kwargs)
|
|
||||||
undo.set_tooltip(_('Undo'))
|
|
||||||
undo.show()
|
|
||||||
return undo
|
|
||||||
|
|
||||||
def redo_button(**kwargs):
|
|
||||||
redo = ToolButton('edit-redo', **kwargs)
|
|
||||||
redo.set_tooltip(_('Redo'))
|
|
||||||
redo.show()
|
|
||||||
return redo
|
|
||||||
|
|
||||||
def separator(**kwargs):
|
|
||||||
separator = gtk.SeparatorToolItem(**kwargs)
|
|
||||||
separator.set_draw(True)
|
|
||||||
separator.show()
|
|
||||||
return separator
|
|
||||||
|
|
||||||
def copy_button(**kwargs):
|
|
||||||
copy = ToolButton('edit-copy', **kwargs)
|
|
||||||
copy.set_tooltip(_('Copy'))
|
|
||||||
copy.show()
|
|
||||||
return copy
|
|
||||||
|
|
||||||
def paste_button(**kwargs):
|
|
||||||
paste = ToolButton('edit-paste', **kwargs)
|
|
||||||
paste.set_tooltip(_('Paste'))
|
|
||||||
paste.show()
|
|
||||||
return paste
|
|
||||||
|
|
||||||
def share_button(activity, **kwargs):
|
|
||||||
palette = RadioPalette()
|
|
||||||
|
|
||||||
private = RadioToolButton(
|
|
||||||
icon_name='zoom-home')
|
|
||||||
palette.append(private, _('Private'))
|
|
||||||
|
|
||||||
neighborhood = RadioToolButton(
|
|
||||||
icon_name='zoom-neighborhood',
|
|
||||||
group=private)
|
|
||||||
neighborhood_handle = neighborhood.connect('clicked',
|
|
||||||
lambda button: activity.share())
|
|
||||||
palette.append(neighborhood, _('My Neighborhood'))
|
|
||||||
|
|
||||||
def update_share():
|
|
||||||
neighborhood.handler_block(neighborhood_handle)
|
|
||||||
try:
|
|
||||||
if activity.get_shared():
|
|
||||||
private.props.sensitive = False
|
|
||||||
neighborhood.props.sensitive = False
|
|
||||||
neighborhood.props.active = True
|
|
||||||
else:
|
|
||||||
private.props.sensitive = True
|
|
||||||
neighborhood.props.sensitive = True
|
|
||||||
private.props.active = True
|
|
||||||
finally:
|
|
||||||
neighborhood.handler_unblock(neighborhood_handle)
|
|
||||||
|
|
||||||
activity.connect('shared', lambda activity: update_share())
|
|
||||||
activity.connect('joined', lambda activity: update_share())
|
|
||||||
|
|
||||||
share = RadioMenuButton(palette=palette)
|
|
||||||
share.show()
|
|
||||||
|
|
||||||
return share
|
|
||||||
|
|
||||||
def keep_button(activity, **kwargs):
|
|
||||||
client = gconf.client_get_default()
|
|
||||||
color = XoColor(client.get_string('/desktop/sugar/user/color'))
|
|
||||||
keep_icon = Icon(icon_name='document-save', xo_color=color)
|
|
||||||
keep_icon.show()
|
|
||||||
|
|
||||||
keep = ToolButton(tooltip=_('Keep'), **kwargs)
|
|
||||||
keep.set_icon_widget(keep_icon)
|
|
||||||
keep.props.accelerator = '<Ctrl>S'
|
|
||||||
keep.connect('clicked', lambda button: activity.copy())
|
|
||||||
keep.show()
|
|
||||||
|
|
||||||
return keep
|
|
||||||
|
@ -24,7 +24,7 @@ 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
|
||||||
|
|
||||||
class RadioPaletteButton(ToolButton):
|
class RadioMenuButton(ToolButton):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
ToolButton.__init__(self, **kwargs)
|
ToolButton.__init__(self, **kwargs)
|
||||||
self.selected_button = None
|
self.selected_button = None
|
||||||
@ -39,10 +39,7 @@ class RadioPaletteButton(ToolButton):
|
|||||||
return
|
return
|
||||||
self.props.palette.update_button()
|
self.props.palette.update_button()
|
||||||
|
|
||||||
class RadioMenuButton(RadioPaletteButton):
|
# We use do_clicked to have a chance to override it in RadioToolsButton
|
||||||
def __init__(self, **kwargs):
|
|
||||||
RadioPaletteButton.__init__(self, **kwargs)
|
|
||||||
|
|
||||||
def do_clicked(self):
|
def do_clicked(self):
|
||||||
if not self.palette:
|
if not self.palette:
|
||||||
return
|
return
|
||||||
@ -58,22 +55,21 @@ class RadioMenuButton(RadioPaletteButton):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.palette.is_up():
|
if self.palette.is_up():
|
||||||
type = gtk.ARROW_DOWN
|
|
||||||
else:
|
|
||||||
type = gtk.ARROW_UP
|
type = gtk.ARROW_UP
|
||||||
|
else:
|
||||||
|
type = gtk.ARROW_DOWN
|
||||||
|
|
||||||
a = self.allocation
|
alloc = self.allocation
|
||||||
|
x = alloc.x + alloc.width / 2 - style.TOOLBAR_ARROW_SIZE / 2
|
||||||
|
y = alloc.y + alloc.height - int(style.TOOLBAR_ARROW_SIZE * .85)
|
||||||
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_NONE, event.area, self,
|
||||||
None, type, True,
|
None, type, True,
|
||||||
a.x + a.width/2 - style.TOOLBAR_ARROW_SIZE/2,
|
x, y, style.TOOLBAR_ARROW_SIZE, style.TOOLBAR_ARROW_SIZE)
|
||||||
a.y + a.height - style.TOOLBAR_ARROW_SIZE - \
|
|
||||||
style._FOCUS_LINE_WIDTH,
|
|
||||||
style.TOOLBAR_ARROW_SIZE, style.TOOLBAR_ARROW_SIZE)
|
|
||||||
|
|
||||||
class RadioToolsButton(RadioPaletteButton):
|
class RadioToolsButton(RadioMenuButton):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
RadioPaletteButton.__init__(self, **kwargs)
|
RadioMenuButton.__init__(self, **kwargs)
|
||||||
|
|
||||||
def do_clicked(self):
|
def do_clicked(self):
|
||||||
if not self.selected_button:
|
if not self.selected_button:
|
||||||
@ -84,26 +80,26 @@ class RadioPalette(Palette):
|
|||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
Palette.__init__(self, **kwargs)
|
Palette.__init__(self, **kwargs)
|
||||||
|
|
||||||
self.top = gtk.HBox()
|
self.button_box = gtk.HBox()
|
||||||
self.top.show()
|
self.button_box.show()
|
||||||
self.set_content(self.top)
|
self.set_content(self.button_box)
|
||||||
|
|
||||||
def append(self, button, label):
|
def append(self, button, label):
|
||||||
children = self.top.get_children()
|
children = self.button_box.get_children()
|
||||||
|
|
||||||
# palette's button should not have sub-palettes
|
if button.palette is not None:
|
||||||
button.palette = None
|
raise RuntimeError("Palette's button should not have sub-palettes")
|
||||||
|
|
||||||
button.show()
|
button.show()
|
||||||
button.connect('clicked', self.__clicked_cb)
|
button.connect('clicked', self.__clicked_cb)
|
||||||
self.top.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)
|
||||||
|
|
||||||
def update_button(self):
|
def update_button(self):
|
||||||
for i in self.top.get_children():
|
for i in self.button_box.get_children():
|
||||||
self.__clicked_cb(i, True)
|
self.__clicked_cb(i, True)
|
||||||
|
|
||||||
def __clicked_cb(self, button, quiet=False):
|
def __clicked_cb(self, button, quiet=False):
|
||||||
@ -114,8 +110,11 @@ class RadioPalette(Palette):
|
|||||||
if not quiet:
|
if not quiet:
|
||||||
self.popdown(immediate=True)
|
self.popdown(immediate=True)
|
||||||
|
|
||||||
parent = self.invoker and self.invoker.parent
|
if self.invoker is not None:
|
||||||
if not isinstance(parent, RadioPaletteButton):
|
parent = self.invoker.parent
|
||||||
|
else:
|
||||||
|
parent = None
|
||||||
|
if not isinstance(parent, RadioMenuButton):
|
||||||
return
|
return
|
||||||
|
|
||||||
parent.set_icon(button.props.icon_name)
|
parent.set_icon(button.props.icon_name)
|
||||||
|
@ -132,4 +132,4 @@ COLOR_TEXT_FIELD_GREY = Color('#E5E5E5')
|
|||||||
|
|
||||||
PALETTE_CURSOR_DISTANCE = zoom(10)
|
PALETTE_CURSOR_DISTANCE = zoom(10)
|
||||||
|
|
||||||
TOOLBAR_ARROW_SIZE = 8
|
TOOLBAR_ARROW_SIZE = zoom(24)
|
||||||
|
@ -88,9 +88,9 @@ class ToolbarButton(ToolButton):
|
|||||||
if not self.expanded or self.palette and self.palette.is_up():
|
if not self.expanded 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_DOWN)
|
|
||||||
else:
|
|
||||||
_paint_arrow(self, event, gtk.ARROW_UP)
|
_paint_arrow(self, event, gtk.ARROW_UP)
|
||||||
|
else:
|
||||||
|
_paint_arrow(self, event, gtk.ARROW_DOWN)
|
||||||
return
|
return
|
||||||
|
|
||||||
alloc = self.allocation
|
alloc = self.allocation
|
||||||
@ -107,7 +107,7 @@ class ToolbarButton(ToolButton):
|
|||||||
alloc.width - style._FOCUS_LINE_WIDTH*2, alloc.height)
|
alloc.width - style._FOCUS_LINE_WIDTH*2, alloc.height)
|
||||||
|
|
||||||
gtk.ToolButton.do_expose_event(self, event)
|
gtk.ToolButton.do_expose_event(self, event)
|
||||||
_paint_arrow(self, event, gtk.ARROW_DOWN)
|
_paint_arrow(self, event, gtk.ARROW_UP)
|
||||||
|
|
||||||
class Toolbar(gtk.VBox):
|
class Toolbar(gtk.VBox):
|
||||||
def __init__(self, padding=style.TOOLBOX_HORIZONTAL_PADDING):
|
def __init__(self, padding=style.TOOLBOX_HORIZONTAL_PADDING):
|
||||||
@ -394,10 +394,11 @@ def _align(box_class, widget):
|
|||||||
return box
|
return box
|
||||||
|
|
||||||
def _paint_arrow(widget, event, type):
|
def _paint_arrow(widget, event, type):
|
||||||
a = widget.allocation
|
alloc = widget.allocation
|
||||||
|
x = alloc.x + alloc.width / 2 - style.TOOLBAR_ARROW_SIZE / 2
|
||||||
|
y = alloc.y + alloc.height - int(style.TOOLBAR_ARROW_SIZE * .85)
|
||||||
|
|
||||||
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_NONE, event.area, widget,
|
||||||
None, type, True,
|
None, type, True,
|
||||||
a.x + a.width/2 - style.TOOLBAR_ARROW_SIZE/2,
|
x, y, style.TOOLBAR_ARROW_SIZE, style.TOOLBAR_ARROW_SIZE)
|
||||||
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