Example #1
0
class HomeController:
    def __init__(self, master_view, master_controller):
        self.view = HomeView(master_view)
        self.items = []
        self.parentView = master_view
        self.parentController = master_controller
        self.db_manager = DBManager()
        print()

    def show_view(self):
        self.view = HomeView(self.parentView)
        self.view.init_frame()
        self.view.btnSearch.config(command=self.on_search_request)
        if len(self.db_manager.get_sources()) == 0:
            self.db_manager.get_items("sources")
        self.view.update_src_items(self.db_manager.sources)
        self.get_news_items()

    def hide_view(self):
        self.view.destroy_view()

    def get_news_items(self):
        items = []
        if len(self.db_manager.sources) > 0:
            print()
            #items = SourceManager.get_data(self.db_manager.instance.sources[0])
        self.view.update_news_items(items)

    def on_search_request(self):
        print(self.view.searchInput)

    def on_toggle_source(self):
        print()
class SourceController:
    def __init__(self, master_view, master_controller):
        self.parentController = master_controller
        self.parentView = master_view
        self.view = SourcesView(master_view)
        self.db_manager = DBManager()
        self.addController = SourcesAddController(self.view.data_container,
                                                  self)

    def show_view(self):
        self.view = SourcesView(self.parentView)
        self.view.init_view()
        self.view.btnAdd.config(command=self.on_add_view_request)
        if len(self.db_manager.instance.sources) == 0:
            self.db_manager.get_items("sources")

        self.view.update_src_items(self.db_manager.instance.sources)
        self.view.set_list_listener(self.on_update_source_request,
                                    self.on_delete_source_request)

    def hide_view(self):
        self.view.destroy()

    def on_update_source_request(self, index):
        self.db_manager.instance.aux_old_item = self.db_manager.instance.sources[
            index]
        self.on_add_view_request()
        self.addController.on_update_view(
            self.db_manager.instance.aux_old_item)

    def on_delete_source_request(self, index):
        self.db_manager.delete_item("sources",
                                    self.db_manager.instance.sources[index])
        self.on_hide_add_view_from_add()

    def on_add_view_request(self):
        self.view.hide_data_container()
        self.addController = SourcesAddController(self.view.aux_container,
                                                  self)
        self.addController.show_view()

    def on_hide_add_view_from_add(self):
        self.db_manager.instance.sources = []
        self.show_view()

    def on_hide_add_view_from_cancel(self):
        self.show_view()