commit 24
This commit is contained in:
Binary file not shown.
@@ -3,6 +3,8 @@ import shutil
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from datetime import datetime
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
# Helper to make icon paths robust, so the script can be run from anywhere
|
||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
@@ -109,6 +111,10 @@ class CustomFileDialog(tk.Toplevel):
|
||||
icon_files = {
|
||||
'computer_small': '/usr/share/icons/lx-icons/32/computer-32.png',
|
||||
'computer_large': '/usr/share/icons/lx-icons/48/computer-48.png',
|
||||
'device_small': '/usr/share/icons/lx-icons/32/device-32.png',
|
||||
'device_large': '/usr/share/icons/lx-icons/48/device-48.png',
|
||||
'usb_small': '/usr/share/icons/lx-icons/32/usb-32.png',
|
||||
'usb_large': '/usr/share/icons/lx-icons/48/usb-48.png',
|
||||
'downloads_small': '/usr/share/icons/lx-icons/32/folder-water-download-32.png',
|
||||
'downloads_large': '/usr/share/icons/lx-icons/48/folder-water-download-48.png',
|
||||
'documents_small': '/usr/share/icons/lx-icons/32/folder-water-documents-32.png',
|
||||
@@ -238,12 +244,12 @@ class CustomFileDialog(tk.Toplevel):
|
||||
main_frame = ttk.Frame(self, style='Accent.TFrame')
|
||||
main_frame.pack(fill="both", expand=True)
|
||||
main_frame.grid_rowconfigure(2, weight=1)
|
||||
main_frame.grid_columnconfigure(0, weight=1)
|
||||
main_frame.grid_columnconfigure(1, weight=1)
|
||||
|
||||
# Top bar for navigation and path
|
||||
top_bar = ttk.Frame(
|
||||
main_frame, style='Accent.TFrame', padding=(0, 5, 0, 5))
|
||||
top_bar.grid(row=0, column=0, sticky="ew")
|
||||
top_bar.grid(row=0, column=0, columnspan=2, sticky="ew")
|
||||
top_bar.grid_columnconfigure(1, weight=1)
|
||||
|
||||
# Navigation buttons
|
||||
@@ -297,17 +303,12 @@ class CustomFileDialog(tk.Toplevel):
|
||||
# Horizontal separator
|
||||
separator_color = "#000000" if self.is_dark else "#d9d9d9"
|
||||
tk.Frame(main_frame, height=1, bg=separator_color).grid(
|
||||
row=1, column=0, sticky="ew")
|
||||
|
||||
# Paned window for sidebar and content
|
||||
paned_window = ttk.PanedWindow(
|
||||
main_frame, orient=tk.HORIZONTAL)
|
||||
paned_window.grid(row=2, column=0, sticky="nsew")
|
||||
row=1, column=0, columnspan=2, sticky="ew")
|
||||
|
||||
# Sidebar
|
||||
sidebar_frame = ttk.Frame(
|
||||
paned_window, style="Sidebar.TFrame", padding=(0, 0, 0, 15))
|
||||
paned_window.add(sidebar_frame, weight=0)
|
||||
main_frame, style="Sidebar.TFrame", padding=(0, 0, 0, 15))
|
||||
sidebar_frame.grid(row=2, column=0, sticky="nsw")
|
||||
sidebar_frame.grid_rowconfigure(0, weight=1)
|
||||
|
||||
sidebar_buttons_frame = ttk.Frame(
|
||||
@@ -336,8 +337,23 @@ class CustomFileDialog(tk.Toplevel):
|
||||
ttk.Separator(sidebar_buttons_frame, orient='horizontal').pack(
|
||||
fill='x', pady=10, padx=20)
|
||||
|
||||
# Mounted devices
|
||||
mounted_devices_frame = ttk.Frame(
|
||||
sidebar_frame, style="Sidebar.TFrame")
|
||||
mounted_devices_frame.grid(row=1, column=0, sticky="ew", padx=10)
|
||||
ttk.Label(mounted_devices_frame, text="Geräte:", background=self.sidebar_color,
|
||||
foreground=self.color_foreground).pack(fill="x", padx=10, pady=(5, 0))
|
||||
|
||||
for device_name, mount_point in self._get_mounted_devices():
|
||||
btn = ttk.Button(mounted_devices_frame, text=f" {device_name}", image=self.icons['computer_small'],
|
||||
compound="left", command=lambda p=mount_point: self.navigate_to(p), style="Dark.TButton.Borderless")
|
||||
btn.pack(fill="x", pady=1)
|
||||
|
||||
ttk.Separator(sidebar_buttons_frame, orient='horizontal').pack(
|
||||
fill='x', pady=10, padx=20)
|
||||
|
||||
storage_frame = ttk.Frame(sidebar_frame, style="Sidebar.TFrame")
|
||||
storage_frame.grid(row=1, column=0, sticky="ew", padx=10)
|
||||
storage_frame.grid(row=2, column=0, sticky="ew", padx=10)
|
||||
self.storage_label = ttk.Label(
|
||||
storage_frame, text="Freier Speicher:", background=self.freespace_background)
|
||||
self.storage_label.pack(fill="x", padx=10)
|
||||
@@ -346,9 +362,9 @@ class CustomFileDialog(tk.Toplevel):
|
||||
self.storage_bar.pack(fill="x", pady=(2, 5), padx=15)
|
||||
|
||||
# Content area
|
||||
content_frame = ttk.Frame(paned_window, padding=(
|
||||
content_frame = ttk.Frame(main_frame, padding=(
|
||||
0, 0, 0, 0), style="AccentBottom.TFrame")
|
||||
paned_window.add(content_frame, weight=1)
|
||||
content_frame.grid(row=2, column=1, sticky="nsew")
|
||||
content_frame.grid_rowconfigure(0, weight=1)
|
||||
content_frame.grid_columnconfigure(0, weight=1)
|
||||
|
||||
@@ -723,3 +739,45 @@ class CustomFileDialog(tk.Toplevel):
|
||||
|
||||
def shorten_text(self, text, max_len):
|
||||
return text if len(text) <= max_len else text[:max_len-3] + "..."
|
||||
|
||||
def _get_mounted_devices(self):
|
||||
devices = []
|
||||
try:
|
||||
# Use lsblk to get information about block devices
|
||||
# -o NAME,MOUNTPOINT,FSTYPE,SIZE,RO,RM,TYPE,LABEL,UUID
|
||||
# -J for JSON output
|
||||
result = subprocess.run(['lsblk', '-J', '-o', 'NAME,MOUNTPOINT,FSTYPE,SIZE,RO,RM,TYPE,LABEL'],
|
||||
capture_output=True, text=True, check=True)
|
||||
data = json.loads(result.stdout)
|
||||
|
||||
for block_device in data.get('blockdevices', []):
|
||||
# Consider only devices with a mountpoint and not of type 'loop' or 'rom'
|
||||
if block_device.get('mountpoint') and block_device.get('type') not in ['loop', 'rom']:
|
||||
name = block_device.get('name')
|
||||
mountpoint = block_device.get('mountpoint')
|
||||
label = block_device.get('label')
|
||||
size = block_device.get('size')
|
||||
|
||||
display_name = label if label else name
|
||||
if size:
|
||||
display_name += f" ({size})"
|
||||
|
||||
devices.append((display_name, mountpoint))
|
||||
|
||||
# Recursively check partitions if any
|
||||
if 'children' in block_device:
|
||||
for child_device in block_device['children']:
|
||||
if child_device.get('mountpoint') and child_device.get('type') not in ['loop', 'rom']:
|
||||
name = child_device.get('name')
|
||||
mountpoint = child_device.get('mountpoint')
|
||||
label = child_device.get('label')
|
||||
size = child_device.get('size')
|
||||
|
||||
display_name = label if label else name
|
||||
if size:
|
||||
display_name += f" ({size})"
|
||||
|
||||
devices.append((display_name, mountpoint))
|
||||
except Exception as e:
|
||||
print(f"Error getting mounted devices: {e}")
|
||||
return devices
|
||||
|
@@ -58,7 +58,7 @@ if __name__ == "__main__":
|
||||
style = ttk.Style(root)
|
||||
root.tk.call('source', f"{theme_path}/water.tcl")
|
||||
try:
|
||||
root.tk.call('set_theme', 'light')
|
||||
root.tk.call('set_theme', 'dark')
|
||||
except tk.TclError:
|
||||
pass
|
||||
root.mainloop()
|
||||
|
Reference in New Issue
Block a user