fix: add safety checks to path display and tree selection to prevent runtime errors during object destruction
This commit is contained in:
@@ -239,30 +239,37 @@ class SharePointApp(wx.Frame):
|
|||||||
self.update_path_display()
|
self.update_path_display()
|
||||||
|
|
||||||
def update_path_display(self):
|
def update_path_display(self):
|
||||||
self.path_sizer.Clear(True)
|
if not self:
|
||||||
|
return
|
||||||
|
|
||||||
# Find alle noder fra rod til nuværende selektion
|
try:
|
||||||
nodes = []
|
self.path_sizer.Clear(True)
|
||||||
curr = self.tree_ctrl.GetSelection()
|
|
||||||
|
|
||||||
while curr.IsOk() and curr != self.tree_root:
|
|
||||||
nodes.insert(0, curr)
|
|
||||||
curr = self.tree_ctrl.GetItemParent(curr)
|
|
||||||
|
|
||||||
# Start ikon/label
|
# Find alle noder fra rod til nuværende selektion
|
||||||
self._add_path_segment("📍 SharePoint", "ROOT")
|
nodes = []
|
||||||
|
curr = self.tree_ctrl.GetSelection()
|
||||||
for node in nodes:
|
|
||||||
arrow = wx.StaticText(self.path_panel, label=" > ")
|
|
||||||
arrow.SetForegroundColour(wx.Colour(150, 150, 150))
|
|
||||||
self.path_sizer.Add(arrow, 0, wx.ALIGN_CENTER_VERTICAL)
|
|
||||||
|
|
||||||
name = self.tree_ctrl.GetItemText(node)
|
while curr.IsOk() and curr != self.tree_root:
|
||||||
self._add_path_segment(name, node)
|
nodes.insert(0, curr)
|
||||||
|
curr = self.tree_ctrl.GetItemParent(curr)
|
||||||
|
|
||||||
|
# Start ikon/label
|
||||||
|
self._add_path_segment("📍 SharePoint", "ROOT")
|
||||||
|
|
||||||
self.path_panel.Layout()
|
for node in nodes:
|
||||||
self.path_panel.Refresh()
|
arrow = wx.StaticText(self.path_panel, label=" > ")
|
||||||
self.Layout() # Tving rammen til at opdatere, så stien kommer frem
|
arrow.SetForegroundColour(wx.Colour(150, 150, 150))
|
||||||
|
self.path_sizer.Add(arrow, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||||
|
|
||||||
|
name = self.tree_ctrl.GetItemText(node)
|
||||||
|
self._add_path_segment(name, node)
|
||||||
|
|
||||||
|
self.path_panel.Layout()
|
||||||
|
self.path_panel.Refresh()
|
||||||
|
self.Layout() # Tving rammen til at opdatere, så stien kommer frem
|
||||||
|
except RuntimeError:
|
||||||
|
# Sker oftest ved lukning hvor objekter er slettet
|
||||||
|
pass
|
||||||
|
|
||||||
def _add_path_segment(self, label, node):
|
def _add_path_segment(self, label, node):
|
||||||
btn = wx.Button(self.path_panel, label=label, style=wx.BU_EXACTFIT | wx.BORDER_NONE)
|
btn = wx.Button(self.path_panel, label=label, style=wx.BU_EXACTFIT | wx.BORDER_NONE)
|
||||||
@@ -429,7 +436,8 @@ class SharePointApp(wx.Frame):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.current_path = data["path"]
|
self.current_path = data["path"]
|
||||||
self.update_path_display()
|
if self:
|
||||||
|
self.update_path_display()
|
||||||
|
|
||||||
if not self.is_navigating_back:
|
if not self.is_navigating_back:
|
||||||
self.history.append(item)
|
self.history.append(item)
|
||||||
@@ -518,6 +526,9 @@ class SharePointApp(wx.Frame):
|
|||||||
|
|
||||||
def _sync_tree_selection(self, target_id):
|
def _sync_tree_selection(self, target_id):
|
||||||
selected = self.tree_ctrl.GetSelection()
|
selected = self.tree_ctrl.GetSelection()
|
||||||
|
if not selected.IsOk():
|
||||||
|
selected = self.tree_root
|
||||||
|
|
||||||
if selected.IsOk():
|
if selected.IsOk():
|
||||||
data = self.tree_item_data.get(selected)
|
data = self.tree_item_data.get(selected)
|
||||||
if data and not data.get("loaded"):
|
if data and not data.get("loaded"):
|
||||||
|
|||||||
Reference in New Issue
Block a user