diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..1ccabc6 --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,91 @@ +from typing import List +from app.utils_drive import Drive +from app.globals import * +from tkinter import * +from tkinter import ttk + +class App: + + drives: List[Drive] = [] + + selected = None + + drive_tree = None + + def __init__(self): + self.root = Tk() + self.root.title("Disk Eraser") + self.root.geometry("400x300") + self.root.minsize(400, 300) + self.__load_menu() + self.__init_table() + self.root.mainloop() + + def __load_menu(self): + main_menu = Menu() + + help_menu = Menu(tearoff=0) + help_menu.add_command(label="Содержание") + help_menu.add_separator() + help_menu.add_command(label="О программе") + + main_menu.add_cascade(label="Справка", menu=help_menu) + bottom_frame = ttk.Frame(borderwidth=1, relief=SOLID, padding=[3, 5]) + erase_button = ttk.Button(bottom_frame, text="Стереть диск") + erase_button.pack(side=RIGHT) + bottom_frame.pack(side=BOTTOM, fill=X) + self.root.config(menu=main_menu) + + def __load_drives(self): + + if OS_TYPE == "Windows": + import wmi + c = wmi.WMI() + self.drives = [] + if disks := c.Win32_DiskDrive(): + for disk in disks: + self.drives.append(Drive(disk.Model, disk.Name, disk.InterfaceType, disk.DefaultBlockSize, int(disk.Size))) + elif OS_TYPE == "Linux": + from diskinfo import Disk, DiskInfo + di = DiskInfo() + disks = di.get_disk_list(sorting=True) + self.drives = [] + for d in disks: + self.drives.append(Drive(d.get_model(), d.get_path(), d.get_type_str(), d.get_logical_block_size(), int(d.get_size()*512))) + + def __init_table(self): + + self.__load_drives() + + # определяем столбцы + columns = ("name", "type", "capacity") + self.drive_tree = ttk.Treeview(columns=columns, show="headings", selectmode="browse") + self.drive_tree.pack(fill=BOTH, expand=1, side=TOP) + + # определяем заголовки + self.drive_tree.heading("name", text="Имя", anchor=W) + self.drive_tree.heading("type", text="Тип", anchor=W) + self.drive_tree.heading("capacity", text="Объем", anchor=W) + + self.drive_tree.column("#1", stretch=YES, width=150, minwidth=120) + self.drive_tree.column("#2", stretch=NO, width=60, minwidth=60) + self.drive_tree.column("#3", stretch=NO, width=100, minwidth=100) + + # добавляем данные + for drive in self.drives: + self.drive_tree.insert("", END, values=(drive.name, drive.disk_type, self.__human_size(drive.capacity))) + + self.drive_tree.bind("<>", self.__drive_selected) + + def __human_size(self, size): + units = ['Б', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ'] + for unit in units: + if size < 1024: + return f"{size:.1f} {unit}" + size /= 1024 + + def __drive_selected(self, event): + for selected_item in self.drive_tree.selection(): + item = self.drive_tree.item(selected_item) + self.selected = item["values"] + print(self.selected) diff --git a/utils/globals.py b/app/globals.py similarity index 100% rename from utils/globals.py rename to app/globals.py diff --git a/utils/utils_drive.py b/app/utils_drive.py similarity index 93% rename from utils/utils_drive.py rename to app/utils_drive.py index 7f31813..79e4d2c 100644 --- a/utils/utils_drive.py +++ b/app/utils_drive.py @@ -1,4 +1,4 @@ -from utils.globals import OS_TYPE +from app.globals import OS_TYPE class Drive(): diff --git a/main.py b/main.py index cde6917..b1c9d1d 100644 --- a/main.py +++ b/main.py @@ -1,25 +1,8 @@ -from utils.utils_drive import Drive -from utils.globals import * +from app import App -if OS_TYPE == "Windows": - import wmi - c = wmi.WMI() - drives = [] - if disks := c.Win32_DiskDrive(): - for disk in disks: - drives.append(Drive(disk.Model, disk.Name, disk.InterfaceType, disk.DefaultBlockSize, int(disk.Size))) -elif OS_TYPE == "Linux": - import subprocess +def main(): + app = App() - # Execute the lsblk command to get information about block devices - result = subprocess.run(['lsblk', '-o', 'NAME,SIZE,MODEL,VENDOR,TRAN'], capture_output=True, text=True) - - # Get the output - output = result.stdout - - # Вывод информации о дисках - print(output) - -# for drive in drives: -# print(f"{drive.name} | {drive.path} | {drive.disk_type} | {drive.block_size} | {drive.capacity}") +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/req.txt b/req.txt new file mode 100644 index 0000000..234ef27 Binary files /dev/null and b/req.txt differ diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 706f94e..0000000 Binary files a/requirements.txt and /dev/null differ