本文整理汇总了Python中sugar.graphics.toolbutton.ToolButton.set_sensitive方法的典型用法代码示例。如果您正苦于以下问题:Python ToolButton.set_sensitive方法的具体用法?Python ToolButton.set_sensitive怎么用?Python ToolButton.set_sensitive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar.graphics.toolbutton.ToolButton
的用法示例。
在下文中一共展示了ToolButton.set_sensitive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EditToolbar
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class EditToolbar(activity.EditToolbar):
def __init__(self, _parent):
activity.EditToolbar.__init__(self)
self._parent = _parent
self.undo.connect('clicked', self.__undo_cb)
self.redo.connect('clicked', self.__redo_cb)
self.copy.connect('clicked', self.__copy_cb)
self.paste.connect('clicked', self.__paste_cb)
menu_item = MenuItem(_('Cut'))
menu_item.connect('activate', self.__cut_cb)
menu_item.show()
self.copy.get_palette().menu.append(menu_item)
self.insert(gtk.SeparatorToolItem(), -1)
self.erase_button = ToolButton('edit-delete')
self.erase_button.set_tooltip(_('Erase selected thought(s)'))
self.erase_button.connect('clicked', self.__delete_cb)
self.insert(self.erase_button, -1)
self.show_all()
self.clipboard = gtk.Clipboard()
self.copy.child.set_sensitive(False)
self.paste.child.set_sensitive(False)
self.erase_button.set_sensitive(False)
def __undo_cb(self, button):
self._parent._undo.undo_action(None)
def __redo_cb(self, button):
self._parent._undo.redo_action(None)
def __cut_cb(self, event):
self._parent._main_area.cut_clipboard(self.clipboard)
def __copy_cb(self, event):
self._parent._main_area.copy_clipboard(self.clipboard)
def __paste_cb(self, event):
self._parent._main_area.paste_clipboard(self.clipboard)
def __delete_cb(self, widget):
self._stop_moving()
self.stop_dragging()
self._parent._main_area.delete_selected_elements()
def stop_dragging(self):
if self._parent._main_area.is_dragging():
self._parent._main_area.drag_menu_cb(self._sw, False)
def _stop_moving(self):
self._parent._main_area.move_mode = False
示例2: HomeWorkViewer
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class HomeWorkViewer(activity.Activity):
def __init__(self, handle):
"""Set up the HelloWorld activity."""
activity.Activity.__init__(self, handle)
self._logger = logging.getLogger('home-work-viewer')
self._logger.setLevel(logging.DEBUG)
self._logger.debug("Inside to __init__ of HomeWorkViewer")
ts = time.time()
self._logger.debug(ts)
#self._logger.debug( datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
'''Obtenemos el JSON de la Actividad'''
json_data=open('json.txt')
self.activity = json.load(json_data, object_hook=lambda d: namedtuple('Activity', d.keys())(*d.values()))
json_data.close()
# we do not have collaboration features
# make the share option insensitive
self.max_participants = 1
# toolbar with the new toolbar redesign
toolbar_box = ToolbarBox()
activity_button = ActivityButton(self)
toolbar_box.toolbar.insert(activity_button, 0)
activity_button.show()
title_entry = TitleEntry(self)
toolbar_box.toolbar.insert(title_entry, 1)
title_entry.show()
separator = gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbar_box.toolbar.insert(separator, -1)
separator.show()
self.buttonBefore = ToolButton('go-previous')
self.buttonBefore.set_tooltip(_('Back'))
self.buttonBefore.connect("clicked", self.backButtonCallBack)
toolbar_box.toolbar.insert(self.buttonBefore, 2)
self.buttonBefore.show()
self.buttonNext = ToolButton('go-next')
self.buttonNext.set_tooltip(_('Next'))
self.buttonNext.connect("clicked", self.nextButtonCallBack)
toolbar_box.toolbar.insert(self.buttonNext, 3)
self.buttonNext.show()
stop_button = StopButton(self)
toolbar_box.toolbar.insert(stop_button, -1)
stop_button.show()
self.set_toolbar_box(toolbar_box)
toolbar_box.show()
self.vBoxMain = gtk.VBox(True, 2)
self.vBoxMain.show()
self.set_canvas(self.vBoxMain)
self.jsonState = None
self.createWindowExercises()
"""Leave this line always in the last"""
#self.show_all()
def exerciseCompletedCallBack(self):
if self.amountExercises > self.exercisesMatches:
self.exercisesMatches = self.exercisesMatches + 1
self.modalDoneWindow = ModalWindowDone(self)
self.modalDoneWindow.show()
self.freezeExerciseWindow()
def manageBackNextButtons(self):
self.getLogger().debug("Inside to manageBackNextButtons")
self.getLogger().debug(self.currentIndexExercise)
self.getLogger().debug(self.amountExercises)
if self.currentIndexExercise == 0:
self.buttonBefore.set_sensitive(False)
if self.amountExercises != 1:
self.buttonNext.set_sensitive(True)
else:
self.buttonNext.set_sensitive(False)
elif self.currentIndexExercise > 0 and self.currentIndexExercise < (self.amountExercises-1):
self.buttonBefore.set_sensitive(True)
self.buttonNext.set_sensitive(True)
else:
self.buttonBefore.set_sensitive(True)
self.buttonNext.set_sensitive(False)
def nextButtonCallBack(self, button, *args):
#.........这里部分代码省略.........
示例3: GameToolbar
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class GameToolbar(gtk.Toolbar):
__gtype_name__ = 'GameToolbar'
__gsignals__ = {
'game-restart': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
'ai-activated': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
'ai-deactivated': (SIGNAL_RUN_FIRST, TYPE_NONE, []),
'game-board-size': (SIGNAL_RUN_FIRST, TYPE_NONE, [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)
def set_ai_button_state(self, value):
self._ai_button.set_active(value)
示例4: CreateToolbar
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class CreateToolbar(gtk.Toolbar):
__gtype_name__ = 'CreateToolbar'
__gsignals__ = {
'create_new_game': (SIGNAL_RUN_FIRST, None, []),
'create_load_game': (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]),
'create_save_game': (SIGNAL_RUN_FIRST, None, 3 * [TYPE_PYOBJECT]),
'create_equal_pairs': (SIGNAL_RUN_FIRST, None, [TYPE_PYOBJECT]),
}
def __init__(self, activity):
gtk.Toolbar.__init__(self)
self.activity = activity
self._lock = True
# New Button
new_icon = join(dirname(__file__), 'images', 'game-new.svg')
new_image = gtk.Image()
new_image.set_from_file(new_icon)
self._new_button = ToolButton()
self._new_button.set_icon_widget(new_image)
self._new_button.set_tooltip(_('New game'))
self._new_button.connect('clicked', self._new_game_bt)
self._add_widget(self._new_button)
# Load Button
load_icon = join(dirname(__file__), 'images', 'game-load.svg')
load_image = gtk.Image()
load_image.set_from_file(load_icon)
self._load_button = ToolButton()
self._load_button.set_icon_widget(load_image)
self._load_button.set_tooltip(_('Load game'))
self._load_button.connect('clicked', self._load_game)
self._add_widget(self._load_button)
# Save Button
save_icon = join(dirname(__file__), 'images', 'game-save.svg')
save_image = gtk.Image()
save_image.set_from_file(save_icon)
self._save_button = ToolButton()
self._save_button.set_icon_widget(save_image)
self._save_button.set_tooltip(_('Save game'))
self._save_button.connect('clicked', self._save_game_bt)
self._save_button.set_sensitive(False)
self._add_widget(self._save_button)
# Separator
separator2 = gtk.SeparatorToolItem()
separator2.set_draw(True)
self.insert(separator2, -1)
self._add_widget(gtk.Label(_('Game name') + ': '))
self.game_name_entry = gtk.Entry()
self._add_widget(self.game_name_entry)
self._equal_pairs = gtk.CheckButton(_('Equal pairs'))
self._add_widget(self._equal_pairs)
self._equal_pairs.connect('toggled', self._emit_equal_pairs)
self._grouped_icon1 = join(dirname(__file__), 'images', 'equal_pairs1.svg')
self._grouped_icon2 = join(dirname(__file__), 'images', 'equal_pairs2.svg')
self._grouped_image1 = gtk.Image()
self._grouped_image2 = gtk.Image()
self._grouped_image1.set_from_file(self._grouped_icon1)
self._grouped_image2.set_from_file(self._grouped_icon2)
self._grouped = ToggleToolButton()
self._grouped.set_icon_widget(self._grouped_image1)
self._grouped.set_tooltip(_('Click for grouped game'))
self._grouped.connect('toggled', self._grouped_cb)
self._add_widget(self._grouped)
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_changed_cb(self, combobox, game_name):
self.game_name_entry.set_text(game_name)
self.emit('create_load_game', game_name)
def _load_game(self, button):
chooser = ObjectChooser(_('Choose memorize game'),
parent=self.activity,
flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)
jobject = ''
try:
result = chooser.run()
if result == gtk.RESPONSE_ACCEPT:
logging.debug('ObjectChooser: %r' % chooser.get_selected_object())
jobject = chooser.get_selected_object()
if not jobject or not jobject.file_path:
return
finally:
chooser.destroy()
del chooser
if jobject and jobject.file_path:
#.........这里部分代码省略.........
示例5: EditToolbar
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class EditToolbar(gtk.Toolbar):
def __init__(self, pc, toolbar_box):
gtk.Toolbar.__init__(self)
self._abiword_canvas = pc.abiword_canvas
copy = CopyButton()
copy.props.accelerator = '<Ctrl>C'
copy.connect('clicked', lambda button: pc.abiword_canvas.copy())
self.insert(copy, -1)
copy.show()
paste = PasteButton()
paste.props.accelerator = '<Ctrl>V'
paste.connect('clicked', lambda button: pc.abiword_canvas.paste())
self.insert(paste, -1)
paste.show()
separator = gtk.SeparatorToolItem()
self.insert(separator, -1)
separator.show()
undo = UndoButton(sensitive=False)
undo.connect('clicked', lambda button: pc.abiword_canvas.undo())
pc.abiword_canvas.connect("can-undo", lambda abi, can_undo:
undo.set_sensitive(can_undo))
self.insert(undo, -1)
undo.show()
redo = RedoButton(sensitive=False)
redo.connect('clicked', lambda button: pc.abiword_canvas.redo())
pc.abiword_canvas.connect("can-redo", lambda abi, can_redo:
redo.set_sensitive(can_redo))
self.insert(redo, -1)
redo.show()
pc.abiword_canvas.connect('text-selected', lambda abi, b:
copy.set_sensitive(True))
pc.abiword_canvas.connect('image-selected', lambda abi, b:
copy.set_sensitive(True))
pc.abiword_canvas.connect('selection-cleared', lambda abi, b:
copy.set_sensitive(False))
separator = gtk.SeparatorToolItem()
self.insert(separator, -1)
separator.show()
search_label = gtk.Label(_("Search") + ": ")
search_label.show()
search_item_page_label = gtk.ToolItem()
search_item_page_label.add(search_label)
self.insert(search_item_page_label, -1)
search_item_page_label.show()
# setup the search options
self._search_entry = iconentry.IconEntry()
self._search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
'system-search')
self._search_entry.connect('activate', self._search_entry_activated_cb)
self._search_entry.connect('changed', self._search_entry_changed_cb)
self._search_entry.add_clear_button()
self._add_widget(self._search_entry, expand=True)
self._findprev = ToolButton('go-previous-paired')
self._findprev.set_tooltip(_('Find previous'))
self.insert(self._findprev, -1)
self._findprev.show()
self._findprev.connect('clicked', self._findprev_cb)
self._findnext = ToolButton('go-next-paired')
self._findnext.set_tooltip(_('Find next'))
self.insert(self._findnext, -1)
self._findnext.show()
self._findnext.connect('clicked', self._findnext_cb)
# set the initial state of the search controls
# note: we won't simple call self._search_entry_changed_cb
# here, as that will call into the abiword_canvas, which
# is not mapped on screen here, causing the set_find_string
# call to fail
self._findprev.set_sensitive(False)
self._findnext.set_sensitive(False)
def _search_entry_activated_cb(self, entry):
logger.debug('_search_entry_activated_cb')
if not self._search_entry.props.text:
return
# find the next entry
self._abiword_canvas.find_next(False)
def _search_entry_changed_cb(self, entry):
logger.debug('_search_entry_changed_cb search for \'%s\'',
self._search_entry.props.text)
if not self._search_entry.props.text:
self._search_entry.activate()
# set the button contexts
self._findprev.set_sensitive(False)
#.........这里部分代码省略.........
示例6: InsertToolbar
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class InsertToolbar(gtk.Toolbar):
def __init__(self, abiword_canvas):
gtk.Toolbar.__init__(self)
self._abiword_canvas = abiword_canvas
self._table = abiword.TableCreator()
self._table.set_labels(_('Table'), _('Cancel'))
self._table_id = self._table.connect('selected', self._table_cb)
image = gtk.Image()
image.set_from_icon_name('insert-table', -1)
self._table.set_image(image)
self._table.set_relief(gtk.RELIEF_NONE)
tool_item = gtk.ToolItem()
tool_item.add(self._table)
self.insert(tool_item, -1)
tool_item.show_all()
self._table_rows_after = ToolButton('row-insert')
self._table_rows_after.set_tooltip(_('Insert Row'))
self._table_rows_after_id = self._table_rows_after.connect( \
'clicked', self._table_rows_after_cb)
self.insert(self._table_rows_after, -1)
self._table_delete_rows = ToolButton('row-remove')
self._table_delete_rows.set_tooltip(_('Delete Row'))
self._table_delete_rows_id = self._table_delete_rows.connect( \
'clicked', self._table_delete_rows_cb)
self.insert(self._table_delete_rows, -1)
self._table_cols_after = ToolButton('column-insert')
self._table_cols_after.set_tooltip(_('Insert Column'))
self._table_cols_after_id = self._table_cols_after.connect( \
'clicked', self._table_cols_after_cb)
self.insert(self._table_cols_after, -1)
self._table_delete_cols = ToolButton('column-remove')
self._table_delete_cols.set_tooltip(_('Delete Column'))
self._table_delete_cols_id = self._table_delete_cols.connect( \
'clicked', self._table_delete_cols_cb)
self.insert(self._table_delete_cols, -1)
separator = gtk.SeparatorToolItem()
self.insert(separator, -1)
image = ToolButton('insert-picture')
image.set_tooltip(_('Insert Image'))
self._image_id = image.connect('clicked', self._image_cb)
self.insert(image, -1)
self.show_all()
self._abiword_canvas.connect('table-state', self._isTable_cb)
#self._abiword_canvas.connect('image-selected', self._image_selected_cb)
def _image_cb(self, button):
def cb(object):
logging.debug('ObjectChooser: %r' % object)
self._abiword_canvas.insert_image(object.file_path, True)
chooser.pick(what=chooser.IMAGE, cb=cb)
def _table_cb(self, abi, rows, cols):
self._abiword_canvas.insert_table(rows, cols)
def _table_rows_after_cb(self, button):
self._abiword_canvas.invoke_cmd('insertRowsAfter', '', 0, 0)
def _table_delete_rows_cb(self, button):
self._abiword_canvas.invoke_cmd('deleteRows', '', 0, 0)
def _table_cols_after_cb(self, button):
self._abiword_canvas.invoke_cmd('insertColsAfter', '', 0, 0)
def _table_delete_cols_cb(self, button):
self._abiword_canvas.invoke_cmd('deleteColumns', '', 0, 0)
def _isTable_cb(self, abi, b):
self._table_rows_after.set_sensitive(b)
self._table_delete_rows.set_sensitive(b)
self._table_cols_after.set_sensitive(b)
self._table_delete_cols.set_sensitive(b)
示例7: NavToolBar
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
#.........这里部分代码省略.........
label_attributes.insert(pango.AttrForeground(65535, 65535, 65535, 0, -1))
self.__total_page_label.set_attributes(label_attributes)
self.__total_page_label.set_text(' / ' + str(self.__deck.getSlideCount()))
self.__total_page_item.add(self.__total_page_label)
self.__total_page_label.show()
self.insert(self.__total_page_item, -1)
self.__total_page_item.show()
# separator between navigation buttons and lock button
separator = gtk.SeparatorToolItem()
separator.set_draw(False)
separator.set_expand(True)
self.insert(separator, -1)
separator.show()
# unlocked button
self.__unlockBtn = ToolButton('unlocked')
self.__unlockBtn.set_tooltip("Student Navigation Unlocked")
# navigation is unlocked by default, so insert the unlock button
self.insert(self.__unlockBtn, 5)
self.__unlockBtn.show()
# locked button
self.__lockBtn = ToolButton('locked')
self.__lockBtn.set_tooltip("Student Navigation Locked")
self.__logger.debug("Connecting to navigation locking and activity sharing signals.")
self.__activity.connect('shared', self.activity_shared_cb)
self.__activity.connect('joined', self.activity_joined_cb)
self.__shared.connect('navigation-lock-change', self.set_lock_button)
# triggers for when slides are changed
self.__deck.connect("slide-changed", self.slide_changed)
self.__deck.connect("deck-changed", self.slide_changed)
self.slide_changed(self.__deck)
self.show()
def activity_shared_cb(self, widget):
#Callback for when the activity is shared
# bind the lock button click with switching lock mode
self.__lockBtn.connect('clicked', self.__shared.lock_mode_switch)
self.__unlockBtn.connect('clicked', self.__shared.lock_mode_switch)
def activity_joined_cb(self, widget):
""" Callback for when the activity is joined """
self.__is_initiating = False
def set_lock_button(self, widget, is_locked):
self.__logger.debug("Changing lock button, lock mode %u, init %u",
is_locked, self.__is_initiating)
if is_locked:
new_button = self.__lockBtn
if not self.__is_initiating:
self.__prevbtn.set_sensitive(False)
self.__nextbtn.set_sensitive(False)
else:
new_button = self.__unlockBtn
if not self.__is_initiating:
self.__prevbtn.set_sensitive(True)
self.__nextbtn.set_sensitive(True)
old = self.get_nth_item(5)
self.remove(old)
self.insert(new_button, 5)
new_button.show()
self.queue_draw()
def next(self, widget):
self.__deck.next()
def previous(self, widget):
self.__deck.previous()
def slide_changed(self, widget):
self.__logger.debug("Changing slides!")
if self.__deck.isAtBeginning():
self.__prevbtn.set_sensitive(False)
else:
self.__prevbtn.set_sensitive(True)
if self.__deck.isAtEnd():
self.__nextbtn.set_sensitive(False)
else:
self.__nextbtn.set_sensitive(True)
self.__num_current_page = self.__deck.getIndex()
self.__num_page_entry.set_text(str(self.__num_current_page + 1))
self.__total_page_label.set_text(' / ' + str(self.__deck.getSlideCount()))
def num_page_activate(self, entry):
page_entered = int(entry.get_text())
if page_entered < 1:
page_entered = 1
elif self.__deck.getSlideCount() < page_entered:
page_entered = self.__deck.getSlideCount()
self.__deck.goToIndex(page_entered - 1, is_local=True)
示例8: NavToolBar
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
#.........这里部分代码省略.........
self.__logger.debug("Connecting to navigation locking and activity sharing signals.")
self.__arbiter.connect_shared(self.activity_shared_cb)
self.__arbiter.connect_joined(self.activity_joined_cb)
self.__arbiter.connect_navigation_lock_change(self.set_lock_button)
# triggers for when slides are changed
self.__arbiter.connect_slide_changed(self.slide_changed_cb)
self.__arbiter.connect_deck_changed(self.slide_changed_cb)
self.slide_changed_cb()
self.insert(self.__prevbtn, -1)
self.insert(self.__nextbtn, -1)
self.insert(self.__num_page_item, -1)
self.insert(self.__total_page_item, -1)
self.insert(self.__separator1, -1)
self.insert(self.__mode_item, -1)
self.insert(self.__separator2, -1)
self.insert(self.__unlockBtn, -1)
self.__prevbtn.show()
self.__nextbtn.show()
self.__num_page_item.show()
self.__total_page_item.show()
self.__separator1.show()
self.__mode_item.show()
self.__separator2.show()
self.__unlockBtn.show()
self.show() # show the entire toolbar
def activity_shared_cb(self, widget):
#Callback for when the activity is shared
# bind the lock button click with switching lock mode
self.__lockBtn.connect('clicked', self.lock_btn_cb)
self.__unlockBtn.connect('clicked', self.lock_btn_cb)
self.__mode_label.set_text(_("Instructor"))
def activity_joined_cb(self, widget):
""" Callback for when the activity is joined """
self.__mode_label.set_text(_("Student"))
self.__lockBtn.set_sensitive(False)
self.__unlockBtn.set_sensitive(False)
def lock_btn_cb(self, widget):
""" The lock/unlock button has been clicked. """
self.emit('lock-button-clicked')
def set_lock_button(self, widget, is_locked):
sharing = self.__arbiter.get_is_instructor()
self.__logger.debug("Changing lock button, lock mode %u, init %u",
is_locked, sharing)
if is_locked:
new_button = self.__lockBtn
if not sharing:
self.__prevbtn.set_sensitive(False)
self.__nextbtn.set_sensitive(False)
else:
new_button = self.__unlockBtn
if not sharing:
self.__prevbtn.set_sensitive(True)
self.__nextbtn.set_sensitive(True)
old = self.get_nth_item(7)
self.remove(old)
self.insert(new_button, 7)
new_button.show()
self.queue_draw()
def next_btn_clicked(self, widget):
self.__arbiter.do_next_slide()
def previous_btn_clicked(self, widget):
self.__arbiter.do_previous_slide()
def slide_changed_cb(self, widget=None):
self.__logger.debug("Changing slides!")
if self.__arbiter.get_deck_is_at_beginning():
self.__prevbtn.set_sensitive(False)
else:
self.__prevbtn.set_sensitive(True)
if self.__arbiter.get_deck_is_at_end():
self.__nextbtn.set_sensitive(False)
else:
self.__nextbtn.set_sensitive(True)
self.__num_current_page = self.__arbiter.get_slide_index()
self.__num_page_entry.set_text(str(self.__num_current_page + 1))
self.__total_page_label.set_text(' / ' + str(self.__arbiter.get_slide_count()))
def num_page_activate(self, entry):
page_entered = int(entry.get_text())
if page_entered < 1:
page_entered = 1
elif self.__arbiter.get_slide_count() < page_entered:
page_entered = self.__arbiter.get_slide_count()
self.__arbiter.do_goto_slide(page_entered - 1, local_request=True)
示例9: Explorer
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class Explorer(activity.Activity):
'''Es la clase que crea la actividad'''
def __init__(self, handle):
activity.Activity.__init__(self, handle, True)
# ToolbarBox:
toolbarbox = ToolbarBox()
activitybutton = ActivityButton(self)
toolbarbox.toolbar.insert(activitybutton, 0)
separator = gtk.SeparatorToolItem()
toolbarbox.toolbar.insert(separator, -1)
explorer_btn = RadioToolButton()
explorer_btn.set_tooltip('Explorador')
explorer_btn.props.icon_name = 'activity-explorer'
toolbarbox.toolbar.insert(explorer_btn, -1)
self._goup = ToolButton('to-subjects')
self._goup.connect('clicked', self._go_up_clicked)
self._goup.set_tooltip('Ver Materias')
self._goup.set_accelerator("<Shift><M>")
self._goup.set_sensitive(False)
toolbarbox.toolbar.insert(self._goup, -1)
self._select_all = ToolButton('select-all')
self._select_all.set_tooltip('Seleccionar todo')
self._select_all.connect("clicked", self._select_all_clicked)
self._select_all.set_sensitive(False)
toolbarbox.toolbar.insert(self._select_all, -1)
self._download = ToolButton('download')
self._download.set_tooltip('Descargar')
self._download.set_sensitive(False)
toolbarbox.toolbar.insert(self._download, -1)
separator = gtk.SeparatorToolItem()
toolbarbox.toolbar.insert(separator, -1)
homework_btn = RadioToolButton()
homework_btn.set_tooltip('Tareas Domiciliarias')
homework_btn.props.icon_name = 'homework'
homework_btn.props.group = explorer_btn
toolbarbox.toolbar.insert(homework_btn, -1)
open_btn = ToolButton()
open_btn.set_tooltip('Seleccionar tarea')
open_btn.props.icon_name = 'open-from-journal'
open_btn.set_sensitive(False)
open_btn.connect("clicked", self._select_hw_from_journal)
toolbarbox.toolbar.insert(open_btn, -1)
self._send = ToolButton()
self._send.set_tooltip('Enviar tarea')
self._send.connect('clicked', self._send_hw_to_server)
self._send.props.icon_name = 'document-send'
self._send.set_sensitive(False)
toolbarbox.toolbar.insert(self._send, -1)
homework_btn.connect('clicked', self.homework_btn_cb, open_btn)
explorer_btn.connect('clicked', self.explorer_btn_cb, open_btn)
separator = gtk.SeparatorToolItem()
separator.set_expand(True)
separator.set_draw(False)
toolbarbox.toolbar.insert(separator, -1)
stopbtn = StopButton(self)
toolbarbox.toolbar.insert(stopbtn, -1)
self.set_toolbar_box(toolbarbox)
self._one_alert = None
# Canvas
self._canvas = gtk.EventBox()
self._name = ''
self._last_name = ''
self._hw_title = ''
self._hw_description = ''
self._hw_path = ''
self._hw_mimetype = ''
self.set_canvas(self._canvas)
self.show_all()
if not utils.get_group():
self.choose_group()
else:
self._do_canvas()
def homework_btn_cb(self, button, open_btn):
'''Se ejecuta cuando se hace click en el boton
de tareas domiciliarias, se encarga de cambiar de pagina'''
self._notebook.set_current_page(2)
self._goup.set_sensitive(False)
self._select_all.set_sensitive(False)
self._download.set_sensitive(False)
open_btn.set_sensitive(True)
self._send.set_sensitive(False)
#.........这里部分代码省略.........
示例10: FreeFromMalariaActivity
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
#.........这里部分代码省略.........
self.sound.set_icon("audio-volume-high")
def create_dialog(self, title, message):
dialog = gtk.MessageDialog(parent=None,
buttons=gtk.BUTTONS_YES_NO,
flags=gtk.DIALOG_DESTROY_WITH_PARENT,
type=gtk.MESSAGE_QUESTION,
message_format=message);
dialog.set_title(title)
return dialog;
def create_dialog_ok(self, title, message):
dialog = gtk.MessageDialog(parent=None,
buttons=gtk.BUTTONS_OK,
flags=gtk.DIALOG_DESTROY_WITH_PARENT,
type=gtk.MESSAGE_QUESTION,
message_format=message);
dialog.set_title(title)
return dialog;
##disables the nav buttons when comic is not being shown
def set_navigation(self, switch):
self.previous_scene_button.set_sensitive(switch);
self.next_scene.set_sensitive(switch);
def create_new_window(self, view):
#self.view = view;
self.mywindow = view.get_window()
self.w_child = self.mywindow.get_child()
self.widget = self.w_child
# if(self.widget==None or self.w_child==None):
# raise RuntimeError("No widget available")
self.pack_and_show()
def pack_and_show(self):
# Create the main container
self._main_view = gtk.VBox()
# Import our class gtktest():
# Step 1: Load class, which creates gtktest.widget
#self.gtktest = devtest2(self)
# Step 2: Remove the widget's parent
if self.widget.parent:
示例11: __init__
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
def __init__(self, handle):
activity.Activity.__init__(self, handle, True)
self.max_participants = 1
# Calendar
self._calendar = gtk.Calendar()
self._calendar_size_ready = False
self._calendar.connect('size_allocate', self._calendar_size_allocate)
# TODO: Create a Help dialog like Implode
#self._helpdialog = HelpDialog()
# Canvas
scroll = gtk.ScrolledWindow()
scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
self.notes_area = NotesArea()
scroll.add_with_viewport(self.notes_area)
self.set_canvas(scroll)
# Toolbars
toolbarbox = ToolbarBox()
activity_button = ActivityToolbarButton(self)
toolbarbox.toolbar.insert(activity_button, 0)
activity_button.show()
separator = gtk.SeparatorToolItem()
toolbarbox.toolbar.insert(separator, -1)
note_add = ToolButton('gtk-add')
note_add.set_tooltip(_('Add a note'))
note_add.connect('clicked', self._show_add_button_pallete)
toolbarbox.toolbar.insert(note_add, -1)
self._calendar.connect('day-selected-double-click',
self.__add_note_cb, note_add)
note_remove = ToggleToolButton('gtk-remove')
note_remove.set_tooltip(_('Remove notes'))
note_remove.connect('clicked', self._active_remove)
toolbarbox.toolbar.insert(note_remove, -1)
separator = gtk.SeparatorToolItem()
toolbarbox.toolbar.insert(separator, -1)
back = ToolButton('go-left')
back.set_tooltip(_('Select previous note'))
back.set_sensitive(False)
back.connect('clicked', lambda w: self.notes_area.select_note(-1))
toolbarbox.toolbar.insert(back, -1)
_next = ToolButton('go-right')
_next.set_tooltip(_('Select next note'))
_next.connect('clicked', lambda w: self.notes_area.select_note(+1))
_next.set_sensitive(False)
toolbarbox.toolbar.insert(_next, -1)
#helpbtn = ToolButton('toolbar-help')
#helpbtn.set_tooltip(_('Help'))
#helpbtn.connect('clicked', self.help)
#toolbarbox.toolbar.insert(helpbtn)
separator = gtk.SeparatorToolItem()
separator.set_draw(False)
separator.set_expand(True)
toolbarbox.toolbar.insert(separator, -1)
stopbtn = StopButton(self)
toolbarbox.toolbar.insert(stopbtn, -1)
self.set_toolbar_box(toolbarbox)
self.notes_area.connect('no-notes', self._no_notes,
note_remove, back, _next)
self.notes_area.connect('note-added', self._note_added, back, _next)
self.show_all()
self._create_add_button_pallete(note_add)
示例12: __init__
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
def __init__(self, handle):
super(PeterActivity, self).__init__(handle)
# Get user's Sugar colors
sugarcolors = profile.get_color().to_string().split(',')
colors = [[int(sugarcolors[0][1:3], 16),
int(sugarcolors[0][3:5], 16),
int(sugarcolors[0][5:7], 16)],
[int(sugarcolors[1][1:3], 16),
int(sugarcolors[1][3:5], 16),
int(sugarcolors[1][5:7], 16)]]
# No sharing
self.max_participants = 1
# Build the activity toolbar.
toolbox = ToolbarBox()
activity_button = ActivityToolbarButton(self)
toolbox.toolbar.insert(activity_button, 0)
activity_button.show()
self._add_speed_slider(toolbox.toolbar)
cyan = ToolButton('cyan')
toolbox.toolbar.insert(cyan, -1)
cyan.set_tooltip(_('Next pattern'))
cyan.connect('clicked', self._button_cb, 'cyan')
cyan.set_sensitive(False)
cyan.show()
green = ToolButton('green')
toolbox.toolbar.insert(green, -1)
green.set_tooltip(_('Draw'))
green.connect('clicked', self._button_cb, 'green')
green.show()
red = ToolButton('red')
toolbox.toolbar.insert(red, -1)
red.set_tooltip(_('Stop'))
red.connect('clicked', self._button_cb, 'red')
red.show()
separator = gtk.SeparatorToolItem()
separator.props.draw = True
toolbox.toolbar.insert(separator, -1)
separator.show()
label = gtk.Label('')
label.set_use_markup(True)
label.show()
labelitem = gtk.ToolItem()
labelitem.add(label)
toolbox.toolbar.insert(labelitem, -1)
labelitem.show()
separator = gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbox.toolbar.insert(separator, -1)
separator.show()
stop_button = StopButton(self)
stop_button.props.accelerator = _('<Ctrl>Q')
toolbox.toolbar.insert(stop_button, -1)
stop_button.show()
toolbox.show()
self.set_toolbox(toolbox)
# Create the game instance.
self.game = Spirolaterals.Spirolaterals(colors)
# Build the Pygame canvas.
self._pygamecanvas = \
sugargame.canvas.PygameCanvas(self)
# Note that set_canvas implicitly calls
# read_file when resuming from the Journal.
self.set_canvas(self._pygamecanvas)
self.game.canvas = self._pygamecanvas
gtk.gdk.screen_get_default().connect('size-changed',
self.__configure_cb)
# Start the game running.
self.game.set_cyan_button(cyan)
self.game.set_label(label)
self._speed_range.set_value(200)
self._pygamecanvas.run_pygame(self.game.run)
示例13: CreateCardPanel
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class CreateCardPanel(gtk.EventBox):
__gsignals__ = {
'add-pair': (SIGNAL_RUN_FIRST, None, 8 * [TYPE_PYOBJECT]),
'update-pair': (SIGNAL_RUN_FIRST, None, 8 * [TYPE_PYOBJECT]),
}
def __init__(self):
def make_label(icon_name, label):
label_box = gtk.HBox()
icon = Icon(
icon_name=icon_name,
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
label_box.pack_start(icon, False)
label = gtk.Label(label)
label.modify_fg(gtk.STATE_NORMAL,
style.COLOR_TOOLBAR_GREY.get_gdk_color())
label_box.pack_start(label)
label_box.show_all()
return label_box
gtk.EventBox.__init__(self)
self.equal_pairs = False
self._updatebutton_sensitive = False
self._card1_has_sound = False
self._card2_has_sound = False
# save buttons
buttons_bar = gtk.HBox()
buttons_bar.props.border_width = 10
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)
buttons_bar.pack_start(self._addbutton, False)
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)
buttons_bar.pack_start(self._updatebutton, False)
# Set card editors
self.cardeditor1 = CardEditor()
self.cardeditor2 = CardEditor()
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)
# edit panel
self.card_box = gtk.HBox()
self.card_box.pack_start(self.cardeditor1)
self.card_box.pack_start(self.cardeditor2)
box = gtk.VBox()
box.pack_start(self.card_box, False)
box.pack_start(buttons_bar, False)
self.add(box)
self.show_all()
def emit_add_pair(self, widget):
self._addbutton.set_sensitive(False)
if self.equal_pairs:
self.emit('add-pair', self.cardeditor1.get_text(),
self.cardeditor1.get_text(),
self.cardeditor1.get_pixbuf(),
self.cardeditor1.get_pixbuf(),
self.cardeditor1.get_snd(), self.cardeditor1.get_snd(),
self.cardeditor1.get_speak(), self.cardeditor1.get_speak()
)
else:
self.emit('add-pair', self.cardeditor1.get_text(),
self.cardeditor2.get_text(),
self.cardeditor1.get_pixbuf(),
self.cardeditor2.get_pixbuf(),
self.cardeditor1.get_snd(), self.cardeditor2.get_snd(),
self.cardeditor1.get_speak(), self.cardeditor2.get_speak()
)
self.clean(None)
def emit_update_pair(self, widget):
self._addbutton.set_sensitive(False)
if self.equal_pairs:
self.emit('update-pair', self.cardeditor1.get_text(),
self.cardeditor1.get_text(),
self.cardeditor1.get_pixbuf(),
self.cardeditor1.get_pixbuf(),
#.........这里部分代码省略.........
示例14: TextAttributesToolbar
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
#.........这里部分代码省略.........
start_index = self._main_area.selected[0].index
end_index = self._main_area.selected[0].end_index
while(1):
found = False
r = it.range()
if start_index == end_index:
if r[0] <= start_index and r[1] > start_index:
found = True
elif start_index < end_index:
if r[0] > end_index:
break
if start_index == end_index and \
r[0] < start_index and \
r[1] > start_index:
found = True
elif start_index != end_index and r[0] <= start_index and \
r[1] >= end_index:
found = True
else:
if r[0] > start_index:
break
if start_index == end_index and \
r[0] < start_index and \
r[1] > start_index:
found = True
elif start_index != end_index and r[0] <= end_index and \
r[1] >= start_index:
found = True
if found:
attr = it.get_attrs()
for x in attr:
if x.type == pango.ATTR_WEIGHT and \
x.value == pango.WEIGHT_BOLD:
attributes["bold"] = False
elif x.type == pango.ATTR_STYLE and \
x.value == pango.STYLE_ITALIC:
attributes["italics"] = False
elif x.type == pango.ATTR_UNDERLINE and \
x.value == pango.UNDERLINE_SINGLE:
attributes["underline"] = False
elif x.type == pango.ATTR_FONT_DESC:
attributes["font"] = x.desc
if not it.next():
break
return attributes
def __font_sizes_cb(self, button, increase):
if not hasattr(self._main_area, 'font_size'):
return
if len(self._main_area.selected) < 1:
return
font_size = self._main_area.font_size
if font_size in self._font_sizes:
i = self._font_sizes.index(font_size)
if increase:
if i < len(self._font_sizes) - 2:
i += 1
else:
if i > 0:
i -= 1
else:
i = self._font_sizes.index(utils.default_font_size)
font_size = self._font_sizes[i]
self.size_label.set_text(str(font_size))
self.font_size_down.set_sensitive(i != 0)
self.font_size_up.set_sensitive(i < len(self._font_sizes) - 2)
self._main_area.set_font(self._main_area.font_name, font_size)
def __bold_cb(self, button):
if len(self._main_area.selected) < 1:
return
value = self.__attribute_values()["bold"]
self._main_area.set_bold(value)
def __italics_cb(self, button):
if len(self._main_area.selected) < 1:
return
value = self.__attribute_values()["italics"]
self._main_area.set_italics(value)
def __underline_cb(self, button):
if len(self._main_area.selected) < 1:
return
value = self.__attribute_values()["underline"]
self._main_area.set_underline(value)
def __foreground_color_cb(self, button):
color = button.get_color()
self._main_area.set_foreground_color(color)
def __background_color_cb(self, button):
color = button.get_color()
self._parent._main_area.set_background_color(color)
def change_active_font(self):
# TODO: update the toolbar
return
示例15: __init__
# 需要导入模块: from sugar.graphics.toolbutton import ToolButton [as 别名]
# 或者: from sugar.graphics.toolbutton.ToolButton import set_sensitive [as 别名]
class RecordControl:
def __init__(self, toolbar):
self._timer_value = TIMER_VALUES[0]
self._timer_button = ToolButton("timer-0")
self._timer_button.set_tooltip(_("Select timer"))
self._timer_button.connect("clicked", self._timer_selection_cb)
toolbar.insert(self._timer_button, -1)
self._setup_timer_palette()
self._duration_value = DURATION_VALUES[0]
self._duration_button = ToolButton("duration-2")
self._duration_button.set_tooltip(_("Select duration"))
self._duration_button.connect("clicked", self._duration_selection_cb)
toolbar.insert(self._duration_button, -1)
self._setup_duration_palette()
self._quality_value = 0
self._quality_button = ToolButton("low-quality")
self._quality_button.set_tooltip(_("Select quality"))
self._quality_button.connect("clicked", self._quality_selection_cb)
toolbar.insert(self._quality_button, -1)
self._setup_quality_palette()
def _timer_selection_cb(self, widget):
if self._timer_palette:
if not self._timer_palette.is_up():
self._timer_palette.popup(immediate=True, state=self._timer_palette.SECONDARY)
else:
self._timer_palette.popdown(immediate=True)
return
def _setup_timer_palette(self):
self._timer_palette = self._timer_button.get_palette()
for seconds in TIMER_VALUES:
if seconds == 0:
text = _("Immediate")
else:
text = ngettext("%s second", "%s seconds", seconds) % seconds
menu_item = MenuItem(icon_name="timer-%d" % (seconds), text_label=text)
menu_item.connect("activate", self._timer_selected_cb, seconds)
self._timer_palette.menu.append(menu_item)
menu_item.show()
def _timer_selected_cb(self, button, seconds):
self.set_timer_idx(TIMER_VALUES.index(seconds))
def _duration_selection_cb(self, widget):
if self._duration_palette:
if not self._duration_palette.is_up():
self._duration_palette.popup(immediate=True, state=self._duration_palette.SECONDARY)
else:
self._duration_palette.popdown(immediate=True)
return
def _setup_duration_palette(self):
self._duration_palette = self._duration_button.get_palette()
for minutes in DURATION_VALUES:
if minutes == 0:
text = gtk.Label(_("Immediate"))
else:
text = ngettext("%s minute", "%s minutes", minutes) % minutes
menu_item = MenuItem(icon_name="duration-%d" % (minutes), text_label=text)
menu_item.connect("activate", self._duration_selected_cb, minutes)
self._duration_palette.menu.append(menu_item)
menu_item.show()
def _duration_selected_cb(self, button, minutes):
self.set_duration_idx(DURATION_VALUES.index(minutes))
def _quality_selection_cb(self, widget):
if self._quality_palette:
if not self._quality_palette.is_up():
self._quality_palette.popup(immediate=True, state=self._quality_palette.SECONDARY)
else:
self._quality_palette.popdown(immediate=True)
return
def _setup_quality_palette(self):
self._quality_palette = self._quality_button.get_palette()
for quality in QUALITY_VALUES:
text = _("%s quality") % (quality)
menu_item = MenuItem(icon_name=quality + "-quality", text_label=text)
menu_item.connect("activate", self._quality_selected_cb, quality)
self._quality_palette.menu.append(menu_item)
menu_item.show()
def _quality_selected_cb(self, button, quality):
self.set_quality(QUALITY_VALUES.index(quality))
def set_mode(self, mode):
if mode == constants.MODE_PHOTO:
self._quality_button.set_sensitive(False)
self._timer_button.set_sensitive(True)
self._duration_button.set_sensitive(False)
if mode == constants.MODE_VIDEO:
self._quality_button.set_sensitive(True)
self._timer_button.set_sensitive(True)
#.........这里部分代码省略.........