예제 #1
0
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
0
 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
0
 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()
예제 #4
0
class _SharedJournalEntry(account.SharedJournalEntry):
    __gsignals__ = {
        'transfer-state-changed':
        (GObject.SignalFlags.RUN_FIRST, None, ([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 _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
 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()
예제 #6
0
 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()
예제 #7
0
 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.cancel_alert)
         alert.show()
예제 #8
0
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)
예제 #9
0
파일: activity.py 프로젝트: sugarlabs/chat
 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()
예제 #10
0
 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()
    def alert_reset(self, mode):
        def _alert_response_cb(alert, response_id):
            self.remove_alert(alert)

        alert = NotifyAlert()
        alert.props.title = _('Time Reset')
        alert.props.msg = _('The timer mode was reset to %s' % mode)
        alert.connect('response', _alert_response_cb)
        alert.show()
        self.add_alert(alert)
    def alert_time(self):
        def _alert_response_cb(alert, response_id):
            self.remove_alert(alert)

        alert = NotifyAlert()
        alert.props.title = _('Time Up!')
        alert.props.msg = _('Your time is up.')
        alert.connect('response', _alert_response_cb)
        alert.show()
        self.add_alert(alert)
예제 #13
0
    def get_alert(self, title, text):
        """
        Show an alert above the activity.
        """

        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()
예제 #14
0
    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()
예제 #15
0
    def _notify_alert(self, title='', msg='', action=None):
        def _notification_alert_response_cb(alert, response_id, self, action):
            self.remove_alert(alert)
            if action is not None:
                action()
            self._restore_cursor()

        alert = NotifyAlert()
        alert.props.title = title
        alert.connect('response', _notification_alert_response_cb, self,
                      action)
        alert.props.msg = msg
        self.add_alert(alert)
        alert.show()
    def _notify_alert(self, title='', msg='', action=None):
        ''' Notify user when xfer is completed '''

        def _notification_alert_response_cb(alert, response_id, self, action):
            self.remove_alert(alert)
            if action is not None:
                action()

        alert = NotifyAlert()
        alert.props.title = title
        alert.connect('response', _notification_alert_response_cb, self,
                      action)
        alert.props.msg = msg
        self.add_alert(alert)
        alert.show()
예제 #17
0
    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()
    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()
예제 #19
0
파일: account.py 프로젝트: tchx84/facebook
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
예제 #20
0
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()
예제 #21
0
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()
예제 #22
0
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
예제 #23
0
    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
예제 #24
0
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))
예제 #25
0
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()

            self._journal.get_window().set_cursor(None)

        self._listview._show_message(_('Loading files...'),
                                     icon_name=ACCOUNT_ICON)
        cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH)
        self._journal.get_window().set_cursor(cursor)
        GObject.idle_add(internal_callback)

    def _upload_file(self, widget, metadata):
        account = self._shared_journal_entry._menu
        account.connect('transfer-state-changed', self._display_alert_cb)
        account.upload_file(None, metadata)

    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 update_files(self, widget):
        self._listview._show_message(_('Updating file list...'),
                                     icon_name=ACCOUNT_ICON)
        cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH)
        self._journal.get_window().set_cursor(cursor)
        if not self._volume_button.props.active:
            self._volume_button.set_active(True)
            self._journal_toggled(self._volume_button)

        def internal_callback():
            inst = self.upload.Upload()
            inst.update_files(self._display_alert_cb, self._load_files)
            self._listview._clear_message()
            self._journal.get_window().set_cursor(None)

        GObject.idle_add(internal_callback)
예제 #26
0
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()

        self.set_toolbar_box(toolbar_box)
        toolbar_box.show_all()

        return toolbar_box

    def _easier_button_cb(self, button):
        self.game.easier()

    def _harder_button_cb(self, button):
        self.game.harder()

    def _toggled_show_trail_cb(self, button):
        if self.game.set_show_trail(button.get_active()):
            self.broadcast_msg('show_trail:%s' % str(button.get_active()))

    def _shared_cb(self, activity):
        logging.debug('Maze was shared')
        self._add_alert(_('Sharing'), _('This maze is shared.'))
        self._setup()

    def _joined_cb(self, activity):
        """Joined a shared activity."""
        if not self.shared_activity:
            return
        logging.debug('Joined a shared chat')
        for buddy in self.shared_activity.get_joined_buddies():
            self._buddy_already_exists(buddy)
        self._setup()
        # request maze data
        self.broadcast_msg('req_maze')

    def _setup(self):
        self.text_channel = TextChannelWrapper(
            self.shared_activity.telepathy_text_chan,
            self.shared_activity.telepathy_conn, self.pservice)
        self.text_channel.set_received_callback(self._received_cb)
        self.shared_activity.connect('buddy-joined', self._buddy_joined_cb)
        self.shared_activity.connect('buddy-left', self._buddy_left_cb)

    def _received_cb(self, buddy, text):
        if buddy == self.owner:
            return
        self.game.msg_received(buddy, text)

    def _add_alert(self, title, text=None):
        self.grab_focus()
        self._alert = ErrorAlert()
        self._alert.props.title = title
        self._alert.props.msg = text
        self.add_alert(self._alert)
        self._alert.connect('response', self._alert_cancel_cb)
        self._alert.show()

    def _alert_cancel_cb(self, alert, response_id):
        self.remove_alert(alert)
        self._alert = None

    def update_alert(self, title, text=None):
        if self._alert is not None:
            self._alert.props.title = title
            self._alert.props.msg = text

    def show_accelerator_alert(self):
        self.grab_focus()
        self._alert = NotifyAlert()
        self._alert.props.title = _('Tablet mode detected.')
        self._alert.props.msg = _('Hold your XO flat and tilt to play!')
        self.add_alert(self._alert)
        self._alert.connect('response', self._alert_cancel_cb)
        self._alert.show()

    def _buddy_joined_cb(self, activity, buddy):
        """Show a buddy who joined"""
        logging.debug('buddy joined')
        if buddy == self.owner:
            logging.debug('its me, exit!')
            return
        self.game.buddy_joined(buddy)

    def _buddy_left_cb(self, activity, buddy):
        self.game.buddy_left(buddy)

    def _buddy_already_exists(self, buddy):
        """Show a buddy already in the chat."""
        if buddy == self.owner:
            return
        self.game.buddy_joined(buddy)

    def broadcast_msg(self, message):
        if self.text_channel:
            # FIXME: can't identify the sender at the other end,
            # add the pubkey to the text message
            self.text_channel.send('%s|%s' % (self.my_key, message))

    def write_file(self, file_path):
        logging.debug('Saving the state of the game...')
        data = {'seed': self.game.maze.seed,
                'width': self.game.maze.width,
                'height': self.game.maze.height,
                'finish_time': self.game.finish_time}
        logging.debug('Saving data: %s', data)
        self.metadata['state'] = json.dumps(data)

    def can_close(self):
        self.game.close_finish_window()
        return True

    def read_file(self, file_path):
        pass
예제 #27
0
파일: account.py 프로젝트: i5o/sugar-gdrive
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()

            self._journal.get_window().set_cursor(None)

        self._listview._show_message(_('Loading files...'),
                icon_name=ACCOUNT_ICON)
        cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH)
        self._journal.get_window().set_cursor(cursor)
        GObject.idle_add(internal_callback)

    def _upload_file(self, widget, metadata):
        account = self._shared_journal_entry._menu
        account.connect('transfer-state-changed', self._display_alert_cb)
        account.upload_file(None, metadata)

    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 update_files(self, widget):
        self._listview._show_message(_('Updating file list...'),
                icon_name=ACCOUNT_ICON)
        cursor = Gdk.Cursor.new(Gdk.CursorType.WATCH)
        self._journal.get_window().set_cursor(cursor)
        if not self._volume_button.props.active:
            self._volume_button.set_active(True)
            self._journal_toggled(self._volume_button)

        def internal_callback():
            inst = self.upload.Upload()
            inst.update_files(self._display_alert_cb, self._load_files)
            self._listview._clear_message()
            self._journal.get_window().set_cursor(None)

        GObject.idle_add(internal_callback)
예제 #28
0
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()

        self.set_toolbar_box(toolbar_box)
        toolbar_box.show_all()

        return toolbar_box

    def _easier_button_cb(self, button):
        self.game.easier()

    def _harder_button_cb(self, button):
        self.game.harder()

    def _toggled_show_trail_cb(self, button):
        if self.game.set_show_trail(button.get_active()):
            self.broadcast_msg('show_trail:%s' % str(button.get_active()))

    def _shared_cb(self, activity):
        logging.debug('Maze was shared')
        self._add_alert(_('Sharing'), _('This maze is shared.'))
        self._setup()

    def _joined_cb(self, activity):
        """Joined a shared activity."""
        if not self.shared_activity:
            return
        logging.debug('Joined a shared chat')
        for buddy in self.shared_activity.get_joined_buddies():
            self._buddy_already_exists(buddy)
        self._setup()
        # request maze data
        self.broadcast_msg('req_maze')

    def _setup(self):
        self.text_channel = TextChannelWrapper(
            self.shared_activity.telepathy_text_chan,
            self.shared_activity.telepathy_conn, self.pservice)
        self.text_channel.set_received_callback(self._received_cb)
        self.shared_activity.connect('buddy-joined', self._buddy_joined_cb)
        self.shared_activity.connect('buddy-left', self._buddy_left_cb)

    def _received_cb(self, buddy, text):
        if buddy == self.owner:
            return
        self.game.msg_received(buddy, text)

    def _add_alert(self, title, text=None):
        self.grab_focus()
        self._alert = ErrorAlert()
        self._alert.props.title = title
        self._alert.props.msg = text
        self.add_alert(self._alert)
        self._alert.connect('response', self._alert_cancel_cb)
        self._alert.show()

    def _alert_cancel_cb(self, alert, response_id):
        self.remove_alert(alert)
        self._alert = None

    def update_alert(self, title, text=None):
        if self._alert is not None:
            self._alert.props.title = title
            self._alert.props.msg = text

    def show_accelerator_alert(self):
        self.grab_focus()
        self._alert = NotifyAlert()
        self._alert.props.title = _('Tablet mode detected.')
        self._alert.props.msg = _('Hold your XO flat and tilt to play!')
        self.add_alert(self._alert)
        self._alert.connect('response', self._alert_cancel_cb)
        self._alert.show()

    def _buddy_joined_cb(self, activity, buddy):
        """Show a buddy who joined"""
        logging.debug('buddy joined')
        if buddy == self.owner:
            logging.debug('its me, exit!')
            return
        self.game.buddy_joined(buddy)

    def _buddy_left_cb(self, activity, buddy):
        self.game.buddy_left(buddy)

    def _buddy_already_exists(self, buddy):
        """Show a buddy already in the chat."""
        if buddy == self.owner:
            return
        self.game.buddy_joined(buddy)

    def broadcast_msg(self, message):
        if self.text_channel:
            # FIXME: can't identify the sender at the other end,
            # add the pubkey to the text message
            self.text_channel.send('%s|%s' % (self.my_key, message))

    def write_file(self, file_path):
        logging.debug('Saving the state of the game...')
        data = {
            'seed': self.game.maze.seed,
            'width': self.game.maze.width,
            'height': self.game.maze.height,
            'finish_time': self.game.finish_time
        }
        logging.debug('Saving data: %s', data)
        self.metadata['state'] = json.dumps(data)

    def can_close(self):
        self.game.close_finish_window()
        return True

    def read_file(self, file_path):
        pass
예제 #29
0
    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