From 04f7890c1c4f4a02b65a07b9c91776d0ded46bad Mon Sep 17 00:00:00 2001 From: Genius Date: Mon, 5 Aug 2024 15:06:14 +0500 Subject: [PATCH] Moved Tkinter UI to Webapp using flask. Fixes #72 Modernised UI with bootstrap. Fixes #101 --- organise_desktop/Clean.py | 133 ++++++++++++++++---------- organise_desktop/templates/index.html | 45 +++++++++ 2 files changed, 129 insertions(+), 49 deletions(-) create mode 100644 organise_desktop/templates/index.html diff --git a/organise_desktop/Clean.py b/organise_desktop/Clean.py index b5aaa69..3e7933f 100644 --- a/organise_desktop/Clean.py +++ b/organise_desktop/Clean.py @@ -1,8 +1,11 @@ import sys import json import os -from cronController import schedule_end, schedule_start -from organiseDesktop import undo, organise_desktop +from cronController import schedule_end, schedule_start +from organiseDesktop import undo as undoo, organise_desktop +from flask import Flask, app, render_template, redirect + +app = Flask(__name__) if sys.version_info >= (3,): from tkinter import * @@ -15,15 +18,33 @@ Extensions = json.load(open(pwd+'/Extension.json', 'r')) folders = [x for x in Extensions] + +@app.route('/undo', methods=['POST']) +def undo(): + undoo() + return redirect('/') + + +@app.route('/schedule-end', methods=['POST']) +def on_schedule_end(): + schedule_end() + return redirect('/') + + class App(Frame): """define the GUI""" - def clean(self): + + @app.route('/clean', methods=['POST']) + def clean(): checked_extensions = {} for x in folders: checked_extensions[x] = Extensions[x] organise_desktop(checked_extensions) - tkMessageBox.showinfo('Complete', 'Desktop clean finished.') + return redirect('/') + # tkMessageBox.showinfo('Complete', 'Desktop clean finished.') + # TODO: Show message box + @app.route('/quit', methods=['POST']) def quit_all(self): sys.exit(0) @@ -34,59 +55,73 @@ def check(self, item): else: folders.append(item) - def on_schedule_start(self): + @app.route('/schedule', methods=['POST']) + def on_schedule_start(): schedule_start(folders) + return redirect('/') + # NOT NEEDED + # def make_checkbutton(self, text): + # cb = Checkbutton(self, text=text, command=lambda: self.check(text)) + # cb.select() + # cb.pack({'side': 'top'}) + # return cb + + # NOT NEEDED + # def make_button(self, text, command): + # btn = Button(self, text=text, command=command) + # btn.pack({'side': 'left'}) + # return btn + + # NOT NEEDED + # def create(self): + # self.winfo_toplevel().title('Desktop Cleaner') + + # for ext in sorted(Extensions.keys()): + # self.make_checkbutton(ext) + + # # buttons and their respective functions + # buttons = {'Clean': self.clean, + # 'Exit': self.quit_all, + # 'Undo': undo, + # 'Schedule': self.on_schedule_start, + # 'Remove\nSchedule': schedule_end + # } + + # for key in buttons: + # self.make_button(key, buttons[key]) - def make_checkbutton(self, text): - cb = Checkbutton(self, text=text, command=lambda: self.check(text)) - cb.select() - cb.pack({'side': 'top'}) - return cb + def __init__(self, master=None): + Frame.__init__(self, master) + self.pack() + self.create() - def make_button(self, text, command): - btn = Button(self, text=text, command=command) - btn.pack({'side': 'left'}) - return btn - def create(self): - self.winfo_toplevel().title('Desktop Cleaner') +@app.route('/') +def main(): + # OLD TKINTER UI - for ext in sorted(Extensions.keys()): - self.make_checkbutton(ext) + # root = Tk() + # # root.resizable = False # commenting this approach and applying the below one. + # # To make the application's size constant and restore button in windows as greyed out(with width=350 and height=330 as mentioned below) + # root.resizable(FALSE, FALSE) + # root.minsize(width=350, height=330) + # root.maxsize(width=350, height=330) - # buttons and their respective functions - buttons = {'Clean': self.clean, - 'Exit': self.quit_all, - 'Undo': undo, - 'Schedule': self.on_schedule_start, - 'Remove\nSchedule': schedule_end - } + # '''Logic to launch the app in center - start''' + # positionRight = int(root.winfo_screenwidth() / 2 - + # 330 / 2) # considering width=330 + # positionDown = int(root.winfo_screenheight() / 2 - + # 350 / 2) # considering height=350 + # root.geometry("+{}+{}".format(positionRight, positionDown)) + # '''Logic to launch the app in center - end''' - for key in buttons: - self.make_button(key, buttons[key]) + # app = App(root) + # root.protocol('WM_DELETE_WINDOW', app.quit_all) + # app.mainloop() + # root.destroy() - def __init__(self, master=None): - Frame.__init__(self, master) - self.pack() - self.create() + return render_template('index.html', extensions=Extensions) -def main(): - root = Tk() - # root.resizable = False # commenting this approach and applying the below one. - root.resizable(FALSE,FALSE) # To make the application's size constant and restore button in windows as greyed out(with width=350 and height=330 as mentioned below) - root.minsize(width=350, height=330) - root.maxsize(width=350, height=330) - - '''Logic to launch the app in center - start''' - positionRight = int(root.winfo_screenwidth() / 2 - 330 / 2) #considering width=330 - positionDown = int(root.winfo_screenheight() / 2 - 350 / 2) #considering height=350 - root.geometry("+{}+{}".format(positionRight, positionDown)) - '''Logic to launch the app in center - end''' - - app = App(root) - root.protocol('WM_DELETE_WINDOW', app.quit_all) - app.mainloop() - root.destroy() if __name__ == '__main__': - main() \ No newline at end of file + app.run(debug=True) diff --git a/organise_desktop/templates/index.html b/organise_desktop/templates/index.html new file mode 100644 index 0000000..e4bfaab --- /dev/null +++ b/organise_desktop/templates/index.html @@ -0,0 +1,45 @@ + + + + + + Clean Desktop + + +

Clean Desktop

+ {% if extensions %} {% for ext in extensions %} + {{ ext }}
+ {% endfor %} {% else %} +

No extensions available.

+ {% endif %} +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +