def next(self): if self.Band_num < len(self.Dat.BandsArrays)-1: self.Band_num+=1 Cache.remove('kv.image') Cache.remove('kv.texture') self.Dat.SaveBAND(self.Dat.BandsArrays[self.Band_num], "TMP.tiff") self.A_image = Image("TMP.tiff")
def restart_game(self): Cache.remove(CACHE_NAME) screen_name = 'game' screen = ValidObject.screen(self.manager.get_screen(screen_name)) screen.ids['left_btn_wrap'].children[0].button_state_style() screen.ids['right_btn_wrap'].children[0].button_state_style() scene = screen.ids['scene'] road = screen.ids['road'] bike = screen.ids['bike'] if screen.ids.get('curtain'): scene.remove_widget(screen.ids['curtain']) road.bike = bike road.init_app_config() road.set_state(State.NONE) road.clear_widgets() road.landing_start() road.set_distance_traveled(0) bike.init_app_config() bike.collected_currency = 0 bike.y = 800 bike.canvas.remove_group("background") Curtain(font_size=FS.H1.value).add_to_game_screen(screen, scene) curtain = screen.ids['curtain'] if not curtain.text: curtain.do_start_timer() Clock.schedule_interval(scene.start_timer, 1) self.manager.current = screen_name
def kivy_benchmark(benchmark, kivy_clock): from kivy.core.window import Window from kivy.cache import Cache from kivy.utils import platform import kivy from kivy.core.gl import glGetString, GL_VENDOR, GL_RENDERER, GL_VERSION for category in list(Cache._objects.keys()): if category not in Cache._categories: continue for key in list(Cache._objects[category].keys()): Cache.remove(category, key) gc.collect() benchmark.extra_info['platform'] = str(sys.platform) benchmark.extra_info['python_version'] = str(sys.version) benchmark.extra_info['python_api'] = str(sys.api_version) benchmark.extra_info['kivy_platform'] = platform benchmark.extra_info['kivy_version'] = kivy.__version__ benchmark.extra_info['gl_vendor'] = str(glGetString(GL_VENDOR)) benchmark.extra_info['gl_renderer'] = str(glGetString(GL_RENDERER)) benchmark.extra_info['gl_version'] = str(glGetString(GL_VERSION)) yield benchmark
def reset_all(self): Cache.remove('textinput.label') self.text_input._trigger_refresh_text() if self.counter_clock is not None: self.counter_clock.cancel() self.running = False self.on_text(self.tape_input.text)
def iter(self, a): #print("svb") r, img = self.cam.read() img = cv2.flip(img, 1) """ if self.tex == None: s = img.shape self.tex = Texture.create(size=(s[0],s[1]), colorfmt='rgb') self.tex.blit_buffer(img, colorfmt='rgb',bufferfmt='ubyte') """ for k in self.objs.keys(): res = cv2.matchTemplate(img, self.objs[k], cv2.TM_CCOEFF_NORMED) thresh = 0.4 loc = np.where(res >= thresh) w, h, _ = self.objs[k].shape for pt in zip(*loc[::-1]): img = cv2.putText(img, k, pt, cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2, cv2.LINE_AA) img = cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2) break cv2.imwrite('/tmp/svb.png', img) Cache.remove('kv.image') Cache.remove('kv.texture') self.gui.rl.ids.iVirButCam.texture = Image('/tmp/svb.png').texture if self.running: Clock.schedule_once(self.iter, 0.1)
def on_customer_passport_picture_ready(self, *args): Cache.remove('kv.image') Cache.remove('kv.texture') self.ids.customer_passport_picture_image.source = '' self.ids.customer_passport_picture_image.source = args[0] self.scr_manager().current = 'edit_customer_screen' self.scr_manager().remove_widget(self.camera_screen)
def drop_request(self, filename, client, load_callback=None, post_callback=None, **kwargs): #Logger.info('_drop_request: from cache queue %s %d %d' % (filename,len(self._client),len(self._q_load))) item = None for i in self._client: if (i[0] == filename): #and (i[1] == client): item = i break if item: Logger.info('_drop_request: found client %s ' % filename) self._client.remove(item) item = None for i in self._q_load: if (i['filename'] == filename): #and (i['load_callback'] == load_callback) and (i['post_callback'] == post_callback): item = i break if item: Logger.info('_drop_request: found _q_load %s ' % filename) self._q_load.remove(item) if not kwargs.get('nocache', False): #Logger.info('_drop_request: dropped %s ' % filename) Cache.remove('kv.loader', filename)
def __init__(self) -> None: App.__init__(self) #Allows access to controller class to send signals self.Controller = Controller() #For GPS/Mapping self.TargetInfo = TargetInfo() self.tp = None self.th_drone_control = None self.th_drone_adv_control = None self.th_doc = None Cache.remove('kv.image') Cache.remove('kv.texture') image = Image.open("Gmap/default.png") temp = image.copy() temp.save("Gmap/drone_path.png") image = Image.open("images/default_score.png") temp = image.copy() temp.save("images/scored.png") temp.save("images/prescored.png")
def previous(self): if self.Band_num >= 0: self.Band_num-=1 Cache.remove('kv.image') Cache.remove('kv.texture') self.Dat.SaveBAND(self.Dat.BandsArrays[self.Band_num], "TMP.tiff") self.A_image = Image("TMP.tiff")
def display_screen(self, next_screen, direction, track, *args, **kwargs): old_screen = None if isinstance(next_screen, str): screen = Cache.get('screens', next_screen) if screen is None or next_screen in SCREEN_BLACKLIST: screen = self._create_screen(next_screen, *args, **kwargs) else: screen.reload(*args, **kwargs) next_screen = screen if len(self.children) > 0: old_screen = self.children[0] if not direction: if len(self.list) > 0: next_screen = self.list.pop() next_screen.reload(*args, **kwargs) else: print("No more screens to backtrack.") return if old_screen is None: Refs.log(f'Display {next_screen.name}') else: Refs.log(f'{old_screen.name} → {next_screen.name}') if next_screen not in self.screens: self.add_widget(next_screen) self.current = next_screen.name if old_screen is not None: if old_screen.name == 'dungeon_battle' and old_screen.boss_encounter: Refs.log(f'Battle from boss encounter - Dont delete') return self.remove_widget(old_screen) if track and old_screen.name not in SCREEN_BLACKLIST: self.list.append(old_screen) if old_screen.name in SCREEN_BLACKLIST: Cache.remove('screens', old_screen)
def on_config_change(self, config, section, key, value): Logger.debug("HMS: on_config_change") if section != "HMS": return if key == "client_id" or key == "client_secret": Cache.remove("HMS", "client_token") self._get_client_token()
def callback(self): weekNumber = int(self.text.split()[-1]) if Cache.get("counter", 'value') == None: Cache.append("counter", 'value', weekNumber) else: Cache.remove("counter", "value") Cache.append("counter", 'value', weekNumber) pages.append(UserAttendance(name="UserAttendance")) Functions.ChangePage(pages, screen)
def clean_input_fields(self): Cache.remove('kv.image') Cache.remove('kv.texture') self.ids.customer_first_name_input.text = '' self.ids.customer_last_name_input.text = '' self.ids.customer_phone_input.text = '' self.ids.customer_email_input.text = '' self.ids.customer_address_input.text = '' self.ids.customer_photo_picture_image.source = '' self.ids.customer_passport_picture_image.source = ''
def test_timestamp_and_lastaccess(test_file): Cache.remove(RESOURCE_CACHE) start = Clock.get_time() resource_find(test_file) ts = Cache.get_timestamp(RESOURCE_CACHE, test_file) last_access = Cache.get_lastaccess(RESOURCE_CACHE, test_file) assert ts >= start, 'Last timestamp not accurate.' assert last_access >= start, 'Last access time is not accurate.'
def set_app(self): Cache.register('bike') Cache.register('map') Cache.remove('bike', 'rm') Cache.append('bike', 'rm', RM) self.sm = ScreenManager(transition=WipeTransition()) self.sm.add_widget(MenuScreen(name='menu')) self.sm.add_widget(GameScreen(name='game')) self.render(self.sm)
def set_config(map_model: MapModel, rest_rm: int): Cache.remove('bike', 'rm') Cache.append('bike', 'rm', rest_rm) Cache.remove('map', 'title') Cache.remove('map', 'level') Cache.remove('map', 'map') Cache.remove('map', 'total_way') Cache.append('map', 'title', map_model.title) Cache.append('map', 'level', map_model.level) Cache.append('map', 'map', map_model.map) Cache.append('map', 'total_way', map_model.total_way)
def update(self, *args): self.new = self.arduino line = self.new.readline(self.new.inWaiting()) self.new.flush() self.new.flushInput() self.new.flushOutput() print line.split(), 'arduino' if len(line.split()) != 0 and "FF" not in line: if Cache.get('id', 'user') == None: Cache.append('id', 'user', line.strip()) else: Cache.remove('id', 'user'), 'purge' Cache.append('id', 'user', line.strip())
def DeleteSavedFace(self): self.ids.displayImage.source = '' imToRemove = CoreImage('faceImg/grayImg.png') imToRemove.remove_from_cache() os.rename("faceImg/grayImg.png", "faceImg/grayImgTemp.png") Cache.remove("kv.image") Cache.remove("kv.textur") self.remove_widget(self.ids.displayImage) os.rename("faceImg/grayImgTemp.png", "faceImg/grayImg.png") self.ids.displayImage.source = 'faceImg/grayImg.png'
def refresh_view_attrs(self, rv, index, data): self.index = index status = data['status'] self.original_image = data.get('original_image', None) or MISSING_IMAGE reshoot_image = MISSING_IMAGE if status == 1: reshoot_image = data.get('reshoot_image', None) or MISSING_IMAGE if reshoot_image != MISSING_IMAGE: Cache.remove('kv.loader', reshoot_image) self.reshoot_image = reshoot_image self.page_number = str(data.get('page_number', None) or '-') self.leaf_number = str(data.get('leaf_number', None) or '-') self.page_type = data.get('page_type', None) or '-' self.note = data.get('note', None) or '-' self.status_image = self._status_images.get(status, MISSING_IMAGE)
def _save_photo(self, *args, **kwargs): """ Saving procedure handler. """ rotation_dct = {90: Image.ROTATE_90, 180: Image.ROTATE_180, 270: Image.ROTATE_270} rotation = self.norm_photo(self.photo.rotation, None, None) rotation = int(str(rotation).rsplit(".", 1)[0]) image_path = self.picture.image_source.source if rotation > 0 and rotation in rotation_dct: im = Image.open(image_path) im = im.transpose(rotation_dct.get(rotation)) im.save(image_path, quality=95) Cache.remove("kv.loader", image_path) self.load_files(image_path) self.reload_photos()
def onCameraClick(self, *args): Cache.remove('kv.image') Cache.remove('kv.texture') self.delete_output_pngs() if self.clicked == True: self.layout.remove_widget(self.output) self.clicked = True self.cameraObject.export_to_png('output.png') latex_string = image_to_latex('output.png') #latex_string = u'\\left. \\begin{array} { l } { 4 x ^ { 3 } + \\int _ { 0 } ^ { x } x ^ { 2 } d x } \\\\ { = 4 x ^ { 3 } + 3 x ^ { 3 } } \\\\ { = 7 x ^ { 3 } } \\end{array} \\right.' print latex_string.__repr__() latex_equations = split_into_equations(latex_string) print latex_equations self.output = Output(latex_equations, size_hint=(1, .35)) self.layout.add_widget(self.output)
def populate_input_fields(self): Cache.remove('kv.image') Cache.remove('kv.texture') customer_info = local_storage.read_customer_info(self.customer_id) or {} self.ids.customer_first_name_input.text = customer_info.get('first_name') or '' self.ids.customer_last_name_input.text = customer_info.get('last_name') or '' self.ids.customer_phone_input.text = customer_info.get('phone') or '' self.ids.customer_email_input.text = customer_info.get('email') or '' self.ids.customer_address_input.text = customer_info.get('address') or '' self.ids.customer_photo_picture_image.source = '' self.ids.customer_photo_picture_image.source = local_storage.customer_photo_filepath(self.customer_id) self.ids.customer_photo_filepath_label.text = local_storage.customer_photo_filepath(self.customer_id) self.ids.customer_passport_picture_image.source = '' self.ids.customer_passport_picture_image.source = local_storage.customer_passport_filepath(self.customer_id) self.ids.customer_passport_picture_filepath_label.text = local_storage.customer_passport_filepath(self.customer_id)
def update_button(self, button): self.move_str += button.id # print(self.move_str) if len(self.move_str) == 4: Cache.remove('kv.image') Cache.remove('kv.texture') move = chess.Move(from_square=chess.parse_square( self.move_str[:2]), to_square=chess.parse_square(self.move_str[2:4])) move = self.check_pawn_promotion(move) print(f"Your move: {move}") if move in self.board.legal_moves: self.board.push(move) [ Path(m).unlink(missing_ok=True) for m in list(Path("moves/").glob("chess*")) ] save_name = f'moves/chess_{str(move)}_{self.board.turn}.png' svg2png(bytestring=chess.svg.board(self.board, size=350), write_to=save_name) self.rect.source = save_name if self.board.is_game_over(): return self.declare_winner() # ai_move = np.random.choice(list(self.board.legal_moves)) # ai_move = list(self.board.legal_moves)[0] # print(ai_move) ai_move = self.engine.make_move(self.board) print(f"AI move: {ai_move}") if isinstance(ai_move, chess.Move): self.board.push(ai_move) else: return self.declare_winner() if self.board.is_game_over(): return self.declare_winner() [ Path(m).unlink(missing_ok=True) for m in list(Path("moves/").glob("chess*")) ] save_name = f'moves/chess_{str(move)}_{self.board.turn}.png' svg2png(bytestring=chess.svg.board(self.board, size=350), write_to=save_name) self.rect.source = save_name self.move_str = ""
def pop1(self): global url #pass #pop = Popup(title='camera', content=AsyncImage(source="http://www.ninjaducks.in/images/duck.png"),size_hint=(None, None), size=(400, 400)) #Image.reload() Cache.remove('kv.asyncimage') Cache.remove('kv.texture') #Image.remove_from_cache() #Image.reload() #img = AsyncImage(source="http://192.168.0.102:5000/img2/"+str(random.randrange(0, 101, 2))) img = AsyncImage(source=url[:-5] + "5000/img2/" + str(random.randrange(0, 101, 2))) pop = Popup(title='camera', content=img, size_hint=(1, 1)) #Image.remove_from_cache() #size=(400, 400) pop.open()
def save_photo_handler(self, animation=None, weakref=None): """ Saving procedure handler. """ rotation_dct = { 90: Image.ROTATE_90, 180: Image.ROTATE_180, 270: Image.ROTATE_270, } rotation = self.norm_photo(self.photo.rotation, None, None) rotation = int(str(rotation).rsplit(".", 1)[0]) image_path = self.picture.image_source.source if rotation > 0 and rotation in rotation_dct: im = Image.open(image_path) im = im.transpose(rotation_dct.get(rotation)) im.save(image_path, quality=95) Cache.remove("kv.loader", image_path) self.load_files(image_path) self.reload_photos()
def on_pre_enter(self, *args): # If we re-entered a book after a camera calibration issue, we may have # stale images in the cache # print "CONFIGURATION OK?" + str(configuration_ok) # If metadata is not set correctly, abort # if not configuration_ok: # self.abort_shooting() # return Cache.remove('kv.image') Cache.remove('kv.texture') backend = self.backend backend.book = self.book backend.reopen_at = self.reopen_at backend.scandata = self.scandata backend.camera_system = self.scribe_widget backend.window = self.get_root_window() backend.logger = Logger backend.init() Clock.schedule_once(self._on_backend_init)
def build(self): #salva ate 10 valores com tempo de vida 60 de segundos Cache.register('mycache', limit=10, timeout=60) # id da cache key = 'objectid' # objeto a ser salvo objeto = Label(text='CACHE') # salvando no cache Cache.append('mycache', key, objeto) # retorna valor do cache instance = Cache.get('mycache', key) #remove do cahce Cache.remove('mycache', key) return instance
def _on_source_load(self, *_): try: image = self._coreimage.image if not image: return except: return self.thumbnail = image self.thumbsize = image.size self.texture = image.texture self.aspect = image.size[1] / image.size[0] if self.loadfullsize: Cache.remove('kv.image', self.source) try: self._coreimage.image.remove_from_cache() self._coreimage.remove_from_cache() except: pass Clock.schedule_once(lambda dt: self._load_fullsize())
def scan(self, dt): self.ids['st_id'].text = '' self.ids['st_name'].text = '' if Cache.get('id', 'user') != None: value = card_exist(Cache.get('id', 'user')) if len(value) == 0: Clock.unschedule(self.scan) Functions.new_card_pop(self) else: values = attendance(Cache.get('id', 'user')) if values == 1: self.ids['st_id'].text = str(value[0][3]) self.ids['st_name'].text = value[0][0] + " " + value[0][1] self.ids['st_warn'].opacity = 0 elif values == 0: self.ids['st_warn'].opacity = 1 elif values == -1: self.ids['st_warn'].text = "Attendance already taken" self.ids['st_warn'].opacity = 1 Cache.remove('id', 'user')
def kivy_benchmark(benchmark, kivy_clock): from kivy.core.window import Window from kivy.cache import Cache from kivy.utils import platform import kivy from kivy.core.gl import glGetString, GL_VENDOR, GL_RENDERER, GL_VERSION from kivy.context import Context from kivy.clock import ClockBase from kivy.factory import FactoryBase, Factory from kivy.lang.builder import BuilderBase, Builder context = Context(init=False) context['Clock'] = ClockBase() context['Factory'] = FactoryBase.create_from(Factory) context['Builder'] = BuilderBase.create_from(Builder) for category in list(Cache._objects.keys()): if category not in Cache._categories: continue for key in list(Cache._objects[category].keys()): Cache.remove(category, key) gc.collect() benchmark.extra_info['platform'] = str(sys.platform) benchmark.extra_info['python_version'] = str(sys.version) benchmark.extra_info['python_api'] = str(sys.api_version) benchmark.extra_info['kivy_platform'] = platform benchmark.extra_info['kivy_version'] = kivy.__version__ benchmark.extra_info['gl_vendor'] = str(glGetString(GL_VENDOR)) benchmark.extra_info['gl_renderer'] = str(glGetString(GL_RENDERER)) benchmark.extra_info['gl_version'] = str(glGetString(GL_VERSION)) context.push() try: yield benchmark finally: context.pop()
def remove_from_cache(self): '''Remove the Image from cache. This facilitates re-loading of images from disk in case the image content has changed. .. versionadded:: 1.3.0 Usage:: im = CoreImage('1.jpg') # -- do something -- im.remove_from_cache() im = CoreImage('1.jpg') # this time image will be re-loaded from disk ''' count = 0 uid = '%s|%s|%s' % (self.filename, self._mipmap, count) Cache.remove("kv.image", uid) while Cache.get("kv.texture", uid): Cache.remove("kv.texture", uid) count += 1 uid = '%s|%s|%s' % (self.filename, self._mipmap, count)
def remove_from_cache(self): '''Remove the Image from cache. This facilitates re-loading of image from disk in case of contents having been changed. .. versionadded:: 1.3.0 Usage:: im = CoreImage('1.jpg') # -- do something -- im.remove_from_cache() im = CoreImage('1.jpg') # this time image will be re-loaded from disk ''' count = 0 uid = '%s|%s|%s' % (self.filename, self._mipmap, count) Cache.remove("kv.image", uid) while Cache.get("kv.texture", uid): Cache.remove("kv.texture", uid) count += 1 uid = '%s|%s|%s' % (self.filename, self._mipmap, count)
def test_load_resource_not_found(): Cache.remove(RESOURCE_CACHE) missing_file_name = "missing_test_file.foo" find_missing_file = resource_find(missing_file_name) assert find_missing_file is None with tempfile.TemporaryDirectory() as temp_dir: missing_file_path = os.path.join(temp_dir, missing_file_name) with open(missing_file_path, "w"): pass # touch file find_missing_file_again = resource_find(missing_file_name) assert find_missing_file_again is None cached_filename = Cache.get(RESOURCE_CACHE, missing_file_name) assert cached_filename is None resource_add_path(temp_dir) found_file = resource_find(missing_file_name) assert missing_file_path == found_file assert missing_file_path == Cache.get(RESOURCE_CACHE, missing_file_name)
def remove_from_cache(self): '''Remove the Image from cache. This facilitates re-loading of images from disk in case the image content has changed. .. versionadded:: 1.3.0 Usage:: im = CoreImage('1.jpg') # -- do something -- im.remove_from_cache() im = CoreImage('1.jpg') # this time image will be re-loaded from disk ''' count = 0 f = self.filename pat = type(f)(u'%s|%d|%d') uid = pat % (f, self._mipmap, count) Cache.remove("kv.image", uid) while Cache.get("kv.texture", uid): Cache.remove("kv.texture", uid) count += 1 uid = pat % (f, self._mipmap, count)
def releaseMemory(self): self.img_texture = False self.border_image = False self.fbo_texture = Texture.create(size=(2, 2), colorfmt="rgba") # clear up cache Cache.remove("kv.image") Cache.remove("kv.texture") Cache.remove("kv.loader") pass
def releaseMemory(self): self.img_texture = False self.border_image = False self.fbo_texture = Texture.create(size=(2, 2), colorfmt="rgba") # clear up cache Cache.remove('kv.image') Cache.remove('kv.texture') Cache.remove('kv.loader') pass
def removeLatestImage(self): if self.latestCapturedPicture != None: self.root.remove_widget(self.latestCapturedPicture) self.slotImages.addExistingImage(self.latestCapturedPicture, lambda anim,pic: self.startPreview()) self.latestCapturedPicture = None # clear up cache Cache.remove('kv.image') Cache.remove('kv.texture') Cache.remove('kv.loader') pass
def removeLatestImage(self): if self.latestCapturedPicture != None: self.root.remove_widget(self.latestCapturedPicture) self.slotImages.addExistingImage( self.latestCapturedPicture, lambda anim, pic: self.startPreview()) self.latestCapturedPicture = None # clear up cache Cache.remove('kv.image') Cache.remove('kv.texture') Cache.remove('kv.loader') pass
def Gistogram(self): self.Dat.SaveBAND(self.Dat.histequalization(self.Dat.ListofBands[self.Band_num]), "TMP.tiff") Cache.remove('kv.image') Cache.remove('kv.texture') self.A_image = Image("TMP.tiff")
def remove_from_cache(self, filename): Cache.remove('kv.loader', filename)
def Composite(self): self.Dat.CompositeBands(self.Dat.BandsArrays[5], self.Dat.BandsArrays[6], self.Dat.BandsArrays[3], self.Dat.BandsArrays[2]) Cache.remove('kv.image') Cache.remove('kv.texture') self.A_image = Image("TMP.tiff")
log('OpenGL informations') log('-------------------') from kivy.core.gl import glGetString, GL_VENDOR, GL_RENDERER, GL_VERSION log('GL Vendor: %s' % glGetString(GL_VENDOR)) log('GL Renderer: %s' % glGetString(GL_RENDERER)) log('GL Version: %s' % glGetString(GL_VERSION)) log('') log('Benchmark') log('---------') for x in benchs: # clean cache to prevent weird case for cat in Cache._categories: Cache.remove(cat) # force gc before next test gc.collect() log('%2d/%-2d %-60s' % (benchs.index(x) + 1, len(benchs), x.__doc__), False) try: sys.stderr.write('.') test = x() except Exception as e: log('failed %s' % str(e)) import traceback traceback.print_exc() continue
def I_NDVI (self): self.Dat.NDVI(self.Dat.BandsArrays[4], self.Dat.BandsArrays[7]) Cache.remove('kv.image') Cache.remove('kv.texture') self.A_image = Image("TMP.tiff")
def I_IOR (self): self.Dat.IOR(self.Dat.BandsArrays[5], self.Dat.BandsArrays[3], self.Dat.BandsArrays[4]) Cache.remove('kv.image') Cache.remove('kv.texture') self.A_image = Image("TMP.tiff")
def _removeImage(w): Cache.remove('kv.image') Cache.remove('kv.texture') Cache.remove('kv.loader') self.root.remove_widget(w)