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()
class Controller: def __init__(self, root): self.db_manager = DBManager() self.db_manager.setFactorySource("Mongo") self.mainView = MainView(root) self.mainView.init_view() self.config_upper_panel_btns() self.init_controllers() self.homeController.show_view() def config_upper_panel_btns(self): self.mainView.btnHome.config(command=self.on_home_request) self.mainView.btnSrc.config(command=self.on_sources_request) self.mainView.btnStats.config(command=self.on_stats_request) def init_controllers(self): self.homeController = HomeController(self.mainView, self) self.srcController = SourceController(self.mainView, self) self.currentController = self.homeController def on_home_request(self): if self.currentController != self.homeController: self.currentController.hide_view() self.currentController = self.homeController self.homeController.show_view() def on_sources_request(self): if self.currentController != self.srcController: self.currentController.hide_view() self.currentController = self.srcController self.srcController.show_view() def on_stats_request(self): return True
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()
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 __init__(self, root): self.db_manager = DBManager() self.db_manager.setFactorySource("Mongo") self.mainView = MainView(root) self.mainView.init_view() self.config_upper_panel_btns() self.init_controllers() self.homeController.show_view()
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()
class SourcesAddController: def __init__(self, master_view, master_controller): self.parentView = master_view self.parentController = master_controller self.view = SourceAddView(master_view) self.source = ScrapingSource(None, None) self.db_manager = DBManager() def show_view(self): self.view = SourceAddView(self.parentView) self.view.init_view() self.view.btnAccept.config(command=self.on_accept_request) self.view.btnDecline.config(command=self.on_decline_request) self.view.btnAddFilter.config(command=self.on_add_filter_request) def on_accept_request(self): self.source.name = self.view.source_name.get("1.0", "end-1c") self.source.url = self.view.source_url.get("1.0", "end-1c") self.db_manager.insert_item("sources", self.source) self.parentController.on_hide_add_view_from_add() def on_decline_request(self): self.parentController.on_hide_add_view_from_cancel() def on_add_filter_request(self): result = self.view.filterResult.get() #html_tag = self.view.filter_tag.get("1.0", "end-1c") name = self.view.filterReference.get("1.0", "end-1c") value = self.view.filterValue.get("1.0", "end-1c") self.source.filters.append(SourceFilter(result, None, name, value)) #self.view.add_filter_item(SourceFilter(result, name, value)) self.view.update_filters_list(self.source.filters) def on_update_request(self): self.source.name = self.view.source_name.get("1.0", "end-1c") self.source.url = self.view.source_url.get("1.0", "end-1c") self.db_manager.update_item("sources", self.source) self.parentController.on_hide_add_view_from_add() def on_update_view(self, source): self.show_view() self.view.btnAccept.config(command=self.on_update_request) self.source.filters = source.filters self.view.update_view(source.name, source.url, source.filters)
def __init__(self, master_view, master_controller): self.parentView = master_view self.parentController = master_controller self.view = SourceAddView(master_view) self.source = ScrapingSource(None, None) self.db_manager = DBManager()