本文整理汇总了Python中sugar3.graphics.toggletoolbutton.ToggleToolButton.get_active方法的典型用法代码示例。如果您正苦于以下问题:Python ToggleToolButton.get_active方法的具体用法?Python ToggleToolButton.get_active怎么用?Python ToggleToolButton.get_active使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.toggletoolbutton.ToggleToolButton
的用法示例。
在下文中一共展示了ToggleToolButton.get_active方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CreateToolbarBuilder
# 需要导入模块: from sugar3.graphics.toggletoolbutton import ToggleToolButton [as 别名]
# 或者: from sugar3.graphics.toggletoolbutton.ToggleToolButton import get_active [as 别名]
class CreateToolbarBuilder(GObject.GObject):
__gtype_name__ = 'CreateToolbar'
__gsignals__ = {
'create_new_game': (GObject.SignalFlags.RUN_FIRST, None, []),
'create_equal_pairs': (GObject.SignalFlags.RUN_FIRST,
None, [GObject.TYPE_PYOBJECT]),
}
def __init__(self, activity):
GObject.GObject.__init__(self)
self.activity = activity
self.toolbar = self.activity.get_toolbar_box().toolbar
self._equal_pairs = ToggleToolButton('pair-non-equals')
self._equal_pairs.set_tooltip(_('Match different tiles'))
self._equal_pairs.connect('toggled', self._emit_equal_pairs)
self.toolbar.insert(self._equal_pairs, -1)
self._grouped = ToggleToolButton('grouped_game1')
self._grouped.set_tooltip(_('Mixed tiles game'))
self._grouped.connect('toggled', self._grouped_cb)
self.toolbar.insert(self._grouped, -1)
self._clear_button = ToolButton('edit-clear')
self._clear_button.set_tooltip(_('Clear all tiles'))
self._clear_button.connect('clicked', self._clear_game_bt)
self.toolbar.insert(self._clear_button, -1)
self.toolbar.show_all()
def _add_widget(self, widget, expand=False):
tool_item = Gtk.ToolItem()
tool_item.set_expand(expand)
tool_item.add(widget)
widget.show()
self.toolbar.insert(tool_item, -1)
tool_item.show()
def _clear_game_bt(self, button):
if self.activity.game.model.is_demo or \
len(self.activity.cardlist.pairs) == 0:
self.clear_game()
else:
alert = Alert()
alert.props.title = _('Clear all the tiles from the game?')
icon = Icon(icon_name='dialog-ok')
alert.add_button(1, _('Clear'), icon)
icon = Icon(icon_name='dialog-cancel')
alert.add_button(0, _('Do not clear'), icon)
alert.connect('response', self._clear_game_alert_cb)
self.activity.add_alert(alert)
def _clear_game_alert_cb(self, alert, response_id):
self.activity.remove_alert(alert)
if response_id == 1:
self.clear_game()
def clear_game(self):
self._equal_pairs.set_active(False)
self._grouped.set_active(False)
self.emit('create_new_game')
def update_controls(self, active):
self._equal_pairs.set_sensitive(active)
self._grouped.set_sensitive(active)
self._clear_button.set_sensitive(active)
def _emit_equal_pairs(self, widget):
if self._equal_pairs.get_active():
self._equal_pairs.set_icon_name('pair-equals')
self._equal_pairs.set_tooltip(_('Match identical tiles'))
equal_pairs = '1'
else:
self._equal_pairs.set_icon_name('pair-non-equals')
self._equal_pairs.set_tooltip(_('Match different tiles'))
equal_pairs = '0'
self.emit('create_equal_pairs', self._equal_pairs.get_active())
logging.debug('createtoolbar._emit_equal_pairs')
if self.activity.game.model.data['equal_pairs'] != equal_pairs:
self.activity.game.model.data['equal_pairs'] = equal_pairs
self.activity.game.model.mark_modified()
def _grouped_cb(self, widget):
if self._grouped.get_active():
self._grouped.set_icon_name('grouped_game2')
self._grouped.set_tooltip(_('Grouped tiles game'))
divided = '1'
else:
self._grouped.set_icon_name('grouped_game1')
self._grouped.set_tooltip(_('Mixed tiles game'))
divided = '0'
logging.debug('createtoolbar._grouped_cb')
if self.activity.game.model.data['divided'] != divided:
self.activity.game.model.data['divided'] = divided
self.activity.game.model.mark_modified()
#.........这里部分代码省略.........