""" WorkshopController This module handles user action from the workshop view """ import logging from WorkshopModel import Tutorial class WorkshopController(): def __init__(self,view,model): self.view = view self.model = model def tutorial_query(self,widget,keyword): """ Handles query from the view @param widget the widget that sent the query @param keyword the keyword for the query, empty to get all tutorials """ self.model.query([keyword.get_text()]) def sort_selection_changed(self,widget,data): """ Handles selection changes in the sorting selection @param widget the widget that sent the query @param sort the property to use to sort tutorial """ sorting = widget.get_active_text() self.view.change_sorting(sorting) def launch_tutorial(self,widget,tutorial): """ Handles start tutorial action @param widget the widget that triggered the action @param tutorial the tutorial to launch """ self.model.launch_tutorial(tutorial) def show_details(self,widget,tutorial): """ show the details for a tutorial @param widget the widget that made the call @param tutorial the tutorial to """ self.view.display_detail(tutorial) def back_pressed(self,widget,data): """ When in detail view, go back to general view @param widget the widget that made the call @param data not used """ self.view.display_main_view() def rate_tutorial(self,tutorial,rating): """ Change the rating for a tutorial @param tutorial The tutorial to rate @param rating The new rating """ self.model.rate_tutorial(tutorial,rating) def edit_tutorial(self,widget,tutorial): """ Edit the tutorial in the detail view @param widget the widget that made the call @param tutorial the tutorial to edit """ self.model.edit_tutorial(tutorial) def update_tutorial(self,widget,tutorial): """ Need to know what this do """ pass def info_tutorial(self,widget,tutorial): """ Edit the infos about the tutorial @param widget the widget that made the call @param tutorial the tutorial to edit """ self.view.display_info_dialog(tutorial) def save_tutorial_info(self,tutorial): """ Save the metadata of a tutorial @param tutorial The tutorial to update containing the new metadata """ self.model.save_metadata(tutorial) def delete_tutorial(self,widget,tutorial): """ Delete a tutorial @param widget the widget that made the call @param tutorial the tutorial to delete """ self.model.delete_tutorial(tutorial) def publish_tutorial(self,widget,tutorial): """ Publish a tutorial @param widget the widget that made the call @param tutorial the tutorial to publish """ self.model.publish_tutorial(tutorial) def unpublish_tutorial(self,widget,tutorial): """ Unpublish a tutorial @param widget the widget that made the call @param tutorial the tutorial to unpublish """ self.model.unpublish_tutorial(tutorial) def get_categories(self): self.model.get_categories_for_workshop() class StoreController(): def __init__(self,view,model): self.view = view self.model = model self.last_call_search = None self.last_call_keyword = None self.last_call_cat = None def show_details(self,widget,tutorial): self.view.show_details(tutorial) def get_categories(self): self.last_call_search = False self.model.get_categories() def search_store(self,widget,data): cat = data["category"].get_active_text() keyword = data["keyword"].get_text() if cat is None or cat == "": cat = 'all' self.model.search_store(keyword,cat) self.last_call_search = True self.last_call_keyword = keyword self.last_call_cat = cat self.last_call_page = 1 def get_tutorials_by_category(self,widget,category): self.model.get_tutorials_by_category(category) self.last_call_search = False self.last_call_cat = category self.last_call_page = 1 def download_tutorial(self,widget,tutorial): self.model.download_tutorial(tutorial) def get_also_like(self): self.model.get_also_like() def get_popular(self): self.model.get_popular() def display_infos(self,widget,tutorial): self.view.display_infos(tutorial) def next_page(self,widget,data): self.last_call_page = self.last_call_page + 1 if self.last_call_search: self.model.search_store(self.last_call_keyword,self.last_call_cat,page = self.last_call_page ) else: self.model.get_tutorials_by_category(self.last_call_cat,page = self.last_call_page ) def prev_page(self,widget,data): self.last_call_page = self.last_call_page - 1 if self.last_call_search: self.model.search_store(self.last_call_keyword,self.last_call_cat,page = self.last_call_page ) else: self.model.get_tutorials_by_category(self.last_call_cat,page = self.last_call_page ) def back_pressed(self,widget,data): self.view.show_search_result() def rate_tutorial(self,tutorial,rating): """ Change the rating for a tutorial @param tutorial The tutorial to rate @param rating The new rating """ self.model.rate_tutorial(tutorial,rating)