|
| 1 | +""" |
| 2 | + Copyright (C) 2018 Jules Lasne <jules.lasne@gmail.com> |
| 3 | + See full notice in `LICENSE' |
| 4 | +""" |
| 5 | + |
| 6 | +from tkinter import * |
| 7 | +import os |
| 8 | +import sys |
| 9 | +from tkinter import filedialog |
| 10 | + |
| 11 | + |
| 12 | +class Checkbar(Frame): |
| 13 | + def __init__(self, parent=None, picks=[], side=LEFT, anchor=W): |
| 14 | + Frame.__init__(self, parent) |
| 15 | + self.vars = [] |
| 16 | + for pick in picks: |
| 17 | + var = IntVar() |
| 18 | + chk = Checkbutton(self, text=pick, variable=var) |
| 19 | + chk.pack(side=side, anchor=anchor, expand=YES) |
| 20 | + self.vars.append(var) |
| 21 | + |
| 22 | + def state(self): |
| 23 | + return map((lambda var: var.get()), self.vars) |
| 24 | + |
| 25 | + |
| 26 | +class Application(): |
| 27 | + def __init__(self): |
| 28 | + self.window = Tk() |
| 29 | + |
| 30 | + def close_window(self): |
| 31 | + self.window.destroy() |
| 32 | + sys.exit() |
| 33 | + |
| 34 | + def close_window_escape(self, event): |
| 35 | + self.window.destroy() |
| 36 | + sys.exit() |
| 37 | + |
| 38 | + def get_project_path(self): |
| 39 | + self.path = filedialog.askdirectory() |
| 40 | + print(self.path) |
| 41 | + |
| 42 | + def callback_project_name_changed(self, *args): |
| 43 | + # @todo: Make groups like when you tick `tests` it ticks all the tests |
| 44 | + self.project_selected = self.project.get() |
| 45 | + if self.project_selected == "other": |
| 46 | + # @todo: whitelist/blacklist for options |
| 47 | + self.options = Checkbar(self.window, ['author', 'norme', 'Makefile']) |
| 48 | + self.options.pack(side=LEFT) |
| 49 | + |
| 50 | + if self.project_selected == "42commandements": |
| 51 | + self.options = None |
| 52 | + |
| 53 | + if self.project_selected == "libft": |
| 54 | + self.options = Checkbar(self.window, ['author', 'forbidden-functions', 'makefile', 'norme', 'static', 'extra', 'required', 'bonus', 'benchmark', 'tests', 'libftest', 'maintest', 'moulitest', 'fillit-checker', 'libft-unit-test']) |
| 55 | + self.options.pack(side=LEFT) |
| 56 | + |
| 57 | + if self.project_selected == "fillit": |
| 58 | + self.options = Checkbar(self.window, ['author', 'forbidden-functions', 'makefile', 'norme', 'tests', 'fillit-checker']) |
| 59 | + self.options.pack(side=LEFT) |
| 60 | + |
| 61 | + def start(self): |
| 62 | + if self.options != None: |
| 63 | + print(list(self.options.state())) |
| 64 | + |
| 65 | + def create_window(self): |
| 66 | + self.window.title("42PyChecker") |
| 67 | + self.window.minsize(width=800, height=800) |
| 68 | + # @todo: Set a icon for app image |
| 69 | + #self.window.iconbitmap(os.path.dirname(os.path.realpath(__file__)) + "/favicon.ico") |
| 70 | + # @todo: Find a way to loop through gif frames to have animated logo |
| 71 | + logo = PhotoImage(file=os.path.dirname(os.path.realpath(__file__)) + "/logo.gif") |
| 72 | + Label(self.window, image=logo).pack() |
| 73 | + Button(self.window, text="Select Project Path", width=20, command=self.get_project_path).pack() |
| 74 | + |
| 75 | + self.project = StringVar(self.window) |
| 76 | + dropdown = OptionMenu(self.window, self.project, "other", "42commandements", "libft", 'fillit') |
| 77 | + dropdown.pack() |
| 78 | + |
| 79 | + Button(self.window, text="Start", command=self.start).pack(side=BOTTOM) |
| 80 | + |
| 81 | + Button(self.window, text="Exit", command=self.close_window).pack(side=BOTTOM) |
| 82 | + self.window.bind('<Escape>', self.close_window_escape) |
| 83 | + |
| 84 | + self.project.trace("w", self.callback_project_name_changed) |
| 85 | + self.window.mainloop() |
0 commit comments