Beispiel #1
0
 def select_phrase(self, pattern):
     if pattern not in self.__phrase_binding or get_phrase_appear_ratio() < float(random.randrange(0, 101)):
         self.__phrase_var.set("")
         return
     phrase_arbitrator = Arbitrator()
     for phrase_obj in self.__phrase_binding[pattern]:
         phrase_arbitrator.add_rank(phrase_obj.name, phrase_obj.rank)
     phrase_arbitrator.finalize_rank()
     arbitrated_phase = phrase_arbitrator.arbitrate()
     if not arbitrated_phase:
         self.__phrase_var.set("")
         return
     chosen_phrase_obj = self.__cur_phrase_obj_dict[arbitrated_phase]
     import os
     base_file_name = os.path.basename(self.__cur_graph_file)
     group_name = self.__cur_image_obj_dict[pattern].group_name
     chosen_sentence = chosen_phrase_obj.select_sentence(pattern, group_name, base_file_name)
     if not chosen_sentence:
         self.__phrase_var.set("")
         return
     resolved_sentence = self.get_resolved_sentence(chosen_sentence, pattern, chosen_phrase_obj)
     self.__phrase_var.set(resolved_sentence)
Beispiel #2
0
 def set_general_setting(self):
     lang = get_lang() if not self.__config.has_option("reminder", "lang") else \
         self.__config.get("reminder", "lang")
     if type(lang) is str:
         lang = EN if "EN" == lang else CHT if "CHT" == lang else None
     assert lang is not None
     data_home = get_data_home() if not self.__config.has_option("reminder", "data_location") else \
         self.__config.get("reminder", "data_location")
     slideshow_frequency = get_slideshow_frequency() if not self.__config.has_option("image", "slideshow_frequency") else \
         float(self.__config.get("image", "slideshow_frequency"))
     phrase_appear_ratio = get_phrase_appear_ratio() if not self.__config.has_option("phrase", "ratio") else \
         float(self.__config.get("phrase", "ratio"))
     api_key = get_api_key() if not self.__config.has_option("search", "api_key") else \
         self.__config.get("search", "api_key")
     cx = get_cx() if not self.__config.has_option("search", "cx") else \
         self.__config.get("search", "cx")
     search_latency = get_search_latency() if not self.__config.has_option("search", "search_latency") else \
         float(self.__config.get("search", "search_latency"))
     fullscreen_mode2 = get_fullscreen_mode2() if not self.__config.has_option("reminder", "fullscreen_mode2") else \
         "True" == self.__config.get("reminder", "fullscreen_mode2")
     verbose = get_verbose() if not self.__config.has_option("reminder", "verbose") else \
         "True" == self.__config.get("reminder", "verbose")
     set_lang(lang)
     set_data_home(data_home)
     set_slideshow_frequency(slideshow_frequency)
     set_phrase_appear_ratio(phrase_appear_ratio)
     set_search_latency(search_latency)
     set_api_key(api_key)
     set_cx(cx)
     set_fullscreen_mode2(fullscreen_mode2)
     set_verbose(verbose)
     print("=======  reminder setting  =============")
     print("data home:       ", data_home)
     print("slideshow:       ", slideshow_frequency)
     print("phrase ratio:    ", phrase_appear_ratio)
     print("search latency:  ", search_latency)
     print("api key:         ", api_key if "" != api_key else "None")
     print("cx:              ", cx if "" != cx else "None")
     print("========================================")