예제 #1
0
    def load_guide(archive):
        """ Loads guide from selected archive.
            On success returns guide list item (data stored in the corresponding 'guide.json' file);
            otherwise returns None. Opens warning popup when guide import fails. """

        guide_name = os.path.splitext(os.path.basename(archive))[0]
        guides_list_item = guides.load_guide(guide_name)
        if guides_list_item is None:
            GuideLoadFailedWarning(archive).open()
            return
        ev.dispatch('on_load_guide', guides_list_item['guide_name'])
예제 #2
0
 def _delete_guides_history_list_item(self, instance, guide_name):
     if self.guides_history_list[-1]['guide_name'] == guide_name:
         if len(self.guides_history_list) > 1:
             guides.set_active_guide(self.guides_history_list[-2]['guide_name'])
         else:
             guides.set_active_guide('')
         del self.guides_history_list[-1]
         ev.dispatch('on_active_guide')
     else:
         item_idx = next(idx for idx, item in enumerate(self.guides_history_list)
                         if item['guide_name'] == guide_name)
         del self.guides_history_list[item_idx]
     ev.dispatch('on_change_guides_list')
예제 #3
0
    def toggle_article_bookmark(self):
        """ Toggle article bookmark in Article model and dispatch an appropriate event. """

        if not self.article_id:
            return
        article = guides.active_guide.article_by_id(self.article_id)
        article_bookmark = article.bookmark()
        if article_bookmark is not None:
            guides.active_guide.delete_bookmark(
                article_bookmark['bookmark_id'])
            ev.dispatch('on_remove_bookmark', self.article_id)
        else:
            guides.active_guide.add_bookmark(self.article_id)
            ev.dispatch('on_add_bookmark', self.article_id)
예제 #4
0
    def pop_screen(self):
        """ Returns identifier for the last visited screen.
            If there is no stored identifier for active guide and there is other guide with screens visited
            during the current application session, the other guide is set as the active one and its
            last visited screen identifier is returned. """

        if not self.guides_history_list:
            return None
        if self.guides_history_list[-1]['visited_screens']:
            active_guide_last_visited_screen = self.guides_history_list[-1]['visited_screens'].pop()
            return active_guide_last_visited_screen
        else:
            prev_guides_history_list_item = self._get_guides_history_list_item_with_last_visited_screen()
            if prev_guides_history_list_item is None:
                return None
            last_visited_screen = prev_guides_history_list_item['visited_screens'].pop()
            guides.set_active_guide(prev_guides_history_list_item['guide_name'])
            ev.dispatch('on_active_guide')
            return last_visited_screen
예제 #5
0
 def _add_guides_history_list_item(self, instance, guide_name):
     self.guides_history_list.insert(0, {'guide_name': guide_name, 'visited_screens': []})
     if len(guides.guides_list) == 1:
         guides.set_active_guide(guide_name)
         ev.dispatch('on_active_guide')
     ev.dispatch('on_change_guides_list')
예제 #6
0
    def change_ui_lang_code(self, active):
        """ Changes application's UI language. """

        if active:
            transl.ui_lang_code = self.lang[1]
            ev.dispatch('on_ui_lang_code', self.lang[1])
예제 #7
0
    def remove_bookmark(self, bookmark_id):
        """ Removes article's bookmark from data model. """

        guides.active_guide.delete_bookmark(bookmark_id)
        ev.dispatch('on_remove_bookmark', self.bookmark_article_id)
예제 #8
0
    def activate_guide(self):
        """ Activate guide upon selecting radio checkbox in the corresponding component view. """

        guides.set_active_guide(self.guide_name)
        ev.dispatch('on_active_guide')
예제 #9
0
    def unload_guide(self):
        """ Unload guide from the application. """

        guides.unload_guide(self.guide_name)
        ev.dispatch('on_unload_guide', self.guide_name)
예제 #10
0
 def activate_guide(self):
     guides.set_active_guide(self.guide_name)
     ev.dispatch('on_active_guide')