Ejemplo n.º 1
0
class DeleteTool(tk.Toplevel):
    """Opens a window to retrieve investigation data"""
    def __init__(self, master=None, *args, **kwargs):
        """Initializes Toplevel object and builds interface"""
        super().__init__(master, *args, **kwargs)
        # initialize variables
        self.selection = tk.StringVar(self)
        # initialize database
        self.db_handler = Database()
        # hide window in background during drawing and load, to prevent flickering and glitches during frame load
        self.withdraw()
        # build and draw the window
        self.build()
        # unhide the Toplevel window immediately after draw and load 
        self.after(0, self.deiconify)

    def build(self):
        """Initializes and builds application widgets"""
        # create input labelframe
        labelframe_1 = tk.LabelFrame(self, fg='brown')
        labelframe_1.pack(side="top", expand='yes', fill='both', padx=2, pady=2, anchor="n")

        # create explanation label
        self.label = tk.Label(labelframe_1, text='Delete...')
        self.label.pack(expand=True, fill='x', side="left", padx=2, pady=2)

        # create data input entry widget
        self.options = tk.OptionMenu(labelframe_1, self.selection, *self.db_handler.retrieve_investigation_ids(),
        command=self.delete_data)
        self.options.pack(expand=True, fill='x', side="left", padx=2, pady=2)
        self.selection.set(self.db_handler.retrieve_investigation_ids()[0])

        # create save button
        self.save_button = tk.Button(labelframe_1, text="Delete", command=self.delete_data)
        self.save_button.pack(expand=False, side="left", padx=2, pady=2, anchor="e")

        # create cancel button
        self.cancel_button = tk.Button(labelframe_1, text="Cancel", command=self.quit)
        self.cancel_button.pack(expand=False, side="left", padx=2, pady=2, anchor="e")

    def delete_data(self, value=None):
        """Deletes investigation data from database"""
        if value:
            investigation_id = value
        else:
            investigation_id = self.selection.get()
        try:
            self.db_handler.delete_investigation(investigation_id)
            self.quit()

        except Exception as e:
            print("[*] Error: ", e)
            self.quit()

    def quit(self):
        """Quits the open window"""
        self.db_handler.close_connection()
        self.destroy()
Ejemplo n.º 2
0
    def open_investigation(self):
        """Open investigation data"""
        db = Database()
        investigation_ids = db.retrieve_investigation_ids()
        if not investigation_ids:
            messagebox.showinfo("No saved investigations", "Please save an investigation before loading data")
            db.close_connection()
        if investigation_ids:
            # clear investigation id
            self.investigation_id_tracker = ""

            self.open = OpenTool()
            self.open.title('Open investigation')
            self.open.geometry('+%d+%d' % (root.winfo_x() +
                                                  20, root.winfo_y() + 20))
            if sys.platform == "win32":
                self.open.iconbitmap(self.icon)
            self.open.resizable(width=False, height=False)
            self.open.protocol('WM_DELETE_WINDOW', self.open.quit_open)
            # set focus on window
            self.open.grab_set()
            self.open.focus()

            # start mainloop
            self.open.mainloop()