class TaskController(): def __init__(self, master, model): if not master or not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") self.__view = TaskView(master) self.__model = model self.__model.set_callback_title(self.title_callback) self.__view.update_title(self.__model.get_title()) self.__view.toggle_button.config(command=self.__model.toggle) self.__view.delete_button.config(command=self.task_delete) self.__view.add_button.config(command=self.task_add) for item in self.__model.tasks: self.__view.listbox.insert(tk.END, item) def task_add(self): task = self.__view.entry.get() self.__view.listbox.insert(tk.END, task) self.__model.add_task(task) def task_delete(self): indexes = list(self.__view.listbox.curselection()) indexes.sort(reverse=True) for index in indexes: self.__model.delete_task(index) self.__view.listbox.delete(index) def title_callback(self): # callback should run update_title from view with model.title self.__view.update_title(self.__model.get_title())
class TaskController(): # Constructor def __init__(self, master, model): ''' if self.master != tk.Tk(): Exception("master is not a tk.Tk()") ''' if isinstance(model, TaskModel) == False: Exception("model is not a TaskModel") self.__model = model # Creates the view self.__view = TaskView(master) # Link View Elements to Controller self.__view.toggle_button.config(command=self.reverse_string) self.title_change(self.__model.get_title()) # Action to Model from View elements def reverse_string(self): self.__model.set_callback_title(self.title_change) self.__model.toggle() # Updates View from Model def title_change(self, title): self.__view.update_title(title)
class TaskController(): """Links all callbacks from model to update view and links the button of view to update model. Keyword arguments: master -- A Tk constructor. model -- A TaskModel class. """ def __init__(self, master, model): if isinstance(master, tk.Tk) == False: raise Exception("master is not a tk.Tk()") if isinstance(model, TaskModel) == False: raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) self.__model.set_callback_title(self.callback) self.__view.toggle_button.config(command=self.__model.toggle) def callback(self, value): """Set the callback of the model to return updated title to View.""" self.__view.update_title(self.__model.get_title()) return value
def __init__(self, master, model): if not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") if not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) self.__model.set_callback_title(self.__view.update_title) self.__view.toggle_button.config(command=self.__model.toggle)
class TaskController(): def __init__(self, master, model): if not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") if not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) self.__model.set_callback_title(self.__view.update_title) self.__view.toggle_button.config(command=self.__model.toggle)
class Root(QMainWindow): task_list_index = 0 task_view_index = 1 def __init__(self): super().__init__() self.model = None self.task_view = None self.initUI() def initUI(self): # self.cal = QCalendarWidget(self) # self.cal.setVerticalHeaderFormat(QCalendarWidget.NoVerticalHeader) # self.cal.setGeometry(0, 0, 250, 250) self.model = TaskModel() self.central = QStackedWidget() task_list = TaskList(self.model) task_list.open.connect(self.task_open) self.central.insertWidget(Root.task_list_index, task_list) self.task_view = TaskView(self.model) self.task_view.close.connect(self.task_view_close) self.central.insertWidget(Root.task_view_index, self.task_view) self.central.setCurrentIndex(Root.task_list_index) self.setCentralWidget(self.central) # QDialog flags: # Qt.Dialog | # Qt.WindowTitleHint | # Qt.WindowSystemMenuHint | # Qt.WindowContextHelpButtonHint | # Qt.WindowCloseButtonHint self.setWindowFlags(Qt.Dialog | Qt.WindowStaysOnTopHint) self.setGeometry(700, 300, 250, 300) self.setWindowTitle('Calendar') @pyqtSlot(int) def task_open(self, index): self.task_view.set_task(index) self.central.setCurrentIndex(Root.task_view_index) @pyqtSlot() def task_view_close(self): self.central.setCurrentIndex(Root.task_list_index) def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.close()
def __init__(self, master, model): if master.__class__.__name__ != "Tk": raise Exception("master is not a tk.Tk()") if not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) ''' Update the TaskView to show the string currently represented by the TaskModel ''' self.__view.update_title(model) ''' When the button is clicked, we want it to also update the view's label ''' self.__model.set_callback_title(self.__view.update_title) self.__view.toggle_button.config(command=self.__model.toggle)
class TaskController(): """docstring for TaskController""" def __init__(self, master, model): # Basic init stuff if not master or not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") if not model or not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) # connecting all the dots. self.__view.update_title(self.__model.get_title()) self.__model.set_callback_title(self.__view.update_title) self.__view.toggle_button.config(command=self.__model.toggle)
class TaskController(): """TaskController Class definition""" #TaskController Constructor: def __init__(self, master, model): if not master or not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") if not TaskModel or not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") #Private attributes: self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) self.__model.set_callback_title(self.__view.update_title) self.__view.toggle_button.config(command=self.__model.toggle)
class TaskController(): def __init__(self, master, model): if not master or not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") self.__view = TaskView(master) self.__model = model self.__model.set_callback_title(self.title_callback) self.__view.update_title(self.__model.get_title()) self.__view.toggle_button.config(command=self.__model.toggle) def title_callback(self): # callback should run update_title from view with model.title self.__view.update_title(self.__model.get_title())
def initUI(self): # self.cal = QCalendarWidget(self) # self.cal.setVerticalHeaderFormat(QCalendarWidget.NoVerticalHeader) # self.cal.setGeometry(0, 0, 250, 250) self.model = TaskModel() self.central = QStackedWidget() task_list = TaskList(self.model) task_list.open.connect(self.task_open) self.central.insertWidget(Root.task_list_index, task_list) self.task_view = TaskView(self.model) self.task_view.close.connect(self.task_view_close) self.central.insertWidget(Root.task_view_index, self.task_view) self.central.setCurrentIndex(Root.task_list_index) self.setCentralWidget(self.central) # QDialog flags: # Qt.Dialog | # Qt.WindowTitleHint | # Qt.WindowSystemMenuHint | # Qt.WindowContextHelpButtonHint | # Qt.WindowCloseButtonHint self.setWindowFlags(Qt.Dialog | Qt.WindowStaysOnTopHint) self.setGeometry(700, 300, 250, 300) self.setWindowTitle('Calendar')
class TaskController: def __init__(self, master, model): if master.__class__.__name__ != "Tk": raise Exception("master is not a tk.Tk()") if not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) ''' Update the TaskView to show the string currently represented by the TaskModel ''' self.__view.update_title(model) ''' When the button is clicked, we want it to also update the view's label ''' self.__model.set_callback_title(self.__view.update_title) self.__view.toggle_button.config(command = self.__model.toggle)
def __init__(self, master, model): if isinstance(master, tk.Tk) == False: raise Exception("master is not a tk.Tk()") if isinstance(model, TaskModel) == False: raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) for i in self.__model.load_from_file('task.json'): self.__view.insert(i['task']) self.__model.set_callback_title(self.callback) self.__view.toggle_button.config(command=self.__model.toggle) self.__view.add_button.config(command=self.add_item) self.__view.remove_button.config(command=self.remove_item)
def __init__(self, master, model): if not master or not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") self.__view = TaskView(master) self.__model = model self.__model.set_callback_title(self.title_callback) self.__view.update_title(self.__model.get_title()) self.__view.toggle_button.config(command=self.__model.toggle)
def __init__(self, master, model): # raise exceptions if isinstance(master, tk.Tk) == False: raise Exception("master is not a tk.Tk()") if isinstance(model, TaskModel) == False: raise Exception("model is not a TaskModel") # set private attributes self.__model = model self.__view = TaskView(master) self.__view.update_title( self.__model.get_title()) # set title for view according to model # link all callbacks from model to update view self.__model.set_callback_title(self.__view.update_title) # self.__view.update_title(self.__model.get_title()) # link view button to update model (link model callback to view) self.__view.toggle_button.configure(command=self.__model.toggle)
def __init__(self, master, model): if not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") if not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") # private attributes self.__model = model # create the view self.__view = TaskView(master) # link view elements with controller self.__view.toggle_button.config(command=self.reverse_string) self.title_change(self.__model.get_title())
class TaskController: # define constructor def __init__(self, master, model): # raise exceptions if isinstance(master, tk.Tk) == False: raise Exception("master is not a tk.Tk()") if isinstance(model, TaskModel) == False: raise Exception("model is not a TaskModel") # set private attributes self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) # set title for view according to model # link all callbacks from model to update view self.__model.set_callback_title(self.__view.update_title) # self.__view.update_title(self.__model.get_title()) # link view button to update model (link model callback to view) self.__view.toggle_button.configure(command=self.__model.toggle)
class TaskController: ''' Constructor ''' def __init__(self, master, model): if master.__class__.__name__ != "Tk": raise Exception("master is not a tk.TK()") if not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) ''' Update taskview ''' self.__view.update_title(model) ''' Link all callbacks from model to update view ''' self.__model.set_callback_title(self.__view.update_title) ''' Link the button of view to update model ''' self.__view.toggle_button.config(command = self.__model.toggle)
class TaskController: # Constructor def __init__(self, master, model): # Private attributes self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) # If master is not tk Class, raise exception if isinstance(master, tk.Tk) == False: raise Exception("master is not a tk.Tk()") # If model is not TaskModel class, raise exception if isinstance(model, TaskModel) == False: raise Exception("model is not a TaskModel") # Link all callbacks from model to update view self.__model.set_callback_title(self.__view.update_title) # link the button of view to update model self.__view.toggle_button.configure(command=self.__model.toggle)
class TaskController(): """ Constructor """ def __init__(self, master, model): if not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") if not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") # private attributes self.__model = model # create the view self.__view = TaskView(master) # link view elements with controller self.__view.toggle_button.config(command=self.reverse_string) self.title_change(self.__model.get_title()) # model from view elements def reverse_string(self): self.__model.set_callback_title(self.title_change) self.__model.toggle() # update view from model def title_change(self, title): self.__view.update_title(title)
def __init__(self, master, model): ''' if self.master != tk.Tk(): Exception("master is not a tk.Tk()") ''' if isinstance(model, TaskModel) == False: Exception("model is not a TaskModel") self.__model = model # Creates the view self.__view = TaskView(master) # Link View Elements to Controller self.__view.toggle_button.config(command=self.reverse_string) self.title_change(self.__model.get_title())
def __init__(self, master, model): if not master or not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") self.__view = TaskView(master) self.__model = model self.__model.set_callback_title(self.title_callback) self.__view.update_title(self.__model.get_title()) self.__view.toggle_button.config(command=self.__model.toggle) self.__view.delete_button.config(command=self.task_delete) self.__view.add_button.config(command=self.task_add) for item in self.__model.tasks: self.__view.listbox.insert(tk.END, item)
class TaskController: def __init__(self, master, model): if not isinstance(master, tk.Tk): raise Exception("master is not a tk.Tk()") if not isinstance(model, TaskModel): raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) self.__model.set_callback_title(self.__view.update_title) self.__view.toggle_button.config(command=self.__model.toggle) self.__view.display_tasks(self.__model.get_tasks()) self.__model.set_callback_add_task(self.__view.add_task) self.__view.set_callback_add_task(self.__model.add_task) self.__view.add_entry.bind("<Return>", self.__view.set_task) self.__view.set_callback_remove_task(self.__model.remove_task) self.__view.remove_button.config(command=self.__view.remove_task)
class TaskController(): """Links all callbacks from model to update view and links the button of view to update model. Keyword arguments: master -- A Tk constructor. model -- A TaskModel class. """ def __init__(self, master, model): if isinstance(master, tk.Tk) == False: raise Exception("master is not a tk.Tk()") if isinstance(model, TaskModel) == False: raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) for i in self.__model.load_from_file('task.json'): self.__view.insert(i['task']) self.__model.set_callback_title(self.callback) self.__view.toggle_button.config(command=self.__model.toggle) self.__view.add_button.config(command=self.add_item) self.__view.remove_button.config(command=self.remove_item) def add_item(self): """Add the item to the JSON file.""" self.__model.add_item(self.__view.e.get()) for i in self.__model.load_from_file('task.json'): if i['id'] == (len(self.__model.load_from_file('task.json')) - 1): self.__view.insert(i['task']) def remove_item(self): """Remove the item from the JSON file.""" self.__model.remove_item() if len(self.__model.load_from_file('task.json')) == 0: self.__view.delete(0) else: for i in self.__model.load_from_file('task.json'): self.__view.delete( len(self.__model.load_from_file('task.json'))) def callback(self, value): """Set the callback of the model to return updated title to View.""" self.__view.update_title(self.__model.get_title()) return value
class TaskController(): """Links all callbacks from model to update view and links the button of view to update model. Keyword arguments: master -- A Tk constructor. model -- A TaskModel class. """ def __init__(self, master, model): if isinstance(master, tk.Tk) == False: raise Exception("master is not a tk.Tk()") if isinstance(model, TaskModel) == False: raise Exception("model is not a TaskModel") self.__model = model self.__view = TaskView(master) self.__view.update_title(self.__model.get_title()) for i in self.__model.load_from_file('task.json'): self.__view.insert(i['task']) self.__model.set_callback_title(self.callback) self.__view.toggle_button.config(command=self.__model.toggle) self.__view.add_button.config(command=self.add_item) self.__view.remove_button.config(command=self.remove_item) def add_item(self): """Add the item to the JSON file.""" self.__model.add_item(self.__view.e.get()) for i in self.__model.load_from_file('task.json'): if i['id'] == (len(self.__model.load_from_file('task.json')) - 1): self.__view.insert(i['task']) def remove_item(self): """Remove the item from the JSON file.""" self.__model.remove_item() if len(self.__model.load_from_file('task.json')) == 0: self.__view.delete(0) else: for i in self.__model.load_from_file('task.json'): self.__view.delete(len(self.__model.load_from_file('task.json'))) def callback(self, value): """Set the callback of the model to return updated title to View.""" self.__view.update_title(self.__model.get_title()) return value
@app.route('/logs') def logs(): return send_file(app.config['LOG_FILENAME'], mimetype='text/plain') @app.route('/currency/<path:date>') def currency(date): try: date = datetime.strptime(date, date_format) price = get_currency_price(date) if price is None: abort(404) return respond(CurrencyResponse(price, date)) except ValueError: abort(400) except HTTPError: abort(502) task_view = TaskView.as_view('tasks') app.add_url_rule('/tasks', defaults={'task_id': None}, view_func=task_view, methods=['GET'], endpoint='tasks') app.add_url_rule('/tasks', view_func=task_view, methods=['PUT'], endpoint='add_task') app.add_url_rule('/tasks/<int:task_id>', view_func=task_view, methods=['GET', 'POST', 'DELETE'], endpoint='task') if __name__ == '__main__': app.run(host=app.config['HOST'], debug=app.config['DEBUG'], port=app.config['PORT'])
import Tkinter as tk from task_model import TaskModel from task_view import TaskView root = tk.Tk() root.withdraw() tv = TaskView(root) tv.update_title("Finish this funny project") root.mainloop()