Skip to content

Commit

Permalink
RUFF
Browse files Browse the repository at this point in the history
  • Loading branch information
rmatsuda committed Oct 11, 2024
1 parent e19c6b0 commit 938f148
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
58 changes: 33 additions & 25 deletions invesalius/gui/task_navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2087,17 +2087,19 @@ def __init__(self, parent, nav_hub):
# at most 1080 pixels (a commonly used height in laptops). Otherwise, the height grows linearly with
# the screen height.
marker_list_height = max(120, int(screen_height / 4))
marker_list_ctrl = gizmos.TreeListCtrl(self, -1,
style=wx.TR_DEFAULT_STYLE
| wx.TR_HIDE_ROOT
| wx.TR_ROW_LINES
| wx.TR_COLUMN_LINES
| wx.TR_FULL_ROW_HIGHLIGHT
# | wx.TR_MULTIPLE
| wx.TR_HIDE_ROOT,
agwStyle=gizmos.TR_MULTIPLE,
size=wx.Size(0, marker_list_height))

marker_list_ctrl = gizmos.TreeListCtrl(
self,
-1,
style=wx.TR_DEFAULT_STYLE
| wx.TR_HIDE_ROOT
| wx.TR_ROW_LINES
| wx.TR_COLUMN_LINES
| wx.TR_FULL_ROW_HIGHLIGHT
# | wx.TR_MULTIPLE
| wx.TR_HIDE_ROOT,
agwStyle=gizmos.TR_MULTIPLE,
size=wx.Size(0, marker_list_height),
)

marker_list_ctrl.AddColumn("#")
marker_list_ctrl.SetColumnWidth(const.ID_COLUMN, 32)
Expand Down Expand Up @@ -2135,7 +2137,7 @@ def __init__(self, parent, nav_hub):

marker_list_ctrl.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnMouseRightDown)
marker_list_ctrl.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnMarkerFocused)
#marker_list_ctrl.Bind(wx.EVT_TREE_ITEM_DESELECTED, self.OnMarkerUnfocused)
# marker_list_ctrl.Bind(wx.EVT_TREE_ITEM_DESELECTED, self.OnMarkerUnfocused)
marker_list_ctrl.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.SetCameraToFocusOnMarker)

marker_list_ctrl.SetMainColumn(0)
Expand Down Expand Up @@ -2280,7 +2282,7 @@ def _DeleteMultiple(self, markers):
print("Invalid itemDataMap key:", key)

num_items = self.marker_list_ctrl.GetCount()
for n in range(1,num_items):
for n in range(1, num_items):
m_id = self.__get_marker_id(n)
reduction_in_m_id = 0
for d_id in deleted_ids:
Expand All @@ -2295,7 +2297,7 @@ def _SetPointOfInterest(self, marker):
idx = self.search_in_tree(marker.marker_id)
item = self.marker_list_ctrl.FindItem(self.root, str(idx))
self.marker_list_ctrl.SetItemBackgroundColour(item, "PURPLE")
self.marker_list_ctrl.SetItemText(item, _("Yes"), const.POINT_OF_INTEREST_TARGET_COLUMN)
self.marker_list_ctrl.SetItemText(item, _("Yes"), const.POINT_OF_INTEREST_TARGET_COLUMN)
uuid = marker.marker_uuid

# Set the point of interest in itemDataMap
Expand All @@ -2308,7 +2310,7 @@ def _UnsetPointOfInterest(self, marker):
idx = self.search_in_tree(marker.marker_id)
item = self.marker_list_ctrl.FindItem(self.root, str(idx))
self.marker_list_ctrl.SetItemBackgroundColour(item, "white")
self.marker_list_ctrl.SetItemText(item, _(""), const.POINT_OF_INTEREST_TARGET_COLUMN)
self.marker_list_ctrl.SetItemText(item, _(""), const.POINT_OF_INTEREST_TARGET_COLUMN)
uuid = marker.marker_uuid

# Unset the point of interest in itemDataMap
Expand Down Expand Up @@ -2562,7 +2564,7 @@ def OnMarkerFocused(self, evt):
# Selection of more than 1 marker not supported by MarkerTransformator
if idx == -1 or idx == "":
return
marker_id = self.__get_marker_id(int(idx.GetText()))-1
marker_id = self.__get_marker_id(int(idx.GetText())) - 1
marker = self.markers.list[marker_id]

# XXX: There seems to be a bug in WxPython when selecting multiple items on the list using,
Expand Down Expand Up @@ -2593,7 +2595,7 @@ def OnMarkerUnfocused(self, evt):

def SetCameraToFocusOnMarker(self, evt):
idx = int(self.marker_list_ctrl.GetMainWindow().GetFocusedItem().GetText())
marker = self.markers.list[idx-1]
marker = self.markers.list[idx - 1]
Publisher.sendMessage("Set camera to focus on marker", marker=marker)

def OnCreateCoilTargetFromLandmark(self, evt):
Expand Down Expand Up @@ -2660,7 +2662,7 @@ def _SetTarget(self, marker):
idx = self.__find_marker_index(marker.marker_id)
item = self.marker_list_ctrl.FindItem(self.root, str(idx))
self.marker_list_ctrl.SetItemBackgroundColour(item, "RED")
self.marker_list_ctrl.SetItemText(item, _("Yes"), const.TARGET_COLUMN)
self.marker_list_ctrl.SetItemText(item, _("Yes"), const.TARGET_COLUMN)

target_uuid = marker.marker_uuid

Expand Down Expand Up @@ -2866,7 +2868,9 @@ def OnMenuChangeMEP(self, evt):
idx = int(self.marker_list_ctrl.GetMainWindow().GetFocusedItem().GetText())
marker = self.__get_marker(idx)

new_mep = dlg.ShowEnterMEPValue(self.marker_list_ctrl.GetMainWindow().GetItemText(idx, const.MEP_COLUMN))
new_mep = dlg.ShowEnterMEPValue(
self.marker_list_ctrl.GetMainWindow().GetItemText(idx, const.MEP_COLUMN)
)
self.markers.ChangeMEP(marker, new_mep)

def _UnsetTarget(self, marker):
Expand All @@ -2878,7 +2882,7 @@ def _UnsetTarget(self, marker):
# Update the marker list control.
item = self.marker_list_ctrl.FindItem(self.root, str(idx))
self.marker_list_ctrl.SetItemBackgroundColour(item, "white")
self.marker_list_ctrl.SetItemText(item, _(""), const.TARGET_COLUMN)
self.marker_list_ctrl.SetItemText(item, _(""), const.TARGET_COLUMN)

# Unset the target in itemDataMap
target_uuid = marker.marker_uuid
Expand All @@ -2894,7 +2898,7 @@ def __find_marker_index(self, marker_id):
num_items = self.marker_list_ctrl.GetCount()
for idx in range(num_items):
item_marker_id = self.__get_marker_id(idx)
list_item = self.marker_list_ctrl.FindItem(self.root, str(item_marker_id+1))
list_item = self.marker_list_ctrl.FindItem(self.root, str(item_marker_id + 1))
if int(list_item.GetText()) == marker_id:
return idx
return None
Expand All @@ -2906,7 +2910,7 @@ def __get_marker_id(self, idx):
list_item = self.marker_list_ctrl.FindItem(self.root, str(idx))
if list_item.GetText() == "":
return 0
return int(list_item.GetText())-1
return int(list_item.GetText()) - 1

def __get_marker(self, idx):
"""
Expand Down Expand Up @@ -3361,12 +3365,16 @@ def _AddMarker(self, marker, render, focus):
list_entry.append(round(marker.y, 1))
list_entry.append(round(marker.z, 1))

item = self.marker_list_ctrl.AppendItem(parentId=self.root, text=str(list_entry[const.ID_COLUMN]))
item = self.marker_list_ctrl.AppendItem(
parentId=self.root, text=str(list_entry[const.ID_COLUMN])
)
if marker.marker_type == MarkerType.BRAIN_TARGET:
item = self.marker_list_ctrl.AppendItem(parentId=item, text=str(list_entry[const.ID_COLUMN]))
item = self.marker_list_ctrl.AppendItem(
parentId=item, text=str(list_entry[const.ID_COLUMN])
)

for count, i in enumerate(list_entry[1:]):
self.marker_list_ctrl.GetMainWindow().SetItemText(item, str(i), count+1)
self.marker_list_ctrl.GetMainWindow().SetItemText(item, str(i), count + 1)
# self.marker_list_ctrl.SetItemData(num_items, key)
# else:
# self.marker_list_ctrl.AppendItem(root, list_entry)
Expand Down
1 change: 1 addition & 0 deletions invesalius/net/neuronavigation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ def pipeline_sensory_stimulus(self, time, state, parameter, duration):
if state != 3:
return
from invesalius.navigation.navigation import NavigationHub

marker_list = NavigationHub().markers.list
for marker in marker_list:
if parameter == 0:
Expand Down
8 changes: 6 additions & 2 deletions tes2wx.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import wx
import wx.dataview as dv


class MainFrame(wx.Frame):
def __init__(self):
super().__init__(None, title="wxPython TreeListCtrl with Columns and Subitems", size=(500, 400))
super().__init__(
None, title="wxPython TreeListCtrl with Columns and Subitems", size=(500, 400)
)
panel = wx.Panel(self)

# Create TreeListCtrl
Expand Down Expand Up @@ -37,8 +40,9 @@ def __init__(self):
sizer.Add(tree_list_ctrl, 1, wx.EXPAND)
panel.SetSizer(sizer)


if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
frame.Show()
app.MainLoop()
app.MainLoop()
17 changes: 12 additions & 5 deletions testwx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import wx
import csv

import wx


class MyFrame(wx.Frame):
def __init__(self):
super().__init__(None, title="ListCtrl with Subitems")
Expand Down Expand Up @@ -57,14 +59,18 @@ def on_item_selected(self, event):
self.Layout() # Refresh layout

def on_export(self, event):
with wx.FileDialog(self, "Save CSV file", wildcard="CSV files (*.csv)|*.csv",
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as file_dialog:
with wx.FileDialog(
self,
"Save CSV file",
wildcard="CSV files (*.csv)|*.csv",
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
) as file_dialog:
if file_dialog.ShowModal() == wx.ID_OK:
path = file_dialog.GetPath()
self.export_to_csv(path)

def export_to_csv(self, path):
with open(path, mode='w', newline='', encoding='utf-8') as file:
with open(path, mode="w", newline="", encoding="utf-8") as file:
writer = csv.writer(file)

# Write header
Expand All @@ -81,7 +87,8 @@ def export_to_csv(self, path):

wx.MessageBox("Exported successfully!", "Info", wx.OK | wx.ICON_INFORMATION)


if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
app.MainLoop()
6 changes: 4 additions & 2 deletions wxtest3.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import wx
from wx.lib.agw.hypertreelist import HyperTreeList


class MyFrame(wx.Frame):
def __init__(self):
super().__init__(None, title="HyperTreeList Example", size=(600, 400))

# Create a HyperTreeList
self.tree = HyperTreeList(self, style= wx.TR_HIDE_ROOT)
self.tree = HyperTreeList(self, style=wx.TR_HIDE_ROOT)

# Add columns
self.tree.AddColumn("Items")
Expand All @@ -30,6 +31,7 @@ def __init__(self):
# Show the frame
self.Show()


app = wx.App(False)
frame = MyFrame()
app.MainLoop()
app.MainLoop()

0 comments on commit 938f148

Please sign in to comment.