def handle_key_key_release(self, event): """ Key release manager for key widget | tk.Event -> None """ #No autocomplete for key widget in put mode if not config.get_mode() == 'put': self.key_autocomplete(event) else: self.key.current_text = self.key.get_contents()
def handle_phrase_tab(self, event): """ Handle tab keypress in Phrase text widget | None -> str """ if config.get_mode() == 'put': if not self.phrase.suggestion_text: self.key.focus() return 'break' self.phrase.handle_tab(event) return 'break' #Interrupt standard tkinter event processing
def handle_phrase_button_release(self, event): self.clear_hints() #Clear hints if active and activate get mode if self.phrase.get_selection(): #If user selected text in phrase box self.key.confirm_suggestion() return elif not config.get_mode() == 'put': self.activate_put_mode() return else: self.phrase.handle_button_release(event)
def set_text(self, language_dict): """ Sets text of all widgets to config settings | None -> None """ self.key_label.config(text=language_dict['key']) self.phrase_label.config(text=language_dict['phrase']) if config.get_mode() == 'get': self.left_button.config(text=language_dict['new']) self.right_button.config(text=language_dict['copy']) else: self.left_button.config(text=language_dict['cancel']) self.right_button.config(text=language_dict['save'])
def handle_key_button_release(self, event): """ Button release manager for key widget | tk.Event -> None When in put mode, switch to get mode if both fields are empty. When in put mode, confirm suggestion before switching focus to key """ self.clear_hints() #Clear hints if active and activate get mode key_contents = self.key.get_contents() phrase_contents = self.phrase.get_contents() if config.get_mode() == 'put': self.phrase.confirm_suggestion() if key_contents == '' == phrase_contents: self.activate_get_mode() #Switch to get mode self.key.handle_button_release(event)
def activate_put_mode(self): """ Sets app to save entry to database | None -> None """ if config.get_mode() == 'put': return language_dict = config.get_language_dict() for item in [self, self.key_label, self.phrase_label]: item.config(bg='#F5FCFF') self.phrase.config( bg='#FFFFFF', borderwidth=2 ) if config.get_show_buttons(): self.left_button.config( text=language_dict['cancel'], ) self.right_button.config( text=language_dict['save'], command=self.save_entry ) self.phrase.focus() self.key.ignore_suggestion() self.phrase.full_clear() config.set_mode('put')
def activate_get_mode(self): """ Sets app to get entry from database | None -> None """ if config.get_mode() == 'get': return language_dict = config.get_language_dict() for item in [self, self.key_label, self.phrase_label]: item.config(bg='#EEEEEE') self.phrase.config( bg='#F5F5F5', borderwidth=3 ) if config.get_show_buttons(): self.left_button.config( text=language_dict['new'], ) self.right_button.config( text=language_dict['copy'], command=self.copy_phrase ) self.key.focus() self.key.full_clear() self.phrase.full_clear() config.set_mode('get')
def __call__(self, environ, start_response): CurrentRequestId.set(None) # Never profile calls to the profiler itself to avoid endless recursion. if (not config.should_profile() or environ.get("PATH_INFO", "").startswith("/gae_mini_profiler/")): app = self.app if self.keep_appstats: app = recording.appstats_wsgi_middleware(app) result = app(environ, start_response) for value in result: yield value else: # Set a random ID for this request so we can look up stats later import base64 CurrentRequestId.set(base64.urlsafe_b64encode(os.urandom(5))) profile_mode = config.get_mode(environ, cookies) # Send request id in headers so jQuery ajax calls can pick # up profiles. def profiled_start_response(status, headers, exc_info = None): if status.startswith("302 "): # Temporary redirect. Add request identifier to redirect location # so next rendered page can show this request's profile. headers = ProfilerWSGIMiddleware.headers_with_modified_redirect(environ, headers) # Access the profiler in closure scope profiler.temporary_redirect = True # Append headers used when displaying profiler results from ajax requests headers.append(("X-MiniProfiler-Id", CurrentRequestId.get())) headers.append(("X-MiniProfiler-QS", str(environ.get("QUERY_STRING")))) headers.append(("Set-Cookie", cookies.set_cookie_value("g-m-p-mode", profile_mode, path="/"))) return start_response(status, headers, exc_info) # As a simple form of rate-limiting, appstats protects all # its work with a memcache lock to ensure that only one # appstats request ever runs at a time, across all # appengine instances. (GvR confirmed this is the purpose # of the lock). So our attempt to profile will fail if # appstats is running on another instance. Boo-urns! We # just turn off the lock-checking for us, which means we # don't rate-limit quite as much with the mini-profiler as # we would do without. old_memcache_add = memcache.add old_memcache_delete = memcache.delete memcache.add = (lambda key, *args, **kwargs: (True if key == recording.lock_key() else old_memcache_add(key, *args, **kwargs))) memcache.delete = (lambda key, *args, **kwargs: (True if key == recording.lock_key() else old_memcache_delete(key, *args, **kwargs))) try: profiler = RequestProfiler(CurrentRequestId.get(), profile_mode) result = profiler.profile_start_response(self.app, environ, profiled_start_response) for value in result: yield value finally: CurrentRequestId.set(None) memcache.add = old_memcache_add memcache.delete = old_memcache_delete
def __call__(self, environ, start_response): CurrentRequestId.set(None) # Never profile calls to the profiler itself to avoid endless recursion. if (not config.should_profile() or environ.get( "PATH_INFO", "").startswith("/gae_mini_profiler/")): app = self.app if self.keep_appstats: app = recording.appstats_wsgi_middleware(app) result = app(environ, start_response) for value in result: yield value else: # Set a random ID for this request so we can look up stats later import base64 CurrentRequestId.set(base64.urlsafe_b64encode(os.urandom(5))) profile_mode = config.get_mode(environ, cookies) # Send request id in headers so jQuery ajax calls can pick # up profiles. def profiled_start_response(status, headers, exc_info=None): if status.startswith("302 "): # Temporary redirect. Add request identifier to redirect location # so next rendered page can show this request's profile. headers = ProfilerWSGIMiddleware.headers_with_modified_redirect( environ, headers) # Access the profiler in closure scope profiler.temporary_redirect = True # Append headers used when displaying profiler results from ajax requests headers.append(("X-MiniProfiler-Id", CurrentRequestId.get())) headers.append( ("X-MiniProfiler-QS", str(environ.get("QUERY_STRING")))) headers.append(("Set-Cookie", cookies.set_cookie_value("g-m-p-mode", profile_mode, path="/"))) return start_response(status, headers, exc_info) # As a simple form of rate-limiting, appstats protects all # its work with a memcache lock to ensure that only one # appstats request ever runs at a time, across all # appengine instances. (GvR confirmed this is the purpose # of the lock). So our attempt to profile will fail if # appstats is running on another instance. Boo-urns! We # just turn off the lock-checking for us, which means we # don't rate-limit quite as much with the mini-profiler as # we would do without. old_memcache_add = memcache.add old_memcache_delete = memcache.delete memcache.add = (lambda key, *args, **kwargs: (True if key == recording.lock_key() else old_memcache_add(key, *args, **kwargs))) memcache.delete = (lambda key, *args, **kwargs: (True if key == recording.lock_key() else old_memcache_delete(key, *args, **kwargs))) try: profiler = RequestProfiler(CurrentRequestId.get(), profile_mode) result = profiler.profile_start_response( self.app, environ, profiled_start_response) for value in result: yield value finally: CurrentRequestId.set(None) memcache.add = old_memcache_add memcache.delete = old_memcache_delete
def clear_hints(self): """ Clear hints and switch to get mode | None -> None """ print(f'clear hints if {config.get_mode() == "hint"}') if config.get_mode() == 'hint': self.activate_get_mode()