From 938f148f58f417ce47e2739473b8242493e29dfe Mon Sep 17 00:00:00 2001 From: rmatsuda Date: Fri, 11 Oct 2024 17:22:19 +0300 Subject: [PATCH] RUFF --- invesalius/gui/task_navigator.py | 58 +++++++++++++++------------ invesalius/net/neuronavigation_api.py | 1 + tes2wx.py | 8 +++- testwx.py | 17 +++++--- wxtest3.py | 6 ++- 5 files changed, 56 insertions(+), 34 deletions(-) diff --git a/invesalius/gui/task_navigator.py b/invesalius/gui/task_navigator.py index 3fe490b2b..891807738 100644 --- a/invesalius/gui/task_navigator.py +++ b/invesalius/gui/task_navigator.py @@ -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) @@ -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) @@ -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: @@ -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 @@ -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 @@ -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, @@ -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): @@ -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 @@ -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): @@ -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 @@ -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 @@ -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): """ @@ -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) diff --git a/invesalius/net/neuronavigation_api.py b/invesalius/net/neuronavigation_api.py index c7f210171..504fa997c 100644 --- a/invesalius/net/neuronavigation_api.py +++ b/invesalius/net/neuronavigation_api.py @@ -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: diff --git a/tes2wx.py b/tes2wx.py index eeafcf270..202168185 100644 --- a/tes2wx.py +++ b/tes2wx.py @@ -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 @@ -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() \ No newline at end of file + app.MainLoop() diff --git a/testwx.py b/testwx.py index 8edbbb0aa..ab8a81578 100644 --- a/testwx.py +++ b/testwx.py @@ -1,6 +1,8 @@ -import wx import csv +import wx + + class MyFrame(wx.Frame): def __init__(self): super().__init__(None, title="ListCtrl with Subitems") @@ -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 @@ -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() \ No newline at end of file + app.MainLoop() diff --git a/wxtest3.py b/wxtest3.py index 35e2668d2..1ab14a33a 100644 --- a/wxtest3.py +++ b/wxtest3.py @@ -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") @@ -30,6 +31,7 @@ def __init__(self): # Show the frame self.Show() + app = wx.App(False) frame = MyFrame() -app.MainLoop() \ No newline at end of file +app.MainLoop()