From 40466824c428da396f37502b925f979af9da68b7 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Mon, 25 May 2020 19:27:46 -0300 Subject: [PATCH] managing mask showing and name edition using click events --- app.py | 21 ++++++++++----------- invesalius/gui/data_notebook.py | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app.py b/app.py index 165b42d..36bc27a 100644 --- a/app.py +++ b/app.py @@ -102,7 +102,7 @@ class InVesalius(wx.App): """ Initialize splash screen and main frame. """ - + from multiprocessing import freeze_support freeze_support() @@ -183,18 +183,18 @@ class Inv3SplashScreen(SplashScreen): # session.SaveConfigFileBackup() - + # Only after language was defined, splash screen will be # shown if lang: - + #import locale #try: # locale.setlocale(locale.LC_ALL, '') #except locale.Error: # pass - - + + # For pt_BR, splash_pt.png should be used if (lang.startswith('pt')): icon_file = "splash_pt.png" @@ -206,13 +206,13 @@ class Inv3SplashScreen(SplashScreen): abs_file_path = os.path.abspath(".." + os.sep) path = abs_file_path path = os.path.join(path, 'icons', icon_file) - + else: path = os.path.join(".","icons", icon_file) if not os.path.exists(path): path = os.path.join(".", "icons", "splash_en.png") - + bmp = wx.Image(path).ConvertToBitmap() try: @@ -236,10 +236,10 @@ class Inv3SplashScreen(SplashScreen): from invesalius.gui.frame import Frame from invesalius.control import Controller from invesalius.project import Project - + self.main = Frame(None) self.control = Controller(self.main) - + self.fc = wx.CallLater(200, self.ShowMain) options, args = parse_comand_line() wx.CallLater(1, use_cmd_optargs, options, args) @@ -502,7 +502,7 @@ def main(): if __name__ == '__main__': #Is needed because of pyinstaller multiprocessing.freeze_support() - + #Needed in win 32 exe if hasattr(sys,"frozen") and sys.platform.startswith('win'): @@ -527,4 +527,3 @@ if __name__ == '__main__': # Init application main() - diff --git a/invesalius/gui/data_notebook.py b/invesalius/gui/data_notebook.py index a3ef0eb..02ce80f 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -366,8 +366,9 @@ class MasksListCtrlPanel(wx.ListCtrl): def __bind_events_wx(self): self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEditLabel) self.Bind(wx.EVT_KEY_UP, self.OnKeyEvent) - self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) + # self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) self.Bind(wx.EVT_LEFT_UP, self.OnClickItem) + self.Bind(wx.EVT_LEFT_DCLICK, self.OnDblClickItem) def __bind_events(self): Publisher.subscribe(self.AddMask, 'Add mask') @@ -482,6 +483,16 @@ class MasksListCtrlPanel(wx.ListCtrl): self.image_gray = Image.open(os.path.join(inv_paths.ICON_DIR, "object_colour.jpg")) + def get_column_clicked(self, position): + epx, epy = position + wpx, wpy = self.GetPosition() + width_sum = 0 + for i in range(self.GetColumnCount()): + width_sum += self.GetColumnWidth(i) + if (epx - wpx) <= width_sum: + return i + return -1 + def OnEditLabel(self, evt): if not evt.IsEditCancelled(): index = evt.GetIndex() @@ -502,7 +513,8 @@ class MasksListCtrlPanel(wx.ListCtrl): def OnClickItem(self, evt): self._click_check = False item_idx, flag = (self.HitTest(evt.GetPosition())) - if flag == wx.LIST_HITTEST_ONITEMICON: + column_clicked = self.get_column_clicked(evt.GetPosition()) + if column_clicked == 0: self._click_check = True item = self.GetItem(item_idx, 0) flag = not bool(item.GetImage()) @@ -510,16 +522,23 @@ class MasksListCtrlPanel(wx.ListCtrl): self.OnCheckItem(item_idx, flag) evt.Skip() - def OnItemActivated(self, evt): - if not self._click_check: - item = self.GetItem(evt.GetItem().GetId(), 1) - ctrl = self.EditLabel(item.GetId()) - w, h = ctrl.GetClientSize() - w = self.GetColumnWidth(1) - ctrl.SetClientSize(w, h) - ctrl.SetValue(item.GetText()) - ctrl.SelectAll() - evt.Skip() + def OnDblClickItem(self, evt): + self._click_check = False + item_idx, flag = (self.HitTest(evt.GetPosition())) + column_clicked = self.get_column_clicked(evt.GetPosition()) + if column_clicked == 1: + item = self.GetItem(item_idx, 1) + self.enter_edition(item) + evt.Skip() + + def enter_edition(self, item): + print("Enter edition") + ctrl = self.EditLabel(item.GetId()) + w, h = ctrl.GetClientSize() + w = self.GetColumnWidth(1) + ctrl.SetClientSize(w, h) + ctrl.SetValue(item.GetText()) + ctrl.SelectAll() def CreateColourBitmap(self, colour): """ -- libgit2 0.21.2