Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turned Tkinter GUI into webapp #105

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 84 additions & 49 deletions organise_desktop/Clean.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand All @@ -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)

Expand All @@ -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()
app.run(debug=True)
45 changes: 45 additions & 0 deletions organise_desktop/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous"
/>
<style>
body {
padding: 2%;
}
.btn {
margin: 0.5%;
}
</style>
<title>Clean Desktop</title>
</head>
<body>
<h1>Clean Desktop</h1>
{% if extensions %} {% for ext in extensions %}
<input checked type="checkbox" name="{{ ext }}" /> {{ ext }} <br />
{% endfor %} {% else %}
<p>No extensions available.</p>
{% endif %}
<br />
<br />
<form action="/clean" method="post">
<button class="btn btn-primary" type="submit">Clean</button>
</form>
<form action="/quit" method="post">
<button class="btn btn-primary" type="submit">Quit</button>
</form>
<form action="/schedule" method="post">
<button class="btn btn-primary" type="submit">Schedule</button>
</form>
<form action="/undo" method="post">
<button class="btn btn-primary" type="submit">undo</button>
</form>
<form action="/schedule-end" method="post">
<button class="btn btn-primary" type="submit">Schedule End</button>
</form>
</body>
</html>