本文整理汇总了Python中sugar3.graphics.toolbutton.ToolButton.set_icon_widget方法的典型用法代码示例。如果您正苦于以下问题:Python ToolButton.set_icon_widget方法的具体用法?Python ToolButton.set_icon_widget怎么用?Python ToolButton.set_icon_widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.toolbutton.ToolButton
的用法示例。
在下文中一共展示了ToolButton.set_icon_widget方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_icon_widget [as 别名]
def __init__(self, handle):
"The entry point to the Activity"
activity.Activity.__init__(self, handle, False)
self.max_participants = 1
self._sequence = 0
self.selected_book = None
self.queryresults = None
self._getter = None
self.show_images = True
self.languages = {}
self._lang_code_handler = languagenames.LanguageNames()
self.catalogs_configuration = {}
self.catalog_history = []
if os.path.exists('/etc/get-books.cfg'):
self._read_configuration('/etc/get-books.cfg')
else:
self._read_configuration()
toolbar_box = ToolbarBox()
activity_button = ToolButton()
color = profile.get_color()
bundle = ActivityBundle(activity.get_bundle_path())
icon = Icon(file=bundle.get_icon(), xo_color=color)
activity_button.set_icon_widget(icon)
activity_button.show()
toolbar_box.toolbar.insert(activity_button, 0)
self._add_search_controls(toolbar_box.toolbar)
separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbar_box.toolbar.insert(separator, -1)
toolbar_box.toolbar.insert(StopButton(self), -1)
self.set_toolbar_box(toolbar_box)
toolbar_box.show_all()
self._books_toolbar = toolbar_box.toolbar
self._create_controls()
self.using_powerd = os.access(POWERD_INHIBIT_DIR, os.W_OK)
self.__book_downloader = self.__image_downloader = None
示例2: Controls
# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_icon_widget [as 别名]
class Controls(GObject.GObject):
"""Class to create the Control (play, back, forward,
add, remove, etc) toolbar"""
SCALE_UPDATE_INTERVAL = 1000
SCALE_DURATION_TEXT = 100
RESEEK_TIMEOUT = 250 # ms
def __init__(self, activity, main_toolbar, secondary_toolbar):
GObject.GObject.__init__(self)
self.activity = activity
self.toolbar = main_toolbar
self.secondary_toolbar = secondary_toolbar
self._scale_update_id = -1
self._scale_value_changed_id = -1
self._scale_reseek_timeout_id = -1
self.open_button = ToolButton('list-add')
self.open_button.set_tooltip(_('Add track'))
self.open_button.show()
self.open_button.connect('clicked', self.__open_button_clicked_cb)
self.toolbar.insert(self.open_button, -1)
erase_playlist_entry_btn = ToolButton(icon_name='list-remove')
erase_playlist_entry_btn.set_tooltip(_('Remove track'))
erase_playlist_entry_btn.connect(
'clicked', self.__erase_playlist_entry_clicked_cb)
self.toolbar.insert(erase_playlist_entry_btn, -1)
self._spacer = Gtk.SeparatorToolItem()
self._spacer.props.draw = True
self._spacer.set_expand(False)
self.toolbar.insert(self._spacer, -1)
self._spacer.show()
self.prev_button = ToolButton('player_rew')
self.prev_button.set_tooltip(_('Previous'))
self.prev_button.props.accelerator = 'Up'
self.prev_button.show()
self.prev_button.connect('clicked', self.__prev_button_clicked_cb)
self.toolbar.insert(self.prev_button, -1)
self.pause_image = Gtk.Image.new_from_stock(Gtk.STOCK_MEDIA_PAUSE,
Gtk.IconSize.BUTTON)
self.pause_image.show()
self.play_image = Gtk.Image.new_from_stock(Gtk.STOCK_MEDIA_PLAY,
Gtk.IconSize.BUTTON)
self.play_image.show()
self.button = ToolButton('media-playback-start')
self.button.set_tooltip(_('Play or Pause'))
self.button.set_icon_widget(self.play_image)
self.button.props.accelerator = 'space'
self.button.set_property('can-default', True)
self.button.show()
self.button.connect('clicked', self._button_clicked_cb)
self.toolbar.insert(self.button, -1)
self.next_button = ToolButton('player_fwd')
self.next_button.set_tooltip(_('Next'))
self.next_button.props.accelerator = 'Down'
self.next_button.show()
self.next_button.connect('clicked', self.__next_button_clicked_cb)
self.toolbar.insert(self.next_button, -1)
self._current_time = Gtk.ToolItem()
self.current_time_label = Gtk.Label(label='')
self._current_time.add(self.current_time_label)
self._current_time.show()
self.toolbar.insert(self._current_time, -1)
self.adjustment = Gtk.Adjustment(0.0, 0.00, 100.0, 0.1, 1.0, 1.0)
self.hscale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL,
adjustment=self.adjustment)
self.hscale.set_draw_value(False)
# FIXME: this seems to be deprecated
# self.hscale.set_update_policy(Gtk.UPDATE_CONTINUOUS)
logging.debug("FIXME: AttributeError: 'Scale' object has no "
"attribute 'set_update_policy'")
self.hscale.connect('button-press-event',
self.__scale_button_press_cb)
self.hscale.connect('button-release-event',
self.__scale_button_release_cb)
self.scale_item = Gtk.ToolItem()
self.scale_item.set_expand(True)
self.scale_item.add(self.hscale)
self.toolbar.insert(self.scale_item, -1)
self._total_time = Gtk.ToolItem()
self.total_time_label = Gtk.Label(label='')
self._total_time.add(self.total_time_label)
self._total_time.show()
self.toolbar.insert(self._total_time, -1)
self.activity.connect('playlist-finished', self.__playlist_finished_cb)
self.activity.player.connect('play', self.__player_play)
#.........这里部分代码省略.........
示例3: DetailToolbox
# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_icon_widget [as 别名]
class DetailToolbox(ToolbarBox):
__gsignals__ = {
'volume-error': (GObject.SignalFlags.RUN_FIRST, None,
([str, str])),
}
def __init__(self, journalactivity):
ToolbarBox.__init__(self)
self._journalactivity = journalactivity
self._metadata = None
self._temp_file_path = None
self._refresh = None
self._resume = ToolButton('activity-start')
self._resume.connect('clicked', self._resume_clicked_cb)
self.toolbar.insert(self._resume, -1)
self._resume.show()
client = GConf.Client.get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
self._copy = ToolButton()
icon = Icon(icon_name='edit-copy', xo_color=color)
self._copy.set_icon_widget(icon)
icon.show()
self._copy.set_tooltip(_('Copy to'))
self._copy.connect('clicked', self._copy_clicked_cb)
self.toolbar.insert(self._copy, -1)
self._copy.show()
self._duplicate = ToolButton()
icon = Icon(icon_name='edit-duplicate', xo_color=color)
self._duplicate.set_icon_widget(icon)
self._duplicate.set_tooltip(_('Duplicate'))
self._duplicate.connect('clicked', self._duplicate_clicked_cb)
self.toolbar.insert(self._duplicate, -1)
if accountsmanager.has_configured_accounts():
self._refresh = ToolButton('entry-refresh')
self._refresh.set_tooltip(_('Refresh'))
self._refresh.connect('clicked', self._refresh_clicked_cb)
self.toolbar.insert(self._refresh, -1)
self._refresh.show()
separator = Gtk.SeparatorToolItem()
self.toolbar.insert(separator, -1)
separator.show()
erase_button = ToolButton('list-remove')
erase_button.set_tooltip(_('Erase'))
erase_button.connect('clicked', self._erase_button_clicked_cb)
self.toolbar.insert(erase_button, -1)
erase_button.show()
def set_metadata(self, metadata):
self._metadata = metadata
self._refresh_copy_palette()
self._refresh_duplicate_palette()
self._refresh_refresh_palette()
self._refresh_resume_palette()
def _resume_clicked_cb(self, button):
misc.resume(self._metadata,
alert_window=journalwindow.get_journal_window())
def _copy_clicked_cb(self, button):
button.palette.popup(immediate=True, state=Palette.SECONDARY)
def _refresh_clicked_cb(self, button):
button.palette.popup(immediate=True, state=Palette.SECONDARY)
def _duplicate_clicked_cb(self, button):
try:
model.copy(self._metadata, '/')
except IOError, e:
logging.exception('Error while copying the entry.')
self.emit('volume-error',
_('Error while copying the entry. %s') % (e.strerror, ),
_('Error'))
示例4: WriteBooksActivity
# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_icon_widget [as 别名]
class WriteBooksActivity(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
self._book_model = BookModel()
self._actual_page = 1
# we do not have collaboration features
# make the share option insensitive
self.max_participants = 1
# get the language configured by the user
# will be used to translate the names of the media files
locale = os.environ.get('LANG', '')
language_location = locale.split('.', 1)[0].lower()
self._language = language_location.split('_')[0]
if self._language == 'en':
# we don't need translate the file names if langauage is 'en'
self._language = None
self._translations = None
if self._language is not None:
# read the translations file if available
dict_path = os.path.join(activity.get_bundle_path(), 'data',
"%s_dict.csv" % self._language)
logging.debug('Looking for media translation dictionary %s',
dict_path)
if os.path.exists(dict_path):
logging.debug('Loading translations')
self._translations = {}
with open(dict_path) as dict_file:
for line in dict_file:
words = line.split(',')
self._translations[words[0]] = words[1].strip()
toolbar_box = ToolbarBox()
activity_button = ActivityToolbarButton(self)
toolbar_box.toolbar.insert(activity_button, 0)
self._edit_toolbar = EditToolbar()
edit_toolbar_button = ToolbarButton(
page=self._edit_toolbar, icon_name='toolbar-edit')
toolbar_box.toolbar.insert(edit_toolbar_button, 1)
set_background_button = ToolButton('set-background')
set_background_button.set_tooltip(_('Set the background'))
set_background_button.connect('clicked',
self.__set_background_clicked_cb)
toolbar_box.toolbar.insert(set_background_button, -1)
insert_picture_button = ToolButton('insert-picture')
insert_picture_button.set_tooltip(_('Add a picture'))
insert_picture_button.connect('clicked',
self.__add_image_clicked_cb)
toolbar_box.toolbar.insert(insert_picture_button, -1)
toolbar_box.toolbar.insert(Gtk.SeparatorToolItem(), -1)
self._duplicate_page_button = ToolButton()
icon = Icon(icon_name='edit-duplicate', xo_color=profile.get_color())
self._duplicate_page_button.set_icon_widget(icon)
self._duplicate_page_button.set_tooltip(_('Duplicate page'))
self._duplicate_page_button.connect(
'clicked', self.__duplicate_page_clicked_cb)
toolbar_box.toolbar.insert(self._duplicate_page_button, -1)
self._add_page_button = ToolButton('list-add')
self._add_page_button.set_tooltip(_('Add a page'))
self._add_page_button.connect('clicked', self.__add_page_clicked_cb)
toolbar_box.toolbar.insert(self._add_page_button, -1)
self._remove_button = ToolButton('edit-delete')
self._remove_button.set_tooltip(_('Remove an image or page'))
self._remove_button.connect('clicked', self.__remove_clicked_cb)
toolbar_box.toolbar.insert(self._remove_button, -1)
self._prev_page_button = ToolButton('go-previous-paired')
self._prev_page_button.set_tooltip(_('Previous page'))
self._prev_page_button.connect('clicked', self.__prev_page_clicked_cb)
toolbar_box.toolbar.insert(self._prev_page_button, -1)
self._next_page_button = ToolButton('go-next-paired')
self._next_page_button.set_tooltip(_('Next page'))
self._next_page_button.connect('clicked', self.__next_page_clicked_cb)
toolbar_box.toolbar.insert(self._next_page_button, -1)
self._view_list_button = ToggleToolButton('view-list')
self._view_list_button.set_tooltip(_('View pages'))
self._view_list_button.connect('toggled', self.__view_list_toggled_cb)
toolbar_box.toolbar.insert(self._view_list_button, -1)
separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbar_box.toolbar.insert(separator, -1)
stop_button = StopButton(self)
toolbar_box.toolbar.insert(stop_button, -1)
#.........这里部分代码省略.........
示例5: GameToolbar
# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_icon_widget [as 别名]
class GameToolbar(Gtk.Toolbar):
__gtype_name__ = 'GameToolbar'
__gsignals__ = {
'game-restart': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, []),
'ai-activated': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, []),
'ai-deactivated': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, []),
'game-board-size': (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, [GObject.TYPE_INT]),
}
def __init__(self, activity):
Gtk.Toolbar.__init__(self)
self.activity = activity
# Reset Button
restart_icon = join(dirname(__file__), 'images', 'gtk-refresh.svg')
restart_image = Gtk.Image()
restart_image.set_from_file(restart_icon)
self._restart_button = ToolButton()
self._restart_button.set_icon_widget(restart_image)
self._restart_button.connect('clicked', self._game_restart_cb)
self._restart_button.set_tooltip(_('Restart Game'))
self.insert(self._restart_button, -1)
self._restart_button.show()
# Separator
separator = Gtk.SeparatorToolItem()
separator.set_draw(True)
self.insert(separator, -1)
self._add_widget(Gtk.Label(_('Board size') + ': '))
# Change size combobox
self._size_combo = ToolComboBox()
self._sizes = ['19 X 19', '13 X 13', '9 X 9']
for i, f in enumerate(self._sizes):
self._size_combo.combo.append_item(i, f)
self._size_combo.combo.connect('changed', self._game_size_cb)
self._add_widget(self._size_combo)
self._size_combo.combo.set_active(0)
# Separator
separator = Gtk.SeparatorToolItem()
separator.set_draw(True)
self.insert(separator, -1)
# Artificial Intelligence Button
self._ai_button = Gtk.ToggleToolButton()
if search_for_gnugo():
self._ai_button.connect('toggled', self._ai_toggled_cb)
self._ai_button.set_label(_('Play against PlayGo!'))
else:
self._ai_button.set_label(_('You need to install gnugo to play against PlayGo'))
self._ai_button.set_sensitive(False)
self.insert(self._ai_button, -1)
self._ai_button.show()
def _add_widget(self, widget, expand=False):
tool_item = Gtk.ToolItem()
tool_item.set_expand(expand)
tool_item.add(widget)
widget.show()
self.insert(tool_item, -1)
tool_item.show()
def _game_restart_cb(self, widget):
self._size_combo.set_sensitive(True)
self.emit('game-restart')
def grey_out_restart(self):
self._restart_button.set_sensitive(False)
def _game_size_cb(self, widget):
game_size = int(self._sizes[self._size_combo.combo.get_active()][:2])
self.emit('game-board-size', game_size)
def grey_out_size_change(self):
self._size_combo.set_sensitive(False)
def update_toolbar(self, widget, data, grid):
size = data.get('size')
self._size_combo.combo.handler_block(self.size_handle_id)
size_index = self._sizes.index(size+' X '+size)
self._size_combo.combo.set_active(int(size_index))
self._size_combo.combo.handler_unblock(self.size_handle_id)
def _ai_toggled_cb(self, widget):
if widget.get_active():
self.emit('ai-activated')
else:
self.emit('ai-deactivated')
def grey_out_ai(self):
self._ai_button.set_sensitive(False)
#.........这里部分代码省略.........
示例6: MessageBox
# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_icon_widget [as 别名]
class MessageBox(Gtk.HBox):
def __init__(self, **kwargs):
GObject.GObject.__init__(self, **kwargs)
self._radius = style.zoom(20)
self.border_color = style.Color("#0000FF")
self.background_color = style.Color("#FFFF00")
self.modify_bg(0, self.background_color.get_gdk_color())
self.set_resize_mode(Gtk.ResizeMode.PARENT)
self.connect("draw", self.__draw_cb)
self.connect("add", self.__add_cb)
close_icon = Icon(icon_name = 'entry-stop')
close_icon.props.pixel_size = style.zoom(20)
drag_icon = Icon(icon_name = 'hand1')
drag_icon.props.pixel_size = style.zoom(20)
self.drag_button = Gtk.Button()
#self.drag_button.set_icon_widget(drag_icon)
self.drag_button.set_image(drag_icon)
drag_icon.show()
self.drag_button.add_events(Gdk.EventMask.POINTER_MOTION_HINT_MASK | \
Gdk.EventMask.POINTER_MOTION_MASK)
self.drag_button.connect("motion_notify_event", self.__motion_notify_cb)
self.drag_button.connect("enter_notify_event", self.__enter_notify_cb)
self.drag_button.connect("button-press-event", self._button_pressed)
self.drag_button.connect("button-release-event", self._button_released)
self.close_button = ToolButton(icon_name='entry-stop')
self.close_button.set_icon_widget(close_icon)
close_icon.show()
self.close_button.connect("clicked", self._close_box)
self.pack_end(self.close_button, False, False, 0)
self.pack_start(self.drag_button, False, False, style.zoom(20))
def __motion_notify_cb(self, widget, event):
if event.get_state() & Gdk.ModifierType.BUTTON1_MASK:
x, y = event.x, event.y
ev = widget.get_parent().get_parent()
fixed = ev.get_parent()
self.lx = self.x + x - self.sx
self.ly = self.y + y - self.sy
fixed.move(ev, self.lx, self.ly)
self.x, self.y = self.lx, self.ly
def __enter_notify_cb(self, widget, event):
win = widget.get_window()
hand_cursor = Gdk.Cursor.new(Gdk.CursorType.HAND2)
win.set_cursor(hand_cursor)
def _button_pressed(self, widget, event):
self.sx = event.x
self.sy = event.y
def _button_released(self, widget, event):
self.x = self.lx
self.y = self.ly
def _close_box(self, button):
self.get_parent().remove(self)
def __add_cb(self, widget, params):
child.set_border_width(style.zoom(5))
def __draw_cb(self, widget, cr):
rect = self.get_allocation()
x = rect.x
y = rect.y
width = rect.width - BORDER_DEFAULT
height = rect.height - BORDER_DEFAULT
logging.debug("final x = " + str(self.x + rect.width) + "screen width = " + str(Gdk.Screen.width()))
diff1 = self.x + rect.width - int(Gdk.Screen.width())
diff2 = self.y + rect.height - int(Gdk.Screen.height())
if diff1 >= 0 or diff2 >= 0:
ev = self.get_parent()
fixed = ev.get_parent()
self.x = random.randint(self.panel_width, int(Gdk.Screen.width()) - rect.width - self.panel_width)
self.y = random.randint(self.panel_width, int(Gdk.Screen.width()) - rect.height - self.panel_width)
fixed.move(ev, self.x, self.y)
cr.move_to(x, y)
cr.arc(x + width - self._radius, y + self._radius,
self._radius, math.pi * 1.5, math.pi * 2)
cr.arc(x + width - self._radius, y + height - self._radius,
self._radius, 0, math.pi * 0.5)
cr.arc(x + self._radius, y + height - self._radius,
self._radius, math.pi * 0.5, math.pi)
cr.arc(x + self._radius, y + self._radius, self._radius,
math.pi, math.pi * 1.5)
cr.close_path()
if self.background_color is not None:
r, g, b, __ = self.background_color.get_rgba()
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_icon_widget [as 别名]
def __init__(self,handle):
activity.Activity.__init__(self,handle,True)
self.basePath=activity.get_bundle_path()
scroll=Gtk.ScrolledWindow();
scroll.set_policy(Gtk.PolicyType.NEVER,Gtk.PolicyType.NEVER);
#get container
self.canvasHolder=TabbedCanvas()
self.canvasHolder.basePath=self.basePath
#add tabControl to scrolled window
scroll.add_with_viewport(self.canvasHolder)
self.set_canvas(scroll)
#add toolbox
toolbox= ToolbarBox(self)
activity_button=ActivityButton(self);
toolbox.toolbar.insert(activity_button,0)
activity_button.show()
separator = Gtk.SeparatorToolItem()
separator.show()
toolbox.toolbar.insert(separator, 1)
#new file button
new_file = ToolButton('list-add')
new_file.set_tooltip(_('New File'))
new_file.props.accelerator=('<ctrl><shift>n')
new_file.connect('clicked', self.newFile)
toolbox.toolbar.insert(new_file,2)
new_file.show()
#close file button
close_file=ToolButton('list-remove')
close_file.set_tooltip(_('Close File'))
close_file.props.accelerator=('<ctrl><shift>x')
close_file.connect('clicked',self.closeFile)
toolbox.toolbar.insert(close_file,3)
#delete button
delete_file=ToolButton('dialog-cancel')
delete_file.set_tooltip('Delete File')
delete_file.props.accelerator=('del')
delete_file.connect('clicked',self.deleteFile)
toolbox.toolbar.insert(delete_file,4)
separator = Gtk.SeparatorToolItem()
separator.show()
toolbox.toolbar.insert(separator, 5)
#save file button
saveBtnImage = Gtk.Image()
saveBtnImage.set_from_file("%s/icons/oopsy_save_as.svg" % os.getcwd())
save_file=ToolButton('gtk-save')
save_file.set_icon_widget(saveBtnImage)
save_file.set_tooltip(_('Save File'))
save_file.props.accelerator=('<ctrl>s')
save_file.connect('clicked',self.saveFile,self.basePath)
toolbox.toolbar.insert(save_file,6)
#compile button
compile_button=ToolButton('view-source')
compile_button.set_tooltip(_('Compile'))
compile_button.props.accelerator=('<ctrl>F6')
compile_button.connect('clicked',self.compileFile,self.basePath)
toolbox.toolbar.insert(compile_button,7)
#run button
gobutton = ToolButton('media-playback-start')
gobutton.props.accelerator = ('<ctrl>F5')
#gobutton.set_icon_widget(goicon_bw)
gobutton.set_tooltip(_("Run!"))
gobutton.connect('clicked',self.executeFile,self.basePath)
toolbox.toolbar.insert(gobutton,8)
separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
separator.show()
toolbox.toolbar.insert(separator, 9)
#stop button
stop_button=StopButton(self)
toolbox.toolbar.insert(stop_button,10)
stop_button.show()
self.set_toolbar_box(toolbox)
act_path = activity.get_bundle_path()
print "BUNDLE_PAth:",act_path
self.loadExplorer(self.basePath)
self.show_all()
示例8: CreateCardPanel
# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_icon_widget [as 别名]
class CreateCardPanel(Gtk.EventBox):
__gsignals__ = {
'add-pair': (GObject.SignalFlags.RUN_FIRST, None,
10 * [GObject.TYPE_PYOBJECT]),
'update-pair': (GObject.SignalFlags.RUN_FIRST, None,
8 * [GObject.TYPE_PYOBJECT]),
'change-font': (GObject.SignalFlags.RUN_FIRST, None,
2 * [GObject.TYPE_PYOBJECT]),
'pair-closed': (GObject.SignalFlags.RUN_FIRST,
None, []),
}
def __init__(self, game):
def make_label(icon_name, label):
label_box = Gtk.VBox()
icon = Icon(icon_name=icon_name,
pixel_size=style.LARGE_ICON_SIZE)
label_box.pack_start(icon, False, False, 0)
label = Gtk.Label(label=label)
label.modify_fg(Gtk.StateType.NORMAL,
style.COLOR_TOOLBAR_GREY.get_gdk_color())
label_box.pack_start(label, True, True, 0)
label_box.show_all()
return label_box
Gtk.EventBox.__init__(self)
self._game = game
self.equal_pairs = False
self._updatebutton_sensitive = False
self._card1_has_sound = False
self._card2_has_sound = False
# save buttons
self._portrait = Gdk.Screen.width() < Gdk.Screen.height()
if self._portrait:
buttons_bar_orientation = Gtk.Orientation.HORIZONTAL
else:
buttons_bar_orientation = Gtk.Orientation.VERTICAL
self._buttons_bar = Gtk.Box(orientation=buttons_bar_orientation)
self._buttons_bar.props.border_width = 10
self._buttons_bar.set_valign(Gtk.Align.CENTER)
self._buttons_bar.set_halign(Gtk.Align.CENTER)
self._addbutton = ToolButton(tooltip=_('Add as new pair'),
sensitive=False)
self._addbutton.set_icon_widget(
make_label('pair-add', ' ' + _('Add')))
self._addbutton.connect('clicked', self.emit_add_pair)
self._buttons_bar.pack_start(self._addbutton, False, False, 0)
self._updatebutton = ToolButton(tooltip=_('Update selected pair'),
sensitive=False)
self._updatebutton.set_icon_widget(
make_label('pair-update', ' ' + _('Update')))
self._updatebutton.connect('clicked', self.emit_update_pair)
self._buttons_bar.pack_start(self._updatebutton, False, False, 0)
self._removebutton = ToolButton(tooltip=_('Remove selected pair'),
sensitive=False)
self._removebutton.set_icon_widget(
make_label('remove', ' ' + _('Remove')))
self._removebutton.connect('clicked', self.emit_close)
self._buttons_bar.pack_start(self._removebutton, False, False, 0)
# Set card editors
self.cardeditor1 = CardEditor(self._game, 1)
self.cardeditor2 = CardEditor(self._game, 2)
self.clean(None)
self.cardeditor1.connect('has-text', self.receive_text_signals)
self.cardeditor2.connect('has-text', self.receive_text_signals)
self.cardeditor1.connect('has-picture', self.receive_picture_signals)
self.cardeditor2.connect('has-picture', self.receive_picture_signals)
self.cardeditor1.connect('has-sound', self.receive_sound_signals)
self.cardeditor2.connect('has-sound', self.receive_sound_signals)
self.cardeditor1.connect('change-font', self.receive_font_signals)
self.cardeditor2.connect('change-font', self.receive_font_signals)
# edit panel
self.card_box = Gtk.HBox()
self.card_box.set_homogeneous(True)
self.cardeditor1.set_halign(Gtk.Align.CENTER)
self.cardeditor1.set_valign(Gtk.Align.CENTER)
self.cardeditor2.set_halign(Gtk.Align.CENTER)
self.cardeditor2.set_valign(Gtk.Align.CENTER)
self.card_box.pack_start(self.cardeditor1, True, True, 0)
self.card_box.pack_start(self.cardeditor2, True, True, 0)
if self._portrait:
main_box_orientation = Gtk.Orientation.VERTICAL
else:
main_box_orientation = Gtk.Orientation.HORIZONTAL
self._main_box = Gtk.Box(orientation=main_box_orientation)
self._main_box.pack_start(self.card_box, True, True, 0)
self._main_box.pack_start(self._buttons_bar, True, True, 0)
self.add(self._main_box)
#.........这里部分代码省略.........
示例9: DetailToolbox
# 需要导入模块: from sugar3.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar3.graphics.toolbutton.ToolButton import set_icon_widget [as 别名]
class DetailToolbox(ToolbarBox):
__gsignals__ = {
'volume-error': (GObject.SignalFlags.RUN_FIRST, None,
([str, str])),
}
def __init__(self, journalactivity):
ToolbarBox.__init__(self)
self._journalactivity = journalactivity
self._metadata = None
self._temp_file_path = None
self._refresh = None
self._resume = ToolButton('activity-start')
self._resume.connect('clicked', self._resume_clicked_cb)
self.toolbar.insert(self._resume, -1)
self._resume.show()
self._resume_menu = None
color = profile.get_color()
self._copy = ToolButton()
icon = Icon(icon_name='edit-copy', xo_color=color)
self._copy.set_icon_widget(icon)
icon.show()
self._copy.set_tooltip(_('Copy to'))
self._copy.connect('clicked', self._copy_clicked_cb)
self.toolbar.insert(self._copy, -1)
self._copy.show()
self._duplicate = ToolButton()
icon = Icon(icon_name='edit-duplicate', xo_color=color)
self._duplicate.set_icon_widget(icon)
self._duplicate.set_tooltip(_('Duplicate'))
self._duplicate.connect('clicked', self._duplicate_clicked_cb)
self.toolbar.insert(self._duplicate, -1)
if accountsmanager.has_configured_accounts():
self._refresh = ToolButton('entry-refresh')
self._refresh.set_tooltip(_('Refresh'))
self._refresh.connect('clicked', self._refresh_clicked_cb)
self.toolbar.insert(self._refresh, -1)
self._refresh.show()
separator = Gtk.SeparatorToolItem()
self.toolbar.insert(separator, -1)
separator.show()
erase_button = ToolButton('list-remove')
erase_button.set_tooltip(_('Erase'))
erase_button.connect('clicked', self._erase_button_clicked_cb)
self.toolbar.insert(erase_button, -1)
erase_button.show()
def set_metadata(self, metadata):
self._metadata = metadata
self._refresh_copy_palette()
self._refresh_duplicate_palette()
self._refresh_refresh_palette()
self._refresh_resume_palette()
def _resume_clicked_cb(self, button):
if not misc.can_resume(self._metadata):
palette = self._resume.get_palette()
palette.popup(immediate=True)
misc.resume(self._metadata,
alert_window=journalwindow.get_journal_window())
def _copy_clicked_cb(self, button):
button.palette.popup(immediate=True)
def _refresh_clicked_cb(self, button):
button.palette.popup(immediate=True)
def _duplicate_clicked_cb(self, button):
try:
model.copy(self._metadata, '/')
except IOError as e:
logging.exception('Error while copying the entry.')
self.emit('volume-error',
_('Error while copying the entry. %s') % (e.strerror, ),
_('Error'))
def _erase_button_clicked_cb(self, button):
alert = Alert()
erase_string = _('Erase')
alert.props.title = erase_string
alert.props.msg = _('Do you want to permanently erase \"%s\"?') \
% self._metadata['title']
icon = Icon(icon_name='dialog-cancel')
alert.add_button(Gtk.ResponseType.CANCEL, _('Cancel'), icon)
icon.show()
ok_icon = Icon(icon_name='dialog-ok')
alert.add_button(Gtk.ResponseType.OK, erase_string, ok_icon)
ok_icon.show()
alert.connect('response', self.__erase_alert_response_cb)
journalwindow.get_journal_window().add_alert(alert)
alert.show()
def __erase_alert_response_cb(self, alert, response_id):
#.........这里部分代码省略.........