def download_profile_stats(self, data=None): if not data: profile = load_profile() if 'kanoworld_id' in profile: user_id = profile['kanoworld_id'] else: return False, 'Profile not registered!' success, text, data = request_wrapper('get', '/users/' + user_id, headers=content_type_json, session=self.session) if not success: return False, text try: version_no = data['user']['avatar']['generator']['version'] save_profile_variable( 'version', version_no, skip_kdesk_refresh=True ) except Exception: pass updated_locally = False try: # Only update locally if version is 2. otherwise we will generate # a default if data['user']['avatar']['generator']['version'] == 2: gen = data['user']['avatar']['generator'] avatar_subcat, avatar_item = gen['character'] updated_locally = set_avatar( avatar_subcat, avatar_item, sync=False ) environment = gen['environment'][1] updated_locally |= set_environment(environment, sync=False) except Exception: pass # app states try: app_data = data['user']['profile']['stats'] except Exception: return False, "Data missing from payload!" for app, values in app_data.iteritems(): if not values or type(values) != dict or \ (len(values.keys()) == 1 and 'save_date' in values): continue if not is_private(app): save_app_state(app, values) if updated_locally: recreate_char(block=True) return True, None
def download_profile_stats(self, data=None): if not data: profile = load_profile() if 'kanoworld_id' in profile: user_id = profile['kanoworld_id'] else: return False, 'Profile not registered!' success, text, data = request_wrapper('get', '/users/' + user_id, headers=content_type_json, session=self.session) if not success: return False, text try: version_no = data['user']['avatar']['generator']['version'] save_profile_variable('version', version_no, skip_kdesk_refresh=True) except Exception: pass updated_locally = False try: # Only update locally if version is 2. otherwise we will generate # a default if data['user']['avatar']['generator']['version'] == 2: gen = data['user']['avatar']['generator'] avatar_subcat, avatar_item = gen['character'] updated_locally = set_avatar(avatar_subcat, avatar_item, sync=False) environment = gen['environment'][1] updated_locally |= set_environment(environment, sync=False) except Exception: pass # app states try: app_data = data['user']['profile']['stats'] except Exception: return False, "Data missing from payload!" for app, values in app_data.iteritems(): if not values or type(values) != dict or \ (len(values.keys()) == 1 and 'save_date' in values): continue if not is_private(app): save_app_state(app, values) if updated_locally: recreate_char(block=True) return True, None
def _get_avatar_path(self): avatar_image_path = get_avatar_circ_image_path() if not os.path.exists(avatar_image_path): recreate_char(block=True) avatar_image_path = get_avatar_circ_image_path() # If it still doesn't exist leave it empty if not os.path.exists(avatar_image_path): # use default avatar_image_path = self._get_local_avatar_path() return avatar_image_path
def download_profile_stats(self, data=None): if not data: profile = load_profile() if "kanoworld_id" in profile: user_id = profile["kanoworld_id"] else: return False, "Profile not registered!" success, text, data = request_wrapper( "get", "/users/" + user_id, headers=content_type_json, session=self.session ) if not success: return False, text try: version_no = data["user"]["avatar"]["generator"]["version"] save_profile_variable("version", version_no) except Exception: pass updated_locally = False try: # Only update locally if version is 2. otherwise we will generate # a default if data["user"]["avatar"]["generator"]["version"] == 2: gen = data["user"]["avatar"]["generator"] avatar_subcat, avatar_item = gen["character"] updated_locally = set_avatar(avatar_subcat, avatar_item) environment = gen["environment"][1] updated_locally |= set_environment(environment) except Exception: pass # app states try: app_data = data["user"]["profile"]["stats"] except Exception: return False, "Data missing from payload!" for app, values in app_data.iteritems(): if not values or (len(values.keys()) == 1 and "save_date" in values): continue if not is_private(app): save_app_state(app, values) if updated_locally: recreate_char(block=True) return True, None
def __init__(self, win): Gtk.EventBox.__init__(self) self._win = win icon_filename = os.path.join(media_dir, "images/icons/edit.png") self.cog_widget_icon = Gtk.Image.new_from_file(icon_filename) launch_char_creator_btn = Gtk.Button() attach_cursor_events(launch_char_creator_btn) hbox = Gtk.Box() edit_label = Gtk.Label(_("Edit").upper()) edit_label.set_margin_right(7) hbox.pack_start(self.cog_widget_icon, False, False, 0) hbox.pack_end(edit_label, False, False, 0) launch_char_creator_btn.connect('clicked', self.go_to_edit_character_screen) launch_char_creator_btn.connect('enter-notify-event', self.set_orange_cog) launch_char_creator_btn.connect('leave-notify-event', self.set_grey_cog) launch_char_creator_btn.get_style_context().add_class('character_cog') launch_char_creator_btn.add(hbox) # Pack this part of the screen into the window self._char_creator = self._win.char_creator # Get picture of character creator and pack it into the window path = self._char_creator.get_image_path() if not os.path.exists(path): # Usually we wouldn't be in this state, but just in case from kano_profile.profile import recreate_char, block_and_sync logger.warn("Character assets not there, will sync and recreate") block_and_sync() recreate_char(block=True) image = Gtk.Image.new_from_file(path) self.fixed = Gtk.Fixed() self.fixed.put(image, 0, 0) self.fixed.put(launch_char_creator_btn, 30, 30) self._win.pack_in_main_content(self.fixed) self._pack_progress_bar() self._win.show_all()