本文整理汇总了Python中sugar3.graphics.alert.NotifyAlert.show方法的典型用法代码示例。如果您正苦于以下问题:Python NotifyAlert.show方法的具体用法?Python NotifyAlert.show怎么用?Python NotifyAlert.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.alert.NotifyAlert
的用法示例。
在下文中一共展示了NotifyAlert.show方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _SharedJournalEntry
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
class _SharedJournalEntry(SharedJournalEntry):
__gsignals__ = {
'transfer-state-changed': (GObject.SignalFlags.RUN_FIRST, None,
([str, str])),
}
def __init__(self, account):
self._account = account
self._alert = None
def get_share_menu(self, get_uid_list):
menu = _ShareMenu(self._account, get_uid_list, True)
self._connect_transfer_signals(menu)
return menu
def __display_alert_cb(self, widget, title, message):
if self._alert is None:
self._alert = NotifyAlert()
self._alert.connect('response', self.__alert_response_cb)
journalwindow.get_journal_window().add_alert(self._alert)
self._alert.show()
self._alert.props.title = title
self._alert.props.msg = message
def __alert_response_cb(self, alert, response_id):
journalwindow.get_journal_window().remove_alert(alert)
self._alert = None
def _connect_transfer_signals(self, transfer_widget):
transfer_widget.connect('transfer-state-changed',
self.__display_alert_cb)
示例2: _alert
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
def _alert(self, title, msg=None):
a = NotifyAlert()
a.props.title = title
a.props.msg = msg
self.activity.add_alert(a)
a.connect('response', lambda a, r: self.activity.remove_alert(a))
a.show()
示例3: _alert
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
def _alert(self, title, text=None):
alert = NotifyAlert(timeout=20)
alert.props.title = title
alert.props.msg = text
self.add_alert(alert)
alert.connect('response', self._alert_cancel_cb)
alert.show()
示例4: alert
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
def alert(self, title, text=None, timeout=5):
if text != None:
alert = NotifyAlert(timeout=timeout)
alert.props.title = title
alert.props.msg = text
self.add_alert(alert)
alert.connect('response', self.alert_cancel_cb)
alert.show()
示例5: FacebookAccount
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
class FacebookAccount(account.Account):
ACCESS_TOKEN_KEY = "/desktop/sugar/collaboration/facebook_access_token"
ACCESS_TOKEN_KEY_EXPIRATION_DATE = \
"/desktop/sugar/collaboration/facebook_access_token_expiration_date"
def __init__(self):
self._client = GConf.Client.get_default()
facebook.FbAccount.set_access_token(self._access_token())
self._alert = None
def get_description(self):
return ACCOUNT_NAME
def is_configured(self):
return self._access_token() is not None
def is_active(self):
expiration_date = \
self._client.get_int(self.ACCESS_TOKEN_KEY_EXPIRATION_DATE)
return expiration_date != 0 and expiration_date > time.time()
def get_share_menu(self, journal_entry_metadata):
fb_share_menu = _FacebookShareMenu(journal_entry_metadata,
self.is_active())
self._connect_transfer_signals(fb_share_menu)
return fb_share_menu
def get_refresh_menu(self):
fb_refresh_menu = _FacebookRefreshMenu(self.is_active())
self._connect_transfer_signals(fb_refresh_menu)
return fb_refresh_menu
def _connect_transfer_signals(self, transfer_widget):
transfer_widget.connect('transfer-state-changed',
self._transfer_state_changed_cb)
def _transfer_state_changed_cb(self, widget, state_message):
logging.debug('_transfer_state_changed_cb')
# First, remove any existing alert
if self._alert is None:
logging.debug('creating new alert')
self._alert = NotifyAlert()
self._alert.props.title = ACCOUNT_NAME
self._alert.connect('response', self._alert_response_cb)
journalwindow.get_journal_window().add_alert(self._alert)
self._alert.show()
logging.debug(state_message)
self._alert.props.msg = state_message
def _alert_response_cb(self, alert, response_id):
journalwindow.get_journal_window().remove_alert(alert)
self._alert = None
def _access_token(self):
return self._client.get_string(self.ACCESS_TOKEN_KEY)
示例6: _alert
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
def _alert(self, title, text=None):
alert = NotifyAlert(timeout=5)
alert.props.title = title
alert.props.msg = text
self.add_alert(alert)
alert.connect('response', self._alert_cancel_cb)
alert.show()
self._has_alert = True
self._fixed_resize_cb()
示例7: _notify_new_game
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
def _notify_new_game(self, prompt):
''' Called from New Game button since loading a new game can
be slooow!! '''
alert = NotifyAlert(3)
alert.props.title = prompt
alert.props.msg = _('A new game is loading.')
def _notification_alert_response_cb(alert, response_id, self):
self.remove_alert(alert)
alert.connect('response', _notification_alert_response_cb, self)
self.add_alert(alert)
alert.show()
示例8: _confirm_save
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
def _confirm_save(self):
''' Called from confirmation alert '''
client.set_string('/desktop/sugar/user/color', '%s,%s' % (
self._game.colors[0], self._game.colors[1]))
alert = NotifyAlert()
alert.props.title = _('Saving colors')
alert.props.msg = _('A restart is required before your new colors '
'will appear.')
def _notification_alert_response_cb(alert, response_id, self):
self.remove_alert(alert)
alert.connect('response', _notification_alert_response_cb, self)
self.add_alert(alert)
alert.show()
示例9: _SharedJournalEntry
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
class _SharedJournalEntry(account.SharedJournalEntry):
__gsignals__ = {
'transfer-state-changed': (GObject.SignalFlags.RUN_FIRST, None,
([str])),
}
def __init__(self, fbaccount):
self._account = fbaccount
self._alert = None
def get_share_menu(self, journal_entry_metadata):
menu = _ShareMenu(
self._account.facebook,
journal_entry_metadata,
self._account.get_token_state() == self._account.STATE_VALID)
self._connect_transfer_signals(menu)
return menu
def get_refresh_menu(self):
menu = _RefreshMenu(
self._account.facebook,
self._account.get_token_state() == self._account.STATE_VALID)
self._connect_transfer_signals(menu)
return menu
def _connect_transfer_signals(self, transfer_widget):
transfer_widget.connect('transfer-state-changed',
self._transfer_state_changed_cb)
def _transfer_state_changed_cb(self, widget, state_message):
logging.debug('_transfer_state_changed_cb')
# First, remove any existing alert
if self._alert is None:
self._alert = NotifyAlert()
self._alert.props.title = ACCOUNT_NAME
self._alert.connect('response', self._alert_response_cb)
journalwindow.get_journal_window().add_alert(self._alert)
self._alert.show()
logging.debug(state_message)
self._alert.props.msg = state_message
def _alert_response_cb(self, alert, response_id):
journalwindow.get_journal_window().remove_alert(alert)
self._alert = None
示例10: publish
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
def publish(activity, force=False):
if not [i for i in book.custom.index if i['ready']]:
alert = NotifyAlert(5)
alert.props.title = _('Nothing to publish')
alert.props.msg = _('Mark arcticles from "Custom" '
'panel and try again.')
alert.connect('response', __alert_notify_response_cb, activity)
activity.add_alert(alert)
alert.show()
return
title = activity.metadata['title']
jobject = datastore.find({
'activity_id': activity.get_id(),
'activity' : book.custom.uid})[0] or None
logger.debug('publish: title=%s jobject=%s force=%s' \
% (title, jobject and jobject[0].metadata['activity'], force))
if jobject:
if force:
jobject = jobject[0]
else:
alert = ConfirmationAlert()
alert.props.title = _('Overwrite existed bundle?')
alert.props.msg = _('A bundle for current object was already created. '
'Click "OK" to overwrite it.')
alert.connect('response', __alert_response_cb, activity, True)
activity.add_alert(alert)
alert.show()
jobject[0].destroy()
return
else:
jobject = datastore.create()
jobject.metadata['activity_id'] = activity.get_id()
jobject.metadata['activity'] = book.custom.uid
jobject.metadata['mime_type'] = 'application/vnd.olpc-content'
jobject.metadata['description'] = \
'This is a bundle containing articles on %s.\n' \
'To view these articles, open the \'Browse\' Activity.\n' \
'Go to \'Books\', and select \'%s\'.' % (title, title)
book.custom.sync_article()
book.custom.revision += 1
jobject.metadata['title'] = title
_publish(title, jobject)
jobject.destroy()
book.custom.sync_index()
alert = NotifyAlert()
alert.props.title = _('Book published to your Journal')
alert.props.msg = _('You can read the book in Browse or '
'access the .xol file from your Journal')
alert.connect('response', __alert_notify_response_cb, activity)
activity.add_alert(alert)
alert.show()
示例11: _SharedJournalEntry
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
class _SharedJournalEntry(account.SharedJournalEntry):
__gsignals__ = {
'transfer-state-changed': (GObject.SignalFlags.RUN_FIRST, None,
([str])),
}
def __init__(self, webaccount):
self._account = webaccount
self._alert = None
def get_share_menu(self, get_uid_list):
menu = _ShareMenu(self._account, get_uid_list, True)
self._connect_transfer_signals(menu)
logging.debug('url cache: %s' % (self._account.url_cache))
return menu
def get_refresh_menu(self):
menu = _RefreshMenu(self._account, False)
self._connect_transfer_signals(menu)
return menu
def _connect_transfer_signals(self, transfer_widget):
transfer_widget.connect('transfer-state-changed',
self.__display_alert_cb)
def __display_alert_cb(self, widget, message):
if self._alert is None:
self._alert = NotifyAlert()
self._alert.props.title = ACCOUNT_NAME
self._alert.connect('response', self.__alert_response_cb)
journalwindow.get_journal_window().add_alert(self._alert)
self._alert.show()
self._alert.props.msg = message
def __alert_response_cb(self, alert, response_id):
journalwindow.get_journal_window().remove_alert(alert)
self._alert = None
示例12: _create_custom_food_cb
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
def _create_custom_food_cb(self, button):
def _notification_alert_response_cb(alert, response_id, self):
self.remove_alert(alert)
name = self.name_entry.get_text()
try:
calories = int(self.calories_entry.get_text())
except:
_logger.debug(self.calories_entry.get_text)
calories = None
pyramid = self.food_spinner.get_active()
if name == '' or name == _('food name'):
alert = NotifyAlert()
alert.props.title = _('Add a new food item.')
alert.connect('response', _notification_alert_response_cb, self)
alert.props.msg = _('You must enter a name for the new food item.')
self.add_alert(alert)
alert.show()
return
elif calories is None or calories < 0:
alert = NotifyAlert()
alert.props.title = _('Add a new food item.')
alert.connect('response', _notification_alert_response_cb, self)
alert.props.msg = _('You must enter calories for the new food \
item.')
self.add_alert(alert)
alert.show()
return
elif self._custom_food_jobject is None:
alert = NotifyAlert()
alert.props.title = _('Add a new food item.')
alert.connect('response', _notification_alert_response_cb, self)
alert.props.msg = _('You must load an image for the new food \
item.')
self.add_alert(alert)
alert.show()
return
_logger.debug(self._custom_food_jobject.file_path)
FOOD.append([name, calories, pyramid, 'apple.png'])
self._game.word_card_append(self._game.food_cards,
self._game.pixbuf)
self._game.food_cards[-1].type = len(FOOD) - 1
self._game.food_cards[-1].set_label(name)
self._game.picture_append(self._custom_food_jobject.file_path)
self._game.small_picture_append(self._custom_food_jobject.file_path)
alert = NotifyAlert()
alert.props.title = _('Add a new food item.')
alert.connect('response', _notification_alert_response_cb, self)
alert.props.msg = _('%s has been loaded.') % (name)
self.add_alert(alert)
alert.show()
self.name_entry.set_text(_('food name'))
self.calories_entry.set_text(_('calories'))
self._custom_food_image_path = None
self._game.build_food_groups()
self._game.new_game()
self.metadata['name-%d' % (self._custom_food_counter)] = name
self.metadata['calories-%d' % (self._custom_food_counter)] = \
str(calories)
self.metadata['pyramid-%d' % (self._custom_food_counter)] = str(pyramid)
self.metadata['jobject-%d' % (self._custom_food_counter)] = \
self._custom_food_jobject.object_id
self._custom_food_counter += 1
_logger.debug('writing %d to counter' % (self._custom_food_counter))
self.metadata['counter'] = str(self._custom_food_counter)
return
示例13: Account
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
class Account(account.Account):
def __init__(self):
self.upload = accountsmanager.get_service('sugargdrive')
self._shared_journal_entry = None
self._journal = None
self._model = None
self._alert = None
self._listview = None
self._volume_button = None
def get_description(self):
return ACCOUNT_DESCRIPTION
def add_journal_button(self):
if not self._journal:
palette = ExtensionPalette()
self._journal = get_journal()
self._listview = self._journal.get_list_view()
self._volumes_toolbar = self._journal.get_volumes_toolbar()
self._volume_button = ExtensionButton(ACCOUNT_ICON, ICONS_PATH)
self._volume_button.connect('toggled', self._journal_toggled)
self._volume_button.connect('load-files', self._load_files)
self._volume_button.connect('data-upload', self._upload_file)
self._volumes_toolbar.add_extension_button(self._volume_button,
ACCOUNT_NAME, palette)
palette.set_item_cb(self.update_files)
def get_token_state(self):
return self.STATE_VALID
def get_shared_journal_entry(self):
if self._shared_journal_entry is None:
self._shared_journal_entry = _SharedJournalEntry(self)
return self._shared_journal_entry
def _journal_toggled(self, widget):
self._journal.get_window().set_cursor(None)
option = widget.props.active
if option:
new_option = False
else:
new_option = True
self._listview.use_options(new_option)
def _load_files(self, *kwargs):
if not self._model:
journal_button = self._volumes_toolbar._volume_buttons[0]
self._model = FilesModel(self.upload, self._display_alert_cb,
self._load_files, journal_button, self._listview)
self._model.clear()
self._listview.tree_view.set_model(self._model)
def internal_callback():
files = []
if os.path.exists(USER_FILES):
f = open(USER_FILES, 'r')
try:
data = json.load(f)
except:
files = []
os.remove(USER_FILES)
self._journal.get_window().set_cursor(None)
f.close()
data = []
isdict = False
if isinstance(data, dict):
isdict = True
if isdict:
data = data['items']
for userfile in data:
txt = '<span weight="bold">%s</span>' % (
GLib.markup_escape_text(userfile['title']))
icon_name = _get_icon_for_mime(userfile['mimeType'])
link = userfile['alternateLink']
itter = self._model.insert(-1, [
'', False, icon_name,
profile.get_color(), txt, '', '', 50,
profile.get_color(), profile.get_color(),
profile.get_color(), True, link,
userfile['mimeType'],
userfile['id'],
userfile['title']])
files.append(itter)
if len(files) == 0 or not os.path.exists(USER_FILES):
self._listview._show_message(_('No files in your '
'account, please update your file list '
'clicking in the toolbar menu option.'),
icon_name=ACCOUNT_ICON)
else:
self._listview._clear_message()
#.........这里部分代码省略.........
示例14: MazeActivity
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
class MazeActivity(activity.Activity):
def __init__(self, handle):
"""Set up the Maze activity."""
activity.Activity.__init__(self, handle)
self._busy_count = 0
self._unbusy_idle_sid = None
self.build_toolbar()
self.pservice = PresenceService()
self.owner = self.pservice.get_owner()
state = None
if 'state' in self.metadata:
state = json.loads(self.metadata['state'])
self.game = game.MazeGame(self, self.owner, state)
self.set_canvas(self.game)
self.game.show()
self.connect("key_press_event", self.game.key_press_cb)
self.text_channel = None
self.my_key = profile.get_pubkey()
self._alert = None
if self.shared_activity:
# we are joining the activity
self._add_alert(_('Joining a maze'), _('Connecting...'))
self.connect('joined', self._joined_cb)
if self.get_shared():
# we have already joined
self._joined_cb()
else:
# we are creating the activity
self.connect('shared', self._shared_cb)
def busy(self):
if self._busy_count == 0:
if self._unbusy_idle_sid is not None:
GLib.source_remove(self._unbusy_idle_sid)
self._unbusy_idle_sid = None
self._old_cursor = self.get_window().get_cursor()
self._set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
self._busy_count += 1
def unbusy(self):
self._unbusy_idle_sid = GLib.idle_add(self._unbusy_idle_cb)
def _unbusy_idle_cb(self):
self._unbusy_idle_sid = None
self._busy_count -= 1
if self._busy_count == 0:
self._set_cursor(self._old_cursor)
def _set_cursor(self, cursor):
self.get_window().set_cursor(cursor)
Gdk.flush()
def build_toolbar(self):
"""Build our Activity toolbar for the Sugar system."""
toolbar_box = ToolbarBox()
activity_button = ActivityToolbarButton(self)
toolbar_box.toolbar.insert(activity_button, 0)
activity_button.show()
separator = Gtk.SeparatorToolItem()
toolbar_box.toolbar.insert(separator, -1)
separator.show()
easier_button = ToolButton('create-easier')
easier_button.set_tooltip(_('Easier level'))
easier_button.connect('clicked', self._easier_button_cb)
toolbar_box.toolbar.insert(easier_button, -1)
harder_button = ToolButton('create-harder')
harder_button.set_tooltip(_('Harder level'))
harder_button.connect('clicked', self._harder_button_cb)
toolbar_box.toolbar.insert(harder_button, -1)
separator = Gtk.SeparatorToolItem()
toolbar_box.toolbar.insert(separator, -1)
separator.show()
self.show_trail_button = ToggleToolButton('show-trail')
self.show_trail_button.set_tooltip(_('Show trail'))
self.show_trail_button.set_active(True)
self.show_trail_button.connect('toggled', self._toggled_show_trail_cb)
toolbar_box.toolbar.insert(self.show_trail_button, -1)
separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_size_request(0, -1)
separator.set_expand(True)
toolbar_box.toolbar.insert(separator, -1)
separator.show()
stop_button = StopButton(self)
toolbar_box.toolbar.insert(stop_button, -1)
stop_button.show()
#.........这里部分代码省略.........
示例15: TwitterAccount
# 需要导入模块: from sugar3.graphics.alert import NotifyAlert [as 别名]
# 或者: from sugar3.graphics.alert.NotifyAlert import show [as 别名]
class TwitterAccount(account.Account):
CONSUMER_TOKEN_KEY = "/desktop/sugar/collaboration/twitter_consumer_token"
CONSUMER_SECRET_KEY = "/desktop/sugar/collaboration/twitter_consumer_secret"
ACCESS_TOKEN_KEY = "/desktop/sugar/collaboration/twitter_access_token"
ACCESS_SECRET_KEY = "/desktop/sugar/collaboration/twitter_access_secret"
def __init__(self):
self._client = GConf.Client.get_default()
ctoken, csecret, atoken, asecret = self._access_tokens()
TwrAccount.set_secrets(ctoken, csecret, atoken, asecret)
self._alert = None
def get_description(self):
return ACCOUNT_NAME
def is_configured(self):
return None not in self._access_tokens()
def is_active(self):
# No expiration date
return None not in self._access_tokens()
def get_share_menu(self, journal_entry_metadata):
twr_share_menu = _TwitterShareMenu(journal_entry_metadata,
self.is_active())
self._connect_transfer_signals(twr_share_menu)
return twr_share_menu
def get_refresh_menu(self):
twr_refresh_menu = _TwitterRefreshMenu(self.is_active())
self._connect_transfer_signals(twr_refresh_menu)
return twr_refresh_menu
def _connect_transfer_signals(self, transfer_widget):
transfer_widget.connect('transfer-state-changed',
self._transfer_state_changed_cb)
def _transfer_state_changed_cb(self, widget, state_message):
logging.debug('_transfer_state_changed_cb')
# First, remove any existing alert
if self._alert is None:
self._alert = NotifyAlert()
self._alert.props.title = ACCOUNT_NAME
self._alert.connect('response', self._alert_response_cb)
journalwindow.get_journal_window().add_alert(self._alert)
self._alert.show()
logging.debug(state_message)
self._alert.props.msg = state_message
def _alert_response_cb(self, alert, response_id):
journalwindow.get_journal_window().remove_alert(alert)
self._alert = None
def _access_tokens(self):
return (self._client.get_string(self.CONSUMER_TOKEN_KEY),
self._client.get_string(self.CONSUMER_SECRET_KEY),
self._client.get_string(self.ACCESS_TOKEN_KEY),
self._client.get_string(self.ACCESS_SECRET_KEY))