class StringPreviewWidget(object): """Widget for testing Logbook strings. It provides a list of scenarios, of which the user can select one and display its strings in a logbook""" def __init__(self, session): self._init_gui(session) # allow for misc delayed initialization to finish before pausing Scheduler().add_new_object(session.speed_pause, self, 2) def show(self): self._gui.show() def _init_gui(self, session): self._gui = load_uh_widget("stringpreviewwidget.xml") self._gui.mapEvents({ 'load' : self.load }) self.scenarios = SavegameManager.get_scenarios() self.listbox = self._gui.findChild(name="scenario_list") self.listbox.items = self.scenarios[1] self.listbox.capture(self.update_infos) self.statslabel = self._gui.findChild(name="stats") self.logbook = LogBook(session) def update_infos(self): """Updates the status label while scrolling the scenario list. No up- date to logbook messages. Those are loaded after Load/Reload is clicked. """ scenario_file_path = self.scenarios[0][self.listbox.selected] data = YamlCache.load_yaml_data(open(scenario_file_path, 'r')) stats = data.get('translation_status', '') # no stats available => empty label self.statslabel.text = unicode(stats) def load(self): """Load selected scenario and show strings""" if self.listbox.selected == -1: self._gui.findChild(name="hintlbl").text = u"Select a scenario first." else: self._gui.findChild(name="hintlbl").text = u"" # remember current entry cur_entry = self.logbook.get_cur_entry() cur_entry = cur_entry if cur_entry is not None else 0 self.logbook.clear() # get logbook actions from scenario file and add them to our logbook scenario_file_path = self.scenarios[0][self.listbox.selected] data = YamlCache.load_yaml_data(open(scenario_file_path, 'r')) events = data['events'] for event in events: for action in event['actions']: if action['type'] in ('logbook', 'logbook'): self.logbook.add_captainslog_entry(action['arguments'], show_logbook=False) try: self.logbook.set_cur_entry(cur_entry) except ValueError: pass # no entries self.logbook._redraw_captainslog() self.logbook.show()
class StringPreviewWidget(object): """Widget for testing Logbook strings. It provides a list of scenarios, of which the user can select one and display its strings in a logbook""" def __init__(self, session): self._init_gui(session) # allow for misc delayed initialisation to finish before pausing Scheduler().add_new_object(session.speed_pause, self, 2) def show(self): self._gui.show() def _init_gui(self, session): self._gui = load_uh_widget("stringpreviewwidget.xml") self._gui.mapEvents({ 'load' : self.load }) self.scenarios = SavegameManager.get_scenarios() self.listbox = self._gui.findChild(name="scenario_list") self.listbox.items = self.scenarios[1] self.logbook = LogBook(session) def load(self): """Load selected scenario and show strings""" if self.listbox.selected == -1: self._gui.findChild(name="hintlbl").text = u"you need to select sth in the list above" else: self._gui.findChild(name="hintlbl").text = u"" # remember current entry cur_entry = self.logbook.get_cur_entry() cur_entry = cur_entry if cur_entry is not None else 0 self.logbook.clear() # get logbook actions from scenario file and add them to our logbook scenario_file_path = self.scenarios[0][self.listbox.selected] data = yaml.load(open(scenario_file_path, 'r')) events = data['events'] for event in events: for action in event['actions']: if action['type'] in ('logbook', 'logbook_w'): head= action['arguments'][0] msg = action['arguments'][1] self.logbook.add_entry(unicode(head), unicode(msg), show_logbook=False) try: self.logbook.set_cur_entry(cur_entry) except ValueError: pass # no entries self.logbook._redraw() self.logbook.show()
class StringPreviewWidget(object): """Widget for testing Logbook strings. It provides a list of scenarios, of which the user can select one and display its strings in a logbook""" def __init__(self): self._init_gui() def show(self): self._gui.show() def _init_gui(self): self._gui = load_xml_translated("stringpreviewwidget.xml") self._gui.mapEvents({ 'load' : self.load }) self.scenarios = SavegameManager.get_scenarios() self.listbox = self._gui.findChild(name="scenario_list") self.listbox.items = self.scenarios[1] self.logbook = LogBook() def load(self): """Load selected scenario and show strings""" if self.listbox.selected == -1: self._gui.findChild(name="hintlbl").text = u"you need to select sth in the list above" else: self._gui.findChild(name="hintlbl").text = u"" # remember current entry cur_entry = self.logbook.get_cur_entry() cur_entry = cur_entry if cur_entry is not None else 0 self.logbook.clear() # get logbook actions from scenario file and add them to our logbook scenario_file_path = self.scenarios[0][self.listbox.selected] data = yaml.load(open(scenario_file_path, 'r')) events = data['events'] for event in events: for action in event['actions']: if action['type'] in ('logbook', 'logbook_w'): head= action['arguments'][0] msg = action['arguments'][1] self.logbook.add_entry(unicode(head), unicode(msg), show_logbook=False) self.logbook.set_cur_entry(cur_entry) self.logbook._redraw() self.logbook.show()
class StringPreviewWidget(Window): """Widget for testing Logbook strings. It provides a list of scenarios, of which the user can select one and display its strings in a logbook""" def __init__(self, session): super().__init__() self._init_gui(session) # allow for misc delayed initialization to finish before pausing Scheduler().add_new_object(session.speed_pause, self, 2) def show(self): self._gui.show() def _init_gui(self, session): self._gui = load_uh_widget("stringpreviewwidget.xml") self._gui.mapEvents({'load': self.load}) self.scenarios = SavegameManager.get_scenarios() self.listbox = self._gui.findChild(name="scenario_list") self.listbox.items = self.scenarios[1] self.listbox.distributeData({'scenario_list': 0}) self.listbox.capture(self.update_infos) self.statslabel = self._gui.findChild(name="stats") self.windows = WindowManager() self.logbook = LogBook(session, self.windows) self.logbook._gui.mapEvents({ OkButton.DEFAULT_NAME: self.logbook.hide, }) self.update_infos() def update_infos(self): """Updates the status label while scrolling the scenario list. No up- date to logbook messages. Those are loaded after Load/Reload is clicked. """ scenario_file_path = self.scenarios[0][self.listbox.selected] data = YamlCache.load_yaml_data(open(scenario_file_path, 'r')) if 'metadata' in data: # no stats available => empty label stats = data['metadata'].get('translation_status', '') else: # Old scenario syntax version without metadata stats = data.get('translation_status', '') self.statslabel.text = str(stats) def load(self): """Load selected scenario and show strings""" # remember current entry cur_entry = self.logbook.get_cur_entry() cur_entry = cur_entry if cur_entry is not None else 0 self.logbook.clear() # get logbook actions from scenario file and add them to our logbook scenario_file_path = self.scenarios[0][self.listbox.selected] data = YamlCache.load_yaml_data(open(scenario_file_path, 'r')) events = data['events'] for event in events: for action in event['actions']: if action['type'] in ('logbook', 'logbook'): self.logbook.add_captainslog_entry(action['arguments'], show_logbook=False) try: self.logbook.set_cur_entry(cur_entry) except ValueError: pass # no entries self.logbook._redraw_captainslog() self.logbook.show()
class StringPreviewWidget(Window): """Widget for testing Logbook strings. It provides a list of scenarios, of which the user can select one and display its strings in a logbook""" def __init__(self, session): super(StringPreviewWidget, self).__init__() self._init_gui(session) # allow for misc delayed initialization to finish before pausing Scheduler().add_new_object(session.speed_pause, self, 2) def show(self): self._gui.show() def _init_gui(self, session): self._gui = load_uh_widget("stringpreviewwidget.xml") self._gui.mapEvents({"load": self.load}) self.scenarios = SavegameManager.get_scenarios() self.listbox = self._gui.findChild(name="scenario_list") self.listbox.items = self.scenarios[1] self.listbox.distributeData({"scenario_list": 0}) self.listbox.capture(self.update_infos) self.statslabel = self._gui.findChild(name="stats") self.windows = WindowManager() self.logbook = LogBook(session, self.windows) self.logbook._gui.mapEvents({OkButton.DEFAULT_NAME: self.logbook.hide}) self.update_infos() def update_infos(self): """Updates the status label while scrolling the scenario list. No up- date to logbook messages. Those are loaded after Load/Reload is clicked. """ scenario_file_path = self.scenarios[0][self.listbox.selected] data = YamlCache.load_yaml_data(open(scenario_file_path, "r")) stats = data.get("translation_status", "") # no stats available => empty label self.statslabel.text = unicode(stats) def load(self): """Load selected scenario and show strings""" # remember current entry cur_entry = self.logbook.get_cur_entry() cur_entry = cur_entry if cur_entry is not None else 0 self.logbook.clear() # get logbook actions from scenario file and add them to our logbook scenario_file_path = self.scenarios[0][self.listbox.selected] data = YamlCache.load_yaml_data(open(scenario_file_path, "r")) events = data["events"] for event in events: for action in event["actions"]: if action["type"] in ("logbook", "logbook"): self.logbook.add_captainslog_entry(action["arguments"], show_logbook=False) try: self.logbook.set_cur_entry(cur_entry) except ValueError: pass # no entries self.logbook._redraw_captainslog() self.logbook.show()