feat: add ImageList to TreeCtrl and ListCtrl for visual item classification

This commit is contained in:
Martin Tranberg
2026-03-30 19:40:00 +02:00
parent 14e327989c
commit 2b82a7aa5c

View File

@@ -63,6 +63,13 @@ class SharePointApp(wx.Frame):
self.tree_root = None
self.is_navigating_back = False
# System Ikoner (ArtProvider - mest basale for kompatibilitet)
self.image_list = wx.ImageList(16, 16)
self.idx_site = self.image_list.Add(wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_OTHER, (16, 16))) # Site (Hus ikon)
self.idx_drive = self.image_list.Add(wx.ArtProvider.GetBitmap(wx.ART_HARDDISK, wx.ART_OTHER, (16, 16))) # Drive
self.idx_folder = self.image_list.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, (16, 16))) # Folder
self.idx_file = self.image_list.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, (16, 16))) # File
# Threading/Sync til filredigering
self.edit_wait_event = threading.Event()
@@ -132,11 +139,13 @@ class SharePointApp(wx.Frame):
# Left side: Tree
self.tree_ctrl = wx.TreeCtrl(self.splitter, style=wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT | wx.BORDER_SUNKEN)
self.tree_ctrl.AssignImageList(self.image_list)
self.tree_ctrl.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.on_tree_expanding)
self.tree_ctrl.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_tree_selected)
# Right side: File Area - ListCtrl
self.list_ctrl = wx.ListCtrl(self.splitter, style=wx.LC_REPORT | wx.BORDER_SUNKEN)
self.list_ctrl.AssignImageList(self.image_list, wx.IMAGE_LIST_SMALL)
self.list_ctrl.InsertColumn(0, "Navn", width=450)
self.list_ctrl.InsertColumn(1, "Type", width=150)
self.list_ctrl.InsertColumn(2, "Sidst ændret", width=200)
@@ -280,7 +289,7 @@ class SharePointApp(wx.Frame):
self.set_status(f"Fandt {len(sites)} sites.")
for site in sites:
name = site.get('displayName', site.get('name'))
node = self.tree_ctrl.AppendItem(self.tree_root, name)
node = self.tree_ctrl.AppendItem(self.tree_root, name, image=self.idx_site)
self.tree_item_data[node] = {
"type": "SITE", "id": site['id'], "name": name,
"drive_id": None, "path": ["SharePoint", name], "loaded": False
@@ -292,7 +301,7 @@ class SharePointApp(wx.Frame):
self.current_items = []
for i, site in enumerate(sites):
name = site.get('displayName', site.get('name'))
self.list_ctrl.InsertItem(i, name)
self.list_ctrl.InsertItem(i, name, self.idx_site)
self.list_ctrl.SetItem(i, 1, "Site")
self.current_items.append({"type": "SITE", "id": site['id'], "name": name})
@@ -338,7 +347,7 @@ class SharePointApp(wx.Frame):
for drive in drives:
name = drive.get('name', 'Ukendt')
drive_id = drive['id']
node = self.tree_ctrl.AppendItem(parent_node, name)
node = self.tree_ctrl.AppendItem(parent_node, name, image=self.idx_drive)
self.tree_item_data[node] = {
"type": "DRIVE", "id": drive_id, "name": name,
"drive_id": drive_id, "path": parent_data["path"] + [name], "loaded": False
@@ -359,7 +368,7 @@ class SharePointApp(wx.Frame):
for folder in folders:
name = folder['name']
folder_id = folder['id']
node = self.tree_ctrl.AppendItem(parent_node, name)
node = self.tree_ctrl.AppendItem(parent_node, name, image=self.idx_folder)
self.tree_item_data[node] = {
"type": "FOLDER", "id": folder_id, "name": name,
"drive_id": parent_data["drive_id"], "path": parent_data["path"] + [name], "loaded": False
@@ -430,7 +439,12 @@ class SharePointApp(wx.Frame):
self.list_ctrl.DeleteAllItems()
self.current_items = []
for i, item in enumerate(items_data):
self.list_ctrl.InsertItem(i, item['name'])
img_idx = self.idx_file
if item['type'] == "FOLDER": img_idx = self.idx_folder
elif item['type'] == "DRIVE": img_idx = self.idx_drive
elif item['type'] == "SITE": img_idx = self.idx_site
self.list_ctrl.InsertItem(i, item['name'], img_idx)
type_str = "Mappe" if item['type'] == "FOLDER" else "Fil" if item['type'] == "FILE" else "Bibliotek"
self.list_ctrl.SetItem(i, 1, type_str)
self.list_ctrl.SetItem(i, 2, item['modified'])