def add_item(): item_name = name_entry.get() item_name = item_name.upper() item_name = item_name.translate({ord(c): None for c in ' \n\t\r'}) if item_name == "": messagebox.showerror( "Błąd", 'Pole "' + constants.ADD_NAME_LABEL_TEXT + '" nie może być puste.') else: item_description = description_entry.get() item_description = item_description.translate( {ord(c): None for c in '\n\t\r'}) item_type = chosen_type.get() if item_type == "": messagebox.showerror("Błąd", "Wybierz rodzaj obiektu.") else: now = generaldefinitions.get_time() notes = constants.ADD_ITEM_INFO + now sql_insert_values = (item_name, item_type, item_description, notes, now) connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: id = plkdatabase.add_item(connection, sql_insert_values) if id is not None: messagebox.showinfo("Info", "Zapis dodano do bazy") connection.close() update_tree_list()
def change_item_description(): item_name = plk_tree.item(plk_tree.selection())["text"] if item_name not in constants.DB_TYPE_NAME_LIST: change_description = messagebox.askquestion("Info", "Zmienić opis?") if change_description == "yes": new_description = simpledialog.askstring("Info", "Podaj nowy opis dla " + item_name + '.', parent=main_window) connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: old_description = plkdatabase.get_description( connection, item_name)[0][0] plkdatabase.update_description(connection, item_name, new_description) now = generaldefinitions.get_time() info = constants.CHANGE_DESCRIPTION_INFO + now + " z [" + old_description + "] na [" + new_description + "]. \n" notes = plkdatabase.get_notes(connection, item_name)[0][0] notes = info + notes plkdatabase.update_notes(connection, item_name, notes) plkdatabase.update_modification_time(connection, item_name, now) update_tree_list() load_memo_info() connection.close()
def ping(): item_name = get_hostname() connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: type = plkdatabase.get_type(connection, item_name)[0][0] connection.close() if type == constants.DB_COMPUTER_TYPE_NAME or type == constants.DB_DEVICE_TYPE_NAME: generaldefinitions.ping_computer(item_name)
def explore_file_system(): hostname = get_hostname() connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: if plkdatabase.get_type( connection, hostname)[0][0] == constants.DB_COMPUTER_TYPE_NAME: connection.close() if generaldefinitions.test_connection(hostname): generaldefinitions.explore_host(hostname) else: messagebox.showerror("Info", hostname + " jest offline.")
def load_memo_info(): item_name = get_hostname() plk_user_memo.delete("1.0", END) if item_name not in constants.DB_TYPE_NAME_LIST: connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: some_info = plkdatabase.get_notes(connection, item_name)[0][0] plk_user_memo.insert(INSERT, some_info) connection.close() color_memo_text() else: plk_user_memo.delete("1.0", END)
def save_memo_info(): item_name = get_hostname() if item_name not in constants.DB_TYPE_NAME_LIST: connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: notes = plk_user_memo.get("1.0", END) back_notes = plkdatabase.get_notes(connection, item_name)[0][0] if notes[:-1] != back_notes: now = generaldefinitions.get_time() plkdatabase.update_notes(connection, item_name, notes) plkdatabase.update_modification_time(connection, item_name, now) connection.close()
def delete_items(): if get_hostname() not in constants.DB_TYPE_NAME_LIST: do_want_delete = messagebox.askquestion("Info", "Usunąć wybrane elementy?") if do_want_delete == "yes": connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: selected_items = plk_tree.selection() for selected_item in selected_items: item_name = plk_tree.item(selected_item)["text"] plkdatabase.delete_item(connection, item_name) current_item_name_label.config(text="") plk_user_memo.delete("1.0", END) connection.close() update_tree_list()
def change_item_type(): item_name = plk_tree.item(plk_tree.selection())["text"] connection = plkdatabase.create_connection(constants.DB_NAME) if item_name not in constants.DB_TYPE_NAME_LIST: change_type = messagebox.askquestion( "Info", "Zmienić typ dla " + item_name + "?") if change_type == "yes": old_type = plkdatabase.get_type(connection, item_name)[0][0] info = """Podaj nową nazwę typu. Dozwolone typy: USER dla użytkowników, COMPUTER dla komputerów, DEVICE dla urządzeń, PROGRAM dla programów, TIP dla wskazówek.""" new_type = simpledialog.askstring(item_name + ": Zmiana typu", info) if new_type != "": new_type = str(new_type) new_type = new_type.upper() new_type = new_type.translate( {ord(c): None for c in ' \n\t\r'}) if new_type in constants.DB_TYPE_VALUE_LIST: plkdatabase.update_type(connection, item_name, new_type) now = generaldefinitions.get_time() info = constants.CHANGE_TYPE_INFO + now + " z [" + old_type + "] na [" + new_type + "]. \n" notes = plkdatabase.get_notes(connection, item_name)[0][0] notes = info + notes plkdatabase.update_notes(connection, item_name, notes) plkdatabase.update_modification_time( connection, item_name, now) load_memo_info() update_tree_list() else: messagebox.showerror("Info", "Błędny typ") connection.close()
def change_item_name(): item_name = plk_tree.item(plk_tree.selection())["text"] if item_name not in constants.DB_TYPE_NAME_LIST: change_name = messagebox.askquestion("Info", "Zmienić nazwę?") if change_name == "yes": new_name = simpledialog.askstring( "Info", "Podaj nową nazwę dla " + item_name + '.') new_name = new_name.upper() new_name = new_name.translate({ord(c): None for c in ' \n\t\r'}) if new_name == "": messagebox.showerror("Info", "Nazwa jest pusta.") else: connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: plkdatabase.update_name(connection, item_name, new_name) now = generaldefinitions.get_time() info = constants.CHANGE_NAME_INFO + now + " z [" + item_name + "] na [" + new_name + "]. \n" notes = plkdatabase.get_notes(connection, new_name)[0][0] notes = info + notes plkdatabase.update_notes(connection, new_name, notes) plkdatabase.update_modification_time( connection, new_name, now) update_tree_list() connection.close()
def sort_tree_on_event(event): def get_order(val): switcher = { "heading#0": "name", "heading#1": "description", "heading#2": "modification_time" } return switcher.get(val, "") region = plk_tree.identify_region(event.x, event.y) if region == "heading": name = plk_tree.identify_column(event.x) order = "ASC" if name == "#2": order = "DESC" header_name = region + name header_name = get_order(header_name) childrens = plk_tree.get_children() for child in childrens: plk_tree.delete(child) set_active_user() plk_users = plk_tree.insert("", 1, text="Użytkownicy", values=(""), open=True) plk_tips = plk_tree.insert("", 1, text="Wskazówki", values=(""), open=True) plk_programs = plk_tree.insert("", 1, text="Programy", values=(""), open=True) plk_devices = plk_tree.insert("", 1, text="Urządzenia", values=(""), open=True) plk_computers = plk_tree.insert("", 1, text="Komputery", values=(""), open=True) connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: rows = plkdatabase.select_and_order_items( connection, constants.DB_USER_TYPE_NAME, header_name, order) if rows is not None: for row in rows: user_name, description, time = str(row).split(",") user_name = user_name.translate( {ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_users, "end", text=user_name, values=(description, time)) rows = plkdatabase.select_and_order_items( connection, constants.DB_COMPUTER_TYPE_NAME, header_name, order) if rows is not None: for row in rows: computer_name, description, time = str(row).split(",") computer_name = computer_name.translate( {ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_computers, "end", text=computer_name, values=(description, time)) rows = plkdatabase.select_and_order_items( connection, constants.DB_DEVICE_TYPE_NAME, header_name, order) if rows is not None: for row in rows: device_name, description, time = str(row).split(",") device_name = device_name.translate( {ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_devices, "end", text=device_name, values=(description, time)) rows = plkdatabase.select_and_order_items( connection, constants.DB_PROGRAM_TYPE_NAME, header_name, order) if rows is not None: for row in rows: program_name, description, time = str(row).split(",") program_name = program_name.translate( {ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_programs, "end", text=program_name, values=(description, time)) rows = plkdatabase.select_and_order_items( connection, constants.DB_TIP_TYPE_NAME, header_name, order) if rows is not None: for row in rows: tip_name, description, time = str(row).split(",") tip_name = tip_name.translate({ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_tips, "end", text=tip_name, values=(description, time)) connection.close()
def update_tree_list(): childrens = plk_tree.get_children() for child in childrens: plk_tree.delete(child) plk_users = plk_tree.insert("", 1, text="Użytkownicy", values=(""), open=True) plk_tips = plk_tree.insert("", 1, text="Wskazówki", values=(""), open=True) plk_programs = plk_tree.insert("", 1, text="Programy", values=(""), open=True) plk_devices = plk_tree.insert("", 1, text="Urządzenia", values=(""), open=True) plk_computers = plk_tree.insert("", 1, text="Komputery", values=(""), open=True) connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: rows = plkdatabase.select_all_users(connection) if rows is not None: for row in rows: user_name, description, time = str(row).split(",") user_name = user_name.translate({ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_users, "end", text=user_name, values=(description, time)) rows = plkdatabase.select_all_computers(connection) if rows is not None: for row in rows: computer_name, description, time = str(row).split(",") computer_name = computer_name.translate( {ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_computers, "end", text=computer_name, values=(description, time)) rows = plkdatabase.select_all_devices(connection) if rows is not None: for row in rows: device_name, description, time = str(row).split(",") device_name = device_name.translate( {ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_devices, "end", text=device_name, values=(description, time)) rows = plkdatabase.select_all_programs(connection) if rows is not None: for row in rows: program_name, description, time = str(row).split(",") program_name = program_name.translate( {ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_programs, "end", text=program_name, values=(description, time)) rows = plkdatabase.select_all_tips(connection) if rows is not None: for row in rows: tip_name, description, time = str(row).split(",") tip_name = tip_name.translate({ord(c): None for c in "('"}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) plk_tree.insert(plk_tips, "end", text=tip_name, values=(description, time)) connection.close()
def search_item(): item_name = search_entry.get() plk_user_memo.delete("1.0", END) set_active_user() if len(item_name) >= 3 and item_name != "": childrens = plk_tree.get_children() for child in childrens: plk_tree.delete(child) plk_users = plk_tree.insert("", 1, text="Użytkownicy", values=(""), open=True) plk_tips = plk_tree.insert("", 1, text="Wskazówki", values=(""), open=True) plk_programs = plk_tree.insert("", 1, text="Programy", values=(""), open=True) plk_devices = plk_tree.insert("", 1, text="Urządzenia", values=(""), open=True) plk_computers = plk_tree.insert("", 1, text="Komputery", values=(""), open=True) connection = plkdatabase.create_connection(constants.DB_NAME) if connection is not None: if item_name[:2] == "->": item_name = item_name[2:] rows = plkdatabase.select_all_items_with_string_in_notes( connection, item_name) else: rows = plkdatabase.select_all_items_with_string( connection, item_name) if rows is not None: for row in rows: item_type, item_name, description, time = str(row).split( ",") item_type = item_type.translate( {ord(c): None for c in "('"}) item_name = item_name.translate( {ord(c): None for c in "(' "}) description = description.translate( {ord(c): None for c in "'"}) time = time.translate({ord(c): None for c in "')"}) if item_type == constants.DB_USER_TYPE_NAME: plk_tree.insert(plk_users, "end", text=item_name, values=(description, time)) elif item_type == constants.DB_COMPUTER_TYPE_NAME: plk_tree.insert(plk_computers, "end", text=item_name, values=(description, time)) elif item_type == constants.DB_DEVICE_TYPE_NAME: plk_tree.insert(plk_devices, "end", text=item_name, values=(description, time)) elif item_type == constants.DB_PROGRAM_TYPE_NAME: plk_tree.insert(plk_programs, "end", text=item_name, values=(description, time)) elif item_type == constants.DB_TIP_TYPE_NAME: plk_tree.insert(plk_tips, "end", text=item_name, values=(description, time)) connection.close() else: update_tree_list()